12725 Commits

Author SHA1 Message Date
Brian Smith
ba1c0f5934 Ignore BoringSSL '41eb357'..'dd81bf7'. 2023-09-24 15:42:15 -07:00
Brian Smith
20b1810a3b Merge BoringSSL '0faffc7': Fix the comment in ecp_nistz256_ord_sqr_mont to match code and prototype. 2023-09-24 15:40:07 -07:00
Brian Smith
6874e555a5 Ignore BoringSSL '361e3e0'..'6b785f6'. 2023-09-24 15:36:50 -07:00
Brian Smith
00401a0afe Skip BoringSSL '91e0b11'. 2023-09-24 15:33:18 -07:00
Brian Smith
97a526c010 Merge BoringSSL '1b2b7b2': Various -Wshorten-64-to-32 fixes. 2023-09-24 15:31:41 -07:00
Brian Smith
b08f7da343 Ignore BoringSSL 'fd52296'..'bbd9f18' 2023-09-24 15:27:42 -07:00
Brian Smith
75d34bc1a8 Merge BoringSSL 7b2795a: Replace even more ad-hoc bytes/integer conversions. 2023-09-24 15:26:51 -07:00
Brian Smith
946731e6d0 Ignore BoringSSL 'f4cdf91..9f426b6'. 2023-09-24 15:05:18 -07:00
Brian Smith
7e7d44c0ec No=op merge of BoringSSL '5c2ef10'. 2023-09-24 15:00:04 -07:00
Brian Smith
6afe1dd20a Ignore BoringSSL 28883d4..2cc2aa9. 2023-09-24 14:54:18 -07:00
Brian Smith
ad59665506
Merge pull request #1650 from briansmith/b/merge-boringssl-10
Merge BoringSSL through 4d7b383e989eff619a60eb1da1b18f613af65daf
2023-09-23 20:28:49 -07:00
Brian Smith
65fb8b80f9 Ignore BoringSSL 'fdeb4aa..4d7b383'. 2023-09-23 15:50:16 -07:00
Brian Smith
5233928eb9 Take BoringSSL '0378578': Dedup a few more load/store implementations. 2023-09-23 15:48:18 -07:00
Brian Smith
6ccdf7bd12 Merge BoringSSL '6c2af68': Remove a few more unions. 2023-09-23 15:12:24 -07:00
David Benjamin
584f1e1016 Cherry-pick BoringSSL ca45987: Move load/store helpers to crypto/internal.h.
These are needed for the next merge from BoringSSL.
2023-09-23 15:03:59 -07:00
Brian Smith
6e9f1b7d8a
Merge pull request #1648 from briansmith/b/merge-boringssl-9
Merge BoringSSL through 0f2c55cb748651833af247bbed43e.
2023-09-21 09:54:42 -07:00
printfn
20ba41d67e Fix broken URL in PKCS#8 docs 2023-09-19 10:19:14 -07:00
Brian Smith
c9fd0ba48f NFC: Remove unneeded #cfg(...) in digest_tests.rs
The code is always enabled since "wasm32" was spelled wrongly. Apparently
the wasm-bindgen compatibility issue is no longer an issue.
2023-09-19 10:16:01 -07:00
Nikolay Arhipov
4983338b68 PS Vita support 2023-09-19 08:35:58 -07:00
Brian Smith
f812f37aba Merge commit '0f2c55cb748651833af247bbed43e' into b/merge-boringssl-9.
Take the changes from BoringSSL, except use `limbs_copy` and `limbs_zero`.
2023-09-18 17:53:44 -07:00
Brian Smith
7cf6516da2 Ignore BoringSSL `41eb890..e3ebb9e'. 2023-09-18 17:19:56 -07:00
David Benjamin
a1843d660b Bump the minimum CMake version to 3.12
CMake 3.12 was released July 2018, so it meets our five year rule. [0]
also requires a CMake version newer than 3.12.

[0] https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md

Change-Id: I2b21d68e3a379108edde9c7d13450bba52f41235
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/63105
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
2023-09-18 22:22:58 +00:00
David Benjamin
340fe150b7 CMake doesn't have an error function
Instead the spelling is message(FATAL_ERROR "blah"). Although
error("blah") also works because it just complains that error doesn't
exist.

Change-Id: I80384e0198a9013f93f9403d0a4c256749905045
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/63106
Reviewed-by: Bob Beck <bbe@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
2023-09-18 21:15:53 +00:00
Brian Smith
e48fdcf782
Merge pull request #1645 from briansmith/b/merge-boringssl-8
Merge BoringSSL through 167f1760ddfeaea1ee1a671ca88aafcccfe30ee0
2023-09-17 12:17:58 -07:00
Brian Smith
ba41827040 Ignore BoringSSL '0ebd69b..167f176'. 2023-09-17 12:03:28 -07:00
Brian Smith
29b441cee1 No-op merge of BoringSSL 'efd09b7'.
This was already done in *ring*'s Rust code.
2023-09-17 12:02:20 -07:00
Brian Smith
c8bbdf9567 Ignore BoringSSL `572c416..d27a01e' 2023-09-17 12:01:04 -07:00
Brian Smith
98ae3272e7 Skip BoringSSL '1e469e4': Replace some more C unions.
None of the changes seem useful to *ring* due to previous oxidation.
2023-09-17 12:00:24 -07:00
Brian Smith
ce97384c1a Ignore BoringSSL 8ba90d1..f575d9b. 2023-09-17 11:45:08 -07:00
Brian Smith
e11e97ea82 No-op merge of BoringSSL 'b8a6514'.
*ring* doesn't use RSAZ. *ring* already uses this simpler loop.
2023-09-17 11:42:50 -07:00
Brian Smith
73d9069605 No-op merge of BoringSSL 'c7de4fe'.
*ring*'s Rust code already did this.
2023-09-17 11:42:01 -07:00
Brian Smith
106235e3e3 No-op merge of BoringSSL 801a801: Add an extra reduction step to the end of RSAZ.
The test case that is enabled in the merged BoringSSL change was already enabled in
*ring*, so nothing changed regarding the test cases. *ring* doesn't use RSAZ.

