142 Commits
Author SHA1 Message Date
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
Bas Westerbaan 1a95e2a1a8 Add ML-DSA-44
Change-Id: Ieb5c6019c75c809b47b3e7cb3ac6af35a082eeca
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/79947
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2025-07-09 10:49:58 -07:00
Andres Erbsen be5be0a4f5 Import Bedrock code for P-256 point double, add
This code is currently only used in the p256.cc.inc (not nistz), but it
uses formulas similar to the nistz implementation. In particular, point
doubling is implemented using coordinate halving instead of multiplying
denominators by powers of two.

This change also removes the affine-addition optimization, counteracting
some of the efficiency gains but still resulting in an overall speedup
for client-side usage. This removal is intended to be temporary. The
verified affine-addition function uses a slightly different (nistz-like)
calling convention. Later work will unify the p256 and p256-nistz
files behind the new calling convention and restore the optimization
for both small and large tables.

Benchmarks on Zen 4:

../main/build-small/bssl.json
Did 14400 ECDH P-256 operations in 1000289us (14395.8 ops/sec)
Did 37000 ECDSA P-256 signing operations in 1009883us (36637.9 ops/sec)
Did 16000 ECDSA P-256 verify operations in 1003734us (15940.5 ops/sec)

build-small/bssl.json
Did 15886 ECDH P-256 operations in 1000894us (15871.8 ops/sec) [+10.3%]
Did 36000 ECDSA P-256 signing operations in 1017983us (35364.0 ops/sec) [-3.5%]
Did 18000 ECDSA P-256 verify operations in 1045215us (17221.3 ops/sec) [+8.0%]

P-256 ECDH is still ~40% slower in the small build than full build.
Estimating with double = 0.6 add, table size alone would yield ~30%.

Change-Id: Ide90296f9e14bf543df4e397f088602942c0b658
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/79787
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: Andres Erbsen <andreser@google.com>
2025-06-30 13:33:16 -07:00
Andres Erbsen 6f1a411710 fix p256_64_msvc.h
Fixed: 427018041
Change-Id: Iae712b9e9cacd9c3e29b3c4e93077592d315ed05
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/79868
Reviewed-by: David Benjamin <davidben@google.com>
Auto-Submit: Andres Erbsen <andreser@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-06-23 12:50:46 -07:00
Andres Erbsen 45f35e007c bedrock2 platform, tests, 64-bit p256_coord_sub
This change adds the scaffolding to integrate code proven in Rocq using
Bedrock and Fiat Cryptography to libcrypto, in particular for optimized
elliptic-curve and finite-field arithmetic. A new implementation of p256
coordinate subtracton is added as an initial demonstration.

Change-Id: I73b3bd8258a33681a2e5b6532e389151e157985b
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/79208
Auto-Submit: Andres Erbsen <andreser@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2025-06-16 08:58:54 -07:00
David Benjamin 1ad8b517de Update googletest
Fixed: 419067923
Change-Id: Ida41103ce2edf5f408e47f69f81abb0575b44eb3
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/79448
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-05-20 13:45:55 -07:00
Brett McLarnon 34492c89a8 Expose P1363-based ECDSA sign/verify functions
Fixed: 411427388
Change-Id: I108eb20a55ea9c9e9ac31e85d1ede05df1116c3f
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/78807
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2025-04-25 11:47:49 -07:00
David Benjamin 2896aa9ca0 Spell Apache 2.0 correctly in fiat/README.chromium
Looks like it's meant to have a hyphen, to match the SPDX identifier.

https: //source.chromium.org/search?q=License%5C:%5C%20Apache%20file:README.chromium&sq=&ss=chromium
https: //chromium.googlesource.com/chromium/src/+/HEAD/docs/adding_to_third_party.md#add-a-license-file-and-run-related-checks
Change-Id: I553cb40dc0ef55a7a3634ac2488f389e1ed47dfc
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/77288
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
2025-04-02 15:00:31 -07:00
Moreno Ambrosin b7254f7c0b Add AES-EAX EVP_AEAD cipher
This is defined in https://doi.org/10.1007/978-3-540-25937-4_25.

