From 6f978d3cfe578611fce3b5af50d06c0fe95f03bf Mon Sep 17 00:00:00 2001 From: mosuem <27859082+mosuem@users.noreply.github.com> Date: Sun, 11 Oct 2026 03:27:36 +0000 Subject: [PATCH] Update BoringSSL to 3fed4f20 --- CHANGELOG.md | 1 + lib/src/bindings/boringssl.g.dart | 176 +++++- lib/src/bindings/record_use_mapping.g.dart | 9 + .../gen/bcm/aesni-gcm-x86_64-win.asm | 2 +- .../boringssl/gen/bcm/aesni-x86_64-win.asm | 6 +- .../gen/bcm/ghash-ssse3-x86_64-win.asm | 2 +- .../boringssl/gen/bcm/ghash-x86_64-win.asm | 2 +- .../boringssl/gen/bcm/p256-x86_64-asm-win.asm | 2 +- .../boringssl/gen/bcm/rsaz-avx2-win.asm | 2 +- .../boringssl/gen/bcm/sha1-x86_64-win.asm | 2 +- .../boringssl/gen/bcm/sha256-x86_64-win.asm | 2 +- .../boringssl/gen/bcm/sha512-x86_64-win.asm | 2 +- .../boringssl/gen/bcm/vpaes-x86_64-win.asm | 2 +- .../boringssl/gen/bcm/x86_64-mont5-win.asm | 2 +- .../gen/crypto/chacha-x86_64-win.asm | 2 +- third_party/boringssl/sources.cmake | 1 + .../boringssl/src/crypto/asn1/a_type.cc | 6 + .../boringssl/src/crypto/asn1/asn1_par.cc | 2 +- .../boringssl/src/crypto/curve25519/cpace.cc | 227 ++++++++ .../src/crypto/curve25519/internal.h | 30 +- third_party/boringssl/src/crypto/dsa/dsa.cc | 12 +- .../boringssl/src/crypto/evp/evp_kem.cc | 9 +- .../boringssl/src/crypto/evp/internal.h | 15 +- third_party/boringssl/src/crypto/evp/p_dh.cc | 34 +- third_party/boringssl/src/crypto/evp/p_dsa.cc | 38 +- third_party/boringssl/src/crypto/evp/p_ec.cc | 68 +-- .../boringssl/src/crypto/evp/p_ed25519.cc | 58 +- .../boringssl/src/crypto/evp/p_hkdf.cc | 10 +- .../boringssl/src/crypto/evp/p_mlkem.cc | 12 +- third_party/boringssl/src/crypto/evp/p_rsa.cc | 98 ++-- .../boringssl/src/crypto/evp/p_x25519.cc | 54 +- .../boringssl/src/crypto/evp/p_xwing.cc | 51 +- .../fipsmodule/bn/exponentiation.cc.inc | 66 ++- .../src/crypto/fipsmodule/ec/ec_key.cc.inc | 10 +- .../crypto/fipsmodule/entropy/jitter.cc.inc | 42 +- .../src/crypto/fipsmodule/rsa/rsa.cc.inc | 10 +- third_party/boringssl/src/crypto/hpke/hpke.cc | 282 +++++---- third_party/boringssl/src/crypto/internal.h | 12 +- third_party/boringssl/src/crypto/pool/pool.cc | 9 + .../boringssl/src/crypto/x509/internal.h | 26 +- .../boringssl/src/crypto/x509/v3_crld.cc | 50 +- .../boringssl/src/crypto/x509/v3_purp.cc | 24 - .../boringssl/src/crypto/x509/x509_lu.cc | 9 + .../boringssl/src/crypto/x509/x509_mtc.cc | 7 +- .../boringssl/src/crypto/x509/x509_vfy.cc | 135 ++--- .../boringssl/src/crypto/x509/x_crl.cc | 51 +- .../boringssl/src/gen/crypto/err_data.cc | 550 +++++++++--------- .../boringssl/src/include/openssl/asn1.h | 1 + .../boringssl/src/include/openssl/base.h | 1 + .../src/include/openssl/bytestring.h | 1 + .../src/include/openssl/curve25519.h | 82 ++- .../boringssl/src/include/openssl/dsa.h | 7 +- .../boringssl/src/include/openssl/ec_key.h | 5 + .../boringssl/src/include/openssl/hpke.h | 23 + .../boringssl/src/include/openssl/pool.h | 6 + .../src/include/openssl/prefix_symbols.h | 32 +- .../boringssl/src/include/openssl/rsa.h | 7 +- .../boringssl/src/include/openssl/span.h | 2 +- .../boringssl/src/include/openssl/x509.h | 10 +- tool/REVISION | 2 +- 60 files changed, 1484 insertions(+), 917 deletions(-) create mode 100644 third_party/boringssl/src/crypto/curve25519/cpace.cc diff --git a/CHANGELOG.md b/CHANGELOG.md index d5f5c40..667800f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 0.4.2-wip - Update BoringSSL to e98a6564. +- Update BoringSSL to 3fed4f20. ## 0.4.1 diff --git a/lib/src/bindings/boringssl.g.dart b/lib/src/bindings/boringssl.g.dart index 32916f6..90fb5de 100644 --- a/lib/src/bindings/boringssl.g.dart +++ b/lib/src/bindings/boringssl.g.dart @@ -7338,6 +7338,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 +7455,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() @@ -8569,6 +8680,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 +9786,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)>( @@ -20533,6 +20666,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. @@ -25986,6 +26130,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)>( @@ -31827,6 +31981,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 +32466,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 +32507,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 +32607,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 @@ -35725,6 +35882,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; @@ -37131,6 +37290,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..34967ef 100644 --- a/lib/src/bindings/record_use_mapping.g.dart +++ b/lib/src/bindings/record_use_mapping.g.dart @@ -543,8 +543,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', @@ -642,6 +647,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 +721,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', @@ -1545,6 +1552,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', @@ -1900,6 +1908,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..70aa8db 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 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_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/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..2048c44 100644 --- a/third_party/boringssl/src/crypto/dsa/dsa.cc +++ b/third_party/boringssl/src/crypto/dsa/dsa.cc @@ -72,6 +72,15 @@ int DSA_up_ref(DSA *dsa) { return 1; } +DSA *DSA_dup_ref(const DSA *dsa) { + if (dsa == nullptr) { + return nullptr; + } + auto *ptr = const_cast(dsa); + DSA_up_ref(ptr); + return ptr; +} + unsigned DSA_bits(const DSA *dsa) { return BN_num_bits(FromOpaque(dsa)->p.get()); } @@ -845,7 +854,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_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_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/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/ec/ec_key.cc.inc b/third_party/boringssl/src/crypto/fipsmodule/ec/ec_key.cc.inc index 18979b9..e1e4e4b 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,15 @@ 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; + } + auto *ptr = const_cast(key); + EC_KEY_up_ref(ptr); + return ptr; +} + 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/rsa/rsa.cc.inc b/third_party/boringssl/src/crypto/fipsmodule/rsa/rsa.cc.inc index edec7ac..34a219f 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,15 @@ int RSA_up_ref(RSA *rsa) { return 1; } +RSA *RSA_dup_ref(const RSA *rsa) { + if (rsa == nullptr) { + return nullptr; + } + auto *ptr = const_cast(rsa); + RSA_up_ref(ptr); + return ptr; +} + 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/pool/pool.cc b/third_party/boringssl/src/crypto/pool/pool.cc index 8b1f5bc..4bc3a19 100644 --- a/third_party/boringssl/src/crypto/pool/pool.cc +++ b/third_party/boringssl/src/crypto/pool/pool.cc @@ -95,6 +95,15 @@ 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; + } + auto *ptr = const_cast(pool); + CRYPTO_BUFFER_POOL_up_ref(ptr); + return ptr; +} + 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. diff --git a/third_party/boringssl/src/crypto/x509/internal.h b/third_party/boringssl/src/crypto/x509/internal.h index f5a76da..ab07fec 100644 --- a/third_party/boringssl/src/crypto/x509/internal.h +++ b/third_party/boringssl/src/crypto/x509/internal.h @@ -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 */; @@ -625,10 +607,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 +629,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); 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..86f23b8 100644 --- a/third_party/boringssl/src/crypto/x509/v3_purp.cc +++ b/third_party/boringssl/src/crypto/x509/v3_purp.cc @@ -146,25 +146,6 @@ int X509_supported_extension(const X509_EXTENSION *ex) { nid == NID_pe_mtcCertificationAuthority_draft; } -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) { int j; auto *impl = FromOpaque(x); @@ -173,11 +154,6 @@ 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; } diff --git a/third_party/boringssl/src/crypto/x509/x509_lu.cc b/third_party/boringssl/src/crypto/x509/x509_lu.cc index 126bf33..91c3b2d 100644 --- a/third_party/boringssl/src/crypto/x509/x509_lu.cc +++ b/third_party/boringssl/src/crypto/x509/x509_lu.cc @@ -149,6 +149,15 @@ 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; + } + auto *ptr = const_cast(store); + X509_STORE_up_ref(ptr); + return ptr; +} + void X509_STORE_free(X509_STORE *vfy) { if (vfy == nullptr) { return; diff --git a/third_party/boringssl/src/crypto/x509/x509_mtc.cc b/third_party/boringssl/src/crypto/x509/x509_mtc.cc index 989dd42..abbbbb4 100644 --- a/third_party/boringssl/src/crypto/x509/x509_mtc.cc +++ b/third_party/boringssl/src/crypto/x509/x509_mtc.cc @@ -163,6 +163,7 @@ class MTCCACosigner { CBS seq, log_hash; if (!CBS_get_asn1(&ext_value, &seq, CBS_ASN1_SEQUENCE) || // + CBS_len(&ext_value) != 0 || // !CBS_get_asn1_element(&seq, &log_hash, CBS_ASN1_SEQUENCE) || // !x509_parse_algorithm(&seq, cosign_sigalg_.get()) || // !CBS_get_asn1_uint64(&seq, &min_serial_) || // @@ -544,9 +545,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_vfy.cc b/third_party/boringssl/src/crypto/x509/x509_vfy.cc index 90a9d1f..6ceaed3 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 @@ -828,24 +827,28 @@ static int get_crl_sk(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509 **pissuer, // 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; + 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; } @@ -902,93 +905,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) { 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,10 +971,10 @@ 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; } @@ -1089,13 +1051,6 @@ static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl) { } } - 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)) { return 0; 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/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..f92153d 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 diff --git a/third_party/boringssl/src/include/openssl/base.h b/third_party/boringssl/src/include/openssl/base.h index 83cc91b..cb63423 100644 --- a/third_party/boringssl/src/include/openssl/base.h +++ b/third_party/boringssl/src/include/openssl/base.h @@ -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; 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/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/dsa.h b/third_party/boringssl/src/include/openssl/dsa.h index fff5b76..3ae4d11 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. diff --git a/third_party/boringssl/src/include/openssl/ec_key.h b/third_party/boringssl/src/include/openssl/ec_key.h index 1480520..d894a67 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); 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/pool.h b/third_party/boringssl/src/include/openssl/pool.h index 23f8c44..6eb759c 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 diff --git a/third_party/boringssl/src/include/openssl/prefix_symbols.h b/third_party/boringssl/src/include/openssl/prefix_symbols.h index a328dfc..58f1fa8 100644 --- a/third_party/boringssl/src/include/openssl/prefix_symbols.h +++ b/third_party/boringssl/src/include/openssl/prefix_symbols.h @@ -615,9 +615,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) @@ -733,6 +738,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 +824,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 +1064,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 +1074,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) @@ -1766,6 +1775,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 +1909,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 +1949,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) @@ -2111,12 +2122,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) @@ -2769,6 +2782,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) @@ -3765,9 +3779,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) @@ -3883,6 +3902,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 +3988,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 +4228,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 +4238,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) @@ -4916,6 +4939,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 +5073,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 +5113,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) @@ -5261,12 +5286,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) @@ -5919,6 +5946,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..1abc611 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. 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/x509.h b/third_party/boringssl/src/include/openssl/x509.h index 0ef08e6..7e70ca2 100644 --- a/third_party/boringssl/src/include/openssl/x509.h +++ b/third_party/boringssl/src/include/openssl/x509.h @@ -2311,8 +2311,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 +2800,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); @@ -5316,8 +5318,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) @@ -5350,7 +5354,7 @@ 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..a2074dd 100644 --- a/tool/REVISION +++ b/tool/REVISION @@ -1 +1 @@ -e98a6564575520260ef95b2389e5d63a24917093 +3fed4f207543470b3d639db6ed40737e30308b51