9192 Commits
Author SHA1 Message Date
David Benjamin 40e035a9e5 Clear the extension list when removing the last extension
The extensions list in a certificate, CRL, and CRL entry is defined as:

... extensions      [3]  EXPLICIT Extensions OPTIONAL ...
... crlEntryExtensions      Extensions OPTIONAL ...
... crlExtensions           [0]  EXPLICIT Extensions OPTIONAL ...

Extensions  ::=  SEQUENCE SIZE (1..MAX) OF Extension

This means that a present but empty extensions list is actually invalid.
Rather, if you have no extensions to encode, you are meant to omit the
list altogether. Fix the delete_ext functions to handle this correctly.

Bug: 442221114
Change-Id: I92af89d3e7120e06489359b3c6e2af499ecf5b85
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81751
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2025-09-01 09:16:47 -07:00
David Benjamin dba32d768e Refresh basic constraints test certificates
Older versions of Go did not encode extension-less certificates
correctly. See https://go-review.googlesource.com/c/go/+/399827

Rerun the script now that the bug is fixed.

Bug: 442221114
Change-Id: I121fe3120d933a0a8fcaf1757cf9f49f014ee710
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81750
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2025-09-01 09:16:42 -07:00
David Benjamin 087d397a93 Document ASN1_item_sign's order of operations a bit
Every time I touch this function, I forget that the algorithm update
actually impacts the serialization.

Change-Id: I8d484f9616d01a6ddd1ad428b01ac4bc922800ab
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81749
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2025-09-01 09:12:56 -07:00
David Benjamin 28e46225a7 Add a few more TODOs for functions that should be const but aren't
Mostly so we don't forget to const them when X509_NAME is finally fixed.

Bug: 42290269
Change-Id: I78a8b31d9b846669db1ba2e98133203e5be24949
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81748
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2025-09-01 09:07:26 -07:00
David Benjamin 50e28f5afc Use the new SPKI API in d2i_RSA_PUBKEY and friends
These functions only need to pull in the algorithms they support. The
new API is slightly less friendly in this context because it expects the
caller to have found the end first, but it's easy enough to to write a
small wrapper.

Bug: 42290364
Change-Id: Ibdc44f399182cd5722700917aec6c151221f4674
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81747
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2025-09-01 08:49:59 -07:00
David Benjamin 85c1fe0b6b Unexport a few more ASN1_ITEMs
Update-Note: ASN1_TIME, DIRECTORYSTRING, and DISPLAYTEXT are no longer
usable in custom macro-based ASN.1 types using <openssl/asn1t.h>. There
do not seem to be any external callers that depend on this.

If this sticks then, after all the built-in types are rewritten, we may
be able to remove MSTRING from tasn_* altogether!

Bug: 42290417
Change-Id: Ia12d8767bcada8eda75550e13bbab5a4a572382c
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81729
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2025-08-31 19:29:51 -07:00
David Benjamin 7c1863dcb7 Make some test data of unknown ASN.1 types slightly less invalid
EXTERNAL, EMBEDDED PDV, and CHARACTER STRING are actually constructed!
They're encoded as some implicitly-tagged SEQUENCE. I couldn't be
bothered to fill in valid contents thought.

While I'm here, make RELATIVE-OID non-empty. That is the most likely new
type for us to pay attention to here, just because we borrowed them for
trust anchor IDs. (I'm not totally clear on whether the empty relative
OID is a valid relative OID. Meh.)

Change-Id: I193e5fb800d317cad8711a09078ac15adf80d76a
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81728
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-31 19:29:40 -07:00
David Benjamin 074b6dad0c Test ASN1_TYPE parsing more extensively
We should be able to parse a variety of valid types, and also reject
syntax errors in any types that we recognize. Also double-check that
nothing went wrong in the translation from i2d_ASN1_TYPE to X509_ALGOR
(basically the only use of ASN1_TYPE in the library).

Change-Id: I825f44c35a7e8ea6374641cf5e0ea5daaf471ad7
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81727
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2025-08-31 19:21:19 -07:00
David Benjamin 208361a22e Add EVP_PKEY_ALG-based raw public/private key importers
Keeping it to X25519/Ed25519 for now, but arguably we could pick "raw"
options for most of our keys. The problem is just when there's a couple
different options. (ECPrivateKey or just the serialized scalar for EC
keys, compressed vs uncompressed points.)