Change-Id: I9173e7f6dda22681770a231d905fd5438cb7c187
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/77007
Auto-Submit: Moreno Ambrosin <ambrosin@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2025-03-11 14:19:33 -07:00
David Benjamin 748a2d281d Update googletest
Been a while since we'd done that.

Change-Id: Ia5c71ca9df0bcd951f2a4f165b736e7350b2f2af
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/76767
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2025-02-24 16:18:55 -08:00
David Benjamin 33d1049b1f Switch the license to Apache 2.0, matching OpenSSL upstream
We use the standard Apache 2.0 file header, described in "APPENDIX: How
to apply the Apache License to your work."

This was primarily automated by running:

  git ls-tree -r --name-only HEAD | xargs go run ./util/relicense.go

See go/boringssl-relicensing-triage for the results of triaging the
output of the tool.

As part of this, switch from taking fiat-crypto under MIT license to
Apache 2.0. (It is licensed under MIT OR Apache-2.0 OR BSD-1-Clause.)

The copyright_summary tool can also be used to confirm we didn't
accidentally drop any copyright lines:

  # Run before the CL
  git grep -l Copyright | xargs go run ./util/copyright_summary.go  -out /tmp/old.json
  # Run after the CL
  git grep -l Copyright | xargs go run ./util/copyright_summary.go  -compare /tmp/old.json

Bug: 364634028
Change-Id: I17c50e761e9d077a1f92e25969e50ed35e320c59
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/75852
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2025-02-03 15:05:16 -08:00
Adam Langley 48d150f594 Add ML-DSA-87 in the FIPS module.
This is deliberately not exported in the public interface. Obviously we
could add it in the future if we wished but, for now, our suggestion is
to use ML-DSA-65. However, if needed in the future, it will already be
ready and FIPS validated inside the module.

Change-Id: I38a59d4e58b76cf74004432e87143380691a722b
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/73347
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2024-12-11 15:46:54 -08:00
Adam Langley 5813c2c10c crypto: switch to C++
This change switches nearly all of BoringSSL to use C++. The public
functions still use the C ABI, and so code written in C can still use
BoringSSL. Also the use of the C++ standard library is minimal and no
run-time requirement for it is intended.

Change-Id: I902d2f51a3c8d6bd0dc4aabe1b192a15d7b788e8
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/72747
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
2024-11-26 21:10:44 +00:00
Adam Langley 0ba2001733 Add ML-DSA.
This change implements FIPS 204.

Change-Id: I0043850767c93cc7235a15c701798fee6e1af1bf
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/69987
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2024-08-19 20:09:26 +00:00
David Benjamin c6c0b65009 Add the Revision field to third_party/fiat/README.chromium
This is copied over from the METADATA file, since Chromium's
infrastructure currently requires some duplicate work.

Bug: 347861602
Change-Id: I21ae055454c6dbe721ea99a4609d8144dd7846ad
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/69407
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2024-06-18 19:56:47 +00:00
Andres Erbsen d477c0d7c4 use AT&T syntax in fiat_p256_adx
Converted using https://github.com/andres-erbsen/fiat-crypto/commit/86a8bdcc1073fb55c01090ef8df622ea2c901ee1

Change-Id: Ic3b4f5b0f52a21eebd7c597a8caebf7b08c21fe3
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/68527
Reviewed-by: Andres Erbsen <andreser@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2024-05-16 21:00:48 +00:00
Andres Erbsen 2a33faebe1 do not call memcpy directly in curve25519_64_adx.h
Change-Id: I7837e600cb5f22aab38cb332de6f579d3cd62a67
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/63745
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2023-10-31 19:05:57 +00:00
Andres Erbsen 20c9406971 Add table-independent x86+adx asm for P-256
With -march=haswell -DOPENSSL_SMALL=1 on cascadelake:
Did 9999 ECDH P-256 operations in 1062469us (9411.1 ops/sec) [+63.5%]
Did 25000 ECDSA P-256 signing operations in 1028302us (24311.9 ops/sec) [+48.9%]
Did 11004 ECDSA P-256 verify operations in 1072646us (10258.7 ops/sec) [+58.8%]

