diff --git a/CHANGELOG.md b/CHANGELOG.md index d5f5c40..52424de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 0.4.2-wip - Update BoringSSL to e98a6564. +- Update BoringSSL to 64188f17. ## 0.4.1 diff --git a/lib/src/bindings/boringssl.g.dart b/lib/src/bindings/boringssl.g.dart index 32916f6..584ce32 100644 --- a/lib/src/bindings/boringssl.g.dart +++ b/lib/src/bindings/boringssl.g.dart @@ -1008,7 +1008,7 @@ external int ASN1_STRING_copy( /// representation that does not always correspond to the DER encoding of the /// type. See the documentation for `ASN1_STRING` for details. /// -/// Prefer `ASN1_STRING_get0_data`. +/// Prefer `ASN1_STRING_get0_data`. See crbug.com/574019297. @meta.RecordUse() @ffi.Native Function(ffi.Pointer)>( symbol: 'bssl_dart_ASN1_STRING_data', @@ -1057,7 +1057,21 @@ external ffi.Pointer ASN1_STRING_get0_data( ) external int ASN1_STRING_get_default_mask(); -/// ASN1_STRING_length returns the length of `str`, in bytes. +/// ASN1_STRING_get_length returns the length of `str`, in bytes. +/// +/// The contents of an `ASN1_STRING` encode the value in some type-specific +/// representation that does not always correspond to the DER encoding of the +/// type. See the documentation for `ASN1_STRING` for details. +@meta.RecordUse() +@ffi.Native)>( + symbol: 'bssl_dart_ASN1_STRING_get_length', +) +external int ASN1_STRING_get_length( + ffi.Pointer str, +); + +/// ASN1_STRING_length returns the length of `str`, in bytes. Prefer +/// `ASN1_STRING_get_length`. /// /// The contents of an `ASN1_STRING` encode the value in some type-specific /// representation that does not always correspond to the DER encoding of the @@ -2381,6 +2395,16 @@ external int BIO_do_connect( ffi.Pointer bio, ); +/// BIO_dup_ref increments the reference count of `bio` and returns the same +/// handle. +@meta.RecordUse() +@ffi.Native Function(ffi.Pointer)>( + symbol: 'bssl_dart_BIO_dup_ref', +) +external ffi.Pointer BIO_dup_ref( + ffi.Pointer bio, +); + /// BIO_eof returns non-zero when `bio` has reached end-of-file. The precise /// meaning of which depends on the concrete type of `bio`. Note that in the /// case of BIO_pair this always returns non-zero. @@ -7338,6 +7362,106 @@ external void CONF_modules_unload( int all, ); +/// CPACE_CTX_free frees `ctx` and all the resources that it has allocated. +@meta.RecordUse() +@ffi.Native)>( + symbol: 'bssl_dart_CPACE_CTX_free', +) +external void CPACE_CTX_free( + ffi.Pointer ctx, +); + +/// CPACE_CTX_new returns a newly-allocated `CPACE_CTX` object that implements +/// one side of the CPace protocol, or nullptr on error. This function implements +/// CPACE-X25519-SHA512 in initiator-responder mode, acting as `role` and with +/// `password` as the password-related string (PRS). +/// +/// `channel_id` and `session_id` are the channel identifier (CI) and session +/// identifier (sid) values, respectively. Both values must match for the +/// exchange to proceed. `assoc_data` is the cleartext associated data (ADa or +/// ADb) to be sent to the peer. These values may be empty if not used. See +/// Section 4.1 of draft-irtf-cfrg-cpace-21 for details. +/// +/// The application-level identities of each party in the protocol should be +/// incorporated into either `channel_id` or each party's respective `assoc_data` +/// values. See Section 10.1 of draft-irtf-cfrg-cpace-21. +/// +/// Once a `CPACE_CTX` is successfully created, the caller should call +/// `CPACE_generate_msg` to generate the message to send to the peer. +@meta.RecordUse() +@ffi.Native< + ffi.Pointer Function( + ffi.UnsignedInt, + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Size, + ) +>(symbol: 'bssl_dart_CPACE_CTX_new') +external ffi.Pointer CPACE_CTX_new( + int role, + ffi.Pointer password, + int password_len, + ffi.Pointer channel_id, + int channel_id_len, + ffi.Pointer assoc_data, + int assoc_data_len, + ffi.Pointer session_id, + int session_id_len, +); + +/// CPACE_generate_msg generates the message to be sent to the peer. On success, +/// it writes the message to `out_msg` and returns one. Otherwise, it returns +/// zero. `ctx` must have been allocated by `CPACE_CTX_new`, with no subsequent +/// functions called on it. +/// +/// `out_msg` only contains the Ya or Yb value. It does not include ADa or ADb. +/// On success, the caller should separately send `out_msg` and their +/// `assoc_data` value to the peer. It is the caller's responsibility to send +/// `assoc_data` together with `out_msg`. After receiving the peer's reply, the +/// caller should call `CPACE_process_msg` to complete the protocol. +@meta.RecordUse() +@ffi.Native, ffi.Pointer)>( + symbol: 'bssl_dart_CPACE_generate_msg', +) +external int CPACE_generate_msg( + ffi.Pointer ctx, + ffi.Pointer out_msg, +); + +/// CPACE_process_msg processes `msg` and `peer_assoc_data` from the peer and +/// computes the shared secret, or intermediate session key (ISK). On success, it +/// writes the secret to `out_shared_secret` and returns one; it also writes a +/// derived session ID if `out_sid` is not NULL. Otherwise, it returns zero. +/// `ctx` must have successfully been passed to `CPACE_generate_msg`, with no +/// subsequent functions called on it. +/// +/// `msg` should contain the peer's Ya or Yb value, and `peer_assoc_data` the +/// peer's ADa or ADb value. +@meta.RecordUse() +@ffi.Native< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Size, + ffi.Pointer, + ffi.Pointer, + ) +>(symbol: 'bssl_dart_CPACE_process_msg') +external int CPACE_process_msg( + ffi.Pointer ctx, + ffi.Pointer in_msg, + ffi.Pointer peer_assoc_data, + int peer_assoc_data_len, + ffi.Pointer shared_secret, + ffi.Pointer sid_out, +); + /// CRL_DIST_POINTS_free releases memory associated with `crldp`. @meta.RecordUse() @ffi.Native)>( @@ -7355,6 +7479,17 @@ external void CRL_DIST_POINTS_free( ) external ffi.Pointer CRL_DIST_POINTS_new(); +/// CRYPTO_BUFFER_POOL_dup_ref increments the reference count of `pool` and +/// returns the same handle. It does not mutate `pool` for thread-safety purposes +/// and may be used concurrently. +@meta.RecordUse() +@ffi.Native< + ffi.Pointer Function(ffi.Pointer) +>(symbol: 'bssl_dart_CRYPTO_BUFFER_POOL_dup_ref') +external ffi.Pointer CRYPTO_BUFFER_POOL_dup_ref( + ffi.Pointer pool, +); + /// CRYPTO_BUFFER_POOL_free decrements the reference count of `pool` and frees it /// if the reference count drops to zero. @meta.RecordUse() @@ -8094,6 +8229,17 @@ external int DH_compute_key_padded( ffi.Pointer dh, ); +/// DH_dup_ref increments the reference count of `dh` and returns the same +/// handle. It does not mutate `dh` for thread-safety purposes and may be used +/// concurrently. +@meta.RecordUse() +@ffi.Native Function(ffi.Pointer)>( + symbol: 'bssl_dart_DH_dup_ref', +) +external ffi.Pointer DH_dup_ref( + ffi.Pointer dh, +); + /// DH_free decrements the reference count of `dh` and frees it if the reference /// count drops to zero. @meta.RecordUse() @@ -8569,6 +8715,17 @@ external ffi.Pointer DSA_dup_DH( ffi.Pointer dsa, ); +/// DSA_dup_ref increments the reference count of `dsa` and returns the same +/// handle. It does not mutate `dsa` for thread-safety purposes and may be used +/// concurrently. +@meta.RecordUse() +@ffi.Native Function(ffi.Pointer)>( + symbol: 'bssl_dart_DSA_dup_ref', +) +external ffi.Pointer DSA_dup_ref( + ffi.Pointer dsa, +); + /// DSA_free decrements the reference count of `dsa` and frees it if the /// reference count drops to zero. @meta.RecordUse() @@ -9664,6 +9821,17 @@ external ffi.Pointer EC_KEY_dup( ffi.Pointer src, ); +/// EC_KEY_dup_ref increases the reference count of `key` and returns the same +/// handle. It does not mutate `key` for thread-safety purposes and may be used +/// concurrently. +@meta.RecordUse() +@ffi.Native Function(ffi.Pointer)>( + symbol: 'bssl_dart_EC_KEY_dup_ref', +) +external ffi.Pointer EC_KEY_dup_ref( + ffi.Pointer key, +); + /// EC_KEY_free frees all the data owned by `key` and `key` itself. @meta.RecordUse() @ffi.Native)>( @@ -12923,9 +13091,6 @@ external int EVP_DigestSignFinal( /// Ed25519, `type` should be NULL. The `EVP_MD_CTX` itself is unused but is /// present so the API is uniform. See `EVP_DigestSign`. /// -/// This function does not mutate `pkey` for thread-safety purposes and may be -/// used concurrently with other non-mutating functions on `pkey`. -/// /// It returns one on success, or zero on error. @meta.RecordUse() @ffi.Native< @@ -13020,9 +13185,6 @@ external int EVP_DigestVerifyFinal( /// Ed25519, `type` should be NULL. The `EVP_MD_CTX` itself is unused but is /// present so the API is uniform. See `EVP_DigestVerify`. /// -/// This function does not mutate `pkey` for thread-safety purposes and may be -/// used concurrently with other non-mutating functions on `pkey`. -/// /// It returns one on success, or zero on error. @meta.RecordUse() @ffi.Native< @@ -15535,11 +15697,6 @@ external ffi.Pointer EVP_RSA_gen( /// actual size of the signature is written to `*out_sig_len`. /// /// It returns one on success and zero otherwise. -/// -/// It does not modify `ctx`, thus it's possible to continue to use `ctx` in -/// order to sign a longer message. It also does not mutate `pkey` for -/// thread-safety purposes and may be used concurrently with other non-mutating -/// functions on `pkey`. @meta.RecordUse() @ffi.Native< ffi.Int Function( @@ -15605,11 +15762,6 @@ external int EVP_SignUpdate( /// calls to `EVP_VerifyUpdate`. /// /// It returns one on success and zero otherwise. -/// -/// It does not modify `ctx`, thus it's possible to continue to use `ctx` in -/// order to verify a longer message. It also does not mutate `pkey` for -/// thread-safety purposes and may be used concurrently with other non-mutating -/// functions on `pkey`. @meta.RecordUse() @ffi.Native< ffi.Int Function( @@ -16595,6 +16747,23 @@ external ffi.Pointer EVP_sha256(); @ffi.Native Function()>(symbol: 'bssl_dart_EVP_sha384') external ffi.Pointer EVP_sha384(); +/// SHA-3 family of digest functions. +/// +/// WARNING: Prefer to use SHA-2 (e.g. `EVP_sha256`) over SHA-3. Despite being a +/// newer hash function, SHA-3 performs poorly and should only be used when +/// necessary for interoperability with existing systems. +@meta.RecordUse() +@ffi.Native Function()>(symbol: 'bssl_dart_EVP_sha3_256') +external ffi.Pointer EVP_sha3_256(); + +@meta.RecordUse() +@ffi.Native Function()>(symbol: 'bssl_dart_EVP_sha3_384') +external ffi.Pointer EVP_sha3_384(); + +@meta.RecordUse() +@ffi.Native Function()>(symbol: 'bssl_dart_EVP_sha3_512') +external ffi.Pointer EVP_sha3_512(); + @meta.RecordUse() @ffi.Native Function()>(symbol: 'bssl_dart_EVP_sha512') external ffi.Pointer EVP_sha512(); @@ -20533,6 +20702,17 @@ external int RSA_decrypt( int padding, ); +/// RSA_dup_ref increments the reference count of `rsa` and returns the same +/// handle. It does not mutate `rsa` for thread-safety purposes and may be used +/// concurrently. +@meta.RecordUse() +@ffi.Native Function(ffi.Pointer)>( + symbol: 'bssl_dart_RSA_dup_ref', +) +external ffi.Pointer RSA_dup_ref( + ffi.Pointer rsa, +); + /// RSA_encrypt encrypts `in_len` bytes from `in` to the public key from `rsa` /// and writes, at most, `max_out` bytes of encrypted data to `out`. The /// `max_out` argument must be, at least, `RSA_size` in order to ensure success. @@ -23066,6 +23246,16 @@ external ffi.Pointer X509_CRL_dup( ffi.Pointer crl, ); +/// X509_CRL_dup_ref adds one to the reference count of `crl` and returns the +/// same. +@meta.RecordUse() +@ffi.Native Function(ffi.Pointer)>( + symbol: 'bssl_dart_X509_CRL_dup_ref', +) +external ffi.Pointer X509_CRL_dup_ref( + ffi.Pointer crl, +); + /// X509_CRL_free decrements `crl`'s reference count and, if zero, releases /// memory associated with `crl`. @meta.RecordUse() @@ -25399,16 +25589,6 @@ external ffi.Pointer X509_STORE_CTX_get0_chain( ffi.Pointer ctx, ); -/// X509_STORE_CTX_get0_current_crl returns the CRL which caused the error -/// returned by `X509_STORE_CTX_get_error`. -@meta.RecordUse() -@ffi.Native Function(ffi.Pointer)>( - symbol: 'bssl_dart_X509_STORE_CTX_get0_current_crl', -) -external ffi.Pointer X509_STORE_CTX_get0_current_crl( - ffi.Pointer ctx, -); - /// X509_STORE_CTX_get0_param returns `ctx`'s verification parameters. This /// object is mutable and may be modified by the caller. @meta.RecordUse() @@ -25986,6 +26166,16 @@ external ffi.Pointer X509_STORE_add_lookup( ffi.Pointer method, ); +/// X509_STORE_dup_ref adds one to the reference count of `store` and returns +/// the same handle. +@meta.RecordUse() +@ffi.Native Function(ffi.Pointer)>( + symbol: 'bssl_dart_X509_STORE_dup_ref', +) +external ffi.Pointer X509_STORE_dup_ref( + ffi.Pointer store, +); + /// X509_STORE_free releases memory associated with `store`. @meta.RecordUse() @ffi.Native)>( @@ -27931,8 +28121,7 @@ external int X509_set_notBefore( ); /// X509_set_pubkey sets `x509`'s public key to `pkey`. It returns one on success -/// and zero on error. This function does not take ownership of `pkey` and -/// internally copies and updates reference counts as needed. +/// and zero on error. @meta.RecordUse() @ffi.Native, ffi.Pointer)>( symbol: 'bssl_dart_X509_set_pubkey', @@ -31827,6 +32016,9 @@ extension SymbolAddresses on _SymbolAddresses { ffi.Pointer> get CONF_modules_free => ffi.Native.addressOf(self.CONF_modules_free); @meta.RecordUse() + ffi.Pointer)>> + get CPACE_CTX_free => ffi.Native.addressOf(self.CPACE_CTX_free); + @meta.RecordUse() ffi.Pointer< ffi.NativeFunction)> > @@ -32309,6 +32501,8 @@ const int CBS_ASN1_PRINTABLESTRING = 19; const int CBS_ASN1_PRIVATE = 3221225472; +const int CBS_ASN1_RELATIVE_OID = 13; + const int CBS_ASN1_SEQUENCE = 536870928; const int CBS_ASN1_SET = 536870929; @@ -32348,6 +32542,7 @@ final class CMS_SignerInfo_st extends ffi.Opaque {} typedef CONF = conf_st; typedef CONF_VALUE = conf_value_st; +typedef CPACE_CTX = cpace_ctx_st; typedef CRL_DIST_POINTS = stack_st_DIST_POINT; typedef CRYPTO_BUFFER = crypto_buffer_st; typedef CRYPTO_BUFFER_POOL = crypto_buffer_pool_st; @@ -32447,9 +32642,6 @@ final class DIST_POINT_NAME_st extends ffi.Struct { external int type; external UnnamedUnion$4 name; - - /// If relativename then this contains the full distribution point name - external ffi.Pointer dpname; } /// A DIST_POINT_st, aka `DIST_POINT`, represents a DistributionPoint structure @@ -32813,9 +33005,9 @@ const int EVP_MAX_IV_LENGTH = 16; const int EVP_MAX_KEY_LENGTH = 64; -const int EVP_MAX_MD_BLOCK_SIZE = 128; +const int EVP_MAX_MD_BLOCK_SIZE = 136; -const int EVP_MAX_MD_DATA_SIZE = 208; +const int EVP_MAX_MD_DATA_SIZE = 240; const int EVP_MAX_MD_SIZE = 64; @@ -33114,11 +33306,11 @@ const int NID_OCSP_sign = 180; const int NID_Private = 385; -const int NID_SLH_DSA_SHA2_128s = 979; +const int NID_SLH_DSA_SHA2_128s = 973; -const int NID_SLH_DSA_SHA2_128s_WITH_SHA256 = 981; +const int NID_SLH_DSA_SHA2_128s_WITH_SHA256 = 975; -const int NID_SLH_DSA_SHAKE_256f = 980; +const int NID_SLH_DSA_SHAKE_256f = 974; const int NID_SMIME = 188; @@ -33300,7 +33492,7 @@ const int NID_aes_256_ofb128 = 428; const int NID_aes_256_xts = 914; -const int NID_alg_mtcProof_draft = 976; +const int NID_alg_mtcProof = 976; const int NID_algorithm = 376; @@ -34370,7 +34562,7 @@ const int NID_pbes2 = 161; const int NID_pbmac1 = 162; -const int NID_pe_mtcCertificationAuthority_draft = 978; +const int NID_pe_mtcCertificationAuthority_SHA256 = 978; const int NID_personalSignature = 499; @@ -34500,7 +34692,7 @@ const int NID_rc5_ecb = 121; const int NID_rc5_ofb64 = 123; -const int NID_rdna_trustAnchorID_draft = 977; +const int NID_rdna_trustAnchorID = 977; const int NID_registeredAddress = 870; @@ -35602,7 +35794,7 @@ final class UnnamedUnion$1 extends ffi.Union { /// md_data contains the hash-specific context. final class UnnamedUnion$2 extends ffi.Union { - @ffi.Array.multi([208]) + @ffi.Array.multi([240]) external ffi.Array md_data; @ffi.Uint64() @@ -35725,6 +35917,8 @@ const int V_ASN1_PRIVATE = 192; const int V_ASN1_REAL = 9; +const int V_ASN1_RELATIVE_OID = 13; + const int V_ASN1_SEQUENCE = 16; const int V_ASN1_SET = 17; @@ -36203,7 +36397,7 @@ const int X509_V_FLAG_ALLOW_TIMEZONE_OFFSET = 16777216; const int X509_V_FLAG_CB_ISSUER_CHECK = 1; -const int X509_V_FLAG_CHECK_SS_SIGNATURE = 16384; +const int X509_V_FLAG_CHECK_SS_SIGNATURE = 0; const int X509_V_FLAG_CRL_CHECK = 4; @@ -36235,7 +36429,7 @@ const int X509_V_FLAG_USE_CHECK_TIME = 2; const int X509_V_FLAG_USE_DELTAS = 8192; -const int X509_V_FLAG_USE_MTC_DRAFT_PLANTS_05 = 4194304; +const int X509_V_FLAG_USE_MTC_DRAFT_PLANTS_07 = 4194304; const int X509_V_FLAG_X509_STRICT = 0; @@ -37131,6 +37325,17 @@ typedef cookie_write_function_t = ) >; +final class cpace_ctx_st extends ffi.Opaque {} + +/// The role that a party plays in the CPACE key agreement protocol. +sealed class cpace_role_t { + /// This role corresponds to the party A in the specification. + static const cpace_role_initiator = 0; + + /// This role corresponds to the party B in the specification. + static const cpace_role_responder = 1; +} + final class crypto_buffer_pool_st extends ffi.Opaque {} final class crypto_buffer_st extends ffi.Opaque {} diff --git a/lib/src/bindings/record_use_mapping.g.dart b/lib/src/bindings/record_use_mapping.g.dart index e680561..f8fd78c 100644 --- a/lib/src/bindings/record_use_mapping.g.dart +++ b/lib/src/bindings/record_use_mapping.g.dart @@ -93,6 +93,7 @@ const recordUseMapping = { 'ASN1_STRING_free': 'bssl_dart_ASN1_STRING_free', 'ASN1_STRING_get0_data': 'bssl_dart_ASN1_STRING_get0_data', 'ASN1_STRING_get_default_mask': 'bssl_dart_ASN1_STRING_get_default_mask', + 'ASN1_STRING_get_length': 'bssl_dart_ASN1_STRING_get_length', 'ASN1_STRING_length': 'bssl_dart_ASN1_STRING_length', 'ASN1_STRING_new': 'bssl_dart_ASN1_STRING_new', 'ASN1_STRING_print': 'bssl_dart_ASN1_STRING_print', @@ -182,6 +183,7 @@ const recordUseMapping = { 'BIO_ctrl_get_write_guarantee': 'bssl_dart_BIO_ctrl_get_write_guarantee', 'BIO_ctrl_pending': 'bssl_dart_BIO_ctrl_pending', 'BIO_do_connect': 'bssl_dart_BIO_do_connect', + 'BIO_dup_ref': 'bssl_dart_BIO_dup_ref', 'BIO_eof': 'bssl_dart_BIO_eof', 'BIO_find_type': 'bssl_dart_BIO_find_type', 'BIO_flush': 'bssl_dart_BIO_flush', @@ -543,8 +545,13 @@ const recordUseMapping = { 'CONF_modules_free': 'bssl_dart_CONF_modules_free', 'CONF_modules_load_file': 'bssl_dart_CONF_modules_load_file', 'CONF_modules_unload': 'bssl_dart_CONF_modules_unload', + 'CPACE_CTX_free': 'bssl_dart_CPACE_CTX_free', + 'CPACE_CTX_new': 'bssl_dart_CPACE_CTX_new', + 'CPACE_generate_msg': 'bssl_dart_CPACE_generate_msg', + 'CPACE_process_msg': 'bssl_dart_CPACE_process_msg', 'CRL_DIST_POINTS_free': 'bssl_dart_CRL_DIST_POINTS_free', 'CRL_DIST_POINTS_new': 'bssl_dart_CRL_DIST_POINTS_new', + 'CRYPTO_BUFFER_POOL_dup_ref': 'bssl_dart_CRYPTO_BUFFER_POOL_dup_ref', 'CRYPTO_BUFFER_POOL_free': 'bssl_dart_CRYPTO_BUFFER_POOL_free', 'CRYPTO_BUFFER_POOL_new': 'bssl_dart_CRYPTO_BUFFER_POOL_new', 'CRYPTO_BUFFER_POOL_up_ref': 'bssl_dart_CRYPTO_BUFFER_POOL_up_ref', @@ -602,6 +609,7 @@ const recordUseMapping = { 'DH_compute_key': 'bssl_dart_DH_compute_key', 'DH_compute_key_hashed': 'bssl_dart_DH_compute_key_hashed', 'DH_compute_key_padded': 'bssl_dart_DH_compute_key_padded', + 'DH_dup_ref': 'bssl_dart_DH_dup_ref', 'DH_free': 'bssl_dart_DH_free', 'DH_generate_key': 'bssl_dart_DH_generate_key', 'DH_generate_parameters_ex': 'bssl_dart_DH_generate_parameters_ex', @@ -642,6 +650,7 @@ const recordUseMapping = { 'DSA_do_sign': 'bssl_dart_DSA_do_sign', 'DSA_do_verify': 'bssl_dart_DSA_do_verify', 'DSA_dup_DH': 'bssl_dart_DSA_dup_DH', + 'DSA_dup_ref': 'bssl_dart_DSA_dup_ref', 'DSA_free': 'bssl_dart_DSA_free', 'DSA_generate_key': 'bssl_dart_DSA_generate_key', 'DSA_generate_parameters_ex': 'bssl_dart_DSA_generate_parameters_ex', @@ -715,6 +724,7 @@ const recordUseMapping = { 'EC_KEY_check_key': 'bssl_dart_EC_KEY_check_key', 'EC_KEY_derive_from_secret': 'bssl_dart_EC_KEY_derive_from_secret', 'EC_KEY_dup': 'bssl_dart_EC_KEY_dup', + 'EC_KEY_dup_ref': 'bssl_dart_EC_KEY_dup_ref', 'EC_KEY_free': 'bssl_dart_EC_KEY_free', 'EC_KEY_generate_key': 'bssl_dart_EC_KEY_generate_key', 'EC_KEY_generate_key_fips': 'bssl_dart_EC_KEY_generate_key_fips', @@ -1241,6 +1251,9 @@ const recordUseMapping = { 'EVP_sha224': 'bssl_dart_EVP_sha224', 'EVP_sha256': 'bssl_dart_EVP_sha256', 'EVP_sha384': 'bssl_dart_EVP_sha384', + 'EVP_sha3_256': 'bssl_dart_EVP_sha3_256', + 'EVP_sha3_384': 'bssl_dart_EVP_sha3_384', + 'EVP_sha3_512': 'bssl_dart_EVP_sha3_512', 'EVP_sha512': 'bssl_dart_EVP_sha512', 'EVP_sha512_256': 'bssl_dart_EVP_sha512_256', 'EXTENDED_KEY_USAGE_free': 'bssl_dart_EXTENDED_KEY_USAGE_free', @@ -1545,6 +1558,7 @@ const recordUseMapping = { 'RSA_check_fips': 'bssl_dart_RSA_check_fips', 'RSA_check_key': 'bssl_dart_RSA_check_key', 'RSA_decrypt': 'bssl_dart_RSA_decrypt', + 'RSA_dup_ref': 'bssl_dart_RSA_dup_ref', 'RSA_encrypt': 'bssl_dart_RSA_encrypt', 'RSA_flags': 'bssl_dart_RSA_flags', 'RSA_free': 'bssl_dart_RSA_free', @@ -1693,6 +1707,7 @@ const recordUseMapping = { 'X509_CRL_delete_ext': 'bssl_dart_X509_CRL_delete_ext', 'X509_CRL_digest': 'bssl_dart_X509_CRL_digest', 'X509_CRL_dup': 'bssl_dart_X509_CRL_dup', + 'X509_CRL_dup_ref': 'bssl_dart_X509_CRL_dup_ref', 'X509_CRL_free': 'bssl_dart_X509_CRL_free', 'X509_CRL_get0_by_cert': 'bssl_dart_X509_CRL_get0_by_cert', 'X509_CRL_get0_by_serial': 'bssl_dart_X509_CRL_get0_by_serial', @@ -1860,8 +1875,6 @@ const recordUseMapping = { 'X509_STORE_CTX_free': 'bssl_dart_X509_STORE_CTX_free', 'X509_STORE_CTX_get0_cert': 'bssl_dart_X509_STORE_CTX_get0_cert', 'X509_STORE_CTX_get0_chain': 'bssl_dart_X509_STORE_CTX_get0_chain', - 'X509_STORE_CTX_get0_current_crl': - 'bssl_dart_X509_STORE_CTX_get0_current_crl', 'X509_STORE_CTX_get0_param': 'bssl_dart_X509_STORE_CTX_get0_param', 'X509_STORE_CTX_get0_parent_ctx': 'bssl_dart_X509_STORE_CTX_get0_parent_ctx', 'X509_STORE_CTX_get0_store': 'bssl_dart_X509_STORE_CTX_get0_store', @@ -1900,6 +1913,7 @@ const recordUseMapping = { 'X509_STORE_add_cert': 'bssl_dart_X509_STORE_add_cert', 'X509_STORE_add_crl': 'bssl_dart_X509_STORE_add_crl', 'X509_STORE_add_lookup': 'bssl_dart_X509_STORE_add_lookup', + 'X509_STORE_dup_ref': 'bssl_dart_X509_STORE_dup_ref', 'X509_STORE_free': 'bssl_dart_X509_STORE_free', 'X509_STORE_get0_objects': 'bssl_dart_X509_STORE_get0_objects', 'X509_STORE_get0_param': 'bssl_dart_X509_STORE_get0_param', diff --git a/third_party/boringssl/gen/bcm/aesni-gcm-x86_64-win.asm b/third_party/boringssl/gen/bcm/aesni-gcm-x86_64-win.asm index a17d4f4..258862e 100644 --- a/third_party/boringssl/gen/bcm/aesni-gcm-x86_64-win.asm +++ b/third_party/boringssl/gen/bcm/aesni-gcm-x86_64-win.asm @@ -967,7 +967,7 @@ $L$one_lsb: DB 89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112 DB 114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0 ALIGN 64 -section .text +section .text code align=64 section .pdata rdata align=4 ALIGN 4 diff --git a/third_party/boringssl/gen/bcm/aesni-x86_64-win.asm b/third_party/boringssl/gen/bcm/aesni-x86_64-win.asm index 7f55ea4..9a79ff0 100644 --- a/third_party/boringssl/gen/bcm/aesni-x86_64-win.asm +++ b/third_party/boringssl/gen/bcm/aesni-x86_64-win.asm @@ -2499,7 +2499,7 @@ $L$key_rcon1b: DB 32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115 DB 115,108,46,111,114,103,62,0 ALIGN 64 -section .text +section .text code align=64 EXTERN __imp_RtlVirtualUnwind @@ -2695,7 +2695,7 @@ $L$SEH_info_ctr32: $L$SEH_info_cbc: DB 9,0,0,0 DD cbc_se_handler wrt ..imagebase -section .pdata +section .pdata rdata align=4 ALIGN 4 DD $L$SEH_begin_aes_hw_set_encrypt_key_base_1 wrt ..imagebase DD $L$SEH_end_aes_hw_set_encrypt_key_base_4 wrt ..imagebase @@ -2706,7 +2706,7 @@ ALIGN 4 DD $L$SEH_info_aes_hw_set_encrypt_key_alt_0 wrt ..imagebase -section .xdata +section .xdata rdata align=8 ALIGN 4 $L$SEH_info_aes_hw_set_encrypt_key_base_0: DB 1 ; version 1, no flags diff --git a/third_party/boringssl/gen/bcm/ghash-ssse3-x86_64-win.asm b/third_party/boringssl/gen/bcm/ghash-ssse3-x86_64-win.asm index 4794beb..64faab6 100644 --- a/third_party/boringssl/gen/bcm/ghash-ssse3-x86_64-win.asm +++ b/third_party/boringssl/gen/bcm/ghash-ssse3-x86_64-win.asm @@ -450,7 +450,7 @@ $L$reverse_bytes: ; .Llow4_mask is an XMM mask which selects the low four bits of each byte. $L$low4_mask: DQ 0x0f0f0f0f0f0f0f0f,0x0f0f0f0f0f0f0f0f -section .text +section .text code align=64 section .pdata rdata align=4 ALIGN 4 diff --git a/third_party/boringssl/gen/bcm/ghash-x86_64-win.asm b/third_party/boringssl/gen/bcm/ghash-x86_64-win.asm index eacd900..abdbb70 100644 --- a/third_party/boringssl/gen/bcm/ghash-x86_64-win.asm +++ b/third_party/boringssl/gen/bcm/ghash-x86_64-win.asm @@ -1214,7 +1214,7 @@ ALIGN 64 DB 60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111 DB 114,103,62,0 ALIGN 64 -section .text +section .text code align=64 section .pdata rdata align=4 ALIGN 4 diff --git a/third_party/boringssl/gen/bcm/p256-x86_64-asm-win.asm b/third_party/boringssl/gen/bcm/p256-x86_64-asm-win.asm index 9976ab3..c82ea79 100644 --- a/third_party/boringssl/gen/bcm/p256-x86_64-asm-win.asm +++ b/third_party/boringssl/gen/bcm/p256-x86_64-asm-win.asm @@ -35,7 +35,7 @@ $L$ord: DQ 0xf3b9cac2fc632551,0xbce6faada7179e84,0xffffffffffffffff,0xffffffff00000000 $L$ordK: DQ 0xccd1c8aaee00bc4f -section .text +section .text code align=64 ; ############################################################################### diff --git a/third_party/boringssl/gen/bcm/rsaz-avx2-win.asm b/third_party/boringssl/gen/bcm/rsaz-avx2-win.asm index a142c27..4272093 100644 --- a/third_party/boringssl/gen/bcm/rsaz-avx2-win.asm +++ b/third_party/boringssl/gen/bcm/rsaz-avx2-win.asm @@ -1846,7 +1846,7 @@ $L$inc: DD 2,2,2,2,3,3,3,3 DD 4,4,4,4,4,4,4,4 ALIGN 64 -section .text +section .text code align=64 EXTERN __imp_RtlVirtualUnwind diff --git a/third_party/boringssl/gen/bcm/sha1-x86_64-win.asm b/third_party/boringssl/gen/bcm/sha1-x86_64-win.asm index b59fb5d..b3a9225 100644 --- a/third_party/boringssl/gen/bcm/sha1-x86_64-win.asm +++ b/third_party/boringssl/gen/bcm/sha1-x86_64-win.asm @@ -5560,7 +5560,7 @@ K_XX_XX: DB 97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114 DB 103,62,0 ALIGN 64 -section .text +section .text code align=64 EXTERN __imp_RtlVirtualUnwind diff --git a/third_party/boringssl/gen/bcm/sha256-x86_64-win.asm b/third_party/boringssl/gen/bcm/sha256-x86_64-win.asm index 339f23a..7f3a21b 100644 --- a/third_party/boringssl/gen/bcm/sha256-x86_64-win.asm +++ b/third_party/boringssl/gen/bcm/sha256-x86_64-win.asm @@ -1785,7 +1785,7 @@ K256: DB 52,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121 DB 32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46 DB 111,114,103,62,0 -section .text +section .text code align=64 global sha256_block_data_order_hw diff --git a/third_party/boringssl/gen/bcm/sha512-x86_64-win.asm b/third_party/boringssl/gen/bcm/sha512-x86_64-win.asm index 2e6760c..9f79afb 100644 --- a/third_party/boringssl/gen/bcm/sha512-x86_64-win.asm +++ b/third_party/boringssl/gen/bcm/sha512-x86_64-win.asm @@ -1829,7 +1829,7 @@ K512: DB 52,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121 DB 32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46 DB 111,114,103,62,0 -section .text +section .text code align=64 global sha512_block_data_order_avx diff --git a/third_party/boringssl/gen/bcm/vpaes-x86_64-win.asm b/third_party/boringssl/gen/bcm/vpaes-x86_64-win.asm index 001618c..cea2195 100644 --- a/third_party/boringssl/gen/bcm/vpaes-x86_64-win.asm +++ b/third_party/boringssl/gen/bcm/vpaes-x86_64-win.asm @@ -1348,7 +1348,7 @@ $L$ctr_add_two: DB 85,110,105,118,101,114,115,105,116,121,41,0 ALIGN 64 -section .text +section .text code align=64 EXTERN __imp_RtlVirtualUnwind diff --git a/third_party/boringssl/gen/bcm/x86_64-mont5-win.asm b/third_party/boringssl/gen/bcm/x86_64-mont5-win.asm index 05e9759..4b73b80 100644 --- a/third_party/boringssl/gen/bcm/x86_64-mont5-win.asm +++ b/third_party/boringssl/gen/bcm/x86_64-mont5-win.asm @@ -3698,7 +3698,7 @@ $L$inc: DB 114,32,120,56,54,95,54,52,44,32,67,82,89,80,84,79 DB 71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111 DB 112,101,110,115,115,108,46,111,114,103,62,0 -section .text +section .text code align=64 EXTERN __imp_RtlVirtualUnwind diff --git a/third_party/boringssl/gen/crypto/chacha-x86_64-win.asm b/third_party/boringssl/gen/crypto/chacha-x86_64-win.asm index e37e31f..9cd683b 100644 --- a/third_party/boringssl/gen/crypto/chacha-x86_64-win.asm +++ b/third_party/boringssl/gen/crypto/chacha-x86_64-win.asm @@ -50,7 +50,7 @@ $L$sixteen: DB 95,54,52,44,32,67,82,89,80,84,79,71,65,77,83,32 DB 98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115 DB 108,46,111,114,103,62,0 -section .text +section .text code align=64 global ChaCha20_ctr32_nohw diff --git a/third_party/boringssl/sources.cmake b/third_party/boringssl/sources.cmake index c6318ca..8267bd8 100644 --- a/third_party/boringssl/sources.cmake +++ b/third_party/boringssl/sources.cmake @@ -95,6 +95,7 @@ set(crypto_sources ${BORINGSSL_ROOT}src/crypto/cpu_arm_linux.cc ${BORINGSSL_ROOT}src/crypto/cpu_intel.cc ${BORINGSSL_ROOT}src/crypto/crypto.cc + ${BORINGSSL_ROOT}src/crypto/curve25519/cpace.cc ${BORINGSSL_ROOT}src/crypto/curve25519/curve25519.cc ${BORINGSSL_ROOT}src/crypto/curve25519/curve25519_64_adx.cc ${BORINGSSL_ROOT}src/crypto/curve25519/spake25519.cc @@ -121,6 +122,7 @@ set(crypto_sources ${BORINGSSL_ROOT}src/crypto/evp/p_ec.cc ${BORINGSSL_ROOT}src/crypto/evp/p_ed25519.cc ${BORINGSSL_ROOT}src/crypto/evp/p_hkdf.cc + ${BORINGSSL_ROOT}src/crypto/evp/p_keccak.cc ${BORINGSSL_ROOT}src/crypto/evp/p_mldsa.cc ${BORINGSSL_ROOT}src/crypto/evp/p_mlkem.cc ${BORINGSSL_ROOT}src/crypto/evp/p_rsa.cc diff --git a/third_party/boringssl/src/crypto/asn1/a_type.cc b/third_party/boringssl/src/crypto/asn1/a_type.cc index 4aac69a..35e0534 100644 --- a/third_party/boringssl/src/crypto/asn1/a_type.cc +++ b/third_party/boringssl/src/crypto/asn1/a_type.cc @@ -292,6 +292,12 @@ int bssl::asn1_parse_any_as_string(CBS *cbs, ASN1_STRING *out) { return 0; } break; + case CBS_ASN1_RELATIVE_OID: + if (!CBS_is_valid_asn1_relative_oid(&body)) { + OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_OBJECT_ENCODING); + return 0; + } + break; case CBS_ASN1_NULL: if (CBS_len(&body) != 0) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_NULL_IS_WRONG_LENGTH); diff --git a/third_party/boringssl/src/crypto/asn1/asn1_lib.cc b/third_party/boringssl/src/crypto/asn1/asn1_lib.cc index e41e43e..960cabb 100644 --- a/third_party/boringssl/src/crypto/asn1/asn1_lib.cc +++ b/third_party/boringssl/src/crypto/asn1/asn1_lib.cc @@ -280,6 +280,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) { + BSSL_CHECK(len >= 0); OPENSSL_free(str->data); str->data = reinterpret_cast(data); str->length = len; @@ -361,6 +362,8 @@ int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) { int ASN1_STRING_length(const ASN1_STRING *str) { return str->length; } +size_t ASN1_STRING_get_length(const ASN1_STRING *str) { return str->length; } + int ASN1_STRING_type(const ASN1_STRING *str) { return str->type; } unsigned char *ASN1_STRING_data(ASN1_STRING *str) { return str->data; } diff --git a/third_party/boringssl/src/crypto/asn1/asn1_par.cc b/third_party/boringssl/src/crypto/asn1/asn1_par.cc index 7767cca..54921d5 100644 --- a/third_party/boringssl/src/crypto/asn1/asn1_par.cc +++ b/third_party/boringssl/src/crypto/asn1/asn1_par.cc @@ -30,7 +30,7 @@ const char *ASN1_tag2str(int tag) { "ENUMERATED", "", "UTF8STRING", - "", + "RELATIVE-OID", "", "", "SEQUENCE", diff --git a/third_party/boringssl/src/crypto/bio/bio.cc b/third_party/boringssl/src/crypto/bio/bio.cc index aabf06d..28c3f4b 100644 --- a/third_party/boringssl/src/crypto/bio/bio.cc +++ b/third_party/boringssl/src/crypto/bio/bio.cc @@ -74,6 +74,13 @@ int BIO_up_ref(BIO *bio) { return 1; } +BIO *BIO_dup_ref(const BIO *bio) { + if (bio == nullptr) { + return nullptr; + } + return FromOpaque(bio)->DupRefInternal(); +} + void BIO_vfree(BIO *bio) { BIO_free(bio); } void BIO_free_all(BIO *bio) { BIO_free(bio); } @@ -291,9 +298,7 @@ void BIO_clear_retry_flags(BIO *bio) { impl->retry_reason = 0; } -int BIO_method_type(const BIO *bio) { - return FromOpaque(bio)->method->type; -} +int BIO_method_type(const BIO *bio) { return FromOpaque(bio)->method->type; } void BIO_copy_next_retry(BIO *bio) { auto *impl = FromOpaque(bio); diff --git a/third_party/boringssl/src/crypto/cms/cms.cc b/third_party/boringssl/src/crypto/cms/cms.cc index e8ba962..ddd9d60 100644 --- a/third_party/boringssl/src/crypto/cms/cms.cc +++ b/third_party/boringssl/src/crypto/cms/cms.cc @@ -56,8 +56,9 @@ class CMSContentInfo : public CMS_ContentInfo_st { BSSL_NAMESPACE_END -CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, - BIO *data, uint32_t flags) { +CMS_ContentInfo *CMS_sign(const X509 *signcert, const EVP_PKEY *pkey, + const STACK_OF(X509) *certs, BIO *data, + uint32_t flags) { // We only support external signatures and do not support embedding // certificates in SignedData. if ((flags & CMS_DETACHED) == 0 || sk_X509_num(certs) != 0) { @@ -88,8 +89,8 @@ CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, void CMS_ContentInfo_free(CMS_ContentInfo *cms) { Delete(FromOpaque(cms)); } -CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms, X509 *signcert, - EVP_PKEY *pkey, const EVP_MD *md, +CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms, const X509 *signcert, + const EVP_PKEY *pkey, const EVP_MD *md, uint32_t flags) { auto *impl = FromOpaque(cms); if ( // Already finalized. diff --git a/third_party/boringssl/src/crypto/curve25519/cpace.cc b/third_party/boringssl/src/crypto/curve25519/cpace.cc new file mode 100644 index 0000000..48ca47e --- /dev/null +++ b/third_party/boringssl/src/crypto/curve25519/cpace.cc @@ -0,0 +1,227 @@ +// Copyright 2026 The BoringSSL Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../internal.h" +#include "../mem_internal.h" +#include "./internal.h" + + +CPACE_CTX *CPACE_CTX_new(enum cpace_role_t role, const uint8_t *password, + size_t password_len, const uint8_t *channel_id, + size_t channel_id_len, const uint8_t *assoc_data, + size_t assoc_data_len, const uint8_t *session_id, + size_t session_id_len) { + bssl::UniquePtr ctx = bssl::MakeUnique(); + if (ctx == nullptr) { + return nullptr; + } + + ctx->our_role = role; + if (!ctx->our_password.CopyFrom(bssl::Span(password, password_len)) || + !ctx->channel_id.CopyFrom(bssl::Span(channel_id, channel_id_len)) || + !ctx->our_aad.CopyFrom(bssl::Span(assoc_data, assoc_data_len)) || + !ctx->session_id.CopyFrom(bssl::Span(session_id, session_id_len))) { + return nullptr; + } + + return ctx.release(); +} + +void CPACE_CTX_free(CPACE_CTX *ctx) { Delete(bssl::FromOpaque(ctx)); } + +namespace { +constexpr uint64_t leb128_len(uint64_t len) { + if (len < 128) { + return 1; + } + return (bssl::CRYPTO_bit_width(len) + 6) / 7; +} + +constexpr size_t kMaxLenTagSize = leb128_len(UINT64_MAX); +constexpr std::string_view kDSI = "CPace255"; + +constexpr size_t leb128_tag(uint64_t len, uint8_t tag[kMaxLenTagSize]) { + size_t tag_len = leb128_len(len); + for (size_t i = 0; i < tag_len; ++i) { + if (len < 128) { + tag[i] = len; + } else { + tag[i] = (len & 0x7f) | 0x80; + len >>= 7; + } + } + return tag_len; +} + +void push_lv_to_hasher(SHA512_CTX &hasher, bssl::Span data) { + uint8_t lv_tag[kMaxLenTagSize]; + size_t lv_tag_len = leb128_tag(data.size(), lv_tag); + SHA512_Update(&hasher, lv_tag, lv_tag_len); + SHA512_Update(&hasher, data.data(), data.size()); +} +} // namespace + + +// This implements the first two steps of G.calculate_generator in Section 8.2 +// of draft-irtf-cfrg-cpace-21. +void bssl::CpaceCtx::ComputeGeneratorStrHash( + uint8_t out_gen_str_hash[32]) const { + // len_zpad = max(0,s_in_bytes - 1 - len(prepend_len(PRS)) - + // len(prepend_len(DSI))) + size_t digest_len = leb128_len(our_password.size()) + our_password.size() // + + leb128_len(kDSI.length()) + kDSI.length(); + size_t len_zpad = 0; + if (digest_len < SHA512_CBLOCK - 1) { + len_zpad = SHA512_CBLOCK - 1 - digest_len; + } + + constexpr uint8_t kZeros[SHA512_CBLOCK] = {}; + // gen_str = generator_string(G.DSI, PRS, CI, sid, H.s_in_bytes) + SHA512_CTX hasher; + SHA512_Init(&hasher); + push_lv_to_hasher(hasher, StringAsBytes(kDSI)); + push_lv_to_hasher(hasher, our_password); + push_lv_to_hasher(hasher, Span(kZeros, len_zpad)); + push_lv_to_hasher(hasher, channel_id); + push_lv_to_hasher(hasher, session_id); + uint8_t out[SHA512_DIGEST_LENGTH]; + // gen_str_hash = H.hash(gen_str, G.field_size_bytes). + SHA512_Final(out, &hasher); + OPENSSL_memcpy(out_gen_str_hash, out, 32); +} + +bool bssl::CpaceCtx::ComputeMessage(uint8_t msg[CPACE_MSG_LEN]) { + if (state != cpace_state_init) { + OPENSSL_PUT_ERROR(CRYPTO, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); + return false; + } + + uint8_t gen_str_hash[32]; + // We now compute the first two steps of G.calculate_generator(H, PRS, sid, + // CI). + ComputeGeneratorStrHash(gen_str_hash); + // This result is then considered as a field coordinate using the u = + // decodeUCoordinate(gen_str_hash, G.field_size_bits) function from RFC7748. + uint8_t g[32], v[32]; + map_to_curve_curve25519_elligator2(g, v, gen_str_hash); + // sample_scalar() = sample_random_bytes(G.field_size_bytes) + RAND_bytes(our_private_key, 32); + auto rc = X25519(our_public_key, our_private_key, g); + OPENSSL_memcpy(msg, our_public_key, 32); + if (!rc) { + // This will happen with negligible probability. + OPENSSL_PUT_ERROR(CRYPTO, ERR_R_INTERNAL_ERROR); + return false; + } + state = cpace_state_msg_generated; + return true; +} + +int CPACE_generate_msg(CPACE_CTX *ctx, uint8_t out_msg[CPACE_MSG_LEN]) { + auto *impl = bssl::FromOpaque(ctx); + return impl->ComputeMessage(out_msg); +} + +bool bssl::CpaceCtx::ComputeISK( + const uint8_t peer_msg[CPACE_MSG_LEN], Span peer_assoc_data, + uint8_t out_shared_secret[CPACE_SHARED_SECRET_LEN], + uint8_t out_sid[SHA512_DIGEST_LENGTH]) { + if (state != cpace_state_msg_generated) { + OPENSSL_PUT_ERROR(CRYPTO, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); + return false; + } + + state = cpace_state_key_generated; + + uint8_t k[32]; + if (X25519(k, our_private_key, peer_msg) != 1) { + // TODO(crbug.com/42290066): This is another instance where unifying the + // reason code and library code into one error code makes most sense. + OPENSSL_PUT_ERROR(EC, EC_R_DECODE_ERROR); + return false; + } + // ISK = H.hash(lv_cat(G.DSI || b"_ISK", sid, K)||transcript(Ya,ADa,Yb,ADb)) + static constexpr std::string_view kDsiIsk = "CPace255_ISK"; + static constexpr std::string_view kDsiSidOut = "CPaceSidOutput"; + SHA512_CTX hasher, sid_hasher; + SHA512_Init(&hasher); + const bool compute_sid = out_sid != nullptr; + if (compute_sid) { + SHA512_Init(&sid_hasher); + SHA512_Update(&sid_hasher, kDsiSidOut.data(), kDsiSidOut.size()); + } + push_lv_to_hasher(hasher, StringAsBytes(kDsiIsk)); + push_lv_to_hasher(hasher, session_id); + push_lv_to_hasher(hasher, Span(k, 32)); + Span peer_public_key(peer_msg, 32); + auto push_our_transcript = [&] { + push_lv_to_hasher(hasher, our_public_key); + push_lv_to_hasher(hasher, our_aad); + if (compute_sid) { + push_lv_to_hasher(sid_hasher, our_public_key); + push_lv_to_hasher(sid_hasher, our_aad); + } + }; + auto push_peer_transcript = [&] { + push_lv_to_hasher(hasher, peer_public_key); + push_lv_to_hasher(hasher, peer_assoc_data); + if (compute_sid) { + push_lv_to_hasher(sid_hasher, peer_public_key); + push_lv_to_hasher(sid_hasher, peer_assoc_data); + } + }; + + switch (our_role) { + case cpace_role_initiator: { + push_our_transcript(); + push_peer_transcript(); + break; + } + case cpace_role_responder: { + push_peer_transcript(); + push_our_transcript(); + break; + } + } + if (compute_sid) { + SHA512_Final(out_sid, &sid_hasher); + } + return SHA512_Final(out_shared_secret, &hasher); +} + +// CPACE_process_msg processes a received message and finalize +int CPACE_process_msg(CPACE_CTX *ctx, const uint8_t msg[CPACE_MSG_LEN], + const uint8_t *peer_assoc_data, + size_t peer_assoc_data_len, + uint8_t out_shared_secret[CPACE_SHARED_SECRET_LEN], + uint8_t out_sid[SHA512_DIGEST_LENGTH]) { + auto *impl = bssl::FromOpaque(ctx); + return impl->ComputeISK(msg, bssl::Span(peer_assoc_data, peer_assoc_data_len), + out_shared_secret, out_sid); +} diff --git a/third_party/boringssl/src/crypto/curve25519/internal.h b/third_party/boringssl/src/crypto/curve25519/internal.h index 7912bb3..d5f9033 100644 --- a/third_party/boringssl/src/crypto/curve25519/internal.h +++ b/third_party/boringssl/src/crypto/curve25519/internal.h @@ -15,9 +15,11 @@ #ifndef OPENSSL_HEADER_CRYPTO_CURVE25519_INTERNAL_H #define OPENSSL_HEADER_CRYPTO_CURVE25519_INTERNAL_H +#include #include -#include "../internal.h" +#include "../mem_internal.h" + BSSL_NAMESPACE_BEGIN @@ -165,8 +167,34 @@ struct spake2_ctx_st { char disable_password_scalar_hack; }; +DECLARE_OPAQUE_STRUCT(cpace_ctx_st, CpaceCtx) + BSSL_NAMESPACE_BEGIN +class CpaceCtx : public cpace_ctx_st { + public: + enum cpace_role_t our_role; + enum cpace_state_t { + cpace_state_init = 0, + cpace_state_msg_generated, + cpace_state_key_generated, + } state = cpace_state_init; + Array our_aad; + Array our_password; + Array channel_id; + Array session_id; + uint8_t our_public_key[32]; + uint8_t our_private_key[32]; + + static constexpr bool kAllowUniquePtr = true; + + void ComputeGeneratorStrHash(uint8_t out_gen_str_hash[32]) const; + bool ComputeMessage(uint8_t msg[32]); + bool ComputeISK(const uint8_t msg[32], Span peer_assoc_data, + uint8_t shared_secret[64], + uint8_t out_sid[SHA512_DIGEST_LENGTH]); +}; + extern const uint8_t k25519Precomp[32][8][3][32]; BSSL_NAMESPACE_END diff --git a/third_party/boringssl/src/crypto/dsa/dsa.cc b/third_party/boringssl/src/crypto/dsa/dsa.cc index 5592fa6..9bb2df1 100644 --- a/third_party/boringssl/src/crypto/dsa/dsa.cc +++ b/third_party/boringssl/src/crypto/dsa/dsa.cc @@ -72,6 +72,13 @@ int DSA_up_ref(DSA *dsa) { return 1; } +DSA *DSA_dup_ref(const DSA *dsa) { + if (dsa == nullptr) { + return nullptr; + } + return FromOpaque(dsa)->DupRefInternal(); +} + unsigned DSA_bits(const DSA *dsa) { return BN_num_bits(FromOpaque(dsa)->p.get()); } @@ -845,7 +852,8 @@ static int dsa_sign_setup(const DSAImpl *dsa, BN_CTX *ctx, BIGNUM **out_kinv, if (!BN_mod(r, r, dsa->q.get(), ctx) || // Compute part of 's = inv(k) (m + xr) mod q' using Fermat's Little // Theorem. - !bn_mod_inverse_prime(kinv, &k, dsa->q.get(), ctx, dsa->method_mont_q.get())) { + !bn_mod_inverse_prime(kinv, &k, dsa->q.get(), ctx, + dsa->method_mont_q.get())) { OPENSSL_PUT_ERROR(DSA, ERR_R_BN_LIB); goto err; } diff --git a/third_party/boringssl/src/crypto/evp/evp.cc b/third_party/boringssl/src/crypto/evp/evp.cc index f99ee15..f52a967 100644 --- a/third_party/boringssl/src/crypto/evp/evp.cc +++ b/third_party/boringssl/src/crypto/evp/evp.cc @@ -63,10 +63,7 @@ EVP_PKEY *EVP_PKEY_dup_ref(const EVP_PKEY *pkey) { if (pkey == nullptr) { return nullptr; } - auto pkey_ref = const_cast(pkey); - // We know that this call always returns one. - EVP_PKEY_up_ref(pkey_ref); - return pkey_ref; + return FromOpaque(pkey)->DupRefInternal(); } int EVP_PKEY_is_opaque(const EVP_PKEY *pkey) { diff --git a/third_party/boringssl/src/crypto/evp/evp_ctx.cc b/third_party/boringssl/src/crypto/evp/evp_ctx.cc index a0d7810..e01e92a 100644 --- a/third_party/boringssl/src/crypto/evp/evp_ctx.cc +++ b/third_party/boringssl/src/crypto/evp/evp_ctx.cc @@ -30,7 +30,8 @@ using namespace bssl; static UniquePtr evp_pkey_ctx_new( - EvpPkey *pkey, const EVP_PKEY_ALG *alg, const EVP_PKEY_CTX_METHOD *pmeth) { + const EvpPkey *pkey, const EVP_PKEY_ALG *alg, + const EVP_PKEY_CTX_METHOD *pmeth) { assert(pkey != nullptr || alg != nullptr); UniquePtr ret = MakeUnique(); if (!ret) { @@ -49,7 +50,7 @@ static UniquePtr evp_pkey_ctx_new( return ret; } -EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e) { +EVP_PKEY_CTX *EVP_PKEY_CTX_new(const EVP_PKEY *pkey, ENGINE *e) { auto *pkey_impl = FromOpaque(pkey); if (pkey_impl == nullptr || pkey_impl->ameth == nullptr) { OPENSSL_PUT_ERROR(EVP, ERR_R_PASSED_NULL_PARAMETER); @@ -151,7 +152,7 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *ctx) { return ret.release(); } -EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx) { +EVP_PKEY *EVP_PKEY_CTX_get0_pkey(const EVP_PKEY_CTX *ctx) { auto *impl = FromOpaque(ctx); return impl->pkey.get(); } @@ -315,7 +316,7 @@ int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx) { return 1; } -int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer) { +int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, const EVP_PKEY *peer) { auto *impl = FromOpaque(ctx); if (!impl || !impl->pmeth || !(impl->pmeth->derive || impl->pmeth->encrypt || impl->pmeth->decrypt) || @@ -330,7 +331,8 @@ int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer) { return 0; } - int ret = impl->pmeth->ctrl(impl, EVP_PKEY_CTRL_PEER_KEY, 0, peer); + int ret = impl->pmeth->ctrl(impl, EVP_PKEY_CTRL_PEER_KEY, 0, + const_cast(peer)); if (ret <= 0) { return 0; @@ -357,7 +359,7 @@ int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer) { } impl->peerkey = UpRef(FromOpaque(peer)); - ret = impl->pmeth->ctrl(impl, EVP_PKEY_CTRL_PEER_KEY, 1, peer); + ret = impl->pmeth->ctrl(impl, EVP_PKEY_CTRL_PEER_KEY, 1, impl->peerkey.get()); if (ret <= 0) { impl->peerkey = nullptr; return 0; diff --git a/third_party/boringssl/src/crypto/evp/evp_kem.cc b/third_party/boringssl/src/crypto/evp/evp_kem.cc index e07ea3e..e718caf 100644 --- a/third_party/boringssl/src/crypto/evp/evp_kem.cc +++ b/third_party/boringssl/src/crypto/evp/evp_kem.cc @@ -36,7 +36,8 @@ static bool check_kem_invocation(const EVP_KEM *kem, OPENSSL_PUT_ERROR(EVP, ERR_R_PASSED_NULL_PARAMETER); return false; } - if (kem->pkey_id != EVP_PKEY_id(pkey_impl)) { + if (kem->pkey_id != EVP_PKEY_id(pkey_impl) || + (kem->check_key != nullptr && !kem->check_key(kem, pkey_impl))) { OPENSSL_PUT_ERROR(EVP, EVP_R_UNSUPPORTED_ALGORITHM); return false; } @@ -68,7 +69,7 @@ int EVP_KEM_encap(const EVP_KEM *kem, uint8_t *out_ciphertext, if (!check_kem_invocation(kem, &ciphertext_len, secret_len, pkey_impl)) { return 0; } - return kem->encap(Span(out_ciphertext, ciphertext_len), + return kem->encap(kem, Span(out_ciphertext, ciphertext_len), Span(out_secret, secret_len), pkey_impl); } @@ -84,7 +85,7 @@ int EVP_KEM_encap_external_entropy_for_testing( OPENSSL_PUT_ERROR(EVP, EVP_R_INVALID_ENTROPY_LENGTH); return 0; } - return kem->encap_external_entropy(Span(out_ciphertext, ciphertext_len), + return kem->encap_external_entropy(kem, Span(out_ciphertext, ciphertext_len), Span(out_secret, secret_len), pkey_impl, Span(entropy, entropy_len)); } @@ -96,6 +97,6 @@ int EVP_KEM_decap(const EVP_KEM *kem, uint8_t *out_secret, size_t secret_len, if (!check_kem_invocation(kem, nullptr, secret_len, pkey_impl)) { return 0; } - return kem->decap(Span(out_secret, secret_len), + return kem->decap(kem, Span(out_secret, secret_len), Span(ciphertext, ciphertext_len), pkey_impl); } diff --git a/third_party/boringssl/src/crypto/evp/internal.h b/third_party/boringssl/src/crypto/evp/internal.h index 2c83190..d4e57dc 100644 --- a/third_party/boringssl/src/crypto/evp/internal.h +++ b/third_party/boringssl/src/crypto/evp/internal.h @@ -317,13 +317,18 @@ struct evp_kem_st { // Fixed length of external entropy for testing. size_t entropy_len; - int (*encap)(bssl::Span out_ciphertext, + // check_key, if non-null, returns whether `key`, whose type matches + // `pkey_id`, is usable with this KEM. + bool (*check_key)(const EVP_KEM *kem, const EVP_PKEY *key); + + int (*encap)(const EVP_KEM *kem, bssl::Span out_ciphertext, bssl::Span out_secret, const EVP_PKEY *peer_key); - int (*encap_external_entropy)(bssl::Span out_ciphertext, + int (*encap_external_entropy)(const EVP_KEM *kem, + bssl::Span out_ciphertext, bssl::Span out_secret, const EVP_PKEY *peer_key, bssl::Span entropy); - int (*decap)(bssl::Span out_secret, + int (*decap)(const EVP_KEM *kem, bssl::Span out_secret, bssl::Span ciphertext, const EVP_PKEY *key); } /* EVP_KEM */; @@ -353,7 +358,7 @@ struct KemAdapter { OPENSSL_PUT_ERROR(EVP, EVP_R_BUFFER_TOO_SMALL); return 0; } - if (KEM.encap(Span(out_ciphertext, KEM.ciphertext_len), + if (KEM.encap(&KEM, Span(out_ciphertext, KEM.ciphertext_len), Span(out_secret, KEM.secret_len), ctx->pkey.get())) { *out_ciphertext_len = KEM.ciphertext_len; *out_secret_len = KEM.secret_len; @@ -373,7 +378,7 @@ struct KemAdapter { OPENSSL_PUT_ERROR(EVP, EVP_R_BUFFER_TOO_SMALL); return 0; } - if (KEM.decap(Span(out_secret, KEM.secret_len), + if (KEM.decap(&KEM, Span(out_secret, KEM.secret_len), Span(ciphertext, ciphertext_len), ctx->pkey.get())) { *out_secret_len = KEM.secret_len; return 1; diff --git a/third_party/boringssl/src/crypto/evp/p_dh.cc b/third_party/boringssl/src/crypto/evp/p_dh.cc index c3d8f7f..7fcd9f1 100644 --- a/third_party/boringssl/src/crypto/evp/p_dh.cc +++ b/third_party/boringssl/src/crypto/evp/p_dh.cc @@ -34,25 +34,25 @@ namespace { extern const EVP_PKEY_CTX_METHOD dh_pkey_meth; -static void dh_free(EvpPkey *pkey) { +void dh_free(EvpPkey *pkey) { DH_free(reinterpret_cast(pkey->pkey)); pkey->pkey = nullptr; } -static int dh_size(const EvpPkey *pkey) { +int dh_size(const EvpPkey *pkey) { return DH_size(reinterpret_cast(pkey->pkey)); } -static int dh_bits(const EvpPkey *pkey) { +int dh_bits(const EvpPkey *pkey) { return DH_bits(reinterpret_cast(pkey->pkey)); } -static int dh_param_missing(const EvpPkey *pkey) { +int dh_param_missing(const EvpPkey *pkey) { const DH *dh = reinterpret_cast(pkey->pkey); return dh == nullptr || DH_get0_p(dh) == nullptr || DH_get0_g(dh) == nullptr; } -static int dh_param_copy(EvpPkey *to, const EvpPkey *from) { +int dh_param_copy(EvpPkey *to, const EvpPkey *from) { if (dh_param_missing(from)) { OPENSSL_PUT_ERROR(EVP, EVP_R_MISSING_PARAMETERS); return 0; @@ -81,7 +81,7 @@ static int dh_param_copy(EvpPkey *to, const EvpPkey *from) { return 1; } -static bool dh_param_equal(const EvpPkey *a, const EvpPkey *b) { +bool dh_param_equal(const EvpPkey *a, const EvpPkey *b) { if (dh_param_missing(a) || dh_param_missing(b)) { return false; } @@ -94,7 +94,7 @@ static bool dh_param_equal(const EvpPkey *a, const EvpPkey *b) { BN_cmp(DH_get0_g(a_dh), DH_get0_g(b_dh)) == 0; } -static bool dh_pub_equal(const EvpPkey *a, const EvpPkey *b) { +bool dh_pub_equal(const EvpPkey *a, const EvpPkey *b) { if (!dh_param_equal(a, b)) { return false; } @@ -104,12 +104,12 @@ static bool dh_pub_equal(const EvpPkey *a, const EvpPkey *b) { return BN_cmp(DH_get0_pub_key(a_dh), DH_get0_pub_key(b_dh)) == 0; } -static bool dh_has_pub(const EvpPkey *pk) { +bool dh_has_pub(const EvpPkey *pk) { const DH *pk_dh = reinterpret_cast(pk->pkey); return DH_get0_pub_key(pk_dh) != nullptr; } -static bool dh_pub_copy(EvpPkey *out, const EvpPkey *pk) { +bool dh_pub_copy(EvpPkey *out, const EvpPkey *pk) { const DH *pk_dh = reinterpret_cast(pk->pkey); const BIGNUM *public_key = DH_get0_pub_key(pk_dh); if (public_key == nullptr) { @@ -128,12 +128,12 @@ static bool dh_pub_copy(EvpPkey *out, const EvpPkey *pk) { return true; } -static bool dh_has_priv(const EvpPkey *pk) { +bool dh_has_priv(const EvpPkey *pk) { const DH *pk_dh = reinterpret_cast(pk->pkey); return DH_get0_priv_key(pk_dh) != nullptr; } -static const EVP_PKEY_ASN1_METHOD dh_asn1_meth = { +const EVP_PKEY_ASN1_METHOD dh_asn1_meth = { /*pkey_id=*/EVP_PKEY_DH, /*oid=*/{0}, /*oid_len=*/0, @@ -167,7 +167,7 @@ struct DH_PKEY_CTX { bool pad = false; }; -static int pkey_dh_init(EvpPkeyCtx *ctx, const EVP_PKEY_ALG *) { +int pkey_dh_init(EvpPkeyCtx *ctx, const EVP_PKEY_ALG *) { DH_PKEY_CTX *dctx = New(); if (dctx == nullptr) { return 0; @@ -177,7 +177,7 @@ static int pkey_dh_init(EvpPkeyCtx *ctx, const EVP_PKEY_ALG *) { return 1; } -static int pkey_dh_copy(EvpPkeyCtx *dst, EvpPkeyCtx *src) { +int pkey_dh_copy(EvpPkeyCtx *dst, EvpPkeyCtx *src) { if (!pkey_dh_init(dst, nullptr)) { return 0; } @@ -188,11 +188,11 @@ static int pkey_dh_copy(EvpPkeyCtx *dst, EvpPkeyCtx *src) { return 1; } -static void pkey_dh_cleanup(EvpPkeyCtx *ctx) { +void pkey_dh_cleanup(EvpPkeyCtx *ctx) { Delete(reinterpret_cast(ctx->data)); } -static int pkey_dh_keygen(EvpPkeyCtx *ctx, EvpPkey *pkey) { +int pkey_dh_keygen(EvpPkeyCtx *ctx, EvpPkey *pkey) { DH *dh = DH_new(); if (dh == nullptr || !EVP_PKEY_assign_DH(pkey, dh)) { DH_free(dh); @@ -207,7 +207,7 @@ static int pkey_dh_keygen(EvpPkeyCtx *ctx, EvpPkey *pkey) { return DH_generate_key(dh); } -static int pkey_dh_derive(EvpPkeyCtx *ctx, uint8_t *out, size_t *out_len) { +int pkey_dh_derive(EvpPkeyCtx *ctx, uint8_t *out, size_t *out_len) { DH_PKEY_CTX *dctx = reinterpret_cast(ctx->data); if (ctx->pkey == nullptr || ctx->peerkey == nullptr) { OPENSSL_PUT_ERROR(EVP, EVP_R_KEYS_NOT_SET); @@ -248,7 +248,7 @@ static int pkey_dh_derive(EvpPkeyCtx *ctx, uint8_t *out, size_t *out_len) { return 1; } -static int pkey_dh_ctrl(EvpPkeyCtx *ctx, int type, int p1, void *p2) { +int pkey_dh_ctrl(EvpPkeyCtx *ctx, int type, int p1, void *p2) { DH_PKEY_CTX *dctx = reinterpret_cast(ctx->data); switch (type) { case EVP_PKEY_CTRL_PEER_KEY: diff --git a/third_party/boringssl/src/crypto/evp/p_dsa.cc b/third_party/boringssl/src/crypto/evp/p_dsa.cc index df02f1f..786d6be 100644 --- a/third_party/boringssl/src/crypto/evp/p_dsa.cc +++ b/third_party/boringssl/src/crypto/evp/p_dsa.cc @@ -31,9 +31,9 @@ namespace { extern const EVP_PKEY_ASN1_METHOD dsa_asn1_meth; -static bssl::evp_decode_result_t dsa_pub_decode(const EVP_PKEY_ALG *alg, - EvpPkey *out, CBS *params, - CBS *key) { +bssl::evp_decode_result_t dsa_pub_decode(const EVP_PKEY_ALG *alg, + EvpPkey *out, CBS *params, + CBS *key) { // See RFC 3279, section 2.3.2. // Decode parameters. RFC 3279 permits DSA parameters to be omitted, in which @@ -59,7 +59,7 @@ static bssl::evp_decode_result_t dsa_pub_decode(const EVP_PKEY_ALG *alg, return evp_decode_ok; } -static int dsa_pub_encode(CBB *out, const EvpPkey *key) { +int dsa_pub_encode(CBB *out, const EvpPkey *key) { const DSAImpl *dsa = reinterpret_cast(key->pkey); const int has_params = dsa->p != nullptr && dsa->q != nullptr && dsa->g != nullptr; @@ -81,9 +81,9 @@ static int dsa_pub_encode(CBB *out, const EvpPkey *key) { return 1; } -static bssl::evp_decode_result_t dsa_priv_decode(const EVP_PKEY_ALG *alg, - EvpPkey *out, CBS *params, - CBS *key) { +bssl::evp_decode_result_t dsa_priv_decode(const EVP_PKEY_ALG *alg, + EvpPkey *out, CBS *params, + CBS *key) { // See PKCS#11, v2.40, section 2.5. // Decode parameters. @@ -124,7 +124,7 @@ static bssl::evp_decode_result_t dsa_priv_decode(const EVP_PKEY_ALG *alg, return evp_decode_ok; } -static int dsa_priv_encode(CBB *out, const EvpPkey *key) { +int dsa_priv_encode(CBB *out, const EvpPkey *key) { const DSAImpl *dsa = reinterpret_cast(key->pkey); if (dsa == nullptr || dsa->priv_key == nullptr) { OPENSSL_PUT_ERROR(EVP, EVP_R_MISSING_PARAMETERS); @@ -148,17 +148,17 @@ static int dsa_priv_encode(CBB *out, const EvpPkey *key) { return 1; } -static int int_dsa_size(const EvpPkey *pkey) { +int int_dsa_size(const EvpPkey *pkey) { const DSAImpl *dsa = reinterpret_cast(pkey->pkey); return DSA_size(dsa); } -static int dsa_bits(const EvpPkey *pkey) { +int dsa_bits(const EvpPkey *pkey) { const DSAImpl *dsa = reinterpret_cast(pkey->pkey); return BN_num_bits(DSA_get0_p(dsa)); } -static int dsa_missing_parameters(const EvpPkey *pkey) { +int dsa_missing_parameters(const EvpPkey *pkey) { const DSAImpl *dsa = reinterpret_cast(pkey->pkey); if (DSA_get0_p(dsa) == nullptr || DSA_get0_q(dsa) == nullptr || DSA_get0_g(dsa) == nullptr) { @@ -167,7 +167,7 @@ static int dsa_missing_parameters(const EvpPkey *pkey) { return 0; } -static int dup_bn_into(UniquePtr *out, const BIGNUM *src) { +int dup_bn_into(UniquePtr *out, const BIGNUM *src) { UniquePtr copy(BN_dup(src)); if (copy == nullptr) { return 0; @@ -176,7 +176,7 @@ static int dup_bn_into(UniquePtr *out, const BIGNUM *src) { return 1; } -static int dsa_copy_parameters(EvpPkey *to, const EvpPkey *from) { +int dsa_copy_parameters(EvpPkey *to, const EvpPkey *from) { if (to->pkey == nullptr) { to->pkey = DSA_new(); if (to->pkey == nullptr) { @@ -194,7 +194,7 @@ static int dsa_copy_parameters(EvpPkey *to, const EvpPkey *from) { return 1; } -static bool dsa_equal_parameters(const EvpPkey *a, const EvpPkey *b) { +bool dsa_equal_parameters(const EvpPkey *a, const EvpPkey *b) { const DSAImpl *a_dsa = reinterpret_cast(a->pkey); const DSAImpl *b_dsa = reinterpret_cast(b->pkey); return BN_cmp(DSA_get0_p(a_dsa), DSA_get0_p(b_dsa)) == 0 && @@ -202,18 +202,18 @@ static bool dsa_equal_parameters(const EvpPkey *a, const EvpPkey *b) { BN_cmp(DSA_get0_g(a_dsa), DSA_get0_g(b_dsa)) == 0; } -static bool dsa_pub_equal(const EvpPkey *a, const EvpPkey *b) { +bool dsa_pub_equal(const EvpPkey *a, const EvpPkey *b) { const DSAImpl *a_dsa = reinterpret_cast(a->pkey); const DSAImpl *b_dsa = reinterpret_cast(b->pkey); return BN_cmp(DSA_get0_pub_key(b_dsa), DSA_get0_pub_key(a_dsa)) == 0; } -static bool dsa_pub_present(const EvpPkey *pk) { +bool dsa_pub_present(const EvpPkey *pk) { const DSA *pk_dsa = reinterpret_cast(pk->pkey); return DSA_get0_pub_key(pk_dsa) != nullptr; } -static bool dsa_pub_copy(EvpPkey *out, const EvpPkey *pk) { +bool dsa_pub_copy(EvpPkey *out, const EvpPkey *pk) { const DSA *pk_dsa = reinterpret_cast(pk->pkey); const BIGNUM *public_key = DSA_get0_pub_key(pk_dsa); if (public_key == nullptr) { @@ -232,12 +232,12 @@ static bool dsa_pub_copy(EvpPkey *out, const EvpPkey *pk) { return true; } -static bool dsa_priv_present(const EvpPkey *pk) { +bool dsa_priv_present(const EvpPkey *pk) { const DSA *pk_dsa = reinterpret_cast(pk->pkey); return DSA_get0_priv_key(pk_dsa) != nullptr; } -static void int_dsa_free(EvpPkey *pkey) { +void int_dsa_free(EvpPkey *pkey) { DSA_free(reinterpret_cast(pkey->pkey)); pkey->pkey = nullptr; } diff --git a/third_party/boringssl/src/crypto/evp/p_ec.cc b/third_party/boringssl/src/crypto/evp/p_ec.cc index 3e72432..3f35e5a 100644 --- a/third_party/boringssl/src/crypto/evp/p_ec.cc +++ b/third_party/boringssl/src/crypto/evp/p_ec.cc @@ -47,7 +47,7 @@ struct EVP_PKEY_ALG_EC : public EVP_PKEY_ALG { extern const EVP_PKEY_ASN1_METHOD ec_asn1_meth; extern const EVP_PKEY_CTX_METHOD ec_pkey_meth; -static int eckey_pub_encode(CBB *out, const EvpPkey *key) { +int eckey_pub_encode(CBB *out, const EvpPkey *key) { const EC_KEY *ec_key = reinterpret_cast(key->pkey); const EC_GROUP *group = EC_KEY_get0_group(ec_key); const EC_POINT *public_key = EC_KEY_get0_public_key(ec_key); @@ -71,9 +71,9 @@ static int eckey_pub_encode(CBB *out, const EvpPkey *key) { return 1; } -static bssl::evp_decode_result_t eckey_pub_decode(const EVP_PKEY_ALG *alg, - EvpPkey *out, CBS *params, - CBS *key) { +bssl::evp_decode_result_t eckey_pub_decode(const EVP_PKEY_ALG *alg, + EvpPkey *out, CBS *params, + CBS *key) { const auto *ec_alg = static_cast(alg); if (ec_alg->ec_group == nullptr) { return evp_decode_unsupported; @@ -107,7 +107,7 @@ static bssl::evp_decode_result_t eckey_pub_decode(const EVP_PKEY_ALG *alg, return evp_decode_ok; } -static bool eckey_pub_equal(const EvpPkey *a, const EvpPkey *b) { +bool eckey_pub_equal(const EvpPkey *a, const EvpPkey *b) { const EC_KEY *a_ec = reinterpret_cast(a->pkey); const EC_KEY *b_ec = reinterpret_cast(b->pkey); const EC_GROUP *group = EC_KEY_get0_group(b_ec); @@ -116,9 +116,9 @@ static bool eckey_pub_equal(const EvpPkey *a, const EvpPkey *b) { return EC_POINT_cmp(group, pa, pb, nullptr) == 0; } -static bssl::evp_decode_result_t eckey_priv_decode(const EVP_PKEY_ALG *alg, - EvpPkey *out, CBS *params, - CBS *key) { +bssl::evp_decode_result_t eckey_priv_decode(const EVP_PKEY_ALG *alg, + EvpPkey *out, CBS *params, + CBS *key) { const auto *ec_alg = static_cast(alg); if (ec_alg->ec_group == nullptr) { return evp_decode_unsupported; @@ -149,7 +149,7 @@ static bssl::evp_decode_result_t eckey_priv_decode(const EVP_PKEY_ALG *alg, return evp_decode_ok; } -static int eckey_priv_encode(CBB *out, const EvpPkey *key) { +int eckey_priv_encode(CBB *out, const EvpPkey *key) { const EC_KEY *ec_key = reinterpret_cast(key->pkey); // Omit the redundant copy of the curve name. This contradicts RFC 5915 but @@ -176,8 +176,8 @@ static int eckey_priv_encode(CBB *out, const EvpPkey *key) { return 1; } -static int eckey_set1_tls_encodedpoint(EvpPkey *pkey, const uint8_t *in, - size_t len) { +int eckey_set1_tls_encodedpoint(EvpPkey *pkey, const uint8_t *in, + size_t len) { EC_KEY *ec_key = reinterpret_cast(pkey->pkey); if (ec_key == nullptr) { OPENSSL_PUT_ERROR(EVP, EVP_R_NO_KEY_SET); @@ -187,8 +187,8 @@ static int eckey_set1_tls_encodedpoint(EvpPkey *pkey, const uint8_t *in, return EC_KEY_oct2key(ec_key, in, len, nullptr); } -static size_t eckey_get1_tls_encodedpoint(const EvpPkey *pkey, - uint8_t **out_ptr) { +size_t eckey_get1_tls_encodedpoint(const EvpPkey *pkey, + uint8_t **out_ptr) { const EC_KEY *ec_key = reinterpret_cast(pkey->pkey); if (ec_key == nullptr) { OPENSSL_PUT_ERROR(EVP, EVP_R_NO_KEY_SET); @@ -199,12 +199,12 @@ static size_t eckey_get1_tls_encodedpoint(const EvpPkey *pkey, nullptr); } -static int int_ec_size(const EvpPkey *pkey) { +int int_ec_size(const EvpPkey *pkey) { const EC_KEY *ec_key = reinterpret_cast(pkey->pkey); return ECDSA_size(ec_key); } -static int ec_bits(const EvpPkey *pkey) { +int ec_bits(const EvpPkey *pkey) { const EC_KEY *ec_key = reinterpret_cast(pkey->pkey); const EC_GROUP *group = EC_KEY_get0_group(ec_key); if (group == nullptr) { @@ -214,12 +214,12 @@ static int ec_bits(const EvpPkey *pkey) { return EC_GROUP_order_bits(group); } -static int ec_missing_parameters(const EvpPkey *pkey) { +int ec_missing_parameters(const EvpPkey *pkey) { const EC_KEY *ec_key = reinterpret_cast(pkey->pkey); return ec_key == nullptr || EC_KEY_get0_group(ec_key) == nullptr; } -static int ec_copy_parameters(EvpPkey *to, const EvpPkey *from) { +int ec_copy_parameters(EvpPkey *to, const EvpPkey *from) { const EC_KEY *from_key = reinterpret_cast(from->pkey); if (from_key == nullptr) { OPENSSL_PUT_ERROR(EVP, EVP_R_NO_KEY_SET); @@ -239,7 +239,7 @@ static int ec_copy_parameters(EvpPkey *to, const EvpPkey *from) { return EC_KEY_set_group(reinterpret_cast(to->pkey), group); } -static bool ec_equal_parameters(const EvpPkey *a, const EvpPkey *b) { +bool ec_equal_parameters(const EvpPkey *a, const EvpPkey *b) { const EC_KEY *a_ec = reinterpret_cast(a->pkey); const EC_KEY *b_ec = reinterpret_cast(b->pkey); if (a_ec == nullptr || b_ec == nullptr) { @@ -254,22 +254,22 @@ static bool ec_equal_parameters(const EvpPkey *a, const EvpPkey *b) { return EC_GROUP_cmp(group_a, group_b, nullptr) == 0; } -static void int_ec_free(EvpPkey *pkey) { +void int_ec_free(EvpPkey *pkey) { EC_KEY_free(reinterpret_cast(pkey->pkey)); pkey->pkey = nullptr; } -static int eckey_opaque(const EvpPkey *pkey) { +int eckey_opaque(const EvpPkey *pkey) { const EC_KEY *ec_key = reinterpret_cast(pkey->pkey); return EC_KEY_is_opaque(ec_key); } -static bool eckey_pub_present(const EvpPkey *pkey) { +bool eckey_pub_present(const EvpPkey *pkey) { const EC_KEY *ec_key = reinterpret_cast(pkey->pkey); return EC_KEY_get0_public_key(ec_key) != nullptr; } -static bool eckey_pub_copy(EvpPkey *out, const EvpPkey *pkey) { +bool eckey_pub_copy(EvpPkey *out, const EvpPkey *pkey) { const EC_KEY *ec_key = reinterpret_cast(pkey->pkey); const EC_POINT *public_key = EC_KEY_get0_public_key(ec_key); if (public_key == nullptr) { @@ -287,7 +287,7 @@ static bool eckey_pub_copy(EvpPkey *out, const EvpPkey *pkey) { return true; } -static bool eckey_priv_present(const EvpPkey *pkey) { +bool eckey_priv_present(const EvpPkey *pkey) { const EC_KEY *ec_key = reinterpret_cast(pkey->pkey); return EC_KEY_get0_private_key(ec_key) != nullptr; } @@ -337,7 +337,7 @@ struct EC_PKEY_CTX { const EC_GROUP *gen_group = nullptr; }; -static int pkey_ec_init(EvpPkeyCtx *ctx, const EVP_PKEY_ALG *alg) { +int pkey_ec_init(EvpPkeyCtx *ctx, const EVP_PKEY_ALG *alg) { EC_PKEY_CTX *dctx = New(); if (!dctx) { return 0; @@ -352,7 +352,7 @@ static int pkey_ec_init(EvpPkeyCtx *ctx, const EVP_PKEY_ALG *alg) { return 1; } -static int pkey_ec_copy(EvpPkeyCtx *dst, EvpPkeyCtx *src) { +int pkey_ec_copy(EvpPkeyCtx *dst, EvpPkeyCtx *src) { if (!pkey_ec_init(dst, nullptr)) { return 0; } @@ -364,12 +364,12 @@ static int pkey_ec_copy(EvpPkeyCtx *dst, EvpPkeyCtx *src) { return 1; } -static void pkey_ec_cleanup(EvpPkeyCtx *ctx) { +void pkey_ec_cleanup(EvpPkeyCtx *ctx) { Delete(reinterpret_cast(ctx->data)); } -static int pkey_ec_sign(EvpPkeyCtx *ctx, uint8_t *sig, size_t *siglen, - const uint8_t *tbs, size_t tbslen) { +int pkey_ec_sign(EvpPkeyCtx *ctx, uint8_t *sig, size_t *siglen, + const uint8_t *tbs, size_t tbslen) { const EC_KEY *ec = reinterpret_cast(ctx->pkey->pkey); if (!sig) { *siglen = ECDSA_size(ec); @@ -387,13 +387,13 @@ static int pkey_ec_sign(EvpPkeyCtx *ctx, uint8_t *sig, size_t *siglen, return 1; } -static int pkey_ec_verify(EvpPkeyCtx *ctx, const uint8_t *sig, size_t siglen, - const uint8_t *tbs, size_t tbslen) { +int pkey_ec_verify(EvpPkeyCtx *ctx, const uint8_t *sig, size_t siglen, + const uint8_t *tbs, size_t tbslen) { const EC_KEY *ec_key = reinterpret_cast(ctx->pkey->pkey); return ECDSA_verify(0, tbs, tbslen, sig, siglen, ec_key); } -static int pkey_ec_derive(EvpPkeyCtx *ctx, uint8_t *key, size_t *keylen) { +int pkey_ec_derive(EvpPkeyCtx *ctx, uint8_t *key, size_t *keylen) { if (!ctx->pkey || !ctx->peerkey) { OPENSSL_PUT_ERROR(EVP, EVP_R_KEYS_NOT_SET); return 0; @@ -421,7 +421,7 @@ static int pkey_ec_derive(EvpPkeyCtx *ctx, uint8_t *key, size_t *keylen) { return 1; } -static int pkey_ec_ctrl(EvpPkeyCtx *ctx, int type, int p1, void *p2) { +int pkey_ec_ctrl(EvpPkeyCtx *ctx, int type, int p1, void *p2) { EC_PKEY_CTX *dctx = reinterpret_cast(ctx->data); switch (type) { @@ -457,7 +457,7 @@ static int pkey_ec_ctrl(EvpPkeyCtx *ctx, int type, int p1, void *p2) { } } -static int pkey_ec_keygen(EvpPkeyCtx *ctx, EvpPkey *pkey) { +int pkey_ec_keygen(EvpPkeyCtx *ctx, EvpPkey *pkey) { EC_PKEY_CTX *dctx = reinterpret_cast(ctx->data); const EC_GROUP *group = dctx->gen_group; if (group == nullptr) { @@ -477,7 +477,7 @@ static int pkey_ec_keygen(EvpPkeyCtx *ctx, EvpPkey *pkey) { return 1; } -static int pkey_ec_paramgen(EvpPkeyCtx *ctx, EvpPkey *pkey) { +int pkey_ec_paramgen(EvpPkeyCtx *ctx, EvpPkey *pkey) { EC_PKEY_CTX *dctx = reinterpret_cast(ctx->data); if (dctx->gen_group == nullptr) { OPENSSL_PUT_ERROR(EVP, EVP_R_NO_PARAMETERS_SET); diff --git a/third_party/boringssl/src/crypto/evp/p_ed25519.cc b/third_party/boringssl/src/crypto/evp/p_ed25519.cc index 868c9f0..3cdbc1d 100644 --- a/third_party/boringssl/src/crypto/evp/p_ed25519.cc +++ b/third_party/boringssl/src/crypto/evp/p_ed25519.cc @@ -41,13 +41,13 @@ extern const EVP_PKEY_CTX_METHOD ed25519_pkey_meth; #define ED25519_PUBLIC_KEY_OFFSET 32 -static void ed25519_free(EvpPkey *pkey) { +void ed25519_free(EvpPkey *pkey) { ED25519_KEY *key = reinterpret_cast(pkey->pkey); Delete(key); pkey->pkey = nullptr; } -static int ed25519_set_priv_raw(EvpPkey *pkey, const uint8_t *in, size_t len) { +int ed25519_set_priv_raw(EvpPkey *pkey, const uint8_t *in, size_t len) { if (len != 32) { OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR); return 0; @@ -67,7 +67,7 @@ static int ed25519_set_priv_raw(EvpPkey *pkey, const uint8_t *in, size_t len) { return 1; } -static int ed25519_set_pub_raw(EvpPkey *pkey, const uint8_t *in, size_t len) { +int ed25519_set_pub_raw(EvpPkey *pkey, const uint8_t *in, size_t len) { if (len != 32) { OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR); return 0; @@ -84,8 +84,8 @@ static int ed25519_set_pub_raw(EvpPkey *pkey, const uint8_t *in, size_t len) { return 1; } -static int ed25519_get_priv_raw(const EvpPkey *pkey, uint8_t *out, - size_t *out_len) { +int ed25519_get_priv_raw(const EvpPkey *pkey, uint8_t *out, + size_t *out_len) { const ED25519_KEY *key = reinterpret_cast(pkey->pkey); if (!key->has_private) { OPENSSL_PUT_ERROR(EVP, EVP_R_NOT_A_PRIVATE_KEY); @@ -108,8 +108,8 @@ static int ed25519_get_priv_raw(const EvpPkey *pkey, uint8_t *out, return 1; } -static int ed25519_get_pub_raw(const EvpPkey *pkey, uint8_t *out, - size_t *out_len) { +int ed25519_get_pub_raw(const EvpPkey *pkey, uint8_t *out, + size_t *out_len) { const ED25519_KEY *key = reinterpret_cast(pkey->pkey); if (out == nullptr) { *out_len = 32; @@ -126,9 +126,9 @@ static int ed25519_get_pub_raw(const EvpPkey *pkey, uint8_t *out, return 1; } -static bssl::evp_decode_result_t ed25519_pub_decode(const EVP_PKEY_ALG *alg, - EvpPkey *out, CBS *params, - CBS *key) { +bssl::evp_decode_result_t ed25519_pub_decode(const EVP_PKEY_ALG *alg, + EvpPkey *out, CBS *params, + CBS *key) { // See RFC 8410, section 4. // The parameters must be omitted. Public keys have length 32. @@ -142,7 +142,7 @@ static bssl::evp_decode_result_t ed25519_pub_decode(const EVP_PKEY_ALG *alg, : evp_decode_error; } -static int ed25519_pub_encode(CBB *out, const EvpPkey *pkey) { +int ed25519_pub_encode(CBB *out, const EvpPkey *pkey) { const ED25519_KEY *key = reinterpret_cast(pkey->pkey); // See RFC 8410, section 4. @@ -163,16 +163,16 @@ static int ed25519_pub_encode(CBB *out, const EvpPkey *pkey) { return 1; } -static bool ed25519_pub_equal(const EvpPkey *a, const EvpPkey *b) { +bool ed25519_pub_equal(const EvpPkey *a, const EvpPkey *b) { const ED25519_KEY *a_key = reinterpret_cast(a->pkey); const ED25519_KEY *b_key = reinterpret_cast(b->pkey); return OPENSSL_memcmp(a_key->key + ED25519_PUBLIC_KEY_OFFSET, b_key->key + ED25519_PUBLIC_KEY_OFFSET, 32) == 0; } -static bssl::evp_decode_result_t ed25519_priv_decode(const EVP_PKEY_ALG *alg, - EvpPkey *out, CBS *params, - CBS *key) { +bssl::evp_decode_result_t ed25519_priv_decode(const EVP_PKEY_ALG *alg, + EvpPkey *out, CBS *params, + CBS *key) { // See RFC 8410, section 7. // Parameters must be empty. The key is a 32-byte value wrapped in an extra @@ -189,7 +189,7 @@ static bssl::evp_decode_result_t ed25519_priv_decode(const EVP_PKEY_ALG *alg, : evp_decode_error; } -static int ed25519_priv_encode(CBB *out, const EvpPkey *pkey) { +int ed25519_priv_encode(CBB *out, const EvpPkey *pkey) { const ED25519_KEY *key = reinterpret_cast(pkey->pkey); if (!key->has_private) { OPENSSL_PUT_ERROR(EVP, EVP_R_NOT_A_PRIVATE_KEY); @@ -216,9 +216,9 @@ static int ed25519_priv_encode(CBB *out, const EvpPkey *pkey) { return 1; } -static bool ed25519_pub_present(const EvpPkey *) { return true; } +bool ed25519_pub_present(const EvpPkey *) { return true; } -static bool ed25519_pub_copy(EvpPkey *out, const EvpPkey *pkey) { +bool ed25519_pub_copy(EvpPkey *out, const EvpPkey *pkey) { const ED25519_KEY *pkey_ed25519 = reinterpret_cast(pkey->pkey); ED25519_KEY *public_copy = New(); @@ -233,14 +233,14 @@ static bool ed25519_pub_copy(EvpPkey *out, const EvpPkey *pkey) { return true; } -static bool ed25519_priv_present(const EvpPkey *pkey) { +bool ed25519_priv_present(const EvpPkey *pkey) { const ED25519_KEY *key = reinterpret_cast(pkey->pkey); return key->has_private; } -static int ed25519_size(const EvpPkey *pkey) { return 64; } +int ed25519_size(const EvpPkey *pkey) { return 64; } -static int ed25519_bits(const EvpPkey *pkey) { return 253; } +int ed25519_bits(const EvpPkey *pkey) { return 253; } const EVP_PKEY_ASN1_METHOD ed25519_asn1_meth = { EVP_PKEY_ED25519, @@ -273,9 +273,9 @@ const EVP_PKEY_ASN1_METHOD ed25519_asn1_meth = { }; // Ed25519 has no parameters to copy. -static int pkey_ed25519_copy(EvpPkeyCtx *dst, EvpPkeyCtx *src) { return 1; } +int pkey_ed25519_copy(EvpPkeyCtx *dst, EvpPkeyCtx *src) { return 1; } -static int pkey_ed25519_keygen(EvpPkeyCtx *ctx, EvpPkey *pkey) { +int pkey_ed25519_keygen(EvpPkeyCtx *ctx, EvpPkey *pkey) { ED25519_KEY *key = New(); if (key == nullptr) { return 0; @@ -289,9 +289,9 @@ static int pkey_ed25519_keygen(EvpPkeyCtx *ctx, EvpPkey *pkey) { return 1; } -static int pkey_ed25519_sign_message(EvpPkeyCtx *ctx, uint8_t *sig, - size_t *siglen, const uint8_t *tbs, - size_t tbslen) { +int pkey_ed25519_sign_message(EvpPkeyCtx *ctx, uint8_t *sig, + size_t *siglen, const uint8_t *tbs, + size_t tbslen) { const ED25519_KEY *key = reinterpret_cast(ctx->pkey->pkey); if (!key->has_private) { @@ -317,9 +317,9 @@ static int pkey_ed25519_sign_message(EvpPkeyCtx *ctx, uint8_t *sig, return 1; } -static int pkey_ed25519_verify_message(EvpPkeyCtx *ctx, const uint8_t *sig, - size_t siglen, const uint8_t *tbs, - size_t tbslen) { +int pkey_ed25519_verify_message(EvpPkeyCtx *ctx, const uint8_t *sig, + size_t siglen, const uint8_t *tbs, + size_t tbslen) { const ED25519_KEY *key = reinterpret_cast(ctx->pkey->pkey); if (siglen != 64 || diff --git a/third_party/boringssl/src/crypto/evp/p_hkdf.cc b/third_party/boringssl/src/crypto/evp/p_hkdf.cc index a45bd6c..3494d5e 100644 --- a/third_party/boringssl/src/crypto/evp/p_hkdf.cc +++ b/third_party/boringssl/src/crypto/evp/p_hkdf.cc @@ -37,12 +37,12 @@ struct HKDF_PKEY_CTX { Vector info; }; -static int pkey_hkdf_init(EvpPkeyCtx *ctx, const EVP_PKEY_ALG *) { +int pkey_hkdf_init(EvpPkeyCtx *ctx, const EVP_PKEY_ALG *) { ctx->data = New(); return 1; } -static int pkey_hkdf_copy(EvpPkeyCtx *dst, EvpPkeyCtx *src) { +int pkey_hkdf_copy(EvpPkeyCtx *dst, EvpPkeyCtx *src) { if (!pkey_hkdf_init(dst, nullptr)) { return 0; } @@ -62,11 +62,11 @@ static int pkey_hkdf_copy(EvpPkeyCtx *dst, EvpPkeyCtx *src) { return 1; } -static void pkey_hkdf_cleanup(EvpPkeyCtx *ctx) { +void pkey_hkdf_cleanup(EvpPkeyCtx *ctx) { Delete(reinterpret_cast(ctx->data)); } -static int pkey_hkdf_derive(EvpPkeyCtx *ctx, uint8_t *out, size_t *out_len) { +int pkey_hkdf_derive(EvpPkeyCtx *ctx, uint8_t *out, size_t *out_len) { HKDF_PKEY_CTX *hctx = reinterpret_cast(ctx->data); if (hctx->md == nullptr) { OPENSSL_PUT_ERROR(EVP, EVP_R_MISSING_PARAMETERS); @@ -110,7 +110,7 @@ static int pkey_hkdf_derive(EvpPkeyCtx *ctx, uint8_t *out, size_t *out_len) { return 0; } -static int pkey_hkdf_ctrl(EvpPkeyCtx *ctx, int type, int p1, void *p2) { +int pkey_hkdf_ctrl(EvpPkeyCtx *ctx, int type, int p1, void *p2) { HKDF_PKEY_CTX *hctx = reinterpret_cast(ctx->data); switch (type) { case EVP_PKEY_CTRL_HKDF_MODE: diff --git a/third_party/boringssl/src/crypto/evp/p_keccak.cc b/third_party/boringssl/src/crypto/evp/p_keccak.cc new file mode 100644 index 0000000..99731c0 --- /dev/null +++ b/third_party/boringssl/src/crypto/evp/p_keccak.cc @@ -0,0 +1,84 @@ +// Copyright 2026 The BoringSSL Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Family of Keccak-derived hash functions including: +// - SHA3-256 +// - SHA3-512 + +#include + +#include "../fipsmodule/digest/internal.h" // IWYU pragma: keep +#include "../fipsmodule/keccak/internal.h" + +BSSL_NAMESPACE_BEGIN +namespace { +template +void keccak_init(EVP_MD_CTX *ctx) { + BORINGSSL_keccak_init(reinterpret_cast(ctx->md_data), + Config); +} + +void keccak_update(EVP_MD_CTX *ctx, const void *data, size_t count) { + BORINGSSL_keccak_absorb(reinterpret_cast(ctx->md_data), + static_cast(data), count); +} + +template +void keccak_final(EVP_MD_CTX *ctx, uint8_t *out) { + BORINGSSL_keccak_squeeze( + reinterpret_cast(ctx->md_data), + static_cast(out), Size); +} + +constexpr EVP_MD evp_md_sha3_256 = { + /*type=*/NID_undef, + /*md_size=*/SHA3_256_DIGEST_LENGTH, + /*flags=*/0, + /*init=*/keccak_init, + /*update=*/keccak_update, + /*final=*/keccak_final, + /*block_size=*/SHA3_256_CBLOCK, + /*ctx_size=*/sizeof(BORINGSSL_keccak_st), +}; + +constexpr EVP_MD evp_md_sha3_384 = { + /*type=*/NID_undef, + /*md_size=*/SHA3_384_DIGEST_LENGTH, + /*flags=*/0, + /*init=*/keccak_init, + /*update=*/keccak_update, + /*final=*/keccak_final, + /*block_size=*/SHA3_384_CBLOCK, + /*ctx_size=*/sizeof(BORINGSSL_keccak_st), +}; + +constexpr EVP_MD evp_md_sha3_512 = { + /*type=*/NID_undef, + /*md_size=*/SHA3_512_DIGEST_LENGTH, + /*flags=*/0, + /*init=*/keccak_init, + /*update=*/keccak_update, + /*final=*/keccak_final, + /*block_size=*/SHA3_512_CBLOCK, + /*ctx_size=*/sizeof(BORINGSSL_keccak_st), +}; + +static_assert(sizeof(BORINGSSL_keccak_st) <= EVP_MAX_MD_DATA_SIZE); +static_assert(SHA3_256_CBLOCK <= EVP_MAX_MD_BLOCK_SIZE); +} // namespace +BSSL_NAMESPACE_END + +const EVP_MD *EVP_sha3_256() { return &bssl::evp_md_sha3_256; } +const EVP_MD *EVP_sha3_384() { return &bssl::evp_md_sha3_384; } +const EVP_MD *EVP_sha3_512() { return &bssl::evp_md_sha3_512; } diff --git a/third_party/boringssl/src/crypto/evp/p_mlkem.cc b/third_party/boringssl/src/crypto/evp/p_mlkem.cc index c62c35e..dd8710c 100644 --- a/third_party/boringssl/src/crypto/evp/p_mlkem.cc +++ b/third_party/boringssl/src/crypto/evp/p_mlkem.cc @@ -356,8 +356,8 @@ struct MLKEMImplementation { return 1; } - static int KemEncap(Span out_ciphertext, Span out_secret, - const EVP_PKEY *peer_key) { + static int KemEncap(const EVP_KEM *kem, Span out_ciphertext, + Span out_secret, const EVP_PKEY *peer_key) { const auto *peer_pubkey = GetKeyData(FromOpaque(peer_key))->GetPublicKey(); if (out_ciphertext.size() != Traits::kCiphertextBytes) { OPENSSL_PUT_ERROR(EVP, EVP_R_INVALID_CIPHERTEXT_LENGTH); @@ -371,7 +371,8 @@ struct MLKEMImplementation { return 1; } - static int KemEncapExternalEntropy(Span out_ciphertext, + static int KemEncapExternalEntropy(const EVP_KEM *kem, + Span out_ciphertext, Span out_secret, const EVP_PKEY *peer_key, Span entropy) { @@ -393,8 +394,8 @@ struct MLKEMImplementation { return 1; } - static int KemDecap(Span out_secret, Span ciphertext, - const EVP_PKEY *key) { + static int KemDecap(const EVP_KEM *kem, Span out_secret, + Span ciphertext, const EVP_PKEY *key) { const auto *priv = GetKeyData(FromOpaque(key))->AsPrivateKeyData(); if (priv == nullptr) { OPENSSL_PUT_ERROR(EVP, EVP_R_NOT_A_PRIVATE_KEY); @@ -413,6 +414,7 @@ struct MLKEMImplementation { /*ciphertext_len=*/Traits::kCiphertextBytes, /*secret_len=*/MLKEM_SHARED_SECRET_BYTES, /*entropy_len=*/BCM_MLKEM_ENCAP_ENTROPY, + /*check_key=*/nullptr, &KemEncap, &KemEncapExternalEntropy, &KemDecap, diff --git a/third_party/boringssl/src/crypto/evp/p_rsa.cc b/third_party/boringssl/src/crypto/evp/p_rsa.cc index 41470be..3d9f1a9 100644 --- a/third_party/boringssl/src/crypto/evp/p_rsa.cc +++ b/third_party/boringssl/src/crypto/evp/p_rsa.cc @@ -46,7 +46,7 @@ extern const EVP_PKEY_ASN1_METHOD rsa_pss_asn1_meth; extern const EVP_PKEY_CTX_METHOD rsa_pkey_meth; extern const EVP_PKEY_CTX_METHOD rsa_pss_pkey_meth; -static int rsa_pub_encode(CBB *out, const EvpPkey *key) { +int rsa_pub_encode(CBB *out, const EvpPkey *key) { // See RFC 3279, section 2.3.1. const RSA *rsa = reinterpret_cast(key->pkey); CBB spki, algorithm, null, key_bitstring; @@ -66,9 +66,9 @@ static int rsa_pub_encode(CBB *out, const EvpPkey *key) { return 1; } -static bssl::evp_decode_result_t rsa_pub_decode(const EVP_PKEY_ALG *alg, - EvpPkey *out, CBS *params, - CBS *key) { +bssl::evp_decode_result_t rsa_pub_decode(const EVP_PKEY_ALG *alg, + EvpPkey *out, CBS *params, + CBS *key) { // See RFC 3279, section 2.3.1. // The parameters must be NULL. @@ -89,7 +89,7 @@ static bssl::evp_decode_result_t rsa_pub_decode(const EVP_PKEY_ALG *alg, return evp_decode_ok; } -static bool rsa_pub_equal(const EvpPkey *a, const EvpPkey *b) { +bool rsa_pub_equal(const EvpPkey *a, const EvpPkey *b) { // We currently assume that all `EVP_PKEY_RSA_PSS` keys have the same // parameters, so this vacuously compares parameters. If we ever support // multiple PSS parameter sets, we probably should compare them too. Note, @@ -100,7 +100,7 @@ static bool rsa_pub_equal(const EvpPkey *a, const EvpPkey *b) { BN_cmp(RSA_get0_e(b_rsa), RSA_get0_e(a_rsa)) == 0; } -static bool rsa_pub_present(const EvpPkey *pk) { +bool rsa_pub_present(const EvpPkey *pk) { const RSA *pk_rsa = reinterpret_cast(pk->pkey); // An RSA public key should always have n and e. It's possible for a (private) // key to have n and d, but not e, so we must explicitly check for the @@ -108,7 +108,7 @@ static bool rsa_pub_present(const EvpPkey *pk) { return RSA_get0_n(pk_rsa) != nullptr && RSA_get0_e(pk_rsa) != nullptr; } -static bool rsa_pub_copy(EvpPkey *out, const EvpPkey *pkey) { +bool rsa_pub_copy(EvpPkey *out, const EvpPkey *pkey) { const RSAImpl *pk_rsa = reinterpret_cast(pkey->pkey); const BIGNUM *pk_n = RSA_get0_n(pk_rsa); const BIGNUM *pk_e = RSA_get0_e(pk_rsa); @@ -126,7 +126,7 @@ static bool rsa_pub_copy(EvpPkey *out, const EvpPkey *pkey) { return true; } -static int rsa_priv_encode(CBB *out, const EvpPkey *key) { +int rsa_priv_encode(CBB *out, const EvpPkey *key) { const RSA *rsa = reinterpret_cast(key->pkey); CBB pkcs8, algorithm, null, private_key; if (!CBB_add_asn1(out, &pkcs8, CBS_ASN1_SEQUENCE) || @@ -145,9 +145,9 @@ static int rsa_priv_encode(CBB *out, const EvpPkey *key) { return 1; } -static bssl::evp_decode_result_t rsa_priv_decode(const EVP_PKEY_ALG *alg, - EvpPkey *out, CBS *params, - CBS *key) { +bssl::evp_decode_result_t rsa_priv_decode(const EVP_PKEY_ALG *alg, + EvpPkey *out, CBS *params, + CBS *key) { // Per RFC 8017, A.1, the parameters have type NULL. CBS null; if (!CBS_get_asn1(params, &null, CBS_ASN1_NULL) || CBS_len(&null) != 0 || @@ -166,12 +166,12 @@ static bssl::evp_decode_result_t rsa_priv_decode(const EVP_PKEY_ALG *alg, return evp_decode_ok; } -static bool rsa_priv_present(const EvpPkey *pk) { +bool rsa_priv_present(const EvpPkey *pk) { const RSA *pk_rsa = reinterpret_cast(pk->pkey); return RSA_get0_n(pk_rsa) != nullptr && RSA_get0_d(pk_rsa) != nullptr; } -static bssl::evp_decode_result_t rsa_decode_pss_params( +bssl::evp_decode_result_t rsa_decode_pss_params( rsa_pss_params_t expected, CBS *params) { if (CBS_len(params) == 0) { return evp_decode_unsupported; @@ -186,7 +186,7 @@ static bssl::evp_decode_result_t rsa_decode_pss_params( return pss_params == expected ? evp_decode_ok : evp_decode_unsupported; } -static int rsa_pub_encode_pss(CBB *out, const EvpPkey *key) { +int rsa_pub_encode_pss(CBB *out, const EvpPkey *key) { const RSAImpl *rsa = reinterpret_cast(key->pkey); CBB spki, algorithm, key_bitstring; if (!CBB_add_asn1(out, &spki, CBS_ASN1_SEQUENCE) || @@ -205,17 +205,17 @@ static int rsa_pub_encode_pss(CBB *out, const EvpPkey *key) { return 1; } -static void evp_pkey_set0_pss(EvpPkey *out, const EVP_PKEY_ALG *alg, - UniquePtr rsa) { +void evp_pkey_set0_pss(EvpPkey *out, const EVP_PKEY_ALG *alg, + UniquePtr rsa) { BSSL_CHECK(alg->pkey_method->pkey_id == EVP_PKEY_RSA_PSS); const auto *alg_pss = static_cast(alg); FromOpaque(rsa.get())->pss_params = alg_pss->pss_params; evp_pkey_set0(out, alg->method, rsa.release()); } -static bssl::evp_decode_result_t rsa_pub_decode_pss(const EVP_PKEY_ALG *alg, - EvpPkey *out, CBS *params, - CBS *key) { +bssl::evp_decode_result_t rsa_pub_decode_pss(const EVP_PKEY_ALG *alg, + EvpPkey *out, CBS *params, + CBS *key) { const auto *alg_pss = static_cast(alg); evp_decode_result_t ret = rsa_decode_pss_params(alg_pss->pss_params, params); if (ret != evp_decode_ok) { @@ -232,7 +232,7 @@ static bssl::evp_decode_result_t rsa_pub_decode_pss(const EVP_PKEY_ALG *alg, return evp_decode_ok; } -static int rsa_priv_encode_pss(CBB *out, const EvpPkey *key) { +int rsa_priv_encode_pss(CBB *out, const EvpPkey *key) { const RSAImpl *rsa = reinterpret_cast(key->pkey); CBB pkcs8, algorithm, private_key; if (!CBB_add_asn1(out, &pkcs8, CBS_ASN1_SEQUENCE) || @@ -251,9 +251,9 @@ static int rsa_priv_encode_pss(CBB *out, const EvpPkey *key) { return 1; } -static bssl::evp_decode_result_t rsa_priv_decode_pss(const EVP_PKEY_ALG *alg, - EvpPkey *out, CBS *params, - CBS *key) { +bssl::evp_decode_result_t rsa_priv_decode_pss(const EVP_PKEY_ALG *alg, + EvpPkey *out, CBS *params, + CBS *key) { const auto *alg_pss = static_cast(alg); evp_decode_result_t ret = rsa_decode_pss_params(alg_pss->pss_params, params); if (ret != evp_decode_ok) { @@ -270,32 +270,32 @@ static bssl::evp_decode_result_t rsa_priv_decode_pss(const EVP_PKEY_ALG *alg, return evp_decode_ok; } -static int rsa_opaque(const EvpPkey *pkey) { +int rsa_opaque(const EvpPkey *pkey) { const RSA *rsa = reinterpret_cast(pkey->pkey); return RSA_is_opaque(rsa); } -static int int_rsa_size(const EvpPkey *pkey) { +int int_rsa_size(const EvpPkey *pkey) { const RSA *rsa = reinterpret_cast(pkey->pkey); return RSA_size(rsa); } -static int rsa_bits(const EvpPkey *pkey) { +int rsa_bits(const EvpPkey *pkey) { const RSA *rsa = reinterpret_cast(pkey->pkey); return RSA_bits(rsa); } -static void int_rsa_free(EvpPkey *pkey) { +void int_rsa_free(EvpPkey *pkey) { RSA_free(reinterpret_cast(pkey->pkey)); pkey->pkey = nullptr; } -static int rsa_pss_params_missing(const EvpPkey *pkey) { +int rsa_pss_params_missing(const EvpPkey *pkey) { const RSA *rsa = reinterpret_cast(pkey->pkey); return rsa == nullptr || FromOpaque(rsa)->pss_params == rsa_pss_none; } -static int rsa_pss_params_copy(EvpPkey *to, const EvpPkey *from) { +int rsa_pss_params_copy(EvpPkey *to, const EvpPkey *from) { const RSA *from_key = reinterpret_cast(from->pkey); if (from_key == nullptr) { OPENSSL_PUT_ERROR(EVP, EVP_R_NO_KEY_SET); @@ -316,7 +316,7 @@ static int rsa_pss_params_copy(EvpPkey *to, const EvpPkey *from) { return 1; } -static bool rsa_pss_params_equal(const EvpPkey *a, const EvpPkey *b) { +bool rsa_pss_params_equal(const EvpPkey *a, const EvpPkey *b) { const RSA *a_rsa = reinterpret_cast(a->pkey); const RSA *b_rsa = reinterpret_cast(b->pkey); if (a_rsa == nullptr || b_rsa == nullptr) { @@ -428,11 +428,11 @@ struct RSA_PKEY_CTX { Array oaep_label; }; -static bool is_pss_only(const EvpPkeyCtx *ctx) { +bool is_pss_only(const EvpPkeyCtx *ctx) { return ctx->pmeth->pkey_id == EVP_PKEY_RSA_PSS; } -static int pkey_rsa_init(EvpPkeyCtx *ctx, const EVP_PKEY_ALG *alg) { +int pkey_rsa_init(EvpPkeyCtx *ctx, const EVP_PKEY_ALG *alg) { RSA_PKEY_CTX *rctx = New(); if (!rctx) { return 0; @@ -462,7 +462,7 @@ static int pkey_rsa_init(EvpPkeyCtx *ctx, const EVP_PKEY_ALG *alg) { return 1; } -static int pkey_rsa_copy(EvpPkeyCtx *dst, EvpPkeyCtx *src) { +int pkey_rsa_copy(EvpPkeyCtx *dst, EvpPkeyCtx *src) { RSA_PKEY_CTX *dctx, *sctx; if (!pkey_rsa_init(dst, nullptr)) { return 0; @@ -489,12 +489,12 @@ static int pkey_rsa_copy(EvpPkeyCtx *dst, EvpPkeyCtx *src) { return 1; } -static void pkey_rsa_cleanup(EvpPkeyCtx *ctx) { +void pkey_rsa_cleanup(EvpPkeyCtx *ctx) { Delete(reinterpret_cast(ctx->data)); } -static int pkey_rsa_sign(EvpPkeyCtx *ctx, uint8_t *sig, size_t *siglen, - const uint8_t *tbs, size_t tbslen) { +int pkey_rsa_sign(EvpPkeyCtx *ctx, uint8_t *sig, size_t *siglen, + const uint8_t *tbs, size_t tbslen) { RSA_PKEY_CTX *rctx = reinterpret_cast(ctx->data); RSA *rsa = reinterpret_cast(ctx->pkey->pkey); const size_t key_len = EVP_PKEY_size(ctx->pkey.get()); @@ -531,8 +531,8 @@ static int pkey_rsa_sign(EvpPkeyCtx *ctx, uint8_t *sig, size_t *siglen, return RSA_sign_raw(rsa, siglen, sig, *siglen, tbs, tbslen, rctx->pad_mode); } -static int pkey_rsa_verify(EvpPkeyCtx *ctx, const uint8_t *sig, size_t siglen, - const uint8_t *tbs, size_t tbslen) { +int pkey_rsa_verify(EvpPkeyCtx *ctx, const uint8_t *sig, size_t siglen, + const uint8_t *tbs, size_t tbslen) { RSA_PKEY_CTX *rctx = reinterpret_cast(ctx->data); RSA *rsa = reinterpret_cast(ctx->pkey->pkey); @@ -566,9 +566,9 @@ static int pkey_rsa_verify(EvpPkeyCtx *ctx, const uint8_t *sig, size_t siglen, return 1; } -static int pkey_rsa_verify_recover(EvpPkeyCtx *ctx, uint8_t *out, - size_t *out_len, const uint8_t *sig, - size_t sig_len) { +int pkey_rsa_verify_recover(EvpPkeyCtx *ctx, uint8_t *out, + size_t *out_len, const uint8_t *sig, + size_t sig_len) { RSA_PKEY_CTX *rctx = reinterpret_cast(ctx->data); RSA *rsa = reinterpret_cast(ctx->pkey->pkey); const size_t key_len = EVP_PKEY_size(ctx->pkey.get()); @@ -626,8 +626,8 @@ static int pkey_rsa_verify_recover(EvpPkeyCtx *ctx, uint8_t *out, return 1; } -static int pkey_rsa_encrypt(EvpPkeyCtx *ctx, uint8_t *out, size_t *outlen, - const uint8_t *in, size_t inlen) { +int pkey_rsa_encrypt(EvpPkeyCtx *ctx, uint8_t *out, size_t *outlen, + const uint8_t *in, size_t inlen) { RSA_PKEY_CTX *rctx = reinterpret_cast(ctx->data); RSA *rsa = reinterpret_cast(ctx->pkey->pkey); const size_t key_len = EVP_PKEY_size(ctx->pkey.get()); @@ -658,8 +658,8 @@ static int pkey_rsa_encrypt(EvpPkeyCtx *ctx, uint8_t *out, size_t *outlen, return RSA_encrypt(rsa, outlen, out, *outlen, in, inlen, rctx->pad_mode); } -static int pkey_rsa_decrypt(EvpPkeyCtx *ctx, uint8_t *out, size_t *outlen, - const uint8_t *in, size_t inlen) { +int pkey_rsa_decrypt(EvpPkeyCtx *ctx, uint8_t *out, size_t *outlen, + const uint8_t *in, size_t inlen) { RSA_PKEY_CTX *rctx = reinterpret_cast(ctx->data); RSA *rsa = reinterpret_cast(ctx->pkey->pkey); const size_t key_len = EVP_PKEY_size(ctx->pkey.get()); @@ -692,7 +692,7 @@ static int pkey_rsa_decrypt(EvpPkeyCtx *ctx, uint8_t *out, size_t *outlen, return RSA_decrypt(rsa, outlen, out, key_len, in, inlen, rctx->pad_mode); } -static int check_padding_md(const EVP_MD *md, int padding) { +int check_padding_md(const EVP_MD *md, int padding) { if (!md) { return 1; } @@ -705,7 +705,7 @@ static int check_padding_md(const EVP_MD *md, int padding) { return 1; } -static int is_known_padding(int padding_mode) { +int is_known_padding(int padding_mode) { switch (padding_mode) { case RSA_PKCS1_PADDING: case RSA_NO_PADDING: @@ -717,7 +717,7 @@ static int is_known_padding(int padding_mode) { } } -static int pkey_rsa_ctrl(EvpPkeyCtx *ctx, int type, int p1, void *p2) { +int pkey_rsa_ctrl(EvpPkeyCtx *ctx, int type, int p1, void *p2) { RSA_PKEY_CTX *rctx = reinterpret_cast(ctx->data); switch (type) { case EVP_PKEY_CTRL_RSA_PADDING: @@ -870,7 +870,7 @@ static int pkey_rsa_ctrl(EvpPkeyCtx *ctx, int type, int p1, void *p2) { } } -static int pkey_rsa_keygen(EvpPkeyCtx *ctx, EvpPkey *pkey) { +int pkey_rsa_keygen(EvpPkeyCtx *ctx, EvpPkey *pkey) { RSA_PKEY_CTX *rctx = reinterpret_cast(ctx->data); if (!rctx->pub_exp) { rctx->pub_exp.reset(BN_new()); diff --git a/third_party/boringssl/src/crypto/evp/p_x25519.cc b/third_party/boringssl/src/crypto/evp/p_x25519.cc index 91df6f4..2c53608 100644 --- a/third_party/boringssl/src/crypto/evp/p_x25519.cc +++ b/third_party/boringssl/src/crypto/evp/p_x25519.cc @@ -37,13 +37,13 @@ struct X25519_KEY { extern const EVP_PKEY_ASN1_METHOD x25519_asn1_meth; extern const EVP_PKEY_CTX_METHOD x25519_pkey_meth; -static void x25519_free(EvpPkey *pkey) { +void x25519_free(EvpPkey *pkey) { X25519_KEY *key = reinterpret_cast(pkey->pkey); OPENSSL_free(key); pkey->pkey = nullptr; } -static int x25519_set_priv_raw(EvpPkey *pkey, const uint8_t *in, size_t len) { +int x25519_set_priv_raw(EvpPkey *pkey, const uint8_t *in, size_t len) { if (len != 32) { OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR); return 0; @@ -62,7 +62,7 @@ static int x25519_set_priv_raw(EvpPkey *pkey, const uint8_t *in, size_t len) { return 1; } -static int x25519_set_pub_raw(EvpPkey *pkey, const uint8_t *in, size_t len) { +int x25519_set_pub_raw(EvpPkey *pkey, const uint8_t *in, size_t len) { if (len != 32) { OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR); return 0; @@ -80,8 +80,7 @@ static int x25519_set_pub_raw(EvpPkey *pkey, const uint8_t *in, size_t len) { return 1; } -static int x25519_get_priv_raw(const EvpPkey *pkey, uint8_t *out, - size_t *out_len) { +int x25519_get_priv_raw(const EvpPkey *pkey, uint8_t *out, size_t *out_len) { const X25519_KEY *key = reinterpret_cast(pkey->pkey); if (!key->has_private) { OPENSSL_PUT_ERROR(EVP, EVP_R_NOT_A_PRIVATE_KEY); @@ -103,8 +102,7 @@ static int x25519_get_priv_raw(const EvpPkey *pkey, uint8_t *out, return 1; } -static int x25519_get_pub_raw(const EvpPkey *pkey, uint8_t *out, - size_t *out_len) { +int x25519_get_pub_raw(const EvpPkey *pkey, uint8_t *out, size_t *out_len) { const X25519_KEY *key = reinterpret_cast(pkey->pkey); if (out == nullptr) { *out_len = 32; @@ -121,13 +119,11 @@ static int x25519_get_pub_raw(const EvpPkey *pkey, uint8_t *out, return 1; } -static int x25519_set1_tls_encodedpoint(EvpPkey *pkey, const uint8_t *in, - size_t len) { +int x25519_set1_tls_encodedpoint(EvpPkey *pkey, const uint8_t *in, size_t len) { return x25519_set_pub_raw(pkey, in, len); } -static size_t x25519_get1_tls_encodedpoint(const EvpPkey *pkey, - uint8_t **out_ptr) { +size_t x25519_get1_tls_encodedpoint(const EvpPkey *pkey, uint8_t **out_ptr) { const X25519_KEY *key = reinterpret_cast(pkey->pkey); if (key == nullptr) { OPENSSL_PUT_ERROR(EVP, EVP_R_NO_KEY_SET); @@ -138,9 +134,9 @@ static size_t x25519_get1_tls_encodedpoint(const EvpPkey *pkey, return *out_ptr == nullptr ? 0 : 32; } -static bssl::evp_decode_result_t x25519_pub_decode(const EVP_PKEY_ALG *alg, - EvpPkey *out, CBS *params, - CBS *key) { +bssl::evp_decode_result_t x25519_pub_decode(const EVP_PKEY_ALG *alg, + EvpPkey *out, CBS *params, + CBS *key) { // See RFC 8410, section 4. // The parameters must be omitted. Public keys have length 32. @@ -154,7 +150,7 @@ static bssl::evp_decode_result_t x25519_pub_decode(const EVP_PKEY_ALG *alg, : evp_decode_error; } -static int x25519_pub_encode(CBB *out, const EvpPkey *pkey) { +int x25519_pub_encode(CBB *out, const EvpPkey *pkey) { const X25519_KEY *key = reinterpret_cast(pkey->pkey); // See RFC 8410, section 4. @@ -174,15 +170,15 @@ static int x25519_pub_encode(CBB *out, const EvpPkey *pkey) { return 1; } -static bool x25519_pub_equal(const EvpPkey *a, const EvpPkey *b) { +bool x25519_pub_equal(const EvpPkey *a, const EvpPkey *b) { const X25519_KEY *a_key = reinterpret_cast(a->pkey); const X25519_KEY *b_key = reinterpret_cast(b->pkey); return OPENSSL_memcmp(a_key->pub, b_key->pub, 32) == 0; } -static bssl::evp_decode_result_t x25519_priv_decode(const EVP_PKEY_ALG *alg, - EvpPkey *out, CBS *params, - CBS *key) { +bssl::evp_decode_result_t x25519_priv_decode(const EVP_PKEY_ALG *alg, + EvpPkey *out, CBS *params, + CBS *key) { // See RFC 8410, section 7. // Parameters must be empty. The key is a 32-byte value wrapped in an extra @@ -199,7 +195,7 @@ static bssl::evp_decode_result_t x25519_priv_decode(const EVP_PKEY_ALG *alg, : evp_decode_error; } -static int x25519_priv_encode(CBB *out, const EvpPkey *pkey) { +int x25519_priv_encode(CBB *out, const EvpPkey *pkey) { const X25519_KEY *key = reinterpret_cast(pkey->pkey); if (!key->has_private) { OPENSSL_PUT_ERROR(EVP, EVP_R_NOT_A_PRIVATE_KEY); @@ -226,9 +222,9 @@ static int x25519_priv_encode(CBB *out, const EvpPkey *pkey) { return 1; } -static bool x25519_pub_present(const EvpPkey *) { return true; } +bool x25519_pub_present(const EvpPkey *) { return true; } -static bool x25519_pub_copy(EvpPkey *out, const EvpPkey *pkey) { +bool x25519_pub_copy(EvpPkey *out, const EvpPkey *pkey) { const X25519_KEY *pkey_x25519 = reinterpret_cast(pkey->pkey); X25519_KEY *public_copy = New(); @@ -241,14 +237,14 @@ static bool x25519_pub_copy(EvpPkey *out, const EvpPkey *pkey) { return true; } -static bool x25519_priv_present(const EvpPkey *pk) { +bool x25519_priv_present(const EvpPkey *pk) { const X25519_KEY *key = reinterpret_cast(pk->pkey); return key->has_private; } -static int x25519_size(const EvpPkey *pkey) { return 32; } +int x25519_size(const EvpPkey *pkey) { return 32; } -static int x25519_bits(const EvpPkey *pkey) { return 253; } +int x25519_bits(const EvpPkey *pkey) { return 253; } const EVP_PKEY_ASN1_METHOD x25519_asn1_meth = { EVP_PKEY_X25519, @@ -281,9 +277,9 @@ const EVP_PKEY_ASN1_METHOD x25519_asn1_meth = { }; // X25519 has no parameters to copy. -static int pkey_x25519_copy(EvpPkeyCtx *dst, EvpPkeyCtx *src) { return 1; } +int pkey_x25519_copy(EvpPkeyCtx *dst, EvpPkeyCtx *src) { return 1; } -static int pkey_x25519_keygen(EvpPkeyCtx *ctx, EvpPkey *pkey) { +int pkey_x25519_keygen(EvpPkeyCtx *ctx, EvpPkey *pkey) { X25519_KEY *key = New(); if (key == nullptr) { return 0; @@ -295,7 +291,7 @@ static int pkey_x25519_keygen(EvpPkeyCtx *ctx, EvpPkey *pkey) { return 1; } -static int pkey_x25519_derive(EvpPkeyCtx *ctx, uint8_t *out, size_t *out_len) { +int pkey_x25519_derive(EvpPkeyCtx *ctx, uint8_t *out, size_t *out_len) { if (ctx->pkey == nullptr || ctx->peerkey == nullptr) { OPENSSL_PUT_ERROR(EVP, EVP_R_KEYS_NOT_SET); return 0; @@ -330,7 +326,7 @@ static int pkey_x25519_derive(EvpPkeyCtx *ctx, uint8_t *out, size_t *out_len) { return 1; } -static int pkey_x25519_ctrl(EvpPkeyCtx *ctx, int type, int p1, void *p2) { +int pkey_x25519_ctrl(EvpPkeyCtx *ctx, int type, int p1, void *p2) { switch (type) { case EVP_PKEY_CTRL_PEER_KEY: // `EVP_PKEY_derive_set_peer` requires the key implement this command, diff --git a/third_party/boringssl/src/crypto/evp/p_xwing.cc b/third_party/boringssl/src/crypto/evp/p_xwing.cc index 8479bf6..7d9362c 100644 --- a/third_party/boringssl/src/crypto/evp/p_xwing.cc +++ b/third_party/boringssl/src/crypto/evp/p_xwing.cc @@ -42,19 +42,19 @@ extern const EVP_PKEY_CTX_METHOD xwing_pkey_meth; // This is the length of `eseed` in draft-connolly-cfrg-xwing-kem-06. constexpr size_t kXwingEncapEntropyBytes = 64; -static void xwing_free(EvpPkey *pkey) { +void xwing_free(EvpPkey *pkey) { Delete(reinterpret_cast(pkey->pkey)); } -static bool xwing_pub_equal(const EvpPkey *a, const EvpPkey *b) { +bool xwing_pub_equal(const EvpPkey *a, const EvpPkey *b) { const XWING_KEY *a_key = reinterpret_cast(a->pkey); const XWING_KEY *b_key = reinterpret_cast(b->pkey); return OPENSSL_memcmp(a_key->pub, b_key->pub, XWING_PUBLIC_KEY_BYTES) == 0; } -static bool xwing_pub_present(const EvpPkey *) { return true; } +bool xwing_pub_present(const EvpPkey *) { return true; } -static bool xwing_pub_copy(EvpPkey *out, const EvpPkey *pkey) { +bool xwing_pub_copy(EvpPkey *out, const EvpPkey *pkey) { const XWING_KEY *pkey_xwing = reinterpret_cast(pkey->pkey); auto public_copy = MakeUnique(); if (public_copy == nullptr) { @@ -66,12 +66,12 @@ static bool xwing_pub_copy(EvpPkey *out, const EvpPkey *pkey) { return true; } -static bool xwing_priv_present(const EvpPkey *pk) { +bool xwing_priv_present(const EvpPkey *pk) { const XWING_KEY *key = reinterpret_cast(pk->pkey); return key->has_private; } -static int xwing_set_priv_seed(EvpPkey *pkey, const uint8_t *in, size_t len) { +int xwing_set_priv_seed(EvpPkey *pkey, const uint8_t *in, size_t len) { auto key = MakeUnique(); if (key == nullptr) { return 0; @@ -88,8 +88,7 @@ static int xwing_set_priv_seed(EvpPkey *pkey, const uint8_t *in, size_t len) { return 1; } -static int xwing_get_priv_seed(const EvpPkey *pkey, uint8_t *out, - size_t *out_len) { +int xwing_get_priv_seed(const EvpPkey *pkey, uint8_t *out, size_t *out_len) { const XWING_KEY *key = reinterpret_cast(pkey->pkey); if (key == nullptr || !key->has_private) { OPENSSL_PUT_ERROR(EVP, EVP_R_NOT_A_PRIVATE_KEY); @@ -113,7 +112,7 @@ static int xwing_get_priv_seed(const EvpPkey *pkey, uint8_t *out, return 1; } -static int xwing_set_pub_raw(EvpPkey *pkey, const uint8_t *in, size_t len) { +int xwing_set_pub_raw(EvpPkey *pkey, const uint8_t *in, size_t len) { if (len != XWING_PUBLIC_KEY_BYTES) { OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR); return 0; @@ -128,8 +127,7 @@ static int xwing_set_pub_raw(EvpPkey *pkey, const uint8_t *in, size_t len) { return 1; } -static int xwing_get_pub_raw(const EvpPkey *pkey, uint8_t *out, - size_t *out_len) { +int xwing_get_pub_raw(const EvpPkey *pkey, uint8_t *out, size_t *out_len) { if (out == nullptr) { *out_len = XWING_PUBLIC_KEY_BYTES; return 1; @@ -144,16 +142,14 @@ static int xwing_get_pub_raw(const EvpPkey *pkey, uint8_t *out, return 1; } -static int xwing_size(const EvpPkey *pkey) { return XWING_CIPHERTEXT_BYTES; } +int xwing_size(const EvpPkey *pkey) { return XWING_CIPHERTEXT_BYTES; } -static int xwing_bits(const EvpPkey *pkey) { - return XWING_PUBLIC_KEY_BYTES * 8; -} +int xwing_bits(const EvpPkey *pkey) { return XWING_PUBLIC_KEY_BYTES * 8; } // X-Wing has no parameters to copy. -static int pkey_xwing_copy_ctx(EvpPkeyCtx *dst, EvpPkeyCtx *src) { return 1; } +int pkey_xwing_copy_ctx(EvpPkeyCtx *dst, EvpPkeyCtx *src) { return 1; } -static int pkey_xwing_keygen(EvpPkeyCtx *ctx, EvpPkey *pkey) { +int pkey_xwing_keygen(EvpPkeyCtx *ctx, EvpPkey *pkey) { auto key = MakeUnique(); if (key == nullptr || !XWING_generate_key(key->pub, &key->priv)) { OPENSSL_PUT_ERROR(EVP, ERR_R_INTERNAL_ERROR); @@ -164,8 +160,8 @@ static int pkey_xwing_keygen(EvpPkeyCtx *ctx, EvpPkey *pkey) { return 1; } -static int xwing_kem_encap(Span out_ciphertext, - Span out_secret, const EVP_PKEY *peer_key) { +int xwing_kem_encap(const EVP_KEM *kem, Span out_ciphertext, + Span out_secret, const EVP_PKEY *peer_key) { if (out_ciphertext.size() != XWING_CIPHERTEXT_BYTES) { OPENSSL_PUT_ERROR(EVP, EVP_R_INVALID_CIPHERTEXT_LENGTH); return 0; @@ -180,10 +176,11 @@ static int xwing_kem_encap(Span out_ciphertext, peer_pubkey->pub); } -static int xwing_kem_encap_external_entropy(Span out_ciphertext, - Span out_secret, - const EVP_PKEY *peer_key, - Span entropy) { +int xwing_kem_encap_external_entropy(const EVP_KEM *kem, + Span out_ciphertext, + Span out_secret, + const EVP_PKEY *peer_key, + Span entropy) { if (out_ciphertext.size() != XWING_CIPHERTEXT_BYTES) { OPENSSL_PUT_ERROR(EVP, EVP_R_INVALID_CIPHERTEXT_LENGTH); return 0; @@ -202,9 +199,8 @@ static int xwing_kem_encap_external_entropy(Span out_ciphertext, peer_pubkey->pub, entropy.data()); } -static int xwing_kem_decap(Span out_secret, - Span ciphertext, - const EVP_PKEY *key) { +int xwing_kem_decap(const EVP_KEM *kem, Span out_secret, + Span ciphertext, const EVP_PKEY *key) { const XWING_KEY *priv = reinterpret_cast(FromOpaque(key)->pkey); if (priv == nullptr || !priv->has_private) { OPENSSL_PUT_ERROR(EVP, EVP_R_NOT_A_PRIVATE_KEY); @@ -223,11 +219,12 @@ static int xwing_kem_decap(Span out_secret, return XWING_decap(out_secret.data(), ciphertext.data(), &priv->priv); } -static const EVP_KEM xwing_evp_kem = { +const EVP_KEM xwing_evp_kem = { EVP_PKEY_XWING, // XWING_CIPHERTEXT_BYTES, // XWING_SHARED_SECRET_BYTES, // kXwingEncapEntropyBytes, // + /*check_key=*/nullptr, // &xwing_kem_encap, // &xwing_kem_encap_external_entropy, // &xwing_kem_decap, // diff --git a/third_party/boringssl/src/crypto/evp/sign.cc b/third_party/boringssl/src/crypto/evp/sign.cc index afccef5..3503c40 100644 --- a/third_party/boringssl/src/crypto/evp/sign.cc +++ b/third_party/boringssl/src/crypto/evp/sign.cc @@ -19,8 +19,6 @@ #include #include -#include "internal.h" - int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) { return EVP_DigestInit_ex(ctx, type, impl); @@ -35,7 +33,7 @@ int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *data, size_t len) { } int EVP_SignFinal(const EVP_MD_CTX *ctx, uint8_t *sig, unsigned *out_sig_len, - EVP_PKEY *pkey) { + const EVP_PKEY *pkey) { // Ensure the final result will fit in `unsigned`. size_t sig_len = EVP_PKEY_size(pkey); if (sig_len > UINT_MAX) { @@ -75,7 +73,7 @@ int EVP_VerifyUpdate(EVP_MD_CTX *ctx, const void *data, size_t len) { } int EVP_VerifyFinal(EVP_MD_CTX *ctx, const uint8_t *sig, size_t sig_len, - EVP_PKEY *pkey) { + const EVP_PKEY *pkey) { uint8_t m[EVP_MAX_MD_SIZE]; unsigned m_len; bssl::ScopedEVP_MD_CTX tmp_ctx; @@ -85,11 +83,9 @@ int EVP_VerifyFinal(EVP_MD_CTX *ctx, const uint8_t *sig, size_t sig_len, } bssl::UniquePtr pkctx(EVP_PKEY_CTX_new(pkey, nullptr)); - if (!pkctx || - !EVP_PKEY_verify_init(pkctx.get()) || + if (!pkctx || !EVP_PKEY_verify_init(pkctx.get()) || !EVP_PKEY_CTX_set_signature_md(pkctx.get(), ctx->digest)) { return 0; } return EVP_PKEY_verify(pkctx.get(), sig, sig_len, m, m_len); } - diff --git a/third_party/boringssl/src/crypto/fipsmodule/bn/exponentiation.cc.inc b/third_party/boringssl/src/crypto/fipsmodule/bn/exponentiation.cc.inc index dfdb907..81b6385 100644 --- a/third_party/boringssl/src/crypto/fipsmodule/bn/exponentiation.cc.inc +++ b/third_party/boringssl/src/crypto/fipsmodule/bn/exponentiation.cc.inc @@ -376,39 +376,67 @@ static void copy_to_prebuf(const BIGNUM *b, int top, BN_ULONG *table, int idx, (void)ret; } +// Window sizes optimized for fixed window size modular exponentiation +// algorithm (BN_mod_exp_mont_consttime). +// +// TODO(davidben): These window sizes were originally set for 64-byte cache +// lines with a cache-line-dependent constant-time mitigation. They can probably +// be revised now that our implementation is no longer cache-time-dependent. +#define BN_window_bits_for_ctime_exponent_size(b) \ + ((b) > 937 ? 6 : (b) > 306 ? 5 : (b) > 89 ? 4 : (b) > 22 ? 3 : 1) +#define BN_MAX_MOD_EXP_CTIME_WINDOW (6) + static int copy_from_prebuf(BIGNUM *b, int top, const BN_ULONG *table, int idx, int window) { if (!bn_wexpand(b, top)) { return 0; } - OPENSSL_memset(b->d, 0, sizeof(BN_ULONG) * top); + assert(window > 0 && window <= BN_MAX_MOD_EXP_CTIME_WINDOW); + + // Compute the selection masks up front. The value barrier prevents Clang + // from adding a branch when `i != idx` and making this copy not constant + // time. const int width = 1 << window; - for (int i = 0; i < width; i++, table += top) { - // Use a value barrier to prevent Clang from adding a branch when `i != idx` - // and making this copy not constant time. Clang is still allowed to learn - // that `mask` is constant across the inner loop, so this won't inhibit any - // vectorization it might do. - BN_ULONG mask = value_barrier_w(constant_time_eq_int(i, idx)); - for (int j = 0; j < top; j++) { - b->d[j] |= table[j] & mask; + BN_ULONG masks[1 << BN_MAX_MOD_EXP_CTIME_WINDOW]; + for (int i = 0; i < width; i++) { + masks[i] = value_barrier_w(constant_time_eq_int(i, idx)); + } + + // Every table entry is read for every limb, independent of `idx`. The output + // is accumulated a few limbs at a time in registers. Updating `b->d` once per + // table entry instead adds a store-to-load dependency to every iteration, + // which the compiler cannot remove because `b->d` may alias `table`. + BN_ULONG *const d = b->d; + int j = 0; + for (; j + 4 <= top; j += 4) { + BN_ULONG a0 = 0, a1 = 0, a2 = 0, a3 = 0; + const BN_ULONG *t = table + j; + for (int i = 0; i < width; i++, t += top) { + BN_ULONG m = masks[i]; + a0 |= t[0] & m; + a1 |= t[1] & m; + a2 |= t[2] & m; + a3 |= t[3] & m; } + d[j] = a0; + d[j + 1] = a1; + d[j + 2] = a2; + d[j + 3] = a3; + } + for (; j < top; j++) { + BN_ULONG a = 0; + const BN_ULONG *t = table + j; + for (int i = 0; i < width; i++, t += top) { + a |= *t & masks[i]; + } + d[j] = a; } b->width = top; return 1; } -// Window sizes optimized for fixed window size modular exponentiation -// algorithm (BN_mod_exp_mont_consttime). -// -// TODO(davidben): These window sizes were originally set for 64-byte cache -// lines with a cache-line-dependent constant-time mitigation. They can probably -// be revised now that our implementation is no longer cache-time-dependent. -#define BN_window_bits_for_ctime_exponent_size(b) \ - ((b) > 937 ? 6 : (b) > 306 ? 5 : (b) > 89 ? 4 : (b) > 22 ? 3 : 1) -#define BN_MAX_MOD_EXP_CTIME_WINDOW (6) - // This variant of `BN_mod_exp_mont` uses fixed windows and fixed memory access // patterns to protect secret exponents (cf. the hyper-threading timing attacks // pointed out by Colin Percival, diff --git a/third_party/boringssl/src/crypto/fipsmodule/dh/dh.cc.inc b/third_party/boringssl/src/crypto/fipsmodule/dh/dh.cc.inc index d018f76..8dfcdee 100644 --- a/third_party/boringssl/src/crypto/fipsmodule/dh/dh.cc.inc +++ b/third_party/boringssl/src/crypto/fipsmodule/dh/dh.cc.inc @@ -353,6 +353,13 @@ int DH_up_ref(DH *dh) { return 1; } +DH *DH_dup_ref(const DH *dh) { + if (dh == nullptr) { + return nullptr; + } + return FromOpaque(dh)->DupRefInternal(); +} + DH *DH_get_rfc7919_2048() { // This is the prime from https://tools.ietf.org/html/rfc7919#appendix-A.1, // which is specifically approved for FIPS in appendix D of SP 800-56Ar3. diff --git a/third_party/boringssl/src/crypto/fipsmodule/digestsign/digestsign.cc.inc b/third_party/boringssl/src/crypto/fipsmodule/digestsign/digestsign.cc.inc index 8920546..a886d46 100644 --- a/third_party/boringssl/src/crypto/fipsmodule/digestsign/digestsign.cc.inc +++ b/third_party/boringssl/src/crypto/fipsmodule/digestsign/digestsign.cc.inc @@ -41,7 +41,7 @@ static int uses_prehash(EVP_PKEY_CTX *pctx, enum evp_sign_verify_t op) { } static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **out_pctx, - const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey, + const EVP_MD *type, ENGINE *e, const EVP_PKEY *pkey, enum evp_sign_verify_t op) { UniquePtr pctx(EVP_PKEY_CTX_new(pkey, e)); if (pctx == nullptr) { @@ -84,12 +84,12 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **out_pctx, } int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, - ENGINE *e, EVP_PKEY *pkey) { + ENGINE *e, const EVP_PKEY *pkey) { return do_sigver_init(ctx, pctx, type, e, pkey, evp_sign); } int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, - const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey) { + const EVP_MD *type, ENGINE *e, const EVP_PKEY *pkey) { return do_sigver_init(ctx, pctx, type, e, pkey, evp_verify); } @@ -143,8 +143,7 @@ int EVP_DigestSignFinal(EVP_MD_CTX *ctx, uint8_t *out_sig, } } -int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const uint8_t *sig, - size_t sig_len) { +int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const uint8_t *sig, size_t sig_len) { if (!uses_prehash(ctx->pctx, evp_verify)) { OPENSSL_PUT_ERROR(EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); return 0; diff --git a/third_party/boringssl/src/crypto/fipsmodule/ec/ec_key.cc.inc b/third_party/boringssl/src/crypto/fipsmodule/ec/ec_key.cc.inc index 18979b9..078e541 100644 --- a/third_party/boringssl/src/crypto/fipsmodule/ec/ec_key.cc.inc +++ b/third_party/boringssl/src/crypto/fipsmodule/ec/ec_key.cc.inc @@ -26,7 +26,6 @@ #include "../../internal.h" #include "../../mem_internal.h" -#include "../bcm_interface.h" #include "../delocate.h" #include "../ecdsa/internal.h" #include "../service_indicator/internal.h" @@ -147,6 +146,13 @@ int EC_KEY_up_ref(EC_KEY *r) { return 1; } +EC_KEY *EC_KEY_dup_ref(const EC_KEY *key) { + if (key == nullptr) { + return nullptr; + } + return FromOpaque(key)->DupRefInternal(); +} + int EC_KEY_is_opaque(const EC_KEY *key) { auto *impl = FromOpaque(key); return impl->ecdsa_meth && (impl->ecdsa_meth->flags & ECDSA_FLAG_OPAQUE); diff --git a/third_party/boringssl/src/crypto/fipsmodule/entropy/jitter.cc.inc b/third_party/boringssl/src/crypto/fipsmodule/entropy/jitter.cc.inc index ebe3a5c..8c75166 100644 --- a/third_party/boringssl/src/crypto/fipsmodule/entropy/jitter.cc.inc +++ b/third_party/boringssl/src/crypto/fipsmodule/entropy/jitter.cc.inc @@ -32,6 +32,7 @@ #include +#include "../../internal.h" #include "internal.h" #include "sha512.cc.inc" @@ -88,6 +89,11 @@ class MemoryAccessSampler { array_size_ & (array_size_ - 1)) { abort(); } + + if (boringssl_fips_break_test("JITTER_APT")) { + // In this break test, array_[0] is used to keep state. See below. + array_[0] = 0; + } } ~MemoryAccessSampler() { OPENSSL_free(const_cast(array_)); } @@ -104,16 +110,28 @@ class MemoryAccessSampler { } bool Next(uint64_t *out) { - // Perform some memory accesses and measure how long it took. The LCG is - // intended to defeat any CPU predictors and thus expose this code to as - // much system entropy as possible. - for (unsigned i = 0; i < num_samples_; i++) { - // The lower bits of an LCG tend to fall into short cycles and so are - // discarded here. - array_[(lcg_.Next() >> 6) & (array_size_ - 1)] += 1; - } + if (boringssl_fips_break_test("JITTER_RCT")) { + // To break the repetition test a constant value is returned. + *out = 1; + } else if (boringssl_fips_break_test("JITTER_APT")) { + // To break the adaptive test, but not the repetition test, a counter + // that advances every fourth call is returned. Since samples are + // processed by `DeltaSampler`, the tests see 0,0,0,1,... which exceeds + // the APT cutoff (348/512) without tripping the RCT (26). + *out = array_[0] >> 2; + array_[0] += 1; + } else { + // Perform some memory accesses and measure how long it took. The LCG is + // intended to defeat any CPU predictors and thus expose this code to as + // much system entropy as possible. + for (unsigned i = 0; i < num_samples_; i++) { + // The lower bits of an LCG tend to fall into short cycles and so are + // discarded here. + array_[(lcg_.Next() >> 6) & (array_size_ - 1)] += 1; + } - *out = GetTimestamp(); + *out = GetTimestamp(); + } return true; } @@ -226,6 +244,9 @@ class RepetitionCountTest { last_sample_ = sample; } if (count_ >= kThreshold) { +#if defined(BORINGSSL_FIPS_BREAK_TESTS) + fprintf(stderr, "Jitter RCT failure.\n"); +#endif return false; } *out = sample; @@ -351,6 +372,9 @@ class AdaptiveProportionTest { const uint16_t new_count = ++counts_[sample]; if (new_count > kThreshold) { +#if defined(BORINGSSL_FIPS_BREAK_TESTS) + fprintf(stderr, "Jitter APT failure.\n"); +#endif return false; } diff --git a/third_party/boringssl/src/crypto/fipsmodule/keccak/internal.h b/third_party/boringssl/src/crypto/fipsmodule/keccak/internal.h index e7d79b0..fa1e2e8 100644 --- a/third_party/boringssl/src/crypto/fipsmodule/keccak/internal.h +++ b/third_party/boringssl/src/crypto/fipsmodule/keccak/internal.h @@ -22,8 +22,18 @@ BSSL_NAMESPACE_BEGIN +#define BITS_TO_BYTES(BITS) ((BITS) / 8) +#define SHA3_256_DIGEST_LENGTH BITS_TO_BYTES(256) +#define SHA3_384_DIGEST_LENGTH BITS_TO_BYTES(384) +#define SHA3_512_DIGEST_LENGTH BITS_TO_BYTES(512) +#define SHA3_BLOCK_SIZE(BITS) BITS_TO_BYTES(1600 - 2 * (BITS)) +#define SHA3_256_CBLOCK SHA3_BLOCK_SIZE(256) +#define SHA3_384_CBLOCK SHA3_BLOCK_SIZE(384) +#define SHA3_512_CBLOCK SHA3_BLOCK_SIZE(512) + enum boringssl_keccak_config_t : int32_t { boringssl_sha3_256, + boringssl_sha3_384, boringssl_sha3_512, boringssl_shake128, boringssl_shake256, diff --git a/third_party/boringssl/src/crypto/fipsmodule/keccak/keccak.cc.inc b/third_party/boringssl/src/crypto/fipsmodule/keccak/keccak.cc.inc index adb09a2..e808dd5 100644 --- a/third_party/boringssl/src/crypto/fipsmodule/keccak/keccak.cc.inc +++ b/third_party/boringssl/src/crypto/fipsmodule/keccak/keccak.cc.inc @@ -205,6 +205,10 @@ static void keccak_init(struct BORINGSSL_keccak_st *ctx, capacity_bytes = 512 / 8; required_out_len = 32; break; + case boringssl_sha3_384: + capacity_bytes = 768 / 8; + required_out_len = 48; + break; case boringssl_sha3_512: capacity_bytes = 1024 / 8; required_out_len = 64; @@ -235,8 +239,9 @@ static void keccak_init(struct BORINGSSL_keccak_st *ctx, [[maybe_unused]] static bool keccak_can_parallel( enum boringssl_keccak_config_t config) { - return config == boringssl_sha3_256 || config == boringssl_sha3_512 || - config == boringssl_shake128 || config == boringssl_shake256; + return config == boringssl_sha3_256 || config == boringssl_sha3_384 || + config == boringssl_sha3_512 || config == boringssl_shake128 || + config == boringssl_shake256; } static bool keccak_is_cshake(enum boringssl_keccak_config_t config) { @@ -430,6 +435,7 @@ void bssl::BORINGSSL_cshake(uint8_t *out, size_t out_len, const uint8_t *in, static uint8_t keccak_terminator(struct BORINGSSL_keccak_st *ctx) { switch (ctx->config) { case boringssl_sha3_256: + case boringssl_sha3_384: case boringssl_sha3_512: return 0x06; case boringssl_shake128: diff --git a/third_party/boringssl/src/crypto/fipsmodule/rsa/rsa.cc.inc b/third_party/boringssl/src/crypto/fipsmodule/rsa/rsa.cc.inc index edec7ac..cf406b2 100644 --- a/third_party/boringssl/src/crypto/fipsmodule/rsa/rsa.cc.inc +++ b/third_party/boringssl/src/crypto/fipsmodule/rsa/rsa.cc.inc @@ -31,7 +31,6 @@ #include "../../internal.h" #include "../../mem_internal.h" -#include "../bcm_interface.h" #include "../bn/internal.h" #include "../delocate.h" #include "internal.h" @@ -222,6 +221,13 @@ int RSA_up_ref(RSA *rsa) { return 1; } +RSA *RSA_dup_ref(const RSA *rsa) { + if (rsa == nullptr) { + return nullptr; + } + return FromOpaque(rsa)->DupRefInternal(); +} + unsigned RSA_bits(const RSA *rsa) { return BN_num_bits(FromOpaque(rsa)->n.get()); } diff --git a/third_party/boringssl/src/crypto/hpke/hpke.cc b/third_party/boringssl/src/crypto/hpke/hpke.cc index 11f61ba..ceeb2e6 100644 --- a/third_party/boringssl/src/crypto/hpke/hpke.cc +++ b/third_party/boringssl/src/crypto/hpke/hpke.cc @@ -49,18 +49,63 @@ using namespace bssl; #define MAX_SEED_LEN XWING_SEED_LEN #define MAX_SHARED_SECRET_LEN SHA256_DIGEST_LENGTH +namespace { + +// HpkeKeyMethod implements the key-type-specific operations that HPKE performs +// on keys of a particular `EVP_PKEY_ALG` type. +struct HpkeKeyMethod { + // hpke_kem_id is the ID of the KEM in RFC 9180. + uint16_t hpke_kem_id; + + // public_key_len corresponds to Npk in RFC 9180. + size_t public_key_len; + // private_key_len corresponds to Nsk in RFC 9180. + size_t private_key_len; + + const EVP_PKEY_ALG *(*alg_func)(); + + // deserialize_private_key and serialize_private_key implement the + // DeserializePrivateKey and SerializePrivateKey operations for the key type + // from section 4 of RFC 9180, using the same format accepted by + // `EVP_HPKE_KEY_init`. + EVP_PKEY *(*deserialize_private_key)(const EVP_PKEY_ALG *alg, + const uint8_t *in, size_t len); + int (*serialize_private_key)(const EVP_PKEY *pkey, uint8_t *out, + size_t *out_len); + + // deserialize_public_key and serialize_public_key implement the + // DeserializePublicKey and SerializePublicKey operations from section 4 of + // RFC 9180. + EVP_PKEY *(*deserialize_public_key)(const EVP_PKEY_ALG *alg, + const uint8_t *in, size_t len); + int (*serialize_public_key)(const EVP_PKEY *pkey, uint8_t *out, + size_t *out_len); + + // derive_key_pair implements the DeriveKeyPair operation from section 4 of + // RFC 9180. + EVP_PKEY *(*derive_key_pair)(const EVP_PKEY_ALG *alg, uint16_t kem_suite_id, + Span ikm); +}; + +} // namespace + struct evp_hpke_kem_st { uint16_t id; - // evp_pkey_alg_func and evp_kem_func, if non-null, provide the EVP_PKEY_CTX - // and EVP_KEM functionality backing this EVP_HPKE_KEM. If these are non-null, - // then `init_key`, `generate_key`, `derive_key`, `encap_with_seed`, and - // `decap` are null and 'seed_len` and `enc_len` are zero (until fully - // migrated), and the `evp_*` function pointers are non-null. + // evp_kem_func and key_method, if non-null, provide the EVP_PKEY_CTX and + // EVP_KEM functionality backing this EVP_HPKE_KEM. If these are non-null, + // then (until fully migrated): + // * `init_key`, `generate_key`, and `derive_key` are null (these operations + // are supplied by `key_method`), + // * `encap_with_seed`, and `decap` are null (these operations are supplied + // by the `EVP_KEM`), + // * `public_key_len` and `private_key_len` are zero (they are supplied by + // `key_method`), and + // * `seed_len` and `enc_len` are zero (they are supplied by the `EVP_KEM`). // TODO(crbug.com/535883377): Unify EVP_HPKE_KEM and EVP_KEM for all supported // HPKE KEMs. - const EVP_PKEY_ALG *(*evp_pkey_alg_func)(); const EVP_KEM *(*evp_kem_func)(); + const HpkeKeyMethod *key_method; size_t public_key_len; size_t private_key_len; @@ -90,21 +135,6 @@ struct evp_hpke_kem_st { size_t *out_shared_secret_len, const uint8_t *enc, size_t enc_len, const uint8_t *peer_public_key, size_t peer_public_key_len); - - // Hooks used for operations with `evp_pkey_alg_func` and `evp_kem_func`, when - // they are non-null. - // TODO(crbug.com/535883377): Unify EVP_HPKE_KEM and EVP_KEM for all supported - // HPKE KEMs. - EVP_PKEY *(*evp_deserialize_private_key)(const EVP_PKEY_ALG *alg, - const uint8_t *in, size_t len); - int (*evp_serialize_private_key)(const EVP_PKEY *pkey, uint8_t *out, - size_t *out_len); - EVP_PKEY *(*evp_deserialize_public_key)(const EVP_PKEY_ALG *alg, - const uint8_t *in, size_t len); - int (*evp_serialize_public_key)(const EVP_PKEY *pkey, uint8_t *out, - size_t *out_len); - EVP_PKEY *(*evp_derive_key_pair)(const EVP_PKEY_ALG *alg, - Span ikm); }; struct evp_hpke_kdf_st { @@ -389,8 +419,8 @@ const EVP_HPKE_KEM *EVP_hpke_x25519_hkdf_sha256() { static const EVP_HPKE_KEM kKEM = { /*id=*/EVP_HPKE_DHKEM_X25519_HKDF_SHA256, // TODO(crbug.com/503758094): Expose this as an EVP_KEM. - /*evp_pkey_alg_func=*/nullptr, /*evp_kem_func=*/nullptr, + /*key_method=*/nullptr, /*public_key_len=*/X25519_PUBLIC_VALUE_LEN, /*private_key_len=*/X25519_PRIVATE_KEY_LEN, /*seed_len=*/X25519_PRIVATE_KEY_LEN, @@ -402,12 +432,6 @@ const EVP_HPKE_KEM *EVP_hpke_x25519_hkdf_sha256() { x25519_decap, x25519_auth_encap_with_seed, x25519_auth_decap, - // TODO(crbug.com/503758094): Implement this in terms of an EVP_KEM. - /*evp_deserialize_private_key=*/nullptr, - /*evp_serialize_private_key=*/nullptr, - /*evp_deserialize_public_key=*/nullptr, - /*evp_serialize_public_key=*/nullptr, - /*evp_derive_key_pair=*/nullptr, }; return &kKEM; } @@ -689,8 +713,8 @@ const EVP_HPKE_KEM *EVP_hpke_p256_hkdf_sha256() { static const EVP_HPKE_KEM kKEM = { /*id=*/EVP_HPKE_DHKEM_P256_HKDF_SHA256, // TODO(crbug.com/503758094): Expose this as an EVP_KEM. - /*evp_pkey_alg_func=*/nullptr, /*evp_kem_func=*/nullptr, + /*key_method=*/nullptr, /*public_key_len=*/P256_PUBLIC_KEY_LEN, /*private_key_len=*/P256_PRIVATE_KEY_LEN, /*seed_len=*/P256_SEED_LEN, @@ -702,12 +726,6 @@ const EVP_HPKE_KEM *EVP_hpke_p256_hkdf_sha256() { p256_decap, p256_auth_encap_with_seed, p256_auth_decap, - // TODO(crbug.com/503758094): Implement this in terms of an EVP_KEM. - /*evp_deserialize_private_key=*/nullptr, - /*evp_serialize_private_key=*/nullptr, - /*evp_deserialize_public_key=*/nullptr, - /*evp_serialize_public_key=*/nullptr, - /*evp_derive_key_pair=*/nullptr, }; return &kKEM; } @@ -718,22 +736,35 @@ const EVP_HPKE_KEM *EVP_hpke_p256_hkdf_sha256() { #define XWING_SEED_LEN 64 #define XWING_SHARED_KEY_LEN XWING_SHARED_SECRET_BYTES -static EVP_PKEY *xwing_derive_key_pair(const EVP_PKEY_ALG *alg, - Span ikm) { - uint8_t seed[XWING_PRIVATE_KEY_BYTES]; - hpke_shake256_labeled_derive(seed, ikm, hpke_kem_suite_id(EVP_HPKE_XWING), +template +static EVP_PKEY *shake256_derive_key_pair_from_private_seed( + const EVP_PKEY_ALG *alg, uint16_t kem_suite_id, Span ikm) { + uint8_t seed[SEED_BYTES]; + hpke_shake256_labeled_derive(seed, ikm, hpke_kem_suite_id(kem_suite_id), "DeriveKeyPair", /*context=*/{}); return EVP_PKEY_from_private_seed(alg, seed, sizeof(seed)); } +static constexpr HpkeKeyMethod kXwingKeyMethod = { + /*hpke_kem_id=*/EVP_HPKE_XWING, + /*public_key_len=*/XWING_PUBLIC_KEY_LEN, + /*private_key_len=*/XWING_PRIVATE_KEY_LEN, + /*alg_func=*/&EVP_pkey_xwing, + /*deserialize_private_key=*/&EVP_PKEY_from_private_seed, + /*serialize_private_key=*/&EVP_PKEY_get_private_seed, + /*deserialize_public_key=*/&EVP_PKEY_from_raw_public_key, + /*serialize_public_key=*/&EVP_PKEY_get_raw_public_key, + /*derive_key_pair=*/ + shake256_derive_key_pair_from_private_seed, +}; const EVP_HPKE_KEM *EVP_hpke_xwing() { static const EVP_HPKE_KEM kKEM = { /*id=*/EVP_HPKE_XWING, - /*evp_pkey_alg_func=*/&EVP_pkey_xwing, /*evp_kem_func=*/&EVP_kem_xwing, - /*public_key_len=*/XWING_PUBLIC_KEY_LEN, - /*private_key_len=*/XWING_PRIVATE_KEY_LEN, + /*key_method=*/&kXwingKeyMethod, + /*public_key_len=*/0, + /*private_key_len=*/0, /*seed_len=*/0, /*enc_len=*/0, /*init_key=*/nullptr, @@ -743,32 +774,32 @@ const EVP_HPKE_KEM *EVP_hpke_xwing() { /*decap=*/nullptr, // X-Wing doesn't support authenticated encapsulation/decapsulation: // https://datatracker.ietf.org/doc/html/draft-connolly-cfrg-xwing-kem-08#name-use-in-hpke - /* auth_encap_with_seed= */ nullptr, - /* auth_decap= */ nullptr, - /*evp_deserialize_private_key=*/&EVP_PKEY_from_private_seed, - /*evp_serialize_private_key=*/&EVP_PKEY_get_private_seed, - /*evp_deserialize_public_key=*/&EVP_PKEY_from_raw_public_key, - /*evp_serialize_public_key=*/&EVP_PKEY_get_raw_public_key, - /*evp_derive_key_pair=*/xwing_derive_key_pair, + /*auth_encap_with_seed=*/nullptr, + /*auth_decap=*/nullptr, }; return &kKEM; } -static EVP_PKEY *mlkem768_derive_key_pair(const EVP_PKEY_ALG *alg, - Span ikm) { - uint8_t seed[MLKEM_SEED_BYTES]; - hpke_shake256_labeled_derive(seed, ikm, hpke_kem_suite_id(EVP_HPKE_MLKEM768), - "DeriveKeyPair", /*context=*/{}); - return EVP_PKEY_from_private_seed(alg, seed, sizeof(seed)); -} +static constexpr HpkeKeyMethod kMlkem768KeyMethod = { + /*hpke_kem_id=*/EVP_HPKE_MLKEM768, + /*public_key_len=*/MLKEM768_PUBLIC_KEY_BYTES, + /*private_key_len=*/MLKEM_SEED_BYTES, + /*alg_func=*/&EVP_pkey_ml_kem_768, + /*deserialize_private_key=*/&EVP_PKEY_from_private_seed, + /*serialize_private_key=*/&EVP_PKEY_get_private_seed, + /*deserialize_public_key=*/&EVP_PKEY_from_raw_public_key, + /*serialize_public_key=*/&EVP_PKEY_get_raw_public_key, + /*derive_key_pair=*/ + shake256_derive_key_pair_from_private_seed, +}; const EVP_HPKE_KEM *EVP_hpke_mlkem768() { static const EVP_HPKE_KEM kKEM = { /*id=*/EVP_HPKE_MLKEM768, - /*evp_pkey_alg_func=*/&EVP_pkey_ml_kem_768, /*evp_kem_func=*/&EVP_kem_ml_kem_768, - /*public_key_len=*/MLKEM768_PUBLIC_KEY_BYTES, - /*private_key_len=*/MLKEM_SEED_BYTES, + /*key_method=*/&kMlkem768KeyMethod, + /*public_key_len=*/0, + /*private_key_len=*/0, /*seed_len=*/0, /*enc_len=*/0, /*init_key=*/nullptr, @@ -780,30 +811,30 @@ const EVP_HPKE_KEM *EVP_hpke_mlkem768() { // https://datatracker.ietf.org/doc/draft-ietf-hpke-pq/01/ /*auth_encap_with_seed=*/nullptr, /*auth_decap=*/nullptr, - /*evp_deserialize_private_key=*/&EVP_PKEY_from_private_seed, - /*evp_serialize_private_key=*/&EVP_PKEY_get_private_seed, - /*evp_deserialize_public_key=*/&EVP_PKEY_from_raw_public_key, - /*evp_serialize_public_key=*/&EVP_PKEY_get_raw_public_key, - /*evp_derive_key_pair=*/mlkem768_derive_key_pair, }; return &kKEM; } -static EVP_PKEY *mlkem1024_derive_key_pair(const EVP_PKEY_ALG *alg, - Span ikm) { - uint8_t seed[MLKEM_SEED_BYTES]; - hpke_shake256_labeled_derive(seed, ikm, hpke_kem_suite_id(EVP_HPKE_MLKEM1024), - "DeriveKeyPair", /*context=*/{}); - return EVP_PKEY_from_private_seed(alg, seed, sizeof(seed)); -} +static constexpr HpkeKeyMethod kMlkem1024KeyMethod = { + /*hpke_kem_id=*/EVP_HPKE_MLKEM1024, + /*public_key_len=*/MLKEM1024_PUBLIC_KEY_BYTES, + /*private_key_len=*/MLKEM_SEED_BYTES, + /*alg_func=*/&EVP_pkey_ml_kem_1024, + /*deserialize_private_key=*/&EVP_PKEY_from_private_seed, + /*serialize_private_key=*/&EVP_PKEY_get_private_seed, + /*deserialize_public_key=*/&EVP_PKEY_from_raw_public_key, + /*serialize_public_key=*/&EVP_PKEY_get_raw_public_key, + /*derive_key_pair=*/ + shake256_derive_key_pair_from_private_seed, +}; const EVP_HPKE_KEM *EVP_hpke_mlkem1024() { static const EVP_HPKE_KEM kKEM = { /*id=*/EVP_HPKE_MLKEM1024, - /*evp_pkey_alg_func=*/&EVP_pkey_ml_kem_1024, /*evp_kem_func=*/&EVP_kem_ml_kem_1024, - /*public_key_len=*/MLKEM1024_PUBLIC_KEY_BYTES, - /*private_key_len=*/MLKEM_SEED_BYTES, + /*key_method=*/&kMlkem1024KeyMethod, + /*public_key_len=*/0, + /*private_key_len=*/0, /*seed_len=*/0, /*enc_len=*/0, /*init_key=*/nullptr, @@ -815,11 +846,6 @@ const EVP_HPKE_KEM *EVP_hpke_mlkem1024() { // https://datatracker.ietf.org/doc/draft-ietf-hpke-pq/01/ /*auth_encap_with_seed=*/nullptr, /*auth_decap=*/nullptr, - /*evp_deserialize_private_key=*/&EVP_PKEY_from_private_seed, - /*evp_serialize_private_key=*/&EVP_PKEY_get_private_seed, - /*evp_deserialize_public_key=*/&EVP_PKEY_from_raw_public_key, - /*evp_serialize_public_key=*/&EVP_PKEY_get_raw_public_key, - /*evp_derive_key_pair=*/mlkem1024_derive_key_pair, }; return &kKEM; } @@ -832,7 +858,7 @@ namespace { // HPKE KEMs. bool uses_evp(const EVP_HPKE_KEM *kem) { - return kem->evp_pkey_alg_func != nullptr && kem->evp_kem_func != nullptr; + return kem->evp_kem_func != nullptr && kem->key_method != nullptr; } } // namespace @@ -840,10 +866,16 @@ bool uses_evp(const EVP_HPKE_KEM *kem) { uint16_t EVP_HPKE_KEM_id(const EVP_HPKE_KEM *kem) { return kem->id; } size_t EVP_HPKE_KEM_public_key_len(const EVP_HPKE_KEM *kem) { + if (uses_evp(kem)) { + return kem->key_method->public_key_len; + } return kem->public_key_len; } size_t EVP_HPKE_KEM_private_key_len(const EVP_HPKE_KEM *kem) { + if (uses_evp(kem)) { + return kem->key_method->private_key_len; + } return kem->private_key_len; } @@ -856,6 +888,18 @@ size_t EVP_HPKE_KEM_enc_len(const EVP_HPKE_KEM *kem) { return kem->enc_len; } +// TODO(crbug.com/535883377): Implement in terms of EVP_KEM for all supported +// HPKE KEMs. +size_t EVP_HPKE_KEM_shared_secret_len(const EVP_HPKE_KEM *kem) { + if (uses_evp(kem)) { + return EVP_KEM_secret_len(kem->evp_kem_func()); + } + // All other KEMs have the same shared secret length. We assume we'll finish + // https://crbug.com/503758094 and move all KEMs to EVP before adding one that + // breaks this. + return SHA256_DIGEST_LENGTH; +} + // TODO(crbug.com/535883377): Implement in terms of EVP_KEM for all supported // HPKE KEMs. void EVP_HPKE_KEY_zero(EVP_HPKE_KEY *key) { @@ -911,8 +955,8 @@ int EVP_HPKE_KEY_init(EVP_HPKE_KEY *key, const EVP_HPKE_KEM *kem, // TODO(crbug.com/535883377): Implement in terms of EVP_KEM for all supported // HPKE KEMs. if (uses_evp(kem)) { - UniquePtr pkey(kem->evp_deserialize_private_key( - kem->evp_pkey_alg_func(), priv_key, priv_key_len)); + UniquePtr pkey(kem->key_method->deserialize_private_key( + kem->key_method->alg_func(), priv_key, priv_key_len)); if (pkey == nullptr) { key->kem = nullptr; return 0; @@ -934,7 +978,7 @@ int EVP_HPKE_KEY_generate(EVP_HPKE_KEY *key, const EVP_HPKE_KEM *kem) { // HPKE KEMs. if (uses_evp(kem)) { UniquePtr pkey( - EVP_PKEY_generate_from_alg(kem->evp_pkey_alg_func())); + EVP_PKEY_generate_from_alg(kem->key_method->alg_func())); if (pkey == nullptr) { key->kem = nullptr; return 0; @@ -956,8 +1000,8 @@ int EVP_HPKE_KEY_derive(EVP_HPKE_KEY *key, const EVP_HPKE_KEM *kem, // TODO(crbug.com/535883377): Implement in terms of EVP_KEM for all supported // HPKE KEMs. if (uses_evp(kem)) { - UniquePtr pkey( - kem->evp_derive_key_pair(kem->evp_pkey_alg_func(), Span(ikm, ikm_len))); + UniquePtr pkey(kem->key_method->derive_key_pair( + kem->key_method->alg_func(), kem->id, Span(ikm, ikm_len))); if (pkey == nullptr) { key->kem = nullptr; return 0; @@ -978,7 +1022,7 @@ const EVP_HPKE_KEM *EVP_HPKE_KEY_kem(const EVP_HPKE_KEY *key) { int EVP_HPKE_KEY_public_key(const EVP_HPKE_KEY *key, uint8_t *out, size_t *out_len, size_t max_out) { - if (max_out < key->kem->public_key_len) { + if (max_out < EVP_HPKE_KEM_public_key_len(key->kem)) { OPENSSL_PUT_ERROR(EVP, EVP_R_INVALID_BUFFER_SIZE); return 0; } @@ -986,7 +1030,7 @@ int EVP_HPKE_KEY_public_key(const EVP_HPKE_KEY *key, uint8_t *out, // HPKE KEMs. if (uses_evp(key->kem)) { *out_len = max_out; - return key->kem->evp_serialize_public_key(key->pkey, out, out_len); + return key->kem->key_method->serialize_public_key(key->pkey, out, out_len); } OPENSSL_memcpy(out, key->public_key, key->kem->public_key_len); *out_len = key->kem->public_key_len; @@ -995,7 +1039,7 @@ int EVP_HPKE_KEY_public_key(const EVP_HPKE_KEY *key, uint8_t *out, int EVP_HPKE_KEY_private_key(const EVP_HPKE_KEY *key, uint8_t *out, size_t *out_len, size_t max_out) { - if (max_out < key->kem->private_key_len) { + if (max_out < EVP_HPKE_KEM_private_key_len(key->kem)) { OPENSSL_PUT_ERROR(EVP, EVP_R_INVALID_BUFFER_SIZE); return 0; } @@ -1003,7 +1047,7 @@ int EVP_HPKE_KEY_private_key(const EVP_HPKE_KEY *key, uint8_t *out, // HPKE KEMs. if (uses_evp(key->kem)) { *out_len = max_out; - return key->kem->evp_serialize_private_key(key->pkey, out, out_len); + return key->kem->key_method->serialize_private_key(key->pkey, out, out_len); } OPENSSL_memcpy(out, key->private_key, key->kem->private_key_len); *out_len = key->kem->private_key_len; @@ -1203,8 +1247,8 @@ int EVP_HPKE_CTX_setup_sender(EVP_HPKE_CTX *ctx, uint8_t *out_enc, shared_secret_len = EVP_KEM_secret_len(evp_kem); assert(size_t{MAX_SHARED_SECRET_LEN} >= shared_secret_len); - UniquePtr peer_pubkey(kem->evp_deserialize_public_key( - kem->evp_pkey_alg_func(), peer_public_key, peer_public_key_len)); + UniquePtr peer_pubkey(kem->key_method->deserialize_public_key( + kem->key_method->alg_func(), peer_public_key, peer_public_key_len)); if (peer_pubkey == nullptr || !EVP_KEM_encap(evp_kem, out_enc, *out_enc_len, shared_secret, shared_secret_len, peer_pubkey.get()) || @@ -1249,8 +1293,8 @@ int EVP_HPKE_CTX_setup_sender_with_seed_for_testing( shared_secret_len = EVP_KEM_secret_len(evp_kem); assert(size_t{MAX_SHARED_SECRET_LEN} >= shared_secret_len); - UniquePtr peer_pubkey(kem->evp_deserialize_public_key( - kem->evp_pkey_alg_func(), peer_public_key, peer_public_key_len)); + UniquePtr peer_pubkey(kem->key_method->deserialize_public_key( + kem->key_method->alg_func(), peer_public_key, peer_public_key_len)); if (peer_pubkey == nullptr || !EVP_KEM_encap_external_entropy_for_testing( evp_kem, out_enc, *out_enc_len, shared_secret, shared_secret_len, @@ -1274,44 +1318,58 @@ int EVP_HPKE_CTX_setup_sender_with_seed_for_testing( return 1; } +int EVP_HPKE_CTX_setup_recipient_with_shared_secret( + EVP_HPKE_CTX *ctx, const EVP_HPKE_KEM *kem, const EVP_HPKE_KDF *kdf, + const EVP_HPKE_AEAD *aead, const uint8_t *shared_secret, + size_t shared_secret_len, const uint8_t *info, size_t info_len) { + EVP_HPKE_CTX_zero(ctx); + + if (shared_secret_len != EVP_HPKE_KEM_shared_secret_len(kem)) { + OPENSSL_PUT_ERROR(EVP, EVP_R_INVALID_BUFFER_SIZE); + return 0; + } + + ctx->is_sender = 0; + ctx->kem = kem; + ctx->kdf = kdf; + ctx->aead = aead; + if (!hpke_key_schedule(ctx, HPKE_MODE_BASE, shared_secret, shared_secret_len, + info, info_len)) { + EVP_HPKE_CTX_cleanup(ctx); + return 0; + } + return 1; +} + int EVP_HPKE_CTX_setup_recipient(EVP_HPKE_CTX *ctx, const EVP_HPKE_KEY *key, const EVP_HPKE_KDF *kdf, const EVP_HPKE_AEAD *aead, const uint8_t *enc, size_t enc_len, const uint8_t *info, size_t info_len) { EVP_HPKE_CTX_zero(ctx); - ctx->is_sender = 0; - ctx->kem = key->kem; - ctx->kdf = kdf; - ctx->aead = aead; + uint8_t shared_secret[MAX_SHARED_SECRET_LEN]; size_t shared_secret_len; // TODO(crbug.com/535883377): Implement in terms of EVP_KEM for all supported // HPKE KEMs. + int decap_ok; if (uses_evp(key->kem)) { const EVP_KEM *evp_kem = key->kem->evp_kem_func(); const EVP_PKEY *decap_key = key->pkey; shared_secret_len = EVP_KEM_secret_len(evp_kem); assert(size_t{MAX_SHARED_SECRET_LEN} >= shared_secret_len); - if (!EVP_KEM_decap(evp_kem, shared_secret, shared_secret_len, enc, enc_len, - decap_key) || - !hpke_key_schedule(ctx, HPKE_MODE_BASE, shared_secret, - shared_secret_len, info, info_len)) { - EVP_HPKE_CTX_cleanup(ctx); - return 0; - } - return 1; + decap_ok = EVP_KEM_decap(evp_kem, shared_secret, shared_secret_len, enc, + enc_len, decap_key); + } else { + decap_ok = + key->kem->decap(key, shared_secret, &shared_secret_len, enc, enc_len); } - if (!key->kem->decap(key, shared_secret, &shared_secret_len, enc, enc_len) || - !hpke_key_schedule(ctx, HPKE_MODE_BASE, shared_secret, shared_secret_len, - info, info_len)) { - EVP_HPKE_CTX_cleanup(ctx); - return 0; - } - return 1; + return decap_ok && EVP_HPKE_CTX_setup_recipient_with_shared_secret( + ctx, key->kem, kdf, aead, shared_secret, + shared_secret_len, info, info_len); } diff --git a/third_party/boringssl/src/crypto/internal.h b/third_party/boringssl/src/crypto/internal.h index e318a24..f49d0a5 100644 --- a/third_party/boringssl/src/crypto/internal.h +++ b/third_party/boringssl/src/crypto/internal.h @@ -657,7 +657,7 @@ class OPENSSL_EXPORT StaticMutex { // UnlockWrite releases a write lock. void UnlockWrite(); -protected: + protected: #if !defined(OPENSSL_THREADS) // Nothing. #elif defined(OPENSSL_WINDOWS_THREADS) @@ -669,7 +669,7 @@ class OPENSSL_EXPORT StaticMutex { #endif }; -class OPENSSL_EXPORT Mutex : public StaticMutex { +class OPENSSL_EXPORT Mutex : public StaticMutex { public: constexpr Mutex() = default; ~Mutex(); @@ -780,9 +780,9 @@ struct ExDataClass { // CRYPTO_get_ex_new_index_ex allocates a new index for `ex_data_class`. Each // class of object should provide a wrapper function that uses the correct // `ExDataClass`. It returns the new index on success and -1 on error. -OPENSSL_EXPORT int CRYPTO_get_ex_new_index_ex( - ExDataClass *ex_data_class, long argl, void *argp, - CRYPTO_EX_free *free_func); +OPENSSL_EXPORT int CRYPTO_get_ex_new_index_ex(ExDataClass *ex_data_class, + long argl, void *argp, + CRYPTO_EX_free *free_func); // CRYPTO_set_ex_data sets an extra data pointer on a given object. Each class // of object should provide a wrapper function. @@ -1031,7 +1031,7 @@ inline uint64_t CRYPTO_rotr_u64(uint64_t value, int shift) { // CRYPTO_bit_width returns the smallest number of bits needed to represent `n`. // It returns zero if `n` is zero. -inline int CRYPTO_bit_width(uint64_t n) { +inline constexpr int CRYPTO_bit_width(uint64_t n) { #if OPENSSL_HAS_BUILTIN(__builtin_clzll) static_assert(sizeof(unsigned long long) >= sizeof(uint64_t)); return n ? (sizeof(unsigned long long) * 8 - __builtin_clzll(n)) : 0; diff --git a/third_party/boringssl/src/crypto/mem_internal.h b/third_party/boringssl/src/crypto/mem_internal.h index 59927e1..488052f 100644 --- a/third_party/boringssl/src/crypto/mem_internal.h +++ b/third_party/boringssl/src/crypto/mem_internal.h @@ -135,6 +135,13 @@ class RefCounted { // ref-count variable. CRYPTO_refcount_inc(&references_); } + + // Only the implementations of `FOO_dup_ref` should call these. + Derived *DupRefInternal() const { + UpRefInternal(); + return const_cast(static_cast(this)); + } + bool DecRefInternal() { if (CRYPTO_refcount_dec_and_test_zero(&references_)) { Derived *d = static_cast(this); diff --git a/third_party/boringssl/src/crypto/obj/obj_dat.h b/third_party/boringssl/src/crypto/obj/obj_dat.h index ced3582..0e7d4c2 100644 --- a/third_party/boringssl/src/crypto/obj/obj_dat.h +++ b/third_party/boringssl/src/crypto/obj/obj_dat.h @@ -16,7 +16,7 @@ BSSL_NAMESPACE_BEGIN -#define NUM_NID 982 +#define NUM_NID 979 static const uint8_t kObjectData[] = { /* NID_rsadsi */ @@ -7146,39 +7146,6 @@ static const uint8_t kObjectData[] = { 0x04, 0x04, 0x02, - /* NID_alg_mtcProof_draft */ - 0x2b, - 0x06, - 0x01, - 0x04, - 0x01, - 0x82, - 0xda, - 0x4b, - 0x2f, - 0x00, - /* NID_rdna_trustAnchorID_draft */ - 0x2b, - 0x06, - 0x01, - 0x04, - 0x01, - 0x82, - 0xda, - 0x4b, - 0x2f, - 0x01, - /* NID_pe_mtcCertificationAuthority_draft */ - 0x2b, - 0x06, - 0x01, - 0x04, - 0x01, - 0x82, - 0xda, - 0x4b, - 0x2f, - 0x02, /* NID_SLH_DSA_SHA2_128s */ 0x60, 0x86, @@ -7209,6 +7176,33 @@ static const uint8_t kObjectData[] = { 0x04, 0x03, 0x23, + /* NID_alg_mtcProof */ + 0x2b, + 0x06, + 0x01, + 0x05, + 0x05, + 0x07, + 0x06, + 0x43, + /* NID_rdna_trustAnchorID */ + 0x2b, + 0x06, + 0x01, + 0x05, + 0x05, + 0x07, + 0x19, + 0x03, + /* NID_pe_mtcCertificationAuthority_SHA256 */ + 0x2b, + 0x06, + 0x01, + 0x05, + 0x05, + 0x07, + 0x01, + 0x26, }; static const ASN1_OBJECT kObjects[NUM_NID] = { @@ -8865,21 +8859,19 @@ static const ASN1_OBJECT kObjects[NUM_NID] = { 0}, {NULL, NULL, NID_undef, 0, NULL, 0}, {"X-Wing", "X-Wing", NID_X_Wing, 0, NULL, 0}, - {NULL, NULL, NID_undef, 0, NULL, 0}, - {NULL, NULL, NID_undef, 0, NULL, 0}, - {NULL, NULL, NID_undef, 0, NULL, 0}, - {"alg-mtcProof-draft", "alg-mtcProof-draft", NID_alg_mtcProof_draft, 10, - &kObjectData[6241], 0}, - {"rdna-trustAnchorID-draft", "rdna-trustAnchorID-draft", - NID_rdna_trustAnchorID_draft, 10, &kObjectData[6251], 0}, - {"pe-mtcCertificationAuthority-draft", "pe-mtcCertificationAuthority-draft", - NID_pe_mtcCertificationAuthority_draft, 10, &kObjectData[6261], 0}, {"id-slh-dsa-sha2-128s", "SLH-DSA-SHA2-128s", NID_SLH_DSA_SHA2_128s, 9, - &kObjectData[6271], 0}, + &kObjectData[6241], 0}, {"id-slh-dsa-shake-256f", "SLH-DSA-SHAKE-256f", NID_SLH_DSA_SHAKE_256f, 9, - &kObjectData[6280], 0}, + &kObjectData[6250], 0}, {"id-hash-slh-dsa-sha2-128s-with-sha256", "SLH-DSA-SHA2-128s-WITH-SHA256", - NID_SLH_DSA_SHA2_128s_WITH_SHA256, 9, &kObjectData[6289], 0}, + NID_SLH_DSA_SHA2_128s_WITH_SHA256, 9, &kObjectData[6259], 0}, + {"alg-mtcProof", "alg-mtcProof", NID_alg_mtcProof, 8, &kObjectData[6268], + 0}, + {"rdna-trustAnchorID", "rdna-trustAnchorID", NID_rdna_trustAnchorID, 8, + &kObjectData[6276], 0}, + {"pe-mtcCertificationAuthority-SHA256", + "pe-mtcCertificationAuthority-SHA256", + NID_pe_mtcCertificationAuthority_SHA256, 8, &kObjectData[6284], 0}, }; static const uint16_t kNIDsInShortNameOrder[] = { @@ -9095,7 +9087,7 @@ static const uint16_t kNIDsInShortNameOrder[] = { 368 /* acceptableResponses */, 446 /* account */, 363 /* ad_timestamping */, - 976 /* alg-mtcProof-draft */, + 976 /* alg-mtcProof */, 376 /* algorithm */, 405 /* ansi-X9-62 */, 910 /* anyExtendedKeyUsage */, @@ -9354,7 +9346,7 @@ static const uint16_t kNIDsInShortNameOrder[] = { 331 /* id-cmc-transactionId */, 787 /* id-ct-asciiTextWithCRLF */, 408 /* id-ecPublicKey */, - 981 /* id-hash-slh-dsa-sha2-128s-with-sha256 */, + 975 /* id-hash-slh-dsa-sha2-128s-with-sha256 */, 508 /* id-hex-multipart-message */, 507 /* id-hex-partial-message */, 260 /* id-it */, @@ -9426,8 +9418,8 @@ static const uint16_t kNIDsInShortNameOrder[] = { 322 /* id-regInfo-certReq */, 321 /* id-regInfo-utf8Pairs */, 512 /* id-set */, - 979 /* id-slh-dsa-sha2-128s */, - 980 /* id-slh-dsa-shake-256f */, + 973 /* id-slh-dsa-sha2-128s */, + 974 /* id-slh-dsa-shake-256f */, 191 /* id-smime-aa */, 215 /* id-smime-aa-contentHint */, 218 /* id-smime-aa-contentIdentifier */, @@ -9560,7 +9552,7 @@ static const uint16_t kNIDsInShortNameOrder[] = { 489 /* pagerTelephoneNumber */, 374 /* path */, 112 /* pbeWithMD5AndCast5CBC */, - 978 /* pe-mtcCertificationAuthority-draft */, + 978 /* pe-mtcCertificationAuthority-SHA256 */, 499 /* personalSignature */, 487 /* personalTitle */, 464 /* photo */, @@ -9614,7 +9606,7 @@ static const uint16_t kNIDsInShortNameOrder[] = { 286 /* qcStatements */, 457 /* qualityLabelledData */, 450 /* rFC822localPart */, - 977 /* rdna-trustAnchorID-draft */, + 977 /* rdna-trustAnchorID */, 870 /* registeredAddress */, 400 /* role */, 877 /* roleOccupant */, @@ -9955,9 +9947,9 @@ static const uint16_t kNIDsInLongNameOrder[] = { 2 /* RSA Data Security, Inc. PKCS */, 188 /* S/MIME */, 167 /* S/MIME Capabilities */, - 979 /* SLH-DSA-SHA2-128s */, - 981 /* SLH-DSA-SHA2-128s-WITH-SHA256 */, - 980 /* SLH-DSA-SHAKE-256f */, + 973 /* SLH-DSA-SHA2-128s */, + 975 /* SLH-DSA-SHA2-128s-WITH-SHA256 */, + 974 /* SLH-DSA-SHAKE-256f */, 387 /* SNMPv2 */, 512 /* Secure Electronic Transactions */, 386 /* Security */, @@ -10041,7 +10033,7 @@ static const uint16_t kNIDsInLongNameOrder[] = { 901 /* aes-256-gcm */, 428 /* aes-256-ofb */, 914 /* aes-256-xts */, - 976 /* alg-mtcProof-draft */, + 976 /* alg-mtcProof */, 376 /* algorithm */, 484 /* associatedDomain */, 485 /* associatedName */, @@ -10520,7 +10512,7 @@ static const uint16_t kNIDsInLongNameOrder[] = { 145 /* pbeWithSHA1And40BitRC4 */, 170 /* pbeWithSHA1AndDES-CBC */, 68 /* pbeWithSHA1AndRC2-CBC */, - 978 /* pe-mtcCertificationAuthority-draft */, + 978 /* pe-mtcCertificationAuthority-SHA256 */, 499 /* personalSignature */, 487 /* personalTitle */, 464 /* photo */, @@ -10580,7 +10572,7 @@ static const uint16_t kNIDsInLongNameOrder[] = { 122 /* rc5-cfb */, 121 /* rc5-ecb */, 123 /* rc5-ofb */, - 977 /* rdna-trustAnchorID-draft */, + 977 /* rdna-trustAnchorID */, 870 /* registeredAddress */, 460 /* rfc822Mailbox */, 117 /* ripemd160 */, @@ -11322,6 +11314,7 @@ static const uint16_t kNIDsInOIDOrder[] = { 397 /* 1.3.6.1.5.5.7.1.10 (OBJ_ac_proxying) */, 398 /* 1.3.6.1.5.5.7.1.11 (OBJ_sinfo_access) */, 663 /* 1.3.6.1.5.5.7.1.14 (OBJ_proxyCertInfo) */, + 978 /* 1.3.6.1.5.5.7.1.38 (OBJ_pe_mtcCertificationAuthority_SHA256) */, 164 /* 1.3.6.1.5.5.7.2.1 (OBJ_id_qt_cps) */, 165 /* 1.3.6.1.5.5.7.2.2 (OBJ_id_qt_unotice) */, 293 /* 1.3.6.1.5.5.7.2.3 (OBJ_textNotice) */, @@ -11357,6 +11350,7 @@ static const uint16_t kNIDsInOIDOrder[] = { 324 /* 1.3.6.1.5.5.7.6.2 (OBJ_id_alg_noSignature) */, 325 /* 1.3.6.1.5.5.7.6.3 (OBJ_id_alg_dh_sig_hmac_sha1) */, 326 /* 1.3.6.1.5.5.7.6.4 (OBJ_id_alg_dh_pop) */, + 976 /* 1.3.6.1.5.5.7.6.67 (OBJ_alg_mtcProof) */, 327 /* 1.3.6.1.5.5.7.7.1 (OBJ_id_cmc_statusInfo) */, 328 /* 1.3.6.1.5.5.7.7.2 (OBJ_id_cmc_identification) */, 329 /* 1.3.6.1.5.5.7.7.3 (OBJ_id_cmc_identityProof) */, @@ -11397,6 +11391,7 @@ static const uint16_t kNIDsInOIDOrder[] = { 664 /* 1.3.6.1.5.5.7.21.0 (OBJ_id_ppl_anyLanguage) */, 665 /* 1.3.6.1.5.5.7.21.1 (OBJ_id_ppl_inheritAll) */, 667 /* 1.3.6.1.5.5.7.21.2 (OBJ_Independent) */, + 977 /* 1.3.6.1.5.5.7.25.3 (OBJ_rdna_trustAnchorID) */, 178 /* 1.3.6.1.5.5.7.48.1 (OBJ_ad_OCSP) */, 179 /* 1.3.6.1.5.5.7.48.2 (OBJ_ad_ca_issuers) */, 363 /* 1.3.6.1.5.5.7.48.3 (OBJ_ad_timeStamping) */, @@ -11535,9 +11530,9 @@ static const uint16_t kNIDsInOIDOrder[] = { 967 /* 2.16.840.1.101.3.4.3.17 (OBJ_ML_DSA_44) */, 968 /* 2.16.840.1.101.3.4.3.18 (OBJ_ML_DSA_65) */, 969 /* 2.16.840.1.101.3.4.3.19 (OBJ_ML_DSA_87) */, - 979 /* 2.16.840.1.101.3.4.3.20 (OBJ_SLH_DSA_SHA2_128s) */, - 980 /* 2.16.840.1.101.3.4.3.31 (OBJ_SLH_DSA_SHAKE_256f) */, - 981 /* 2.16.840.1.101.3.4.3.35 (OBJ_SLH_DSA_SHA2_128s_WITH_SHA256) */, + 973 /* 2.16.840.1.101.3.4.3.20 (OBJ_SLH_DSA_SHA2_128s) */, + 974 /* 2.16.840.1.101.3.4.3.31 (OBJ_SLH_DSA_SHAKE_256f) */, + 975 /* 2.16.840.1.101.3.4.3.35 (OBJ_SLH_DSA_SHA2_128s_WITH_SHA256) */, 970 /* 2.16.840.1.101.3.4.4.2 (OBJ_ML_KEM_768) */, 966 /* 2.16.840.1.101.3.4.4.3 (OBJ_ML_KEM_1024) */, 71 /* 2.16.840.1.113730.1.1 (OBJ_netscape_cert_type) */, @@ -11637,9 +11632,6 @@ static const uint16_t kNIDsInOIDOrder[] = { 138 /* 1.3.6.1.4.1.311.10.3.4 (OBJ_ms_efs) */, 648 /* 1.3.6.1.4.1.311.20.2.2 (OBJ_ms_smartcard_login) */, 649 /* 1.3.6.1.4.1.311.20.2.3 (OBJ_ms_upn) */, - 976 /* 1.3.6.1.4.1.44363.47.0 (OBJ_alg_mtcProof_draft) */, - 977 /* 1.3.6.1.4.1.44363.47.1 (OBJ_rdna_trustAnchorID_draft) */, - 978 /* 1.3.6.1.4.1.44363.47.2 (OBJ_pe_mtcCertificationAuthority_draft) */, 751 /* 1.2.392.200011.61.1.1.1.2 (OBJ_camellia_128_cbc) */, 752 /* 1.2.392.200011.61.1.1.1.3 (OBJ_camellia_192_cbc) */, 753 /* 1.2.392.200011.61.1.1.1.4 (OBJ_camellia_256_cbc) */, diff --git a/third_party/boringssl/src/crypto/pkcs7/internal.h b/third_party/boringssl/src/crypto/pkcs7/internal.h index a6ab04e..66f8955 100644 --- a/third_party/boringssl/src/crypto/pkcs7/internal.h +++ b/third_party/boringssl/src/crypto/pkcs7/internal.h @@ -59,7 +59,7 @@ int pkcs7_add_signed_data(CBB *out, uint64_t signed_data_version, // // Note: CMS v1 and PKCS#7 v1.5 are not completely compatible, but they overlap // in all cases implemented by this function. -int pkcs7_add_external_signature(CBB *out, X509 *sign_cert, EVP_PKEY *key, +int pkcs7_add_external_signature(CBB *out, X509 *sign_cert, const EVP_PKEY *key, const EVP_MD *md, BIO *data, bool use_key_id); BSSL_NAMESPACE_END diff --git a/third_party/boringssl/src/crypto/pkcs7/pkcs7_x509.cc b/third_party/boringssl/src/crypto/pkcs7/pkcs7_x509.cc index cb9a725..c179e3a 100644 --- a/third_party/boringssl/src/crypto/pkcs7/pkcs7_x509.cc +++ b/third_party/boringssl/src/crypto/pkcs7/pkcs7_x509.cc @@ -472,9 +472,9 @@ static int write_signer_info(CBB *out, void *arg) { return 1; } -int bssl::pkcs7_add_external_signature(CBB *out, X509 *sign_cert, EVP_PKEY *key, - const EVP_MD *md, BIO *data, - bool use_key_id) { +int bssl::pkcs7_add_external_signature(CBB *out, X509 *sign_cert, + const EVP_PKEY *key, const EVP_MD *md, + BIO *data, bool use_key_id) { signer_info_data si_data; si_data.use_key_id = use_key_id; si_data.sign_cert = sign_cert; @@ -494,7 +494,7 @@ int bssl::pkcs7_add_external_signature(CBB *out, X509 *sign_cert, EVP_PKEY *key, /*cert_crl_cb=*/nullptr, write_signer_info, &si_data); } -PKCS7 *PKCS7_sign(X509 *sign_cert, EVP_PKEY *pkey, STACK_OF(X509) *certs, +PKCS7 *PKCS7_sign(X509 *sign_cert, const EVP_PKEY *pkey, STACK_OF(X509) *certs, BIO *data, int flags) { ScopedCBB cbb; if (!CBB_init(cbb.get(), 2048)) { diff --git a/third_party/boringssl/src/crypto/pool/pool.cc b/third_party/boringssl/src/crypto/pool/pool.cc index 8b1f5bc..21e2203 100644 --- a/third_party/boringssl/src/crypto/pool/pool.cc +++ b/third_party/boringssl/src/crypto/pool/pool.cc @@ -95,6 +95,13 @@ int CRYPTO_BUFFER_POOL_up_ref(CRYPTO_BUFFER_POOL *pool) { return 1; } +CRYPTO_BUFFER_POOL *CRYPTO_BUFFER_POOL_dup_ref(const CRYPTO_BUFFER_POOL *pool) { + if (pool == nullptr) { + return nullptr; + } + return FromOpaque(pool)->DupRefInternal(); +} + void CryptoBuffer::UpRefInternal() const { // This is safe in the case that `buf->pool` is NULL because it's just // standard reference counting in that case. @@ -264,6 +271,9 @@ int CRYPTO_BUFFER_up_ref(CRYPTO_BUFFER *buf) { } CRYPTO_BUFFER *CRYPTO_BUFFER_dup_ref(const CRYPTO_BUFFER *buf) { + if (buf == nullptr) { + return nullptr; + } auto *buf_ = const_cast(buf); FromOpaque(buf_)->UpRefInternal(); return buf_; diff --git a/third_party/boringssl/src/crypto/trust_token/trust_token.cc b/third_party/boringssl/src/crypto/trust_token/trust_token.cc index d0e5c24..b295a6b 100644 --- a/third_party/boringssl/src/crypto/trust_token/trust_token.cc +++ b/third_party/boringssl/src/crypto/trust_token/trust_token.cc @@ -279,13 +279,13 @@ int TRUST_TOKEN_CLIENT_add_key(TRUST_TOKEN_CLIENT *ctx, size_t *out_key_index, return 1; } -int TRUST_TOKEN_CLIENT_set_srr_key(TRUST_TOKEN_CLIENT *ctx, EVP_PKEY *key) { +int TRUST_TOKEN_CLIENT_set_srr_key(TRUST_TOKEN_CLIENT *ctx, + const EVP_PKEY *key) { if (!ctx->method->has_srr) { return 1; } EVP_PKEY_free(ctx->srr_key); - EVP_PKEY_up_ref(key); - ctx->srr_key = key; + ctx->srr_key = EVP_PKEY_dup_ref(key); return 1; } @@ -515,10 +515,10 @@ int TRUST_TOKEN_ISSUER_add_key(TRUST_TOKEN_ISSUER *ctx, const uint8_t *key, return 1; } -int TRUST_TOKEN_ISSUER_set_srr_key(TRUST_TOKEN_ISSUER *ctx, EVP_PKEY *key) { +int TRUST_TOKEN_ISSUER_set_srr_key(TRUST_TOKEN_ISSUER *ctx, + const EVP_PKEY *key) { EVP_PKEY_free(ctx->srr_key); - EVP_PKEY_up_ref(key); - ctx->srr_key = key; + ctx->srr_key = EVP_PKEY_dup_ref(key); return 1; } diff --git a/third_party/boringssl/src/crypto/x509/a_sign.cc b/third_party/boringssl/src/crypto/x509/a_sign.cc index 3e313d4..f09e80a 100644 --- a/third_party/boringssl/src/crypto/x509/a_sign.cc +++ b/third_party/boringssl/src/crypto/x509/a_sign.cc @@ -31,7 +31,7 @@ using namespace bssl; int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, - ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, + ASN1_BIT_STRING *signature, void *asn, const EVP_PKEY *pkey, const EVP_MD *type) { if (signature->type != V_ASN1_BIT_STRING) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TYPE); diff --git a/third_party/boringssl/src/crypto/x509/internal.h b/third_party/boringssl/src/crypto/x509/internal.h index f5a76da..238a2e8 100644 --- a/third_party/boringssl/src/crypto/x509/internal.h +++ b/third_party/boringssl/src/crypto/x509/internal.h @@ -61,7 +61,7 @@ class X509Pubkey : public X509_pubkey_st { int x509_parse_public_key(CBS *cbs, X509_PUBKEY *out, Span algs); int x509_marshal_public_key(CBB *cbb, const X509_PUBKEY *in); -int x509_pubkey_set1(X509_PUBKEY *key, EVP_PKEY *pkey); +int x509_pubkey_set1(X509_PUBKEY *key, const EVP_PKEY *pkey); // X509_PUBKEY is an `ASN1_ITEM` whose ASN.1 type is SubjectPublicKeyInfo and C // type is `X509_PUBKEY*`. @@ -170,18 +170,18 @@ class X509Impl : public x509_st, public RefCounted { UniquePtr buf; CRYPTO_EX_DATA ex_data; // These contain copies of various extension values - long ex_pathlen = -1; - uint32_t ex_flags = 0; - uint32_t ex_kusage = 0; - uint32_t ex_xkusage = 0; - UniquePtr skid; - UniquePtr akid; - UniquePtr crldp; - UniquePtr altname; - UniquePtr nc; - unsigned char cert_hash[SHA256_DIGEST_LENGTH] = {}; + mutable long ex_pathlen = -1; + mutable uint32_t ex_flags = 0; + mutable uint32_t ex_kusage = 0; + mutable uint32_t ex_xkusage = 0; + mutable UniquePtr skid; + mutable UniquePtr akid; + mutable UniquePtr crldp; + mutable UniquePtr altname; + mutable UniquePtr nc; + mutable unsigned char cert_hash[SHA256_DIGEST_LENGTH] = {}; bssl::X509_CERT_AUX *aux = nullptr; - Mutex lock; + mutable Mutex lock; private: friend RefCounted; @@ -263,22 +263,6 @@ DECLARE_ASN1_FUNCTIONS_const(X509_CRL_INFO) BSSL_NAMESPACE_END -// Values in idp_flags field -// IDP present -#define IDP_PRESENT 0x1 -// IDP values inconsistent -#define IDP_INVALID 0x2 -// onlyuser true -#define IDP_ONLYUSER 0x4 -// onlyCA true -#define IDP_ONLYCA 0x8 -// onlyattr true -#define IDP_ONLYATTR 0x10 -// indirectCRL true -#define IDP_INDIRECT 0x20 -// onlysomereasons present -#define IDP_REASONS 0x40 - struct X509_crl_st { // actual signature bssl::X509_CRL_INFO *crl; @@ -289,8 +273,6 @@ struct X509_crl_st { // Copies of various extensions AUTHORITY_KEYID *akid; ISSUING_DIST_POINT *idp; - // Convenient breakdown of IDP - int idp_flags; unsigned char crl_hash[SHA256_DIGEST_LENGTH]; } /* X509_CRL */; @@ -424,10 +406,6 @@ struct x509_store_ctx_st { int error_depth; int error; X509 *current_cert; - X509_CRL *current_crl; // current CRL - - X509 *current_crl_issuer; // issuer of current CRL - int current_crl_score; // score of current CRL CRYPTO_EX_DATA ex_data; } /* X509_STORE_CTX */; @@ -499,12 +477,11 @@ int x509_sign_to_bit_string(EVP_MD_CTX *ctx, ASN1_BIT_STRING *out, // the user-initial-policy-set. If `user_policies` is NULL or empty, it is // interpreted as anyPolicy. `flags` is a set of `X509_V_FLAG_*` values to // apply. It returns `X509_V_OK` on success and `X509_V_ERR_*` on error. It -// additionally sets `*out_current_cert` to the certificate where the error -// occurred. If the function succeeded, or the error applies to the entire -// chain, it sets `*out_current_cert` to NULL. +// additionally sets `*out_error_depth` to the index of certificate where the +// error occurred. int X509_policy_check(const STACK_OF(X509) *certs, const STACK_OF(ASN1_OBJECT) *user_policies, - unsigned long flags, X509 **out_current_cert); + unsigned long flags, int *out_error_depth); // x509_check_issued_with_callback calls `X509_check_issued`, but allows the // verify callback to override the result. It returns one on success and zero on @@ -545,7 +522,7 @@ OPENSSL_EXPORT int x509v3_looks_like_dns_name(const unsigned char *in, // x509v3_cache_extensions fills in a number of fields relating to X.509 // extensions in `x`. It returns one on success and zero if some extensions were // invalid. -OPENSSL_EXPORT int x509v3_cache_extensions(X509 *x); +OPENSSL_EXPORT int x509v3_cache_extensions(const X509 *x); // x509v3_a2i_ipadd decodes `ipasc` as an IPv4 or IPv6 address. IPv6 addresses // use colon-separated syntax while IPv4 addresses use dotted decimal syntax. If @@ -625,10 +602,7 @@ STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line); // GENERAL_NAME_cmp returns zero if `a` and `b` are equal and a non-zero // value otherwise. Note this function does not provide a comparison suitable // for sorting. -// -// This function is exported for testing. -OPENSSL_EXPORT int GENERAL_NAME_cmp(const GENERAL_NAME *a, - const GENERAL_NAME *b); +int GENERAL_NAME_cmp(const GENERAL_NAME *a, const GENERAL_NAME *b); // X509_VERIFY_PARAM_lookup returns a pre-defined `X509_VERIFY_PARAM` named by // `name`, or NULL if no such name is defined. @@ -650,9 +624,6 @@ int X509_is_valid_trust_id(int trust); int X509_PURPOSE_get_trust(const X509_PURPOSE *xp); -// TODO(https://crbug.com/boringssl/695): Remove this. -int DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, X509_NAME *iname); - // x509_parse_name parses a DER-encoded, X.509 Name from `cbs` and writes the // result to `*out`. It returns one on success and zero on error. int x509_parse_name(CBS *cbs, X509_NAME *out); @@ -670,7 +641,7 @@ int x509_name_copy(X509_NAME *dst, const X509_NAME *src); // Merkle Tree Certificate (MTC) verification functions. // x509_is_merkle_tree_ca returns whether `x509` contains an extension of type -// id-pe-mtcCertificationAuthority. +// id-pe-mtcCertificationAuthority-SHA256. bool x509_is_merkle_tree_ca(const X509 *x509); // x509_evaluate_mtc_subtree_inclusion_proof carries out the procedure in diff --git a/third_party/boringssl/src/crypto/x509/policy.cc b/third_party/boringssl/src/crypto/x509/policy.cc index b2c5fba..194b0b5 100644 --- a/third_party/boringssl/src/crypto/x509/policy.cc +++ b/third_party/boringssl/src/crypto/x509/policy.cc @@ -571,8 +571,8 @@ int asn1_object_cmp(const ASN1_OBJECT *const *a, const ASN1_OBJECT *const *b) { int X509_policy_check(const STACK_OF(X509) *certs, const STACK_OF(ASN1_OBJECT) *user_policies, - unsigned long flags, X509 **out_current_cert) { - *out_current_cert = nullptr; + unsigned long flags, int *out_error_depth) { + *out_error_depth = 0; // Skip policy checking if the chain is just the trust anchor. const size_t num_certs = sk_X509_num(certs); @@ -593,6 +593,7 @@ int X509_policy_check(const STACK_OF(X509) *certs, X509 *cert = sk_X509_value(certs, i); uint32_t ex_flags = X509_get_extension_flags(cert); if (ex_flags & EXFLAG_INVALID) { + *out_error_depth = static_cast(i); return X509_V_ERR_OUT_OF_MEM; } const bool is_self_issued = (ex_flags & EXFLAG_SI) != 0; @@ -610,17 +611,19 @@ int X509_policy_check(const STACK_OF(X509) *certs, const int any_policy_allowed = inhibit_any_policy > 0 || (i > 0 && is_self_issued); if (!process_certificate_policies(cert, &*level, any_policy_allowed)) { - *out_current_cert = cert; + *out_error_depth = static_cast(i); return X509_V_ERR_INVALID_POLICY_EXTENSION; } // RFC 5280, section 6.1.3, step (f). if (explicit_policy == 0 && level->is_empty()) { + *out_error_depth = static_cast(i); return X509_V_ERR_NO_EXPLICIT_POLICY; } // Insert the completed level into the list. if (!levels.Push(*std::exchange(level, std::nullopt))) { + *out_error_depth = static_cast(i); return X509_V_ERR_OUT_OF_MEM; } level = std::nullopt; @@ -631,7 +634,7 @@ int X509_policy_check(const STACK_OF(X509) *certs, // RFC 5280, section 6.1.4, steps (a) and (b). level = process_policy_mappings(cert, &levels.back(), policy_mapping > 0); if (!level.has_value()) { - *out_current_cert = cert; + *out_error_depth = static_cast(i); return X509_V_ERR_INVALID_POLICY_EXTENSION; } } @@ -653,7 +656,7 @@ int X509_policy_check(const STACK_OF(X509) *certs, } if (!process_policy_constraints(cert, &explicit_policy, &policy_mapping, &inhibit_any_policy)) { - *out_current_cert = cert; + *out_error_depth = static_cast(i); return X509_V_ERR_INVALID_POLICY_EXTENSION; } } diff --git a/third_party/boringssl/src/crypto/x509/v3_crld.cc b/third_party/boringssl/src/crypto/x509/v3_crld.cc index 48d1538..6db3c62 100644 --- a/third_party/boringssl/src/crypto/x509/v3_crld.cc +++ b/third_party/boringssl/src/crypto/x509/v3_crld.cc @@ -286,27 +286,10 @@ static void *v2i_crld(const X509V3_EXT_METHOD *method, const X509V3_CTX *ctx, return crld.release(); } -static int dpn_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, - void *exarg) { - DIST_POINT_NAME *dpn = asn1_load_ptr_as(pval); - - switch (operation) { - case ASN1_OP_NEW_POST: - dpn->dpname = nullptr; - break; - - case ASN1_OP_FREE_POST: - X509_NAME_free(dpn->dpname); - break; - } - return 1; -} - - -ASN1_CHOICE_cb(DIST_POINT_NAME, dpn_cb) = { +ASN1_CHOICE(DIST_POINT_NAME) = { ASN1_IMP_SEQUENCE_OF(DIST_POINT_NAME, name.fullname, GENERAL_NAME, 0), ASN1_IMP_SET_OF(DIST_POINT_NAME, name.relativename, X509_NAME_ENTRY, 1), -} ASN1_CHOICE_END_cb(DIST_POINT_NAME, DIST_POINT_NAME, type) +} ASN1_CHOICE_END(DIST_POINT_NAME) IMPLEMENT_ASN1_ALLOC_FUNCTIONS(DIST_POINT_NAME) @@ -486,32 +469,3 @@ static int i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out, } return 1; } - -int bssl::DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, X509_NAME *iname) { - size_t i; - STACK_OF(X509_NAME_ENTRY) *frag; - X509_NAME_ENTRY *ne; - if (!dpn || (dpn->type != 1)) { - return 1; - } - frag = dpn->name.relativename; - dpn->dpname = X509_NAME_dup(iname); - if (!dpn->dpname) { - return 0; - } - for (i = 0; i < sk_X509_NAME_ENTRY_num(frag); i++) { - ne = sk_X509_NAME_ENTRY_value(frag, i); - if (!X509_NAME_add_entry(dpn->dpname, ne, -1, i ? 0 : 1)) { - X509_NAME_free(dpn->dpname); - dpn->dpname = nullptr; - return 0; - } - } - // generate cached encoding of name - if (i2d_X509_NAME(dpn->dpname, nullptr) < 0) { - X509_NAME_free(dpn->dpname); - dpn->dpname = nullptr; - return 0; - } - return 1; -} diff --git a/third_party/boringssl/src/crypto/x509/v3_purp.cc b/third_party/boringssl/src/crypto/x509/v3_purp.cc index d832c5b..2dba0d0 100644 --- a/third_party/boringssl/src/crypto/x509/v3_purp.cc +++ b/third_party/boringssl/src/crypto/x509/v3_purp.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -142,30 +143,11 @@ int X509_supported_extension(const X509_EXTENSION *ex) { nid == NID_policy_constraints || // nid == NID_name_constraints || // nid == NID_policy_mappings || // - nid == NID_inhibit_any_policy || - nid == NID_pe_mtcCertificationAuthority_draft; + nid == NID_inhibit_any_policy || // + nid == NID_pe_mtcCertificationAuthority_SHA256; } -static int setup_dp(X509 *x, DIST_POINT *dp) { - if (!dp->distpoint || (dp->distpoint->type != 1)) { - return 1; - } - X509_NAME *iname = nullptr; - for (size_t i = 0; i < sk_GENERAL_NAME_num(dp->CRLissuer); i++) { - GENERAL_NAME *gen = sk_GENERAL_NAME_value(dp->CRLissuer, i); - if (gen->type == GEN_DIRNAME) { - iname = gen->d.directoryName; - break; - } - } - if (!iname) { - iname = X509_get_issuer_name(x); - } - - return DIST_POINT_set_dpname(dp->distpoint, iname); -} - -static int setup_crldp(X509 *x) { +static int setup_crldp(const X509 *x) { int j; auto *impl = FromOpaque(x); impl->crldp.reset(reinterpret_cast( @@ -173,15 +155,10 @@ static int setup_crldp(X509 *x) { if (impl->crldp == nullptr && j != -1) { return 0; } - for (size_t i = 0; i < sk_DIST_POINT_num(impl->crldp.get()); i++) { - if (!setup_dp(x, sk_DIST_POINT_value(impl->crldp.get(), i))) { - return 0; - } - } return 1; } -int bssl::x509v3_cache_extensions(X509 *x) { +int bssl::x509v3_cache_extensions(const X509 *x) { BASIC_CONSTRAINTS *bs; ASN1_BIT_STRING *usage; EXTENDED_KEY_USAGE *extusage; @@ -365,7 +342,7 @@ static int check_ca(const X509 *x) { } int X509_check_ca(const X509 *x) { - if (!x509v3_cache_extensions(const_cast(x))) { + if (!x509v3_cache_extensions(x)) { return 0; } return check_ca(x); @@ -474,8 +451,8 @@ int X509_check_issued(const X509 *issuer, const X509 *subject) { X509_get_issuer_name(subject))) { return X509_V_ERR_SUBJECT_ISSUER_MISMATCH; } - if (!x509v3_cache_extensions(const_cast(issuer)) || - !x509v3_cache_extensions(const_cast(subject))) { + if (!x509v3_cache_extensions(issuer) || + !x509v3_cache_extensions(subject)) { return X509_V_ERR_UNSPECIFIED; } diff --git a/third_party/boringssl/src/crypto/x509/x509_cmp.cc b/third_party/boringssl/src/crypto/x509/x509_cmp.cc index 4dea236..5c78399 100644 --- a/third_party/boringssl/src/crypto/x509/x509_cmp.cc +++ b/third_party/boringssl/src/crypto/x509/x509_cmp.cc @@ -107,8 +107,8 @@ int X509_cmp(const X509 *a, const X509 *b) { // comparison and may cause misbehaving sorts by transitivity. For now, we // retain the old OpenSSL behavior, which was to ignore the error. See // https://crbug.com/boringssl/355. - x509v3_cache_extensions((X509Impl *)a_impl); - x509v3_cache_extensions((X509Impl *)b_impl); + x509v3_cache_extensions(a_impl); + x509v3_cache_extensions(b_impl); return OPENSSL_memcmp(a_impl->cert_hash, b_impl->cert_hash, SHA256_DIGEST_LENGTH); diff --git a/third_party/boringssl/src/crypto/x509/x509_lu.cc b/third_party/boringssl/src/crypto/x509/x509_lu.cc index 126bf33..5b60327 100644 --- a/third_party/boringssl/src/crypto/x509/x509_lu.cc +++ b/third_party/boringssl/src/crypto/x509/x509_lu.cc @@ -149,6 +149,13 @@ int X509_STORE_up_ref(X509_STORE *store) { return 1; } +X509_STORE *X509_STORE_dup_ref(const X509_STORE *store) { + if (store == nullptr) { + return nullptr; + } + return FromOpaque(store)->DupRefInternal(); +} + void X509_STORE_free(X509_STORE *vfy) { if (vfy == nullptr) { return; @@ -204,7 +211,7 @@ int X509_STORE_CTX_get_by_subject(X509_STORE_CTX *vs, int type, return 1; } -static int x509_store_add(X509Store *ctx, void *x, int is_crl) { +static int x509_store_add(X509Store *ctx, const void *x, int is_crl) { if (x == nullptr) { return 0; } @@ -216,12 +223,11 @@ static int x509_store_add(X509Store *ctx, void *x, int is_crl) { if (is_crl) { obj->type = X509_LU_CRL; - obj->data.crl = (X509_CRL *)x; + obj->data.crl = X509_CRL_dup_ref(static_cast(x)); } else { obj->type = X509_LU_X509; - obj->data.x509 = (X509 *)x; + obj->data.x509 = X509_dup_ref(static_cast(x)); } - X509_OBJECT_up_ref_count(obj); ctx->objs_lock.LockWrite(); @@ -241,11 +247,11 @@ static int x509_store_add(X509Store *ctx, void *x, int is_crl) { return ret; } -int X509_STORE_add_cert(X509_STORE *ctx, X509 *x) { +int X509_STORE_add_cert(X509_STORE *ctx, const X509 *x) { return x509_store_add(FromOpaque(ctx), x, /*is_crl=*/0); } -int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x) { +int X509_STORE_add_crl(X509_STORE *ctx, const X509_CRL *x) { return x509_store_add(FromOpaque(ctx), x, /*is_crl=*/1); } diff --git a/third_party/boringssl/src/crypto/x509/x509_mtc.cc b/third_party/boringssl/src/crypto/x509/x509_mtc.cc index 989dd42..1b4a8ae 100644 --- a/third_party/boringssl/src/crypto/x509/x509_mtc.cc +++ b/third_party/boringssl/src/crypto/x509/x509_mtc.cc @@ -38,17 +38,16 @@ namespace { // Prefix for domain separation to denote a Merkle Tree leaf or interior node. constexpr uint8_t kMTCLeafDomainSeparator[] = {0x00}; constexpr uint8_t kMTCNodeDomainSeparator[] = {0x01}; -// DER encoding of AlgorithmIdentifier for alg-mtcProof-draft with absent -// parameters. -// SEQUENCE (12 bytes) { -// OBJECT IDENTIFIER 1.3.6.1.4.1.44363.47.0 (10 bytes) +// DER encoding of AlgorithmIdentifier for alg-mtcProof with absent parameters. +// SEQUENCE (10 bytes) { +// OBJECT IDENTIFIER 1.3.6.1.5.5.7.6.67 (8 bytes) // } constexpr uint8_t kMTCAlgorithmIdentifier[] = { 0x30, // SEQUENCE tag - 12, // tag + len + OID bytes + 10, // tag + len + OID bytes 0x06, // OBJECT tag - 10, // OID length - OBJ_ENC_alg_mtcProof_draft, + 8, // OID length + OBJ_ENC_alg_mtcProof, }; // MTCLogEntryType enum value for tbs_cert_entry. constexpr uint8_t kMTCLogEntryTypeTBSCertEntry[] = {0x00, 0x01}; @@ -64,6 +63,8 @@ constexpr uint8_t kASCIIOIDPrefix[16] = {'o', 'i', 'd', '/', '1', '.', '4', '.', '1', '.'}; // DER encoded OID component found in trust anchor IDs for issuance logs. constexpr uint8_t kEncOIDLogs = 0x00; +// draft-ietf-tls-trust-anchor-ids-06 limits trust anchor IDs to 32 bytes. +constexpr size_t kMaxTrustAnchorIdBytes = 32; constexpr CBS_ASN1_TAG kTBSVersionTag = CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 0; @@ -88,10 +89,18 @@ inline bool lsb(uint64_t n) { return n & 1; } // is_mtc_proof returns whether `algor` is an mtcProof AlgorithmIdentifier. bool is_mtc_proof(const X509_ALGOR *algor) { - return OBJ_obj2nid(algor->algorithm) == NID_alg_mtcProof_draft && + return OBJ_obj2nid(algor->algorithm) == NID_alg_mtcProof && algor->parameter == nullptr; } +// is_mtc_serial_valid returns whether `serial` is within +// (mtcMinSerial..mtcMaxSerial), which implies the log number is > 0. +bool is_mtc_serial_valid(uint64_t serial) { + // mtcMinSerial is 2^48. mtcMaxSerial is 2^64-1, the largest number + // representable as uint64_t, so is not checked explicitly. + return serial >> 48; +} + // Returns the first hash value (of size `log_hash_size`) remaining in // `inclusion_proof` and advances `inclusion_proof` past the returned value. // Returns an empty span if there are no more hash values of the appropriate @@ -137,6 +146,7 @@ bool DigestUpdateNextASN1Element(EVP_MD_CTX *ctx, CBS *cbs) { // MTCCACosigner represents a Merkle Tree CA and its corresponding CA cosigner // (see draft-ietf-plants-merkle-tree-certs, section 5.5). +// Only id-pe-mtcCertificationAuthority-SHA256 is supported. class MTCCACosigner { public: MTCCACosigner() = default; @@ -150,62 +160,59 @@ class MTCCACosigner { bool Init(const X509 *x509, const EVP_PKEY *pkey) { // Get and parse the MTCCertificationAuthority extension (see section 5.5). int ext_index = - X509_get_ext_by_NID(x509, NID_pe_mtcCertificationAuthority_draft, -1); + X509_get_ext_by_NID(x509, NID_pe_mtcCertificationAuthority_SHA256, -1); const X509_EXTENSION *ext = X509_get_ext(x509, ext_index); if (ext == nullptr || !X509_EXTENSION_get_critical(ext)) { OPENSSL_PUT_ERROR(X509, X509_R_INVALID_MTC_CA); return false; } const ASN1_STRING *value = X509_EXTENSION_get_data(ext); - CBS ext_value; + CBS ext_value, seq; CBS_init(&ext_value, ASN1_STRING_get0_data(value), ASN1_STRING_length(value)); - - CBS seq, log_hash; - if (!CBS_get_asn1(&ext_value, &seq, CBS_ASN1_SEQUENCE) || // - !CBS_get_asn1_element(&seq, &log_hash, CBS_ASN1_SEQUENCE) || // - !x509_parse_algorithm(&seq, cosign_sigalg_.get()) || // - !CBS_get_asn1_uint64(&seq, &min_serial_) || // - !CBS_get_asn1_uint64(&seq, &max_serial_) || // + if (!CBS_get_asn1(&ext_value, &seq, CBS_ASN1_SEQUENCE) || // + CBS_len(&ext_value) != 0 || // + !x509_parse_algorithm(&seq, cosign_sigalg_.get()) || // + !CBS_get_asn1_uint64(&seq, &min_serial_) || // + !CBS_get_asn1_uint64(&seq, &max_serial_) || // CBS_len(&seq) != 0) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR); return false; } - log_hash_ = EVP_parse_digest_algorithm(&log_hash); - if (log_hash_ == nullptr) { - return false; - } - if (CBS_len(&log_hash) != 0) { - OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR); + if (!is_mtc_serial_valid(min_serial_) || + !is_mtc_serial_valid(max_serial_)) { + OPENSSL_PUT_ERROR(X509, X509_R_INVALID_MTC_CA); return false; } - // Extract the CA ID from the subject (see section 5.1). const X509_NAME *subject = X509_get_subject_name(x509); int tai_index = - X509_NAME_get_index_by_NID(subject, NID_rdna_trustAnchorID_draft, -1); + X509_NAME_get_index_by_NID(subject, NID_rdna_trustAnchorID, -1); if (tai_index < 0 || X509_NAME_entry_count(subject) != 1) { OPENSSL_PUT_ERROR(X509, X509_R_INVALID_MTC_CA); return false; } - // For initial experimentation, the attribute's value is a UTF8String - // containing the trust anchor ID's ASCII representation. - const ASN1_STRING *tai_ascii = + const ASN1_STRING *tai = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(subject, tai_index)); - if (ASN1_STRING_type(tai_ascii) != V_ASN1_UTF8STRING) { + // RELATIVE-OID has no dedicated ASN1_STRING representation, so the value + // is stored as V_ASN1_OTHER containing the entire element. + if (ASN1_STRING_type(tai) != V_ASN1_OTHER) { OPENSSL_PUT_ERROR(X509, X509_R_WRONG_TYPE); return false; } - std::string_view tai_ascii_str = BytesAsStringView( - Span(ASN1_STRING_get0_data(tai_ascii), ASN1_STRING_length(tai_ascii))); - ScopedCBB ca_id_enc; - if (!CBB_init(ca_id_enc.get(), 64) || - !CBB_add_asn1_relative_oid_from_text( - ca_id_enc.get(), tai_ascii_str.data(), tai_ascii_str.size())) { + CBS tai_elem, tai_relative_oid; + CBS_init(&tai_elem, ASN1_STRING_get0_data(tai), ASN1_STRING_length(tai)); + if (!CBS_get_asn1(&tai_elem, &tai_relative_oid, CBS_ASN1_RELATIVE_OID) || + CBS_len(&tai_elem) != 0 || + !CBS_is_valid_asn1_relative_oid(&tai_relative_oid)) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_OBJECT_ENCODING); return false; } - if (!CBBFinishArray(ca_id_enc.get(), &ca_id_enc_oid_)) { + if (CBS_len(&tai_relative_oid) > kMaxTrustAnchorIdBytes) { + OPENSSL_PUT_ERROR(X509, X509_R_INVALID_MTC_CA); + return false; + } + if (!ca_id_enc_oid_.CopyFrom(tai_relative_oid)) { OPENSSL_PUT_ERROR(X509, ERR_R_INTERNAL_ERROR); return false; } @@ -215,7 +222,9 @@ class MTCCACosigner { } bool IsSerialInRange(uint64_t serial) const { - return min_serial_ <= serial && serial <= max_serial_; + bool ok = min_serial_ <= serial && serial <= max_serial_; + assert(!ok || is_mtc_serial_valid(serial)); + return ok; } // Constructs CosignedMessage and computes signature. @@ -248,7 +257,7 @@ class MTCCACosigner { return trust_anchor_id == ca_id_enc_oid_; } - const EVP_MD *log_hash() const { return log_hash_; } + const EVP_MD *log_hash() const { return EVP_sha256(); } private: // WriteTaiAscii concatenates the trust anchor ID prefix with the CA ID as a @@ -256,9 +265,9 @@ class MTCCACosigner { // OID components from `oid_suffix`, and writes the ASCII string // representation of the full trust anchor ID to `out`. bool WriteTaiAscii(CBB *out, Span oid_suffix = {}) const { - // Trust anchor IDs are constrained to 256 bytes by spec (and are typically - // much shorter). - uint8_t id[256]; + // Trust anchor IDs such as the CA ID are limited to 32 bytes by spec, but + // `oid_suffix` may add additional bytes. + uint8_t id[2 * kMaxTrustAnchorIdBytes]; CBB id_cbb; if (!CBB_init_fixed(&id_cbb, id, sizeof(id)) || !CBB_add_bytes(&id_cbb, ca_id_enc_oid_.data(), ca_id_enc_oid_.size())) { @@ -301,21 +310,20 @@ class MTCCACosigner { // 5.1 and 5.4), in the form of a DER-encoded relative OID. This does not // include any framing, only the element's contents. Array ca_id_enc_oid_; - // Log hash algorithm. - const EVP_MD *log_hash_ = nullptr; // Public key of the CA cosigner. UniquePtr cosign_pubkey_; // Signature algorithm for CA cosigner signatures. ScopedX509Algor cosign_sigalg_; - // Min and max allowed serial number, (0..2^64-1). + // Min and max allowed serial number, both (2^48 .. 2^64-1). uint64_t min_serial_ = 0u; uint64_t max_serial_ = 0u; }; } // namespace +// Only id-pe-mtcCertificationAuthority-SHA256 is supported. bool x509_is_merkle_tree_ca(const X509 *x509) { - return X509_get_ext_by_NID(x509, NID_pe_mtcCertificationAuthority_draft, + return X509_get_ext_by_NID(x509, NID_pe_mtcCertificationAuthority_SHA256, -1) >= 0; } @@ -420,7 +428,7 @@ int x509_verify_mtc(const X509 *x509, const EVP_PKEY *pkey, !CBS_get_u48(&mtc_proof, &subtree_start) || !CBS_get_u48(&mtc_proof, &subtree_end) || !CBS_get_u16_length_prefixed(&mtc_proof, &inclusion_proof) || - !CBS_get_u16_length_prefixed(&mtc_proof, &signatures) || + !CBS_get_u24_length_prefixed(&mtc_proof, &signatures) || CBS_len(&mtc_proof) != 0) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR); return 0; @@ -496,12 +504,9 @@ int x509_verify_mtc(const X509 *x509, const EVP_PKEY *pkey, return 0; } // `index` is the least significant 48 bits of `serial`. - uint64_t index = serial & ((uint64_t{1} << 48) - 1); - uint64_t log_number = serial >> 48; - if (log_number == 0) { - OPENSSL_PUT_ERROR(X509, X509_R_INVALID_PARAMETER); - return 0; - } + const uint64_t index = serial & ((uint64_t{1} << 48) - 1); + const uint64_t log_number = serial >> 48; + assert(is_mtc_serial_valid(serial)); // The TBSCertificate's `signature` field must match the expected MTC // signature algorithm identifier. @@ -544,9 +549,13 @@ int x509_verify_mtc(const X509 *x509, const EVP_PKEY *pkey, } uint8_t spki_digest[EVP_MAX_MD_SIZE]; unsigned int spki_digest_len; + // The short-form DER length can only encode lengths up to 127 (0x7f). The MTC + // spec permits longer hash lengths up to 255 (0xff), which would require a + // long-form length, but no `EVP_MD` currently outputs more than 127 bytes, so + // reject them here instead of supporting both short and long encoding forms. if (!EVP_Digest(CBS_data(&spki), CBS_len(&spki), spki_digest, &spki_digest_len, issuer_mtc_ca.log_hash(), nullptr) || - spki_digest_len == 0 || spki_digest_len > 0xff) { + spki_digest_len == 0 || spki_digest_len > 0x7f) { OPENSSL_PUT_ERROR(X509, ERR_R_INTERNAL_ERROR); return 0; } diff --git a/third_party/boringssl/src/crypto/x509/x509_set.cc b/third_party/boringssl/src/crypto/x509/x509_set.cc index ae45063..2ede541 100644 --- a/third_party/boringssl/src/crypto/x509/x509_set.cc +++ b/third_party/boringssl/src/crypto/x509/x509_set.cc @@ -143,7 +143,7 @@ void X509_get0_uids(const X509 *x509, const ASN1_BIT_STRING **out_issuer_uid, } } -int X509_set_pubkey(X509 *x, EVP_PKEY *pkey) { +int X509_set_pubkey(X509 *x, const EVP_PKEY *pkey) { if (x == nullptr) { return 0; } diff --git a/third_party/boringssl/src/crypto/x509/x509_vfy.cc b/third_party/boringssl/src/crypto/x509/x509_vfy.cc index 90a9d1f..d291f54 100644 --- a/third_party/boringssl/src/crypto/x509/x509_vfy.cc +++ b/third_party/boringssl/src/crypto/x509/x509_vfy.cc @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include #include #include @@ -60,6 +59,14 @@ static ExDataClass g_ex_data_class(/*with_app_data=*/true); // CRL issuer matches CRL AKID #define CRL_SCORE_AKID 0x004 +namespace { +struct CRLInfo { + UniquePtr crl; + X509 *issuer = nullptr; + int score = 0; +}; +} // namespace + static int null_callback(int ok, X509_STORE_CTX *e); static X509 *find_issuer(X509_STORE_CTX *ctx, const STACK_OF(X509) *sk, const X509 *x); @@ -68,20 +75,22 @@ static int check_name_constraints(X509_STORE_CTX *ctx); static int check_id(X509_STORE_CTX *ctx); static int check_trust(X509_STORE_CTX *ctx); static int check_revocation(X509_STORE_CTX *ctx); -static int check_cert(X509_STORE_CTX *ctx); +static int check_revocation_for_cert(X509_STORE_CTX *ctx, int depth); static int check_policy(X509_STORE_CTX *ctx); static UniquePtr get_trusted_issuer(X509_STORE_CTX *ctx, const X509 *x); -static int get_crl_score(X509_STORE_CTX *ctx, X509 **pissuer, X509_CRL *crl, - X509 *x); -static int get_crl(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509 *x); -static int crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl, X509 **pissuer, - int *pcrl_score); -static int crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score); -static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl); -static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); - -static int internal_verify(X509_STORE_CTX *ctx); +static int get_crl_score(X509_STORE_CTX *ctx, X509 **out_issuer, + const X509_CRL *crl, const X509 *x, int depth); +static int get_crl(X509_STORE_CTX *ctx, CRLInfo *out_crl_info, const X509 *x, + int depth); +static int crl_akid_check(X509_STORE_CTX *ctx, const X509_CRL *crl, + X509 **out_issuer, int *out_crl_score, int depth); +static int crl_crldp_check(const X509 *x, const X509_CRL *crl, int crl_score); +static int check_crl(X509_STORE_CTX *ctx, const CRLInfo &crl_info, int depth); +static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, const X509 *x, + int depth); + +static int check_chain_signatures_and_time(X509_STORE_CTX *ctx); static int null_callback(int ok, X509_STORE_CTX *e) { return ok; } @@ -108,6 +117,14 @@ static int call_verify_cb(int ok, X509_STORE_CTX *ctx) { return ok; } +// TODO(crbug.com/42290549): Switch remaining `call_verify_cb` calls to this +// function. +static int call_verify_cb_at_depth(int ok, X509_STORE_CTX *ctx, int depth) { + ctx->current_cert = sk_X509_value(ctx->chain, depth); + ctx->error_depth = depth; + return call_verify_cb(ok, ctx); +} + // Given a certificate try and find an exact match in the store static UniquePtr lookup_cert_match(X509_STORE_CTX *ctx, const X509 *x) { // Lookup all certs with matching subject name @@ -254,10 +271,8 @@ int X509_verify_cert(X509_STORE_CTX *ctx) { UniquePtr issuer = get_trusted_issuer(ctx, last); if (issuer == nullptr || X509_cmp(last, issuer.get()) != 0) { ctx->error = X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT; - ctx->current_cert = last; - ctx->error_depth = num - 1; bad_chain = 1; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, num - 1)) { return 0; } } else { @@ -323,7 +338,6 @@ int X509_verify_cert(X509_STORE_CTX *ctx) { } else { ctx->error = X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT; } - ctx->current_cert = last; } else { if (!PushToStack(ctx->chain, std::move(chain_ss))) { ctx->error = X509_V_ERR_OUT_OF_MEM; @@ -331,13 +345,11 @@ int X509_verify_cert(X509_STORE_CTX *ctx) { } num++; ctx->last_untrusted = num; - ctx->current_cert = sk_X509_last(ctx->chain); ctx->error = X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN; } - ctx->error_depth = num - 1; bad_chain = 1; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, num - 1)) { return 0; } } @@ -347,8 +359,8 @@ int X509_verify_cert(X509_STORE_CTX *ctx) { !check_id(ctx) || // We check revocation status after copying parameters because they may // be needed for CRL signature verification. - !check_revocation(ctx) || // - !internal_verify(ctx) || // + !check_revocation(ctx) || // + !check_chain_signatures_and_time(ctx) || // !check_name_constraints(ctx) || // TODO(davidben): Does `check_policy` still need to be conditioned on // |!bad_chain|? DoS concerns have been resolved. @@ -415,9 +427,7 @@ static int check_chain_extensions(X509_STORE_CTX *ctx) { if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL) && (x->ex_flags & EXFLAG_CRITICAL)) { ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION; - ctx->error_depth = i; - ctx->current_cert = x; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, i)) { return 0; } } @@ -425,18 +435,14 @@ static int check_chain_extensions(X509_STORE_CTX *ctx) { int must_be_ca = i > 0; if (must_be_ca && !X509_check_ca(x)) { ctx->error = X509_V_ERR_INVALID_CA; - ctx->error_depth = i; - ctx->current_cert = x; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, i)) { return 0; } } if (ctx->param->purpose > 0 && X509_check_purpose(x, purpose, must_be_ca) != 1) { ctx->error = X509_V_ERR_INVALID_PURPOSE; - ctx->error_depth = i; - ctx->current_cert = x; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, i)) { return 0; } } @@ -451,9 +457,7 @@ static int check_chain_extensions(X509_STORE_CTX *ctx) { // considered - they are just not counted as part of the path length! if (i > 1 && x->ex_pathlen != -1 && plen > x->ex_pathlen + 1) { ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED; - ctx->error_depth = i; - ctx->current_cert = x; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, i)) { return 0; } } @@ -522,9 +526,7 @@ static int check_name_constraints(X509_STORE_CTX *ctx) { return 0; default: ctx->error = rv; - ctx->error_depth = i; - ctx->current_cert = x; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, i)) { return 0; } break; @@ -554,9 +556,7 @@ static int check_name_constraints(X509_STORE_CTX *ctx) { return 0; default: ctx->error = rv; - ctx->error_depth = 0; - ctx->current_cert = leaf; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, /*depth=*/0)) { return 0; } break; @@ -568,9 +568,7 @@ static int check_name_constraints(X509_STORE_CTX *ctx) { static int check_id_error(X509_STORE_CTX *ctx, int errcode) { ctx->error = errcode; - ctx->current_cert = ctx->cert; - ctx->error_depth = 0; - return call_verify_cb(0, ctx); + return call_verify_cb_at_depth(0, ctx, /*depth=*/0); } static int check_hosts(X509 *x, X509_VERIFY_PARAM *param) { @@ -625,10 +623,8 @@ static int check_trust(X509_STORE_CTX *ctx) { // If explicitly rejected notify callback and reject if not // overridden. if (trust == X509_TRUST_REJECTED) { - ctx->error_depth = (int)i; - ctx->current_cert = x; ctx->error = X509_V_ERR_CERT_REJECTED; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, static_cast(i))) { return X509_TRUST_REJECTED; } } @@ -665,58 +661,36 @@ static int check_revocation(X509_STORE_CTX *ctx) { last = 0; } for (int i = 0; i <= last; i++) { - ctx->error_depth = i; - if (!check_cert(ctx)) { + if (!check_revocation_for_cert(ctx, i)) { return 0; } } return 1; } -static int check_cert(X509_STORE_CTX *ctx) { - X509_CRL *crl = nullptr; - int ok = 0, cnum = ctx->error_depth; - X509 *x = sk_X509_value(ctx->chain, cnum); - ctx->current_cert = x; - ctx->current_crl_issuer = nullptr; - ctx->current_crl_score = 0; - - // Try to retrieve the relevant CRL. Note that `get_crl` sets - // `current_crl_issuer` and `current_crl_score`, which `check_crl` then reads. - // - // TODO(davidben): The awkward internal calling convention is a historical - // artifact of when these functions were user-overridable callbacks, even - // though there was no way to set them correctly. These callbacks have since - // been removed, so we can pass input and output parameters more directly. - if (!get_crl(ctx, &crl, x)) { +static int check_revocation_for_cert(X509_STORE_CTX *ctx, int depth) { + X509 *x = sk_X509_value(ctx->chain, depth); + CRLInfo crl_info; + if (!get_crl(ctx, &crl_info, x, depth)) { ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL; - ok = call_verify_cb(0, ctx); - goto err; + return call_verify_cb_at_depth(0, ctx, depth); } - ctx->current_crl = crl; - if (!check_crl(ctx, crl) || // - !cert_crl(ctx, crl, x)) { - goto err; + if (!check_crl(ctx, crl_info, depth) || // + !cert_crl(ctx, crl_info.crl.get(), x, depth)) { + return 0; } - ok = 1; - -err: - X509_CRL_free(crl); - ctx->current_crl = nullptr; - return ok; + return 1; } // Check CRL times against values in X509_STORE_CTX -static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify) { +static int check_crl_time(X509_STORE_CTX *ctx, const X509_CRL *crl, bool notify, + int depth) { if (ctx->param->flags & X509_V_FLAG_NO_CHECK_TIME) { return 1; } - if (notify) { - ctx->current_crl = crl; - } int64_t ptime; if (ctx->param->flags & X509_V_FLAG_USE_CHECK_TIME) { ptime = ctx->param->check_time; @@ -730,7 +704,7 @@ static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify) { return 0; } ctx->error = X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, depth)) { return 0; } } @@ -740,7 +714,7 @@ static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify) { return 0; } ctx->error = X509_V_ERR_CRL_NOT_YET_VALID; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, depth)) { return 0; } } @@ -753,7 +727,7 @@ static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify) { return 0; } ctx->error = X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, depth)) { return 0; } } @@ -762,36 +736,27 @@ static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify) { return 0; } ctx->error = X509_V_ERR_CRL_HAS_EXPIRED; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, depth)) { return 0; } } } - if (notify) { - ctx->current_crl = nullptr; - } - return 1; } -static int get_crl_sk(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509 **pissuer, - int *pscore, STACK_OF(X509_CRL) *crls) { - int crl_score, best_score = *pscore; - X509 *x = ctx->current_cert; - X509_CRL *best_crl = nullptr; - X509 *crl_issuer = nullptr, *best_crl_issuer = nullptr; - - for (size_t i = 0; i < sk_X509_CRL_num(crls); i++) { - X509_CRL *crl = sk_X509_CRL_value(crls, i); - crl_score = get_crl_score(ctx, &crl_issuer, crl, x); - if (crl_score < best_score || crl_score == 0) { +static int get_crl_sk(X509_STORE_CTX *ctx, CRLInfo *best, + STACK_OF(X509_CRL) *crls, const X509 *x, int depth) { + for (X509_CRL *crl : crls) { + X509 *crl_issuer = nullptr; + int crl_score = get_crl_score(ctx, &crl_issuer, crl, x, depth); + if (crl_score < best->score || crl_score == 0) { continue; } // If current CRL is equivalent use it if it is newer - if (crl_score == best_score && best_crl != nullptr) { + if (crl_score == best->score && best->crl != nullptr) { int day, sec; - if (ASN1_TIME_diff(&day, &sec, X509_CRL_get0_lastUpdate(best_crl), + if (ASN1_TIME_diff(&day, &sec, X509_CRL_get0_lastUpdate(best->crl.get()), X509_CRL_get0_lastUpdate(crl)) == 0) { continue; } @@ -801,62 +766,52 @@ static int get_crl_sk(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509 **pissuer, continue; } } - best_crl = crl; - best_crl_issuer = crl_issuer; - best_score = crl_score; - } - - if (best_crl) { - if (*pcrl) { - X509_CRL_free(*pcrl); - } - *pcrl = best_crl; - *pissuer = best_crl_issuer; - *pscore = best_score; - X509_CRL_up_ref(best_crl); - } - - if (best_score >= CRL_SCORE_VALID) { - return 1; + best->crl = UpRef(crl); + best->issuer = crl_issuer; + best->score = crl_score; } - return 0; + return best->score >= CRL_SCORE_VALID; } // For a given CRL return how suitable it is for the supplied certificate // 'x'. The return value is a mask of several criteria. If the issuer is not // the certificate issuer this is returned in *pissuer. -static int get_crl_score(X509_STORE_CTX *ctx, X509 **pissuer, X509_CRL *crl, - X509 *x) { - int crl_score = 0; - - // First see if we can reject CRL straight away - - // Invalid IDP cannot be processed - if (crl->idp_flags & IDP_INVALID) { - return 0; - } - // Reason codes and indirect CRLs are not supported. - if (crl->idp_flags & (IDP_INDIRECT | IDP_REASONS)) { - return 0; +static int get_crl_score(X509_STORE_CTX *ctx, X509 **out_issuer, + const X509_CRL *crl, const X509 *x, int depth) { + if (crl->idp) { + // Per RFC 5280, section 5.2.5, at most one of onlyContainsUserCerts, + // onlyContainsCACerts, and onlyContainsAttributeCerts may be true. + // TODO(crbug.com/42290307): Move this check to the `ISSUING_DIST_POINT` + // parser. + int num_only = + (!!crl->idp->onlyuser) + (!!crl->idp->onlyCA) + (!!crl->idp->onlyattr); + if (num_only > 1) { + return 0; + } + // Reason codes and indirect CRLs are not supported. + if (crl->idp->indirectCRL || crl->idp->onlysomereasons) { + return 0; + } } + // We do not support indirect CRLs, so the issuer names must match. if (X509_NAME_cmp(X509_get_issuer_name(x), X509_CRL_get_issuer(crl))) { return 0; } - crl_score |= CRL_SCORE_ISSUER_NAME; + int crl_score = CRL_SCORE_ISSUER_NAME; if (!(crl->flags & EXFLAG_CRITICAL)) { crl_score |= CRL_SCORE_NOCRITICAL; } // Check expiry - if (check_crl_time(ctx, crl, 0)) { + if (check_crl_time(ctx, crl, /*notify=*/false, depth)) { crl_score |= CRL_SCORE_TIME; } // Check authority key ID and locate certificate issuer - if (!crl_akid_check(ctx, crl, pissuer, &crl_score)) { + if (!crl_akid_check(ctx, crl, out_issuer, &crl_score, depth)) { // If we can't locate certificate issuer at this point forget it return 0; } @@ -869,32 +824,28 @@ static int get_crl_score(X509_STORE_CTX *ctx, X509 **pissuer, X509_CRL *crl, return crl_score; } -static int crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl, X509 **pissuer, - int *pcrl_score) { - X509 *crl_issuer = nullptr; - X509_NAME *cnm = X509_CRL_get_issuer(crl); - int cidx = ctx->error_depth; - - if ((size_t)cidx != sk_X509_num(ctx->chain) - 1) { - cidx++; +static int crl_akid_check(X509_STORE_CTX *ctx, const X509_CRL *crl, + X509 **out_issuer, int *out_crl_score, int depth) { + const X509_NAME *cnm = X509_CRL_get_issuer(crl); + if ((size_t)depth != sk_X509_num(ctx->chain) - 1) { + depth++; } - crl_issuer = sk_X509_value(ctx->chain, cidx); - + X509 *crl_issuer = sk_X509_value(ctx->chain, depth); if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) { - *pcrl_score |= CRL_SCORE_AKID | CRL_SCORE_ISSUER_CERT; - *pissuer = crl_issuer; + *out_crl_score |= CRL_SCORE_AKID | CRL_SCORE_ISSUER_CERT; + *out_issuer = crl_issuer; return 1; } - for (cidx++; cidx < (int)sk_X509_num(ctx->chain); cidx++) { - crl_issuer = sk_X509_value(ctx->chain, cidx); + for (depth++; depth < (int)sk_X509_num(ctx->chain); depth++) { + crl_issuer = sk_X509_value(ctx->chain, depth); if (X509_NAME_cmp(X509_get_subject_name(crl_issuer), cnm)) { continue; } if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) { - *pcrl_score |= CRL_SCORE_AKID | CRL_SCORE_SAME_PATH; - *pissuer = crl_issuer; + *out_crl_score |= CRL_SCORE_AKID | CRL_SCORE_SAME_PATH; + *out_issuer = crl_issuer; return 1; } } @@ -902,93 +853,52 @@ static int crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl, X509 **pissuer, return 0; } -// Check for match between two dist point names: three separate cases. 1. -// Both are relative names and compare X509_NAME types. 2. One full, one -// relative. Compare X509_NAME to GENERAL_NAMES. 3. Both are full names and -// compare two GENERAL_NAMES. 4. One is NULL: automatic match. -static int idp_check_dp(DIST_POINT_NAME *a, DIST_POINT_NAME *b) { - X509_NAME *nm = nullptr; - GENERAL_NAMES *gens = nullptr; - GENERAL_NAME *gena, *genb; - size_t i, j; - if (!a || !b) { +static int idp_check_dp(const DIST_POINT_NAME *dp_cert, + const DIST_POINT_NAME *dp_crl) { + // If the CRL IDP does not have a distributionPoint field, the CRL is scoped + // to the entire CA and matches everything. + // + // TODO(crbug.com/42290219): This covers a null `dp_crl`, but not `dp_cert`. + // If `dp_cert` is null, that means the certificate's DistributionPoint lacks + // a distributionPoint. However, DistributionPoints are required to have + // either distributionPoint or cRLIssuer (indirect CRL) and we reject the + // latter. However, we don't seem to check this in the parser. Enforce this so + // that `dp_cert` cannot be null. + if (!dp_cert || !dp_crl) { return 1; } - if (a->type == 1) { - if (!a->dpname) { - return 0; - } - // Case 1: two X509_NAME - if (b->type == 1) { - if (!b->dpname) { - return 0; - } - if (!X509_NAME_cmp(a->dpname, b->dpname)) { - return 1; - } else { - return 0; - } - } - // Case 2: set name and GENERAL_NAMES appropriately - nm = a->dpname; - gens = b->name.fullname; - } else if (b->type == 1) { - if (!b->dpname) { - return 0; - } - // Case 2: set name and GENERAL_NAMES appropriately - gens = a->name.fullname; - nm = b->dpname; - } - - // Handle case 2 with one GENERAL_NAMES and one X509_NAME - if (nm) { - for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) { - gena = sk_GENERAL_NAME_value(gens, i); - if (gena->type != GEN_DIRNAME) { - continue; - } - if (!X509_NAME_cmp(nm, gena->d.directoryName)) { - return 1; - } - } + // We only support fullName, not nameRelativeToCRLIssuer. + if (dp_cert->type != 0 || dp_crl->type != 0) { return 0; } - - // Else case 3: two GENERAL_NAMES - - for (i = 0; i < sk_GENERAL_NAME_num(a->name.fullname); i++) { - gena = sk_GENERAL_NAME_value(a->name.fullname, i); - for (j = 0; j < sk_GENERAL_NAME_num(b->name.fullname); j++) { - genb = sk_GENERAL_NAME_value(b->name.fullname, j); - if (!GENERAL_NAME_cmp(gena, genb)) { + // Check that the CRL's distributionPoint has some name in common with the + // certificate's. A CA might shard across multiple CRLs. This check ensures we + // are looking at the right shard. + // + // TODO(crbug.com/565047760): This should not be an O(N^2) comparison. + for (const GENERAL_NAME *gen_cert : dp_cert->name.fullname) { + for (const GENERAL_NAME *gen_crl : dp_crl->name.fullname) { + if (GENERAL_NAME_cmp(gen_cert, gen_crl) == 0) { return 1; } } } - return 0; } // Check CRLDP and IDP -static int crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score) { +static int crl_crldp_check(const X509 *x, const X509_CRL *crl, int crl_score) { auto *impl = FromOpaque(x); - // TODO(bbe): crbug.com/409778435 Make tests for the corner cases we hit - // here so that we stay correct for RFC 5280 6.3.3 steps b.1 and b.2 - if (crl->idp_flags & IDP_ONLYATTR) { - return 0; - } if (impl->ex_flags & EXFLAG_CA) { - if (crl->idp_flags & IDP_ONLYUSER) { + if (crl->idp && crl->idp->onlyuser) { return 0; } } else { - if (crl->idp_flags & IDP_ONLYCA) { + if (crl->idp && crl->idp->onlyCA) { return 0; } } - for (size_t i = 0; i < sk_DIST_POINT_num(impl->crldp.get()); i++) { - DIST_POINT *dp = sk_DIST_POINT_value(impl->crldp.get(), i); + for (const DIST_POINT *dp : impl->crldp.get()) { // Skip distribution points with a reasons field or a CRL issuer: // // We do not support CRLs partitioned by reason code. RFC 5280 requires CAs @@ -1009,41 +919,30 @@ static int crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score) { } // If the CRL does not specify an issuing distribution point, allow it to - // match anything. - // - // TODO(davidben): Does this match RFC 5280? It's hard to follow because RFC - // 5280 starts from distribution points, while this starts from CRLs. + // match anything. This partially implements RFC 5280. The final paragraph of + // RFC 5280, section 6.3.3, specifies a default CRL-DP. This default would + // match IDP-less CRLs and CRLs with an IDP of the default CRL-DP. We do not + // implement the second condition. return !crl->idp || !crl->idp->distpoint; } // Retrieve CRL corresponding to current certificate. -static int get_crl(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509 *x) { - X509 *issuer = nullptr; - int crl_score = 0; - X509_CRL *crl = nullptr; - STACK_OF(X509_CRL) *skcrl = nullptr; - if (get_crl_sk(ctx, &crl, &issuer, &crl_score, ctx->crls)) { - goto done; - } - - // Lookup CRLs from store - skcrl = X509_STORE_CTX_get1_crls(ctx, X509_get_issuer_name(x)); - - // If no CRLs found and a near match from get_crl_sk use that - if (!skcrl && crl) { - goto done; +static int get_crl(X509_STORE_CTX *ctx, CRLInfo *out_crl_info, const X509 *x, + int depth) { + CRLInfo best; + if (!get_crl_sk(ctx, &best, ctx->crls, x, depth)) { + // If we haven't yet found a CRL with sufficiently high score, lookup CRLs + // from the store. + UniquePtr skcrl( + X509_STORE_CTX_get1_crls(ctx, X509_get_issuer_name(x))); + if (skcrl) { + get_crl_sk(ctx, &best, skcrl.get(), x, depth); + } } - get_crl_sk(ctx, &crl, &issuer, &crl_score, skcrl); - - sk_X509_CRL_pop_free(skcrl, X509_CRL_free); - -done: // If we got any kind of CRL use it and return success - if (crl) { - ctx->current_crl_issuer = issuer; - ctx->current_crl_score = crl_score; - *pcrl = crl; + if (best.crl) { + *out_crl_info = std::move(best); return 1; } @@ -1051,22 +950,22 @@ static int get_crl(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509 *x) { } // Check CRL validity -static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl) { - X509Impl *issuer = nullptr; - int cnum = ctx->error_depth; - int chnum = (int)sk_X509_num(ctx->chain) - 1; +static int check_crl(X509_STORE_CTX *ctx, const CRLInfo &crl_info, int depth) { + X509_CRL *crl = crl_info.crl.get(); + int root_depth = (int)sk_X509_num(ctx->chain) - 1; // If we have an alternative CRL issuer cert use that. Otherwise, it is the // issuer of the current certificate. - if (ctx->current_crl_issuer) { - issuer = FromOpaque(ctx->current_crl_issuer); - } else if (cnum < chnum) { - issuer = FromOpaque(sk_X509_value(ctx->chain, cnum + 1)); + X509Impl *issuer = nullptr; + if (crl_info.issuer) { + issuer = FromOpaque(crl_info.issuer); + } else if (depth < root_depth) { + issuer = FromOpaque(sk_X509_value(ctx->chain, depth + 1)); } else { - issuer = FromOpaque(sk_X509_value(ctx->chain, chnum)); + issuer = FromOpaque(sk_X509_value(ctx->chain, root_depth)); // If not self signed, can't check signature if (!x509_check_issued_with_callback(ctx, issuer, issuer)) { ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, depth)) { return 0; } } @@ -1077,27 +976,20 @@ static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl) { if ((issuer->ex_flags & EXFLAG_KUSAGE) && !(issuer->ex_kusage & X509v3_KU_CRL_SIGN)) { ctx->error = X509_V_ERR_KEYUSAGE_NO_CRL_SIGN; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, depth)) { return 0; } } - if (!(ctx->current_crl_score & CRL_SCORE_SCOPE)) { + if (!(crl_info.score & CRL_SCORE_SCOPE)) { ctx->error = X509_V_ERR_DIFFERENT_CRL_SCOPE; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, depth)) { return 0; } } - if (crl->idp_flags & IDP_INVALID) { - ctx->error = X509_V_ERR_INVALID_EXTENSION; - if (!call_verify_cb(0, ctx)) { - return 0; - } - } - - if (!(ctx->current_crl_score & CRL_SCORE_TIME)) { - if (!check_crl_time(ctx, crl, 1)) { + if (!(crl_info.score & CRL_SCORE_TIME)) { + if (!check_crl_time(ctx, crl, /*notify=*/true, depth)) { return 0; } } @@ -1106,14 +998,14 @@ static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl) { EVP_PKEY *ikey = X509_get0_pubkey(issuer); if (!ikey) { ctx->error = X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, depth)) { return 0; } } else { // Verify CRL signature if (X509_CRL_verify(crl, ikey) <= 0) { ctx->error = X509_V_ERR_CRL_SIGNATURE_FAILURE; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, depth)) { return 0; } } @@ -1124,7 +1016,8 @@ static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl) { } // Check certificate against CRL -static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x) { +static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, const X509 *x, + int depth) { // The rules changed for this... previously if a CRL contained unhandled // critical extensions it could still be used to indicate a certificate // was revoked. This has since been changed since critical extension can @@ -1132,7 +1025,7 @@ static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x) { if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL) && (crl->flags & EXFLAG_CRITICAL)) { ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, depth)) { return 0; } } @@ -1140,7 +1033,7 @@ static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x) { X509_REVOKED *rev; if (X509_CRL_get0_by_cert(crl, &rev, x)) { ctx->error = X509_V_ERR_CERT_REVOKED; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, depth)) { return 0; } } @@ -1149,22 +1042,21 @@ static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x) { } static int check_policy(X509_STORE_CTX *ctx) { - X509 *current_cert = nullptr; + int error_depth; int ret = X509_policy_check(ctx->chain, ctx->param->policies, - ctx->param->flags, ¤t_cert); + ctx->param->flags, &error_depth); if (ret != X509_V_OK) { - ctx->current_cert = current_cert; ctx->error = ret; if (ret == X509_V_ERR_OUT_OF_MEM) { return 0; } - return call_verify_cb(0, ctx); + return call_verify_cb_at_depth(0, ctx, error_depth); } return 1; } -static int check_cert_time(X509_STORE_CTX *ctx, X509 *x) { +static int check_cert_time(X509_STORE_CTX *ctx, X509 *x, int depth) { if (ctx->param->flags & X509_V_FLAG_NO_CHECK_TIME) { return 1; } @@ -1181,16 +1073,14 @@ static int check_cert_time(X509_STORE_CTX *ctx, X509 *x) { : X509_cmp_time_posix(X509_get_notBefore(x), ptime); if (i == 0) { ctx->error = X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD; - ctx->current_cert = x; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, depth)) { return 0; } } if (i > 0) { ctx->error = X509_V_ERR_CERT_NOT_YET_VALID; - ctx->current_cert = x; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, depth)) { return 0; } } @@ -1200,16 +1090,14 @@ static int check_cert_time(X509_STORE_CTX *ctx, X509 *x) { : X509_cmp_time_posix(X509_get_notAfter(x), ptime); if (i == 0) { ctx->error = X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD; - ctx->current_cert = x; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, depth)) { return 0; } } if (i < 0) { ctx->error = X509_V_ERR_CERT_HAS_EXPIRED; - ctx->current_cert = x; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, depth)) { return 0; } } @@ -1218,9 +1106,14 @@ static int check_cert_time(X509_STORE_CTX *ctx, X509 *x) { } static int verify_signature(X509_STORE_CTX *ctx, const X509 *x509, - const X509 *issuer, EVP_PKEY *pkey) { + const X509 *issuer) { + EVP_PKEY *pkey = X509_get0_pubkey(issuer); + if (pkey == nullptr) { + return X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY; + } + int ret; - if ((ctx->param->flags & X509_V_FLAG_USE_MTC_DRAFT_PLANTS_05) && + if ((ctx->param->flags & X509_V_FLAG_USE_MTC_DRAFT_PLANTS_07) && x509_is_merkle_tree_ca(issuer)) { ret = x509_verify_mtc(x509, pkey, issuer); } else { @@ -1229,73 +1122,28 @@ static int verify_signature(X509_STORE_CTX *ctx, const X509 *x509, return ret ? X509_V_OK : X509_V_ERR_CERT_SIGNATURE_FAILURE; } -static int internal_verify(X509_STORE_CTX *ctx) { - // TODO(davidben): This logic is incredibly confusing. Rewrite this: - // - // First, don't allow the verify callback to suppress - // X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY, which will simplify the - // signature check. Then replace jumping into the middle of the loop. It's - // trying to ensure that all certificates see `check_cert_time`, then checking - // the root's self signature when requested, but not breaking partial chains - // in the process. - int n = (int)sk_X509_num(ctx->chain); - ctx->error_depth = n - 1; - n--; - X509 *xi = sk_X509_value(ctx->chain, n); - X509 *xs; - if (x509_check_issued_with_callback(ctx, xi, xi)) { - xs = xi; - } else { - if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN) { - xs = xi; - goto check_cert; - } - if (n <= 0) { - ctx->error = X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE; - ctx->current_cert = xi; - return call_verify_cb(0, ctx); - } - n--; - ctx->error_depth = n; - xs = sk_X509_value(ctx->chain, n); - } - - // ctx->error=0; not needed - while (n >= 0) { - ctx->error_depth = n; - - // Skip signature check for self signed certificates unless - // explicitly asked for. It doesn't add any security and just wastes - // time. - if (xs != xi || (ctx->param->flags & X509_V_FLAG_CHECK_SS_SIGNATURE)) { - EVP_PKEY *pkey = X509_get0_pubkey(xi); - int err = pkey == nullptr ? X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY - : verify_signature(ctx, xs, xi, pkey); - if (err != X509_V_OK) { +static int check_chain_signatures_and_time(X509_STORE_CTX *ctx) { + size_t num = sk_X509_num(ctx->chain); + for (size_t i = num - 1; i < num; i--) { + X509 *x509 = sk_X509_value(ctx->chain, i); + if (i < num - 1) { + X509 *issuer = sk_X509_value(ctx->chain, i + 1); + if (int err = verify_signature(ctx, x509, issuer); err != X509_V_OK) { ctx->error = err; - ctx->current_cert = xs; - if (!call_verify_cb(0, ctx)) { + if (!call_verify_cb_at_depth(0, ctx, static_cast(i))) { return 0; } } } - check_cert: - if (!check_cert_time(ctx, xs)) { + if (!check_cert_time(ctx, x509, static_cast(i))) { return 0; } // The last error (if any) is still in the error value - ctx->current_cert = xs; - if (!call_verify_cb(1, ctx)) { + if (!call_verify_cb_at_depth(1, ctx, static_cast(i))) { return 0; } - - n--; - if (n >= 0) { - xi = xs; - xs = sk_X509_value(ctx->chain, n); - } } return 1; @@ -1393,10 +1241,6 @@ STACK_OF(X509) *X509_STORE_CTX_get1_chain(const X509_STORE_CTX *ctx) { return X509_chain_up_ref(ctx->chain); } -X509_CRL *X509_STORE_CTX_get0_current_crl(const X509_STORE_CTX *ctx) { - return ctx->current_crl; -} - X509_STORE_CTX *X509_STORE_CTX_get0_parent_ctx(const X509_STORE_CTX *ctx) { // In OpenSSL, an `X509_STORE_CTX` sometimes has a parent context during CRL // path validation for indirect CRLs. We require the CRL to be issued diff --git a/third_party/boringssl/src/crypto/x509/x509cset.cc b/third_party/boringssl/src/crypto/x509/x509cset.cc index 19e938a..5ece53d 100644 --- a/third_party/boringssl/src/crypto/x509/x509cset.cc +++ b/third_party/boringssl/src/crypto/x509/x509cset.cc @@ -103,6 +103,15 @@ int X509_CRL_up_ref(X509_CRL *crl) { return 1; } +X509_CRL *X509_CRL_dup_ref(const X509_CRL *crl) { + if (crl == nullptr) { + return nullptr; + } + auto *ptr = const_cast(crl); + CRYPTO_refcount_inc(&ptr->references); + return ptr; +} + long X509_CRL_get_version(const X509_CRL *crl) { return ASN1_INTEGER_get(crl->crl->version); } diff --git a/third_party/boringssl/src/crypto/x509/x_crl.cc b/third_party/boringssl/src/crypto/x509/x_crl.cc index d30c172..d67e458 100644 --- a/third_party/boringssl/src/crypto/x509/x_crl.cc +++ b/third_party/boringssl/src/crypto/x509/x_crl.cc @@ -33,7 +33,6 @@ using namespace bssl; static int X509_REVOKED_cmp(const X509_REVOKED *const *a, const X509_REVOKED *const *b); -static int setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp); BSSL_NAMESPACE_BEGIN @@ -141,7 +140,6 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, crl->idp = nullptr; crl->akid = nullptr; crl->flags = 0; - crl->idp_flags = 0; break; case ASN1_OP_D2I_POST: { @@ -176,11 +174,7 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, crl->idp = reinterpret_cast(X509_CRL_get_ext_d2i( crl, NID_issuing_distribution_point, &i, nullptr)); - if (crl->idp != nullptr) { - if (!setup_idp(crl, crl->idp)) { - return 0; - } - } else if (i != -1) { + if (crl->idp == nullptr && i != -1) { return 0; } @@ -223,49 +217,6 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, return 1; } -// Convert IDP into a more convenient form -// -// TODO(davidben): Each of these flags are already booleans, so this is not -// really more convenient. We can probably remove `idp_flags`. -static int setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) { - int idp_only = 0; - // Set various flags according to IDP - crl->idp_flags |= IDP_PRESENT; - if (idp->onlyuser > 0) { - idp_only++; - crl->idp_flags |= IDP_ONLYUSER; - } - if (idp->onlyCA > 0) { - idp_only++; - crl->idp_flags |= IDP_ONLYCA; - } - if (idp->onlyattr > 0) { - idp_only++; - crl->idp_flags |= IDP_ONLYATTR; - } - - // Per RFC 5280, section 5.2.5, at most one of onlyContainsUserCerts, - // onlyContainsCACerts, and onlyContainsAttributeCerts may be true. - // - // TODO(crbug.com/boringssl/443): Move this check to the `ISSUING_DIST_POINT` - // parser. - if (idp_only > 1) { - crl->idp_flags |= IDP_INVALID; - } - - if (idp->indirectCRL > 0) { - crl->idp_flags |= IDP_INDIRECT; - } - - if (idp->onlysomereasons) { - crl->idp_flags |= IDP_REASONS; - } - - // TODO(davidben): The new verifier does not support nameRelativeToCRLIssuer. - // Remove this? - return DIST_POINT_set_dpname(idp->distpoint, X509_CRL_get_issuer(crl)); -} - BSSL_NAMESPACE_BEGIN ASN1_SEQUENCE_ref(X509_CRL, crl_cb) = { diff --git a/third_party/boringssl/src/crypto/x509/x_pubkey.cc b/third_party/boringssl/src/crypto/x509/x_pubkey.cc index 4862f1f..3d59a1e 100644 --- a/third_party/boringssl/src/crypto/x509/x_pubkey.cc +++ b/third_party/boringssl/src/crypto/x509/x_pubkey.cc @@ -118,7 +118,7 @@ IMPLEMENT_EXTERN_ASN1_PARSE_INTO(X509_PUBKEY, X509_PUBKEY_new, X509_PUBKEY_free, BSSL_NAMESPACE_END -int bssl::x509_pubkey_set1(X509_PUBKEY *key, EVP_PKEY *pkey) { +int bssl::x509_pubkey_set1(X509_PUBKEY *key, const EVP_PKEY *pkey) { ScopedCBB cbb; if (!CBB_init(cbb.get(), 64) || !EVP_marshal_public_key(cbb.get(), pkey)) { OPENSSL_PUT_ERROR(X509, X509_R_PUBLIC_KEY_ENCODE_ERROR); diff --git a/third_party/boringssl/src/crypto/x509/x_x509.cc b/third_party/boringssl/src/crypto/x509/x_x509.cc index 413c40f..a2f1f1d 100644 --- a/third_party/boringssl/src/crypto/x509/x_x509.cc +++ b/third_party/boringssl/src/crypto/x509/x_x509.cc @@ -328,10 +328,10 @@ int X509_up_ref(X509 *x) { } X509 *X509_dup_ref(const X509 *x) { - auto *x_ref = const_cast(x); - // We know that this call always returns one. - X509_up_ref(x_ref); - return x_ref; + if (x == nullptr) { + return nullptr; + } + return FromOpaque(x)->DupRefInternal(); } int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused, diff --git a/third_party/boringssl/src/gen/crypto/err_data.cc b/third_party/boringssl/src/gen/crypto/err_data.cc index 9e0884a..b365a54 100644 --- a/third_party/boringssl/src/gen/crypto/err_data.cc +++ b/third_party/boringssl/src/gen/crypto/err_data.cc @@ -207,53 +207,53 @@ const uint32_t kOpenSSLReasonValues[] = { 0x283500f7, 0x28358cc1, 0x2836099a, - 0x2c323524, + 0x2c32353c, 0x2c32945a, - 0x2c333532, - 0x2c33b544, - 0x2c343558, - 0x2c34b56a, - 0x2c353585, - 0x2c35b597, - 0x2c3635c7, + 0x2c33354a, + 0x2c33b55c, + 0x2c343570, + 0x2c34b582, + 0x2c35359d, + 0x2c35b5af, + 0x2c3635df, 0x2c36833a, - 0x2c3735d4, - 0x2c37b600, - 0x2c38365f, - 0x2c38b676, - 0x2c393694, - 0x2c39b6a4, - 0x2c3a36b6, - 0x2c3ab6ca, - 0x2c3b36db, - 0x2c3bb6fa, + 0x2c3735ec, + 0x2c37b618, + 0x2c383677, + 0x2c38b68e, + 0x2c3936ac, + 0x2c39b6bc, + 0x2c3a36ce, + 0x2c3ab6e2, + 0x2c3b36f3, + 0x2c3bb712, 0x2c3c146c, 0x2c3c9482, - 0x2c3d373f, + 0x2c3d3757, 0x2c3d949b, - 0x2c3e3769, - 0x2c3eb777, - 0x2c3f378f, - 0x2c3fb7a7, - 0x2c4037d1, + 0x2c3e3781, + 0x2c3eb78f, + 0x2c3f37a7, + 0x2c3fb7bf, + 0x2c4037e9, 0x2c409347, - 0x2c4137e2, - 0x2c41b7f5, + 0x2c4137fa, + 0x2c41b80d, 0x2c42130d, - 0x2c42b806, + 0x2c42b81e, 0x2c43076d, - 0x2c43b6ec, - 0x2c443634, - 0x2c44b7b4, - 0x2c4535aa, - 0x2c45b5e6, - 0x2c463684, - 0x2c46b70e, - 0x2c473723, - 0x2c47b75c, - 0x2c483646, - 0x2c48b613, - 0x2c493622, + 0x2c43b704, + 0x2c44364c, + 0x2c44b7cc, + 0x2c4535c2, + 0x2c45b5fe, + 0x2c46369c, + 0x2c46b726, + 0x2c47373b, + 0x2c47b774, + 0x2c48365e, + 0x2c48b62b, + 0x2c49363a, 0x30320000, 0x30328015, 0x3033001f, @@ -455,154 +455,154 @@ const uint32_t kOpenSSLReasonValues[] = { 0x404fa30c, 0x405023c8, 0x4050a3dc, - 0x40512429, - 0x40522439, - 0x4052a469, - 0x40532481, - 0x4053a494, - 0x405424a9, - 0x4054a4cc, - 0x405524f7, - 0x4055a534, - 0x40562559, - 0x4056a572, - 0x4057258a, - 0x4057a59d, - 0x405825b2, - 0x4058a5d9, - 0x40592608, - 0x4059a648, - 0x405aa65c, - 0x405b2674, - 0x405ba685, - 0x405c2698, - 0x405ca6ed, - 0x405d26fa, - 0x405da71f, - 0x405e275d, + 0x40512441, + 0x40522451, + 0x4052a481, + 0x40532499, + 0x4053a4ac, + 0x405424c1, + 0x4054a4e4, + 0x4055250f, + 0x4055a54c, + 0x40562571, + 0x4056a58a, + 0x405725a2, + 0x4057a5b5, + 0x405825ca, + 0x4058a5f1, + 0x40592620, + 0x4059a660, + 0x405aa674, + 0x405b268c, + 0x405ba69d, + 0x405c26b0, + 0x405ca705, + 0x405d2712, + 0x405da737, + 0x405e2775, 0x405e8afe, - 0x405f278d, - 0x405fa79a, - 0x406027a8, - 0x4060a7ca, - 0x4061283e, - 0x4061a876, - 0x4062288d, - 0x4062a89e, - 0x406328eb, - 0x4063a900, - 0x40642917, - 0x4064a943, - 0x4065295e, - 0x4065a975, - 0x4066298d, - 0x4066a9b7, - 0x406729e2, - 0x4067aa27, - 0x40682a6f, - 0x4068aa90, - 0x40692ac2, - 0x4069aaf0, - 0x406a2b11, - 0x406aab31, - 0x406b2cb9, - 0x406bacdc, - 0x406c2cf2, - 0x406caffc, - 0x406d302b, - 0x406db053, - 0x406e3081, - 0x406eb0ce, - 0x406f3127, - 0x406fb15f, - 0x40703172, - 0x4070b18f, + 0x405f27a5, + 0x405fa7b2, + 0x406027c0, + 0x4060a7e2, + 0x40612856, + 0x4061a88e, + 0x406228a5, + 0x4062a8b6, + 0x40632903, + 0x4063a918, + 0x4064292f, + 0x4064a95b, + 0x40652976, + 0x4065a98d, + 0x406629a5, + 0x4066a9cf, + 0x406729fa, + 0x4067aa3f, + 0x40682a87, + 0x4068aaa8, + 0x40692ada, + 0x4069ab08, + 0x406a2b29, + 0x406aab49, + 0x406b2cd1, + 0x406bacf4, + 0x406c2d0a, + 0x406cb014, + 0x406d3043, + 0x406db06b, + 0x406e3099, + 0x406eb0e6, + 0x406f313f, + 0x406fb177, + 0x4070318a, + 0x4070b1a7, 0x4071084d, - 0x4071b1a1, - 0x407231b4, - 0x4072b1ea, - 0x40733202, + 0x4071b1b9, + 0x407231cc, + 0x4072b202, + 0x4073321a, 0x40739684, - 0x40743216, - 0x4074b230, - 0x40753241, - 0x4075b255, - 0x40763263, + 0x4074322e, + 0x4074b248, + 0x40753259, + 0x4075b26d, + 0x4076327b, 0x4076940a, - 0x407732a0, - 0x4077b2fc, - 0x40783317, - 0x4078b369, - 0x40793380, - 0x4079b396, - 0x407a33c2, - 0x407ab3d5, - 0x407b33ea, - 0x407bb3fc, - 0x407c342d, - 0x407cb436, - 0x407d2aab, + 0x407732b8, + 0x4077b314, + 0x4078332f, + 0x4078b381, + 0x40793398, + 0x4079b3ae, + 0x407a33da, + 0x407ab3ed, + 0x407b3402, + 0x407bb414, + 0x407c3445, + 0x407cb44e, + 0x407d2ac3, 0x407da334, - 0x407e332c, - 0x407ea5e9, + 0x407e3344, + 0x407ea601, 0x407f1ee9, 0x407fa0dd, 0x408022a6, 0x40809f22, - 0x40812457, + 0x4081246f, 0x4081a1e4, - 0x4082306c, + 0x40823084, 0x40829c64, - 0x408325c4, - 0x4083a928, + 0x408325dc, + 0x4083a940, 0x40841f46, - 0x4084a621, - 0x408526a9, - 0x4085a805, - 0x4086273f, + 0x4084a639, + 0x408526c1, + 0x4085a81d, + 0x40862757, 0x4086a380, - 0x408730b2, - 0x4087a853, + 0x408730ca, + 0x4087a86b, 0x40881ca2, - 0x4088aa3a, + 0x4088aa52, 0x40891cf1, 0x40899c7e, - 0x408a2d2a, + 0x408a2d42, 0x408a9a9c, - 0x408b3411, - 0x408bb13c, - 0x408c26cf, + 0x408b3429, + 0x408bb154, + 0x408c26e7, 0x408d202e, 0x408d9f78, 0x408e215e, - 0x408ea514, - 0x408f2a4e, - 0x408fa821, - 0x40902a03, - 0x4090a711, - 0x40912d12, + 0x408ea52c, + 0x408f2a66, + 0x408fa839, + 0x40902a1b, + 0x4090a729, + 0x40912d2a, 0x40919ad4, 0x40921d3e, - 0x4092b0ed, - 0x409331cd, + 0x4092b105, + 0x409331e5, 0x4093a391, 0x40941f5a, - 0x4094ad43, - 0x409528af, - 0x4095b3a2, - 0x40963099, + 0x4094ad5b, + 0x409528c7, + 0x4095b3ba, + 0x409630b1, 0x4096a2bf, - 0x40972411, + 0x40972429, 0x4097a1ad, 0x40981d9e, - 0x4098a8c3, - 0x40993109, - 0x4099a541, - 0x409a24da, + 0x4098a8db, + 0x40993121, + 0x4099a559, + 0x409a24f2, 0x409a9ab8, 0x409b1fb4, 0x409b9fdf, - 0x409c32de, + 0x409c32f6, 0x409ca007, 0x409d227b, 0x409da1fa, @@ -613,57 +613,58 @@ const uint32_t kOpenSSLReasonValues[] = { 0x40a0231c, 0x40a0a1c7, 0x40a12215, - 0x40a1a635, + 0x40a1a64d, 0x40a223ad, - 0x40a2a77e, - 0x40a327f2, - 0x40a3b2c2, - 0x40a423f7, + 0x40a2a796, + 0x40a3280a, + 0x40a3b2da, + 0x40a4240f, 0x40a4a22c, 0x40a51f36, 0x40a5a34e, - 0x40a626b9, + 0x40a626d1, 0x40a6a24e, - 0x40a73288, - 0x40a7a44b, + 0x40a732a0, + 0x40a7a463, 0x40a82369, - 0x40a8b350, + 0x40a8b368, 0x40a92266, 0x40a99f11, - 0x41f42be4, - 0x41f92c76, - 0x41fe2b69, - 0x41feae1f, - 0x41ff2f4d, - 0x42032bfd, - 0x42082c1f, - 0x4208ac5b, - 0x42092b4d, - 0x4209ac95, - 0x420a2ba4, - 0x420aab84, - 0x420b2bc4, - 0x420bac3d, - 0x420c2f69, - 0x420cad53, - 0x420d2e06, - 0x420dae3d, - 0x42122e70, - 0x42172f30, - 0x4217aeb2, - 0x421c2ed4, - 0x421f2e8f, - 0x42212fe1, - 0x42262f13, - 0x422b2fbf, - 0x422bade1, - 0x422c2fa1, - 0x422cad94, - 0x422d2d6d, - 0x422daf80, - 0x422e2dc0, - 0x42302eef, - 0x4230ae57, + 0x40aa23f7, + 0x41f42bfc, + 0x41f92c8e, + 0x41fe2b81, + 0x41feae37, + 0x41ff2f65, + 0x42032c15, + 0x42082c37, + 0x4208ac73, + 0x42092b65, + 0x4209acad, + 0x420a2bbc, + 0x420aab9c, + 0x420b2bdc, + 0x420bac55, + 0x420c2f81, + 0x420cad6b, + 0x420d2e1e, + 0x420dae55, + 0x42122e88, + 0x42172f48, + 0x4217aeca, + 0x421c2eec, + 0x421f2ea7, + 0x42212ff9, + 0x42262f2b, + 0x422b2fd7, + 0x422badf9, + 0x422c2fb9, + 0x422cadac, + 0x422d2d85, + 0x422daf98, + 0x422e2dd8, + 0x42302f07, + 0x4230ae6f, 0x44320778, 0x44328787, 0x44330793, @@ -719,71 +720,71 @@ const uint32_t kOpenSSLReasonValues[] = { 0x4c419564, 0x4c4216cd, 0x4c4294ac, - 0x50323818, - 0x5032b827, - 0x50333832, - 0x5033b842, - 0x5034385b, - 0x5034b875, - 0x50353883, - 0x5035b899, - 0x503638ab, - 0x5036b8c1, - 0x503738da, - 0x5037b8ed, - 0x50383905, - 0x5038b916, - 0x5039392b, - 0x5039b93f, - 0x503a395f, - 0x503ab975, - 0x503b398d, - 0x503bb99f, - 0x503c39bb, - 0x503cb9d2, - 0x503d39eb, - 0x503dba01, - 0x503e3a0e, - 0x503eba24, - 0x503f3a36, + 0x50323830, + 0x5032b83f, + 0x5033384a, + 0x5033b85a, + 0x50343873, + 0x5034b88d, + 0x5035389b, + 0x5035b8b1, + 0x503638c3, + 0x5036b8d9, + 0x503738f2, + 0x5037b905, + 0x5038391d, + 0x5038b92e, + 0x50393943, + 0x5039b957, + 0x503a3977, + 0x503ab98d, + 0x503b39a5, + 0x503bb9b7, + 0x503c39d3, + 0x503cb9ea, + 0x503d3a03, + 0x503dba19, + 0x503e3a26, + 0x503eba3c, + 0x503f3a4e, 0x503f83b3, - 0x50403a49, - 0x5040ba59, - 0x50413a73, - 0x5041ba82, - 0x50423a9c, - 0x5042bab9, - 0x50433ac9, - 0x5043bad9, - 0x50443af6, + 0x50403a61, + 0x5040ba71, + 0x50413a8b, + 0x5041ba9a, + 0x50423ab4, + 0x5042bad1, + 0x50433ae1, + 0x5043baf1, + 0x50443b0e, 0x50448469, - 0x50453b0a, - 0x5045bb28, - 0x50463b3b, - 0x5046bb51, - 0x50473b63, - 0x5047bb78, - 0x50483b9e, - 0x5048bbac, - 0x50493bbf, - 0x5049bbd4, - 0x504a3bea, - 0x504abbfa, - 0x504b3c1a, - 0x504bbc2d, - 0x504c3c50, - 0x504cbc7e, - 0x504d3cab, - 0x504dbcc8, - 0x504e3ce3, - 0x504ebcff, - 0x504f3d11, - 0x504fbd28, - 0x50503d37, + 0x50453b22, + 0x5045bb40, + 0x50463b53, + 0x5046bb69, + 0x50473b7b, + 0x5047bb90, + 0x50483bb6, + 0x5048bbc4, + 0x50493bd7, + 0x5049bbec, + 0x504a3c02, + 0x504abc12, + 0x504b3c32, + 0x504bbc45, + 0x504c3c68, + 0x504cbc96, + 0x504d3cc3, + 0x504dbce0, + 0x504e3cfb, + 0x504ebd17, + 0x504f3d29, + 0x504fbd40, + 0x50503d4f, 0x50508729, - 0x50513d4a, - 0x5051bae8, - 0x50523c90, + 0x50513d62, + 0x5051bb00, + 0x50523ca8, 0x58321011, 0x68320fd3, 0x68328d2b, @@ -828,19 +829,19 @@ const uint32_t kOpenSSLReasonValues[] = { 0x7c321323, 0x80321577, 0x80328090, - 0x803334f3, + 0x8033350b, 0x803380b9, - 0x80343502, - 0x8034b46a, - 0x80353488, - 0x8035b516, - 0x803634ca, - 0x8036b479, - 0x803734bc, - 0x8037b457, - 0x803834dd, - 0x8038b499, - 0x803934ae, + 0x8034351a, + 0x8034b482, + 0x803534a0, + 0x8035b52e, + 0x803634e2, + 0x8036b491, + 0x803734d4, + 0x8037b46f, + 0x803834f5, + 0x8038b4b1, + 0x803934c6, 0x84320bb0, 0x84328bc9, }; @@ -1296,6 +1297,7 @@ const char kOpenSSLReasonStringData[] = "INVALID_SPAKE2PLUSV1_VALUE\0" "INVALID_SSL_SESSION\0" "INVALID_TICKET_KEYS_LENGTH\0" + "INVALID_TRUST_ANCHOR_ID\0" "INVALID_TRUST_ANCHOR_LIST\0" "KEY_USAGE_BIT_INCORRECT\0" "LENGTH_MISMATCH\0" diff --git a/third_party/boringssl/src/include/openssl/asn1.h b/third_party/boringssl/src/include/openssl/asn1.h index 1dae5f7..2882a25 100644 --- a/third_party/boringssl/src/include/openssl/asn1.h +++ b/third_party/boringssl/src/include/openssl/asn1.h @@ -90,6 +90,7 @@ extern "C" { #define V_ASN1_REAL 9 #define V_ASN1_ENUMERATED 10 #define V_ASN1_UTF8STRING 12 +#define V_ASN1_RELATIVE_OID 13 #define V_ASN1_SEQUENCE 16 #define V_ASN1_SET 17 #define V_ASN1_NUMERICSTRING 18 @@ -516,23 +517,12 @@ OPENSSL_EXPORT int ASN1_STRING_type(const ASN1_STRING *str); OPENSSL_EXPORT const unsigned char *ASN1_STRING_get0_data( const ASN1_STRING *str); -// ASN1_STRING_data returns a mutable pointer to `str`'s contents. Callers -// should use `ASN1_STRING_length` to determine the length of the string. The -// string may have embedded NUL bytes and may not be NUL-terminated. -// -// The contents of an `ASN1_STRING` encode the value in some type-specific -// representation that does not always correspond to the DER encoding of the -// type. See the documentation for `ASN1_STRING` for details. -// -// Prefer `ASN1_STRING_get0_data`. -OPENSSL_EXPORT unsigned char *ASN1_STRING_data(ASN1_STRING *str); - -// ASN1_STRING_length returns the length of `str`, in bytes. +// ASN1_STRING_get_length returns the length of `str`, in bytes. // // The contents of an `ASN1_STRING` encode the value in some type-specific // representation that does not always correspond to the DER encoding of the // type. See the documentation for `ASN1_STRING` for details. -OPENSSL_EXPORT int ASN1_STRING_length(const ASN1_STRING *str); +OPENSSL_EXPORT size_t ASN1_STRING_get_length(const ASN1_STRING *str); // ASN1_STRING_cmp compares `a` and `b`'s type and contents. It returns an // integer equal to, less than, or greater than zero if `a` is equal to, less @@ -1809,6 +1799,25 @@ OPENSSL_EXPORT unsigned long ASN1_STRING_get_default_mask(void); // ASN1_STRING_TABLE_cleanup does nothing. OPENSSL_EXPORT void ASN1_STRING_TABLE_cleanup(void); +// ASN1_STRING_data returns a mutable pointer to `str`'s contents. Callers +// should use `ASN1_STRING_length` to determine the length of the string. The +// string may have embedded NUL bytes and may not be NUL-terminated. +// +// The contents of an `ASN1_STRING` encode the value in some type-specific +// representation that does not always correspond to the DER encoding of the +// type. See the documentation for `ASN1_STRING` for details. +// +// Prefer `ASN1_STRING_get0_data`. See crbug.com/574019297. +OPENSSL_EXPORT unsigned char *ASN1_STRING_data(ASN1_STRING *str); + +// ASN1_STRING_length returns the length of `str`, in bytes. Prefer +// `ASN1_STRING_get_length`. +// +// The contents of an `ASN1_STRING` encode the value in some type-specific +// representation that does not always correspond to the DER encoding of the +// type. See the documentation for `ASN1_STRING` for details. +OPENSSL_EXPORT int ASN1_STRING_length(const ASN1_STRING *str); + // M_ASN1_* are legacy aliases for various `ASN1_STRING` functions. Use the // functions themselves. #define M_ASN1_STRING_length(x) ASN1_STRING_length(x) diff --git a/third_party/boringssl/src/include/openssl/base.h b/third_party/boringssl/src/include/openssl/base.h index 83cc91b..e2741eb 100644 --- a/third_party/boringssl/src/include/openssl/base.h +++ b/third_party/boringssl/src/include/openssl/base.h @@ -73,7 +73,7 @@ extern "C" { // A consumer may use this symbol in the preprocessor to temporarily build // against multiple revisions of BoringSSL at the same time. It is not // recommended to do so for longer than is necessary. -#define BORINGSSL_API_VERSION 43 +#define BORINGSSL_API_VERSION 44 #if defined(BORINGSSL_SHARED_LIBRARY) @@ -287,6 +287,7 @@ typedef struct cbs_st CBS; typedef struct cmac_ctx_st CMAC_CTX; typedef struct conf_st CONF; typedef struct conf_value_st CONF_VALUE; +typedef struct cpace_ctx_st CPACE_CTX; typedef struct crypto_buffer_pool_st CRYPTO_BUFFER_POOL; typedef struct crypto_buffer_st CRYPTO_BUFFER; typedef struct crypto_ivec_st CRYPTO_IVEC; @@ -394,7 +395,7 @@ typedef void *OPENSSL_BLOCK; #if defined(BORINGSSL_NO_CXX) #define BORINGSSL_MAKE_DELETER(type, deleter) -#define BORINGSSL_MAKE_UP_REF(type, up_ref_func) +#define BORINGSSL_MAKE_UP_REF(type, dup_ref_func) #define BORINGSSL_MAKE_STACK_TRAITS(type, init_func, cleanup_func) #define BORINGSSL_MAKE_STACK_TRAITS_MOVABLE(type, init_func, cleanup_func, \ move_func) @@ -526,12 +527,9 @@ class StackAllocatedMovable { template using UniquePtr = std::unique_ptr; -#define BORINGSSL_MAKE_UP_REF(type, up_ref_func) \ - inline UniquePtr UpRef(type *v) { \ - if (v != nullptr) { \ - up_ref_func(v); \ - } \ - return UniquePtr(v); \ +#define BORINGSSL_MAKE_UP_REF(type, dup_ref_func) \ + inline UniquePtr UpRef(const type *v) { \ + return UniquePtr(dup_ref_func(v)); \ } \ \ inline UniquePtr UpRef(const UniquePtr &ptr) { \ diff --git a/third_party/boringssl/src/include/openssl/bio.h b/third_party/boringssl/src/include/openssl/bio.h index 630be3e..48ee4ae 100644 --- a/third_party/boringssl/src/include/openssl/bio.h +++ b/third_party/boringssl/src/include/openssl/bio.h @@ -15,7 +15,7 @@ #ifndef OPENSSL_HEADER_BIO_H #define OPENSSL_HEADER_BIO_H -#include // IWYU pragma: export +#include // IWYU pragma: export #include // For FILE @@ -65,6 +65,10 @@ OPENSSL_EXPORT void BIO_vfree(BIO *bio); // BIO_up_ref increments the reference count of `bio` and returns one. OPENSSL_EXPORT int BIO_up_ref(BIO *bio); +// BIO_dup_ref increments the reference count of `bio` and returns the same +// handle. +OPENSSL_EXPORT BIO *BIO_dup_ref(const BIO *bio); + // Basic I/O. @@ -613,18 +617,20 @@ OPENSSL_EXPORT int BIO_do_connect(BIO *bio); #define BIO_CTRL_DGRAM_QUERY_MTU 40 // as kernel for current MTU -#define BIO_CTRL_DGRAM_SET_MTU 42 /* set cached value for MTU. want to use - this if asking the kernel fails */ +#define BIO_CTRL_DGRAM_SET_MTU \ + 42 /* set cached value for MTU. want to use \ + this if asking the kernel fails */ -#define BIO_CTRL_DGRAM_MTU_EXCEEDED 43 /* check whether the MTU was exceed in - the previous write operation. */ +#define BIO_CTRL_DGRAM_MTU_EXCEEDED \ + 43 /* check whether the MTU was exceed in \ + the previous write operation. */ // BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT is unsupported as it is unused by consumers // and depends on `timeval`, which is not 2038-clean on all platforms. -#define BIO_CTRL_DGRAM_GET_PEER 46 +#define BIO_CTRL_DGRAM_GET_PEER 46 -#define BIO_CTRL_DGRAM_GET_FALLBACK_MTU 47 +#define BIO_CTRL_DGRAM_GET_FALLBACK_MTU 47 // BIO Pairs. @@ -1031,7 +1037,7 @@ extern "C++" { BSSL_NAMESPACE_BEGIN BORINGSSL_MAKE_DELETER(BIO, BIO_free) -BORINGSSL_MAKE_UP_REF(BIO, BIO_up_ref) +BORINGSSL_MAKE_UP_REF(BIO, BIO_dup_ref) BORINGSSL_MAKE_DELETER(BIO_METHOD, BIO_meth_free) BSSL_NAMESPACE_END diff --git a/third_party/boringssl/src/include/openssl/bytestring.h b/third_party/boringssl/src/include/openssl/bytestring.h index d1d607c..3a49beb 100644 --- a/third_party/boringssl/src/include/openssl/bytestring.h +++ b/third_party/boringssl/src/include/openssl/bytestring.h @@ -238,6 +238,7 @@ OPENSSL_EXPORT int CBS_get_u64_decimal(CBS *cbs, uint64_t *out); #define CBS_ASN1_OBJECT 0x6u #define CBS_ASN1_ENUMERATED 0xau #define CBS_ASN1_UTF8STRING 0xcu +#define CBS_ASN1_RELATIVE_OID 0xdu #define CBS_ASN1_SEQUENCE (0x10u | CBS_ASN1_CONSTRUCTED) #define CBS_ASN1_SET (0x11u | CBS_ASN1_CONSTRUCTED) #define CBS_ASN1_NUMERICSTRING 0x12u diff --git a/third_party/boringssl/src/include/openssl/cms.h b/third_party/boringssl/src/include/openssl/cms.h index d365a46..5a44517 100644 --- a/third_party/boringssl/src/include/openssl/cms.h +++ b/third_party/boringssl/src/include/openssl/cms.h @@ -15,7 +15,7 @@ #ifndef OPENSSL_HEADER_CMS_H #define OPENSSL_HEADER_CMS_H -#include // IWYU pragma: export +#include // IWYU pragma: export #include @@ -69,8 +69,9 @@ DECLARE_STACK_OF(X509) // incomplete. `data` will then be ignored and should be NULL. The caller can // then continue configuring it and finalizing it with `CMS_final`. Otherwise, // the object will be finalized with `data` and `flags` passed to `CMS_final`. -OPENSSL_EXPORT CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, - STACK_OF(X509) *certs, BIO *data, +OPENSSL_EXPORT CMS_ContentInfo *CMS_sign(const X509 *signcert, + const EVP_PKEY *pkey, + const STACK_OF(X509) *certs, BIO *data, uint32_t flags); // CMS_ContentInfo_free releases memory associated with `cms`. @@ -102,7 +103,8 @@ OPENSSL_EXPORT void CMS_ContentInfo_free(CMS_ContentInfo *cms); // Subsequent calls will fail. Additionally, only RSA keys are currently // supported for `pkey`. OPENSSL_EXPORT CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms, - X509 *signcert, EVP_PKEY *pkey, + const X509 *signcert, + const EVP_PKEY *pkey, const EVP_MD *md, uint32_t flags); diff --git a/third_party/boringssl/src/include/openssl/curve25519.h b/third_party/boringssl/src/include/openssl/curve25519.h index f7ee156..1eac821 100644 --- a/third_party/boringssl/src/include/openssl/curve25519.h +++ b/third_party/boringssl/src/include/openssl/curve25519.h @@ -15,7 +15,8 @@ #ifndef OPENSSL_HEADER_CURVE25519_H #define OPENSSL_HEADER_CURVE25519_H -#include // IWYU pragma: export +#include // IWYU pragma: export +#include #if defined(__cplusplus) extern "C" { @@ -163,10 +164,11 @@ enum spake2_role_t { // bound into the protocol. For example MAC addresses, hostnames, usernames // etc. These values are not exposed and can avoid context-confusion attacks // when a password is shared between several devices. -OPENSSL_EXPORT 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); +OPENSSL_EXPORT 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_free frees `ctx` and all the resources that it has allocated. OPENSSL_EXPORT void SPAKE2_CTX_free(SPAKE2_CTX *ctx); @@ -219,6 +221,75 @@ OPENSSL_EXPORT int SPAKE2_process_msg(SPAKE2_CTX *ctx, uint8_t *out_key, size_t their_msg_len); +// CPace. +// +// See https://datatracker.ietf.org/doc/draft-irtf-cfrg-cpace/ + +// The role that a party plays in the CPACE key agreement protocol. +enum cpace_role_t { + // This role corresponds to the party A in the specification. + cpace_role_initiator, + // This role corresponds to the party B in the specification. + cpace_role_responder, +}; + +// CPACE_CTX_new returns a newly-allocated `CPACE_CTX` object that implements +// one side of the CPace protocol, or nullptr on error. This function implements +// CPACE-X25519-SHA512 in initiator-responder mode, acting as `role` and with +// `password` as the password-related string (PRS). +// +// `channel_id` and `session_id` are the channel identifier (CI) and session +// identifier (sid) values, respectively. Both values must match for the +// exchange to proceed. `assoc_data` is the cleartext associated data (ADa or +// ADb) to be sent to the peer. These values may be empty if not used. See +// Section 4.1 of draft-irtf-cfrg-cpace-21 for details. +// +// The application-level identities of each party in the protocol should be +// incorporated into either `channel_id` or each party's respective `assoc_data` +// values. See Section 10.1 of draft-irtf-cfrg-cpace-21. +// +// Once a `CPACE_CTX` is successfully created, the caller should call +// `CPACE_generate_msg` to generate the message to send to the peer. +OPENSSL_EXPORT CPACE_CTX *CPACE_CTX_new( + enum cpace_role_t role, const uint8_t *password, size_t password_len, + const uint8_t *channel_id, size_t channel_id_len, const uint8_t *assoc_data, + size_t assoc_data_len, const uint8_t *session_id, size_t session_id_len); + +// CPACE_CTX_free frees `ctx` and all the resources that it has allocated. +OPENSSL_EXPORT void CPACE_CTX_free(CPACE_CTX *ctx); + +#define CPACE_MSG_LEN 32 +#define CPACE_SHARED_SECRET_LEN 64 + +// CPACE_generate_msg generates the message to be sent to the peer. On success, +// it writes the message to `out_msg` and returns one. Otherwise, it returns +// zero. `ctx` must have been allocated by `CPACE_CTX_new`, with no subsequent +// functions called on it. +// +// `out_msg` only contains the Ya or Yb value. It does not include ADa or ADb. +// On success, the caller should separately send `out_msg` and their +// `assoc_data` value to the peer. It is the caller's responsibility to send +// `assoc_data` together with `out_msg`. After receiving the peer's reply, the +// caller should call `CPACE_process_msg` to complete the protocol. +OPENSSL_EXPORT int CPACE_generate_msg(CPACE_CTX *ctx, + uint8_t out_msg[CPACE_MSG_LEN]); + +// CPACE_process_msg processes `msg` and `peer_assoc_data` from the peer and +// computes the shared secret, or intermediate session key (ISK). On success, it +// writes the secret to `out_shared_secret` and returns one; it also writes a +// derived session ID if `out_sid` is not NULL. Otherwise, it returns zero. +// `ctx` must have successfully been passed to `CPACE_generate_msg`, with no +// subsequent functions called on it. +// +// `msg` should contain the peer's Ya or Yb value, and `peer_assoc_data` the +// peer's ADa or ADb value. +OPENSSL_EXPORT int CPACE_process_msg( + CPACE_CTX *ctx, const uint8_t in_msg[CPACE_MSG_LEN], + const uint8_t *peer_assoc_data, size_t peer_assoc_data_len, + uint8_t shared_secret[CPACE_SHARED_SECRET_LEN], + uint8_t sid_out[SHA512_DIGEST_LENGTH]); + + #if defined(__cplusplus) } // extern C @@ -226,6 +297,7 @@ extern "C++" { BSSL_NAMESPACE_BEGIN +BORINGSSL_MAKE_DELETER(CPACE_CTX, CPACE_CTX_free) BORINGSSL_MAKE_DELETER(SPAKE2_CTX, SPAKE2_CTX_free) BSSL_NAMESPACE_END diff --git a/third_party/boringssl/src/include/openssl/dh.h b/third_party/boringssl/src/include/openssl/dh.h index 59e8c9c..6cb5d9e 100644 --- a/third_party/boringssl/src/include/openssl/dh.h +++ b/third_party/boringssl/src/include/openssl/dh.h @@ -15,7 +15,7 @@ #ifndef OPENSSL_HEADER_DH_H #define OPENSSL_HEADER_DH_H -#include // IWYU pragma: export +#include // IWYU pragma: export #if defined(__cplusplus) extern "C" { @@ -49,6 +49,11 @@ OPENSSL_EXPORT void DH_free(DH *dh); // mutate `dh` for thread-safety purposes and may be used concurrently. OPENSSL_EXPORT int DH_up_ref(DH *dh); +// DH_dup_ref increments the reference count of `dh` and returns the same +// handle. It does not mutate `dh` for thread-safety purposes and may be used +// concurrently. +OPENSSL_EXPORT DH *DH_dup_ref(const DH *dh); + // Properties. @@ -317,7 +322,7 @@ extern "C++" { BSSL_NAMESPACE_BEGIN BORINGSSL_MAKE_DELETER(DH, DH_free) -BORINGSSL_MAKE_UP_REF(DH, DH_up_ref) +BORINGSSL_MAKE_UP_REF(DH, DH_dup_ref) BSSL_NAMESPACE_END diff --git a/third_party/boringssl/src/include/openssl/digest.h b/third_party/boringssl/src/include/openssl/digest.h index 8a81bc1..73270de 100644 --- a/third_party/boringssl/src/include/openssl/digest.h +++ b/third_party/boringssl/src/include/openssl/digest.h @@ -44,6 +44,16 @@ OPENSSL_EXPORT const EVP_MD *EVP_sha512(void); OPENSSL_EXPORT const EVP_MD *EVP_sha512_256(void); OPENSSL_EXPORT const EVP_MD *EVP_blake2b256(void); +// SHA-3 family of digest functions. +// +// WARNING: Prefer to use SHA-2 (e.g. `EVP_sha256`) over SHA-3. Despite being a +// newer hash function, SHA-3 performs poorly and should only be used when +// necessary for interoperability with existing systems. + +OPENSSL_EXPORT const EVP_MD *EVP_sha3_256(void); +OPENSSL_EXPORT const EVP_MD *EVP_sha3_384(void); +OPENSSL_EXPORT const EVP_MD *EVP_sha3_512(void); + // EVP_md5_sha1 is a TLS-specific `EVP_MD` which computes the concatenation of // MD5 and SHA-1, as used in TLS 1.1 and below. OPENSSL_EXPORT const EVP_MD *EVP_md5_sha1(void); @@ -127,7 +137,7 @@ OPENSSL_EXPORT int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, // EVP_MAX_MD_BLOCK_SIZE is the largest digest block size supported, in // bytes. -#define EVP_MAX_MD_BLOCK_SIZE 128 // SHA-512 is the longest so far. +#define EVP_MAX_MD_BLOCK_SIZE 136 // SHA3-256 is the longest so far. // EVP_DigestFinal_ex finishes the digest in `ctx` and writes the output to // `md_out`. `EVP_MD_CTX_size` bytes are written, which is at most @@ -344,9 +354,9 @@ OPENSSL_EXPORT int EVP_Q_digest(OSSL_LIB_CTX *libctx, const char *name, struct evp_md_pctx_ops; // EVP_MAX_MD_DATA_SIZE is a private constant which specifies the size of the -// largest digest state. SHA-512 and BLAKE2b are joint-largest. Consuming code -// only uses this via the `EVP_MD_CTX` type. -#define EVP_MAX_MD_DATA_SIZE 208 +// largest digest state. SHA3-256 is the largest. Consuming code only uses this +// via the `EVP_MD_CTX` type. +#define EVP_MAX_MD_DATA_SIZE 240 // env_md_ctx_st is typoed ("evp" -> "env"), but the typo comes from OpenSSL // and some consumers forward-declare these structures so we're leaving it diff --git a/third_party/boringssl/src/include/openssl/dsa.h b/third_party/boringssl/src/include/openssl/dsa.h index fff5b76..a77bf91 100644 --- a/third_party/boringssl/src/include/openssl/dsa.h +++ b/third_party/boringssl/src/include/openssl/dsa.h @@ -15,7 +15,7 @@ #ifndef OPENSSL_HEADER_DSA_H #define OPENSSL_HEADER_DSA_H -#include // IWYU pragma: export +#include // IWYU pragma: export #include @@ -51,6 +51,11 @@ OPENSSL_EXPORT void DSA_free(DSA *dsa); // not mutate `dsa` for thread-safety purposes and may be used concurrently. OPENSSL_EXPORT int DSA_up_ref(DSA *dsa); +// DSA_dup_ref increments the reference count of `dsa` and returns the same +// handle. It does not mutate `dsa` for thread-safety purposes and may be used +// concurrently. +OPENSSL_EXPORT DSA *DSA_dup_ref(const DSA *dsa); + // Properties. @@ -370,7 +375,7 @@ extern "C++" { BSSL_NAMESPACE_BEGIN BORINGSSL_MAKE_DELETER(DSA, DSA_free) -BORINGSSL_MAKE_UP_REF(DSA, DSA_up_ref) +BORINGSSL_MAKE_UP_REF(DSA, DSA_dup_ref) BORINGSSL_MAKE_DELETER(DSA_SIG, DSA_SIG_free) BSSL_NAMESPACE_END diff --git a/third_party/boringssl/src/include/openssl/ec_key.h b/third_party/boringssl/src/include/openssl/ec_key.h index 1480520..296b7c0 100644 --- a/third_party/boringssl/src/include/openssl/ec_key.h +++ b/third_party/boringssl/src/include/openssl/ec_key.h @@ -60,6 +60,11 @@ OPENSSL_EXPORT EC_KEY *EC_KEY_dup(const EC_KEY *src); // not mutate `key` for thread-safety purposes and may be used concurrently. OPENSSL_EXPORT int EC_KEY_up_ref(EC_KEY *key); +// EC_KEY_dup_ref increases the reference count of `key` and returns the same +// handle. It does not mutate `key` for thread-safety purposes and may be used +// concurrently. +OPENSSL_EXPORT EC_KEY *EC_KEY_dup_ref(const EC_KEY *key); + // EC_KEY_is_opaque returns one if `key` is opaque and doesn't expose its key // material. Otherwise it return zero. OPENSSL_EXPORT int EC_KEY_is_opaque(const EC_KEY *key); @@ -347,7 +352,7 @@ extern "C++" { BSSL_NAMESPACE_BEGIN BORINGSSL_MAKE_DELETER(EC_KEY, EC_KEY_free) -BORINGSSL_MAKE_UP_REF(EC_KEY, EC_KEY_up_ref) +BORINGSSL_MAKE_UP_REF(EC_KEY, EC_KEY_dup_ref) BSSL_NAMESPACE_END diff --git a/third_party/boringssl/src/include/openssl/evp.h b/third_party/boringssl/src/include/openssl/evp.h index 8a767ca..4af1726 100644 --- a/third_party/boringssl/src/include/openssl/evp.h +++ b/third_party/boringssl/src/include/openssl/evp.h @@ -498,13 +498,10 @@ OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_generate_from_alg(const EVP_PKEY_ALG *alg); // Ed25519, `type` should be NULL. The `EVP_MD_CTX` itself is unused but is // present so the API is uniform. See `EVP_DigestSign`. // -// This function does not mutate `pkey` for thread-safety purposes and may be -// used concurrently with other non-mutating functions on `pkey`. -// // It returns one on success, or zero on error. OPENSSL_EXPORT int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, ENGINE *e, - EVP_PKEY *pkey); + const EVP_PKEY *pkey); // EVP_DigestSignUpdate appends `len` bytes from `data` to the data which will // be signed in `EVP_DigestSignFinal`. It returns one. @@ -554,13 +551,10 @@ OPENSSL_EXPORT int EVP_DigestSign(EVP_MD_CTX *ctx, uint8_t *out_sig, // Ed25519, `type` should be NULL. The `EVP_MD_CTX` itself is unused but is // present so the API is uniform. See `EVP_DigestVerify`. // -// This function does not mutate `pkey` for thread-safety purposes and may be -// used concurrently with other non-mutating functions on `pkey`. -// // It returns one on success, or zero on error. OPENSSL_EXPORT int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, ENGINE *e, - EVP_PKEY *pkey); + const EVP_PKEY *pkey); // EVP_DigestVerifyUpdate appends `len` bytes from `data` to the data which // will be verified by `EVP_DigestVerifyFinal`. It returns one. @@ -615,13 +609,9 @@ OPENSSL_EXPORT int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *data, // actual size of the signature is written to `*out_sig_len`. // // It returns one on success and zero otherwise. -// -// It does not modify `ctx`, thus it's possible to continue to use `ctx` in -// order to sign a longer message. It also does not mutate `pkey` for -// thread-safety purposes and may be used concurrently with other non-mutating -// functions on `pkey`. OPENSSL_EXPORT int EVP_SignFinal(const EVP_MD_CTX *ctx, uint8_t *sig, - unsigned int *out_sig_len, EVP_PKEY *pkey); + unsigned int *out_sig_len, + const EVP_PKEY *pkey); // Verifying (old functions) @@ -650,13 +640,8 @@ OPENSSL_EXPORT int EVP_VerifyUpdate(EVP_MD_CTX *ctx, const void *data, // calls to `EVP_VerifyUpdate`. // // It returns one on success and zero otherwise. -// -// It does not modify `ctx`, thus it's possible to continue to use `ctx` in -// order to verify a longer message. It also does not mutate `pkey` for -// thread-safety purposes and may be used concurrently with other non-mutating -// functions on `pkey`. OPENSSL_EXPORT int EVP_VerifyFinal(EVP_MD_CTX *ctx, const uint8_t *sig, - size_t sig_len, EVP_PKEY *pkey); + size_t sig_len, const EVP_PKEY *pkey); // Printing @@ -752,7 +737,7 @@ OPENSSL_EXPORT int EVP_PBE_scrypt(const char *password, size_t password_len, // EVP_PKEY_CTX_new allocates a fresh `EVP_PKEY_CTX` for use with `pkey`. It // returns the context or NULL on error. -OPENSSL_EXPORT EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e); +OPENSSL_EXPORT EVP_PKEY_CTX *EVP_PKEY_CTX_new(const EVP_PKEY *pkey, ENGINE *e); // EVP_PKEY_CTX_new_id allocates a fresh `EVP_PKEY_CTX` for a key of type `id` // (e.g. `EVP_PKEY_HMAC`). This can be used for key generation where @@ -770,7 +755,7 @@ OPENSSL_EXPORT void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx); OPENSSL_EXPORT EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *ctx); // EVP_PKEY_CTX_get0_pkey returns the `EVP_PKEY` associated with `ctx`. -OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_CTX_get0_pkey(EVP_PKEY_CTX *ctx); +OPENSSL_EXPORT EVP_PKEY *EVP_PKEY_CTX_get0_pkey(const EVP_PKEY_CTX *ctx); // EVP_PKEY_sign_init initialises an `EVP_PKEY_CTX` for a signing operation. It // should be called before `EVP_PKEY_sign`. @@ -897,7 +882,8 @@ OPENSSL_EXPORT int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx); // by `ctx` to `peer`. It should be called after `EVP_PKEY_derive_init`. (For // example, this is used to set the peer's key in (EC)DH.) It returns one on // success and zero on error. -OPENSSL_EXPORT int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer); +OPENSSL_EXPORT int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, + const EVP_PKEY *peer); // EVP_PKEY_derive derives a shared key from `ctx`. If `key` is non-NULL then, // on entry, `out_key_len` must contain the amount of space at `key`. If @@ -1633,7 +1619,7 @@ extern "C++" { BSSL_NAMESPACE_BEGIN BORINGSSL_MAKE_DELETER(EVP_PKEY, EVP_PKEY_free) -BORINGSSL_MAKE_UP_REF(EVP_PKEY, EVP_PKEY_up_ref) +BORINGSSL_MAKE_UP_REF(EVP_PKEY, EVP_PKEY_dup_ref) BORINGSSL_MAKE_DELETER(EVP_PKEY_CTX, EVP_PKEY_CTX_free) BSSL_NAMESPACE_END diff --git a/third_party/boringssl/src/include/openssl/hpke.h b/third_party/boringssl/src/include/openssl/hpke.h index 9e1a77e..a9e4a17 100644 --- a/third_party/boringssl/src/include/openssl/hpke.h +++ b/third_party/boringssl/src/include/openssl/hpke.h @@ -83,6 +83,10 @@ OPENSSL_EXPORT size_t EVP_HPKE_KEM_private_key_len(const EVP_HPKE_KEM *kem); // secret, for `kem`. This value will be at most `EVP_HPKE_MAX_ENC_LENGTH`. OPENSSL_EXPORT size_t EVP_HPKE_KEM_enc_len(const EVP_HPKE_KEM *kem); +// EVP_HPKE_KEM_shared_secret_len returns the length of the shared secret +// produced by `kem`. +OPENSSL_EXPORT size_t EVP_HPKE_KEM_shared_secret_len(const EVP_HPKE_KEM *kem); + // The following constants are KDF identifiers. #define EVP_HPKE_HKDF_SHA256 0x0001 #define EVP_HPKE_HKDF_SHA384 0x0002 @@ -271,6 +275,25 @@ OPENSSL_EXPORT int EVP_HPKE_CTX_setup_recipient( const EVP_HPKE_AEAD *aead, const uint8_t *enc, size_t enc_len, const uint8_t *info, size_t info_len); +// EVP_HPKE_CTX_setup_recipient_with_shared_secret behaves like +// `EVP_HPKE_CTX_setup_recipient`, but takes the shared secret explicitly. +// +// WARNING: `shared_secret` must be the result of decapsulating the sender's +// `enc` value with the recipient's private key. Using the wrong shared secret +// will result in an `EVP_HPKE_CTX` that cannot decrypt the sender's messages. +// Additionally, an attacker with knowledge of `shared_secret` will be able to +// decrypt and forge encrypted messages. +// +// It returns one on success and zero on error. +// +// On success, callers may call `EVP_HPKE_CTX_open` to decrypt messages from the +// sender. Callers must then call `EVP_HPKE_CTX_cleanup` when done. On failure, +// calling `EVP_HPKE_CTX_cleanup` is safe, but not required. +OPENSSL_EXPORT int EVP_HPKE_CTX_setup_recipient_with_shared_secret( + EVP_HPKE_CTX *ctx, const EVP_HPKE_KEM *kem, const EVP_HPKE_KDF *kdf, + const EVP_HPKE_AEAD *aead, const uint8_t *shared_secret, + size_t shared_secret_len, const uint8_t *info, size_t info_len); + // EVP_HPKE_CTX_setup_auth_sender implements the SetupAuthS HPKE operation. It // behaves like `EVP_HPKE_CTX_setup_sender` but authenticates the resulting // context with `key`. diff --git a/third_party/boringssl/src/include/openssl/nid.h b/third_party/boringssl/src/include/openssl/nid.h index 9ca8e67..38e5dc8 100644 --- a/third_party/boringssl/src/include/openssl/nid.h +++ b/third_party/boringssl/src/include/openssl/nid.h @@ -5511,48 +5511,47 @@ extern "C" { #define SN_X_Wing "X-Wing" #define NID_X_Wing 972 -#define SN_alg_mtcProof_draft "alg-mtcProof-draft" -#define NID_alg_mtcProof_draft 976 -#define OBJ_alg_mtcProof_draft 1L, 3L, 6L, 1L, 4L, 1L, 44363L, 47L, 0L -#define OBJ_ENC_alg_mtcProof_draft \ - 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xda, 0x4b, 0x2f, 0x00 - -#define SN_rdna_trustAnchorID_draft "rdna-trustAnchorID-draft" -#define NID_rdna_trustAnchorID_draft 977 -#define OBJ_rdna_trustAnchorID_draft 1L, 3L, 6L, 1L, 4L, 1L, 44363L, 47L, 1L -#define OBJ_ENC_rdna_trustAnchorID_draft \ - 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xda, 0x4b, 0x2f, 0x01 - -#define SN_pe_mtcCertificationAuthority_draft \ - "pe-mtcCertificationAuthority-draft" -#define NID_pe_mtcCertificationAuthority_draft 978 -#define OBJ_pe_mtcCertificationAuthority_draft \ - 1L, 3L, 6L, 1L, 4L, 1L, 44363L, 47L, 2L -#define OBJ_ENC_pe_mtcCertificationAuthority_draft \ - 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xda, 0x4b, 0x2f, 0x02 - #define SN_SLH_DSA_SHA2_128s "id-slh-dsa-sha2-128s" #define LN_SLH_DSA_SHA2_128s "SLH-DSA-SHA2-128s" -#define NID_SLH_DSA_SHA2_128s 979 +#define NID_SLH_DSA_SHA2_128s 973 #define OBJ_SLH_DSA_SHA2_128s 2L, 16L, 840L, 1L, 101L, 3L, 4L, 3L, 20L #define OBJ_ENC_SLH_DSA_SHA2_128s \ 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x14 #define SN_SLH_DSA_SHAKE_256f "id-slh-dsa-shake-256f" #define LN_SLH_DSA_SHAKE_256f "SLH-DSA-SHAKE-256f" -#define NID_SLH_DSA_SHAKE_256f 980 +#define NID_SLH_DSA_SHAKE_256f 974 #define OBJ_SLH_DSA_SHAKE_256f 2L, 16L, 840L, 1L, 101L, 3L, 4L, 3L, 31L #define OBJ_ENC_SLH_DSA_SHAKE_256f \ 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x1f #define SN_SLH_DSA_SHA2_128s_WITH_SHA256 "id-hash-slh-dsa-sha2-128s-with-sha256" #define LN_SLH_DSA_SHA2_128s_WITH_SHA256 "SLH-DSA-SHA2-128s-WITH-SHA256" -#define NID_SLH_DSA_SHA2_128s_WITH_SHA256 981 +#define NID_SLH_DSA_SHA2_128s_WITH_SHA256 975 #define OBJ_SLH_DSA_SHA2_128s_WITH_SHA256 \ 2L, 16L, 840L, 1L, 101L, 3L, 4L, 3L, 35L #define OBJ_ENC_SLH_DSA_SHA2_128s_WITH_SHA256 \ 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03, 0x23 +#define SN_alg_mtcProof "alg-mtcProof" +#define NID_alg_mtcProof 976 +#define OBJ_alg_mtcProof 1L, 3L, 6L, 1L, 5L, 5L, 7L, 6L, 67L +#define OBJ_ENC_alg_mtcProof 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x06, 0x43 + +#define SN_rdna_trustAnchorID "rdna-trustAnchorID" +#define NID_rdna_trustAnchorID 977 +#define OBJ_rdna_trustAnchorID 1L, 3L, 6L, 1L, 5L, 5L, 7L, 25L, 3L +#define OBJ_ENC_rdna_trustAnchorID \ + 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x19, 0x03 + +#define SN_pe_mtcCertificationAuthority_SHA256 \ + "pe-mtcCertificationAuthority-SHA256" +#define NID_pe_mtcCertificationAuthority_SHA256 978 +#define OBJ_pe_mtcCertificationAuthority_SHA256 \ + 1L, 3L, 6L, 1L, 5L, 5L, 7L, 1L, 38L +#define OBJ_ENC_pe_mtcCertificationAuthority_SHA256 \ + 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x01, 0x26 + #if defined(__cplusplus) } /* extern C */ diff --git a/third_party/boringssl/src/include/openssl/pkcs7.h b/third_party/boringssl/src/include/openssl/pkcs7.h index 85c851e..b8f5b2b 100644 --- a/third_party/boringssl/src/include/openssl/pkcs7.h +++ b/third_party/boringssl/src/include/openssl/pkcs7.h @@ -15,7 +15,7 @@ #ifndef OPENSSL_HEADER_PKCS7_H #define OPENSSL_HEADER_PKCS7_H -#include // IWYU pragma: export +#include // IWYU pragma: export #include @@ -59,8 +59,8 @@ OPENSSL_EXPORT int PKCS7_bundle_raw_certificates( // PKCS7_bundle_certificates behaves like `PKCS7_bundle_raw_certificates` but // takes `X509` objects as input. -OPENSSL_EXPORT int PKCS7_bundle_certificates( - CBB *out, const STACK_OF(X509) *certs); +OPENSSL_EXPORT int PKCS7_bundle_certificates(CBB *out, + const STACK_OF(X509) *certs); // PKCS7_get_CRLs parses a PKCS#7, SignedData structure from `cbs` and appends // the included CRLs to `out_crls`. It returns one on success and zero on error. @@ -144,8 +144,7 @@ typedef struct { // d2i_PKCS7 parses a BER-encoded, PKCS#7 signed data ContentInfo structure from // `len` bytes at `*inp`, as described in `d2i_SAMPLE`. -OPENSSL_EXPORT PKCS7 *d2i_PKCS7(PKCS7 **out, const uint8_t **inp, - size_t len); +OPENSSL_EXPORT PKCS7 *d2i_PKCS7(PKCS7 **out, const uint8_t **inp, size_t len); // d2i_PKCS7_bio behaves like `d2i_PKCS7` but reads the input from `bio`. If // the length of the object is indefinite the full contents of `bio` are read. @@ -215,7 +214,7 @@ OPENSSL_EXPORT int PKCS7_type_is_signedAndEnveloped(const PKCS7 *p7); // // Note this function only implements a subset of the corresponding OpenSSL // function. It is provided for backwards compatibility only. -OPENSSL_EXPORT PKCS7 *PKCS7_sign(X509 *sign_cert, EVP_PKEY *pkey, +OPENSSL_EXPORT PKCS7 *PKCS7_sign(X509 *sign_cert, const EVP_PKEY *pkey, STACK_OF(X509) *certs, BIO *data, int flags); diff --git a/third_party/boringssl/src/include/openssl/pool.h b/third_party/boringssl/src/include/openssl/pool.h index 23f8c44..2c3855b 100644 --- a/third_party/boringssl/src/include/openssl/pool.h +++ b/third_party/boringssl/src/include/openssl/pool.h @@ -59,6 +59,12 @@ OPENSSL_EXPORT void CRYPTO_BUFFER_POOL_free(CRYPTO_BUFFER_POOL *pool); // used concurrently. OPENSSL_EXPORT int CRYPTO_BUFFER_POOL_up_ref(CRYPTO_BUFFER_POOL *pool); +// CRYPTO_BUFFER_POOL_dup_ref increments the reference count of `pool` and +// returns the same handle. It does not mutate `pool` for thread-safety purposes +// and may be used concurrently. +OPENSSL_EXPORT CRYPTO_BUFFER_POOL *CRYPTO_BUFFER_POOL_dup_ref( + const CRYPTO_BUFFER_POOL *pool); + // CRYPTO_BUFFER_new returns a `CRYPTO_BUFFER` containing a copy of `data`, or // else NULL on error. If `pool` is not NULL then the returned value may be a // reference to a previously existing `CRYPTO_BUFFER` that contained the same @@ -124,9 +130,9 @@ extern "C++" { BSSL_NAMESPACE_BEGIN BORINGSSL_MAKE_DELETER(CRYPTO_BUFFER_POOL, CRYPTO_BUFFER_POOL_free) -BORINGSSL_MAKE_UP_REF(CRYPTO_BUFFER_POOL, CRYPTO_BUFFER_POOL_up_ref) +BORINGSSL_MAKE_UP_REF(CRYPTO_BUFFER_POOL, CRYPTO_BUFFER_POOL_dup_ref) BORINGSSL_MAKE_DELETER(CRYPTO_BUFFER, CRYPTO_BUFFER_free) -BORINGSSL_MAKE_UP_REF(CRYPTO_BUFFER, CRYPTO_BUFFER_up_ref) +BORINGSSL_MAKE_UP_REF(CRYPTO_BUFFER, CRYPTO_BUFFER_dup_ref) BSSL_NAMESPACE_END diff --git a/third_party/boringssl/src/include/openssl/prefix_symbols.h b/third_party/boringssl/src/include/openssl/prefix_symbols.h index a328dfc..47df60c 100644 --- a/third_party/boringssl/src/include/openssl/prefix_symbols.h +++ b/third_party/boringssl/src/include/openssl/prefix_symbols.h @@ -130,6 +130,7 @@ #pragma redefine_extname ASN1_STRING_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(ASN1_STRING_free) #pragma redefine_extname ASN1_STRING_get0_data BORINGSSL_ADD_USER_LABEL_AND_PREFIX(ASN1_STRING_get0_data) #pragma redefine_extname ASN1_STRING_get_default_mask BORINGSSL_ADD_USER_LABEL_AND_PREFIX(ASN1_STRING_get_default_mask) +#pragma redefine_extname ASN1_STRING_get_length BORINGSSL_ADD_USER_LABEL_AND_PREFIX(ASN1_STRING_get_length) #pragma redefine_extname ASN1_STRING_length BORINGSSL_ADD_USER_LABEL_AND_PREFIX(ASN1_STRING_length) #pragma redefine_extname ASN1_STRING_new BORINGSSL_ADD_USER_LABEL_AND_PREFIX(ASN1_STRING_new) #pragma redefine_extname ASN1_STRING_print BORINGSSL_ADD_USER_LABEL_AND_PREFIX(ASN1_STRING_print) @@ -232,6 +233,7 @@ #pragma redefine_extname BIO_ctrl_get_write_guarantee BORINGSSL_ADD_USER_LABEL_AND_PREFIX(BIO_ctrl_get_write_guarantee) #pragma redefine_extname BIO_ctrl_pending BORINGSSL_ADD_USER_LABEL_AND_PREFIX(BIO_ctrl_pending) #pragma redefine_extname BIO_do_connect BORINGSSL_ADD_USER_LABEL_AND_PREFIX(BIO_do_connect) +#pragma redefine_extname BIO_dup_ref BORINGSSL_ADD_USER_LABEL_AND_PREFIX(BIO_dup_ref) #pragma redefine_extname BIO_eof BORINGSSL_ADD_USER_LABEL_AND_PREFIX(BIO_eof) #pragma redefine_extname BIO_f_base64 BORINGSSL_ADD_USER_LABEL_AND_PREFIX(BIO_f_base64) #pragma redefine_extname BIO_f_ssl BORINGSSL_ADD_USER_LABEL_AND_PREFIX(BIO_f_ssl) @@ -615,9 +617,14 @@ #pragma redefine_extname CONF_modules_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CONF_modules_free) #pragma redefine_extname CONF_modules_load_file BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CONF_modules_load_file) #pragma redefine_extname CONF_modules_unload BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CONF_modules_unload) +#pragma redefine_extname CPACE_CTX_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CPACE_CTX_free) +#pragma redefine_extname CPACE_CTX_new BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CPACE_CTX_new) +#pragma redefine_extname CPACE_generate_msg BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CPACE_generate_msg) +#pragma redefine_extname CPACE_process_msg BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CPACE_process_msg) #pragma redefine_extname CRL_DIST_POINTS_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CRL_DIST_POINTS_free) #pragma redefine_extname CRL_DIST_POINTS_it BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CRL_DIST_POINTS_it) #pragma redefine_extname CRL_DIST_POINTS_new BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CRL_DIST_POINTS_new) +#pragma redefine_extname CRYPTO_BUFFER_POOL_dup_ref BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CRYPTO_BUFFER_POOL_dup_ref) #pragma redefine_extname CRYPTO_BUFFER_POOL_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CRYPTO_BUFFER_POOL_free) #pragma redefine_extname CRYPTO_BUFFER_POOL_new BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CRYPTO_BUFFER_POOL_new) #pragma redefine_extname CRYPTO_BUFFER_POOL_up_ref BORINGSSL_ADD_USER_LABEL_AND_PREFIX(CRYPTO_BUFFER_POOL_up_ref) @@ -692,6 +699,7 @@ #pragma redefine_extname DH_compute_key BORINGSSL_ADD_USER_LABEL_AND_PREFIX(DH_compute_key) #pragma redefine_extname DH_compute_key_hashed BORINGSSL_ADD_USER_LABEL_AND_PREFIX(DH_compute_key_hashed) #pragma redefine_extname DH_compute_key_padded BORINGSSL_ADD_USER_LABEL_AND_PREFIX(DH_compute_key_padded) +#pragma redefine_extname DH_dup_ref BORINGSSL_ADD_USER_LABEL_AND_PREFIX(DH_dup_ref) #pragma redefine_extname DH_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(DH_free) #pragma redefine_extname DH_generate_key BORINGSSL_ADD_USER_LABEL_AND_PREFIX(DH_generate_key) #pragma redefine_extname DH_generate_parameters BORINGSSL_ADD_USER_LABEL_AND_PREFIX(DH_generate_parameters) @@ -733,6 +741,7 @@ #pragma redefine_extname DSA_do_sign BORINGSSL_ADD_USER_LABEL_AND_PREFIX(DSA_do_sign) #pragma redefine_extname DSA_do_verify BORINGSSL_ADD_USER_LABEL_AND_PREFIX(DSA_do_verify) #pragma redefine_extname DSA_dup_DH BORINGSSL_ADD_USER_LABEL_AND_PREFIX(DSA_dup_DH) +#pragma redefine_extname DSA_dup_ref BORINGSSL_ADD_USER_LABEL_AND_PREFIX(DSA_dup_ref) #pragma redefine_extname DSA_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(DSA_free) #pragma redefine_extname DSA_generate_key BORINGSSL_ADD_USER_LABEL_AND_PREFIX(DSA_generate_key) #pragma redefine_extname DSA_generate_parameters BORINGSSL_ADD_USER_LABEL_AND_PREFIX(DSA_generate_parameters) @@ -818,6 +827,7 @@ #pragma redefine_extname EC_KEY_check_key BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EC_KEY_check_key) #pragma redefine_extname EC_KEY_derive_from_secret BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EC_KEY_derive_from_secret) #pragma redefine_extname EC_KEY_dup BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EC_KEY_dup) +#pragma redefine_extname EC_KEY_dup_ref BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EC_KEY_dup_ref) #pragma redefine_extname EC_KEY_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EC_KEY_free) #pragma redefine_extname EC_KEY_generate_key BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EC_KEY_generate_key) #pragma redefine_extname EC_KEY_generate_key_fips BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EC_KEY_generate_key_fips) @@ -1057,6 +1067,7 @@ #pragma redefine_extname EVP_HPKE_CTX_setup_auth_sender BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_CTX_setup_auth_sender) #pragma redefine_extname EVP_HPKE_CTX_setup_auth_sender_with_seed_for_testing BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_CTX_setup_auth_sender_with_seed_for_testing) #pragma redefine_extname EVP_HPKE_CTX_setup_recipient BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_CTX_setup_recipient) +#pragma redefine_extname EVP_HPKE_CTX_setup_recipient_with_shared_secret BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_CTX_setup_recipient_with_shared_secret) #pragma redefine_extname EVP_HPKE_CTX_setup_sender BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_CTX_setup_sender) #pragma redefine_extname EVP_HPKE_CTX_setup_sender_with_seed_for_testing BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_CTX_setup_sender_with_seed_for_testing) #pragma redefine_extname EVP_HPKE_CTX_zero BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_CTX_zero) @@ -1066,6 +1077,7 @@ #pragma redefine_extname EVP_HPKE_KEM_id BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_KEM_id) #pragma redefine_extname EVP_HPKE_KEM_private_key_len BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_KEM_private_key_len) #pragma redefine_extname EVP_HPKE_KEM_public_key_len BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_KEM_public_key_len) +#pragma redefine_extname EVP_HPKE_KEM_shared_secret_len BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_KEM_shared_secret_len) #pragma redefine_extname EVP_HPKE_KEY_cleanup BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_KEY_cleanup) #pragma redefine_extname EVP_HPKE_KEY_copy BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_KEY_copy) #pragma redefine_extname EVP_HPKE_KEY_derive BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_HPKE_KEY_derive) @@ -1369,6 +1381,9 @@ #pragma redefine_extname EVP_sha224 BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_sha224) #pragma redefine_extname EVP_sha256 BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_sha256) #pragma redefine_extname EVP_sha384 BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_sha384) +#pragma redefine_extname EVP_sha3_256 BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_sha3_256) +#pragma redefine_extname EVP_sha3_384 BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_sha3_384) +#pragma redefine_extname EVP_sha3_512 BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_sha3_512) #pragma redefine_extname EVP_sha512 BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_sha512) #pragma redefine_extname EVP_sha512_256 BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EVP_sha512_256) #pragma redefine_extname EXTENDED_KEY_USAGE_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(EXTENDED_KEY_USAGE_free) @@ -1766,6 +1781,7 @@ #pragma redefine_extname RSA_check_fips BORINGSSL_ADD_USER_LABEL_AND_PREFIX(RSA_check_fips) #pragma redefine_extname RSA_check_key BORINGSSL_ADD_USER_LABEL_AND_PREFIX(RSA_check_key) #pragma redefine_extname RSA_decrypt BORINGSSL_ADD_USER_LABEL_AND_PREFIX(RSA_decrypt) +#pragma redefine_extname RSA_dup_ref BORINGSSL_ADD_USER_LABEL_AND_PREFIX(RSA_dup_ref) #pragma redefine_extname RSA_encrypt BORINGSSL_ADD_USER_LABEL_AND_PREFIX(RSA_encrypt) #pragma redefine_extname RSA_flags BORINGSSL_ADD_USER_LABEL_AND_PREFIX(RSA_flags) #pragma redefine_extname RSA_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(RSA_free) @@ -1899,7 +1915,7 @@ #pragma redefine_extname SSL_COMP_get_compression_methods BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_COMP_get_compression_methods) #pragma redefine_extname SSL_COMP_get_id BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_COMP_get_id) #pragma redefine_extname SSL_COMP_get_name BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_COMP_get_name) -#pragma redefine_extname SSL_CREDENTIAL_add1_trust_anchor_group_inclusion BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CREDENTIAL_add1_trust_anchor_group_inclusion) +#pragma redefine_extname SSL_CREDENTIAL_add1_trust_anchor_group BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CREDENTIAL_add1_trust_anchor_group) #pragma redefine_extname SSL_CREDENTIAL_dup_ref BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CREDENTIAL_dup_ref) #pragma redefine_extname SSL_CREDENTIAL_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CREDENTIAL_free) #pragma redefine_extname SSL_CREDENTIAL_get0_pre_shared_key_id BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CREDENTIAL_get0_pre_shared_key_id) @@ -1939,6 +1955,7 @@ #pragma redefine_extname SSL_CTX_clear_extra_chain_certs BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_clear_extra_chain_certs) #pragma redefine_extname SSL_CTX_clear_mode BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_clear_mode) #pragma redefine_extname SSL_CTX_clear_options BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_clear_options) +#pragma redefine_extname SSL_CTX_dup_ref BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_dup_ref) #pragma redefine_extname SSL_CTX_enable_ocsp_stapling BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_enable_ocsp_stapling) #pragma redefine_extname SSL_CTX_enable_signed_cert_timestamps BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_enable_signed_cert_timestamps) #pragma redefine_extname SSL_CTX_enable_tls_channel_id BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_enable_tls_channel_id) @@ -2044,7 +2061,6 @@ #pragma redefine_extname SSL_CTX_set_ex_data BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_set_ex_data) #pragma redefine_extname SSL_CTX_set_false_start_allowed_without_alpn BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_set_false_start_allowed_without_alpn) #pragma redefine_extname SSL_CTX_set_grease_enabled BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_set_grease_enabled) -#pragma redefine_extname SSL_CTX_set_grease_sigalgs_enabled BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_set_grease_sigalgs_enabled) #pragma redefine_extname SSL_CTX_set_info_callback BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_set_info_callback) #pragma redefine_extname SSL_CTX_set_keylog_callback BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_set_keylog_callback) #pragma redefine_extname SSL_CTX_set_max_cert_list BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_set_max_cert_list) @@ -2111,12 +2127,14 @@ #pragma redefine_extname SSL_CTX_use_certificate_file BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_use_certificate_file) #pragma redefine_extname SSL_CTX_use_psk_identity_hint BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_use_psk_identity_hint) #pragma redefine_extname SSL_ECH_KEYS_add BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_ECH_KEYS_add) +#pragma redefine_extname SSL_ECH_KEYS_dup_ref BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_ECH_KEYS_dup_ref) #pragma redefine_extname SSL_ECH_KEYS_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_ECH_KEYS_free) #pragma redefine_extname SSL_ECH_KEYS_has_duplicate_config_id BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_ECH_KEYS_has_duplicate_config_id) #pragma redefine_extname SSL_ECH_KEYS_marshal_retry_configs BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_ECH_KEYS_marshal_retry_configs) #pragma redefine_extname SSL_ECH_KEYS_new BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_ECH_KEYS_new) #pragma redefine_extname SSL_ECH_KEYS_up_ref BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_ECH_KEYS_up_ref) #pragma redefine_extname SSL_SESSION_copy_without_early_data BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_SESSION_copy_without_early_data) +#pragma redefine_extname SSL_SESSION_dup_ref BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_SESSION_dup_ref) #pragma redefine_extname SSL_SESSION_early_data_capable BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_SESSION_early_data_capable) #pragma redefine_extname SSL_SESSION_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_SESSION_free) #pragma redefine_extname SSL_SESSION_from_bytes BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_SESSION_from_bytes) @@ -2567,6 +2585,7 @@ #pragma redefine_extname X509_CRL_delete_ext BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_CRL_delete_ext) #pragma redefine_extname X509_CRL_digest BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_CRL_digest) #pragma redefine_extname X509_CRL_dup BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_CRL_dup) +#pragma redefine_extname X509_CRL_dup_ref BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_CRL_dup_ref) #pragma redefine_extname X509_CRL_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_CRL_free) #pragma redefine_extname X509_CRL_get0_by_cert BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_CRL_get0_by_cert) #pragma redefine_extname X509_CRL_get0_by_serial BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_CRL_get0_by_serial) @@ -2733,7 +2752,6 @@ #pragma redefine_extname X509_STORE_CTX_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_STORE_CTX_free) #pragma redefine_extname X509_STORE_CTX_get0_cert BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_STORE_CTX_get0_cert) #pragma redefine_extname X509_STORE_CTX_get0_chain BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_STORE_CTX_get0_chain) -#pragma redefine_extname X509_STORE_CTX_get0_current_crl BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_STORE_CTX_get0_current_crl) #pragma redefine_extname X509_STORE_CTX_get0_param BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_STORE_CTX_get0_param) #pragma redefine_extname X509_STORE_CTX_get0_parent_ctx BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_STORE_CTX_get0_parent_ctx) #pragma redefine_extname X509_STORE_CTX_get0_store BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_STORE_CTX_get0_store) @@ -2769,6 +2787,7 @@ #pragma redefine_extname X509_STORE_add_cert BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_STORE_add_cert) #pragma redefine_extname X509_STORE_add_crl BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_STORE_add_crl) #pragma redefine_extname X509_STORE_add_lookup BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_STORE_add_lookup) +#pragma redefine_extname X509_STORE_dup_ref BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_STORE_dup_ref) #pragma redefine_extname X509_STORE_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_STORE_free) #pragma redefine_extname X509_STORE_get0_objects BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_STORE_get0_objects) #pragma redefine_extname X509_STORE_get0_param BORINGSSL_ADD_USER_LABEL_AND_PREFIX(X509_STORE_get0_param) @@ -3280,6 +3299,7 @@ #define ASN1_STRING_free BORINGSSL_ADD_PREFIX(ASN1_STRING_free) #define ASN1_STRING_get0_data BORINGSSL_ADD_PREFIX(ASN1_STRING_get0_data) #define ASN1_STRING_get_default_mask BORINGSSL_ADD_PREFIX(ASN1_STRING_get_default_mask) +#define ASN1_STRING_get_length BORINGSSL_ADD_PREFIX(ASN1_STRING_get_length) #define ASN1_STRING_length BORINGSSL_ADD_PREFIX(ASN1_STRING_length) #define ASN1_STRING_new BORINGSSL_ADD_PREFIX(ASN1_STRING_new) #define ASN1_STRING_print BORINGSSL_ADD_PREFIX(ASN1_STRING_print) @@ -3382,6 +3402,7 @@ #define BIO_ctrl_get_write_guarantee BORINGSSL_ADD_PREFIX(BIO_ctrl_get_write_guarantee) #define BIO_ctrl_pending BORINGSSL_ADD_PREFIX(BIO_ctrl_pending) #define BIO_do_connect BORINGSSL_ADD_PREFIX(BIO_do_connect) +#define BIO_dup_ref BORINGSSL_ADD_PREFIX(BIO_dup_ref) #define BIO_eof BORINGSSL_ADD_PREFIX(BIO_eof) #define BIO_f_base64 BORINGSSL_ADD_PREFIX(BIO_f_base64) #define BIO_f_ssl BORINGSSL_ADD_PREFIX(BIO_f_ssl) @@ -3765,9 +3786,14 @@ #define CONF_modules_free BORINGSSL_ADD_PREFIX(CONF_modules_free) #define CONF_modules_load_file BORINGSSL_ADD_PREFIX(CONF_modules_load_file) #define CONF_modules_unload BORINGSSL_ADD_PREFIX(CONF_modules_unload) +#define CPACE_CTX_free BORINGSSL_ADD_PREFIX(CPACE_CTX_free) +#define CPACE_CTX_new BORINGSSL_ADD_PREFIX(CPACE_CTX_new) +#define CPACE_generate_msg BORINGSSL_ADD_PREFIX(CPACE_generate_msg) +#define CPACE_process_msg BORINGSSL_ADD_PREFIX(CPACE_process_msg) #define CRL_DIST_POINTS_free BORINGSSL_ADD_PREFIX(CRL_DIST_POINTS_free) #define CRL_DIST_POINTS_it BORINGSSL_ADD_PREFIX(CRL_DIST_POINTS_it) #define CRL_DIST_POINTS_new BORINGSSL_ADD_PREFIX(CRL_DIST_POINTS_new) +#define CRYPTO_BUFFER_POOL_dup_ref BORINGSSL_ADD_PREFIX(CRYPTO_BUFFER_POOL_dup_ref) #define CRYPTO_BUFFER_POOL_free BORINGSSL_ADD_PREFIX(CRYPTO_BUFFER_POOL_free) #define CRYPTO_BUFFER_POOL_new BORINGSSL_ADD_PREFIX(CRYPTO_BUFFER_POOL_new) #define CRYPTO_BUFFER_POOL_up_ref BORINGSSL_ADD_PREFIX(CRYPTO_BUFFER_POOL_up_ref) @@ -3842,6 +3868,7 @@ #define DH_compute_key BORINGSSL_ADD_PREFIX(DH_compute_key) #define DH_compute_key_hashed BORINGSSL_ADD_PREFIX(DH_compute_key_hashed) #define DH_compute_key_padded BORINGSSL_ADD_PREFIX(DH_compute_key_padded) +#define DH_dup_ref BORINGSSL_ADD_PREFIX(DH_dup_ref) #define DH_free BORINGSSL_ADD_PREFIX(DH_free) #define DH_generate_key BORINGSSL_ADD_PREFIX(DH_generate_key) #define DH_generate_parameters BORINGSSL_ADD_PREFIX(DH_generate_parameters) @@ -3883,6 +3910,7 @@ #define DSA_do_sign BORINGSSL_ADD_PREFIX(DSA_do_sign) #define DSA_do_verify BORINGSSL_ADD_PREFIX(DSA_do_verify) #define DSA_dup_DH BORINGSSL_ADD_PREFIX(DSA_dup_DH) +#define DSA_dup_ref BORINGSSL_ADD_PREFIX(DSA_dup_ref) #define DSA_free BORINGSSL_ADD_PREFIX(DSA_free) #define DSA_generate_key BORINGSSL_ADD_PREFIX(DSA_generate_key) #define DSA_generate_parameters BORINGSSL_ADD_PREFIX(DSA_generate_parameters) @@ -3968,6 +3996,7 @@ #define EC_KEY_check_key BORINGSSL_ADD_PREFIX(EC_KEY_check_key) #define EC_KEY_derive_from_secret BORINGSSL_ADD_PREFIX(EC_KEY_derive_from_secret) #define EC_KEY_dup BORINGSSL_ADD_PREFIX(EC_KEY_dup) +#define EC_KEY_dup_ref BORINGSSL_ADD_PREFIX(EC_KEY_dup_ref) #define EC_KEY_free BORINGSSL_ADD_PREFIX(EC_KEY_free) #define EC_KEY_generate_key BORINGSSL_ADD_PREFIX(EC_KEY_generate_key) #define EC_KEY_generate_key_fips BORINGSSL_ADD_PREFIX(EC_KEY_generate_key_fips) @@ -4207,6 +4236,7 @@ #define EVP_HPKE_CTX_setup_auth_sender BORINGSSL_ADD_PREFIX(EVP_HPKE_CTX_setup_auth_sender) #define EVP_HPKE_CTX_setup_auth_sender_with_seed_for_testing BORINGSSL_ADD_PREFIX(EVP_HPKE_CTX_setup_auth_sender_with_seed_for_testing) #define EVP_HPKE_CTX_setup_recipient BORINGSSL_ADD_PREFIX(EVP_HPKE_CTX_setup_recipient) +#define EVP_HPKE_CTX_setup_recipient_with_shared_secret BORINGSSL_ADD_PREFIX(EVP_HPKE_CTX_setup_recipient_with_shared_secret) #define EVP_HPKE_CTX_setup_sender BORINGSSL_ADD_PREFIX(EVP_HPKE_CTX_setup_sender) #define EVP_HPKE_CTX_setup_sender_with_seed_for_testing BORINGSSL_ADD_PREFIX(EVP_HPKE_CTX_setup_sender_with_seed_for_testing) #define EVP_HPKE_CTX_zero BORINGSSL_ADD_PREFIX(EVP_HPKE_CTX_zero) @@ -4216,6 +4246,7 @@ #define EVP_HPKE_KEM_id BORINGSSL_ADD_PREFIX(EVP_HPKE_KEM_id) #define EVP_HPKE_KEM_private_key_len BORINGSSL_ADD_PREFIX(EVP_HPKE_KEM_private_key_len) #define EVP_HPKE_KEM_public_key_len BORINGSSL_ADD_PREFIX(EVP_HPKE_KEM_public_key_len) +#define EVP_HPKE_KEM_shared_secret_len BORINGSSL_ADD_PREFIX(EVP_HPKE_KEM_shared_secret_len) #define EVP_HPKE_KEY_cleanup BORINGSSL_ADD_PREFIX(EVP_HPKE_KEY_cleanup) #define EVP_HPKE_KEY_copy BORINGSSL_ADD_PREFIX(EVP_HPKE_KEY_copy) #define EVP_HPKE_KEY_derive BORINGSSL_ADD_PREFIX(EVP_HPKE_KEY_derive) @@ -4519,6 +4550,9 @@ #define EVP_sha224 BORINGSSL_ADD_PREFIX(EVP_sha224) #define EVP_sha256 BORINGSSL_ADD_PREFIX(EVP_sha256) #define EVP_sha384 BORINGSSL_ADD_PREFIX(EVP_sha384) +#define EVP_sha3_256 BORINGSSL_ADD_PREFIX(EVP_sha3_256) +#define EVP_sha3_384 BORINGSSL_ADD_PREFIX(EVP_sha3_384) +#define EVP_sha3_512 BORINGSSL_ADD_PREFIX(EVP_sha3_512) #define EVP_sha512 BORINGSSL_ADD_PREFIX(EVP_sha512) #define EVP_sha512_256 BORINGSSL_ADD_PREFIX(EVP_sha512_256) #define EXTENDED_KEY_USAGE_free BORINGSSL_ADD_PREFIX(EXTENDED_KEY_USAGE_free) @@ -4916,6 +4950,7 @@ #define RSA_check_fips BORINGSSL_ADD_PREFIX(RSA_check_fips) #define RSA_check_key BORINGSSL_ADD_PREFIX(RSA_check_key) #define RSA_decrypt BORINGSSL_ADD_PREFIX(RSA_decrypt) +#define RSA_dup_ref BORINGSSL_ADD_PREFIX(RSA_dup_ref) #define RSA_encrypt BORINGSSL_ADD_PREFIX(RSA_encrypt) #define RSA_flags BORINGSSL_ADD_PREFIX(RSA_flags) #define RSA_free BORINGSSL_ADD_PREFIX(RSA_free) @@ -5049,7 +5084,7 @@ #define SSL_COMP_get_compression_methods BORINGSSL_ADD_PREFIX(SSL_COMP_get_compression_methods) #define SSL_COMP_get_id BORINGSSL_ADD_PREFIX(SSL_COMP_get_id) #define SSL_COMP_get_name BORINGSSL_ADD_PREFIX(SSL_COMP_get_name) -#define SSL_CREDENTIAL_add1_trust_anchor_group_inclusion BORINGSSL_ADD_PREFIX(SSL_CREDENTIAL_add1_trust_anchor_group_inclusion) +#define SSL_CREDENTIAL_add1_trust_anchor_group BORINGSSL_ADD_PREFIX(SSL_CREDENTIAL_add1_trust_anchor_group) #define SSL_CREDENTIAL_dup_ref BORINGSSL_ADD_PREFIX(SSL_CREDENTIAL_dup_ref) #define SSL_CREDENTIAL_free BORINGSSL_ADD_PREFIX(SSL_CREDENTIAL_free) #define SSL_CREDENTIAL_get0_pre_shared_key_id BORINGSSL_ADD_PREFIX(SSL_CREDENTIAL_get0_pre_shared_key_id) @@ -5089,6 +5124,7 @@ #define SSL_CTX_clear_extra_chain_certs BORINGSSL_ADD_PREFIX(SSL_CTX_clear_extra_chain_certs) #define SSL_CTX_clear_mode BORINGSSL_ADD_PREFIX(SSL_CTX_clear_mode) #define SSL_CTX_clear_options BORINGSSL_ADD_PREFIX(SSL_CTX_clear_options) +#define SSL_CTX_dup_ref BORINGSSL_ADD_PREFIX(SSL_CTX_dup_ref) #define SSL_CTX_enable_ocsp_stapling BORINGSSL_ADD_PREFIX(SSL_CTX_enable_ocsp_stapling) #define SSL_CTX_enable_signed_cert_timestamps BORINGSSL_ADD_PREFIX(SSL_CTX_enable_signed_cert_timestamps) #define SSL_CTX_enable_tls_channel_id BORINGSSL_ADD_PREFIX(SSL_CTX_enable_tls_channel_id) @@ -5194,7 +5230,6 @@ #define SSL_CTX_set_ex_data BORINGSSL_ADD_PREFIX(SSL_CTX_set_ex_data) #define SSL_CTX_set_false_start_allowed_without_alpn BORINGSSL_ADD_PREFIX(SSL_CTX_set_false_start_allowed_without_alpn) #define SSL_CTX_set_grease_enabled BORINGSSL_ADD_PREFIX(SSL_CTX_set_grease_enabled) -#define SSL_CTX_set_grease_sigalgs_enabled BORINGSSL_ADD_PREFIX(SSL_CTX_set_grease_sigalgs_enabled) #define SSL_CTX_set_info_callback BORINGSSL_ADD_PREFIX(SSL_CTX_set_info_callback) #define SSL_CTX_set_keylog_callback BORINGSSL_ADD_PREFIX(SSL_CTX_set_keylog_callback) #define SSL_CTX_set_max_cert_list BORINGSSL_ADD_PREFIX(SSL_CTX_set_max_cert_list) @@ -5261,12 +5296,14 @@ #define SSL_CTX_use_certificate_file BORINGSSL_ADD_PREFIX(SSL_CTX_use_certificate_file) #define SSL_CTX_use_psk_identity_hint BORINGSSL_ADD_PREFIX(SSL_CTX_use_psk_identity_hint) #define SSL_ECH_KEYS_add BORINGSSL_ADD_PREFIX(SSL_ECH_KEYS_add) +#define SSL_ECH_KEYS_dup_ref BORINGSSL_ADD_PREFIX(SSL_ECH_KEYS_dup_ref) #define SSL_ECH_KEYS_free BORINGSSL_ADD_PREFIX(SSL_ECH_KEYS_free) #define SSL_ECH_KEYS_has_duplicate_config_id BORINGSSL_ADD_PREFIX(SSL_ECH_KEYS_has_duplicate_config_id) #define SSL_ECH_KEYS_marshal_retry_configs BORINGSSL_ADD_PREFIX(SSL_ECH_KEYS_marshal_retry_configs) #define SSL_ECH_KEYS_new BORINGSSL_ADD_PREFIX(SSL_ECH_KEYS_new) #define SSL_ECH_KEYS_up_ref BORINGSSL_ADD_PREFIX(SSL_ECH_KEYS_up_ref) #define SSL_SESSION_copy_without_early_data BORINGSSL_ADD_PREFIX(SSL_SESSION_copy_without_early_data) +#define SSL_SESSION_dup_ref BORINGSSL_ADD_PREFIX(SSL_SESSION_dup_ref) #define SSL_SESSION_early_data_capable BORINGSSL_ADD_PREFIX(SSL_SESSION_early_data_capable) #define SSL_SESSION_free BORINGSSL_ADD_PREFIX(SSL_SESSION_free) #define SSL_SESSION_from_bytes BORINGSSL_ADD_PREFIX(SSL_SESSION_from_bytes) @@ -5717,6 +5754,7 @@ #define X509_CRL_delete_ext BORINGSSL_ADD_PREFIX(X509_CRL_delete_ext) #define X509_CRL_digest BORINGSSL_ADD_PREFIX(X509_CRL_digest) #define X509_CRL_dup BORINGSSL_ADD_PREFIX(X509_CRL_dup) +#define X509_CRL_dup_ref BORINGSSL_ADD_PREFIX(X509_CRL_dup_ref) #define X509_CRL_free BORINGSSL_ADD_PREFIX(X509_CRL_free) #define X509_CRL_get0_by_cert BORINGSSL_ADD_PREFIX(X509_CRL_get0_by_cert) #define X509_CRL_get0_by_serial BORINGSSL_ADD_PREFIX(X509_CRL_get0_by_serial) @@ -5883,7 +5921,6 @@ #define X509_STORE_CTX_free BORINGSSL_ADD_PREFIX(X509_STORE_CTX_free) #define X509_STORE_CTX_get0_cert BORINGSSL_ADD_PREFIX(X509_STORE_CTX_get0_cert) #define X509_STORE_CTX_get0_chain BORINGSSL_ADD_PREFIX(X509_STORE_CTX_get0_chain) -#define X509_STORE_CTX_get0_current_crl BORINGSSL_ADD_PREFIX(X509_STORE_CTX_get0_current_crl) #define X509_STORE_CTX_get0_param BORINGSSL_ADD_PREFIX(X509_STORE_CTX_get0_param) #define X509_STORE_CTX_get0_parent_ctx BORINGSSL_ADD_PREFIX(X509_STORE_CTX_get0_parent_ctx) #define X509_STORE_CTX_get0_store BORINGSSL_ADD_PREFIX(X509_STORE_CTX_get0_store) @@ -5919,6 +5956,7 @@ #define X509_STORE_add_cert BORINGSSL_ADD_PREFIX(X509_STORE_add_cert) #define X509_STORE_add_crl BORINGSSL_ADD_PREFIX(X509_STORE_add_crl) #define X509_STORE_add_lookup BORINGSSL_ADD_PREFIX(X509_STORE_add_lookup) +#define X509_STORE_dup_ref BORINGSSL_ADD_PREFIX(X509_STORE_dup_ref) #define X509_STORE_free BORINGSSL_ADD_PREFIX(X509_STORE_free) #define X509_STORE_get0_objects BORINGSSL_ADD_PREFIX(X509_STORE_get0_objects) #define X509_STORE_get0_param BORINGSSL_ADD_PREFIX(X509_STORE_get0_param) diff --git a/third_party/boringssl/src/include/openssl/rsa.h b/third_party/boringssl/src/include/openssl/rsa.h index 6ff32e9..f7c6cfa 100644 --- a/third_party/boringssl/src/include/openssl/rsa.h +++ b/third_party/boringssl/src/include/openssl/rsa.h @@ -15,7 +15,7 @@ #ifndef OPENSSL_HEADER_RSA_H #define OPENSSL_HEADER_RSA_H -#include // IWYU pragma: export +#include // IWYU pragma: export #include #include @@ -65,6 +65,11 @@ OPENSSL_EXPORT void RSA_free(RSA *rsa); // not mutate `rsa` for thread-safety purposes and may be used concurrently. OPENSSL_EXPORT int RSA_up_ref(RSA *rsa); +// RSA_dup_ref increments the reference count of `rsa` and returns the same +// handle. It does not mutate `rsa` for thread-safety purposes and may be used +// concurrently. +OPENSSL_EXPORT RSA *RSA_dup_ref(const RSA *rsa); + // Properties. @@ -832,7 +837,7 @@ extern "C++" { BSSL_NAMESPACE_BEGIN BORINGSSL_MAKE_DELETER(RSA, RSA_free) -BORINGSSL_MAKE_UP_REF(RSA, RSA_up_ref) +BORINGSSL_MAKE_UP_REF(RSA, RSA_dup_ref) BSSL_NAMESPACE_END diff --git a/third_party/boringssl/src/include/openssl/span.h b/third_party/boringssl/src/include/openssl/span.h index 5f205b6..72447af 100644 --- a/third_party/boringssl/src/include/openssl/span.h +++ b/third_party/boringssl/src/include/openssl/span.h @@ -15,7 +15,7 @@ #ifndef OPENSSL_HEADER_SSL_SPAN_H #define OPENSSL_HEADER_SSL_SPAN_H -#include // IWYU pragma: export +#include // IWYU pragma: export #if !defined(BORINGSSL_NO_CXX) diff --git a/third_party/boringssl/src/include/openssl/trust_token.h b/third_party/boringssl/src/include/openssl/trust_token.h index cf909ae..e0fbcea 100644 --- a/third_party/boringssl/src/include/openssl/trust_token.h +++ b/third_party/boringssl/src/include/openssl/trust_token.h @@ -15,7 +15,7 @@ #ifndef OPENSSL_HEADER_TRUST_TOKEN_H #define OPENSSL_HEADER_TRUST_TOKEN_H -#include // IWYU pragma: export +#include // IWYU pragma: export #include #if defined(__cplusplus) @@ -152,7 +152,7 @@ OPENSSL_EXPORT int TRUST_TOKEN_CLIENT_add_key(TRUST_TOKEN_CLIENT *ctx, // TRUST_TOKEN_CLIENT_set_srr_key sets the public key used to verify the SRR. It // returns one on success and zero on error. OPENSSL_EXPORT int TRUST_TOKEN_CLIENT_set_srr_key(TRUST_TOKEN_CLIENT *ctx, - EVP_PKEY *key); + const EVP_PKEY *key); // TRUST_TOKEN_CLIENT_begin_issuance produces a request for `count` trust tokens // and serializes the request into a newly-allocated buffer, setting `*out` to @@ -180,11 +180,9 @@ OPENSSL_EXPORT int TRUST_TOKEN_CLIENT_begin_issuance_over_message( // arrives without the specified key present. The caller takes ownership of the // list and must call `sk_TRUST_TOKEN_pop_free` when done. The list is empty if // issuance fails. -OPENSSL_EXPORT STACK_OF(TRUST_TOKEN) * - TRUST_TOKEN_CLIENT_finish_issuance(TRUST_TOKEN_CLIENT *ctx, - size_t *out_key_index, - const uint8_t *response, - size_t response_len); +OPENSSL_EXPORT STACK_OF(TRUST_TOKEN) *TRUST_TOKEN_CLIENT_finish_issuance( + TRUST_TOKEN_CLIENT *ctx, size_t *out_key_index, const uint8_t *response, + size_t response_len); // TRUST_TOKEN_CLIENT_begin_redemption produces a request to redeem a token @@ -243,7 +241,7 @@ OPENSSL_EXPORT int TRUST_TOKEN_ISSUER_add_key(TRUST_TOKEN_ISSUER *ctx, // TRUST_TOKEN_ISSUER_set_srr_key sets the private key used to sign the SRR. It // returns one on success and zero on error. OPENSSL_EXPORT int TRUST_TOKEN_ISSUER_set_srr_key(TRUST_TOKEN_ISSUER *ctx, - EVP_PKEY *key); + const EVP_PKEY *key); // TRUST_TOKEN_ISSUER_issue ingests `request` for token issuance // and generates up to `max_issuance` valid tokens, producing a list of blinded diff --git a/third_party/boringssl/src/include/openssl/x509.h b/third_party/boringssl/src/include/openssl/x509.h index 0ef08e6..6e2fa75 100644 --- a/third_party/boringssl/src/include/openssl/x509.h +++ b/third_party/boringssl/src/include/openssl/x509.h @@ -486,9 +486,8 @@ OPENSSL_EXPORT int X509_set_issuer_name(X509 *x509, const X509_NAME *name); OPENSSL_EXPORT int X509_set_subject_name(X509 *x509, const X509_NAME *name); // X509_set_pubkey sets `x509`'s public key to `pkey`. It returns one on success -// and zero on error. This function does not take ownership of `pkey` and -// internally copies and updates reference counts as needed. -OPENSSL_EXPORT int X509_set_pubkey(X509 *x509, EVP_PKEY *pkey); +// and zero on error. +OPENSSL_EXPORT int X509_set_pubkey(X509 *x509, const EVP_PKEY *pkey); // X509_delete_ext removes the extension in `x` at index `loc` and returns the // removed extension, or NULL if `loc` was out of bounds. If non-NULL, the @@ -682,6 +681,10 @@ DEFINE_STACK_OF(X509_REVOKED) // X509_CRL_up_ref adds one to the reference count of `crl` and returns one. OPENSSL_EXPORT int X509_CRL_up_ref(X509_CRL *crl); +// X509_CRL_dup_ref adds one to the reference count of `crl` and returns the +// same. +OPENSSL_EXPORT X509_CRL *X509_CRL_dup_ref(const X509_CRL *crl); + // X509_CRL_dup returns a newly-allocated copy of `crl`, or NULL on error. This // function works by serializing the structure, so if `crl` is incomplete, it // may fail. @@ -2311,8 +2314,6 @@ typedef struct DIST_POINT_NAME_st { GENERAL_NAMES *fullname; STACK_OF(X509_NAME_ENTRY) *relativename; } name; - // If relativename then this contains the full distribution point name - X509_NAME *dpname; } DIST_POINT_NAME; // DIST_POINT_NAME_new returns a newly-allocated, empty `DIST_POINT_NAME` @@ -2802,6 +2803,10 @@ OPENSSL_EXPORT X509_STORE *X509_STORE_new(void); // Although `store` is not const, this function's use of `store` is thread-safe. OPENSSL_EXPORT int X509_STORE_up_ref(X509_STORE *store); +// X509_STORE_dup_ref adds one to the reference count of `store` and returns +// the same handle. +OPENSSL_EXPORT X509_STORE *X509_STORE_dup_ref(const X509_STORE *store); + // X509_STORE_free releases memory associated with `store`. OPENSSL_EXPORT void X509_STORE_free(X509_STORE *store); @@ -2817,7 +2822,7 @@ OPENSSL_EXPORT void X509_STORE_free(X509_STORE *store); // is a race condition whether `x509` is available for issuer lookups. // Moreover, the result may differ for each issuer lookup performed by a single // `X509_verify_cert` call. -OPENSSL_EXPORT int X509_STORE_add_cert(X509_STORE *store, X509 *x509); +OPENSSL_EXPORT int X509_STORE_add_cert(X509_STORE *store, const X509 *x509); // X509_STORE_add_crl adds `crl` to `store`. It returns one on success and zero // on error. This function internally increments `crl`'s reference count, so the @@ -2834,7 +2839,7 @@ OPENSSL_EXPORT int X509_STORE_add_cert(X509_STORE *store, X509 *x509); // To vary the set of CRLs over time, callers should either create a new // `X509_STORE` or configure CRLs on a per-verification basis with // `X509_STORE_CTX_set0_crls`. -OPENSSL_EXPORT int X509_STORE_add_crl(X509_STORE *store, X509_CRL *crl); +OPENSSL_EXPORT int X509_STORE_add_crl(X509_STORE *store, const X509_CRL *crl); // X509_STORE_get0_param returns `store`'s verification parameters. This object // is mutable and may be modified by the caller. For an individual certificate @@ -3066,11 +3071,6 @@ OPENSSL_EXPORT int X509_STORE_CTX_get_error_depth(const X509_STORE_CTX *ctx); // error returned by `X509_STORE_CTX_get_error`. OPENSSL_EXPORT X509 *X509_STORE_CTX_get_current_cert(const X509_STORE_CTX *ctx); -// X509_STORE_CTX_get0_current_crl returns the CRL which caused the error -// returned by `X509_STORE_CTX_get_error`. -OPENSSL_EXPORT X509_CRL *X509_STORE_CTX_get0_current_crl( - const X509_STORE_CTX *ctx); - // X509_STORE_CTX_get0_store returns the `X509_STORE` that `ctx` uses. OPENSSL_EXPORT X509_STORE *X509_STORE_CTX_get0_store(const X509_STORE_CTX *ctx); @@ -3272,9 +3272,10 @@ OPENSSL_EXPORT int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to, // X509_V_FLAG_USE_DELTAS causes all verifications to fail. Delta CRL support // has been removed. #define X509_V_FLAG_USE_DELTAS 0x2000 -// X509_V_FLAG_CHECK_SS_SIGNATURE checks the redundant signature on self-signed -// trust anchors. This check provides no security benefit and only wastes CPU. -#define X509_V_FLAG_CHECK_SS_SIGNATURE 0x4000 +// X509_V_FLAG_CHECK_SS_SIGNATURE does nothing. Historically it would check the +// redundant signature on self-signed trust anchors. This check provided no +// security benefit and only wasted CPU. +#define X509_V_FLAG_CHECK_SS_SIGNATURE 0x0 // X509_V_FLAG_TRUSTED_FIRST does nothing. The behavior it controls is always // enabled. #define X509_V_FLAG_TRUSTED_FIRST 0x0 @@ -3289,9 +3290,9 @@ OPENSSL_EXPORT int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to, // X509_V_FLAG_ALLOW_TIMEZONE_OFFSET allows `notBefore` and `notAfter` fields // to contain a time zone offset. #define X509_V_FLAG_ALLOW_TIMEZONE_OFFSET 0x1000000 -// X509_V_FLAG_USE_MTC_DRAFT_PLANTS_05 enables the verification of Merkle Tree -// Certificates as specified in draft-ietf-plants-merkle-tree-certs-05. -#define X509_V_FLAG_USE_MTC_DRAFT_PLANTS_05 0x400000 +// X509_V_FLAG_USE_MTC_DRAFT_PLANTS_07 enables the verification of Merkle Tree +// Certificates as specified in draft-ietf-plants-merkle-tree-certs-07. +#define X509_V_FLAG_USE_MTC_DRAFT_PLANTS_07 0x400000 // X509_VERIFY_PARAM_set_flags enables all values in `flags` in `param`'s // verification flags and returns one. `flags` should be a combination of @@ -4516,7 +4517,7 @@ OPENSSL_EXPORT int ASN1_item_verify(const ASN1_ITEM *it, OPENSSL_EXPORT int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, ASN1_BIT_STRING *signature, void *data, - EVP_PKEY *pkey, const EVP_MD *type); + const EVP_PKEY *pkey, const EVP_MD *type); // ASN1_item_sign_ctx behaves like `ASN1_item_sign` except the signature is // signed with `ctx`, `ctx`, which must have been initialized with @@ -5316,8 +5317,10 @@ BORINGSSL_MAKE_DELETER(BASIC_CONSTRAINTS, BASIC_CONSTRAINTS_free) // TODO(davidben): Move this to conf.h and rename to CONF_VALUE_free. BORINGSSL_MAKE_DELETER(CONF_VALUE, X509V3_conf_free) BORINGSSL_MAKE_DELETER(DIST_POINT, DIST_POINT_free) +BORINGSSL_MAKE_DELETER(DIST_POINT_NAME, DIST_POINT_NAME_free) BORINGSSL_MAKE_DELETER(GENERAL_NAME, GENERAL_NAME_free) BORINGSSL_MAKE_DELETER(GENERAL_SUBTREE, GENERAL_SUBTREE_free) +BORINGSSL_MAKE_DELETER(ISSUING_DIST_POINT, ISSUING_DIST_POINT_free) BORINGSSL_MAKE_DELETER(NAME_CONSTRAINTS, NAME_CONSTRAINTS_free) BORINGSSL_MAKE_DELETER(NETSCAPE_SPKI, NETSCAPE_SPKI_free) BORINGSSL_MAKE_DELETER(NOTICEREF, NOTICEREF_free) @@ -5328,11 +5331,11 @@ BORINGSSL_MAKE_DELETER(POLICYQUALINFO, POLICYQUALINFO_free) BORINGSSL_MAKE_DELETER(RSA_PSS_PARAMS, RSA_PSS_PARAMS_free) BORINGSSL_MAKE_DELETER(USERNOTICE, USERNOTICE_free) BORINGSSL_MAKE_DELETER(X509, X509_free) -BORINGSSL_MAKE_UP_REF(X509, X509_up_ref) +BORINGSSL_MAKE_UP_REF(X509, X509_dup_ref) BORINGSSL_MAKE_DELETER(X509_ALGOR, X509_ALGOR_free) BORINGSSL_MAKE_DELETER(X509_ATTRIBUTE, X509_ATTRIBUTE_free) BORINGSSL_MAKE_DELETER(X509_CRL, X509_CRL_free) -BORINGSSL_MAKE_UP_REF(X509_CRL, X509_CRL_up_ref) +BORINGSSL_MAKE_UP_REF(X509_CRL, X509_CRL_dup_ref) BORINGSSL_MAKE_DELETER(X509_EXTENSION, X509_EXTENSION_free) BORINGSSL_MAKE_DELETER(X509_INFO, X509_INFO_free) BORINGSSL_MAKE_DELETER(X509_LOOKUP, X509_LOOKUP_free) @@ -5344,13 +5347,13 @@ BORINGSSL_MAKE_DELETER(X509_REQ, X509_REQ_free) BORINGSSL_MAKE_DELETER(X509_REVOKED, X509_REVOKED_free) BORINGSSL_MAKE_DELETER(X509_SIG, X509_SIG_free) BORINGSSL_MAKE_DELETER(X509_STORE, X509_STORE_free) -BORINGSSL_MAKE_UP_REF(X509_STORE, X509_STORE_up_ref) +BORINGSSL_MAKE_UP_REF(X509_STORE, X509_STORE_dup_ref) BORINGSSL_MAKE_DELETER(X509_STORE_CTX, X509_STORE_CTX_free) BORINGSSL_MAKE_DELETER(X509_VERIFY_PARAM, X509_VERIFY_PARAM_free) BSSL_NAMESPACE_END -} // extern C++ +} // extern C++ #endif // !BORINGSSL_NO_CXX #define X509_R_AKID_MISMATCH 100 diff --git a/tool/REVISION b/tool/REVISION index 978305a..0678169 100644 --- a/tool/REVISION +++ b/tool/REVISION @@ -1 +1 @@ -e98a6564575520260ef95b2389e5d63a24917093 +64188f173d4bd19873db8a9d247470e9e1580ec2