Bug: 42290364
Change-Id: I1e1a0a3fa971f27a962946301091ebe11bac2725
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81667
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2025-08-28 12:30:53 -07:00
David Benjamin 74c3b4b7fd Use EVP_PKEY_bits in SimplePathBuilderDelegate
No need to dip out of EVP for this one.

Change-Id: Ide03d28edd5316addbb9051d527fec23ace259ba
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81660
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-28 12:30:47 -07:00
David Benjamin 92ae3b9b6e Update citations from RFC 3447 to RFC 8017
Change-Id: Ie3ab169e5bde403382eb0edbe9e774aba2a23692
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81659
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2025-08-28 12:24:07 -07:00
David Benjamin 815fec1839 Replace OPENSSL_ARRAY_SIZE with std::size
In the STL, <iterator> has a std::size for arrays. Some of these could
also just be ranged for loops. One static_assert could not use
std::size(out->whatever) because out was not a compile-time value, but
std::extent_v<decltype(out->whatever)> works instead.

Change-Id: I28007c79f5583e09167b81a34a447e205ee6dd9b
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81658
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-28 12:22:59 -07:00
David Benjamin 42dea116cf Const-correct the kPrintMethods table
Change-Id: I002e9e37b77c2e63d6d6df3833b936f21eaec4d7
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81657
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2025-08-28 12:22:49 -07:00
David Benjamin be4e218c9e Add SHA-256-only support for EVP_PKEY_RSA_PSS
While, in principle, PSS is better than PKCS#1 v1.5, and
algorithm-specific keys are better than mixing them up, RSASSA-PSS was
so badly mis-standardized in RFC 3447 and RFC 4055 that this is not
worth it. Any marginal benefits one might get from PSS is completely
overshadowed by the mountain of unforced errors those two RFCs made.
Applications are better off just using ECDSA.

Nonetheless, it is a thing we are now supporting. Add off-by-default
support for EVP_PKEY_RSA_PSS, only using the SHA-256 parameter set. In
OpenSSL's implementation, the underlying RSA object stores an
RSA_PSS_PARAMS, though the RSA-level APIs don't enforce the parameters,
only the EVP-level APIs do. For now, since the SHA-256 parameters are
the only ones we support, I have not bothered adding extra state to the
RSA object. If we need to add more parameters, we can store the
rsa_pss_params_t enum on the RSA object. (Preferably after we've split
the BCM and non-BCM halves of the RSA object.)

This support is off by default and must remain so. We have a bit of a
mess API-wise: OpenSSL made EVP_PKEY_get0_RSA work with
EVP_PKEY_RSA_PSS. This is plausible in that applications may want to
inspect RSA components and that is, for now, the API to do so. However,
existing callers generally assume a non-NULL EVP_PKEY_get0_RSA return
implies EVP_PKEY_RSA. Changing this will break those callers.

Thus the opt-in not only limits a badly-designed key type, but also
prevents existing callers from being exposed to this unexpected state.

These keys are not wired up to libssl and we have no plans to do so.

Bug: 384818542
Change-Id: I4d99be86ce1d891a2e50335ef097913707ede55a
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81656
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-28 12:02:37 -07:00
David Benjamin caf92ce446 Write a CBS-based RSA-PSS parameter parser
For now this is just used by the X.509 verification logic and supports
the three sets of parameters we accept. Later EVP_PKEY_RSA_PSS will use
the same parser.

Bug: 384818542
Change-Id: I4d9a83283cbf239268f37d814f00d0b6ec3b46f2
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81655
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-28 11:26:48 -07:00
David Benjamin b0e18ff06e Switch libssl to the new SPKI parsing APIs
Bug: 42290364
Change-Id: I91bc1950e5759c5267131fc0bc301104aeca7d7b
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81654
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-28 10:12:43 -07:00
David Benjamin 9cda5e2023 Switch libpki to the new SPKI-parsing APIs
For now this uses a hardcoded, but smaller, list of accepted algorithms.
Ideally we'd get the algorithms from the caller, via the same APIs that
limit acceptable keys.