Same configuration measured no performance difference on haswell.

The added assembly code occupies 1352 bytes.

Change-Id: I42635b7a9bf24d942817976a5d4ce269f642251c
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/63185
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2023-10-05 02:28:40 +00:00
David Benjamin fa343af32b Update googletest and include googlemock
Some tests in the Chromium verifier use gmock. Since upstream googletest
considers them a single project now, just import both of them.

Update-Note: As part of this, I've made gtest_main.cc now initializes
gmock alongside gtest. This means BoringSSL's test targets now depend on
both. Downstream builds where googletest and googlemock are separate
build targets may need to add a dependency. (Though every downstream
test I looked at treats them as one target, so this is most likely a
no-op.)

Bug: chromium:1322914
Change-Id: Ief38c675bc13a4639dee061d058580967ab99d41
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/62945
Commit-Queue: Bob Beck <bbe@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
2023-09-05 21:11:19 +00:00
David Benjamin 164b86dccd Explicitly mark saved registers with .cfi_restore
Although it works without these (we just refer the unwinder to the red
zone), older versions of libunwind seem to have a bug that cause it to
flakily fail to restore rbx without this. I've attempted to bisect the
problem, but the issue is very flaky and I've failed to find the culprit
four times now, so just give up and work around it. Explicit restores
match what we do in other files.

Hopefully this will clear some issues tha fiat-crypto's CI are running
into.

Change-Id: I6a19679a37cad8e93e6dee554b6a9b3b9b4bbe4a
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/62865
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2023-08-29 20:56:11 +00:00
David Benjamin 11d943ac2d Fix RBP-based unwind in fiat assembly
RBP pointed 8 bytes off of where it should be. I've left the RSP offsets
alone, though it does mean they're shifted by 8 from what they
previously were. Per Andres, the new version of CryptOpt will generate
an RBP-compatible prolog, but for now I've just fixed it up by hand.
(This part was already hand-written.)

Change-Id: I23720e76affff6fae46b8f85b0a509380ccc8bc0
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/62805
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
2023-08-28 19:34:00 +00:00
Anne Redulla 1f786137e4 [ssci] Added Shipped field to READMEs
This CL adds the Shipped field (and may update the
License File field) in Chromium READMEs. Changes were
automatically created, so if you disagree with any of
them (e.g. a package is used only for testing purposes
and is not shipped), comment the suggested change and
why.

See the LSC doc at go/lsc-chrome-metadata.

Bug: b:285450740
Change-Id: I63755d8a42ea69ff6d3a4e0c21ddacd2b7ce9053
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/61545
Auto-Submit: Anne Redulla <aredulla@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2023-07-14 15:21:20 +00:00
Bob Beck 9fc1c33e9c Add Intel Indirect Branch Tracking support.
This allows operating systems to insist on IBT
enforcement as an exploit mitigation mechanism without
needing to make an exception for anything using a
bundled boringssl, such as chrome, mono, and qtwebengine.

Change-Id: Iac28dd3d2af177b89ffde10ae97bce23739feb94
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/60625
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2023-07-10 18:55:14 +00:00
David Benjamin a905bbb52a Consistently include BTI markers in every assembly file
Trying to migrate Chromium to the "link all the asm files together"
strategy broke the aarch64 Android build because some of the ifdef'd out
assembly files were missing the .note.gnu.property section for BTI. If
we add support for IBT, that'll be another one.

To fix this, introduce <openssl/asm_base.h>, which must be included at
the start of every assembly file (before the target ifdefs). This does a
couple things:

- It emits BTI and noexecstack markers into every assembly file, even
  those that ifdef themselves out.

- It resolves the MSan -> OPENSSL_NO_ASM logic, so we only need to do it
  once.

- It defines the same OPENSSL_X86_64, etc., defines we set elsewhere, so
  we can ensure they're consistent.

This required carving files up a bit. <openssl/base.h> has a lot of
things, such that trying to guard everything in it on __ASSEMBLER__
would be tedious. Instead, I moved the target defines to a new
<openssl/target.h>. Then <openssl/asm_base.h> is the new header that
pulls in all those things.