```
git difftool \
    801a801:crypto/fipsmodule/bn/bn_tests.txt \
    .\src\arithmetic\bigint_elem_exp_consttime_tests.txt
```
2023-09-17 11:41:53 -07:00
David Benjamin
76e98c4351 Always end BN_mod_exp_mont_consttime with normal Montgomery reduction.
This partially fixes a bug where, on x86_64, BN_mod_exp_mont_consttime
would sometimes return m, the modulus, when it should have returned
zero. Thanks to Guido Vranken for reporting it. It is only a partial fix
because the same bug also exists in the "rsaz" codepath. That will be
fixed in the subsequent CL. (See the commented out test.)

The bug only affects zero outputs (with non-zero inputs), so we believe
it has no security impact on our cryptographic functions. BoringSSL
calls BN_mod_exp_mont_consttime in the following cases:

- RSA private key operations
- Primality testing, raising the witness to the odd part of p-1
- DSA keygen and key import, pub = g^priv (mod p)
- DSA signing, r = g^k (mod p)
- DH keygen, pub = g^priv (mod p)
- Diffie-Hellman, secret = peer^priv (mod p)

It is not possible in the RSA private key operation, provided p and q
are primes. If using CRT, we are working modulo a prime, so zero output
with non-zero input is impossible. If not using CRT, we work mod n.
While there are nilpotent values mod n, none of them hit zero by
exponentiating. (Both p and q would need to divide the input, which
means n divides the input.)

In primality testing, this can only be hit when the input was composite.
But as the rest of the loop cannot then hit 1, we'll correctly report it
as composite anyway.

DSA and DH work modulo a prime, where this case cannot happen.

Analysis:

This bug is the result of sloppiness with the looser bounds from "almost
Montgomery multiplication", described in
https://eprint.iacr.org/2011/239. Prior to upstream's
ec9cc70f72454b8d4a84247c86159613cee83b81, I believe x86_64-mont5.pl
implemented standard Montgomery reduction (the left half of figure 3 in
the paper).

