Update BoringSSL to fcef13a49852397a0d39c00be8d7bc2ba1ab6fb9 & include C++ files (#303)

* Update package vendoring script

* Update BoringSSL to fcef13a49852397a0d39c00be8d7bc2ba1ab6fb9

* Handle ERR_GET_ERR becoming a function

* Update CMake
This commit is contained in:
Cory Benfield authored and GitHub committed 2024-11-27 11:24:17 +00:00
1 parent ff0f781cf7
commit bd94260799
351 files changed
+8192 -5493

No files matched your search

+2 -2
View File
@@ -20,7 +20,7 @@
// Sources/CCryptoBoringSSL directory. The source repository is at
// https://boringssl.googlesource.com/boringssl.
//
// BoringSSL Commit: 2587c4974dbe9872451151c8e975f58567a1ce0d
// BoringSSL Commit: fcef13a49852397a0d39c00be8d7bc2ba1ab6fb9
import PackageDescription
@@ -186,5 +186,5 @@ let package = Package(
),
.testTarget(name: "CryptoBoringWrapperTests", dependencies: ["CryptoBoringWrapper"]),
],
cxxLanguageStandard: .cxx11
cxxLanguageStandard: .cxx14
)
+250 -249
View File
@@ -13,255 +13,256 @@
##===----------------------------------------------------------------------===##
add_library(CCryptoBoringSSL STATIC
"crypto/asn1/a_bitstr.c"
"crypto/asn1/a_bool.c"
"crypto/asn1/a_d2i_fp.c"
"crypto/asn1/a_dup.c"
"crypto/asn1/a_gentm.c"
"crypto/asn1/a_i2d_fp.c"
"crypto/asn1/a_int.c"
"crypto/asn1/a_mbstr.c"
"crypto/asn1/a_object.c"
"crypto/asn1/a_octet.c"
"crypto/asn1/a_strex.c"
"crypto/asn1/a_strnid.c"
"crypto/asn1/a_time.c"
"crypto/asn1/a_type.c"
"crypto/asn1/a_utctm.c"
"crypto/asn1/asn1_lib.c"
"crypto/asn1/asn1_par.c"
"crypto/asn1/asn_pack.c"
"crypto/asn1/f_int.c"
"crypto/asn1/f_string.c"
"crypto/asn1/posix_time.c"
"crypto/asn1/tasn_dec.c"
"crypto/asn1/tasn_enc.c"
"crypto/asn1/tasn_fre.c"
"crypto/asn1/tasn_new.c"
"crypto/asn1/tasn_typ.c"
"crypto/asn1/tasn_utl.c"
"crypto/base64/base64.c"
"crypto/bio/bio.c"
"crypto/bio/bio_mem.c"
"crypto/bio/connect.c"
"crypto/bio/errno.c"
"crypto/bio/fd.c"
"crypto/bio/file.c"
"crypto/bio/hexdump.c"
"crypto/bio/pair.c"
"crypto/bio/printf.c"
"crypto/bio/socket.c"
"crypto/bio/socket_helper.c"
"crypto/blake2/blake2.c"
"crypto/bn_extra/bn_asn1.c"
"crypto/bn_extra/convert.c"
"crypto/buf/buf.c"
"crypto/bytestring/asn1_compat.c"
"crypto/bytestring/ber.c"
"crypto/bytestring/cbb.c"
"crypto/bytestring/cbs.c"
"crypto/bytestring/unicode.c"
"crypto/chacha/chacha.c"
"crypto/cipher_extra/cipher_extra.c"
"crypto/cipher_extra/derive_key.c"
"crypto/cipher_extra/e_aesctrhmac.c"
"crypto/cipher_extra/e_aesgcmsiv.c"
"crypto/cipher_extra/e_chacha20poly1305.c"
"crypto/cipher_extra/e_des.c"
"crypto/cipher_extra/e_null.c"
"crypto/cipher_extra/e_rc2.c"
"crypto/cipher_extra/e_rc4.c"
"crypto/cipher_extra/e_tls.c"
"crypto/cipher_extra/tls_cbc.c"
"crypto/conf/conf.c"
"crypto/cpu_aarch64_apple.c"
"crypto/cpu_aarch64_fuchsia.c"
"crypto/cpu_aarch64_linux.c"
"crypto/cpu_aarch64_openbsd.c"
"crypto/cpu_aarch64_sysreg.c"
"crypto/cpu_aarch64_win.c"
"crypto/cpu_arm_freebsd.c"
"crypto/cpu_arm_linux.c"
"crypto/cpu_intel.c"
"crypto/crypto.c"
"crypto/curve25519/curve25519.c"
"crypto/curve25519/curve25519_64_adx.c"
"crypto/curve25519/spake25519.c"
"crypto/des/des.c"
"crypto/dh_extra/dh_asn1.c"
"crypto/dh_extra/params.c"
"crypto/digest_extra/digest_extra.c"
"crypto/dilithium/dilithium.c"
"crypto/dsa/dsa.c"
"crypto/dsa/dsa_asn1.c"
"crypto/ec_extra/ec_asn1.c"
"crypto/ec_extra/ec_derive.c"
"crypto/ec_extra/hash_to_curve.c"
"crypto/ecdh_extra/ecdh_extra.c"
"crypto/ecdsa_extra/ecdsa_asn1.c"
"crypto/engine/engine.c"
"crypto/err/err.c"
"crypto/evp/evp.c"
"crypto/evp/evp_asn1.c"
"crypto/evp/evp_ctx.c"
"crypto/evp/p_dh.c"
"crypto/evp/p_dh_asn1.c"
"crypto/evp/p_dsa_asn1.c"
"crypto/evp/p_ec.c"
"crypto/evp/p_ec_asn1.c"
"crypto/evp/p_ed25519.c"
"crypto/evp/p_ed25519_asn1.c"
"crypto/evp/p_hkdf.c"
"crypto/evp/p_rsa.c"
"crypto/evp/p_rsa_asn1.c"
"crypto/evp/p_x25519.c"
"crypto/evp/p_x25519_asn1.c"
"crypto/evp/pbkdf.c"
"crypto/evp/print.c"
"crypto/evp/scrypt.c"
"crypto/evp/sign.c"
"crypto/ex_data.c"
"crypto/fipsmodule/bcm.c"
"crypto/fipsmodule/fips_shared_support.c"
"crypto/hpke/hpke.c"
"crypto/hrss/hrss.c"
"crypto/keccak/keccak.c"
"crypto/kyber/kyber.c"
"crypto/lhash/lhash.c"
"crypto/md4/md4.c"
"crypto/md5/md5.c"
"crypto/mem.c"
"crypto/mldsa/mldsa.c"
"crypto/obj/obj.c"
"crypto/obj/obj_xref.c"
"crypto/pem/pem_all.c"
"crypto/pem/pem_info.c"
"crypto/pem/pem_lib.c"
"crypto/pem/pem_oth.c"
"crypto/pem/pem_pk8.c"
"crypto/pem/pem_pkey.c"
"crypto/pem/pem_x509.c"
"crypto/pem/pem_xaux.c"
"crypto/pkcs7/pkcs7.c"
"crypto/pkcs7/pkcs7_x509.c"
"crypto/pkcs8/p5_pbev2.c"
"crypto/pkcs8/pkcs8.c"
"crypto/pkcs8/pkcs8_x509.c"
"crypto/poly1305/poly1305.c"
"crypto/poly1305/poly1305_arm.c"
"crypto/poly1305/poly1305_vec.c"
"crypto/pool/pool.c"
"crypto/rand_extra/deterministic.c"
"crypto/rand_extra/fork_detect.c"
"crypto/rand_extra/forkunsafe.c"
"crypto/rand_extra/getentropy.c"
"crypto/rand_extra/ios.c"
"crypto/rand_extra/passive.c"
"crypto/rand_extra/rand_extra.c"
"crypto/rand_extra/trusty.c"
"crypto/rand_extra/urandom.c"
"crypto/rand_extra/windows.c"
"crypto/rc4/rc4.c"
"crypto/refcount.c"
"crypto/rsa_extra/rsa_asn1.c"
"crypto/rsa_extra/rsa_crypt.c"
"crypto/rsa_extra/rsa_extra.c"
"crypto/rsa_extra/rsa_print.c"
"crypto/sha/sha1.c"
"crypto/sha/sha256.c"
"crypto/sha/sha512.c"
"crypto/siphash/siphash.c"
"crypto/slhdsa/fors.c"
"crypto/slhdsa/merkle.c"
"crypto/slhdsa/slhdsa.c"
"crypto/slhdsa/thash.c"
"crypto/slhdsa/wots.c"
"crypto/spx/spx.c"
"crypto/spx/spx_address.c"
"crypto/spx/spx_fors.c"
"crypto/spx/spx_merkle.c"
"crypto/spx/spx_thash.c"
"crypto/spx/spx_util.c"
"crypto/spx/spx_wots.c"
"crypto/stack/stack.c"
"crypto/thread.c"
"crypto/thread_none.c"
"crypto/thread_pthread.c"
"crypto/thread_win.c"
"crypto/trust_token/pmbtoken.c"
"crypto/trust_token/trust_token.c"
"crypto/trust_token/voprf.c"
"crypto/x509/a_digest.c"
"crypto/x509/a_sign.c"
"crypto/x509/a_verify.c"
"crypto/x509/algorithm.c"
"crypto/x509/asn1_gen.c"
"crypto/x509/by_dir.c"
"crypto/x509/by_file.c"
"crypto/x509/i2d_pr.c"
"crypto/x509/name_print.c"
"crypto/x509/policy.c"
"crypto/x509/rsa_pss.c"
"crypto/x509/t_crl.c"
"crypto/x509/t_req.c"
"crypto/x509/t_x509.c"
"crypto/x509/t_x509a.c"
"crypto/x509/v3_akey.c"
"crypto/x509/v3_akeya.c"
"crypto/x509/v3_alt.c"
"crypto/x509/v3_bcons.c"
"crypto/x509/v3_bitst.c"
"crypto/x509/v3_conf.c"
"crypto/x509/v3_cpols.c"
"crypto/x509/v3_crld.c"
"crypto/x509/v3_enum.c"
"crypto/x509/v3_extku.c"
"crypto/x509/v3_genn.c"
"crypto/x509/v3_ia5.c"
"crypto/x509/v3_info.c"
"crypto/x509/v3_int.c"
"crypto/x509/v3_lib.c"
"crypto/x509/v3_ncons.c"
"crypto/x509/v3_ocsp.c"
"crypto/x509/v3_pcons.c"
"crypto/x509/v3_pmaps.c"
"crypto/x509/v3_prn.c"
"crypto/x509/v3_purp.c"
"crypto/x509/v3_skey.c"
"crypto/x509/v3_utl.c"
"crypto/x509/x509.c"
"crypto/x509/x509_att.c"
"crypto/x509/x509_cmp.c"
"crypto/x509/x509_d2.c"
"crypto/x509/x509_def.c"
"crypto/x509/x509_ext.c"
"crypto/x509/x509_lu.c"
"crypto/x509/x509_obj.c"
"crypto/x509/x509_req.c"
"crypto/x509/x509_set.c"
"crypto/x509/x509_trs.c"
"crypto/x509/x509_txt.c"
"crypto/x509/x509_v3.c"
"crypto/x509/x509_vfy.c"
"crypto/x509/x509_vpm.c"
"crypto/x509/x509cset.c"
"crypto/x509/x509name.c"
"crypto/x509/x509rset.c"
"crypto/x509/x509spki.c"
"crypto/x509/x_algor.c"
"crypto/x509/x_all.c"
"crypto/x509/x_attrib.c"
"crypto/x509/x_crl.c"
"crypto/x509/x_exten.c"
"crypto/x509/x_name.c"
"crypto/x509/x_pubkey.c"
"crypto/x509/x_req.c"
"crypto/x509/x_sig.c"
"crypto/x509/x_spki.c"
"crypto/x509/x_val.c"
"crypto/x509/x_x509.c"
"crypto/x509/x_x509a.c"
"gen/crypto/err_data.c")
"crypto/asn1/a_bitstr.cc"
"crypto/asn1/a_bool.cc"
"crypto/asn1/a_d2i_fp.cc"
"crypto/asn1/a_dup.cc"
"crypto/asn1/a_gentm.cc"
"crypto/asn1/a_i2d_fp.cc"
"crypto/asn1/a_int.cc"
"crypto/asn1/a_mbstr.cc"
"crypto/asn1/a_object.cc"
"crypto/asn1/a_octet.cc"
"crypto/asn1/a_strex.cc"
"crypto/asn1/a_strnid.cc"
"crypto/asn1/a_time.cc"
"crypto/asn1/a_type.cc"
"crypto/asn1/a_utctm.cc"
"crypto/asn1/asn1_lib.cc"
"crypto/asn1/asn1_par.cc"
"crypto/asn1/asn_pack.cc"
"crypto/asn1/f_int.cc"
"crypto/asn1/f_string.cc"
"crypto/asn1/posix_time.cc"
"crypto/asn1/tasn_dec.cc"
"crypto/asn1/tasn_enc.cc"
"crypto/asn1/tasn_fre.cc"
"crypto/asn1/tasn_new.cc"
"crypto/asn1/tasn_typ.cc"
"crypto/asn1/tasn_utl.cc"
"crypto/base64/base64.cc"
"crypto/bio/bio.cc"
"crypto/bio/bio_mem.cc"
"crypto/bio/connect.cc"
"crypto/bio/errno.cc"
"crypto/bio/fd.cc"
"crypto/bio/file.cc"
"crypto/bio/hexdump.cc"
"crypto/bio/pair.cc"
"crypto/bio/printf.cc"
"crypto/bio/socket.cc"
"crypto/bio/socket_helper.cc"
"crypto/blake2/blake2.cc"
"crypto/bn_extra/bn_asn1.cc"
"crypto/bn_extra/convert.cc"
"crypto/buf/buf.cc"
"crypto/bytestring/asn1_compat.cc"
"crypto/bytestring/ber.cc"
"crypto/bytestring/cbb.cc"
"crypto/bytestring/cbs.cc"
"crypto/bytestring/unicode.cc"
"crypto/chacha/chacha.cc"
"crypto/cipher_extra/cipher_extra.cc"
"crypto/cipher_extra/derive_key.cc"
"crypto/cipher_extra/e_aesctrhmac.cc"
"crypto/cipher_extra/e_aesgcmsiv.cc"
"crypto/cipher_extra/e_chacha20poly1305.cc"
"crypto/cipher_extra/e_des.cc"
"crypto/cipher_extra/e_null.cc"
"crypto/cipher_extra/e_rc2.cc"
"crypto/cipher_extra/e_rc4.cc"
"crypto/cipher_extra/e_tls.cc"
"crypto/cipher_extra/tls_cbc.cc"
"crypto/conf/conf.cc"
"crypto/cpu_aarch64_apple.cc"
"crypto/cpu_aarch64_fuchsia.cc"
"crypto/cpu_aarch64_linux.cc"
"crypto/cpu_aarch64_openbsd.cc"
"crypto/cpu_aarch64_sysreg.cc"
"crypto/cpu_aarch64_win.cc"
"crypto/cpu_arm_freebsd.cc"
"crypto/cpu_arm_linux.cc"
"crypto/cpu_intel.cc"
"crypto/crypto.cc"
"crypto/curve25519/curve25519.cc"
"crypto/curve25519/curve25519_64_adx.cc"
"crypto/curve25519/spake25519.cc"
"crypto/des/des.cc"
"crypto/dh_extra/dh_asn1.cc"
"crypto/dh_extra/params.cc"
"crypto/digest_extra/digest_extra.cc"
"crypto/dilithium/dilithium.cc"
"crypto/dsa/dsa.cc"
"crypto/dsa/dsa_asn1.cc"
"crypto/ec_extra/ec_asn1.cc"
"crypto/ec_extra/ec_derive.cc"
"crypto/ec_extra/hash_to_curve.cc"
"crypto/ecdh_extra/ecdh_extra.cc"
"crypto/ecdsa_extra/ecdsa_asn1.cc"
"crypto/engine/engine.cc"
"crypto/err/err.cc"
"crypto/evp/evp.cc"
"crypto/evp/evp_asn1.cc"
"crypto/evp/evp_ctx.cc"
"crypto/evp/p_dh.cc"
"crypto/evp/p_dh_asn1.cc"
"crypto/evp/p_dsa_asn1.cc"
"crypto/evp/p_ec.cc"
"crypto/evp/p_ec_asn1.cc"
"crypto/evp/p_ed25519.cc"
"crypto/evp/p_ed25519_asn1.cc"
"crypto/evp/p_hkdf.cc"
"crypto/evp/p_rsa.cc"
"crypto/evp/p_rsa_asn1.cc"
"crypto/evp/p_x25519.cc"
"crypto/evp/p_x25519_asn1.cc"
"crypto/evp/pbkdf.cc"
"crypto/evp/print.cc"
"crypto/evp/scrypt.cc"
"crypto/evp/sign.cc"
"crypto/ex_data.cc"
"crypto/fipsmodule/bcm.cc"
"crypto/fipsmodule/fips_shared_support.cc"
"crypto/hpke/hpke.cc"
"crypto/hrss/hrss.cc"
"crypto/keccak/keccak.cc"
"crypto/kyber/kyber.cc"
"crypto/lhash/lhash.cc"
"crypto/md4/md4.cc"
"crypto/md5/md5.cc"
"crypto/mem.cc"
"crypto/mldsa/mldsa.cc"
"crypto/mlkem/mlkem.cc"
"crypto/obj/obj.cc"
"crypto/obj/obj_xref.cc"
"crypto/pem/pem_all.cc"
"crypto/pem/pem_info.cc"
"crypto/pem/pem_lib.cc"
"crypto/pem/pem_oth.cc"
"crypto/pem/pem_pk8.cc"
"crypto/pem/pem_pkey.cc"
"crypto/pem/pem_x509.cc"
"crypto/pem/pem_xaux.cc"
"crypto/pkcs7/pkcs7.cc"
"crypto/pkcs7/pkcs7_x509.cc"
"crypto/pkcs8/p5_pbev2.cc"
"crypto/pkcs8/pkcs8.cc"
"crypto/pkcs8/pkcs8_x509.cc"
"crypto/poly1305/poly1305.cc"
"crypto/poly1305/poly1305_arm.cc"
"crypto/poly1305/poly1305_vec.cc"
"crypto/pool/pool.cc"
"crypto/rand_extra/deterministic.cc"
"crypto/rand_extra/fork_detect.cc"
"crypto/rand_extra/forkunsafe.cc"
"crypto/rand_extra/getentropy.cc"
"crypto/rand_extra/ios.cc"
"crypto/rand_extra/passive.cc"
"crypto/rand_extra/rand_extra.cc"
"crypto/rand_extra/trusty.cc"
"crypto/rand_extra/urandom.cc"
"crypto/rand_extra/windows.cc"
"crypto/rc4/rc4.cc"
"crypto/refcount.cc"
"crypto/rsa_extra/rsa_asn1.cc"
"crypto/rsa_extra/rsa_crypt.cc"
"crypto/rsa_extra/rsa_extra.cc"
"crypto/rsa_extra/rsa_print.cc"
"crypto/sha/sha1.cc"
"crypto/sha/sha256.cc"
"crypto/sha/sha512.cc"
"crypto/siphash/siphash.cc"
"crypto/slhdsa/fors.cc"
"crypto/slhdsa/merkle.cc"
"crypto/slhdsa/slhdsa.cc"
"crypto/slhdsa/thash.cc"
"crypto/slhdsa/wots.cc"
"crypto/spx/spx.cc"
"crypto/spx/spx_address.cc"
"crypto/spx/spx_fors.cc"
"crypto/spx/spx_merkle.cc"
"crypto/spx/spx_thash.cc"
"crypto/spx/spx_util.cc"
"crypto/spx/spx_wots.cc"
"crypto/stack/stack.cc"
"crypto/thread.cc"
"crypto/thread_none.cc"
"crypto/thread_pthread.cc"
"crypto/thread_win.cc"
"crypto/trust_token/pmbtoken.cc"
"crypto/trust_token/trust_token.cc"
"crypto/trust_token/voprf.cc"
"crypto/x509/a_digest.cc"
"crypto/x509/a_sign.cc"
"crypto/x509/a_verify.cc"
"crypto/x509/algorithm.cc"
"crypto/x509/asn1_gen.cc"
"crypto/x509/by_dir.cc"
"crypto/x509/by_file.cc"
"crypto/x509/i2d_pr.cc"
"crypto/x509/name_print.cc"
"crypto/x509/policy.cc"
"crypto/x509/rsa_pss.cc"
"crypto/x509/t_crl.cc"
"crypto/x509/t_req.cc"
"crypto/x509/t_x509.cc"
"crypto/x509/t_x509a.cc"
"crypto/x509/v3_akey.cc"
"crypto/x509/v3_akeya.cc"
"crypto/x509/v3_alt.cc"
"crypto/x509/v3_bcons.cc"
"crypto/x509/v3_bitst.cc"
"crypto/x509/v3_conf.cc"
"crypto/x509/v3_cpols.cc"
"crypto/x509/v3_crld.cc"
"crypto/x509/v3_enum.cc"
"crypto/x509/v3_extku.cc"
"crypto/x509/v3_genn.cc"
"crypto/x509/v3_ia5.cc"
"crypto/x509/v3_info.cc"
"crypto/x509/v3_int.cc"
"crypto/x509/v3_lib.cc"
"crypto/x509/v3_ncons.cc"
"crypto/x509/v3_ocsp.cc"
"crypto/x509/v3_pcons.cc"
"crypto/x509/v3_pmaps.cc"
"crypto/x509/v3_prn.cc"
"crypto/x509/v3_purp.cc"
"crypto/x509/v3_skey.cc"
"crypto/x509/v3_utl.cc"
"crypto/x509/x509.cc"
"crypto/x509/x509_att.cc"
"crypto/x509/x509_cmp.cc"
"crypto/x509/x509_d2.cc"
"crypto/x509/x509_def.cc"
"crypto/x509/x509_ext.cc"
"crypto/x509/x509_lu.cc"
"crypto/x509/x509_obj.cc"
"crypto/x509/x509_req.cc"
"crypto/x509/x509_set.cc"
"crypto/x509/x509_trs.cc"
"crypto/x509/x509_txt.cc"
"crypto/x509/x509_v3.cc"
"crypto/x509/x509_vfy.cc"
"crypto/x509/x509_vpm.cc"
"crypto/x509/x509cset.cc"
"crypto/x509/x509name.cc"
"crypto/x509/x509rset.cc"
"crypto/x509/x509spki.cc"
"crypto/x509/x_algor.cc"
"crypto/x509/x_all.cc"
"crypto/x509/x_attrib.cc"
"crypto/x509/x_crl.cc"
"crypto/x509/x_exten.cc"
"crypto/x509/x_name.cc"
"crypto/x509/x_pubkey.cc"
"crypto/x509/x_req.cc"
"crypto/x509/x_sig.cc"
"crypto/x509/x_spki.cc"
"crypto/x509/x_val.cc"
"crypto/x509/x_x509.cc"
"crypto/x509/x_x509a.cc"
"gen/crypto/err_data.cc")
if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
target_sources(CCryptoBoringSSL PRIVATE
@@ -142,6 +142,7 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
const unsigned char *p;
unsigned char *s;
int padding;
uint8_t padding_mask;
if (len < 1) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_SHORT);
@@ -170,7 +171,7 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
}
// Unused bits in a BIT STRING must be zero.
uint8_t padding_mask = (1 << padding) - 1;
padding_mask = (1 << padding) - 1;
if (padding != 0 && (len < 1 || (p[len - 1] & padding_mask) != 0)) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BIT_STRING_PADDING);
goto err;
@@ -182,7 +183,7 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
ret->flags |= (ASN1_STRING_FLAG_BITS_LEFT | padding); // set
if (len > 0) {
s = OPENSSL_memdup(p, len);
s = reinterpret_cast<uint8_t *>(OPENSSL_memdup(p, len));
if (s == NULL) {
goto err;
}
@@ -72,7 +72,7 @@ void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x) {
return NULL;
}
const uint8_t *ptr = data;
void *ret = ASN1_item_d2i(x, &ptr, len, it);
void *ret = ASN1_item_d2i(reinterpret_cast<ASN1_VALUE **>(x), &ptr, len, it);
OPENSSL_free(data);
return ret;
}
@@ -73,7 +73,7 @@ void *ASN1_item_dup(const ASN1_ITEM *it, void *x) {
return NULL;
}
i = ASN1_item_i2d(x, &b, it);
i = ASN1_item_i2d(reinterpret_cast<ASN1_VALUE *>(x), &b, it);
if (b == NULL) {
return NULL;
}
@@ -74,7 +74,7 @@ int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) {
int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x) {
unsigned char *b = NULL;
int n = ASN1_item_i2d(x, &b, it);
int n = ASN1_item_i2d(reinterpret_cast<ASN1_VALUE *>(x), &b, it);
if (b == NULL) {
return 0;
}
@@ -408,6 +408,7 @@ static ASN1_STRING *bn_to_asn1_string(const BIGNUM *bn, ASN1_STRING *ai,
} else {
ret = ai;
}
int len;
if (ret == NULL) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
goto err;
@@ -419,7 +420,7 @@ static ASN1_STRING *bn_to_asn1_string(const BIGNUM *bn, ASN1_STRING *ai,
ret->type = type;
}
int len = BN_num_bytes(bn);
len = BN_num_bytes(bn);
if (!ASN1_STRING_set(ret, NULL, len) ||
!BN_bn2bin_padded(ret->data, len, bn)) {
goto err;
@@ -226,6 +226,8 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in,
CBB cbb;
CBB_zero(&cbb);
// If both the same type just copy across
uint8_t *data = NULL;
size_t data_len = 0;
if (inform == outform) {
if (!ASN1_STRING_set(dest, in, len)) {
goto err;
@@ -245,12 +247,12 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in,
goto err;
}
}
uint8_t *data = NULL;
size_t data_len;
if (// OpenSSL historically NUL-terminated this value with a single byte,
// even for |MBSTRING_BMP| and |MBSTRING_UNIV|.
!CBB_add_u8(&cbb, 0) || !CBB_finish(&cbb, &data, &data_len) ||
data_len < 1 || data_len > INT_MAX) {
if (/* OpenSSL historically NUL-terminated this value with a single byte,
* even for |MBSTRING_BMP| and |MBSTRING_UNIV|. */
!CBB_add_u8(&cbb, 0) || //
!CBB_finish(&cbb, &data, &data_len) || //
data_len < 1 || //
data_len > INT_MAX) {
OPENSSL_PUT_ERROR(ASN1, ERR_R_INTERNAL_ERROR);
OPENSSL_free(data);
goto err;
@@ -272,7 +274,7 @@ int asn1_is_printable(uint32_t value) {
if (value > 0x7f) {
return 0;
}
return OPENSSL_isalnum(value) || //
return OPENSSL_isalnum(value) || //
value == ' ' || value == '\'' || value == '(' || value == ')' ||
value == '+' || value == ',' || value == '-' || value == '.' ||
value == '/' || value == ':' || value == '=' || value == '?';
@@ -114,7 +114,7 @@ int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a) {
int len = i2t_ASN1_OBJECT(buf, sizeof(buf), a);
if (len > (int)sizeof(buf) - 1) {
// The input was truncated. Allocate a buffer that fits.
allocated = OPENSSL_malloc(len + 1);
allocated = reinterpret_cast<char *>(OPENSSL_malloc(len + 1));
if (allocated == NULL) {
return -1;
}
@@ -159,7 +159,8 @@ static int table_cmp(const ASN1_STRING_TABLE *a, const ASN1_STRING_TABLE *b) {
}
static int table_cmp_void(const void *a, const void *b) {
return table_cmp(a, b);
return table_cmp(reinterpret_cast<const ASN1_STRING_TABLE *>(a),
reinterpret_cast<const ASN1_STRING_TABLE *>(b));
}
static uint32_t table_hash(const ASN1_STRING_TABLE *tbl) {
@@ -169,9 +170,9 @@ static uint32_t table_hash(const ASN1_STRING_TABLE *tbl) {
static const ASN1_STRING_TABLE *asn1_string_table_get(int nid) {
ASN1_STRING_TABLE key;
key.nid = nid;
const ASN1_STRING_TABLE *tbl =
const ASN1_STRING_TABLE *tbl = reinterpret_cast<ASN1_STRING_TABLE *>(
bsearch(&key, tbl_standard, OPENSSL_ARRAY_SIZE(tbl_standard),
sizeof(ASN1_STRING_TABLE), table_cmp_void);
sizeof(ASN1_STRING_TABLE), table_cmp_void));
if (tbl != NULL) {
return tbl;
}
@@ -198,6 +199,7 @@ int ASN1_STRING_TABLE_add(int nid, long minsize, long maxsize,
int ret = 0;
CRYPTO_MUTEX_lock_write(&string_tables_lock);
ASN1_STRING_TABLE *tbl = NULL;
if (string_tables == NULL) {
string_tables = lh_ASN1_STRING_TABLE_new(table_hash, table_cmp);
if (string_tables == NULL) {
@@ -214,7 +216,8 @@ int ASN1_STRING_TABLE_add(int nid, long minsize, long maxsize,
}
}
ASN1_STRING_TABLE *tbl = OPENSSL_malloc(sizeof(ASN1_STRING_TABLE));
tbl = reinterpret_cast<ASN1_STRING_TABLE *>(
OPENSSL_malloc(sizeof(ASN1_STRING_TABLE)));
if (tbl == NULL) {
goto err;
}
@@ -137,10 +137,10 @@ void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) {
a->value.boolean = value ? ASN1_BOOLEAN_TRUE : ASN1_BOOLEAN_FALSE;
break;
case V_ASN1_OBJECT:
a->value.object = value;
a->value.object = reinterpret_cast<ASN1_OBJECT *>(value);
break;
default:
a->value.asn1_string = value;
a->value.asn1_string = reinterpret_cast<ASN1_STRING *>(value);
break;
}
}
@@ -151,14 +151,14 @@ int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value) {
ASN1_TYPE_set(a, type, p);
} else if (type == V_ASN1_OBJECT) {
ASN1_OBJECT *odup;
odup = OBJ_dup(value);
odup = OBJ_dup(reinterpret_cast<const ASN1_OBJECT *>(value));
if (!odup) {
return 0;
}
ASN1_TYPE_set(a, type, odup);
} else {
ASN1_STRING *sdup;
sdup = ASN1_STRING_dup(value);
sdup = ASN1_STRING_dup(reinterpret_cast<const ASN1_STRING *>(value));
if (!sdup) {
return 0;
}
@@ -271,7 +271,7 @@ ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str) {
}
int ASN1_STRING_set(ASN1_STRING *str, const void *_data, ossl_ssize_t len_s) {
const char *data = _data;
const char *data = reinterpret_cast<const char *>(_data);
size_t len;
if (len_s < 0) {
if (data == NULL) {
@@ -291,9 +291,9 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, ossl_ssize_t len_s) {
if (str->length <= (int)len || str->data == NULL) {
unsigned char *c = str->data;
if (c == NULL) {
str->data = OPENSSL_malloc(len + 1);
str->data = reinterpret_cast<uint8_t *>(OPENSSL_malloc(len + 1));
} else {
str->data = OPENSSL_realloc(c, len + 1);
str->data = reinterpret_cast<uint8_t *>(OPENSSL_realloc(c, len + 1));
}
if (str->data == NULL) {
@@ -315,7 +315,7 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, ossl_ssize_t len_s) {
void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len) {
OPENSSL_free(str->data);
str->data = data;
str->data = reinterpret_cast<uint8_t *>(data);
str->length = len;
}
@@ -62,7 +62,7 @@
ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **out) {
uint8_t *new_data = NULL;
int len = ASN1_item_i2d(obj, &new_data, it);
int len = ASN1_item_i2d(reinterpret_cast<ASN1_VALUE *>(obj), &new_data, it);
if (len <= 0) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ENCODE_ERROR);
return NULL;
@@ -91,7 +91,7 @@ void *ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it) {
void *ret = ASN1_item_d2i(NULL, &p, oct->length, it);
if (ret == NULL || p != oct->data + oct->length) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
ASN1_item_free(ret, it);
ASN1_item_free(reinterpret_cast<ASN1_VALUE *>(ret), it);
return NULL;
}
return ret;
@@ -154,7 +154,7 @@ int OPENSSL_tm_to_posix(const struct tm *tm, int64_t *out) {
}
int OPENSSL_posix_to_tm(int64_t time, struct tm *out_tm) {
struct tm tmp_tm = {0};
struct tm tmp_tm = {};
if (!utc_from_posix_time(time, &tmp_tm.tm_year, &tmp_tm.tm_mon,
&tmp_tm.tm_mday, &tmp_tm.tm_hour, &tmp_tm.tm_min,
&tmp_tm.tm_sec)) {
@@ -282,7 +282,8 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
goto err;
}
const ASN1_EXTERN_FUNCS *ef = it->funcs;
const ASN1_EXTERN_FUNCS *ef =
reinterpret_cast<const ASN1_EXTERN_FUNCS *>(it->funcs);
return ef->asn1_ex_d2i(pval, in, len, it, opt, NULL);
}
@@ -294,7 +295,7 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
goto err;
}
const ASN1_AUX *aux = it->funcs;
const ASN1_AUX *aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) {
goto auxerr;
@@ -379,7 +380,7 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
goto err;
}
const ASN1_AUX *aux = it->funcs;
const ASN1_AUX *aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) {
goto auxerr;
@@ -90,7 +90,7 @@ int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) {
if (len <= 0) {
return len;
}
buf = OPENSSL_malloc(len);
buf = reinterpret_cast<uint8_t *>(OPENSSL_malloc(len));
if (!buf) {
return -1;
}
@@ -191,7 +191,8 @@ int asn1_item_ex_i2d_opt(ASN1_VALUE **pval, unsigned char **out,
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
return -1;
}
const ASN1_EXTERN_FUNCS *ef = it->funcs;
const ASN1_EXTERN_FUNCS *ef =
reinterpret_cast<const ASN1_EXTERN_FUNCS *>(it->funcs);
int ret = ef->asn1_ex_i2d(pval, out, it);
if (ret == 0) {
// |asn1_ex_i2d| should never return zero. We have already checked
@@ -424,7 +425,8 @@ typedef struct {
} DER_ENC;
static int der_cmp(const void *a, const void *b) {
const DER_ENC *d1 = a, *d2 = b;
const DER_ENC *d1 = reinterpret_cast<const DER_ENC *>(a),
*d2 = reinterpret_cast<const DER_ENC *>(b);
int cmplen, i;
cmplen = (d1->length < d2->length) ? d1->length : d2->length;
i = OPENSSL_memcmp(d1->data, d2->data, cmplen);
@@ -453,14 +455,15 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
}
int ret = 0;
unsigned char *const buf = OPENSSL_malloc(skcontlen);
DER_ENC *encoded = OPENSSL_calloc(sk_ASN1_VALUE_num(sk), sizeof(*encoded));
uint8_t *const buf = reinterpret_cast<uint8_t *>(OPENSSL_malloc(skcontlen));
DER_ENC *encoded = reinterpret_cast<DER_ENC *>(
OPENSSL_calloc(sk_ASN1_VALUE_num(sk), sizeof(*encoded)));
uint8_t *p = buf;
if (encoded == NULL || buf == NULL) {
goto err;
}
// Encode all the elements into |buf| and populate |encoded|.
unsigned char *p = buf;
for (size_t i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
ASN1_VALUE *skitem = sk_ASN1_VALUE_value(sk, i);
encoded[i].data = p;
@@ -94,7 +94,7 @@ void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) {
break;
case ASN1_ITYPE_CHOICE: {
const ASN1_AUX *aux = it->funcs;
const ASN1_AUX *aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
if (asn1_cb) {
i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);
@@ -118,7 +118,7 @@ void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) {
}
case ASN1_ITYPE_EXTERN:
ef = it->funcs;
ef = reinterpret_cast<const ASN1_EXTERN_FUNCS *>(it->funcs);
if (ef && ef->asn1_ex_free) {
ef->asn1_ex_free(pval, it);
}
@@ -128,7 +128,7 @@ void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) {
if (!asn1_refcount_dec_and_test_zero(pval, it)) {
return;
}
const ASN1_AUX *aux = it->funcs;
const ASN1_AUX *aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
if (asn1_cb) {
i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);
@@ -91,7 +91,7 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
switch (it->itype) {
case ASN1_ITYPE_EXTERN:
ef = it->funcs;
ef = reinterpret_cast<const ASN1_EXTERN_FUNCS *>(it->funcs);
if (ef && ef->asn1_ex_new) {
if (!ef->asn1_ex_new(pval, it)) {
goto memerr;
@@ -116,7 +116,7 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
break;
case ASN1_ITYPE_CHOICE: {
const ASN1_AUX *aux = it->funcs;
const ASN1_AUX *aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
if (asn1_cb) {
i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
@@ -127,7 +127,7 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
return 1;
}
}
*pval = OPENSSL_zalloc(it->size);
*pval = reinterpret_cast<ASN1_VALUE *>(OPENSSL_zalloc(it->size));
if (!*pval) {
goto memerr;
}
@@ -139,7 +139,7 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
}
case ASN1_ITYPE_SEQUENCE: {
const ASN1_AUX *aux = it->funcs;
const ASN1_AUX *aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
if (asn1_cb) {
i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
@@ -150,7 +150,7 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
return 1;
}
}
*pval = OPENSSL_zalloc(it->size);
*pval = reinterpret_cast<ASN1_VALUE *>(OPENSSL_zalloc(it->size));
if (!*pval) {
goto memerr;
}
@@ -279,7 +279,8 @@ static int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
return 1;
case V_ASN1_ANY: {
ASN1_TYPE *typ = OPENSSL_malloc(sizeof(ASN1_TYPE));
ASN1_TYPE *typ =
reinterpret_cast<ASN1_TYPE *>(OPENSSL_malloc(sizeof(ASN1_TYPE)));
if (!typ) {
return 0;
}
@@ -77,7 +77,7 @@
// Given an ASN1_ITEM CHOICE type return the selector value
int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it) {
int *sel = offset2ptr(*pval, it->utype);
int *sel = reinterpret_cast<int *>(offset2ptr(*pval, it->utype));
return *sel;
}
@@ -85,7 +85,7 @@ int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it) {
int asn1_set_choice_selector(ASN1_VALUE **pval, int value,
const ASN1_ITEM *it) {
int *sel, ret;
sel = offset2ptr(*pval, it->utype);
sel = reinterpret_cast<int *>(offset2ptr(*pval, it->utype));
ret = *sel;
*sel = value;
return ret;
@@ -96,11 +96,12 @@ static CRYPTO_refcount_t *asn1_get_references(ASN1_VALUE **pval,
if (it->itype != ASN1_ITYPE_SEQUENCE) {
return NULL;
}
const ASN1_AUX *aux = it->funcs;
const ASN1_AUX *aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) {
return NULL;
}
return offset2ptr(*pval, aux->ref_offset);
return reinterpret_cast<CRYPTO_refcount_t *>(
offset2ptr(*pval, aux->ref_offset));
}
void asn1_refcount_set_one(ASN1_VALUE **pval, const ASN1_ITEM *it) {
@@ -124,11 +125,11 @@ static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it) {
if (!pval || !*pval) {
return NULL;
}
aux = it->funcs;
aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
if (!aux || !(aux->flags & ASN1_AFLG_ENCODING)) {
return NULL;
}
return offset2ptr(*pval, aux->enc_offset);
return reinterpret_cast<ASN1_ENCODING *>(offset2ptr(*pval, aux->enc_offset));
}
void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it) {
@@ -163,7 +164,7 @@ int asn1_enc_save(ASN1_VALUE **pval, const uint8_t *in, size_t in_len,
enc->buf = buf;
enc->enc = (uint8_t *)in;
} else {
enc->enc = OPENSSL_memdup(in, in_len);
enc->enc = reinterpret_cast<uint8_t *>(OPENSSL_memdup(in, in_len));
if (!enc->enc) {
return 0;
}
@@ -202,7 +203,8 @@ int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
// Given an ASN1_TEMPLATE get a pointer to a field
ASN1_VALUE **asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) {
ASN1_VALUE **pvaltmp = offset2ptr(*pval, tt->offset);
ASN1_VALUE **pvaltmp =
reinterpret_cast<ASN1_VALUE **>(offset2ptr(*pval, tt->offset));
// NOTE for BOOLEAN types the field is just a plain int so we can't return
// int **, so settle for (int *).
return pvaltmp;
@@ -224,9 +226,10 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
adb = ASN1_ADB_ptr(tt->item);
// Get the selector field
sfld = offset2ptr(*pval, adb->offset);
sfld = reinterpret_cast<ASN1_VALUE **>(offset2ptr(*pval, adb->offset));
// Check if NULL
int selector;
if (*sfld == NULL) {
if (!adb->null_tt) {
goto err;
@@ -238,7 +241,7 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
// NB: don't check for NID_undef here because it
// might be a legitimate value in the table
assert(tt->flags & ASN1_TFLG_ADB_OID);
int selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld);
selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld);
// Try to find matching entry in table Maybe should check application types
// first to allow application override? Might also be useful to have a flag
@@ -121,12 +121,11 @@ int EVP_EncodedLength(size_t *out_len, size_t len) {
}
EVP_ENCODE_CTX *EVP_ENCODE_CTX_new(void) {
return OPENSSL_zalloc(sizeof(EVP_ENCODE_CTX));
return reinterpret_cast<EVP_ENCODE_CTX *>(
OPENSSL_zalloc(sizeof(EVP_ENCODE_CTX)));
}
void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx) {
OPENSSL_free(ctx);
}
void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx) { OPENSSL_free(ctx); }
void EVP_EncodeInit(EVP_ENCODE_CTX *ctx) {
OPENSSL_memset(ctx, 0, sizeof(EVP_ENCODE_CTX));
@@ -302,9 +301,9 @@ static int base64_decode_quad(uint8_t *out, size_t *out_num_bytes,
const uint32_t v = ((uint32_t)a) << 18 | ((uint32_t)b) << 12 |
((uint32_t)c) << 6 | (uint32_t)d;
const unsigned padding_pattern = (in[0] == '=') << 3 |
(in[1] == '=') << 2 |
(in[2] == '=') << 1 |
const unsigned padding_pattern = (in[0] == '=') << 3 | //
(in[1] == '=') << 2 | //
(in[2] == '=') << 1 | //
(in[3] == '=');
// In presence of padding, the lowest bits of v are unused. Canonical encoding
@@ -412,8 +411,7 @@ int EVP_DecodeBase64(uint8_t *out, size_t *out_len, size_t max_out,
}
size_t max_len;
if (!EVP_DecodedLength(&max_len, in_len) ||
max_out < max_len) {
if (!EVP_DecodedLength(&max_len, in_len) || max_out < max_len) {
return 0;
}
@@ -449,7 +447,7 @@ int EVP_DecodeBlock(uint8_t *dst, const uint8_t *src, size_t src_len) {
// Trim newlines, spaces and tabs from the end of the line.
while (src_len > 0) {
switch (src[src_len-1]) {
switch (src[src_len - 1]) {
case ' ':
case '\t':
case '\r':
@@ -462,8 +460,7 @@ int EVP_DecodeBlock(uint8_t *dst, const uint8_t *src, size_t src_len) {
}
size_t dst_len;
if (!EVP_DecodedLength(&dst_len, src_len) ||
dst_len > INT_MAX ||
if (!EVP_DecodedLength(&dst_len, src_len) || dst_len > INT_MAX ||
!EVP_DecodeBase64(dst, &dst_len, dst_len, src, src_len)) {
return -1;
}
@@ -73,7 +73,7 @@ static CRYPTO_EX_DATA_CLASS g_ex_data_class =
CRYPTO_EX_DATA_CLASS_INIT_WITH_APP_DATA;
BIO *BIO_new(const BIO_METHOD *method) {
BIO *ret = OPENSSL_zalloc(sizeof(BIO));
BIO *ret = reinterpret_cast<BIO *>(OPENSSL_zalloc(sizeof(BIO)));
if (ret == NULL) {
return NULL;
}
@@ -116,13 +116,9 @@ int BIO_up_ref(BIO *bio) {
return 1;
}
void BIO_vfree(BIO *bio) {
BIO_free(bio);
}
void BIO_vfree(BIO *bio) { BIO_free(bio); }
void BIO_free_all(BIO *bio) {
BIO_free(bio);
}
void BIO_free_all(BIO *bio) { BIO_free(bio); }
int BIO_read(BIO *bio, void *buf, int len) {
if (bio == NULL || bio->method == NULL || bio->method->bread == NULL) {
@@ -136,7 +132,7 @@ int BIO_read(BIO *bio, void *buf, int len) {
if (len <= 0) {
return 0;
}
int ret = bio->method->bread(bio, buf, len);
int ret = bio->method->bread(bio, reinterpret_cast<char *>(buf), len);
if (ret > 0) {
bio->num_read += ret;
}
@@ -174,7 +170,7 @@ int BIO_write(BIO *bio, const void *in, int inl) {
if (inl <= 0) {
return 0;
}
int ret = bio->method->bwrite(bio, in, inl);
int ret = bio->method->bwrite(bio, reinterpret_cast<const char *>(in), inl);
if (ret > 0) {
bio->num_write += ret;
}
@@ -182,7 +178,7 @@ int BIO_write(BIO *bio, const void *in, int inl) {
}
int BIO_write_all(BIO *bio, const void *data, size_t len) {
const uint8_t *data_u8 = data;
const uint8_t *data_u8 = reinterpret_cast<const uint8_t *>(data);
while (len > 0) {
int ret = BIO_write(bio, data_u8, len > INT_MAX ? INT_MAX : (int)len);
if (ret <= 0) {
@@ -204,9 +200,7 @@ int BIO_puts(BIO *bio, const char *in) {
return BIO_write(bio, in, (int)len);
}
int BIO_flush(BIO *bio) {
return (int)BIO_ctrl(bio, BIO_CTRL_FLUSH, 0, NULL);
}
int BIO_flush(BIO *bio) { return (int)BIO_ctrl(bio, BIO_CTRL_FLUSH, 0, NULL); }
long BIO_ctrl(BIO *bio, int cmd, long larg, void *parg) {
if (bio == NULL) {
@@ -237,21 +231,13 @@ long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg) {
return BIO_ctrl(b, cmd, larg, (void *)&i);
}
int BIO_reset(BIO *bio) {
return (int)BIO_ctrl(bio, BIO_CTRL_RESET, 0, NULL);
}
int BIO_reset(BIO *bio) { return (int)BIO_ctrl(bio, BIO_CTRL_RESET, 0, NULL); }
int BIO_eof(BIO *bio) {
return (int)BIO_ctrl(bio, BIO_CTRL_EOF, 0, NULL);
}
int BIO_eof(BIO *bio) { return (int)BIO_ctrl(bio, BIO_CTRL_EOF, 0, NULL); }
void BIO_set_flags(BIO *bio, int flags) {
bio->flags |= flags;
}
void BIO_set_flags(BIO *bio, int flags) { bio->flags |= flags; }
int BIO_test_flags(const BIO *bio, int flags) {
return bio->flags & flags;
}
int BIO_test_flags(const BIO *bio, int flags) { return bio->flags & flags; }
int BIO_should_read(const BIO *bio) {
return BIO_test_flags(bio, BIO_FLAGS_READ);
@@ -273,9 +259,7 @@ int BIO_get_retry_reason(const BIO *bio) { return bio->retry_reason; }
void BIO_set_retry_reason(BIO *bio, int reason) { bio->retry_reason = reason; }
void BIO_clear_flags(BIO *bio, int flags) {
bio->flags &= ~flags;
}
void BIO_clear_flags(BIO *bio, int flags) { bio->flags &= ~flags; }
void BIO_set_retry_read(BIO *bio) {
bio->flags |= BIO_FLAGS_READ | BIO_FLAGS_SHOULD_RETRY;
@@ -287,9 +271,7 @@ void BIO_set_retry_write(BIO *bio) {
static const int kRetryFlags = BIO_FLAGS_RWS | BIO_FLAGS_SHOULD_RETRY;
int BIO_get_retry_flags(BIO *bio) {
return bio->flags & kRetryFlags;
}
int BIO_get_retry_flags(BIO *bio) { return bio->flags & kRetryFlags; }
void BIO_clear_retry_flags(BIO *bio) {
bio->flags &= ~kRetryFlags;
@@ -318,7 +300,7 @@ long BIO_callback_ctrl(BIO *bio, int cmd, bio_info_cb fp) {
}
size_t BIO_pending(const BIO *bio) {
const long r = BIO_ctrl((BIO *) bio, BIO_CTRL_PENDING, 0, NULL);
const long r = BIO_ctrl((BIO *)bio, BIO_CTRL_PENDING, 0, NULL);
assert(r >= 0);
if (r < 0) {
@@ -327,12 +309,10 @@ size_t BIO_pending(const BIO *bio) {
return r;
}
size_t BIO_ctrl_pending(const BIO *bio) {
return BIO_pending(bio);
}
size_t BIO_ctrl_pending(const BIO *bio) { return BIO_pending(bio); }
size_t BIO_wpending(const BIO *bio) {
const long r = BIO_ctrl((BIO *) bio, BIO_CTRL_WPENDING, 0, NULL);
const long r = BIO_ctrl((BIO *)bio, BIO_CTRL_WPENDING, 0, NULL);
assert(r >= 0);
if (r < 0) {
@@ -430,9 +410,7 @@ static int print_bio(const char *str, size_t len, void *bio) {
return BIO_write_all((BIO *)bio, str, len);
}
void ERR_print_errors(BIO *bio) {
ERR_print_errors_cb(print_bio, bio);
}
void ERR_print_errors(BIO *bio) { ERR_print_errors_cb(print_bio, bio); }
// bio_read_all reads everything from |bio| and prepends |prefix| to it. On
// success, |*out| is set to an allocated buffer (which should be freed with
@@ -454,7 +432,7 @@ static int bio_read_all(BIO *bio, uint8_t **out, size_t *out_len,
if (len < prefix_len) {
return 0;
}
*out = OPENSSL_malloc(len);
*out = reinterpret_cast<uint8_t *>(OPENSSL_malloc(len));
if (*out == NULL) {
return 0;
}
@@ -485,7 +463,8 @@ static int bio_read_all(BIO *bio, uint8_t **out, size_t *out_len,
if (len < kChunkSize || len > max_len) {
len = max_len;
}
uint8_t *new_buf = OPENSSL_realloc(*out, len);
uint8_t *new_buf =
reinterpret_cast<uint8_t *>(OPENSSL_realloc(*out, len));
if (new_buf == NULL) {
OPENSSL_free(*out);
return 0;
@@ -594,7 +573,7 @@ int BIO_read_asn1(BIO *bio, uint8_t **out, size_t *out_len, size_t max_len) {
return 0;
}
if ((len32 >> ((num_bytes-1)*8)) == 0) {
if ((len32 >> ((num_bytes - 1) * 8)) == 0) {
// Length should have been at least one byte shorter.
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
return 0;
@@ -603,16 +582,14 @@ int BIO_read_asn1(BIO *bio, uint8_t **out, size_t *out_len, size_t max_len) {
len = len32;
}
if (len + header_len < len ||
len + header_len > max_len ||
len > INT_MAX) {
if (len + header_len < len || len + header_len > max_len || len > INT_MAX) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TOO_LONG);
return 0;
}
len += header_len;
*out_len = len;
*out = OPENSSL_malloc(len);
*out = reinterpret_cast<uint8_t *>(OPENSSL_malloc(len));
if (*out == NULL) {
return 0;
}
@@ -644,7 +621,8 @@ int BIO_get_new_index(void) {
}
BIO_METHOD *BIO_meth_new(int type, const char *name) {
BIO_METHOD *method = OPENSSL_zalloc(sizeof(BIO_METHOD));
BIO_METHOD *method =
reinterpret_cast<BIO_METHOD *>(OPENSSL_zalloc(sizeof(BIO_METHOD)));
if (method == NULL) {
return NULL;
}
@@ -653,18 +631,14 @@ BIO_METHOD *BIO_meth_new(int type, const char *name) {
return method;
}
void BIO_meth_free(BIO_METHOD *method) {
OPENSSL_free(method);
}
void BIO_meth_free(BIO_METHOD *method) { OPENSSL_free(method); }
int BIO_meth_set_create(BIO_METHOD *method,
int (*create_func)(BIO *)) {
int BIO_meth_set_create(BIO_METHOD *method, int (*create_func)(BIO *)) {
method->create = create_func;
return 1;
}
int BIO_meth_set_destroy(BIO_METHOD *method,
int (*destroy_func)(BIO *)) {
int BIO_meth_set_destroy(BIO_METHOD *method, int (*destroy_func)(BIO *)) {
method->destroy = destroy_func;
return 1;
}
@@ -710,10 +684,10 @@ int BIO_meth_set_puts(BIO_METHOD *method, int (*puts)(BIO *, const char *)) {
return 1;
}
int BIO_get_ex_new_index(long argl, void *argp,
CRYPTO_EX_unused *unused,
CRYPTO_EX_dup *dup_unused,
CRYPTO_EX_free *free_func) {
int BIO_get_ex_new_index(long argl, void *argp, //
CRYPTO_EX_unused *unused, //
CRYPTO_EX_dup *dup_unused, //
CRYPTO_EX_free *free_func) {
return CRYPTO_get_ex_new_index_ex(&g_ex_data_class, argl, argp, free_func);
}
@@ -83,7 +83,7 @@ BIO *BIO_new_mem_buf(const void *buf, ossl_ssize_t len) {
b = (BUF_MEM *)ret->ptr;
// BIO_FLAGS_MEM_RDONLY ensures |b->data| is not written to.
b->data = (void *)buf;
b->data = reinterpret_cast<char *>(const_cast<void *>(buf));
b->length = size;
b->max = size;
@@ -135,7 +135,7 @@ static int mem_read(BIO *bio, char *out, int outl) {
return 0;
}
BUF_MEM *b = bio->ptr;
BUF_MEM *b = reinterpret_cast<BUF_MEM *>(bio->ptr);
int ret = outl;
if ((size_t)ret > b->length) {
ret = (int)b->length;
@@ -169,7 +169,7 @@ static int mem_write(BIO *bio, const char *in, int inl) {
return -1;
}
BUF_MEM *b = bio->ptr;
BUF_MEM *b = reinterpret_cast<BUF_MEM *>(bio->ptr);
if (!BUF_MEM_append(b, in, inl)) {
return -1;
}
@@ -185,14 +185,15 @@ static int mem_gets(BIO *bio, char *buf, int size) {
// The buffer size includes space for the trailing NUL, so we can read at most
// one fewer byte.
BUF_MEM *b = bio->ptr;
BUF_MEM *b = reinterpret_cast<BUF_MEM *>(bio->ptr);
int ret = size - 1;
if ((size_t)ret > b->length) {
ret = (int)b->length;
}
// Stop at the first newline.
const char *newline = OPENSSL_memchr(b->data, '\n', ret);
const char *newline =
reinterpret_cast<char *>(OPENSSL_memchr(b->data, '\n', ret));
if (newline != NULL) {
ret = (int)(newline - b->data + 1);
}
@@ -231,7 +232,7 @@ static long mem_ctrl(BIO *bio, int cmd, long num, void *ptr) {
case BIO_CTRL_INFO:
ret = (long)b->length;
if (ptr != NULL) {
char **pptr = ptr;
char **pptr = reinterpret_cast<char **>(ptr);
*pptr = b->data;
}
break;
@@ -242,7 +243,7 @@ static long mem_ctrl(BIO *bio, int cmd, long num, void *ptr) {
break;
case BIO_C_GET_BUF_MEM_PTR:
if (ptr != NULL) {
BUF_MEM **pptr = ptr;
BUF_MEM **pptr = reinterpret_cast<BUF_MEM **>(ptr);
*pptr = b;
}
break;
@@ -63,9 +63,9 @@
#include <string.h>
#if !defined(OPENSSL_WINDOWS)
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#else
OPENSSL_MSVC_PRAGMA(warning(push, 3))
@@ -77,8 +77,8 @@ OPENSSL_MSVC_PRAGMA(warning(pop))
#include <CCryptoBoringSSL_err.h>
#include <CCryptoBoringSSL_mem.h>
#include "internal.h"
#include "../internal.h"
#include "internal.h"
enum {
@@ -109,9 +109,7 @@ typedef struct bio_connect_st {
} BIO_CONNECT;
#if !defined(OPENSSL_WINDOWS)
static int closesocket(int sock) {
return close(sock);
}
static int closesocket(int sock) { return close(sock); }
#endif
// split_host_and_port sets |*out_host| and |*out_port| to the host and port
@@ -231,7 +229,7 @@ static int conn_state(BIO *bio, BIO_CONNECT *c) {
}
BIO_clear_retry_flags(bio);
ret = connect(bio->num, (struct sockaddr*) &c->them, c->them_length);
ret = connect(bio->num, (struct sockaddr *)&c->them, c->them_length);
if (ret < 0) {
if (bio_socket_should_retry(ret)) {
BIO_set_flags(bio, (BIO_FLAGS_IO_SPECIAL | BIO_FLAGS_SHOULD_RETRY));
@@ -261,7 +259,8 @@ static int conn_state(BIO *bio, BIO_CONNECT *c) {
BIO_clear_retry_flags(bio);
OPENSSL_PUT_SYSTEM_ERROR();
OPENSSL_PUT_ERROR(BIO, BIO_R_NBIO_CONNECT_ERROR);
ERR_add_error_data(4, "host=", c->param_hostname, ":", c->param_port);
ERR_add_error_data(4, "host=", c->param_hostname, ":",
c->param_port);
ret = 0;
}
goto exit_loop;
@@ -296,7 +295,8 @@ end:
}
static BIO_CONNECT *BIO_CONNECT_new(void) {
BIO_CONNECT *ret = OPENSSL_zalloc(sizeof(BIO_CONNECT));
BIO_CONNECT *ret =
reinterpret_cast<BIO_CONNECT *>(OPENSSL_zalloc(sizeof(BIO_CONNECT)));
if (ret == NULL) {
return NULL;
}
@@ -323,7 +323,7 @@ static int conn_new(BIO *bio) {
}
static void conn_close_socket(BIO *bio) {
BIO_CONNECT *c = (BIO_CONNECT *) bio->ptr;
BIO_CONNECT *c = (BIO_CONNECT *)bio->ptr;
if (bio->num == -1) {
return;
@@ -342,7 +342,7 @@ static int conn_free(BIO *bio) {
conn_close_socket(bio);
}
BIO_CONNECT_free((BIO_CONNECT*) bio->ptr);
BIO_CONNECT_free((BIO_CONNECT *)bio->ptr);
return 1;
}
@@ -422,13 +422,15 @@ static long conn_ctrl(BIO *bio, int cmd, long num, void *ptr) {
bio->init = 1;
if (num == 0) {
OPENSSL_free(data->param_hostname);
data->param_hostname = OPENSSL_strdup(ptr);
data->param_hostname =
OPENSSL_strdup(reinterpret_cast<const char *>(ptr));
if (data->param_hostname == NULL) {
ret = 0;
}
} else if (num == 1) {
OPENSSL_free(data->param_port);
data->param_port = OPENSSL_strdup(ptr);
data->param_port =
OPENSSL_strdup(reinterpret_cast<const char *>(ptr));
if (data->param_port == NULL) {
ret = 0;
}
@@ -464,7 +466,8 @@ static long conn_ctrl(BIO *bio, int cmd, long num, void *ptr) {
case BIO_CTRL_FLUSH:
break;
case BIO_CTRL_GET_CALLBACK: {
int (**fptr)(const BIO *bio, int state, int xret) = ptr;
int (**fptr)(const BIO *bio, int state, int xret);
fptr = reinterpret_cast<decltype(fptr)>(ptr);
*fptr = data->info_callback;
} break;
default:
@@ -488,7 +491,8 @@ static long conn_callback_ctrl(BIO *bio, int cmd, bio_info_cb fp) {
OPENSSL_MSVC_PRAGMA(warning(push))
OPENSSL_MSVC_PRAGMA(warning(disable : 4191))
OPENSSL_CLANG_PRAGMA("clang diagnostic push")
OPENSSL_CLANG_PRAGMA("clang diagnostic ignored \"-Wunknown-warning-option\"")
OPENSSL_CLANG_PRAGMA(
"clang diagnostic ignored \"-Wunknown-warning-option\"")
OPENSSL_CLANG_PRAGMA("clang diagnostic ignored \"-Wcast-function-type\"")
data->info_callback = (int (*)(const struct bio_st *, int, int))fp;
OPENSSL_CLANG_PRAGMA("clang diagnostic pop")
@@ -524,11 +528,11 @@ static const BIO_METHOD methods_connectp = {
const BIO_METHOD *BIO_s_connect(void) { return &methods_connectp; }
int BIO_set_conn_hostname(BIO *bio, const char *name) {
return (int)BIO_ctrl(bio, BIO_C_SET_CONNECT, 0, (void*) name);
return (int)BIO_ctrl(bio, BIO_C_SET_CONNECT, 0, (void *)name);
}
int BIO_set_conn_port(BIO *bio, const char *port_str) {
return (int)BIO_ctrl(bio, BIO_C_SET_CONNECT, 1, (void*) port_str);
return (int)BIO_ctrl(bio, BIO_C_SET_CONNECT, 1, (void *)port_str);
}
int BIO_set_conn_int_port(BIO *bio, const int *port) {
@@ -143,7 +143,7 @@ static int file_free(BIO *bio) {
}
if (bio->init && bio->ptr != NULL) {
fclose(bio->ptr);
fclose(reinterpret_cast<FILE *>(bio->ptr));
bio->ptr = NULL;
}
bio->init = 0;
@@ -208,7 +208,7 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) {
// tested under POSIX will inadvertently change the state of |FILE|
// objects when wrapping them in a |BIO|.
if (num & BIO_FP_TEXT) {
_setmode(_fileno(ptr), _O_TEXT);
_setmode(_fileno(reinterpret_cast<FILE *>(ptr)), _O_TEXT);
}
#endif
b->shutdown = (int)num & BIO_CLOSE;
@@ -236,7 +236,7 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) {
ret = 0;
break;
}
fp = fopen_if_available(ptr, mode);
fp = fopen_if_available(reinterpret_cast<const char *>(ptr), mode);
if (fp == NULL) {
OPENSSL_PUT_SYSTEM_ERROR();
ERR_add_error_data(5, "fopen('", ptr, "','", mode, "')");
@@ -81,7 +81,8 @@ struct bio_bio_st {
};
static int bio_new(BIO *bio) {
struct bio_bio_st *b = OPENSSL_zalloc(sizeof *b);
struct bio_bio_st *b =
reinterpret_cast<bio_bio_st *>(OPENSSL_zalloc(sizeof *b));
if (b == NULL) {
return 0;
}
@@ -92,7 +93,7 @@ static int bio_new(BIO *bio) {
}
static void bio_destroy_pair(BIO *bio) {
struct bio_bio_st *b = bio->ptr;
struct bio_bio_st *b = reinterpret_cast<bio_bio_st *>(bio->ptr);
BIO *peer_bio;
struct bio_bio_st *peer_b;
@@ -105,7 +106,7 @@ static void bio_destroy_pair(BIO *bio) {
return;
}
peer_b = peer_bio->ptr;
peer_b = reinterpret_cast<bio_bio_st *>(peer_bio->ptr);
assert(peer_b != NULL);
assert(peer_b->peer == bio);
@@ -124,7 +125,7 @@ static void bio_destroy_pair(BIO *bio) {
}
static int bio_free(BIO *bio) {
struct bio_bio_st *b = bio->ptr;
struct bio_bio_st *b = reinterpret_cast<bio_bio_st *>(bio->ptr);
assert(b != NULL);
@@ -149,10 +150,10 @@ static int bio_read(BIO *bio, char *buf, int size_) {
return 0;
}
b = bio->ptr;
b = reinterpret_cast<bio_bio_st *>(bio->ptr);
assert(b != NULL);
assert(b->peer != NULL);
peer_b = b->peer->ptr;
peer_b = reinterpret_cast<bio_bio_st *>(b->peer->ptr);
assert(peer_b != NULL);
assert(peer_b->buf != NULL);
@@ -233,7 +234,7 @@ static int bio_write(BIO *bio, const char *buf, int num_) {
return 0;
}
b = bio->ptr;
b = reinterpret_cast<bio_bio_st *>(bio->ptr);
assert(b != NULL);
assert(b->peer != NULL);
assert(b->buf != NULL);
@@ -302,8 +303,8 @@ static int bio_make_pair(BIO *bio1, BIO *bio2, size_t writebuf1_len,
assert(bio1 != NULL);
assert(bio2 != NULL);
b1 = bio1->ptr;
b2 = bio2->ptr;
b1 = reinterpret_cast<bio_bio_st *>(bio1->ptr);
b2 = reinterpret_cast<bio_bio_st *>(bio2->ptr);
if (b1->peer != NULL || b2->peer != NULL) {
OPENSSL_PUT_ERROR(BIO, BIO_R_IN_USE);
@@ -314,7 +315,7 @@ static int bio_make_pair(BIO *bio1, BIO *bio2, size_t writebuf1_len,
if (writebuf1_len) {
b1->size = writebuf1_len;
}
b1->buf = OPENSSL_malloc(b1->size);
b1->buf = reinterpret_cast<uint8_t *>(OPENSSL_malloc(b1->size));
if (b1->buf == NULL) {
return 0;
}
@@ -326,7 +327,7 @@ static int bio_make_pair(BIO *bio1, BIO *bio2, size_t writebuf1_len,
if (writebuf2_len) {
b2->size = writebuf2_len;
}
b2->buf = OPENSSL_malloc(b2->size);
b2->buf = reinterpret_cast<uint8_t *>(OPENSSL_malloc(b2->size));
if (b2->buf == NULL) {
return 0;
}
@@ -349,13 +350,12 @@ static int bio_make_pair(BIO *bio1, BIO *bio2, size_t writebuf1_len,
static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) {
long ret;
struct bio_bio_st *b = bio->ptr;
struct bio_bio_st *b = reinterpret_cast<bio_bio_st *>(bio->ptr);
assert(b != NULL);
switch (cmd) {
// specific CTRL codes
// Specific control codes first:
case BIO_C_GET_WRITE_BUF_SIZE:
ret = (long)b->size;
break;
@@ -392,8 +392,8 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) {
ret = 1;
break;
// standard CTRL codes follow
// Standard control codes:
case BIO_CTRL_GET_CLOSE:
ret = bio->shutdown;
break;
@@ -405,7 +405,8 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) {
case BIO_CTRL_PENDING:
if (b->peer != NULL) {
struct bio_bio_st *peer_b = b->peer->ptr;
struct bio_bio_st *peer_b =
reinterpret_cast<bio_bio_st *>(b->peer->ptr);
ret = (long)peer_b->len;
} else {
ret = 0;
@@ -424,10 +425,11 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) {
break;
case BIO_CTRL_EOF: {
BIO *other_bio = ptr;
BIO *other_bio = reinterpret_cast<BIO *>(ptr);
if (other_bio) {
struct bio_bio_st *other_b = other_bio->ptr;
struct bio_bio_st *other_b =
reinterpret_cast<bio_bio_st *>(other_bio->ptr);
assert(other_b != NULL);
ret = other_b->len == 0 && other_b->closed;
} else {
@@ -449,8 +451,8 @@ static const BIO_METHOD methods_biop = {
static const BIO_METHOD *bio_s_bio(void) { return &methods_biop; }
int BIO_new_bio_pair(BIO** bio1_p, size_t writebuf1_len,
BIO** bio2_p, size_t writebuf2_len) {
int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1_len, BIO **bio2_p,
size_t writebuf2_len) {
BIO *bio1 = BIO_new(bio_s_bio());
BIO *bio2 = BIO_new(bio_s_bio());
if (bio1 == NULL || bio2 == NULL ||
@@ -75,12 +75,12 @@ int BIO_printf(BIO *bio, const char *format, ...) {
return -1;
}
if ((size_t) out_len >= sizeof(buf)) {
if ((size_t)out_len >= sizeof(buf)) {
const int requested_len = out_len;
// The output was truncated. Note that vsnprintf's return value
// does not include a trailing NUL, but the buffer must be sized
// for it.
out = OPENSSL_malloc(requested_len + 1);
out = reinterpret_cast<char *>(OPENSSL_malloc(requested_len + 1));
out_malloced = 1;
if (out == NULL) {
return -1;
@@ -121,7 +121,7 @@ void BLAKE2B256_Update(BLAKE2B_CTX *b2b, const void *in_data, size_t len) {
return;
}
const uint8_t *data = in_data;
const uint8_t *data = reinterpret_cast<const uint8_t *>(in_data);
size_t todo = sizeof(b2b->block) - b2b->block_used;
if (todo > len) {
todo = len;
@@ -78,8 +78,9 @@ static const char hextable[] = "0123456789abcdef";
char *BN_bn2hex(const BIGNUM *bn) {
int width = bn_minimal_width(bn);
char *buf = OPENSSL_malloc(1 /* leading '-' */ + 1 /* zero is non-empty */ +
width * BN_BYTES * 2 + 1 /* trailing NUL */);
char *buf = reinterpret_cast<char *>(
OPENSSL_malloc(1 /* leading '-' */ + 1 /* zero is non-empty */ +
width * BN_BYTES * 2 + 1 /* trailing NUL */));
if (buf == NULL) {
return NULL;
}
@@ -112,7 +113,7 @@ char *BN_bn2hex(const BIGNUM *bn) {
// decode_hex decodes |in_len| bytes of hex data from |in| and updates |bn|.
static int decode_hex(BIGNUM *bn, const char *in, int in_len) {
if (in_len > INT_MAX/4) {
if (in_len > INT_MAX / 4) {
OPENSSL_PUT_ERROR(BN, BN_R_BIGNUM_TOO_LONG);
return 0;
}
@@ -163,8 +164,7 @@ static int decode_dec(BIGNUM *bn, const char *in, int in_len) {
l *= 10;
l += in[i] - '0';
if (++j == BN_DEC_NUM) {
if (!BN_mul_word(bn, BN_DEC_CONV) ||
!BN_add_word(bn, l)) {
if (!BN_mul_word(bn, BN_DEC_CONV) || !BN_add_word(bn, l)) {
return 0;
}
l = 0;
@@ -174,10 +174,11 @@ static int decode_dec(BIGNUM *bn, const char *in, int in_len) {
return 1;
}
typedef int (*decode_func) (BIGNUM *bn, const char *in, int in_len);
typedef int (*char_test_func) (int c);
typedef int (*decode_func)(BIGNUM *bn, const char *in, int in_len);
typedef int (*char_test_func)(int c);
static int bn_x2bn(BIGNUM **outp, const char *in, decode_func decode, char_test_func want_char) {
static int bn_x2bn(BIGNUM **outp, const char *in, decode_func decode,
char_test_func want_char) {
BIGNUM *ret = NULL;
int neg = 0, i;
int num;
@@ -191,7 +192,8 @@ static int bn_x2bn(BIGNUM **outp, const char *in, decode_func decode, char_test_
in++;
}
for (i = 0; want_char((unsigned char)in[i]) && i + neg < INT_MAX; i++) {}
for (i = 0; want_char((unsigned char)in[i]) && i + neg < INT_MAX; i++) {
}
num = i + neg;
if (outp == NULL) {
@@ -238,7 +240,7 @@ char *BN_bn2dec(const BIGNUM *a) {
// and fix at the end.
BIGNUM *copy = NULL;
CBB cbb;
if (!CBB_init(&cbb, 16) ||
if (!CBB_init(&cbb, 16) || //
!CBB_add_u8(&cbb, 0 /* trailing NUL */)) {
goto err;
}
@@ -270,7 +272,7 @@ char *BN_bn2dec(const BIGNUM *a) {
}
}
if (BN_is_negative(a) &&
if (BN_is_negative(a) && //
!CBB_add_u8(&cbb, '-')) {
goto err;
}
@@ -282,7 +284,7 @@ char *BN_bn2dec(const BIGNUM *a) {
}
// Reverse the buffer.
for (size_t i = 0; i < len/2; i++) {
for (size_t i = 0; i < len / 2; i++) {
uint8_t tmp = data[i];
data[i] = data[len - 1 - i];
data[len - 1 - i] = tmp;
@@ -308,7 +310,7 @@ int BN_asc2bn(BIGNUM **outp, const char *in) {
}
if (in[0] == '0' && (in[1] == 'X' || in[1] == 'x')) {
if (!BN_hex2bn(outp, in+2)) {
if (!BN_hex2bn(outp, in + 2)) {
return 0;
}
} else {
@@ -377,9 +379,7 @@ size_t BN_bn2mpi(const BIGNUM *in, uint8_t *out) {
}
const size_t len = bytes + extend;
if (len < bytes ||
4 + len < len ||
(len & 0xffffffff) != len) {
if (len < bytes || 4 + len < len || (len & 0xffffffff) != len) {
// If we cannot represent the number then we emit zero as the interface
// doesn't allow an error to be signalled.
if (out) {
@@ -411,9 +411,9 @@ BIGNUM *BN_mpi2bn(const uint8_t *in, size_t len, BIGNUM *out) {
OPENSSL_PUT_ERROR(BN, BN_R_BAD_ENCODING);
return NULL;
}
const size_t in_len = ((size_t)in[0] << 24) |
((size_t)in[1] << 16) |
((size_t)in[2] << 8) |
const size_t in_len = ((size_t)in[0] << 24) | //
((size_t)in[1] << 16) | //
((size_t)in[2] << 8) | //
((size_t)in[3]);
if (in_len != len - 4) {
OPENSSL_PUT_ERROR(BN, BN_R_BAD_ENCODING);
@@ -449,7 +449,7 @@ BIGNUM *BN_mpi2bn(const uint8_t *in, size_t len, BIGNUM *out) {
}
int BN_bn2binpad(const BIGNUM *in, uint8_t *out, int len) {
if (len < 0 ||
if (len < 0 || //
!BN_bn2bin_padded(out, (size_t)len, in)) {
return -1;
}
@@ -457,7 +457,7 @@ int BN_bn2binpad(const BIGNUM *in, uint8_t *out, int len) {
}
int BN_bn2lebinpad(const BIGNUM *in, uint8_t *out, int len) {
if (len < 0 ||
if (len < 0 || //
!BN_bn2le_padded(out, (size_t)len, in)) {
return -1;
}
@@ -58,13 +58,15 @@
#include <string.h>
#include <CCryptoBoringSSL_mem.h>
#include <CCryptoBoringSSL_err.h>
#include <CCryptoBoringSSL_mem.h>
#include "../internal.h"
BUF_MEM *BUF_MEM_new(void) { return OPENSSL_zalloc(sizeof(BUF_MEM)); }
BUF_MEM *BUF_MEM_new(void) {
return reinterpret_cast<BUF_MEM *>(OPENSSL_zalloc(sizeof(BUF_MEM)));
}
void BUF_MEM_free(BUF_MEM *buf) {
if (buf == NULL) {
@@ -92,7 +94,8 @@ int BUF_MEM_reserve(BUF_MEM *buf, size_t cap) {
return 0;
}
char *new_buf = OPENSSL_realloc(buf->data, alloc_size);
char *new_buf =
reinterpret_cast<char *>(OPENSSL_realloc(buf->data, alloc_size));
if (new_buf == NULL) {
return 0;
}
@@ -18,15 +18,13 @@
#include <limits.h>
#include <string.h>
#include <CCryptoBoringSSL_mem.h>
#include <CCryptoBoringSSL_err.h>
#include <CCryptoBoringSSL_mem.h>
#include "../internal.h"
void CBB_zero(CBB *cbb) {
OPENSSL_memset(cbb, 0, sizeof(CBB));
}
void CBB_zero(CBB *cbb) { OPENSSL_memset(cbb, 0, sizeof(CBB)); }
static void cbb_init(CBB *cbb, uint8_t *buf, size_t cap, int can_resize) {
cbb->is_child = 0;
@@ -41,7 +39,7 @@ static void cbb_init(CBB *cbb, uint8_t *buf, size_t cap, int can_resize) {
int CBB_init(CBB *cbb, size_t initial_capacity) {
CBB_zero(cbb);
uint8_t *buf = OPENSSL_malloc(initial_capacity);
uint8_t *buf = reinterpret_cast<uint8_t *>(OPENSSL_malloc(initial_capacity));
if (initial_capacity > 0 && buf == NULL) {
return 0;
}
@@ -92,7 +90,8 @@ static int cbb_buffer_reserve(struct cbb_buffer_st *base, uint8_t **out,
if (newcap < base->cap || newcap < newlen) {
newcap = newlen;
}
uint8_t *newbuf = OPENSSL_realloc(base->buf, newcap);
uint8_t *newbuf =
reinterpret_cast<uint8_t *>(OPENSSL_realloc(base->buf, newcap));
if (newbuf == NULL) {
goto err;
}
@@ -200,13 +199,13 @@ int CBB_flush(CBB *cbb) {
assert(child->base == base);
size_t child_start = child->offset + child->pending_len_len;
if (!CBB_flush(cbb->child) ||
child_start < child->offset ||
size_t len;
if (!CBB_flush(cbb->child) || child_start < child->offset ||
base->len < child_start) {
goto err;
}
size_t len = base->len - child_start;
len = base->len - child_start;
if (child->pending_is_asn1) {
// For ASN.1 we assume that we'll only need a single byte for the length.
@@ -215,7 +214,7 @@ int CBB_flush(CBB *cbb) {
uint8_t len_len;
uint8_t initial_length_byte;
assert (child->pending_len_len == 1);
assert(child->pending_len_len == 1);
if (len > 0xfffffffe) {
OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW);
@@ -403,8 +402,7 @@ int CBB_add_zeros(CBB *cbb, size_t len) {
}
int CBB_add_space(CBB *cbb, uint8_t **out_data, size_t len) {
if (!CBB_flush(cbb) ||
!cbb_buffer_add(cbb_get_base(cbb), out_data, len)) {
if (!CBB_flush(cbb) || !cbb_buffer_add(cbb_get_base(cbb), out_data, len)) {
return 0;
}
return 1;
@@ -421,9 +419,7 @@ int CBB_reserve(CBB *cbb, uint8_t **out_data, size_t len) {
int CBB_did_write(CBB *cbb, size_t len) {
struct cbb_buffer_st *base = cbb_get_base(cbb);
size_t newlen = base->len + len;
if (cbb->child != NULL ||
newlen < base->len ||
newlen > base->cap) {
if (cbb->child != NULL || newlen < base->len || newlen > base->cap) {
return 0;
}
base->len = newlen;
@@ -450,33 +446,23 @@ static int cbb_add_u(CBB *cbb, uint64_t v, size_t len_len) {
return 1;
}
int CBB_add_u8(CBB *cbb, uint8_t value) {
return cbb_add_u(cbb, value, 1);
}
int CBB_add_u8(CBB *cbb, uint8_t value) { return cbb_add_u(cbb, value, 1); }
int CBB_add_u16(CBB *cbb, uint16_t value) {
return cbb_add_u(cbb, value, 2);
}
int CBB_add_u16(CBB *cbb, uint16_t value) { return cbb_add_u(cbb, value, 2); }
int CBB_add_u16le(CBB *cbb, uint16_t value) {
return CBB_add_u16(cbb, CRYPTO_bswap2(value));
}
int CBB_add_u24(CBB *cbb, uint32_t value) {
return cbb_add_u(cbb, value, 3);
}
int CBB_add_u24(CBB *cbb, uint32_t value) { return cbb_add_u(cbb, value, 3); }
int CBB_add_u32(CBB *cbb, uint32_t value) {
return cbb_add_u(cbb, value, 4);
}
int CBB_add_u32(CBB *cbb, uint32_t value) { return cbb_add_u(cbb, value, 4); }
int CBB_add_u32le(CBB *cbb, uint32_t value) {
return CBB_add_u32(cbb, CRYPTO_bswap4(value));
}
int CBB_add_u64(CBB *cbb, uint64_t value) {
return cbb_add_u(cbb, value, 8);
}
int CBB_add_u64(CBB *cbb, uint64_t value) { return cbb_add_u(cbb, value, 8); }
int CBB_add_u64le(CBB *cbb, uint64_t value) {
return CBB_add_u64(cbb, CRYPTO_bswap8(value));
@@ -501,13 +487,13 @@ int CBB_add_asn1_uint64(CBB *cbb, uint64_t value) {
int CBB_add_asn1_uint64_with_tag(CBB *cbb, uint64_t value, CBS_ASN1_TAG tag) {
CBB child;
int started = 0;
if (!CBB_add_asn1(cbb, &child, tag)) {
goto err;
}
int started = 0;
for (size_t i = 0; i < 8; i++) {
uint8_t byte = (value >> 8*(7-i)) & 0xff;
uint8_t byte = (value >> 8 * (7 - i)) & 0xff;
if (!started) {
if (byte == 0) {
// Don't encode leading zeros.
@@ -573,8 +559,7 @@ err:
int CBB_add_asn1_octet_string(CBB *cbb, const uint8_t *data, size_t data_len) {
CBB child;
if (!CBB_add_asn1(cbb, &child, CBS_ASN1_OCTETSTRING) ||
!CBB_add_bytes(&child, data, data_len) ||
!CBB_flush(cbb)) {
!CBB_add_bytes(&child, data, data_len) || !CBB_flush(cbb)) {
cbb_on_error(cbb);
return 0;
}
@@ -585,8 +570,7 @@ int CBB_add_asn1_octet_string(CBB *cbb, const uint8_t *data, size_t data_len) {
int CBB_add_asn1_bool(CBB *cbb, int value) {
CBB child;
if (!CBB_add_asn1(cbb, &child, CBS_ASN1_BOOLEAN) ||
!CBB_add_u8(&child, value != 0 ? 0xff : 0) ||
!CBB_flush(cbb)) {
!CBB_add_u8(&child, value != 0 ? 0xff : 0) || !CBB_flush(cbb)) {
cbb_on_error(cbb);
return 0;
}
@@ -620,24 +604,20 @@ int CBB_add_asn1_oid_from_text(CBB *cbb, const char *text, size_t len) {
// OIDs must have at least two components.
uint64_t a, b;
if (!parse_dotted_decimal(&cbs, &a) ||
!parse_dotted_decimal(&cbs, &b)) {
if (!parse_dotted_decimal(&cbs, &a) || !parse_dotted_decimal(&cbs, &b)) {
return 0;
}
// The first component is encoded as 40 * |a| + |b|. This assumes that |a| is
// 0, 1, or 2 and that, when it is 0 or 1, |b| is at most 39.
if (a > 2 ||
(a < 2 && b > 39) ||
b > UINT64_MAX - 80 ||
if (a > 2 || (a < 2 && b > 39) || b > UINT64_MAX - 80 ||
!add_base128_integer(cbb, 40u * a + b)) {
return 0;
}
// The remaining components are encoded unmodified.
while (CBS_len(&cbs) > 0) {
if (!parse_dotted_decimal(&cbs, &a) ||
!add_base128_integer(cbb, a)) {
if (!parse_dotted_decimal(&cbs, &a) || !add_base128_integer(cbb, a)) {
return 0;
}
}
@@ -648,7 +628,8 @@ int CBB_add_asn1_oid_from_text(CBB *cbb, const char *text, size_t len) {
static int compare_set_of_element(const void *a_ptr, const void *b_ptr) {
// See X.690, section 11.6 for the ordering. They are sorted in ascending
// order by their DER encoding.
const CBS *a = a_ptr, *b = b_ptr;
const CBS *a = reinterpret_cast<const CBS *>(a_ptr),
*b = reinterpret_cast<const CBS *>(b_ptr);
size_t a_len = CBS_len(a), b_len = CBS_len(b);
size_t min_len = a_len < b_len ? a_len : b_len;
int ret = OPENSSL_memcmp(CBS_data(a), CBS_data(b), min_len);
@@ -687,8 +668,12 @@ int CBB_flush_asn1_set_of(CBB *cbb) {
// remain valid as we rewrite |cbb|.
int ret = 0;
size_t buf_len = CBB_len(cbb);
uint8_t *buf = OPENSSL_memdup(CBB_data(cbb), buf_len);
CBS *children = OPENSSL_calloc(num_children, sizeof(CBS));
uint8_t *buf =
reinterpret_cast<uint8_t *>(OPENSSL_memdup(CBB_data(cbb), buf_len));
CBS *children =
reinterpret_cast<CBS *>(OPENSSL_calloc(num_children, sizeof(CBS)));
uint8_t *out;
size_t offset = 0;
if (buf == NULL || children == NULL) {
goto err;
}
@@ -701,8 +686,7 @@ int CBB_flush_asn1_set_of(CBB *cbb) {
qsort(children, num_children, sizeof(CBS), compare_set_of_element);
// Write the contents back in the new order.
uint8_t *out = (uint8_t *)CBB_data(cbb);
size_t offset = 0;
out = (uint8_t *)CBB_data(cbb);
for (size_t i = 0; i < num_children; i++) {
OPENSSL_memcpy(out + offset, CBS_data(&children[i]), CBS_len(&children[i]));
offset += CBS_len(&children[i]);
@@ -50,7 +50,7 @@ int CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len) {
if (cbs->len == 0) {
return 1;
}
*out_ptr = OPENSSL_memdup(cbs->data, cbs->len);
*out_ptr = reinterpret_cast<uint8_t *>(OPENSSL_memdup(cbs->data, cbs->len));
if (*out_ptr == NULL) {
return 0;
}
@@ -62,7 +62,7 @@ int CBS_strdup(const CBS *cbs, char **out_ptr) {
if (*out_ptr != NULL) {
OPENSSL_free(*out_ptr);
}
*out_ptr = OPENSSL_strndup((const char*)cbs->data, cbs->len);
*out_ptr = OPENSSL_strndup((const char *)cbs->data, cbs->len);
return (*out_ptr != NULL);
}
@@ -144,9 +144,7 @@ int CBS_get_u32le(CBS *cbs, uint32_t *out) {
return 1;
}
int CBS_get_u64(CBS *cbs, uint64_t *out) {
return cbs_get_u(cbs, out, 8);
}
int CBS_get_u64(CBS *cbs, uint64_t *out) { return cbs_get_u(cbs, out, 8); }
int CBS_get_u64le(CBS *cbs, uint64_t *out) {
if (!cbs_get_u(cbs, out, 8)) {
@@ -207,7 +205,8 @@ int CBS_get_u24_length_prefixed(CBS *cbs, CBS *out) {
}
int CBS_get_until_first(CBS *cbs, CBS *out, uint8_t c) {
const uint8_t *split = OPENSSL_memchr(CBS_data(cbs), c, CBS_len(cbs));
const uint8_t *split = reinterpret_cast<const uint8_t *>(
OPENSSL_memchr(CBS_data(cbs), c, CBS_len(cbs)));
if (split == NULL) {
return 0;
}
@@ -223,7 +222,7 @@ int CBS_get_u64_decimal(CBS *cbs, uint64_t *out) {
break;
}
CBS_skip(cbs, 1);
if (// Forbid stray leading zeros.
if (/* Forbid stray leading zeros */
(v == 0 && seen_digit) ||
// Check for overflow.
v > UINT64_MAX / 10 || //
@@ -341,7 +340,7 @@ static int cbs_get_any_asn1_element(CBS *cbs, CBS *out, CBS_ASN1_TAG *out_tag,
// 8.1.3.
if ((length_byte & 0x80) == 0) {
// Short form length.
len = ((size_t) length_byte) + header_len;
len = ((size_t)length_byte) + header_len;
if (out_header_len != NULL) {
*out_header_len = header_len;
}
@@ -420,7 +419,7 @@ int CBS_get_any_asn1(CBS *cbs, CBS *out, CBS_ASN1_TAG *out_tag) {
}
int CBS_get_any_asn1_element(CBS *cbs, CBS *out, CBS_ASN1_TAG *out_tag,
size_t *out_header_len) {
size_t *out_header_len) {
return cbs_get_any_asn1_element(cbs, out, out_tag, out_header_len, NULL, NULL,
/*ber_ok=*/0);
}
@@ -515,8 +514,7 @@ int CBS_get_asn1_int64(CBS *cbs, int64_t *out) {
int CBS_get_asn1_bool(CBS *cbs, int *out) {
CBS bytes;
if (!CBS_get_asn1(cbs, &bytes, CBS_ASN1_BOOLEAN) ||
CBS_len(&bytes) != 1) {
if (!CBS_get_asn1(cbs, &bytes, CBS_ASN1_BOOLEAN) || CBS_len(&bytes) != 1) {
return 0;
}
@@ -529,7 +527,8 @@ int CBS_get_asn1_bool(CBS *cbs, int *out) {
return 1;
}
int CBS_get_optional_asn1(CBS *cbs, CBS *out, int *out_present, CBS_ASN1_TAG tag) {
int CBS_get_optional_asn1(CBS *cbs, CBS *out, int *out_present,
CBS_ASN1_TAG tag) {
int present = 0;
if (CBS_peek_asn1_tag(cbs, tag)) {
@@ -576,8 +575,7 @@ int CBS_get_optional_asn1_uint64(CBS *cbs, uint64_t *out, CBS_ASN1_TAG tag,
return 0;
}
if (present) {
if (!CBS_get_asn1_uint64(&child, out) ||
CBS_len(&child) != 0) {
if (!CBS_get_asn1_uint64(&child, out) || CBS_len(&child) != 0) {
return 0;
}
} else {
@@ -597,8 +595,7 @@ int CBS_get_optional_asn1_bool(CBS *cbs, int *out, CBS_ASN1_TAG tag,
uint8_t boolean;
if (!CBS_get_asn1(&child, &child2, CBS_ASN1_BOOLEAN) ||
CBS_len(&child2) != 1 ||
CBS_len(&child) != 0) {
CBS_len(&child2) != 1 || CBS_len(&child) != 0) {
return 0;
}
@@ -619,8 +616,7 @@ int CBS_get_optional_asn1_bool(CBS *cbs, int *out, CBS_ASN1_TAG tag,
int CBS_is_valid_asn1_bitstring(const CBS *cbs) {
CBS in = *cbs;
uint8_t num_unused_bits;
if (!CBS_get_u8(&in, &num_unused_bits) ||
num_unused_bits > 7) {
if (!CBS_get_u8(&in, &num_unused_bits) || num_unused_bits > 7) {
return 0;
}
@@ -707,12 +703,12 @@ int CBS_is_valid_asn1_oid(const CBS *cbs) {
}
char *CBS_asn1_oid_to_text(const CBS *cbs) {
CBS copy = *cbs;
CBB cbb;
if (!CBB_init(&cbb, 32)) {
goto err;
}
CBS copy = *cbs;
// The first component is 40 * value1 + value2, where value1 is 0, 1, or 2.
uint64_t v;
if (!parse_base128_integer(&copy, &v)) {
@@ -724,15 +720,13 @@ char *CBS_asn1_oid_to_text(const CBS *cbs) {
!add_decimal(&cbb, v - 80)) {
goto err;
}
} else if (!add_decimal(&cbb, v / 40) ||
!CBB_add_u8(&cbb, '.') ||
} else if (!add_decimal(&cbb, v / 40) || !CBB_add_u8(&cbb, '.') ||
!add_decimal(&cbb, v % 40)) {
goto err;
}
while (CBS_len(&copy) != 0) {
if (!parse_base128_integer(&copy, &v) ||
!CBB_add_u8(&cbb, '.') ||
if (!parse_base128_integer(&copy, &v) || !CBB_add_u8(&cbb, '.') ||
!add_decimal(&cbb, v)) {
goto err;
}
@@ -740,8 +734,7 @@ char *CBS_asn1_oid_to_text(const CBS *cbs) {
uint8_t *txt;
size_t txt_len;
if (!CBB_add_u8(&cbb, '\0') ||
!CBB_finish(&cbb, &txt, &txt_len)) {
if (!CBB_add_u8(&cbb, '\0') || !CBB_finish(&cbb, &txt, &txt_len)) {
goto err;
}
@@ -814,7 +807,7 @@ static int CBS_parse_rfc5280_time_internal(const CBS *cbs, int is_gentime,
if (!cbs_get_two_digits(&copy, &tmp)) {
return 0;
}
year += tmp;
year += tmp;
} else {
year = 1900;
if (!cbs_get_two_digits(&copy, &tmp)) {
@@ -36,7 +36,7 @@
// Optimised AES-GCM-SIV
struct aead_aes_gcm_siv_asm_ctx {
alignas(16) uint8_t key[16*15];
alignas(16) uint8_t key[16 * 15];
int is_128_bit;
};
@@ -57,15 +57,17 @@ static struct aead_aes_gcm_siv_asm_ctx *asm_ctx_from_ctx(
return (struct aead_aes_gcm_siv_asm_ctx *)(&ctx->state.opaque[offset]);
}
extern "C" {
// aes128gcmsiv_aes_ks writes an AES-128 key schedule for |key| to
// |out_expanded_key|.
extern void aes128gcmsiv_aes_ks(
const uint8_t key[16], uint8_t out_expanded_key[16*15]);
extern void aes128gcmsiv_aes_ks(const uint8_t key[16],
uint8_t out_expanded_key[16 * 15]);
// aes256gcmsiv_aes_ks writes an AES-256 key schedule for |key| to
// |out_expanded_key|.
extern void aes256gcmsiv_aes_ks(
const uint8_t key[32], uint8_t out_expanded_key[16*15]);
extern void aes256gcmsiv_aes_ks(const uint8_t key[32],
uint8_t out_expanded_key[16 * 15]);
}
static int aead_aes_gcm_siv_asm_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
size_t key_len, size_t tag_len) {
@@ -103,6 +105,7 @@ static int aead_aes_gcm_siv_asm_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
static void aead_aes_gcm_siv_asm_cleanup(EVP_AEAD_CTX *ctx) {}
extern "C" {
// aesgcmsiv_polyval_horner updates the POLYVAL value in |in_out_poly| to
// include a number (|in_blocks|) of 16-byte blocks of data from |in|, given
// the POLYVAL key in |key|.
@@ -217,6 +220,7 @@ extern void aes256gcmsiv_enc_msg_x8(const uint8_t *in, uint8_t *out,
const uint8_t *tag,
const struct aead_aes_gcm_siv_asm_ctx *key,
size_t in_len);
}
// gcm_siv_asm_polyval evaluates POLYVAL at |auth_key| on the given plaintext
// and AD. The result is written to |out_tag|.
@@ -228,7 +232,7 @@ static void gcm_siv_asm_polyval(uint8_t out_tag[16], const uint8_t *in,
const size_t ad_blocks = ad_len / 16;
const size_t in_blocks = in_len / 16;
int htable_init = 0;
alignas(16) uint8_t htable[16*8];
alignas(16) uint8_t htable[16 * 8];
if (ad_blocks > 8 || in_blocks > 8) {
htable_init = 1;
@@ -335,8 +339,7 @@ static int aead_aes_gcm_siv_asm_seal_scatter(
const uint64_t in_len_64 = in_len;
const uint64_t ad_len_64 = ad_len;
if (in_len_64 > (UINT64_C(1) << 36) ||
ad_len_64 >= (UINT64_C(1) << 61)) {
if (in_len_64 > (UINT64_C(1) << 36) || ad_len_64 >= (UINT64_C(1) << 61)) {
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TOO_LARGE);
return 0;
}
@@ -424,9 +427,9 @@ static int aead_aes_gcm_siv_asm_open_gather(
struct aead_aes_gcm_siv_asm_ctx expanded_key;
if (gcm_siv_ctx->is_128_bit) {
aes128gcmsiv_aes_ks((const uint8_t *) record_enc_key, &expanded_key.key[0]);
aes128gcmsiv_aes_ks((const uint8_t *)record_enc_key, &expanded_key.key[0]);
} else {
aes256gcmsiv_aes_ks((const uint8_t *) record_enc_key, &expanded_key.key[0]);
aes256gcmsiv_aes_ks((const uint8_t *)record_enc_key, &expanded_key.key[0]);
}
// calculated_tag is 16*8 bytes, rather than 16 bytes, because
// aes[128|256]gcmsiv_dec uses the extra as scratch space.
@@ -535,7 +538,7 @@ struct aead_aes_gcm_siv_ctx {
AES_KEY ks;
} ks;
block128_f kgk_block;
unsigned is_256:1;
unsigned is_256 : 1;
};
static_assert(sizeof(((EVP_AEAD_CTX *)NULL)->state) >=
@@ -635,8 +638,8 @@ static void gcm_siv_polyval(
}
uint8_t length_block[16];
CRYPTO_store_u64_le(length_block, ((uint64_t) ad_len) * 8);
CRYPTO_store_u64_le(length_block + 8, ((uint64_t) in_len) * 8);
CRYPTO_store_u64_le(length_block, ((uint64_t)ad_len) * 8);
CRYPTO_store_u64_le(length_block + 8, ((uint64_t)in_len) * 8);
CRYPTO_POLYVAL_update_blocks(&polyval_ctx, length_block,
sizeof(length_block));
@@ -659,10 +662,9 @@ struct gcm_siv_record_keys {
// gcm_siv_keys calculates the keys for a specific GCM-SIV record with the
// given nonce and writes them to |*out_keys|.
static void gcm_siv_keys(
const struct aead_aes_gcm_siv_ctx *gcm_siv_ctx,
struct gcm_siv_record_keys *out_keys,
const uint8_t nonce[EVP_AEAD_AES_GCM_SIV_NONCE_LEN]) {
static void gcm_siv_keys(const struct aead_aes_gcm_siv_ctx *gcm_siv_ctx,
struct gcm_siv_record_keys *out_keys,
const uint8_t nonce[EVP_AEAD_AES_GCM_SIV_NONCE_LEN]) {
const AES_KEY *const key = &gcm_siv_ctx->ks.ks;
uint8_t key_material[(128 /* POLYVAL key */ + 256 /* max AES key */) / 8];
const size_t blocks_needed = gcm_siv_ctx->is_256 ? 6 : 4;
@@ -703,8 +705,7 @@ static int aead_aes_gcm_siv_seal_scatter(
const uint64_t ad_len_64 = ad_len;
if (in_len + EVP_AEAD_AES_GCM_SIV_TAG_LEN < in_len ||
in_len_64 > (UINT64_C(1) << 36) ||
ad_len_64 >= (UINT64_C(1) << 61)) {
in_len_64 > (UINT64_C(1) << 36) || ad_len_64 >= (UINT64_C(1) << 61)) {
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TOO_LARGE);
return 0;
}
@@ -830,12 +831,8 @@ const EVP_AEAD *EVP_aead_aes_256_gcm_siv(void) {
#else
const EVP_AEAD *EVP_aead_aes_128_gcm_siv(void) {
return &aead_aes_128_gcm_siv;
}
const EVP_AEAD *EVP_aead_aes_128_gcm_siv(void) { return &aead_aes_128_gcm_siv; }
const EVP_AEAD *EVP_aead_aes_256_gcm_siv(void) {
return &aead_aes_256_gcm_siv;
}
const EVP_AEAD *EVP_aead_aes_256_gcm_siv(void) { return &aead_aes_256_gcm_siv; }
#endif // AES_GCM_SIV_ASM
@@ -85,14 +85,16 @@ static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
}
static const EVP_CIPHER evp_des_cbc = {
.nid = NID_des_cbc,
.block_size = 8,
.key_len = 8,
.iv_len = 8,
.ctx_size = sizeof(EVP_DES_KEY),
.flags = EVP_CIPH_CBC_MODE,
.init = des_init_key,
.cipher = des_cbc_cipher,
/*nid=*/NID_des_cbc,
/*block_size=*/8,
/*key_len=*/8,
/*iv_len=*/8,
/*ctx_size=*/sizeof(EVP_DES_KEY),
/*flags=*/EVP_CIPH_CBC_MODE,
/*init=*/des_init_key,
/*cipher=*/des_cbc_cipher,
/*cleanup=*/nullptr,
/*ctrl=*/nullptr,
};
const EVP_CIPHER *EVP_des_cbc(void) { return &evp_des_cbc; }
@@ -112,14 +114,16 @@ static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
}
static const EVP_CIPHER evp_des_ecb = {
.nid = NID_des_ecb,
.block_size = 8,
.key_len = 8,
.iv_len = 0,
.ctx_size = sizeof(EVP_DES_KEY),
.flags = EVP_CIPH_ECB_MODE,
.init = des_init_key,
.cipher = des_ecb_cipher,
/*nid=*/NID_des_ecb,
/*block_size=*/8,
/*key_len=*/8,
/*iv_len=*/0,
/*ctx_size=*/sizeof(EVP_DES_KEY),
/*flags=*/EVP_CIPH_ECB_MODE,
/*init=*/des_init_key,
/*cipher=*/des_ecb_cipher,
/*cleanup=*/nullptr,
/*ctrl=*/nullptr,
};
const EVP_CIPHER *EVP_des_ecb(void) { return &evp_des_ecb; }
@@ -149,14 +153,16 @@ static int des_ede3_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
}
static const EVP_CIPHER evp_des_ede3_cbc = {
.nid = NID_des_ede3_cbc,
.block_size = 8,
.key_len = 24,
.iv_len = 8,
.ctx_size = sizeof(DES_EDE_KEY),
.flags = EVP_CIPH_CBC_MODE,
.init = des_ede3_init_key,
.cipher = des_ede3_cbc_cipher,
/*nid=*/NID_des_ede3_cbc,
/*block_size=*/8,
/*key_len=*/24,
/*iv_len=*/8,
/*ctx_size=*/sizeof(DES_EDE_KEY),
/*flags=*/EVP_CIPH_CBC_MODE,
/*init=*/des_ede3_init_key,
/*cipher=*/des_ede3_cbc_cipher,
/*cleanup=*/nullptr,
/*ctrl=*/nullptr,
};
const EVP_CIPHER *EVP_des_ede3_cbc(void) { return &evp_des_ede3_cbc; }
@@ -172,14 +178,16 @@ static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
}
static const EVP_CIPHER evp_des_ede_cbc = {
.nid = NID_des_ede_cbc,
.block_size = 8,
.key_len = 16,
.iv_len = 8,
.ctx_size = sizeof(DES_EDE_KEY),
.flags = EVP_CIPH_CBC_MODE,
.init = des_ede_init_key,
.cipher = des_ede3_cbc_cipher,
/*nid=*/NID_des_ede_cbc,
/*block_size=*/8,
/*key_len=*/16,
/*iv_len=*/8,
/*ctx_size=*/sizeof(DES_EDE_KEY),
/*flags=*/EVP_CIPH_CBC_MODE,
/*init=*/des_ede_init_key,
/*cipher=*/des_ede3_cbc_cipher,
/*cleanup=*/nullptr,
/*ctrl=*/nullptr,
};
const EVP_CIPHER *EVP_des_ede_cbc(void) { return &evp_des_ede_cbc; }
@@ -191,7 +199,7 @@ static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
}
in_len -= ctx->cipher->block_size;
DES_EDE_KEY *dat = (DES_EDE_KEY *) ctx->cipher_data;
DES_EDE_KEY *dat = (DES_EDE_KEY *)ctx->cipher_data;
for (size_t i = 0; i <= in_len; i += ctx->cipher->block_size) {
DES_ecb3_encrypt_ex(in + i, out + i, &dat->ks.ks[0], &dat->ks.ks[1],
&dat->ks.ks[2], ctx->encrypt);
@@ -200,27 +208,31 @@ static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
}
static const EVP_CIPHER evp_des_ede = {
.nid = NID_des_ede_ecb,
.block_size = 8,
.key_len = 16,
.iv_len = 0,
.ctx_size = sizeof(DES_EDE_KEY),
.flags = EVP_CIPH_ECB_MODE,
.init = des_ede_init_key,
.cipher = des_ede_ecb_cipher,
/*nid=*/NID_des_ede_ecb,
/*block_size=*/8,
/*key_len=*/16,
/*iv_len=*/0,
/*ctx_size=*/sizeof(DES_EDE_KEY),
/*flags=*/EVP_CIPH_ECB_MODE,
/*init=*/des_ede_init_key,
/*cipher=*/des_ede_ecb_cipher,
/*cleanup=*/nullptr,
/*ctrl=*/nullptr,
};
const EVP_CIPHER *EVP_des_ede(void) { return &evp_des_ede; }
static const EVP_CIPHER evp_des_ede3 = {
.nid = NID_des_ede3_ecb,
.block_size = 8,
.key_len = 24,
.iv_len = 0,
.ctx_size = sizeof(DES_EDE_KEY),
.flags = EVP_CIPH_ECB_MODE,
.init = des_ede3_init_key,
.cipher = des_ede_ecb_cipher,
/*nid=*/NID_des_ede3_ecb,
/*block_size=*/8,
/*key_len=*/24,
/*iv_len=*/0,
/*ctx_size=*/sizeof(DES_EDE_KEY),
/*flags=*/EVP_CIPH_ECB_MODE,
/*init=*/des_ede3_init_key,
/*cipher=*/des_ede_ecb_cipher,
/*cleanup=*/nullptr,
/*ctrl=*/nullptr,
};
const EVP_CIPHER *EVP_des_ede3(void) { return &evp_des_ede3; }
@@ -69,8 +69,8 @@ static int null_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
return 1;
}
static int null_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
const uint8_t *in, size_t in_len) {
static int null_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
size_t in_len) {
if (in != out) {
OPENSSL_memcpy(out, in, in_len);
}
@@ -78,13 +78,16 @@ static int null_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
}
static const EVP_CIPHER n_cipher = {
.nid = NID_undef,
.block_size = 1,
.key_len = 0,
.iv_len = 0,
.ctx_size = 0,
.init = null_init_key,
.cipher = null_cipher,
/*nid=*/NID_undef,
/*block_size=*/1,
/*key_len=*/0,
/*iv_len=*/0,
/*ctx_size=*/0,
/*flags=*/0,
/*init=*/null_init_key,
/*cipher=*/null_cipher,
/*cleanup=*/nullptr,
/*ctrl=*/nullptr,
};
const EVP_CIPHER *EVP_enc_null(void) { return &n_cipher; }
@@ -138,7 +138,9 @@
} \
} while (0)
typedef struct rc2_key_st { uint16_t data[64]; } RC2_KEY;
typedef struct rc2_key_st {
uint16_t data[64];
} RC2_KEY;
static void RC2_encrypt(uint32_t *d, RC2_KEY *key) {
int i, n;
@@ -427,29 +429,31 @@ static int rc2_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) {
}
static const EVP_CIPHER rc2_40_cbc = {
.nid = NID_rc2_40_cbc,
.block_size = 8,
.key_len = 5 /* 40 bit */,
.iv_len = 8,
.ctx_size = sizeof(EVP_RC2_KEY),
.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
.init = rc2_init_key,
.cipher = rc2_cbc_cipher,
.ctrl = rc2_ctrl,
/*nid=*/NID_rc2_40_cbc,
/*block_size=*/8,
/*key_len=*/5 /* 40 bit */,
/*iv_len=*/8,
/*ctx_size=*/sizeof(EVP_RC2_KEY),
/*flags=*/EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
/*init=*/rc2_init_key,
/*cipher=*/rc2_cbc_cipher,
/*cleanup=*/nullptr,
/*ctrl=*/rc2_ctrl,
};
const EVP_CIPHER *EVP_rc2_40_cbc(void) { return &rc2_40_cbc; }
static const EVP_CIPHER rc2_cbc = {
.nid = NID_rc2_cbc,
.block_size = 8,
.key_len = 16 /* 128 bit */,
.iv_len = 8,
.ctx_size = sizeof(EVP_RC2_KEY),
.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
.init = rc2_init_key,
.cipher = rc2_cbc_cipher,
.ctrl = rc2_ctrl,
/*nid=*/NID_rc2_cbc,
/*block_size=*/8,
/*key_len=*/16 /* 128 bit */,
/*iv_len=*/8,
/*ctx_size=*/sizeof(EVP_RC2_KEY),
/*flags=*/EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
/*init=*/rc2_init_key,
/*cipher=*/rc2_cbc_cipher,
/*cleanup=*/nullptr,
/*ctrl=*/rc2_ctrl,
};
const EVP_CIPHER *EVP_rc2_cbc(void) { return &rc2_cbc; }
@@ -81,14 +81,16 @@ static int rc4_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
}
static const EVP_CIPHER rc4 = {
.nid = NID_rc4,
.block_size = 1,
.key_len = 16,
.iv_len = 0,
.ctx_size = sizeof(RC4_KEY),
.flags = EVP_CIPH_VARIABLE_LENGTH,
.init = rc4_init_key,
.cipher = rc4_cipher,
/*nid=*/NID_rc4,
/*block_size=*/1,
/*key_len=*/16,
/*iv_len=*/0,
/*ctx_size=*/sizeof(RC4_KEY),
/*flags=*/EVP_CIPH_VARIABLE_LENGTH,
/*init=*/rc4_init_key,
/*cipher=*/rc4_cipher,
/*cleanup=*/nullptr,
/*ctrl=*/nullptr,
};
const EVP_CIPHER *EVP_rc4(void) { return &rc4; }
@@ -57,8 +57,8 @@
#include <CCryptoBoringSSL_conf.h>
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <string.h>
#include <CCryptoBoringSSL_bio.h>
#include <CCryptoBoringSSL_buf.h>
@@ -66,8 +66,8 @@
#include <CCryptoBoringSSL_lhash.h>
#include <CCryptoBoringSSL_mem.h>
#include "internal.h"
#include "../internal.h"
#include "internal.h"
struct conf_section_st {
@@ -106,7 +106,7 @@ CONF *NCONF_new(void *method) {
return NULL;
}
CONF *conf = OPENSSL_malloc(sizeof(CONF));
CONF *conf = reinterpret_cast<CONF *>(OPENSSL_malloc(sizeof(CONF)));
if (conf == NULL) {
return NULL;
}
@@ -121,7 +121,9 @@ CONF *NCONF_new(void *method) {
return conf;
}
CONF_VALUE *CONF_VALUE_new(void) { return OPENSSL_zalloc(sizeof(CONF_VALUE)); }
CONF_VALUE *CONF_VALUE_new(void) {
return reinterpret_cast<CONF_VALUE *>(OPENSSL_zalloc(sizeof(CONF_VALUE)));
}
static void value_free(CONF_VALUE *value) {
if (value == NULL) {
@@ -161,7 +163,8 @@ void NCONF_free(CONF *conf) {
}
static CONF_SECTION *NCONF_new_section(const CONF *conf, const char *section) {
CONF_SECTION *s = OPENSSL_malloc(sizeof(CONF_SECTION));
CONF_SECTION *s =
reinterpret_cast<CONF_SECTION *>(OPENSSL_malloc(sizeof(CONF_SECTION)));
if (!s) {
return NULL;
}
@@ -275,10 +278,10 @@ err:
}
static CONF_SECTION *get_section(const CONF *conf, const char *section) {
CONF_SECTION template;
OPENSSL_memset(&template, 0, sizeof(template));
template.name = (char *) section;
return lh_CONF_SECTION_retrieve(conf->sections, &template);
CONF_SECTION templ;
OPENSSL_memset(&templ, 0, sizeof(templ));
templ.name = (char *)section;
return lh_CONF_SECTION_retrieve(conf->sections, &templ);
}
const STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,
@@ -292,16 +295,16 @@ const STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,
const char *NCONF_get_string(const CONF *conf, const char *section,
const char *name) {
CONF_VALUE template, *value;
CONF_VALUE templ, *value;
if (section == NULL) {
section = kDefaultSectionName;
}
OPENSSL_memset(&template, 0, sizeof(template));
template.section = (char *)section;
template.name = (char *)name;
value = lh_CONF_VALUE_retrieve(conf->values, &template);
OPENSSL_memset(&templ, 0, sizeof(templ));
templ.section = (char *)section;
templ.name = (char *)name;
value = lh_CONF_VALUE_retrieve(conf->values, &templ);
if (value == NULL) {
return NULL;
}
@@ -14,8 +14,8 @@
#include "internal.h"
#if defined(OPENSSL_ARM) && defined(OPENSSL_FREEBSD) && \
!defined(OPENSSL_STATIC_ARMCAP)
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_ARM) && \
defined(OPENSSL_FREEBSD) && !defined(OPENSSL_STATIC_ARMCAP)
#include <sys/auxv.h>
#include <sys/types.h>
@@ -14,8 +14,8 @@
#include "internal.h"
#if defined(OPENSSL_ARM) && defined(OPENSSL_LINUX) && \
!defined(OPENSSL_STATIC_ARMCAP)
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_ARM) && \
defined(OPENSSL_LINUX) && !defined(OPENSSL_STATIC_ARMCAP)
#include <errno.h>
#include <fcntl.h>
#include <sys/auxv.h>
@@ -55,7 +55,7 @@ static int read_file(char **out_ptr, size_t *out_len, const char *path) {
static const size_t kReadSize = 1024;
int ret = 0;
size_t cap = kReadSize, len = 0;
char *buf = OPENSSL_malloc(cap);
char *buf = reinterpret_cast<char *>(OPENSSL_malloc(cap));
if (buf == NULL) {
goto err;
}
@@ -66,7 +66,7 @@ static int read_file(char **out_ptr, size_t *out_len, const char *path) {
if (new_cap < cap) {
goto err;
}
char *new_buf = OPENSSL_realloc(buf, new_cap);
char *new_buf = reinterpret_cast<char *>(OPENSSL_realloc(buf, new_cap));
if (new_buf == NULL) {
goto err;
}
@@ -56,7 +56,8 @@
#include <CCryptoBoringSSL_base.h>
#if !defined(OPENSSL_NO_ASM) && (defined(OPENSSL_X86) || defined(OPENSSL_X86_64))
#if !defined(OPENSSL_NO_ASM) && \
(defined(OPENSSL_X86) || defined(OPENSSL_X86_64))
#include <inttypes.h>
#include <stdio.h>
@@ -88,21 +89,19 @@ static void OPENSSL_cpuid(uint32_t *out_eax, uint32_t *out_ebx,
#elif defined(__pic__) && defined(OPENSSL_32_BIT)
// Inline assembly may not clobber the PIC register. For 32-bit, this is EBX.
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47602.
__asm__ volatile (
"xor %%ecx, %%ecx\n"
"mov %%ebx, %%edi\n"
"cpuid\n"
"xchg %%edi, %%ebx\n"
: "=a"(*out_eax), "=D"(*out_ebx), "=c"(*out_ecx), "=d"(*out_edx)
: "a"(leaf)
);
__asm__ volatile(
"xor %%ecx, %%ecx\n"
"mov %%ebx, %%edi\n"
"cpuid\n"
"xchg %%edi, %%ebx\n"
: "=a"(*out_eax), "=D"(*out_ebx), "=c"(*out_ecx), "=d"(*out_edx)
: "a"(leaf));
#else
__asm__ volatile (
"xor %%ecx, %%ecx\n"
"cpuid\n"
: "=a"(*out_eax), "=b"(*out_ebx), "=c"(*out_ecx), "=d"(*out_edx)
: "a"(leaf)
);
__asm__ volatile(
"xor %%ecx, %%ecx\n"
"cpuid\n"
: "=a"(*out_eax), "=b"(*out_ebx), "=c"(*out_ecx), "=d"(*out_edx)
: "a"(leaf));
#endif
}
@@ -113,7 +112,7 @@ static uint64_t OPENSSL_xgetbv(uint32_t xcr) {
return (uint64_t)_xgetbv(xcr);
#else
uint32_t eax, edx;
__asm__ volatile ("xgetbv" : "=a"(eax), "=d"(edx) : "c"(xcr));
__asm__ volatile("xgetbv" : "=a"(eax), "=d"(edx) : "c"(xcr));
return (((uint64_t)edx) << 32) | eax;
#endif
}
@@ -121,27 +120,27 @@ static uint64_t OPENSSL_xgetbv(uint32_t xcr) {
// handle_cpu_env applies the value from |in| to the CPUID values in |out[0]|
// and |out[1]|. See the comment in |OPENSSL_cpuid_setup| about this.
static void handle_cpu_env(uint32_t *out, const char *in) {
const int invert = in[0] == '~';
const int or = in[0] == '|';
const int skip_first_byte = invert || or;
const int hex = in[skip_first_byte] == '0' && in[skip_first_byte+1] == 'x';
const int invert_op = in[0] == '~';
const int or_op = in[0] == '|';
const int skip_first_byte = invert_op || or_op;
const int hex = in[skip_first_byte] == '0' && in[skip_first_byte + 1] == 'x';
int sscanf_result;
uint64_t v;
if (hex) {
sscanf_result = sscanf(in + invert + 2, "%" PRIx64, &v);
sscanf_result = sscanf(in + invert_op + 2, "%" PRIx64, &v);
} else {
sscanf_result = sscanf(in + invert, "%" PRIu64, &v);
sscanf_result = sscanf(in + invert_op, "%" PRIu64, &v);
}
if (!sscanf_result) {
return;
}
if (invert) {
if (invert_op) {
out[0] &= ~v;
out[1] &= ~(v >> 32);
} else if (or) {
} else if (or_op) {
out[0] |= v;
out[1] |= (v >> 32);
} else {
@@ -157,11 +156,11 @@ void OPENSSL_cpuid_setup(void) {
uint32_t num_ids = eax;
int is_intel = ebx == 0x756e6547 /* Genu */ &&
edx == 0x49656e69 /* ineI */ &&
int is_intel = ebx == 0x756e6547 /* Genu */ && //
edx == 0x49656e69 /* ineI */ && //
ecx == 0x6c65746e /* ntel */;
int is_amd = ebx == 0x68747541 /* Auth */ &&
edx == 0x69746e65 /* enti */ &&
int is_amd = ebx == 0x68747541 /* Auth */ && //
edx == 0x69746e65 /* enti */ && //
ecx == 0x444d4163 /* cAMD */;
uint32_t extended_features[2] = {0};
@@ -225,9 +224,9 @@ void OPENSSL_cpuid_setup(void) {
// See Intel manual, volume 1, section 14.3.
if ((xcr0 & 6) != 6) {
// YMM registers cannot be used.
ecx &= ~(1u << 28); // AVX
ecx &= ~(1u << 12); // FMA
ecx &= ~(1u << 11); // AMD XOP
ecx &= ~(1u << 28); // AVX
ecx &= ~(1u << 12); // FMA
ecx &= ~(1u << 11); // AMD XOP
extended_features[0] &= ~(1u << 5); // AVX2
extended_features[1] &= ~(1u << 9); // VAES
extended_features[1] &= ~(1u << 10); // VPCLMULQDQ
@@ -17,8 +17,8 @@
#include <assert.h>
#include <stdio.h>
#include "fipsmodule/rand/internal.h"
#include "bcm_support.h"
#include "fipsmodule/rand/internal.h"
#include "internal.h"
@@ -132,14 +132,6 @@ int CRYPTO_is_confidential_build(void) {
#endif
}
int CRYPTO_has_asm(void) {
#if defined(OPENSSL_NO_ASM)
return 0;
#else
return 1;
#endif
}
void CRYPTO_pre_sandbox_init(void) {
// Read from /proc/cpuinfo if needed.
OPENSSL_init_cpuid();
@@ -26,8 +26,8 @@
#include <CCryptoBoringSSL_rand.h>
#include <CCryptoBoringSSL_sha.h>
#include "internal.h"
#include "../internal.h"
#include "internal.h"
// Various pre-computed constants.
#include "./curve25519_tables.h"
@@ -168,13 +168,9 @@ static void fe_tobytes(uint8_t s[32], const fe *f) {
}
// h = 0
static void fe_0(fe *h) {
OPENSSL_memset(h, 0, sizeof(fe));
}
static void fe_0(fe *h) { OPENSSL_memset(h, 0, sizeof(fe)); }
static void fe_loose_0(fe_loose *h) {
OPENSSL_memset(h, 0, sizeof(fe_loose));
}
static void fe_loose_0(fe_loose *h) { OPENSSL_memset(h, 0, sizeof(fe_loose)); }
// h = 1
static void fe_1(fe *h) {
@@ -205,7 +201,7 @@ static void fe_sub(fe_loose *h, const fe *f, const fe *g) {
assert_fe_loose(h->v);
}
static void fe_carry(fe *h, const fe_loose* f) {
static void fe_carry(fe *h, const fe_loose *f) {
assert_fe_loose(f->v);
fiat_25519_carry(h->v, f->v);
assert_fe(h->v);
@@ -261,7 +257,7 @@ static void fe_sq_tt(fe *h, const fe *f) {
//
// Preconditions: b in {0,1}.
static void fe_cswap(fe *f, fe *g, fe_limb_t b) {
b = 0-b;
b = 0 - b;
for (unsigned i = 0; i < FE_NUM_LIMBS; i++) {
fe_limb_t x = f->v[i] ^ g->v[i];
x &= b;
@@ -293,9 +289,8 @@ static void fe_cmov(fe_loose *f, const fe_loose *g, fe_limb_t b) {
//
// TODO(davidben): Switch to fiat's calling convention, or ask fiat to emit a
// different one.
(void)fiat_25519_selectznz;
b = 0-b;
b = 0 - b;
for (unsigned i = 0; i < FE_NUM_LIMBS; i++) {
fe_limb_t x = f->v[i] ^ g->v[i];
x &= b;
@@ -304,9 +299,7 @@ static void fe_cmov(fe_loose *f, const fe_loose *g, fe_limb_t b) {
}
// h = f
static void fe_copy(fe *h, const fe *f) {
OPENSSL_memmove(h, f, sizeof(fe));
}
static void fe_copy(fe *h, const fe *f) { OPENSSL_memmove(h, f, sizeof(fe)); }
static void fe_copy_lt(fe_loose *h, const fe *f) {
static_assert(sizeof(fe_loose) == sizeof(fe), "fe and fe_loose mismatch");
@@ -506,8 +499,8 @@ int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t s[32]) {
fe_carry(&u, &v);
fe_add(&v, &vxx, &h->Z); // v = dy^2+1
fe_mul_ttl(&w, &u, &v); // w = u*v
fe_pow22523(&h->X, &w); // x = w^((q-5)/8)
fe_mul_ttl(&w, &u, &v); // w = u*v
fe_pow22523(&h->X, &w); // x = w^((q-5)/8)
fe_mul_ttt(&h->X, &h->X, &u); // x = u*w^((q-5)/8)
fe_sq_tt(&vxx, &h->X);
@@ -706,7 +699,7 @@ void x25519_ge_scalarmult_small_precomp(
for (i = 0; i < 15; i++) {
// The precomputed table is assumed to already clear the top bit, so
// |fe_frombytes_strict| may be used directly.
const uint8_t *bytes = &precomp_table[i*(2 * 32)];
const uint8_t *bytes = &precomp_table[i * (2 * 32)];
fe x, y;
fe_frombytes_strict(&x, bytes);
fe_frombytes_strict(&y, bytes + 32);
@@ -736,7 +729,7 @@ void x25519_ge_scalarmult_small_precomp(
ge_precomp_0(&e);
for (j = 1; j < 16; j++) {
cmov(&e, &multiples[j-1], 1&constant_time_eq_w(index, j));
cmov(&e, &multiples[j - 1], 1 & constant_time_eq_w(index, j));
}
ge_cached cached;
@@ -763,9 +756,11 @@ static void table_select(ge_precomp *t, const int pos, const signed char b) {
uint8_t babs = b - ((bnegative & b) << 1);
uint8_t t_bytes[3][32] = {
{constant_time_is_zero_w(b) & 1}, {constant_time_is_zero_w(b) & 1}, {0}};
#if defined(__clang__) // materialize for vectorization, 6% speedup
__asm__("" : "+m" (t_bytes) : /*no inputs*/);
{static_cast<uint8_t>(constant_time_is_zero_w(b) & 1)},
{static_cast<uint8_t>(constant_time_is_zero_w(b) & 1)},
{0}};
#if defined(__clang__) // materialize for vectorization, 6% speedup
__asm__("" : "+m"(t_bytes) : /*no inputs*/);
#endif
static_assert(sizeof(t_bytes) == sizeof(k25519Precomp[pos][0]), "");
for (int i = 0; i < 8; i++) {
@@ -787,7 +782,7 @@ static void table_select(ge_precomp *t, const int pos, const signed char b) {
fe_copy_lt(&minust.yplusx, &yminusx);
fe_copy_lt(&minust.yminusx, &yplusx);
fe_neg(&minust.xy2d, &xy2d);
cmov(t, &minust, bnegative>>7);
cmov(t, &minust, bnegative >> 7);
}
// h = a * B
@@ -903,7 +898,7 @@ void x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar, const ge_p3 *A) {
ge_p2_dbl(&t, r);
x25519_ge_p1p1_to_p3(&u, &t);
uint8_t index = scalar[31 - i/8];
uint8_t index = scalar[31 - i / 8];
index >>= 4 - (i & 4);
index &= 0xf;
@@ -911,7 +906,7 @@ void x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar, const ge_p3 *A) {
ge_cached selected;
ge_cached_0(&selected);
for (j = 0; j < 16; j++) {
cmov_cached(&selected, &Ai[j], 1&constant_time_eq_w(index, j));
cmov_cached(&selected, &Ai[j], 1 & constant_time_eq_w(index, j));
}
x25519_ge_add(&t, &u, &selected);
@@ -1937,10 +1932,10 @@ int ED25519_verify(const uint8_t *message, size_t message_len,
// kOrder is the order of Curve25519 in little-endian form.
static const uint64_t kOrder[4] = {
UINT64_C(0x5812631a5cf5d3ed),
UINT64_C(0x14def9dea2f79cd6),
0,
UINT64_C(0x1000000000000000),
UINT64_C(0x5812631a5cf5d3ed),
UINT64_C(0x14def9dea2f79cd6),
0,
UINT64_C(0x1000000000000000),
};
for (size_t i = 3;; i--) {
uint64_t word = CRYPTO_load_u64_le(scopy + i * 8);
@@ -2045,8 +2040,10 @@ static void x25519_scalar_mult_generic(uint8_t out[32],
// Coq transcription of ladderstep formula (called from transcribed loop):
// <https://github.com/mit-plv/fiat-crypto/blob/2456d821825521f7e03e65882cc3521795b0320f/src/Curves/Montgomery/XZ.v#L89>
// <https://github.com/mit-plv/fiat-crypto/blob/2456d821825521f7e03e65882cc3521795b0320f/src/Curves/Montgomery/XZProofs.v#L131>
// x1 != 0 <https://github.com/mit-plv/fiat-crypto/blob/2456d821825521f7e03e65882cc3521795b0320f/src/Curves/Montgomery/XZProofs.v#L217>
// x1 = 0 <https://github.com/mit-plv/fiat-crypto/blob/2456d821825521f7e03e65882cc3521795b0320f/src/Curves/Montgomery/XZProofs.v#L147>
// x1 != 0
// <https://github.com/mit-plv/fiat-crypto/blob/2456d821825521f7e03e65882cc3521795b0320f/src/Curves/Montgomery/XZProofs.v#L217>
// x1 = 0
// <https://github.com/mit-plv/fiat-crypto/blob/2456d821825521f7e03e65882cc3521795b0320f/src/Curves/Montgomery/XZProofs.v#L147>
fe_sub(&tmp0l, &x3, &z3);
fe_sub(&tmp1l, &x2, &z2);
fe_add(&x2l, &x2, &z2);
@@ -31,13 +31,17 @@
// points used in the SPAKE2 protocol.
//
// N:
// x: 49918732221787544735331783592030787422991506689877079631459872391322455579424
// y: 54629554431565467720832445949441049581317094546788069926228343916274969994000
// x:
// 49918732221787544735331783592030787422991506689877079631459872391322455579424
// y:
// 54629554431565467720832445949441049581317094546788069926228343916274969994000
// encoded: 10e3df0ae37d8e7a99b5fe74b44672103dbddcbd06af680d71329a11693bc778
//
// M:
// x: 31406539342727633121250288103050113562375374900226415211311216773867585644232
// y: 21177308356423958466833845032658859666296341766942662650232962324899758529114
// x:
// 31406539342727633121250288103050113562375374900226415211311216773867585644232
// y:
// 21177308356423958466833845032658859666296341766942662650232962324899758529114
// encoded: 5ada7e4bf6ddd9adb6626d32131c6b5c51a1e347a3478f53cfcf441b88eed12e
//
// These points and their precomputation tables are generated with the
@@ -269,10 +273,11 @@ static const uint8_t kSpakeMSmallPrecomp[15 * 2 * 32] = {
0xa6, 0x76, 0x81, 0x28, 0xb2, 0x65, 0xe8, 0x47, 0x14, 0xc6, 0x39, 0x06,
};
SPAKE2_CTX *SPAKE2_CTX_new(enum spake2_role_t my_role,
const uint8_t *my_name, size_t my_name_len,
const uint8_t *their_name, size_t their_name_len) {
SPAKE2_CTX *ctx = OPENSSL_zalloc(sizeof(SPAKE2_CTX));
SPAKE2_CTX *SPAKE2_CTX_new(enum spake2_role_t my_role, const uint8_t *my_name,
size_t my_name_len, const uint8_t *their_name,
size_t their_name_len) {
SPAKE2_CTX *ctx =
reinterpret_cast<SPAKE2_CTX *>(OPENSSL_zalloc(sizeof(SPAKE2_CTX)));
if (ctx == NULL) {
return NULL;
}
@@ -341,8 +346,8 @@ static void scalar_add(scalar *dest, const scalar *src) {
}
int SPAKE2_generate_msg(SPAKE2_CTX *ctx, uint8_t *out, size_t *out_len,
size_t max_out_len, const uint8_t *password,
size_t password_len) {
size_t max_out_len, const uint8_t *password,
size_t password_len) {
if (ctx->state != spake2_state_init) {
return 0;
}
@@ -459,8 +464,7 @@ static void update_with_length_prefix(SHA512_CTX *sha, const uint8_t *data,
int SPAKE2_process_msg(SPAKE2_CTX *ctx, uint8_t *out_key, size_t *out_key_len,
size_t max_out_key_len, const uint8_t *their_msg,
size_t their_msg_len) {
if (ctx->state != spake2_state_msg_generated ||
their_msg_len != 32) {
if (ctx->state != spake2_state_msg_generated || their_msg_len != 32) {
return 0;
}
@@ -473,9 +477,9 @@ int SPAKE2_process_msg(SPAKE2_CTX *ctx, uint8_t *out_key, size_t *out_key_len,
// Unmask peer's value.
ge_p3 peers_mask;
x25519_ge_scalarmult_small_precomp(&peers_mask, ctx->password_scalar,
ctx->my_role == spake2_role_alice
? kSpakeNSmallPrecomp
: kSpakeMSmallPrecomp);
ctx->my_role == spake2_role_alice
? kSpakeNSmallPrecomp
: kSpakeMSmallPrecomp);
ge_cached peers_mask_cached;
x25519_ge_p3_to_cached(&peers_mask_cached, &peers_mask);
@@ -60,19 +60,19 @@
#include <CCryptoBoringSSL_blake2.h>
#include <CCryptoBoringSSL_bytestring.h>
#include <CCryptoBoringSSL_obj.h>
#include <CCryptoBoringSSL_md4.h>
#include <CCryptoBoringSSL_md5.h>
#include <CCryptoBoringSSL_nid.h>
#include <CCryptoBoringSSL_obj.h>
#include "../asn1/internal.h"
#include "../internal.h"
#include "../fipsmodule/digest/internal.h"
#include "../internal.h"
struct nid_to_digest {
int nid;
const EVP_MD* (*md_func)(void);
const EVP_MD *(*md_func)(void);
const char *short_name;
const char *long_name;
};
@@ -107,7 +107,7 @@ static const struct nid_to_digest nid_to_digest_mapping[] = {
LN_sha512WithRSAEncryption},
};
const EVP_MD* EVP_get_digestbynid(int nid) {
const EVP_MD *EVP_get_digestbynid(int nid) {
if (nid == NID_undef) {
// Skip the |NID_undef| entries in |nid_to_digest_mapping|.
return NULL;
@@ -127,20 +127,20 @@ static const struct {
uint8_t oid_len;
int nid;
} kMDOIDs[] = {
// 1.2.840.113549.2.4
{ {0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x04}, 8, NID_md4 },
// 1.2.840.113549.2.5
{ {0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05}, 8, NID_md5 },
// 1.3.14.3.2.26
{ {0x2b, 0x0e, 0x03, 0x02, 0x1a}, 5, NID_sha1 },
// 2.16.840.1.101.3.4.2.1
{ {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01}, 9, NID_sha256 },
// 2.16.840.1.101.3.4.2.2
{ {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02}, 9, NID_sha384 },
// 2.16.840.1.101.3.4.2.3
{ {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03}, 9, NID_sha512 },
// 2.16.840.1.101.3.4.2.4
{ {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04}, 9, NID_sha224 },
// 1.2.840.113549.2.4
{{0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x04}, 8, NID_md4},
// 1.2.840.113549.2.5
{{0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05}, 8, NID_md5},
// 1.3.14.3.2.26
{{0x2b, 0x0e, 0x03, 0x02, 0x1a}, 5, NID_sha1},
// 2.16.840.1.101.3.4.2.1
{{0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01}, 9, NID_sha256},
// 2.16.840.1.101.3.4.2.2
{{0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02}, 9, NID_sha384},
// 2.16.840.1.101.3.4.2.3
{{0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03}, 9, NID_sha512},
// 2.16.840.1.101.3.4.2.4
{{0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04}, 9, NID_sha224},
};
static const EVP_MD *cbs_to_md(const CBS *cbs) {
@@ -188,7 +188,7 @@ const EVP_MD *EVP_parse_digest_algorithm(CBS *cbs) {
if (CBS_len(&algorithm) > 0) {
CBS param;
if (!CBS_get_asn1(&algorithm, &param, CBS_ASN1_NULL) ||
CBS_len(&param) != 0 ||
CBS_len(&param) != 0 || //
CBS_len(&algorithm) != 0) {
OPENSSL_PUT_ERROR(DIGEST, DIGEST_R_DECODE_ERROR);
return NULL;
@@ -223,7 +223,7 @@ int EVP_marshal_digest_algorithm(CBB *cbb, const EVP_MD *md) {
}
// TODO(crbug.com/boringssl/710): Is this correct? See RFC 4055, section 2.1.
if (!CBB_add_asn1(&algorithm, &null, CBS_ASN1_NULL) ||
if (!CBB_add_asn1(&algorithm, &null, CBS_ASN1_NULL) || //
!CBB_flush(cbb)) {
return 0;
}
@@ -244,76 +244,69 @@ const EVP_MD *EVP_get_digestbyname(const char *name) {
return NULL;
}
static void blake2b256_init(EVP_MD_CTX *ctx) { BLAKE2B256_Init(ctx->md_data); }
static void blake2b256_init(EVP_MD_CTX *ctx) {
BLAKE2B256_Init(reinterpret_cast<BLAKE2B_CTX *>(ctx->md_data));
}
static void blake2b256_update(EVP_MD_CTX *ctx, const void *data, size_t len) {
BLAKE2B256_Update(ctx->md_data, data, len);
BLAKE2B256_Update(reinterpret_cast<BLAKE2B_CTX *>(ctx->md_data), data, len);
}
static void blake2b256_final(EVP_MD_CTX *ctx, uint8_t *md) {
BLAKE2B256_Final(md, ctx->md_data);
BLAKE2B256_Final(md, reinterpret_cast<BLAKE2B_CTX *>(ctx->md_data));
}
static const EVP_MD evp_md_blake2b256 = {
NID_undef,
BLAKE2B256_DIGEST_LENGTH,
0,
blake2b256_init,
blake2b256_update,
blake2b256_final,
BLAKE2B_CBLOCK,
sizeof(BLAKE2B_CTX),
NID_undef, BLAKE2B256_DIGEST_LENGTH, 0,
blake2b256_init, blake2b256_update, blake2b256_final,
BLAKE2B_CBLOCK, sizeof(BLAKE2B_CTX),
};
const EVP_MD *EVP_blake2b256(void) { return &evp_md_blake2b256; }
static void md4_init(EVP_MD_CTX *ctx) {
BSSL_CHECK(MD4_Init(ctx->md_data));
BSSL_CHECK(MD4_Init(reinterpret_cast<MD4_CTX *>(ctx->md_data)));
}
static void md4_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
BSSL_CHECK(MD4_Update(ctx->md_data, data, count));
BSSL_CHECK(
MD4_Update(reinterpret_cast<MD4_CTX *>(ctx->md_data), data, count));
}
static void md4_final(EVP_MD_CTX *ctx, uint8_t *out) {
BSSL_CHECK(MD4_Final(out, ctx->md_data));
BSSL_CHECK(MD4_Final(out, reinterpret_cast<MD4_CTX *>(ctx->md_data)));
}
static const EVP_MD evp_md_md4 = {
NID_md4,
MD4_DIGEST_LENGTH,
0,
md4_init,
md4_update,
md4_final,
64,
sizeof(MD4_CTX),
NID_md4, //
MD4_DIGEST_LENGTH, //
0,
md4_init,
md4_update,
md4_final,
64,
sizeof(MD4_CTX),
};
const EVP_MD *EVP_md4(void) { return &evp_md_md4; }
static void md5_init(EVP_MD_CTX *ctx) {
BSSL_CHECK(MD5_Init(ctx->md_data));
BSSL_CHECK(MD5_Init(reinterpret_cast<MD5_CTX *>(ctx->md_data)));
}
static void md5_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
BSSL_CHECK(MD5_Update(ctx->md_data, data, count));
BSSL_CHECK(
MD5_Update(reinterpret_cast<MD5_CTX *>(ctx->md_data), data, count));
}
static void md5_final(EVP_MD_CTX *ctx, uint8_t *out) {
BSSL_CHECK(MD5_Final(out, ctx->md_data));
BSSL_CHECK(MD5_Final(out, reinterpret_cast<MD5_CTX *>(ctx->md_data)));
}
static const EVP_MD evp_md_md5 = {
NID_md5,
MD5_DIGEST_LENGTH,
0,
md5_init,
md5_update,
md5_final,
64,
sizeof(MD5_CTX),
NID_md5, MD5_DIGEST_LENGTH, 0, md5_init,
md5_update, md5_final, 64, sizeof(MD5_CTX),
};
const EVP_MD *EVP_md5(void) { return &evp_md_md5; }
@@ -324,32 +317,32 @@ typedef struct {
} MD5_SHA1_CTX;
static void md5_sha1_init(EVP_MD_CTX *md_ctx) {
MD5_SHA1_CTX *ctx = md_ctx->md_data;
MD5_SHA1_CTX *ctx = reinterpret_cast<MD5_SHA1_CTX *>(md_ctx->md_data);
BSSL_CHECK(MD5_Init(&ctx->md5) && SHA1_Init(&ctx->sha1));
}
static void md5_sha1_update(EVP_MD_CTX *md_ctx, const void *data,
size_t count) {
MD5_SHA1_CTX *ctx = md_ctx->md_data;
MD5_SHA1_CTX *ctx = reinterpret_cast<MD5_SHA1_CTX *>(md_ctx->md_data);
BSSL_CHECK(MD5_Update(&ctx->md5, data, count) &&
SHA1_Update(&ctx->sha1, data, count));
SHA1_Update(&ctx->sha1, data, count));
}
static void md5_sha1_final(EVP_MD_CTX *md_ctx, uint8_t *out) {
MD5_SHA1_CTX *ctx = md_ctx->md_data;
MD5_SHA1_CTX *ctx = reinterpret_cast<MD5_SHA1_CTX *>(md_ctx->md_data);
BSSL_CHECK(MD5_Final(out, &ctx->md5) &&
SHA1_Final(out + MD5_DIGEST_LENGTH, &ctx->sha1));
SHA1_Final(out + MD5_DIGEST_LENGTH, &ctx->sha1));
}
const EVP_MD evp_md_md5_sha1 = {
NID_md5_sha1,
MD5_DIGEST_LENGTH + SHA_DIGEST_LENGTH,
0,
md5_sha1_init,
md5_sha1_update,
md5_sha1_final,
64,
sizeof(MD5_SHA1_CTX),
NID_md5_sha1,
MD5_DIGEST_LENGTH + SHA_DIGEST_LENGTH,
0,
md5_sha1_init,
md5_sha1_update,
md5_sha1_final,
64,
sizeof(MD5_SHA1_CTX),
};
const EVP_MD *EVP_md5_sha1(void) { return &evp_md_md5_sha1; }
@@ -1165,9 +1165,10 @@ int DILITHIUM_generate_key_external_entropy(
vectorl s1_ntt;
vectork t;
};
struct values_st *values = OPENSSL_malloc(sizeof(*values));
struct values_st *values =
reinterpret_cast<values_st *>(OPENSSL_malloc(sizeof(*values)));
if (values == NULL) {
goto err;
return 0;
}
struct private_key *priv = private_key_from_external(out_private_key);
@@ -1217,8 +1218,6 @@ err:
int DILITHIUM_public_from_private(
struct DILITHIUM_public_key *out_public_key,
const struct DILITHIUM_private_key *private_key) {
int ret = 0;
// Intermediate values, allocated on the heap to allow use when there is a
// limited amount of stack.
struct values_st {
@@ -1227,9 +1226,10 @@ int DILITHIUM_public_from_private(
vectork t;
vectork t0;
};
struct values_st *values = OPENSSL_malloc(sizeof(*values));
struct values_st *values =
reinterpret_cast<values_st *>(OPENSSL_malloc(sizeof(*values)));
if (values == NULL) {
goto err;
return 0;
}
const struct private_key *priv = private_key_from_external(private_key);
@@ -1250,10 +1250,8 @@ int DILITHIUM_public_from_private(
vectork_power2_round(&pub->t1, &values->t0, &values->t);
ret = 1;
err:
OPENSSL_free(values);
return ret;
return 1;
}
// FIPS 204, Algorithm 2 (`ML-DSA.Sign`). Returns 1 on success and 0 on failure.
@@ -1299,7 +1297,8 @@ static int dilithium_sign_with_randomizer(
vectork r0;
vectork ct0;
};
struct values_st *values = OPENSSL_malloc(sizeof(*values));
struct values_st *values =
reinterpret_cast<values_st *>(OPENSSL_malloc(sizeof(*values)));
if (values == NULL) {
goto err;
}
@@ -1428,8 +1427,6 @@ int DILITHIUM_sign(uint8_t out_encoded_signature[DILITHIUM_SIGNATURE_BYTES],
int DILITHIUM_verify(const struct DILITHIUM_public_key *public_key,
const uint8_t encoded_signature[DILITHIUM_SIGNATURE_BYTES],
const uint8_t *msg, size_t msg_len) {
int ret = 0;
// Intermediate values, allocated on the heap to allow use when there is a
// limited amount of stack.
struct values_st {
@@ -1442,9 +1439,10 @@ int DILITHIUM_verify(const struct DILITHIUM_public_key *public_key,
vectork w_approx;
vectork w1;
};
struct values_st *values = OPENSSL_malloc(sizeof(*values));
struct values_st *values =
reinterpret_cast<values_st *>(OPENSSL_malloc(sizeof(*values)));
if (values == NULL) {
goto err;
return 0;
}
const struct public_key *pub = public_key_from_external(public_key);
@@ -1452,7 +1450,8 @@ int DILITHIUM_verify(const struct DILITHIUM_public_key *public_key,
CBS cbs;
CBS_init(&cbs, encoded_signature, DILITHIUM_SIGNATURE_BYTES);
if (!dilithium_parse_signature(&values->sign, &cbs)) {
goto err;
OPENSSL_free(values);
return 0;
}
matrix_expand(&values->a_ntt, pub->rho);
@@ -1494,12 +1493,12 @@ int DILITHIUM_verify(const struct DILITHIUM_public_key *public_key,
uint32_t z_max = vectorl_max(&values->sign.z);
size_t h_ones = vectork_count_ones(&values->sign.h);
int ret = 0;
if (z_max < kGamma1 - BETA && h_ones <= OMEGA &&
OPENSSL_memcmp(c_tilde, values->sign.c_tilde, 2 * LAMBDA_BYTES) == 0) {
ret = 1;
}
err:
OPENSSL_free(values);
return ret;
}
@@ -72,10 +72,10 @@
#include <CCryptoBoringSSL_sha.h>
#include <CCryptoBoringSSL_thread.h>
#include "internal.h"
#include "../fipsmodule/bn/internal.h"
#include "../fipsmodule/dh/internal.h"
#include "../internal.h"
#include "internal.h"
// Primality test according to FIPS PUB 186[-1], Appendix 2.1: 50 rounds of
@@ -88,7 +88,7 @@ static int dsa_sign_setup(const DSA *dsa, BN_CTX *ctx_in, BIGNUM **out_kinv,
static CRYPTO_EX_DATA_CLASS g_ex_data_class = CRYPTO_EX_DATA_CLASS_INIT;
DSA *DSA_new(void) {
DSA *dsa = OPENSSL_zalloc(sizeof(DSA));
DSA *dsa = reinterpret_cast<DSA *>(OPENSSL_zalloc(sizeof(DSA)));
if (dsa == NULL) {
return NULL;
}
@@ -179,8 +179,7 @@ int DSA_set0_key(DSA *dsa, BIGNUM *pub_key, BIGNUM *priv_key) {
}
int DSA_set0_pqg(DSA *dsa, BIGNUM *p, BIGNUM *q, BIGNUM *g) {
if ((dsa->p == NULL && p == NULL) ||
(dsa->q == NULL && q == NULL) ||
if ((dsa->p == NULL && p == NULL) || (dsa->q == NULL && q == NULL) ||
(dsa->g == NULL && g == NULL)) {
return 0;
}
@@ -312,7 +311,8 @@ int DSA_generate_parameters_ex(DSA *dsa, unsigned bits, const uint8_t *seed_in,
}
// step 4
r = BN_is_prime_fasttest_ex(q, DSS_prime_checks, ctx, use_random_seed, cb);
r = BN_is_prime_fasttest_ex(q, DSS_prime_checks, ctx, use_random_seed,
cb);
if (r > 0) {
break;
}
@@ -356,25 +356,20 @@ int DSA_generate_parameters_ex(DSA *dsa, unsigned bits, const uint8_t *seed_in,
}
// step 8
if (!BN_bin2bn(md, qsize, r0) ||
!BN_lshift(r0, r0, (qsize << 3) * k) ||
if (!BN_bin2bn(md, qsize, r0) || !BN_lshift(r0, r0, (qsize << 3) * k) ||
!BN_add(W, W, r0)) {
goto err;
}
}
// more of step 8
if (!BN_mask_bits(W, bits - 1) ||
!BN_copy(X, W) ||
!BN_add(X, X, test)) {
if (!BN_mask_bits(W, bits - 1) || !BN_copy(X, W) || !BN_add(X, X, test)) {
goto err;
}
// step 9
if (!BN_lshift1(r0, q) ||
!BN_mod(c, X, r0, ctx) ||
!BN_sub(r0, c, BN_value_one()) ||
!BN_sub(p, X, r0)) {
if (!BN_lshift1(r0, q) || !BN_mod(c, X, r0, ctx) ||
!BN_sub(r0, c, BN_value_one()) || !BN_sub(p, X, r0)) {
goto err;
}
@@ -407,14 +402,12 @@ end:
// We now need to generate g
// Set r0=(p-1)/q
if (!BN_sub(test, p, BN_value_one()) ||
!BN_div(r0, NULL, test, q, ctx)) {
if (!BN_sub(test, p, BN_value_one()) || !BN_div(r0, NULL, test, q, ctx)) {
goto err;
}
mont = BN_MONT_CTX_new_for_modulus(p, ctx);
if (mont == NULL ||
!BN_set_word(test, h)) {
if (mont == NULL || !BN_set_word(test, h)) {
goto err;
}
@@ -541,7 +534,9 @@ err:
return ok;
}
DSA_SIG *DSA_SIG_new(void) { return OPENSSL_zalloc(sizeof(DSA_SIG)); }
DSA_SIG *DSA_SIG_new(void) {
return reinterpret_cast<DSA_SIG *>(OPENSSL_zalloc(sizeof(DSA_SIG)));
}
void DSA_SIG_free(DSA_SIG *sig) {
if (!sig) {
@@ -583,8 +578,7 @@ static int mod_mul_consttime(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
BIGNUM *tmp = BN_CTX_get(ctx);
// |BN_mod_mul_montgomery| removes a factor of R, so we cancel it with a
// single |BN_to_montgomery| which adds one factor of R.
int ok = tmp != NULL &&
BN_to_montgomery(tmp, a, mont, ctx) &&
int ok = tmp != NULL && BN_to_montgomery(tmp, a, mont, ctx) &&
BN_mod_mul_montgomery(r, tmp, b, mont, ctx);
BN_CTX_end(ctx);
return ok;
@@ -609,79 +603,80 @@ DSA_SIG *DSA_do_sign(const uint8_t *digest, size_t digest_len, const DSA *dsa) {
BN_init(&m);
BN_init(&xr);
s = BN_new();
if (s == NULL) {
goto err;
}
ctx = BN_CTX_new();
if (ctx == NULL) {
goto err;
}
// Cap iterations so that invalid parameters do not infinite loop. This does
// not impact valid parameters because the probability of requiring even one
// retry is negligible, let alone 32. Unfortunately, DSA was mis-specified, so
// invalid parameters are reachable from most callers handling untrusted
// private keys. (The |dsa_check_key| call above is not sufficient. Checking
// whether arbitrary paremeters form a valid DSA group is expensive.)
static const int kMaxIterations = 32;
int iters = 0;
redo:
if (!dsa_sign_setup(dsa, ctx, &kinv, &r)) {
goto err;
}
if (digest_len > BN_num_bytes(dsa->q)) {
// If the digest length is greater than the size of |dsa->q| use the
// BN_num_bits(dsa->q) leftmost bits of the digest, see FIPS 186-3, 4.2.
// Note the above check that |dsa->q| is a multiple of 8 bits.
digest_len = BN_num_bytes(dsa->q);
}
if (BN_bin2bn(digest, digest_len, &m) == NULL) {
goto err;
}
// |m| is bounded by 2^(num_bits(q)), which is slightly looser than q. This
// violates |bn_mod_add_consttime| and |mod_mul_consttime|'s preconditions.
// (The underlying algorithms could accept looser bounds, but we reduce for
// simplicity.)
size_t q_width = bn_minimal_width(dsa->q);
if (!bn_resize_words(&m, q_width) ||
!bn_resize_words(&xr, q_width)) {
goto err;
}
bn_reduce_once_in_place(m.d, 0 /* no carry word */, dsa->q->d,
xr.d /* scratch space */, q_width);
// Compute s = inv(k) (m + xr) mod q. Note |dsa->method_mont_q| is
// initialized by |dsa_sign_setup|.
if (!mod_mul_consttime(&xr, dsa->priv_key, r, dsa->method_mont_q, ctx) ||
!bn_mod_add_consttime(s, &xr, &m, dsa->q, ctx) ||
!mod_mul_consttime(s, s, kinv, dsa->method_mont_q, ctx)) {
goto err;
}
// The signature is computed from the private key, but is public.
bn_declassify(r);
bn_declassify(s);
// Redo if r or s is zero as required by FIPS 186-3: this is
// very unlikely.
if (BN_is_zero(r) || BN_is_zero(s)) {
iters++;
if (iters > kMaxIterations) {
OPENSSL_PUT_ERROR(DSA, DSA_R_TOO_MANY_ITERATIONS);
{
if (s == NULL) {
goto err;
}
ctx = BN_CTX_new();
if (ctx == NULL) {
goto err;
}
goto redo;
}
ret = DSA_SIG_new();
if (ret == NULL) {
goto err;
// Cap iterations so that invalid parameters do not infinite loop. This does
// not impact valid parameters because the probability of requiring even one
// retry is negligible, let alone 32. Unfortunately, DSA was mis-specified,
// so invalid parameters are reachable from most callers handling untrusted
// private keys. (The |dsa_check_key| call above is not sufficient. Checking
// whether arbitrary paremeters form a valid DSA group is expensive.)
static const int kMaxIterations = 32;
int iters = 0;
redo:
if (!dsa_sign_setup(dsa, ctx, &kinv, &r)) {
goto err;
}
if (digest_len > BN_num_bytes(dsa->q)) {
// If the digest length is greater than the size of |dsa->q| use the
// BN_num_bits(dsa->q) leftmost bits of the digest, see FIPS 186-3, 4.2.
// Note the above check that |dsa->q| is a multiple of 8 bits.
digest_len = BN_num_bytes(dsa->q);
}
if (BN_bin2bn(digest, digest_len, &m) == NULL) {
goto err;
}
// |m| is bounded by 2^(num_bits(q)), which is slightly looser than q. This
// violates |bn_mod_add_consttime| and |mod_mul_consttime|'s preconditions.
// (The underlying algorithms could accept looser bounds, but we reduce for
// simplicity.)
size_t q_width = bn_minimal_width(dsa->q);
if (!bn_resize_words(&m, q_width) || !bn_resize_words(&xr, q_width)) {
goto err;
}
bn_reduce_once_in_place(m.d, 0 /* no carry word */, dsa->q->d,
xr.d /* scratch space */, q_width);
// Compute s = inv(k) (m + xr) mod q. Note |dsa->method_mont_q| is
// initialized by |dsa_sign_setup|.
if (!mod_mul_consttime(&xr, dsa->priv_key, r, dsa->method_mont_q, ctx) ||
!bn_mod_add_consttime(s, &xr, &m, dsa->q, ctx) ||
!mod_mul_consttime(s, s, kinv, dsa->method_mont_q, ctx)) {
goto err;
}
// The signature is computed from the private key, but is public.
bn_declassify(r);
bn_declassify(s);
// Redo if r or s is zero as required by FIPS 186-3: this is
// very unlikely.
if (BN_is_zero(r) || BN_is_zero(s)) {
iters++;
if (iters > kMaxIterations) {
OPENSSL_PUT_ERROR(DSA, DSA_R_TOO_MANY_ITERATIONS);
goto err;
}
goto redo;
}
ret = DSA_SIG_new();
if (ret == NULL) {
goto err;
}
ret->r = r;
ret->s = s;
}
ret->r = r;
ret->s = s;
err:
if (ret == NULL) {
@@ -725,71 +720,73 @@ int DSA_do_check_signature(int *out_valid, const uint8_t *digest,
BN_init(&u2);
BN_init(&t1);
BN_CTX *ctx = BN_CTX_new();
if (ctx == NULL) {
goto err;
}
{
if (ctx == NULL) {
goto err;
}
if (BN_is_zero(sig->r) || BN_is_negative(sig->r) ||
BN_ucmp(sig->r, dsa->q) >= 0) {
if (BN_is_zero(sig->r) || BN_is_negative(sig->r) ||
BN_ucmp(sig->r, dsa->q) >= 0) {
ret = 1;
goto err;
}
if (BN_is_zero(sig->s) || BN_is_negative(sig->s) ||
BN_ucmp(sig->s, dsa->q) >= 0) {
ret = 1;
goto err;
}
// Calculate W = inv(S) mod Q
// save W in u2
if (BN_mod_inverse(&u2, sig->s, dsa->q, ctx) == NULL) {
goto err;
}
// save M in u1
unsigned q_bits = BN_num_bits(dsa->q);
if (digest_len > (q_bits >> 3)) {
// if the digest length is greater than the size of q use the
// BN_num_bits(dsa->q) leftmost bits of the digest, see
// fips 186-3, 4.2
digest_len = (q_bits >> 3);
}
if (BN_bin2bn(digest, digest_len, &u1) == NULL) {
goto err;
}
// u1 = M * w mod q
if (!BN_mod_mul(&u1, &u1, &u2, dsa->q, ctx)) {
goto err;
}
// u2 = r * w mod q
if (!BN_mod_mul(&u2, sig->r, &u2, dsa->q, ctx)) {
goto err;
}
if (!BN_MONT_CTX_set_locked((BN_MONT_CTX **)&dsa->method_mont_p,
(CRYPTO_MUTEX *)&dsa->method_mont_lock, dsa->p,
ctx)) {
goto err;
}
if (!BN_mod_exp2_mont(&t1, dsa->g, &u1, dsa->pub_key, &u2, dsa->p, ctx,
dsa->method_mont_p)) {
goto err;
}
// BN_copy(&u1,&t1);
// let u1 = u1 mod q
if (!BN_mod(&u1, &t1, dsa->q, ctx)) {
goto err;
}
// V is now in u1. If the signature is correct, it will be
// equal to R.
*out_valid = BN_ucmp(&u1, sig->r) == 0;
ret = 1;
goto err;
}
if (BN_is_zero(sig->s) || BN_is_negative(sig->s) ||
BN_ucmp(sig->s, dsa->q) >= 0) {
ret = 1;
goto err;
}
// Calculate W = inv(S) mod Q
// save W in u2
if (BN_mod_inverse(&u2, sig->s, dsa->q, ctx) == NULL) {
goto err;
}
// save M in u1
unsigned q_bits = BN_num_bits(dsa->q);
if (digest_len > (q_bits >> 3)) {
// if the digest length is greater than the size of q use the
// BN_num_bits(dsa->q) leftmost bits of the digest, see
// fips 186-3, 4.2
digest_len = (q_bits >> 3);
}
if (BN_bin2bn(digest, digest_len, &u1) == NULL) {
goto err;
}
// u1 = M * w mod q
if (!BN_mod_mul(&u1, &u1, &u2, dsa->q, ctx)) {
goto err;
}
// u2 = r * w mod q
if (!BN_mod_mul(&u2, sig->r, &u2, dsa->q, ctx)) {
goto err;
}
if (!BN_MONT_CTX_set_locked((BN_MONT_CTX **)&dsa->method_mont_p,
(CRYPTO_MUTEX *)&dsa->method_mont_lock, dsa->p,
ctx)) {
goto err;
}
if (!BN_mod_exp2_mont(&t1, dsa->g, &u1, dsa->pub_key, &u2, dsa->p, ctx,
dsa->method_mont_p)) {
goto err;
}
// BN_copy(&u1,&t1);
// let u1 = u1 mod q
if (!BN_mod(&u1, &t1, dsa->q, ctx)) {
goto err;
}
// V is now in u1. If the signature is correct, it will be
// equal to R.
*out_valid = BN_ucmp(&u1, sig->r) == 0;
ret = 1;
err:
if (ret != 1) {
@@ -835,23 +832,25 @@ int DSA_check_signature(int *out_valid, const uint8_t *digest,
uint8_t *der = NULL;
s = DSA_SIG_new();
if (s == NULL) {
goto err;
}
{
if (s == NULL) {
goto err;
}
const uint8_t *sigp = sig;
if (d2i_DSA_SIG(&s, &sigp, sig_len) == NULL || sigp != sig + sig_len) {
goto err;
}
const uint8_t *sigp = sig;
if (d2i_DSA_SIG(&s, &sigp, sig_len) == NULL || sigp != sig + sig_len) {
goto err;
}
// Ensure that the signature uses DER and doesn't have trailing garbage.
int der_len = i2d_DSA_SIG(s, &der);
if (der_len < 0 || (size_t)der_len != sig_len ||
OPENSSL_memcmp(sig, der, sig_len)) {
goto err;
}
// Ensure that the signature uses DER and doesn't have trailing garbage.
int der_len = i2d_DSA_SIG(s, &der);
if (der_len < 0 || (size_t)der_len != sig_len ||
OPENSSL_memcmp(sig, der, sig_len)) {
goto err;
}
ret = DSA_do_check_signature(out_valid, digest, digest_len, s, dsa);
ret = DSA_do_check_signature(out_valid, digest, digest_len, s, dsa);
}
err:
OPENSSL_free(der);
@@ -20,10 +20,10 @@
#include <assert.h>
#include "internal.h"
#include "../fipsmodule/bn/internal.h"
#include "../fipsmodule/ec/internal.h"
#include "../internal.h"
#include "internal.h"
// This file implements hash-to-curve, as described in RFC 9380.
@@ -63,71 +63,74 @@ static int expand_message_xmd(const EVP_MD *md, uint8_t *out, size_t out_len,
EVP_MD_CTX ctx;
EVP_MD_CTX_init(&ctx);
// Long DSTs are hashed down to size. See section 5.3.3.
static_assert(EVP_MAX_MD_SIZE < 256, "hashed DST still too large");
uint8_t dst_buf[EVP_MAX_MD_SIZE];
if (dst_len >= 256) {
static const char kPrefix[] = "H2C-OVERSIZE-DST-";
if (!EVP_DigestInit_ex(&ctx, md, NULL) ||
!EVP_DigestUpdate(&ctx, kPrefix, sizeof(kPrefix) - 1) ||
!EVP_DigestUpdate(&ctx, dst, dst_len) ||
!EVP_DigestFinal_ex(&ctx, dst_buf, NULL)) {
goto err;
}
dst = dst_buf;
dst_len = md_size;
}
uint8_t dst_len_u8 = (uint8_t)dst_len;
// Compute b_0.
static const uint8_t kZeros[EVP_MAX_MD_BLOCK_SIZE] = {0};
// If |out_len| exceeds 16 bits then |i| will wrap below causing an error to
// be returned. This depends on the static assert above.
uint8_t l_i_b_str_zero[3] = {out_len >> 8, out_len, 0};
uint8_t b_0[EVP_MAX_MD_SIZE];
if (!EVP_DigestInit_ex(&ctx, md, NULL) ||
!EVP_DigestUpdate(&ctx, kZeros, block_size) ||
!EVP_DigestUpdate(&ctx, msg, msg_len) ||
!EVP_DigestUpdate(&ctx, l_i_b_str_zero, sizeof(l_i_b_str_zero)) ||
!EVP_DigestUpdate(&ctx, dst, dst_len) ||
!EVP_DigestUpdate(&ctx, &dst_len_u8, 1) ||
!EVP_DigestFinal_ex(&ctx, b_0, NULL)) {
goto err;
}
uint8_t b_i[EVP_MAX_MD_SIZE];
uint8_t i = 1;
while (out_len > 0) {
if (i == 0) {
// Input was too large.
OPENSSL_PUT_ERROR(EC, ERR_R_INTERNAL_ERROR);
goto err;
}
if (i > 1) {
for (size_t j = 0; j < md_size; j++) {
b_i[j] ^= b_0[j];
{
// Long DSTs are hashed down to size. See section 5.3.3.
static_assert(EVP_MAX_MD_SIZE < 256, "hashed DST still too large");
uint8_t dst_buf[EVP_MAX_MD_SIZE];
if (dst_len >= 256) {
static const char kPrefix[] = "H2C-OVERSIZE-DST-";
if (!EVP_DigestInit_ex(&ctx, md, NULL) ||
!EVP_DigestUpdate(&ctx, kPrefix, sizeof(kPrefix) - 1) ||
!EVP_DigestUpdate(&ctx, dst, dst_len) ||
!EVP_DigestFinal_ex(&ctx, dst_buf, NULL)) {
goto err;
}
} else {
OPENSSL_memcpy(b_i, b_0, md_size);
dst = dst_buf;
dst_len = md_size;
}
uint8_t dst_len_u8 = (uint8_t)dst_len;
// Compute b_0.
static const uint8_t kZeros[EVP_MAX_MD_BLOCK_SIZE] = {0};
// If |out_len| exceeds 16 bits then |i| will wrap below causing an error to
// be returned. This depends on the static assert above.
uint8_t l_i_b_str_zero[3] = {static_cast<uint8_t>(out_len >> 8),
static_cast<uint8_t>(out_len), 0};
uint8_t b_0[EVP_MAX_MD_SIZE];
if (!EVP_DigestInit_ex(&ctx, md, NULL) ||
!EVP_DigestUpdate(&ctx, b_i, md_size) ||
!EVP_DigestUpdate(&ctx, &i, 1) ||
!EVP_DigestUpdate(&ctx, kZeros, block_size) ||
!EVP_DigestUpdate(&ctx, msg, msg_len) ||
!EVP_DigestUpdate(&ctx, l_i_b_str_zero, sizeof(l_i_b_str_zero)) ||
!EVP_DigestUpdate(&ctx, dst, dst_len) ||
!EVP_DigestUpdate(&ctx, &dst_len_u8, 1) ||
!EVP_DigestFinal_ex(&ctx, b_i, NULL)) {
!EVP_DigestFinal_ex(&ctx, b_0, NULL)) {
goto err;
}
size_t todo = out_len >= md_size ? md_size : out_len;
OPENSSL_memcpy(out, b_i, todo);
out += todo;
out_len -= todo;
i++;
}
uint8_t b_i[EVP_MAX_MD_SIZE];
uint8_t i = 1;
while (out_len > 0) {
if (i == 0) {
// Input was too large.
OPENSSL_PUT_ERROR(EC, ERR_R_INTERNAL_ERROR);
goto err;
}
if (i > 1) {
for (size_t j = 0; j < md_size; j++) {
b_i[j] ^= b_0[j];
}
} else {
OPENSSL_memcpy(b_i, b_0, md_size);
}
ret = 1;
if (!EVP_DigestInit_ex(&ctx, md, NULL) ||
!EVP_DigestUpdate(&ctx, b_i, md_size) ||
!EVP_DigestUpdate(&ctx, &i, 1) ||
!EVP_DigestUpdate(&ctx, dst, dst_len) ||
!EVP_DigestUpdate(&ctx, &dst_len_u8, 1) ||
!EVP_DigestFinal_ex(&ctx, b_i, NULL)) {
goto err;
}
size_t todo = out_len >= md_size ? md_size : out_len;
OPENSSL_memcpy(out, b_i, todo);
out += todo;
out_len -= todo;
i++;
}
ret = 1;
}
err:
EVP_MD_CTX_cleanup(&ctx);
@@ -144,8 +147,7 @@ static int num_bytes_to_derive(size_t *out, const BIGNUM *modulus, unsigned k) {
// |felem_reduce| and |ec_scalar_reduce|. All defined hash-to-curve suites
// define |k| to be well under this bound. (|k| is usually around half of
// |p_bits|.)
if (L * 8 >= 2 * bits - 2 ||
L > 2 * EC_MAX_BYTES) {
if (L * 8 >= 2 * bits - 2 || L > 2 * EC_MAX_BYTES) {
assert(0);
OPENSSL_PUT_ERROR(EC, ERR_R_INTERNAL_ERROR);
return 0;
@@ -462,9 +464,9 @@ int EC_hash_to_curve_p384_xmd_sha384_sswu(const EC_GROUP *group, EC_POINT *out,
msg, msg_len);
}
int ec_hash_to_scalar_p384_xmd_sha384(
const EC_GROUP *group, EC_SCALAR *out, const uint8_t *dst, size_t dst_len,
const uint8_t *msg, size_t msg_len) {
int ec_hash_to_scalar_p384_xmd_sha384(const EC_GROUP *group, EC_SCALAR *out,
const uint8_t *dst, size_t dst_len,
const uint8_t *msg, size_t msg_len) {
if (EC_GROUP_get_curve_name(group) != NID_secp384r1) {
OPENSSL_PUT_ERROR(EC, EC_R_GROUP_MISMATCH);
return 0;
@@ -475,8 +477,8 @@ int ec_hash_to_scalar_p384_xmd_sha384(
}
int ec_hash_to_curve_p384_xmd_sha512_sswu_draft07(
const EC_GROUP *group, EC_JACOBIAN *out, const uint8_t *dst,
size_t dst_len, const uint8_t *msg, size_t msg_len) {
const EC_GROUP *group, EC_JACOBIAN *out, const uint8_t *dst, size_t dst_len,
const uint8_t *msg, size_t msg_len) {
// See section 8.3 of draft-irtf-cfrg-hash-to-curve-07.
if (EC_GROUP_get_curve_name(group) != NID_secp384r1) {
OPENSSL_PUT_ERROR(EC, EC_R_GROUP_MISMATCH);
@@ -57,8 +57,8 @@
#include <CCryptoBoringSSL_bn.h>
#include <CCryptoBoringSSL_bytestring.h>
#include <CCryptoBoringSSL_err.h>
#include <CCryptoBoringSSL_ec_key.h>
#include <CCryptoBoringSSL_err.h>
#include <CCryptoBoringSSL_mem.h>
#include "../bytestring/internal.h"
@@ -79,8 +79,7 @@ static ECDSA_SIG *ecdsa_sig_from_fixed(const EC_KEY *key, const uint8_t *in,
return NULL;
}
ECDSA_SIG *ret = ECDSA_SIG_new();
if (ret == NULL ||
!BN_bin2bn(in, scalar_len, ret->r) ||
if (ret == NULL || !BN_bin2bn(in, scalar_len, ret->r) ||
!BN_bin2bn(in + scalar_len, scalar_len, ret->s)) {
ECDSA_SIG_free(ret);
return NULL;
@@ -100,8 +99,7 @@ static int ecdsa_sig_to_fixed(const EC_KEY *key, uint8_t *out, size_t *out_len,
OPENSSL_PUT_ERROR(EC, EC_R_BUFFER_TOO_SMALL);
return 0;
}
if (BN_is_negative(sig->r) ||
!BN_bn2bin_padded(out, scalar_len, sig->r) ||
if (BN_is_negative(sig->r) || !BN_bn2bin_padded(out, scalar_len, sig->r) ||
BN_is_negative(sig->s) ||
!BN_bn2bin_padded(out + scalar_len, scalar_len, sig->s)) {
OPENSSL_PUT_ERROR(ECDSA, ECDSA_R_BAD_SIGNATURE);
@@ -115,7 +113,7 @@ int ECDSA_sign(int type, const uint8_t *digest, size_t digest_len, uint8_t *sig,
unsigned int *out_sig_len, const EC_KEY *eckey) {
if (eckey->ecdsa_meth && eckey->ecdsa_meth->sign) {
return eckey->ecdsa_meth->sign(digest, digest_len, sig, out_sig_len,
(EC_KEY*) eckey /* cast away const */);
(EC_KEY *)eckey /* cast away const */);
}
*out_sig_len = 0;
@@ -137,8 +135,7 @@ int ECDSA_sign(int type, const uint8_t *digest, size_t digest_len, uint8_t *sig,
CBB cbb;
CBB_init_fixed(&cbb, sig, ECDSA_size(eckey));
size_t len;
if (!ECDSA_SIG_marshal(&cbb, s) ||
!CBB_finish(&cbb, NULL, &len)) {
if (!ECDSA_SIG_marshal(&cbb, s) || !CBB_finish(&cbb, NULL, &len)) {
OPENSSL_PUT_ERROR(ECDSA, ECDSA_R_ENCODE_ERROR);
goto err;
}
@@ -165,8 +162,8 @@ int ECDSA_verify(int type, const uint8_t *digest, size_t digest_len,
// Defend against potential laxness in the DER parser.
size_t der_len;
if (!ECDSA_SIG_to_bytes(&der, &der_len, s) ||
der_len != sig_len || OPENSSL_memcmp(sig, der, sig_len) != 0) {
if (!ECDSA_SIG_to_bytes(&der, &der_len, s) || der_len != sig_len ||
OPENSSL_memcmp(sig, der, sig_len) != 0) {
// This should never happen. crypto/bytestring is strictly DER.
OPENSSL_PUT_ERROR(ECDSA, ERR_R_INTERNAL_ERROR);
goto err;
@@ -205,7 +202,8 @@ size_t ECDSA_size(const EC_KEY *key) {
}
ECDSA_SIG *ECDSA_SIG_new(void) {
ECDSA_SIG *sig = OPENSSL_malloc(sizeof(ECDSA_SIG));
ECDSA_SIG *sig =
reinterpret_cast<ECDSA_SIG *>(OPENSSL_malloc(sizeof(ECDSA_SIG)));
if (sig == NULL) {
return NULL;
}
@@ -228,13 +226,9 @@ void ECDSA_SIG_free(ECDSA_SIG *sig) {
OPENSSL_free(sig);
}
const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig) {
return sig->r;
}
const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig) { return sig->r; }
const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig) {
return sig->s;
}
const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig) { return sig->s; }
void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **out_r,
const BIGNUM **out_s) {
@@ -301,8 +295,7 @@ ECDSA_SIG *ECDSA_SIG_parse(CBS *cbs) {
CBS child;
if (!CBS_get_asn1(cbs, &child, CBS_ASN1_SEQUENCE) ||
!BN_parse_asn1_unsigned(&child, ret->r) ||
!BN_parse_asn1_unsigned(&child, ret->s) ||
CBS_len(&child) != 0) {
!BN_parse_asn1_unsigned(&child, ret->s) || CBS_len(&child) != 0) {
OPENSSL_PUT_ERROR(ECDSA, ECDSA_R_BAD_SIGNATURE);
ECDSA_SIG_free(ret);
return NULL;
@@ -325,8 +318,7 @@ ECDSA_SIG *ECDSA_SIG_from_bytes(const uint8_t *in, size_t in_len) {
int ECDSA_SIG_marshal(CBB *cbb, const ECDSA_SIG *sig) {
CBB child;
if (!CBB_add_asn1(cbb, &child, CBS_ASN1_SEQUENCE) ||
!BN_marshal_asn1(&child, sig->r) ||
!BN_marshal_asn1(&child, sig->s) ||
!BN_marshal_asn1(&child, sig->r) || !BN_marshal_asn1(&child, sig->s) ||
!CBB_flush(cbb)) {
OPENSSL_PUT_ERROR(ECDSA, ECDSA_R_ENCODE_ERROR);
return 0;
@@ -338,8 +330,7 @@ int ECDSA_SIG_to_bytes(uint8_t **out_bytes, size_t *out_len,
const ECDSA_SIG *sig) {
CBB cbb;
CBB_zero(&cbb);
if (!CBB_init(&cbb, 0) ||
!ECDSA_SIG_marshal(&cbb, sig) ||
if (!CBB_init(&cbb, 0) || !ECDSA_SIG_marshal(&cbb, sig) ||
!CBB_finish(&cbb, out_bytes, out_len)) {
OPENSSL_PUT_ERROR(ECDSA, ECDSA_R_ENCODE_ERROR);
CBB_cleanup(&cbb);
@@ -402,8 +393,7 @@ ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **out, const uint8_t **inp, long len) {
int i2d_ECDSA_SIG(const ECDSA_SIG *sig, uint8_t **outp) {
CBB cbb;
if (!CBB_init(&cbb, 0) ||
!ECDSA_SIG_marshal(&cbb, sig)) {
if (!CBB_init(&cbb, 0) || !ECDSA_SIG_marshal(&cbb, sig)) {
CBB_cleanup(&cbb);
return -1;
}
@@ -14,8 +14,8 @@
#include <CCryptoBoringSSL_engine.h>
#include <string.h>
#include <assert.h>
#include <string.h>
#include <CCryptoBoringSSL_ec_key.h>
#include <CCryptoBoringSSL_err.h>
@@ -31,7 +31,9 @@ struct engine_st {
ECDSA_METHOD *ecdsa_method;
};
ENGINE *ENGINE_new(void) { return OPENSSL_zalloc(sizeof(ENGINE)); }
ENGINE *ENGINE_new(void) {
return reinterpret_cast<ENGINE *>(OPENSSL_zalloc(sizeof(ENGINE)));
}
int ENGINE_free(ENGINE *engine) {
// Methods are currently required to be static so are not unref'ed.
@@ -46,17 +48,18 @@ int ENGINE_free(ENGINE *engine) {
// static.
static int set_method(void **out_member, const void *method, size_t method_size,
size_t compiled_size) {
const struct openssl_method_common_st *common = method;
const struct openssl_method_common_st *common =
reinterpret_cast<const openssl_method_common_st *>(method);
if (method_size != compiled_size || !common->is_static) {
return 0;
}
*out_member = (void*) method;
*out_member = (void *)method;
return 1;
}
int ENGINE_set_RSA_method(ENGINE *engine, const RSA_METHOD *method,
size_t method_size) {
size_t method_size) {
return set_method((void **)&engine->rsa_method, method, method_size,
sizeof(RSA_METHOD));
}
@@ -76,11 +79,12 @@ ECDSA_METHOD *ENGINE_get_ECDSA_method(const ENGINE *engine) {
}
void METHOD_ref(void *method_in) {
assert(((struct openssl_method_common_st*) method_in)->is_static);
assert(((struct openssl_method_common_st *)method_in)->is_static);
}
void METHOD_unref(void *method_in) {
struct openssl_method_common_st *method = method_in;
struct openssl_method_common_st *method =
reinterpret_cast<openssl_method_common_st *>(method_in);
if (method == NULL) {
return;
@@ -168,7 +168,7 @@ static char *strdup_libc_malloc(const char *str) {
// |strdup| is not in C until C23, so MSVC triggers deprecation warnings, and
// glibc and musl gate it on a feature macro. Reimplementing it is easier.
size_t len = strlen(str);
char *ret = malloc(len + 1);
char *ret = reinterpret_cast<char *>(malloc(len + 1));
if (ret != NULL) {
memcpy(ret, str, len + 1);
}
@@ -202,7 +202,7 @@ static int global_next_library = ERR_NUM_LIBS;
static CRYPTO_MUTEX global_next_library_mutex = CRYPTO_MUTEX_INIT;
static void err_state_free(void *statep) {
ERR_STATE *state = statep;
ERR_STATE *state = reinterpret_cast<ERR_STATE *>(statep);
if (state == NULL) {
return;
@@ -217,9 +217,10 @@ static void err_state_free(void *statep) {
// err_get_state gets the ERR_STATE object for the current thread.
static ERR_STATE *err_get_state(void) {
ERR_STATE *state = CRYPTO_get_thread_local(OPENSSL_THREAD_LOCAL_ERR);
ERR_STATE *state = reinterpret_cast<ERR_STATE *>(
CRYPTO_get_thread_local(OPENSSL_THREAD_LOCAL_ERR));
if (state == NULL) {
state = malloc(sizeof(ERR_STATE));
state = reinterpret_cast<ERR_STATE *>(malloc(sizeof(ERR_STATE)));
if (state == NULL) {
return NULL;
}
@@ -380,19 +381,15 @@ int ERR_get_next_error_library(void) {
return ret;
}
void ERR_remove_state(unsigned long pid) {
ERR_clear_error();
}
void ERR_remove_state(unsigned long pid) { ERR_clear_error(); }
void ERR_clear_system_error(void) {
errno = 0;
}
void ERR_clear_system_error(void) { errno = 0; }
// err_string_cmp is a compare function for searching error values with
// |bsearch| in |err_string_lookup|.
static int err_string_cmp(const void *a, const void *b) {
const uint32_t a_key = *((const uint32_t*) a) >> 15;
const uint32_t b_key = *((const uint32_t*) b) >> 15;
const uint32_t a_key = *((const uint32_t *)a) >> 15;
const uint32_t b_key = *((const uint32_t *)b) >> 15;
if (a_key < b_key) {
return -1;
@@ -406,8 +403,7 @@ static int err_string_cmp(const void *a, const void *b) {
// err_string_lookup looks up the string associated with |lib| and |key| in
// |values| and |string_data|. It returns the string or NULL if not found.
static const char *err_string_lookup(uint32_t lib, uint32_t key,
const uint32_t *values,
size_t num_values,
const uint32_t *values, size_t num_values,
const char *string_data) {
// |values| points to data in err_data.h, which is generated by
// err_data_generate.go. It's an array of uint32_t values. Each value has the
@@ -426,8 +422,8 @@ static const char *err_string_lookup(uint32_t lib, uint32_t key,
return NULL;
}
uint32_t search_key = lib << 26 | key << 15;
const uint32_t *result = bsearch(&search_key, values, num_values,
sizeof(uint32_t), err_string_cmp);
const uint32_t *result = reinterpret_cast<const uint32_t *>(bsearch(
&search_key, values, num_values, sizeof(uint32_t), err_string_cmp));
if (result == NULL) {
return NULL;
}
@@ -632,7 +628,7 @@ void ERR_print_errors_cb(ERR_print_errors_callback_t callback, void *ctx) {
// thread_hash is the least-significant bits of the |ERR_STATE| pointer value
// for this thread.
const unsigned long thread_hash = (uintptr_t) err_get_state();
const unsigned long thread_hash = (uintptr_t)err_get_state();
for (;;) {
packed_error = ERR_get_error_line_data(&file, &line, &data, &flags);
@@ -649,9 +645,9 @@ void ERR_print_errors_cb(ERR_print_errors_callback_t callback, void *ctx) {
}
}
static int print_errors_to_file(const char* msg, size_t msg_len, void* ctx) {
static int print_errors_to_file(const char *msg, size_t msg_len, void *ctx) {
assert(msg[msg_len] == '\0');
FILE* fp = ctx;
FILE *fp = reinterpret_cast<FILE *>(ctx);
int res = fputs(msg, fp);
return res < 0 ? 0 : 1;
}
@@ -722,16 +718,16 @@ static void err_add_error_vdata(unsigned num, va_list args) {
}
size_t substr_len = strlen(substr);
if (SIZE_MAX - total_size < substr_len) {
return; // Would overflow.
return; // Would overflow.
}
total_size += substr_len;
}
va_end(args_copy);
if (total_size == SIZE_MAX) {
return; // Would overflow.
return; // Would overflow.
}
total_size += 1; // NUL terminator.
if ((buf = malloc(total_size)) == NULL) {
total_size += 1; // NUL terminator.
if ((buf = reinterpret_cast<char *>(malloc(total_size))) == NULL) {
return;
}
buf[0] = '\0';
@@ -741,7 +737,7 @@ static void err_add_error_vdata(unsigned num, va_list args) {
continue;
}
if (OPENSSL_strlcat(buf, substr, total_size) >= total_size) {
assert(0); // should not be possible.
assert(0); // should not be possible.
}
}
va_end(args);
@@ -855,7 +851,8 @@ ERR_SAVE_STATE *ERR_save_state(void) {
return NULL;
}
ERR_SAVE_STATE *ret = malloc(sizeof(ERR_SAVE_STATE));
ERR_SAVE_STATE *ret =
reinterpret_cast<ERR_SAVE_STATE *>(malloc(sizeof(ERR_SAVE_STATE)));
if (ret == NULL) {
return NULL;
}
@@ -865,7 +862,8 @@ ERR_SAVE_STATE *ERR_save_state(void) {
? state->top - state->bottom
: ERR_NUM_ERRORS + state->top - state->bottom;
assert(num_errors < ERR_NUM_ERRORS);
ret->errors = malloc(num_errors * sizeof(struct err_error_st));
ret->errors = reinterpret_cast<err_error_st *>(
malloc(num_errors * sizeof(struct err_error_st)));
if (ret->errors == NULL) {
free(ret);
return NULL;
@@ -64,8 +64,8 @@
#include <CCryptoBoringSSL_nid.h>
#include <CCryptoBoringSSL_thread.h>
#include "internal.h"
#include "../internal.h"
#include "internal.h"
// Node depends on |EVP_R_NOT_XOF_OR_INVALID_LENGTH|.
@@ -78,7 +78,8 @@ OPENSSL_DECLARE_ERROR_REASON(EVP, NOT_XOF_OR_INVALID_LENGTH)
OPENSSL_DECLARE_ERROR_REASON(EVP, EMPTY_PSK)
EVP_PKEY *EVP_PKEY_new(void) {
EVP_PKEY *ret = OPENSSL_zalloc(sizeof(EVP_PKEY));
EVP_PKEY *ret =
reinterpret_cast<EVP_PKEY *>(OPENSSL_zalloc(sizeof(EVP_PKEY)));
if (ret == NULL) {
return NULL;
}
@@ -196,9 +197,7 @@ int EVP_PKEY_bits(const EVP_PKEY *pkey) {
return 0;
}
int EVP_PKEY_id(const EVP_PKEY *pkey) {
return pkey->type;
}
int EVP_PKEY_id(const EVP_PKEY *pkey) { return pkey->type; }
// evp_pkey_asn1_find returns the ASN.1 method table for the given |nid|, which
// should be one of the |EVP_PKEY_*| values. It returns NULL if |nid| is
@@ -238,13 +237,13 @@ int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key) {
// public API.
switch (type) {
case EVP_PKEY_RSA:
return EVP_PKEY_assign_RSA(pkey, key);
return EVP_PKEY_assign_RSA(pkey, reinterpret_cast<RSA *>(key));
case EVP_PKEY_DSA:
return EVP_PKEY_assign_DSA(pkey, key);
return EVP_PKEY_assign_DSA(pkey, reinterpret_cast<DSA *>(key));
case EVP_PKEY_EC:
return EVP_PKEY_assign_EC_KEY(pkey, key);
return EVP_PKEY_assign_EC_KEY(pkey, reinterpret_cast<EC_KEY *>(key));
case EVP_PKEY_DH:
return EVP_PKEY_assign_DH(pkey, key);
return EVP_PKEY_assign_DH(pkey, reinterpret_cast<DH *>(key));
}
OPENSSL_PUT_ERROR(EVP, EVP_R_UNSUPPORTED_ALGORITHM);
@@ -67,15 +67,12 @@
static const EVP_PKEY_METHOD *const evp_methods[] = {
&rsa_pkey_meth,
&ec_pkey_meth,
&ed25519_pkey_meth,
&x25519_pkey_meth,
&hkdf_pkey_meth,
&rsa_pkey_meth, &ec_pkey_meth, &ed25519_pkey_meth,
&x25519_pkey_meth, &hkdf_pkey_meth,
};
static const EVP_PKEY_METHOD *evp_pkey_meth_find(int type) {
for (size_t i = 0; i < sizeof(evp_methods)/sizeof(EVP_PKEY_METHOD*); i++) {
for (size_t i = 0; i < sizeof(evp_methods) / sizeof(EVP_PKEY_METHOD *); i++) {
if (evp_methods[i]->pkey_id == type) {
return evp_methods[i];
}
@@ -86,7 +83,8 @@ static const EVP_PKEY_METHOD *evp_pkey_meth_find(int type) {
static EVP_PKEY_CTX *evp_pkey_ctx_new(EVP_PKEY *pkey, ENGINE *e,
const EVP_PKEY_METHOD *pmeth) {
EVP_PKEY_CTX *ret = OPENSSL_zalloc(sizeof(EVP_PKEY_CTX));
EVP_PKEY_CTX *ret =
reinterpret_cast<EVP_PKEY_CTX *>(OPENSSL_zalloc(sizeof(EVP_PKEY_CTX)));
if (!ret) {
return NULL;
}
@@ -155,7 +153,8 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *ctx) {
return NULL;
}
EVP_PKEY_CTX *ret = OPENSSL_zalloc(sizeof(EVP_PKEY_CTX));
EVP_PKEY_CTX *ret =
reinterpret_cast<EVP_PKEY_CTX *>(OPENSSL_zalloc(sizeof(EVP_PKEY_CTX)));
if (!ret) {
return NULL;
}
@@ -23,7 +23,8 @@ typedef struct dh_pkey_ctx_st {
} DH_PKEY_CTX;
static int pkey_dh_init(EVP_PKEY_CTX *ctx) {
DH_PKEY_CTX *dctx = OPENSSL_zalloc(sizeof(DH_PKEY_CTX));
DH_PKEY_CTX *dctx =
reinterpret_cast<DH_PKEY_CTX *>(OPENSSL_zalloc(sizeof(DH_PKEY_CTX)));
if (dctx == NULL) {
return 0;
}
@@ -37,8 +38,8 @@ static int pkey_dh_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) {
return 0;
}
const DH_PKEY_CTX *sctx = src->data;
DH_PKEY_CTX *dctx = dst->data;
const DH_PKEY_CTX *sctx = reinterpret_cast<DH_PKEY_CTX *>(src->data);
DH_PKEY_CTX *dctx = reinterpret_cast<DH_PKEY_CTX *>(dst->data);
dctx->pad = sctx->pad;
return 1;
}
@@ -63,14 +64,14 @@ static int pkey_dh_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) {
}
static int pkey_dh_derive(EVP_PKEY_CTX *ctx, uint8_t *out, size_t *out_len) {
DH_PKEY_CTX *dctx = ctx->data;
DH_PKEY_CTX *dctx = reinterpret_cast<DH_PKEY_CTX *>(ctx->data);
if (ctx->pkey == NULL || ctx->peerkey == NULL) {
OPENSSL_PUT_ERROR(EVP, EVP_R_KEYS_NOT_SET);
return 0;
}
DH *our_key = ctx->pkey->pkey;
DH *peer_key = ctx->peerkey->pkey;
DH *our_key = reinterpret_cast<DH *>(ctx->pkey->pkey);
DH *peer_key = reinterpret_cast<DH *>(ctx->peerkey->pkey);
if (our_key == NULL || peer_key == NULL) {
OPENSSL_PUT_ERROR(EVP, EVP_R_KEYS_NOT_SET);
return 0;
@@ -104,7 +105,7 @@ static int pkey_dh_derive(EVP_PKEY_CTX *ctx, uint8_t *out, size_t *out_len) {
}
static int pkey_dh_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
DH_PKEY_CTX *dctx = ctx->data;
DH_PKEY_CTX *dctx = reinterpret_cast<DH_PKEY_CTX *>(ctx->data);
switch (type) {
case EVP_PKEY_CTRL_PEER_KEY:
// |EVP_PKEY_derive_set_peer| requires the key implement this command,
@@ -122,13 +123,21 @@ static int pkey_dh_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
}
const EVP_PKEY_METHOD dh_pkey_meth = {
.pkey_id = EVP_PKEY_DH,
.init = pkey_dh_init,
.copy = pkey_dh_copy,
.cleanup = pkey_dh_cleanup,
.keygen = pkey_dh_keygen,
.derive = pkey_dh_derive,
.ctrl = pkey_dh_ctrl,
/*pkey_id=*/EVP_PKEY_DH,
/*init=*/pkey_dh_init,
/*copy=*/pkey_dh_copy,
/*cleanup=*/pkey_dh_cleanup,
/*keygen=*/pkey_dh_keygen,
/*sign=*/nullptr,
/*sign_message=*/nullptr,
/*verify=*/nullptr,
/*verify_message=*/nullptr,
/*verify_recover=*/nullptr,
/*encrypt=*/nullptr,
/*decrypt=*/nullptr,
/*derive=*/pkey_dh_derive,
/*paramgen=*/nullptr,
/*ctrl=*/pkey_dh_ctrl,
};
int EVP_PKEY_CTX_set_dh_pad(EVP_PKEY_CTX *ctx, int pad) {
@@ -13,21 +13,25 @@
#include <CCryptoBoringSSL_dh.h>
#include <CCryptoBoringSSL_err.h>
#include "internal.h"
#include "../internal.h"
#include "internal.h"
static void dh_free(EVP_PKEY *pkey) {
DH_free(pkey->pkey);
DH_free(reinterpret_cast<DH *>(pkey->pkey));
pkey->pkey = NULL;
}
static int dh_size(const EVP_PKEY *pkey) { return DH_size(pkey->pkey); }
static int dh_size(const EVP_PKEY *pkey) {
return DH_size(reinterpret_cast<const DH *>(pkey->pkey));
}
static int dh_bits(const EVP_PKEY *pkey) { return DH_bits(pkey->pkey); }
static int dh_bits(const EVP_PKEY *pkey) {
return DH_bits(reinterpret_cast<const DH *>(pkey->pkey));
}
static int dh_param_missing(const EVP_PKEY *pkey) {
const DH *dh = pkey->pkey;
const DH *dh = reinterpret_cast<const DH *>(pkey->pkey);
return dh == NULL || DH_get0_p(dh) == NULL || DH_get0_g(dh) == NULL;
}
@@ -37,13 +41,13 @@ static int dh_param_copy(EVP_PKEY *to, const EVP_PKEY *from) {
return 0;
}
const DH *dh = from->pkey;
const DH *dh = reinterpret_cast<DH *>(from->pkey);
const BIGNUM *q_old = DH_get0_q(dh);
BIGNUM *p = BN_dup(DH_get0_p(dh));
BIGNUM *q = q_old == NULL ? NULL : BN_dup(q_old);
BIGNUM *g = BN_dup(DH_get0_g(dh));
if (p == NULL || (q_old != NULL && q == NULL) || g == NULL ||
!DH_set0_pqg(to->pkey, p, q, g)) {
!DH_set0_pqg(reinterpret_cast<DH *>(to->pkey), p, q, g)) {
BN_free(p);
BN_free(q);
BN_free(g);
@@ -61,8 +65,8 @@ static int dh_param_cmp(const EVP_PKEY *a, const EVP_PKEY *b) {
// Matching OpenSSL, only compare p and g for PKCS#3-style Diffie-Hellman.
// OpenSSL only checks q in X9.42-style Diffie-Hellman ("DHX").
const DH *a_dh = a->pkey;
const DH *b_dh = b->pkey;
const DH *a_dh = reinterpret_cast<const DH *>(a->pkey);
const DH *b_dh = reinterpret_cast<const DH *>(b->pkey);
return BN_cmp(DH_get0_p(a_dh), DH_get0_p(b_dh)) == 0 &&
BN_cmp(DH_get0_g(a_dh), DH_get0_g(b_dh)) == 0;
}
@@ -72,21 +76,34 @@ static int dh_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b) {
return 0;
}
const DH *a_dh = a->pkey;
const DH *b_dh = b->pkey;
const DH *a_dh = reinterpret_cast<const DH *>(a->pkey);
const DH *b_dh = reinterpret_cast<const DH *>(b->pkey);
return BN_cmp(DH_get0_pub_key(a_dh), DH_get0_pub_key(b_dh)) == 0;
}
const EVP_PKEY_ASN1_METHOD dh_asn1_meth = {
.pkey_id = EVP_PKEY_DH,
.pkey_method = &dh_pkey_meth,
.pub_cmp = dh_pub_cmp,
.pkey_size = dh_size,
.pkey_bits = dh_bits,
.param_missing = dh_param_missing,
.param_copy = dh_param_copy,
.param_cmp = dh_param_cmp,
.pkey_free = dh_free,
/*pkey_id=*/EVP_PKEY_DH,
/*oid=*/{0},
/*oid_len=*/0,
/*pkey_method=*/&dh_pkey_meth,
/*pub_decode=*/nullptr,
/*pub_encode=*/nullptr,
/*pub_cmp=*/dh_pub_cmp,
/*priv_decode=*/nullptr,
/*priv_encode=*/nullptr,
/*set_priv_raw=*/nullptr,
/*set_pub_raw=*/nullptr,
/*get_priv_raw=*/nullptr,
/*get_pub_raw=*/nullptr,
/*set1_tls_encodedpoint=*/nullptr,
/*get1_tls_encodedpoint=*/nullptr,
/*pkey_opaque=*/nullptr,
/*pkey_size=*/dh_size,
/*pkey_bits=*/dh_bits,
/*param_missing=*/dh_param_missing,
/*param_copy=*/dh_param_copy,
/*param_cmp=*/dh_param_cmp,
/*pkey_free=*/dh_free,
};
int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key) {
@@ -108,7 +125,7 @@ DH *EVP_PKEY_get0_DH(const EVP_PKEY *pkey) {
OPENSSL_PUT_ERROR(EVP, EVP_R_EXPECTING_A_DH_KEY);
return NULL;
}
return pkey->pkey;
return reinterpret_cast<DH *>(const_cast<EVP_PKEY *>(pkey)->pkey);
}
DH *EVP_PKEY_get1_DH(const EVP_PKEY *pkey) {
@@ -55,9 +55,9 @@
#include <CCryptoBoringSSL_evp.h>
#include <CCryptoBoringSSL_digest.h>
#include <CCryptoBoringSSL_bn.h>
#include <CCryptoBoringSSL_bytestring.h>
#include <CCryptoBoringSSL_digest.h>
#include <CCryptoBoringSSL_dsa.h>
#include <CCryptoBoringSSL_err.h>
@@ -88,8 +88,7 @@ static int dsa_pub_decode(EVP_PKEY *out, CBS *params, CBS *key) {
goto err;
}
if (!BN_parse_asn1_unsigned(key, dsa->pub_key) ||
CBS_len(key) != 0) {
if (!BN_parse_asn1_unsigned(key, dsa->pub_key) || CBS_len(key) != 0) {
OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);
goto err;
}
@@ -103,7 +102,7 @@ err:
}
static int dsa_pub_encode(CBB *out, const EVP_PKEY *key) {
const DSA *dsa = key->pkey;
const DSA *dsa = reinterpret_cast<const DSA *>(key->pkey);
const int has_params = dsa->p != NULL && dsa->q != NULL && dsa->g != NULL;
// See RFC 5480, section 2.
@@ -112,12 +111,10 @@ static int dsa_pub_encode(CBB *out, const EVP_PKEY *key) {
!CBB_add_asn1(&spki, &algorithm, CBS_ASN1_SEQUENCE) ||
!CBB_add_asn1(&algorithm, &oid, CBS_ASN1_OBJECT) ||
!CBB_add_bytes(&oid, dsa_asn1_meth.oid, dsa_asn1_meth.oid_len) ||
(has_params &&
!DSA_marshal_parameters(&algorithm, dsa)) ||
(has_params && !DSA_marshal_parameters(&algorithm, dsa)) ||
!CBB_add_asn1(&spki, &key_bitstring, CBS_ASN1_BITSTRING) ||
!CBB_add_u8(&key_bitstring, 0 /* padding */) ||
!BN_marshal_asn1(&key_bitstring, dsa->pub_key) ||
!CBB_flush(out)) {
!BN_marshal_asn1(&key_bitstring, dsa->pub_key) || !CBB_flush(out)) {
OPENSSL_PUT_ERROR(EVP, EVP_R_ENCODE_ERROR);
return 0;
}
@@ -140,8 +137,7 @@ static int dsa_priv_decode(EVP_PKEY *out, CBS *params, CBS *key) {
if (dsa->priv_key == NULL) {
goto err;
}
if (!BN_parse_asn1_unsigned(key, dsa->priv_key) ||
CBS_len(key) != 0) {
if (!BN_parse_asn1_unsigned(key, dsa->priv_key) || CBS_len(key) != 0) {
OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);
goto err;
}
@@ -174,7 +170,7 @@ err:
}
static int dsa_priv_encode(CBB *out, const EVP_PKEY *key) {
const DSA *dsa = key->pkey;
const DSA *dsa = reinterpret_cast<const DSA *>(key->pkey);
if (dsa == NULL || dsa->priv_key == NULL) {
OPENSSL_PUT_ERROR(EVP, EVP_R_MISSING_PARAMETERS);
return 0;
@@ -189,8 +185,7 @@ static int dsa_priv_encode(CBB *out, const EVP_PKEY *key) {
!CBB_add_bytes(&oid, dsa_asn1_meth.oid, dsa_asn1_meth.oid_len) ||
!DSA_marshal_parameters(&algorithm, dsa) ||
!CBB_add_asn1(&pkcs8, &private_key, CBS_ASN1_OCTETSTRING) ||
!BN_marshal_asn1(&private_key, dsa->priv_key) ||
!CBB_flush(out)) {
!BN_marshal_asn1(&private_key, dsa->priv_key) || !CBB_flush(out)) {
OPENSSL_PUT_ERROR(EVP, EVP_R_ENCODE_ERROR);
return 0;
}
@@ -199,17 +194,17 @@ static int dsa_priv_encode(CBB *out, const EVP_PKEY *key) {
}
static int int_dsa_size(const EVP_PKEY *pkey) {
const DSA *dsa = pkey->pkey;
const DSA *dsa = reinterpret_cast<const DSA *>(pkey->pkey);
return DSA_size(dsa);
}
static int dsa_bits(const EVP_PKEY *pkey) {
const DSA *dsa = pkey->pkey;
const DSA *dsa = reinterpret_cast<const DSA *>(pkey->pkey);
return BN_num_bits(DSA_get0_p(dsa));
}
static int dsa_missing_parameters(const EVP_PKEY *pkey) {
const DSA *dsa = pkey->pkey;
const DSA *dsa = reinterpret_cast<const DSA *>(pkey->pkey);
if (DSA_get0_p(dsa) == NULL || DSA_get0_q(dsa) == NULL ||
DSA_get0_g(dsa) == NULL) {
return 1;
@@ -231,8 +226,8 @@ static int dup_bn_into(BIGNUM **out, BIGNUM *src) {
}
static int dsa_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) {
DSA *to_dsa = to->pkey;
const DSA *from_dsa = from->pkey;
DSA *to_dsa = reinterpret_cast<DSA *>(to->pkey);
const DSA *from_dsa = reinterpret_cast<const DSA *>(from->pkey);
if (!dup_bn_into(&to_dsa->p, from_dsa->p) ||
!dup_bn_into(&to_dsa->q, from_dsa->q) ||
!dup_bn_into(&to_dsa->g, from_dsa->g)) {
@@ -243,21 +238,21 @@ static int dsa_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) {
}
static int dsa_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) {
const DSA *a_dsa = a->pkey;
const DSA *b_dsa = b->pkey;
const DSA *a_dsa = reinterpret_cast<const DSA *>(a->pkey);
const DSA *b_dsa = reinterpret_cast<const DSA *>(b->pkey);
return BN_cmp(DSA_get0_p(a_dsa), DSA_get0_p(b_dsa)) == 0 &&
BN_cmp(DSA_get0_q(a_dsa), DSA_get0_q(b_dsa)) == 0 &&
BN_cmp(DSA_get0_g(a_dsa), DSA_get0_g(b_dsa)) == 0;
}
static int dsa_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b) {
const DSA *a_dsa = a->pkey;
const DSA *b_dsa = b->pkey;
const DSA *a_dsa = reinterpret_cast<const DSA *>(a->pkey);
const DSA *b_dsa = reinterpret_cast<const DSA *>(b->pkey);
return BN_cmp(DSA_get0_pub_key(b_dsa), DSA_get0_pub_key(a_dsa)) == 0;
}
static void int_dsa_free(EVP_PKEY *pkey) {
DSA_free(pkey->pkey);
DSA_free(reinterpret_cast<DSA *>(pkey->pkey));
pkey->pkey = NULL;
}
@@ -326,7 +321,7 @@ DSA *EVP_PKEY_get0_DSA(const EVP_PKEY *pkey) {
OPENSSL_PUT_ERROR(EVP, EVP_R_EXPECTING_A_DSA_KEY);
return NULL;
}
return pkey->pkey;
return reinterpret_cast<DSA *>(pkey->pkey);
}
DSA *EVP_PKEY_get1_DSA(const EVP_PKEY *pkey) {
@@ -67,9 +67,9 @@
#include <CCryptoBoringSSL_mem.h>
#include <CCryptoBoringSSL_nid.h>
#include "internal.h"
#include "../fipsmodule/ec/internal.h"
#include "../internal.h"
#include "internal.h"
typedef struct {
@@ -80,7 +80,8 @@ typedef struct {
static int pkey_ec_init(EVP_PKEY_CTX *ctx) {
EC_PKEY_CTX *dctx = OPENSSL_zalloc(sizeof(EC_PKEY_CTX));
EC_PKEY_CTX *dctx =
reinterpret_cast<EC_PKEY_CTX *>(OPENSSL_zalloc(sizeof(EC_PKEY_CTX)));
if (!dctx) {
return 0;
}
@@ -94,15 +95,15 @@ static int pkey_ec_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) {
return 0;
}
const EC_PKEY_CTX *sctx = src->data;
EC_PKEY_CTX *dctx = dst->data;
const EC_PKEY_CTX *sctx = reinterpret_cast<EC_PKEY_CTX *>(src->data);
EC_PKEY_CTX *dctx = reinterpret_cast<EC_PKEY_CTX *>(dst->data);
dctx->md = sctx->md;
dctx->gen_group = sctx->gen_group;
return 1;
}
static void pkey_ec_cleanup(EVP_PKEY_CTX *ctx) {
EC_PKEY_CTX *dctx = ctx->data;
EC_PKEY_CTX *dctx = reinterpret_cast<EC_PKEY_CTX *>(ctx->data);
if (!dctx) {
return;
}
@@ -112,7 +113,7 @@ static void pkey_ec_cleanup(EVP_PKEY_CTX *ctx) {
static int pkey_ec_sign(EVP_PKEY_CTX *ctx, uint8_t *sig, size_t *siglen,
const uint8_t *tbs, size_t tbslen) {
const EC_KEY *ec = ctx->pkey->pkey;
const EC_KEY *ec = reinterpret_cast<EC_KEY *>(ctx->pkey->pkey);
if (!sig) {
*siglen = ECDSA_size(ec);
return 1;
@@ -131,18 +132,17 @@ static int pkey_ec_sign(EVP_PKEY_CTX *ctx, uint8_t *sig, size_t *siglen,
static int pkey_ec_verify(EVP_PKEY_CTX *ctx, const uint8_t *sig, size_t siglen,
const uint8_t *tbs, size_t tbslen) {
const EC_KEY *ec_key = ctx->pkey->pkey;
const EC_KEY *ec_key = reinterpret_cast<EC_KEY *>(ctx->pkey->pkey);
return ECDSA_verify(0, tbs, tbslen, sig, siglen, ec_key);
}
static int pkey_ec_derive(EVP_PKEY_CTX *ctx, uint8_t *key,
size_t *keylen) {
static int pkey_ec_derive(EVP_PKEY_CTX *ctx, uint8_t *key, size_t *keylen) {
if (!ctx->pkey || !ctx->peerkey) {
OPENSSL_PUT_ERROR(EVP, EVP_R_KEYS_NOT_SET);
return 0;
}
const EC_KEY *eckey = ctx->pkey->pkey;
const EC_KEY *eckey = reinterpret_cast<EC_KEY *>(ctx->pkey->pkey);
if (!key) {
const EC_GROUP *group;
group = EC_KEY_get0_group(eckey);
@@ -150,7 +150,7 @@ static int pkey_ec_derive(EVP_PKEY_CTX *ctx, uint8_t *key,
return 1;
}
const EC_KEY *eckey_peer = ctx->peerkey->pkey;
const EC_KEY *eckey_peer = reinterpret_cast<EC_KEY *>(ctx->peerkey->pkey);
const EC_POINT *pubkey = EC_KEY_get0_public_key(eckey_peer);
// NB: unlike PKCS#3 DH, if *outlen is less than maximum size this is
@@ -165,11 +165,11 @@ static int pkey_ec_derive(EVP_PKEY_CTX *ctx, uint8_t *key,
}
static int pkey_ec_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
EC_PKEY_CTX *dctx = ctx->data;
EC_PKEY_CTX *dctx = reinterpret_cast<EC_PKEY_CTX *>(ctx->data);
switch (type) {
case EVP_PKEY_CTRL_MD: {
const EVP_MD *md = p2;
const EVP_MD *md = reinterpret_cast<const EVP_MD *>(p2);
int md_type = EVP_MD_type(md);
if (md_type != NID_sha1 && md_type != NID_sha224 &&
md_type != NID_sha256 && md_type != NID_sha384 &&
@@ -205,19 +205,17 @@ static int pkey_ec_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
}
static int pkey_ec_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) {
EC_PKEY_CTX *dctx = ctx->data;
EC_PKEY_CTX *dctx = reinterpret_cast<EC_PKEY_CTX *>(ctx->data);
const EC_GROUP *group = dctx->gen_group;
if (group == NULL) {
if (ctx->pkey == NULL) {
OPENSSL_PUT_ERROR(EVP, EVP_R_NO_PARAMETERS_SET);
return 0;
}
group = EC_KEY_get0_group(ctx->pkey->pkey);
group = EC_KEY_get0_group(reinterpret_cast<EC_KEY *>(ctx->pkey->pkey));
}
EC_KEY *ec = EC_KEY_new();
if (ec == NULL ||
!EC_KEY_set_group(ec, group) ||
!EC_KEY_generate_key(ec)) {
if (ec == NULL || !EC_KEY_set_group(ec, group) || !EC_KEY_generate_key(ec)) {
EC_KEY_free(ec);
return 0;
}
@@ -226,14 +224,13 @@ static int pkey_ec_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) {
}
static int pkey_ec_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) {
EC_PKEY_CTX *dctx = ctx->data;
EC_PKEY_CTX *dctx = reinterpret_cast<EC_PKEY_CTX *>(ctx->data);
if (dctx->gen_group == NULL) {
OPENSSL_PUT_ERROR(EVP, EVP_R_NO_PARAMETERS_SET);
return 0;
}
EC_KEY *ec = EC_KEY_new();
if (ec == NULL ||
!EC_KEY_set_group(ec, dctx->gen_group)) {
if (ec == NULL || !EC_KEY_set_group(ec, dctx->gen_group)) {
EC_KEY_free(ec);
return 0;
}
@@ -9,7 +9,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -66,7 +66,7 @@
static int eckey_pub_encode(CBB *out, const EVP_PKEY *key) {
const EC_KEY *ec_key = key->pkey;
const EC_KEY *ec_key = reinterpret_cast<const EC_KEY *>(key->pkey);
const EC_GROUP *group = EC_KEY_get0_group(ec_key);
const EC_POINT *public_key = EC_KEY_get0_public_key(ec_key);
@@ -101,7 +101,7 @@ static int eckey_pub_decode(EVP_PKEY *out, CBS *params, CBS *key) {
}
eckey = EC_KEY_new();
if (eckey == NULL || //
if (eckey == NULL || //
!EC_KEY_set_group(eckey, group) ||
!EC_KEY_oct2key(eckey, CBS_data(key), CBS_len(key), NULL)) {
goto err;
@@ -116,8 +116,8 @@ err:
}
static int eckey_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b) {
const EC_KEY *a_ec = a->pkey;
const EC_KEY *b_ec = b->pkey;
const EC_KEY *a_ec = reinterpret_cast<const EC_KEY *>(a->pkey);
const EC_KEY *b_ec = reinterpret_cast<const EC_KEY *>(b->pkey);
const EC_GROUP *group = EC_KEY_get0_group(b_ec);
const EC_POINT *pa = EC_KEY_get0_public_key(a_ec),
*pb = EC_KEY_get0_public_key(b_ec);
@@ -151,7 +151,7 @@ static int eckey_priv_decode(EVP_PKEY *out, CBS *params, CBS *key) {
}
static int eckey_priv_encode(CBB *out, const EVP_PKEY *key) {
const EC_KEY *ec_key = key->pkey;
const EC_KEY *ec_key = reinterpret_cast<const EC_KEY *>(key->pkey);
// Omit the redundant copy of the curve name. This contradicts RFC 5915 but
// aligns with PKCS #11. SEC 1 only says they may be omitted if known by other
@@ -179,7 +179,7 @@ static int eckey_priv_encode(CBB *out, const EVP_PKEY *key) {
static int eckey_set1_tls_encodedpoint(EVP_PKEY *pkey, const uint8_t *in,
size_t len) {
EC_KEY *ec_key = pkey->pkey;
EC_KEY *ec_key = reinterpret_cast<EC_KEY *>(pkey->pkey);
if (ec_key == NULL) {
OPENSSL_PUT_ERROR(EVP, EVP_R_NO_KEY_SET);
return 0;
@@ -190,7 +190,7 @@ static int eckey_set1_tls_encodedpoint(EVP_PKEY *pkey, const uint8_t *in,
static size_t eckey_get1_tls_encodedpoint(const EVP_PKEY *pkey,
uint8_t **out_ptr) {
const EC_KEY *ec_key = pkey->pkey;
const EC_KEY *ec_key = reinterpret_cast<const EC_KEY *>(pkey->pkey);
if (ec_key == NULL) {
OPENSSL_PUT_ERROR(EVP, EVP_R_NO_KEY_SET);
return 0;
@@ -200,12 +200,12 @@ static size_t eckey_get1_tls_encodedpoint(const EVP_PKEY *pkey,
}
static int int_ec_size(const EVP_PKEY *pkey) {
const EC_KEY *ec_key = pkey->pkey;
const EC_KEY *ec_key = reinterpret_cast<const EC_KEY *>(pkey->pkey);
return ECDSA_size(ec_key);
}
static int ec_bits(const EVP_PKEY *pkey) {
const EC_KEY *ec_key = pkey->pkey;
const EC_KEY *ec_key = reinterpret_cast<const EC_KEY *>(pkey->pkey);
const EC_GROUP *group = EC_KEY_get0_group(ec_key);
if (group == NULL) {
ERR_clear_error();
@@ -215,12 +215,12 @@ static int ec_bits(const EVP_PKEY *pkey) {
}
static int ec_missing_parameters(const EVP_PKEY *pkey) {
const EC_KEY *ec_key = pkey->pkey;
const EC_KEY *ec_key = reinterpret_cast<const EC_KEY *>(pkey->pkey);
return ec_key == NULL || EC_KEY_get0_group(ec_key) == NULL;
}
static int ec_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) {
const EC_KEY *from_key = from->pkey;
const EC_KEY *from_key = reinterpret_cast<const EC_KEY *>(from->pkey);
if (from_key == NULL) {
OPENSSL_PUT_ERROR(EVP, EVP_R_NO_KEY_SET);
return 0;
@@ -236,12 +236,12 @@ static int ec_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) {
return 0;
}
}
return EC_KEY_set_group(to->pkey, group);
return EC_KEY_set_group(reinterpret_cast<EC_KEY *>(to->pkey), group);
}
static int ec_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) {
const EC_KEY *a_ec = a->pkey;
const EC_KEY *b_ec = b->pkey;
const EC_KEY *a_ec = reinterpret_cast<const EC_KEY *>(a->pkey);
const EC_KEY *b_ec = reinterpret_cast<const EC_KEY *>(b->pkey);
if (a_ec == NULL || b_ec == NULL) {
return -2;
}
@@ -258,12 +258,12 @@ static int ec_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) {
}
static void int_ec_free(EVP_PKEY *pkey) {
EC_KEY_free(pkey->pkey);
EC_KEY_free(reinterpret_cast<EC_KEY *>(pkey->pkey));
pkey->pkey = NULL;
}
static int eckey_opaque(const EVP_PKEY *pkey) {
const EC_KEY *ec_key = pkey->pkey;
const EC_KEY *ec_key = reinterpret_cast<const EC_KEY *>(pkey->pkey);
return EC_KEY_is_opaque(ec_key);
}
@@ -320,7 +320,7 @@ EC_KEY *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey) {
OPENSSL_PUT_ERROR(EVP, EVP_R_EXPECTING_AN_EC_KEY_KEY);
return NULL;
}
return pkey->pkey;
return reinterpret_cast<EC_KEY *>(pkey->pkey);
}
EC_KEY *EVP_PKEY_get1_EC_KEY(const EVP_PKEY *pkey) {
@@ -25,7 +25,8 @@
static int pkey_ed25519_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) { return 1; }
static int pkey_ed25519_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) {
ED25519_KEY *key = OPENSSL_malloc(sizeof(ED25519_KEY));
ED25519_KEY *key =
reinterpret_cast<ED25519_KEY *>(OPENSSL_malloc(sizeof(ED25519_KEY)));
if (key == NULL) {
return 0;
}
@@ -44,7 +45,8 @@ static int pkey_ed25519_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) {
static int pkey_ed25519_sign_message(EVP_PKEY_CTX *ctx, uint8_t *sig,
size_t *siglen, const uint8_t *tbs,
size_t tbslen) {
const ED25519_KEY *key = ctx->pkey->pkey;
const ED25519_KEY *key =
reinterpret_cast<const ED25519_KEY *>(ctx->pkey->pkey);
if (!key->has_private) {
OPENSSL_PUT_ERROR(EVP, EVP_R_NOT_A_PRIVATE_KEY);
return 0;
@@ -71,7 +73,8 @@ static int pkey_ed25519_sign_message(EVP_PKEY_CTX *ctx, uint8_t *sig,
static int pkey_ed25519_verify_message(EVP_PKEY_CTX *ctx, const uint8_t *sig,
size_t siglen, const uint8_t *tbs,
size_t tbslen) {
const ED25519_KEY *key = ctx->pkey->pkey;
const ED25519_KEY *key =
reinterpret_cast<const ED25519_KEY *>(ctx->pkey->pkey);
if (siglen != 64 ||
!ED25519_verify(tbs, tbslen, sig, key->key + ED25519_PUBLIC_KEY_OFFSET)) {
OPENSSL_PUT_ERROR(EVP, EVP_R_INVALID_SIGNATURE);
@@ -82,19 +85,19 @@ static int pkey_ed25519_verify_message(EVP_PKEY_CTX *ctx, const uint8_t *sig,
}
const EVP_PKEY_METHOD ed25519_pkey_meth = {
EVP_PKEY_ED25519,
NULL /* init */,
pkey_ed25519_copy,
NULL /* cleanup */,
pkey_ed25519_keygen,
NULL /* sign */,
pkey_ed25519_sign_message,
NULL /* verify */,
pkey_ed25519_verify_message,
NULL /* verify_recover */,
NULL /* encrypt */,
NULL /* decrypt */,
NULL /* derive */,
NULL /* paramgen */,
NULL /* ctrl */,
/*pkey_id=*/EVP_PKEY_ED25519,
/*init=*/nullptr,
/*copy=*/pkey_ed25519_copy,
/*cleanup=*/nullptr,
/*keygen=*/pkey_ed25519_keygen,
/*sign=*/nullptr,
/*sign_message=*/pkey_ed25519_sign_message,
/*verify=*/nullptr,
/*verify_message=*/pkey_ed25519_verify_message,
/*verify_recover=*/nullptr,
/*encrypt=*/nullptr,
/*decrypt=*/nullptr,
/*derive=*/nullptr,
/*paramgen=*/nullptr,
/*ctrl=*/nullptr,
};
@@ -19,8 +19,8 @@
#include <CCryptoBoringSSL_err.h>
#include <CCryptoBoringSSL_mem.h>
#include "internal.h"
#include "../internal.h"
#include "internal.h"
static void ed25519_free(EVP_PKEY *pkey) {
@@ -34,7 +34,8 @@ static int ed25519_set_priv_raw(EVP_PKEY *pkey, const uint8_t *in, size_t len) {
return 0;
}
ED25519_KEY *key = OPENSSL_malloc(sizeof(ED25519_KEY));
ED25519_KEY *key =
reinterpret_cast<ED25519_KEY *>(OPENSSL_malloc(sizeof(ED25519_KEY)));
if (key == NULL) {
return 0;
}
@@ -56,7 +57,8 @@ static int ed25519_set_pub_raw(EVP_PKEY *pkey, const uint8_t *in, size_t len) {
return 0;
}
ED25519_KEY *key = OPENSSL_malloc(sizeof(ED25519_KEY));
ED25519_KEY *key =
reinterpret_cast<ED25519_KEY *>(OPENSSL_malloc(sizeof(ED25519_KEY)));
if (key == NULL) {
return 0;
}
@@ -71,7 +73,7 @@ static int ed25519_set_pub_raw(EVP_PKEY *pkey, const uint8_t *in, size_t len) {
static int ed25519_get_priv_raw(const EVP_PKEY *pkey, uint8_t *out,
size_t *out_len) {
const ED25519_KEY *key = pkey->pkey;
const ED25519_KEY *key = reinterpret_cast<const ED25519_KEY *>(pkey->pkey);
if (!key->has_private) {
OPENSSL_PUT_ERROR(EVP, EVP_R_NOT_A_PRIVATE_KEY);
return 0;
@@ -95,7 +97,7 @@ static int ed25519_get_priv_raw(const EVP_PKEY *pkey, uint8_t *out,
static int ed25519_get_pub_raw(const EVP_PKEY *pkey, uint8_t *out,
size_t *out_len) {
const ED25519_KEY *key = pkey->pkey;
const ED25519_KEY *key = reinterpret_cast<const ED25519_KEY *>(pkey->pkey);
if (out == NULL) {
*out_len = 32;
return 1;
@@ -124,7 +126,7 @@ static int ed25519_pub_decode(EVP_PKEY *out, CBS *params, CBS *key) {
}
static int ed25519_pub_encode(CBB *out, const EVP_PKEY *pkey) {
const ED25519_KEY *key = pkey->pkey;
const ED25519_KEY *key = reinterpret_cast<const ED25519_KEY *>(pkey->pkey);
// See RFC 8410, section 4.
CBB spki, algorithm, oid, key_bitstring;
@@ -145,8 +147,8 @@ static int ed25519_pub_encode(CBB *out, const EVP_PKEY *pkey) {
}
static int ed25519_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b) {
const ED25519_KEY *a_key = a->pkey;
const ED25519_KEY *b_key = b->pkey;
const ED25519_KEY *a_key = reinterpret_cast<const ED25519_KEY *>(a->pkey);
const ED25519_KEY *b_key = reinterpret_cast<const ED25519_KEY *>(b->pkey);
return OPENSSL_memcmp(a_key->key + ED25519_PUBLIC_KEY_OFFSET,
b_key->key + ED25519_PUBLIC_KEY_OFFSET, 32) == 0;
}
@@ -158,8 +160,7 @@ static int ed25519_priv_decode(EVP_PKEY *out, CBS *params, CBS *key) {
// OCTET STRING layer.
CBS inner;
if (CBS_len(params) != 0 ||
!CBS_get_asn1(key, &inner, CBS_ASN1_OCTETSTRING) ||
CBS_len(key) != 0) {
!CBS_get_asn1(key, &inner, CBS_ASN1_OCTETSTRING) || CBS_len(key) != 0) {
OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);
return 0;
}
@@ -168,7 +169,7 @@ static int ed25519_priv_decode(EVP_PKEY *out, CBS *params, CBS *key) {
}
static int ed25519_priv_encode(CBB *out, const EVP_PKEY *pkey) {
const ED25519_KEY *key = pkey->pkey;
const ED25519_KEY *key = reinterpret_cast<const ED25519_KEY *>(pkey->pkey);
if (!key->has_private) {
OPENSSL_PUT_ERROR(EVP, EVP_R_NOT_A_PRIVATE_KEY);
return 0;
@@ -185,7 +186,7 @@ static int ed25519_priv_encode(CBB *out, const EVP_PKEY *pkey) {
!CBB_add_asn1(&private_key, &inner, CBS_ASN1_OCTETSTRING) ||
// The PKCS#8 encoding stores only the 32-byte seed which is the first 32
// bytes of the private key.
!CBB_add_bytes(&inner, key->key, 32) ||
!CBB_add_bytes(&inner, key->key, 32) || //
!CBB_flush(out)) {
OPENSSL_PUT_ERROR(EVP, EVP_R_ENCODE_ERROR);
return 0;
Loaded 100 of 351 files, more files were not shown because too many files have changed in this diff. Show more