Bug: 42290364
Change-Id: Ife60a841f836d1a67cf8daea30f5b961a3ba32ff
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81653
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-28 10:12:38 -07:00
David Benjamin 50d8772137 bssl-crypto: Switch to new SPKI/PKCS8 parsing APIs
These work much better for what bssl-crypto wants to do because we won't
forget to check the key type.

Bug: 42290364
Change-Id: I3250258e4935700f82eb196516dd4eda1766ce95
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81652
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-28 10:10:34 -07:00
David Benjamin 96c2425224 Introduce EVP_PKEY_ALG
This adds new SPKI and PKCS#8 parser entrypoints that pass in the list
of allowed algorithms. Algorithms are expressed as EVP_PKEY_ALG
functions and roughly things that can create EVP_PKEYs in various ways.
(Right now just SPKI and PKCS#8 parsers, but I'm imagining that they'll
also be the handle for the "raw" public/private key parsers and things
like the list of curves for ECPrivateKey or X9.62 points.)

The immediate motivation is to give a handle for opting into
EVP_PKEY_RSA_PSS (we don't want most applications to be exposed to
those), but I'm hoping this can also:

- Let us add legacy or experimental algorithms for one caller without
  worrying about exposing all callers to them.

- Let size-constrained applications use EVP without worrying about
  binary size.

- Reduce the need for people to check the key type after parsing keys. I
  would like to it eliminate the need, but RSA having a continuum of
  sizes makes things tricky. For now, EVP_pkey_rsa() just accepts all
  supported RSA sizes (512 through 8192, but hopefully we can clamp it
  down).

While we're here, correct what, in hindsight, were I think some missteps
in the EVP_parse_public_key convention:

- Not saying the name of the format in the function name. Since I expect
  we'll add EVP_PKEY_from_ec_private_key, EVP_PKEY_from_rsa_private_key,
  etc., functions to start filling out EVP, having the name of the
  format would have been nice.

- Taking an in/out CBS parameter. As an in/out parameter, we don't check
  trailing data and just pass it to the caller to check. This optimized
  for parsing an SPKI inside a structure, rather than standalone. In
  practice, folks forget to check trailing data.

In comparison to OpenSSL 3.x, I think an EVP_PKEY_ALG is roughly an
OSSL_KEYMGMT, but that's a very confusing name. Maybe also with bits of
the OSSL_DECODER in there. Mostly I don't understand their very
complicated (and apparently quadratic-time) decoder system.

OpenSSL 3.x also has an OSSL_LIB_CTX which has been threaded into a
bunch of objects. Having BoringSSL's OSSL_LIB_CTX carry a list of these
things would be plausible, but different call sites within a single
application may support different algorithms, so let's start with the
explicit list approach and see where we go from there.

Bug: 42290364
Change-Id: I342603efdc167c8f587357d17800d7ad545d5908
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81651
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2025-08-28 10:03:48 -07:00
David Benjamin b402cff383 Add internal EC parsing functions that take lists of allowed groups
They're internal for now; I'm thinking we'll just have the public
versions of these at the EVP layer for now and try to move past this
mess where there's two versions of every API.

The API is mildly annoying in that both this caller and the one added
next will want to distinguish UNKNOWN_GROUP from other errors, but the
recent helper function makes checking the error queue not tooooo bad.

Bug: 42290364
Change-Id: Ibb5e3e643a9180459cc09b4559ee40696cea2688
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81650
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-28 09:55:01 -07:00
David Benjamin 136d6b7f61 Test lookup and creation by RSA parameters in evp_test
In preparation for when we add RSA-PSS and want to test that those also
import properly.

Change-Id: I50d35d0bbd0d2240a7609d9efa828578360969d4
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81649
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
2025-08-27 14:08:04 -07:00
Andres Erbsen 1a1ec90270 bump fiat-crypto (remove redundant return statements)
Change-Id: I72b27357ce3611d9dd1c1c799222106a18470a14
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81707
Auto-Submit: Andres Erbsen <andreser@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-27 09:33:38 -07:00
David Benjamin 5c2bd0ab04 Make FileTest work with std::string_view
Change-Id: I036153287e133917464ec9066cf2b5becd178dea
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81648
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-27 07:31:31 -07:00
David Benjamin afb970dea4 Test key import in EVPTest a bit more extensively
Between the "raw" import and what'll soon be a few parsing entrypoints,
we'll have a few different ways to make keys. Rather than importing one
key and then checking properties, this function is now meant to describe
properties of a key and then:

- For each set of properties that is enough to construct a key,
  construct that key.

- For each key that was constructed, check all properties apply to that
  key.

Rather than having ExpectNo* attributes, let's just say that if you omit
the raw public/private key, the expectation is that you don't have one.
I've also dropped "Expect" on the positive cases because it is now both
a property to check and a way to construct the key.

We've since added a few properties of keys that aren't curently
well-tested, so go test those. This revealed that actually the DSA test
vectors were misnamed. The test public key didn't correspond to the test
public key and they were of different sizes.

I tried to test the EC point format getting but ran into
https://crbug.com/441087671, so I'm going to just ignore this for now.

Change-Id: I5a0432061e33fcc92f790023ad40019e8eaf27c1
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81647
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-27 07:31:25 -07:00
Takuto Ikuta 51ed8ad6b7 infra/config: Remove luci.recipes.use_python3 experiment
Python3 is used by default in recipes now and this config is not
necessary anymore.

Bug: 440235171
Change-Id: I723dc493872bcafc2f88ae9cae5d90b1f251e397
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81687
Reviewed-by: David Benjamin <davidben@google.com>
Auto-Submit: Takuto Ikuta <tikuta@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-27 07:26:18 -07:00
David Benjamin 7091d0949c Add an ERR_equals function
Checking for an error on the error queue is very tedious. You have to
check both library and reason code separately, which often means you
need to save the error code to a local variable.

Make an ERR_equals function. I've gone ahead and just made it public API
because even within BoringSSL, it seems to come up everywhere.

Change-Id: Ia963c9ae743ac5c6939846f8f64bbc98b495ce0b
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81627
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
2025-08-25 16:00:23 -07:00
Adam Langley f8c5f5668d Add utility for dumping raw jitter samples.
Change-Id: Idafa206d2d8b6e36d4e8333fba1bf96208fec2a9
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/80927
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2025-08-25 11:30:36 -07:00
David Benjamin e4fa20e7ad Use inline asm to read cntvct_el0 to accommodate GCC
The safer instrinsics-based pattern isn't GCC-compatible, because GCC
added the intrisc some 8 years later than Clang did.

Bug: 440670941
Change-Id: I3db3ef2393b21aae8427457a3c26b62993b75eaa
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81607
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2025-08-25 10:37:10 -07:00
David Benjamin 26e8a8acb9 bssl-crypto: Fix Ed25519 SPKI parser to check key types
Otherwise it mistakenly interprets an X25519 SPKI as an Ed25519 key.
Once that is fixed, a number of these error conditions are impossible.

Change-Id: Iffd116252f1f632f8f917c56b1676069686eddbf
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81587
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-22 16:07:22 -07:00
Adam Langley edb1440439 Add a jitter entropy source.
This code is not yet used outside of tests.

Change-Id: I825b7c8692985219021ef5ecf5b84ebfe8624e74
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/80367
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2025-08-22 13:04:39 -07:00
David Benjamin b0ef87e5e3 Set an EVP_PKEY's algorithm and data together
We internally half-initialize EVP_PKEYs everywhere, but there are very
few places where we actually need to half-initialize them.

This changes most of the EVP_PKEY_ASN1_METHOD callbacks so that output
EVP_PKEYs are not half-initialized with the method first. Rather, the
callback is expected to fill in the method and contents together.

EVP_PKEY_copy_parameters remains as a goofy exception because it's an
in-out parameter. In principle, it is possible to have a goofy
parameter-less, key-only DSA object, and we need to fill in the
parameters later. This was due to how DSA was embedded into X.509. But
we don't support DSA in X.509 and we removed this parameterless state
from the parser, so we probably can remove this now. (I've left it as-is
for now.)