Bug: 542
Change-Id: I1682b4d929adea72908655fa1bb15765a6b3473b
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/60765
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2023-06-22 23:36:55 +00:00
Andres Erbsen 9c30e5389c Credit CryptOpt in third_party/fiat/README.md
Change-Id: I824560a5bddb9183e61c663ca4cbdc4530177e66
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/60945
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: Andres Erbsen <andreser@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
2023-06-20 21:17:23 +00:00
David Benjamin ae88f198a4 Fix fiat asm .private_extern declaration on Apple platforms
Chromium actually has a checker for unexpected exported symbols, which
caught this.

Change-Id: If1af4c26a3326eea185725f9e84c17f5d9f0f58e
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/60665
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
2023-06-10 21:01:58 +00:00
David Benjamin 23ed9d3852 Add target attributes to curve25519_64_adx.h
__builtin_ia32_addcarryx_u64 is, strictly speaking, an ADX intrinsic.
GCC and newer Clang seem to actually implement it without ADX, but
Clang 7 and older will actually try to generate ADX code with it. But
since the caller is not marked target("adx"), this fails to build.

Manually add ADX and BMI2 target attributes to all these functions. The
compiler should be free to use those instructions as these functions all
call into an ADX+BMI2 assembly function anyway. (Though it doesn't do
much with this.)

Note we cannot just annotate fiat_addcarryx_u64. Clang and GCC won't
inline across incompatible targets, so if we tag fiat_addcarryx_u64, we
need to tag the callers up the chain until we're willing to stop
inlining.

Change-Id: I855bb88fea666d92997984836e664292d90df5be
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/60612
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
2023-06-08 21:58:02 +00:00
David Benjamin 3f680b0eff Remove a layer of indirection from fiat curve25519 assembly
This fixes the generated Bazel build. Bazel is strict about having all
dependencies declared, which includes files that are #included into
other files. (It also is not particularly pleased about textual
headers and wants them declared in a separate place.)

The new fiat curve25519 assembly is currently split into a BoringSSL
half, and a more generic fiat half. For now, just move the BoringSSL
customizations directly into the fiat half. This isn't ideal, as we'd,
long term, like something where the fiat code can be made standalone.
But, to fix the build, just patch in the changes now and we can ponder
how to do this better later. (Build tools and conventions for assembly
are much less clear than C, sadly.)

Also add the .note.GNU-stack bit at the end.

Change-Id: I04aa733eabf8562dba42dee63a8fd25c86a59db9
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/60566
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2023-06-08 01:55:30 +00:00
David Benjamin d995d82ad5 Add .type, .hidden, and .size to the new fiat ADX assembly
.type seems to be needed for the unwind tester to report symbols
correctly. I assume it does other useful things. .hidden
(.private_extern on macOS) keeps it from being exported out of shared
libraries. I'm not positive what .size does, but if ELF wants to know
the size of the function, we should probably tell it that.

Change-Id: Iaa2e4f8a72e81092ec1d81ee2177504c7dc89c76
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/60465
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Andres Erbsen <andreser@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
2023-06-07 14:57:07 +00:00
Andres Erbsen 9d4f833eec Use ADX asm for Curve25519 base-point multiplication
Did 75000 Ed25519 key generation operations in 1007110us (74470.5 ops/sec) [+26.9%]
Did 72000 Ed25519 signing operations in 1011133us (71207.2 ops/sec) [+25.5%]
Did 78000 Curve25519 base-point multiplication operations in 1006737us (77478.0 ops/sec) [+27.5%]

Change-Id: I32ca2056f42f9b92af315d8381e1b72be69dd331
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/60386
Commit-Queue: Andres Erbsen <andreser@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2023-06-06 21:09:49 +00:00
Andres Erbsen 43f88915f9 Add saturated X25519 for x86_64+ADX running Linux
Did 29000 Curve25519 arbitrary point multiplication operations in 1026074us (28263.1 ops/sec) [+31.2%]