Though it did not document this, ec9cc70f7245 changed it to implement
the "almost" variant (the right half of the figure.) The difference is
that, rather than subtracting if T >= m, it subtracts if T >= R. In
code, it is the difference between something like our bn_reduce_once,
vs. subtracting based only on T's carry bit. (Interestingly, the
.Lmul_enter branch of bn_mul_mont_gather5 seems to still implement
normal reduction, but the .Lmul4x_enter branch is an almost reduction.)

That means none of the intermediate values here are bounded by m. They
are only bounded by R. Accordingly, Figure 2 in the paper ends with
step 10: REDUCE h modulo m. BN_mod_exp_mont_consttime is missing this
step. The bn_from_montgomery call only implements step 9, AMM(h, 1).
(x86_64-mont5.pl's bn_from_montgomery only implements an almost
reduction.)

The impact depends on how unreduced AMM(h, 1) can be. Remark 1 of the
paper discusses this, but is ambiguous about the scope of its 2^(n-1) <
m < 2^n precondition. The m+1 bound appears to be unconditional:

Montgomery reduction ultimately adds some 0 <= Y < m*R to T, to get a
multiple of R, and then divides by R. The output, pre-subtraction, is
thus less than m + T/R. MM works because T < mR => T' < m + mR/R = 2m.
A single subtraction of m if T' >= m gives T'' < m. AMM works because
T < R^2 => T' < m + R^2/R = m + R. A single subtraction of m if T' >= R
gives T'' < R. See also Lemma 1, Section 3 and Section 4 of the paper,
though their formulation is more complicated to capture the word-by-word
algorithm. It's ultimately the same adjustment to T.

But in AMM(h, 1), T = h*1 = h < R, so AMM(h, 1) < m + R/R = m + 1. That
is, AMM(h, 1) <= m. So the only case when AMM(h, 1) isn't fully reduced
is if it outputs m. Thus, our limited impact. Indeed, Remark 1 mentions
step 10 isn't necessary because m is a prime and the inputs are
non-zero. But that doesn't apply here because BN_mod_exp_mont_consttime
may be called elsewhere.

Fix:

To fix this, we could add the missing step 10, but a full division would
not be constant-time. The analysis above says it could be a single
subtraction, bn_reduce_once, but then we could integrate it into
the subtraction already in plain Montgomery reduction, implemented by
uppercase BN_from_montgomery. h*1 = h < R <= m*R, so we are within
bounds.

Thus, we delete lowercase bn_from_montgomery altogether, and have the
mont5 path use the same BN_from_montgomery ending as the non-mont5 path.
This only impacts the final step of the whole exponentiation and has no
measurable perf impact.

In doing so, add comments describing these looser bounds.  This includes
one subtlety that BN_mod_exp_mont_consttime actually mixes bn_mul_mont
(MM) with bn_mul_mont_gather5/bn_power5 (AMM). But this is fine because
MM is AMM-compatible; when passed AMM's looser inputs, it will still
produce a correct looser output.

Ideally we'd drop the "almost" reduction and stick to the more
straightforward bounds. As this only impacts the final subtraction in
each reduction, I would be surprised if it actually had a real
performance impact. But this would involve deeper change to
x86_64-mont5.pl, so I haven't tried this yet.

I believe this is basically the same bug as
https://github.com/golang/go/issues/13907 from Go.

Change-Id: I06f879777bb2ef181e9da7632ec858582e2afa38
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/52825
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2023-09-15 17:01:39 -07:00
Brian Smith
fd3f3d5e1e NFC: bigint: Move definition of elem_inverse_consttime.
`elem_inverse_consttime` was accidentally between two different
definitions of `elem_exp_consttime`. Fix that.
2023-09-15 13:23:28 -07:00
Brian Smith
2251fcd371 NFC: bigint: Expand use of BoringSSL exponentiation test vectors.
Prepare to merge the rest of the not-yet-merged BoringSSL changes.

The recent refactoring of `PrivateExponent` lets us add a new test-only
constructor that can support a wider range of exponents. Also, there's
no reason to avoid test vectors with a base of zero. We do need to still
reject 0 as an *exponent* and too-small moduli.

Accordingly, merge in all the relevant test vectors from BoringSSL's
`bn_test.txt` into `bigint_elem_exp_consttime_tests.txt` as of
BoringSSL a8b1633d1c6be133b9f684cc5cdd778bfd8d564e, which is the last
commit of BoringSSL that has been merged into *ring* so far.