Bug: 42290409
Change-Id: I2a576571d75ce755fd7e963be467aa5d94f20466
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81550
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Lily Chen <chlily@google.com>
Commit-Queue: Lily Chen <chlily@google.com>
2025-08-22 13:04:12 -07:00
David Benjamin 5b7171f2da Make some more half-empty EVP_PKEY states impossible
EVP_PKEY_{assign,set1}_FOO would check for NULL, return an error, but
still leave the EVP_PKEY assigned to that type on failure. Check for
NULL first, so that we don't leave it in that state.

I originally did this with a slightly more ambitious goal of also
banning EVP_PKEY_set1_EC_KEY if the EC_KEY has no parameters. That was
so that, in the happy future where we have EVP_PKEY_ALGs for P-256 and
P-384, EVP_PKEY_ASN1_METHOD would simply be renamed EVP_PKEY_ALG and
every key would have an associated EVP_PKEY_ALG.

For that to work, EVP_PKEY_set1_EC_KEY must never be ambiguous about
which EVP_PKEY_ALG to associate with the EVP_PKEY.

However, the existence of custom EC_GROUPs throws a spanner in that.
We need to support EVP_PKEY_set1_EC_KEY with an custom EC_GROUP (at
least until we manage to get Conscrypt to stop using this function). So,
at least for now, I'm thinking we say that EVP_PKEY_ALGs point to
EVP_PKEY_ASN1_METHODs but you can't go from EVP_PKEY back to
EVP_PKEY_ALG, and we'll see how irksome of an API that becomes.

(We can always go back to this idea later. The custom EC_GROUPs thing
isn't fatal if EC_KEYs with funny EC_GROUPs map to some goofy private
EVP_PKEY_ALG that can't parse anything.)

Still, half-empty states are generally bad, so I'm going to keep this
change on the branch and see if we can get it to stick.

Update-Note: Some half-empty, invalid EVP_PKEY states are now
impossible. Running through tests, no callers were tripping this. There
seems to be no legitimate reason to do this.

Bug: 42290409
Change-Id: I0211a38ab62268a05e3ff1d138a092e4feec10b1
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81549
Reviewed-by: Lily Chen <chlily@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-22 11:29:50 -07:00
David Benjamin 9b602f2d91 Limit EVP_PKEY_set_type to EVP_PKEY_X25519
Per the docs, the only real use case is setting EVP_PKEY_X25519. Outside
BoringSSL, the one caller using other key types to make test keys has
since been fixed. One call to EVP_PKEY_set_type(EVP_PKEY_NONE) remains,
but this CL does not break it.

This removes one path to making this flavor of half-empty keys for all
but X25519, where we're forced to have such keys for OpenSSL
compatibility.

Update-Note: EVP_PKEY_set_type will now only succeed for
EVP_PKEY_X25519. EVP_PKEY_set_type(EVP_PKEY_NONE) will continue to clear
the pkey and then fail. Going through code search, there are not
expected to be any affected callers.

Bug: 42290409
Change-Id: I20ca762be71f71a628f5894045e5b66b7773c215
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81548
Reviewed-by: Lily Chen <chlily@google.com>
Commit-Queue: Lily Chen <chlily@google.com>
2025-08-21 15:06:00 -07:00
David Benjamin 4d48736c2a Add a test that arbitrary curves can be wrapped in EVP_PKEY
Conscrypt relies on both this working at the EC_KEY level, but also
EVP_PKEY. Make sure this keeps working, even as we mess around with
EVP_PKEY's EC bits to separate the curves out.

While I'm here, move the common HexToBIGNUM wrapper into test_util.h.

Bug: 42290364
Change-Id: I58fa5a8487b8a499000a798040a53fc851b0a732
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81547
Reviewed-by: Lily Chen <chlily@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-21 14:42:26 -07:00
David Benjamin 5dc17fad95 Stop tracking an ENGINE in EVP_PKEY_CTX
We don't use this field. We just save what the caller passed in and then
ignore it.

Change-Id: I962b7bfbc9aa7cec70244acd2b13ccfa21e53575
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81528
Commit-Queue: Lily Chen <chlily@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Lily Chen <chlily@google.com>
2025-08-21 14:38:42 -07:00
David Benjamin b62f30a74b Rename EVP_PKEY_METHOD to EVP_PKEY_CTX_METHOD
EVP_PKEY_ASN1_METHOD is really EVP_PKEY_METHOD and EVP_PKEY_METHOD is
really EVP_PKEY_CTX_METHOD.

Change-Id: I9445fd12dcf99634a906726d1a42586c1dc7146e
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81527
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Lily Chen <chlily@google.com>
Commit-Queue: Lily Chen <chlily@google.com>
2025-08-21 13:59:52 -07:00
David Benjamin 04eb147f75 Pull the EC_GROUP_new_by_curve_name up into EVP_PKEY_CTX_set_ec_paramgen_curve_nid
ec_pkey_meth, and thus every all of EC EVP_PKEY logic, currently depends
on all supported curves by way of EC_GROUP_new_by_curve_name. In
reality, the only call pattern which depends on every curve is
"paramgem", when callers do:

    EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, nullptr);
    EVP_PKEY_paramgen_init(ctx);
    EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, NID_X9_62_prime256v1);
    EVP_PKEY_paramgen(ctx, &key);