Change-Id: I9c7d47a047dc68d37202b6cf40d7d12b5b4936f8
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/60385
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2023-06-06 18:24:25 +00:00
David Benjamin bf80254924 Update googletest
It's been a couple years since we did that.

I had to upstream a fix to CreateArgvFromArgs, but that landed quickly,
so we're actually carrying no googletest patches with this.

Change-Id: Ifaf3476f2079d444512a235756cfe54f492b9c92
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/59745
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
2023-05-11 17:40:32 +00:00
Bob Beck 4540c3caf0 OpenBSD Support
Includes bits by me and Robert Nagy <robert.nagy@gmail.com> who has a
google CLA.

Update-Note: Additionally, BoringSSL now requires macOS 10.12 or later
for getentropy support. This is consistent with
https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md

WANT_LGTM=all

Change-Id: I5ab74fa8a6677fac29c316aa29a954df401ba647
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/59225
Commit-Queue: Bob Beck <bbe@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2023-05-11 16:37:32 +00:00
Andres Erbsen aa31748bc8 Generate 64-bit Curve25519 and P256 code for MSVC
Change-Id: I2218807c6bfe445460a01f6c86712640915e87df
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/57666
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2023-04-19 16:09:32 +00:00
David Benjamin 8c8e7a683f Update fiat-crypto.
The files no longer need to be patched because fiat-crypto now has its
own copy of our value barrier. It does, however, require syncing our
NO_ASM define with fiat's.

fiat-crypto is now licensed under any of MIT, BSD 1-clause, or Apache 2.
I've stuck with the MIT one as that's what we were previously importing.

No measurable perf difference before/after this CL, with GCC or Clang on
x86_64.

Change-Id: I2939fd517de37aabdea3ead49150135200a1b112
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/52045
Reviewed-by: Adam Langley <agl@google.com>
2022-03-23 19:34:10 +00:00
David Benjamin 4df05c5235 Update third_party/googletest.
Fuchsia is looking to remove the ZX_WAIT_ASYNC_ONCE constant, and our
copy of GoogleTest still has it. As usually with GoogleTest updates, our
old local patch is no longer necessary, but now we need a new one.

Change-Id: I8d226f01cf0951fd278605688684bf1ce3e17898
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/44884
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2021-01-06 17:41:42 +00:00
David Benjamin 47b1e39042 Tidy up third_party/fiat.
Originally, when we imported fiat-crypto field operations, the pipeline
was in early stages and the generated code had to be manually integrated
with the rest of the curve implementation, so we moved all our
supporting code to third_party/fiat for simplicity. Over time more
supporting code, like the table generators, landed there to be next to
its callers.

fiat-crypto now generates standalone files which we #include into the
supporting code. This moves the supporting code back to the usual
location. It also updates the README.md file to reflect the new
pipeline. (Most of it was a documentation of the old pipeline, which was
much more manual.)

Change-Id: I64db7235feb6566f0d3cd4db3a7146050edaf25a
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/40904
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2020-04-23 19:50:07 +00:00
David Benjamin 25ab623a86 Prefix g_pre_comp in p256.c as well.
I missed a symbol.

Change-Id: I83c6828620a54eaab26cad08b1714402a2758fc0
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/40905
Commit-Queue: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2020-04-23 19:05:07 +00:00
David Benjamin 13d09f0527 Properly namespace everything in third_party/fiat/p256.c.
This file gets #included into other files, so we shouldn't use generic
names like 'fe'. This will let us import other fiat-crypto curves in the
future, if we want them.

Change-Id: Ie4e222729bde7e4ccd368b86fb9048a2ea4a58ac
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/40824
Reviewed-by: David Benjamin <davidben@google.com>
Reviewed-by: Steven Valdez <svaldez@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2020-04-22 20:04:56 +00:00
David Benjamin baca5b4fa0 Update fiat-crypto.
This pulls in the latest upstream files and reapplies our value_barrier patch.
In particular, https://github.com/mit-plv/fiat-crypto/pull/723 made 64-bit
P-256 faster!