```
git diff \
  a8b1633d1c:crypto/fipsmodule/bn/bn_tests.txt \
  src/arithmetic/bigint_elem_exp_consttime_tests.txt
```
2023-09-15 13:23:28 -07:00
Brian Smith
3bd30bb1bf bigint: Split BoxedLimbs into its own submodule.
`git diff HEAD^1:src/arithmetic/bigint.rs src/arithmetic/bigint/boxed_limbs.rs`
2023-09-14 11:15:51 -07:00
Brian Smith
cbdd045faa bigint: Stop using BoxedLimbs in PrivateExponent.
When constructing a `PrivateExponent` we enforce that the exponent is
appropriately-sized for its associated modulus; this check is relied on
in RSA private key construction for key component consistency checks.

However, once the `PrivateExponent` is constructed there is no reason
to relate its value to the modulus. Doing so has inhibited us from
using some test vectors that are in the BoringSSL test suite. Further
this usage blocks encapsulating `BoxedLimbs` into its own submodule.
2023-09-14 11:15:51 -07:00
Brian Smith
0c0d71d5f4 bigint: Split N0 into its own module.
`git diff HEAD^1:src/arithmetic/bigint.rs src/arithmetic/bigint/n0.rs`
2023-09-14 11:15:51 -07:00
Brian Smith
96169cf693 bigint: Make Modulus::from_boxed_limbs private.
Ensure all the functions responsible for maintaining invariants for
`Modulus` values are within `Modulus`.

Clarify the constraints on the relationship between the moduli in
`Modulus::from_elem`.
2023-09-14 11:15:51 -07:00
Brian Smith
7ab206e423 bigint: Split Modulus (and PartialModulus) into a submodule.
Better encapsulate `Modulus` and `PartialModulus`.

`git diff HEAD^1:src/arithmetic/bigint.rs src/arithmetic/bigint/modulus.rs`
2023-09-14 11:15:51 -07:00
Brian Smith
dc47d5f3a7 bigint: Split PrivateExponent into its own submodule.
Better encapsulate `PrivateExponent` and enforce its immutability.

`git diff HEAD^1:src/arithmetic/bigint.rs src/arithmetic/bigint/private_exponent.rs`
2023-09-14 11:15:51 -07:00
Brian Smith
e8da038f27 bigint: Split Nonnegative into its own module.
Clarify that `Nonnegative` values are immutable by enforcing this
through the module system.

Some read-only to-be-refactored-away methods of `Nonnegative` stay in
`bigint` to avoid moving them back-and-forth later.

`git diff HEAD^1:src/arithmetic/bigint.rs src/arithmetic/nonnegative.rs`
2023-09-14 11:15:51 -07:00
David Benjamin
ecb7e9ae5c Require C11 in MSVC too
BoringSSL can currently be built in C11 or pre-C11 mode in MSVC. They're
broadly the same, but do use completely different implementations of
alignas and alignof. Now that every build configuration I'm aware of has
been moved to the C11 mode, we don't even test the pre-C11 mode anymore.
Start requiring it.

Update-Note: If building with MSVC, BoringSSL now requires building with
/std:c11 or later. (On non-MSVC compilers, we have required C11 for a
while now.)

Fixed: 624
Change-Id: Ie9f66eee0bebac8143c23a7229c6854afaefea6e
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/63065
Commit-Queue: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2023-09-12 23:48:58 +00:00
Victor Tan
558960d1e1 Add support for the new ALPS codepoint
Old version Chrome with the existing ALPS codepoint can potentially cause network error due to an arithmetic overflow bug in Chrome ALPS decoder (We already fixed the issues starting from M100 in Chrome).

This CL add a new codepoint for ALPS extension in a way that can be enabled on individual connections., To support multiple versions of Chrome, we need to support both codepoints in BoringSSL.

For details: https://docs.google.com/document/d/16pysbV_ym_qAau_DBYnrw2A4h5ve2212wfcoYASt52U