This is a really roundabout way to get at a basically static object. EVP
is kinda cumbersome. The other pattern is keygen when you don't already
have an object that represents the curve, since OpenSSL does not provide
such a thing.

    EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, nullptr);
    EVP_PKEY_keygen_init(ctx);
    EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, NID_X9_62_prime256v1);
    EVP_PKEY_keygen(ctx, &key);

That one is harder to avoid because EVP does not provide a better way to
do this. Ideally our API would look more like
EVP_generate_ec_key(EC_group_p256()), or perhaps
EVP_PKEY_generate(EVP_pkey_ec_p256()) or something.

Either way, we can lift the dependency to
EVP_PKEY_CTX_set_ec_paramgen_curve_nid which is the function that
actually pulls in all curves, and then folks who don't use that pattern
aren't impacted. The other thing I considered was to make
EVP_PKEY_CTX_new_id(EVP_PKEY_EC) use a different method table from
EVP_PKEY_CTX_new(pkey), but this was really easy.

(We can do this because our EVP_PKEY_CTRL_* constants are completely
internal. We don't have to implement the same hooks that upstream does.)

Bug: 42290364
Change-Id: Ib223b966d1a48527088e1bb13435ac6dc2c11749
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81509
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Lily Chen <chlily@google.com>
Commit-Queue: Lily Chen <chlily@google.com>
2025-08-21 13:20:27 -07:00
David Benjamin 57a6e5dfd1 Split evp_tests.txt into separate files
It's getting a bit large. rsa_tests.txt is unfortunately still kind of
large, but we can't easily split that up because the test vector
framework is slightly stateful. (The key parsing tests remember all
parsed keys so that they can be used later by the operation tests.)

Change-Id: I62b669814c04fbe5aba7a9e4f8614e39550a3d7a
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81508
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: Lily Chen <chlily@google.com>
Reviewed-by: Lily Chen <chlily@google.com>
2025-08-21 13:20:16 -07:00
David Benjamin e363befd68 Add a test for SPKI and PKCS8 parsing with unknown algorithms
In particular, EVP_parse_public_key was written to avoid checking for a
whole number of bytes until *after* we've recognized the OID. This is
almost certainly not worth the effort, but I suppose if we tried to do
that, we should test it.

Why X.509 decided SPKIs use BIT STRINGs instead of OCTET STRINGs, who
knows.

Change-Id: Ib18887c6bed2dbbd3407de262b4912ad38ccf9dd
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81507
Reviewed-by: Lily Chen <chlily@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-21 13:09:52 -07:00
Lily Chen 308b43646c Fix markdown syntax in BUILDING.md
Change-Id: Ieb0cb854013f81a0c0ea222d1fe1dbf9adcdab27
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81447
Auto-Submit: Lily Chen <chlily@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-21 09:28:58 -07:00
David Benjamin 908bdb84c5 Test async BIO_flush and fix a corner case
We were simulating non-blocking writes, but not non-blocking flush.
Model it as consuming one byte in AsyncBio.

In doing so, fix an obscure corner case in DTLS: If flushing after ACK
blocked, the next try would write a new ACK to the transport. There's no
real harm in this (we're running over UDP), but our tests intentionally
check for exactly the right number of writes and this was easy to fix.

This completely doesn't matter as a non-blocking writes on UDP-like
sockets are not really a thing, much less buffered non-blocking writes
on them. I don't even concretely know of anyone relying on BIO_flush in
TCP-like BIOs anymore in libssl. But since we try to support it, we
should test that we get it right.

Fixed: 381906252
Change-Id: I5296fcb01ca409d3026ca1150d6bdeaccc868014
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81348
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Lily Chen <chlily@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-08-19 11:13:18 -07:00
David Benjamin 729648fb79 Rename EVP_R_EXPECTING_AN_EC_KEY_KEY to match OpenSSL
EC_KEY_KEY looks very silly. In OpenSSL, this is
EVP_R_EXPECTING_A_EC_KEY. It's a little odd that they say "a EC key"
instead of "an EC key", but ah well. (They do say "an RSA key".) May as
well match.

Update-Note: Code search finds no references to the BoringSSL name, so
this is not expected to impact anything.

Change-Id: I7563645fd269e4a62fbc46de2647f06bde00e1e4
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81428
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: Lily Chen <chlily@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Lily Chen <chlily@google.com>
2025-08-18 16:36:18 -07:00
David Benjamin 716f066168 Document the generators for all the MODP groups
Saves the trouble of looking them up. Every group in RFC 3526 has
generator 2.

Change-Id: I58ec06510a6ca22a3bce03186e6eb7a510c7948e
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81427
Commit-Queue: Lily Chen <chlily@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Lily Chen <chlily@google.com>
2025-08-18 16:27:50 -07:00
David Benjamin eb895133fb Remove an old, impractical TODO
Given OpenSSL puts it all in one header, I don't think we can ever make
<openssl/evp.h> stop including <openssl/digest.h>. Best we can do is
move the public/private key stuff into its own header and make
<openssl/evp.h> be the compat one.

Change-Id: I60310630657513a1cb410cd401ae7e80b1c16913
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81408
Commit-Queue: Lily Chen <chlily@google.com>
Reviewed-by: Lily Chen <chlily@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
0.20250818.0
2025-08-18 14:44:53 -07:00
David Benjamin 505aa91a0d Say a bit more in docs about how to use EVP_PKEY_CTX
We also should say *somewhere* what the algorithm-specific behavior for
each operation is, but this at least gets the general framework down in
the section header.

Change-Id: I9e81e5a0da528aa3d0c3f53421d3b9df3cf813ec
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81407
Reviewed-by: Lily Chen <chlily@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: Lily Chen <chlily@google.com>
2025-08-18 14:44:27 -07:00
David Benjamin 2c8fdd5919 Bump version for BCR
Change-Id: Iab3e25d428bd1c77c69571d8e39aa950ca05f925
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81387
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Lily Chen <chlily@google.com>
Commit-Queue: Lily Chen <chlily@google.com>
2025-08-18 14:35:01 -07:00
David Benjamin e3727310c6 Run through more code in PKCS#8 and SPKI parsers
Bug: 438886851
Change-Id: I10f2575889135b94b5a5104a44568e3ac39b442c
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81369
Commit-Queue: Lily Chen <chlily@google.com>
Reviewed-by: Lily Chen <chlily@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
2025-08-18 14:34:11 -07:00
David Benjamin 4d0dfef2f0 Fix typo in comment
Change-Id: Idfc5c5a024ca12de73993ea44399d3bfc78b1696
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81388
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Lily Chen <chlily@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Commit-Queue: Lily Chen <chlily@google.com>
2025-08-18 13:07:22 -07:00
David Benjamin cd033d7e12 runner: Remove need for an AllCurves value
Among other things, this shortcut meant that every curve test explicitly
configures every other curve, but only the curve under test needs to be
configured.

Change-Id: If21dcd997c78c6a02dab30aa16259c60ea7f479b
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81347
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Lily Chen <chlily@google.com>
Commit-Queue: Lily Chen <chlily@google.com>
2025-08-18 13:00:05 -07:00
David Benjamin 5f0c7cdfbb Remove redundant copy of EVP_PKEY type
pkey->type and pkey->ameth->pkey_id are always synchronized with each
other. No sense in holding on to both.

Change-Id: Ibd447d31cd12946380e5c66ace1020048a8104e7
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81308
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Lily Chen <chlily@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
2025-08-18 12:41:59 -07:00