32-bit x86, gcc
Before:
Did 3150 ECDH P-256 operations in 4027477us (782.1 ops/sec)
Did 9912 ECDSA P-256 signing operations in 4067212us (2437.1 ops/sec)
Did 3772 ECDSA P-256 verify operations in 4059197us (929.2 ops/sec)
Did 74800 Ed25519 key generation operations in 4020883us (18602.9 ops/sec)
Did 74000 Ed25519 signing operations in 4001827us (18491.6 ops/sec)
Did 21371 Ed25519 verify operations in 4024606us (5310.1 ops/sec)
Did 78000 Curve25519 base-point multiplication operations in 4051574us (19251.8 ops/sec)
Did 25133 Curve25519 arbitrary point multiplication operations in 4063280us (6185.4 ops/sec)
After:
Did 3250 ECDH P-256 operations in 4025179us (807.4 ops/sec) [+3.2%]
Did 10277 ECDSA P-256 signing operations in 4084926us (2515.8 ops/sec) [+3.2%]
Did 3895 ECDSA P-256 verify operations in 4048734us (962.0 ops/sec) [+3.5%]
Did 74480 Ed25519 key generation operations in 4002460us (18608.6 ops/sec) [+0.0%]
Did 74000 Ed25519 signing operations in 4004425us (18479.6 ops/sec) [-0.1%]
Did 21756 Ed25519 verify operations in 4038856us (5386.7 ops/sec) [+1.4%]
Did 78000 Curve25519 base-point multiplication operations in 4031991us (19345.3 ops/sec) [+0.5%]
Did 25133 Curve25519 arbitrary point multiplication operations in 4064925us (6182.9 ops/sec) [-0.0%]

x86_64, clang, OPENSSL_SMALL
Before:
Did 20090 ECDH P-256 operations in 4019408us (4998.2 ops/sec)
Did 56000 ECDSA P-256 signing operations in 4004370us (13984.7 ops/sec)
Did 23562 ECDSA P-256 verify operations in 4062283us (5800.2 ops/sec)
Did 127000 Ed25519 key generation operations in 4005053us (31709.9 ops/sec)
Did 128000 Ed25519 signing operations in 4021902us (31825.7 ops/sec)
Did 71000 Ed25519 verify operations in 4036015us (17591.6 ops/sec)
Did 132000 Curve25519 base-point multiplication operations in 4002101us (32982.7 ops/sec)
Did 93000 Curve25519 arbitrary point multiplication operations in 4023827us (23112.3 ops/sec)
After:
Did 22263 ECDH P-256 operations in 4005099us (5558.7 ops/sec) [+11.2%]
Did 61000 ECDSA P-256 signing operations in 4024810us (15156.0 ops/sec) [+8.4%]
Did 27426 ECDSA P-256 verify operations in 4038547us (6791.1 ops/sec) [+17.1%]
Did 128000 Ed25519 key generation operations in 4015033us (31880.2 ops/sec) [+0.5%]
Did 127000 Ed25519 signing operations in 4003894us (31719.1 ops/sec) [-0.3%]
Did 70000 Ed25519 verify operations in 4017446us (17424.0 ops/sec) [-1.0%]
Did 132000 Curve25519 base-point multiplication operations in 4006282us (32948.3 ops/sec) [-0.1%]
Did 93000 Curve25519 arbitrary point multiplication operations in 4025190us (23104.5 ops/sec) [-0.0%]

Change-Id: I2f705772899c701480ca0e0885e6b75dd1bb1f5d
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/40746
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2020-04-22 19:06:26 +00:00
David Benjamin 1d43e57c30 Base EC_FELEM conversions on bytes rather than BIGNUMs.
It is tricky to create EC_FELEMs right now. This will simplify making them.

Change-Id: Icde518efed61381004e2e5569a45d653af48ca2a
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/40585
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2020-04-07 23:10:10 +00:00
David Benjamin bd1fa86feb Clean up various EC inversion functions.
This fixes two issues. First, we have been lax about whether the
low-level inversion functions fail on zero input or output zero. Fix the
documentation and call the latter inv0 or inverse0 to match the
terminology used in draft-irtf-cfrg-hash-to-curve. (Although we may not
actually need inv0 given the optimization in D.2.)