Change-Id: Iea7822e757d23009648febc8eaff1c91b0f06e18
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/61125
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2023-09-12 18:01:21 +00:00
Maurice Lam
1e3da32f37 Expose curves for ECDH
Change-Id: Ifed7917ff1f54f2fbacf9abb967465d921fd7e3e
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/63045
Reviewed-by: Adam Langley <agl@google.com>
2023-09-09 02:31:37 +00:00
Bob Beck
3aecf1d00b Sync pki to chromium ce4bc9571462aa298d79b591df9d997323cf5157
Bug: chromium:1322914
Change-Id: Ic5a1349013bcfb279e5fee9f9838c63558d663b7
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/63025
Auto-Submit: Bob Beck <bbe@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2023-09-08 18:22:05 +00:00
David Benjamin
15b1f9c6a4 Help the compiler dedup ia32cap and armcap accesses
https://boringssl-review.googlesource.com/c/boringssl/+/62585 made the
compiler emit multiple CRYPTO_library_init calls in functions which
dispatch between a tower of alternatives. Ideally, the compiler would
know that at most one call suffices.

There doesn't seem to be such an attribute, but we can get the same
effect with pure or const attributes. We tie init with returning the
capability vector. On Intel, because the vector is so large, we have to
go with a weaker version. Somewhat annoyingly, the getter must be
out-of-line, because otherwise the compiler inlines first and loses the
attribute.

I went with pure because we allow our unit tests to mutate
OPENSSL_armcap_P, which means the Arm one is, strictly speaking, pure,
not const. This slightly reduces optimization potential, but should
still allow deduping in most places. Confirmed that aes_init_key
now only calls a helper function once.

See discussion in
https://boringssl-review.googlesource.com/c/boringssl/+/62585/comment/26083b88_b3db2b75/

Bug: 35
Change-Id: I9bc464f0e5a0ed9601017a5037028f906693a137
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/62985
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
2023-09-08 17:47:42 +00:00
David Benjamin
e5b6c141a1 Automatically call CRYPTO_library_init before C accesses
All the C accesses have been sufficiently abstracted that this is pretty
easy to handle automatically.

We still have accesses from assembly, so we're not quite
initializationless yet. But this does get us most of the way there. I'm
thinking what's next is:

- Make a list of asm symbols that touch armcap or ia32cap
- For each, figure out the place(s) in the calling code where we need to
  init manually and/or pull the dispatch up into C

One interesting subtlety with how this CL does it: although this CL
means you can freely call, say, CRYPTO_is_SSSE3_capable without
CRYPTO_library_init, you cannot *quite* assume that CRYPTO_library_init
has been called after you call CRYPTO_is_SSSE3_capable. It is possible
that the build defined __SSSE3__, in which case CRYPTO_is_SSSE3_capable
does nothing. This does complicate resolving the asm cases above.

Bug: 35
Change-Id: Ie52c74e4a59a7019c3af0526dbb35950604ada66
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/62585
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
2023-09-07 22:29:34 +00:00
Adam Langley
be84aeed7d acvptool: create fresh variables in loops.
Referencing a variable in a closure captures it by _address_. So
referencing a loop variable can go horribly wrong:
https://go.dev/play/p/f2ivPAIN_bG

This is accepted as essentially a bug by Go and will be fixed in a
future release (https://github.com/golang/go/wiki/LoopvarExperiment).
But, for now at least, work around it.

Our tests trim the ACVP inputs to only have a single test case per group
in many cases, which hides most of this issue from tests. When we run
run full ACVP sets, our modulewrapper is seemingly fast enough not to
notice there either. But I've updated one of the tests here by
duplicating a test case enough that it catches this a meaningful amount
of the time.

Change-Id: I8216c00f67636ab7dad927eae4b49ae45ae3cf31
Bug: 646
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/62965
Reviewed-by: David Benjamin <davidben@google.com>
Auto-Submit: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2023-09-06 16:43:18 +00:00
Bob Beck
8e7025e3df Sync pki to chromium 1ef93e346424a24fa27ee55a36254b6ee0f96e86
Bug: chromium:1322914
Change-Id: Ic9b93a733290c40ac7c64e67d1e4f611f2f8b46c
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/62966
Auto-Submit: Bob Beck <bbe@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
2023-09-06 14:05:18 +00:00