This has no actual effect because the functions were only used in
contexts where the inputs were already guaranteed to be non-zero. Still,
we should be consistent here.

Second, ec_scalar_inv_montgomery and ec_scalar_inv_montgomery_vartime
claim to perform the same operation, but they do not. First, one
computed inv0 and the other computed inv (except only in some
implementations, so fix it to be consistent). Second, the former
computes inverses in the Montgomery domain, while the latter converts to
the Montgomery domain and then inverts. Rename it to
ec_scalar_to_montgomery_inv_vartime, which is... questionably
understandable but at least looks different.

Change-Id: I9b4829ce5013bdb9528078a093f41b1b158df265
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/40526
Reviewed-by: Adam Langley <agl@google.com>
2020-04-07 20:28:59 +00:00
David Benjamin be1d14b789 Import Wycheproof primality tests.
Change-Id: I885fb8f282b6339bdb061fde1c8d3d74706de5b5
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/39196
Reviewed-by: Adam Langley <agl@google.com>
2019-12-16 22:20:51 +00:00
David Benjamin a165168277 Import Wycheproof PKCS#1 decrypt tests.
Change-Id: I2f9bca4233b42ff5604e1516ad482142470467dd
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/39193
Reviewed-by: Adam Langley <agl@google.com>
2019-12-16 20:25:35 +00:00
David Benjamin 355828a2f7 Import Wycheproof OAEP tests.
Change-Id: I49fb836e92ee6c0b668b3921f6f873b8f79e793d
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/39192
Reviewed-by: Adam Langley <agl@google.com>
2019-12-16 20:24:27 +00:00
David Benjamin e5905d01c3 Import Wycheproof PKCS#1 signing tests.
In doing so, add an IgnoreAllInstructions option for FileTest. FileTest
tracks unused fields so test drivers don't accidentally miss a portion
of the test. Wycheproof tests, however, have many different key formats
in instructions. These are tedious to list out, so add an option to
ignore them, on the assumption that checking attributes is more useful
than instructions.

Change-Id: I01cc9f3a95577d576c8c2dd68f5092fceb3215b1
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/39191
Reviewed-by: Adam Langley <agl@google.com>
2019-12-16 20:21:41 +00:00
David Benjamin 305a03a8b0 Skip JWK keys when converting Wycheproof tests.
We expand the dictionaries, which is no longer JWK anyway.

Change-Id: I26f0b8beedf82a7efe40a536171eab940c0ec7d5
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/39190
Reviewed-by: Adam Langley <agl@google.com>
2019-12-16 20:19:46 +00:00
David Benjamin 55ed2a60d3 Import Wycheproof's size-specific RSA PKCS#1 verifying tests.
It's unclear to me whether the normal rsa_signature_test.txt file is
still needed with these, but I've left it in for now.

Change-Id: I6db9c9556820263c2b0bc37d144e6403b9a7a178
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/39189
Reviewed-by: Adam Langley <agl@google.com>
2019-12-16 20:18:35 +00:00
David Benjamin 906bbef001 Handle "acceptable" Wycheproof inputs unambiguously.
This CL updates the JSON conversion to preserve the flags. A
WycheproofResult now captures both "result" and "flags". An "acceptable"
test case's validity is determined by its flags. By default, we consider
an "acceptable" case as invalid, but a test driver may mark some of them
as valid by listing the flags as a parameter.

Previously, some Wycheproof tests (I think it was x25519_tests.txt?) did
not contain enough information to resolve this unambiguously. This has
since been fixed.

This also makes the converted files smaller because we no longer expand the
flags into comments.

Change-Id: I2ca02d7f1b95f250409e8b23c4ad7bb595d77fdf
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/39188
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-12-16 20:17:51 +00:00
David Benjamin 62f662dbeb Import Wycheproof XChaCha20-Poly1305 tests.
Change-Id: Iaa10ebfc61aa2f928f057a62737d5d97743d6305
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/39187
Reviewed-by: Adam Langley <agl@google.com>
2019-12-16 20:17:00 +00:00