156 Commits

Author SHA1 Message Date
Brian Smith
501fc4eeaa Replace *ring*'s P-256 arithmetic with BoringSSL's P-256 arithmetic.
Use Fiat Crypto for non-x86_64 platforms, like BoringSSL. Continue
using the nistz256 code on Windows, differently from BoringSSL.

Make *ring* more consistent with BoringSSL.
2021-02-10 12:20:26 -08:00
Brian Smith
ef7cf3bfc5 Merge BoringSSL 47b1e39: Tidy up third_party/fiat. 2020-06-02 14:02:26 -05:00
Brian Smith
9fb77fa2d4 Merge BoringSSL: baca5b4: Update fiat-crypto. 2020-06-02 13:29:42 -05:00
Brian Smith
0e7fdf5e91 Split ASSERT into dev_assert_secret and debug_assert_nonsecret. 2020-05-29 13:23:29 -05: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
David Benjamin
b19efcc1cf Import Wycheproof HMAC tests.
Change-Id: I712ac83efc3bf1edfd4485cb0e822f5719629293
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/39186
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-12-16 20:14:01 +00:00
David Benjamin
8e71fe9ca8 Import Wycheproof HKDF tests.
Change-Id: Iece24241327778eb092a069fd1a0784c9d2a7363
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/39185
Reviewed-by: Adam Langley <agl@google.com>
2019-12-16 18:58:12 +00:00
David Benjamin
15cd8bf433 Update Wycheproof test vectors.
Wycheproof have added many more tests. They'll be imported in subsequent
CLs.

Change-Id: I69d8e09328b08edbd0a96757db26b380d7a7c7ee
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/39184
Reviewed-by: Adam Langley <agl@google.com>
2019-12-16 18:53:44 +00:00
Adam Langley
7f02881e96 Drop CECPQ2b code.
The experiment which motivated CECPQ2b has concluded (although the
results haven't been published yet) and the SIKE code is causing some
issues for gRPC in gprc/grpc#20100. Also, this is code size that takes
up space in Android etc.

Change-Id: I43b0b8c420f236c0fe9b40bf2517d2fde98495d5
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/38384
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2019-10-18 22:33:00 +00:00
Adam Langley
20ae5e6f6c Correct relative path.
This path has always had one-too-few “..” elements since the file first
appeared, but everyone seems to have lived with it, presumably because
/include is in the search path and the compiler tries relative to that.

Change-Id: I30006209ad74d064ded5dd2cd34b1f14806dcffe
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/38344
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2019-10-18 17:49:29 +00:00
Brian Smith
ed47ae8c67 Support clang-cl better. 2019-07-22 12:08:35 -10:00
Adam Langley
07432f325d Prefix all the SIKE symbols.
I should have noticed this previously, but the SIKE code was exporting
symbols called generic things like “params”. They're not dynamically
exported, but BoringSSL is often statically linked so better to ensure
that these things are prefixed to avoid the risk of collisions.

Change-Id: I3a942dbc8f4eab703d5f1d6898f67513fd7b578c
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/36745
Commit-Queue: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2019-07-19 18:15:13 +00:00
Adam Langley
1a3178cf02 Rename SIKE's params.c.
We already have crypto/dh/params.c and some of our downstream consumers
cannot take two source files with the same name in the same build
target.

Change-Id: I324ace094c2215b443e98fc9ae69876ea1929efa
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/36744
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2019-07-19 17:35:23 +00:00
Kris Kwiatkowski
3c8ae0fd3e Implements SIKE/p434
* CECPQ2b will use SIKE/p434 instead of SIKE/p503
* KEM uses SHA256 instead of HMAC-256
* implements new starting curve: y^2=x^3 + 6x^2 + x
* adds optimized implementation for aarch64
* adds optimized implementation for AMD64
  which do not support MULX/ADOX/ADCX
* syncs the SIKE test code with the NIST Round 2
  specification.
* removes references to field size from variables
  names, tests and defines.

Change-Id: I5359c6c62ad342354c6d337f7ee525158586ec93
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/36704
Reviewed-by: Adam Langley <agl@google.com>
2019-07-16 22:30:03 +00:00
Brian Smith
4399add9cf Don't require the C toolchain to provide assert.h for non-debug builds. 2019-07-15 21:33:55 -10:00
Brian Smith
4bbba957f8 Merge BoringSSL 92b7c89: Add a value barrier to constant-time selects. 2019-07-02 17:01:41 -10:00
Brian Smith
65ab723a19 Move masking of scalars in Curve25519 code to Rust. 2019-07-01 17:54:45 -10:00
David Benjamin
92b7c89e6e Add a value barrier to constant-time selects.
Clang recognizes the (mask & a) | (~mask & b) pattern as a select. While
it often optimizes this into a cmov, it sometimes inserts branches
instead, particularly when it detects a string of cmovs with the same
condition.

In the long term, we need language-level support for expressing our
constraints. In the short term, introduce value barriers to prevent the
compiler from reasoning about our bit tricks. Thanks to Chandler Carruth
for suggesting this pattern. It should be reasonably robust, short of
value-based PGO or the compiler learning to reason about empty inline
assembly blocks.

Apply barriers to our various constant-time selects. We should invest
more in the valgrind-based tooling to figure out if there are other
instances.

Change-Id: Icc24ce36a61f7fec021a762c27197b9c5bd28c5d
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/36484
Reviewed-by: Chandler Carruth <chandlerc@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-06-19 17:19:13 +00:00
David Benjamin
12d9ed670d Avoid leaking intermediate states in point doubling special case.
Point addition formulas for short Weierstrass curves are often
incomplete and do not work for P + P. EC implementations usually rely on
constant-time operations never hitting this case, or at least it being
rare[0].

However, the condition checks several values. Our C functions use && and
||, and the P-256 assembly also branches. This can leak intermediate
values via a small side channel. Thanks to David Schrammel and Samuel
Weiser for reporting this.

nistz256 base point multiplication (keygen, ECDSA signing) is unaffected
due to ecp_nistz256_point_add_affine lacking a doubling case. nistp224
and nistp256 base point multiplication, on some compilers, are saved by
quirks of the "mixed" path. The generic code's base point multiplication
and all methods' arbitrary point multiplication (ECDH; ephemeral keys
makes this less interesting) are affected.

Fix the branches in the nistz256 assembly, and use bit operations in C.
Note the C versions are all different because P-224 believes true is 1,
P-256 believes true is any non-zero value, and the generic code believes
true is 0xf...f. This should be double-checked when reviewing.

Aside: The nistz256 assembly also special-cases nontrivial P + (-P) in
arbitrary point multiplication. Fortunately, the formulas in util.c hold
there and I believe one can show P + (-P) is unreachable for all curves.
Still, it would be nice to omit the branch if we can verify the assembly
works anyway.

[0] 03da376ff7/crypto/ec/ecp_nistp521.c (L1259)

Change-Id: I8958624cd6b5272e5076c6c1605ab089e85f4cb7
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/36465
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2019-06-19 17:19:04 +00:00
Brian Smith
6960614893 Remove #includes <string.h> in Curve25519. 2019-06-14 13:48:57 -10:00
Adam Langley
8f574c37da Add AES-KWP
KWP is Key Wrap with Padding, defined in RFC 5649 and SP 800-38F. Like
Key Wrap, it's a poor-man's AEAD and shouldn't be used. However, some
existing systems use it and we need to interoperate.

The interface of the added functions is a little unfortunate, but they
match the interfaces of the existing Key Wrap functions which, in turn,
match functions in OpenSSL. Hopefully this way, if OpenSSL ever add
support, we'll line up.

Change-Id: I3496c288f32230a891261586ca2e9c4ee8456c09
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/36324
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2019-06-13 22:43:59 +00:00
David Benjamin
0ad091adcd Split EC_METHOD.mul into two operations.
See I9c20b660ce4b58dc633588cfd5b2e97a40203ec3. Aside for p224-64.c, we'd
already split mul_public into a dedicated function, at which point it's
simpler to just have three functions.

This makes it clearer when we do and don't care about the doubling case
coming up and avoids a bunch of NULL checks.

Change-Id: I7c5dafa7f12f4f53937d912ba22c90cb5a786f04
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/36225
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-05-30 20:55:46 +00:00
David Benjamin
79ab5e8faa Fix the last casts in third_party/sike.
These even trip UBSan because they break alignment requirements. The
crypto_word_t isn't doing anything here, so just read bytes.

Change-Id: Icb6dfce2c3a10f8252bbb0889cbeedcf1e8d8e62
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/36066
Reviewed-by: Adam Langley <alangley@gmail.com>
Commit-Queue: David Benjamin <davidben@google.com>
2019-05-17 13:51:48 +00:00
David Benjamin
b4b41cad0a Remove no-op casts around tt1.
I believe this is defined, but it's also unnecessary.

Change-Id: I01313ece2134bd7afecb6c8539d35b5b06c6777a
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/36065
Reviewed-by: Adam Langley <alangley@gmail.com>
2019-05-17 00:21:36 +00:00
David Benjamin
c93e525df1 Define p503 with crypto_word_t, not uint64_t.
Most of the crypto_word_t* casts in third_party/sike are due to p503
being defined with uint64_t. This is a strict aliasing violation and
easily avoided with a TOBN-like macro when defining p503.

This clears almost all of the casts. Also remove an unused stdbool.h
include.

Change-Id: Ife3a4ec620f8b7f4e09c87c6fc43d8b82396046b
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/36064
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <alangley@gmail.com>
2019-05-16 23:27:15 +00:00
Kris Kwiatkowski
7922e5abcc Add support for SIKE/p503 post-quantum KEM
Based on Microsoft's implementation available on github:
Source: https://github.com/Microsoft/PQCrypto-SIDH
Commit: 77044b76181eb61c744ac8eb7ddc7a8fe72f6919

Following changes has been applied

* In intel assembly, use MOV instead of MOVQ:
  Intel instruction reference in the Intel Software Developer's Manual
  volume 2A, the MOVQ has 4 forms. None of them mentions moving
  literal to GPR, hence "movq $rax, 0x0" is wrong. Instead, on 64bit
  system, MOV can be used.

* Some variables were wrongly zero-initialized (as per C99 spec).

* Rewrite x86_64 assembly to AT&T format.

* Move assembly for x86_64 and aarch64 to perlasm.

* Changes to aarch64 assembly, to avoid using x18 platform register.
  Assembly also correctly constructs linked list of stack-frames as
  described in AAPCS64, 5.2.3.

* Move constant values to .RODATA segment, as keeping them in .TEXT
  segment is not compatible with XOM.

* Fixes issue in arm64 code related to the fact that compiler doesn't
  reserve enough space for the linker to relocate address of a global
  variable when used by 'ldr' instructions. Solution is to use 'adrp'
  followed by 'add' instruction. Relocations for 'adrp' and 'add'
  instructions is generated by prefixing the label with :pg_hi21:
  and :lo12: respectively.

* Enable MULX and ADX. Code from MS doesn't support PIC. MULX can't
  reference global variable directly. Instead RIP-relative addressing
  can be used. This improves performance around 10%-13% on SkyLake

* Check if CPU supports BMI2 and ADOX instruction at runtime. On AMD64
  optimized implementation of montgomery multiplication and reduction
  have 2 implementations - faster one takes advantage of BMI2
  instruction set introduced in Haswell and ADOX introduced in
  Broadwell. Thanks to OPENSSL_ia32cap_P it can be decided at runtime
  which implementation to choose. As CPU configuration is static by
  nature, branch predictor will be correct most of the time and hence
  this check very often has no cost.

* Reuse some utilities from boringssl instead of reimplementing them.
  This includes things like:
  * definition of a limb size (use crypto_word_t instead of digit_t)
  * use functions for checking in constant time if value is 0 and/or
    less then
  * #define's used for conditional compilation

* Use SSE2 for conditional swap on vector registers. Improves
  performance a little bit.

* Fix f2elm_t definition. Code imported from MSR defines f2elm_t type as
  a array of arrays. This decays to a pointer to an array (when passing
  as an argument). In C, one can't assign const pointer to an array with
  non-const pointer to an array. Seems it violates 6.7.3/8 from C99
  (same for C11). This problem occures in GCC 6, only when -pedantic
  flag is specified and it occures always in GCC 4.9 (debian jessie).

* Fix definition of eval_3_isog. Second argument in eval_3_isog mustn't be
  const. Similar reason as above.

* Use HMAC-SHA256 instead of cSHAKE-256 to avoid upstreaming cSHAKE
  and SHA3 code.

* Add speed and unit tests for SIKE.

Some speed results:

Skylake (64-bit):

Did 408 SIKE/P503 generate operations in 1002573us (407.0 ops/sec)
Did 275 SIKE/P503 encap operations in 1070570us (256.9 ops/sec)
Did 264 SIKE/P503 decap operations in 1098955us (240.2 ops/sec)

Skylake (32-bit):

Did 9 SIKE/P503 generate operations in 1051620us (8.6 ops/sec)
Did 5 SIKE/P503 encap operations in 1038251us (4.8 ops/sec)
Did 5 SIKE/P503 decap operations in 1103617us (4.5 ops/sec)

Change-Id: I22f0bb1f9edff314a35cd74b48e8c4962568e330
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/35204
Reviewed-by: Adam Langley <alangley@gmail.com>
2019-05-16 22:04:58 +00:00
David Benjamin
be7006adac Update third_party/googletest.
The new version of googletest deprecates INSTANTIATE_TEST_CASE_P in
favor of INSTANTIATE_TEST_SUITE_P, so apply the change.

This requires blacklisting C4628 on MSVC 2015 which says about digraphs
given foo<::std::tuple<...>>. Disable that warning. Digraphs are not
useful and C++11 apparently explicitly disambiguates that.

It also requires applying
https://github.com/google/googletest/pull/2226, to deal with a warning
in older MSVC.

Update-Note: Consumers using BoringSSL with their own copy of googletest
must ensure googletest was updated to a version from 2019-01-03 or
later for INSTANTIATE_TEST_SUITE_P to work. (I believe all relevant
consumers are fine here. If anyone can't update googletest and is
building BoringSSL tests, building with
-DINSTANTIATE_TEST_SUITE_P=INSTANTIATE_TEST_CASE_P would work as
workaround.)

Bug: chromium:936651
Change-Id: I23ada8de34a53131cab88a36a88d3185ab085c64
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/35504
Reviewed-by: Adam Langley <agl@google.com>
2019-04-10 22:09:43 +00:00
Brian Smith
3618e8c3eb Remove dead CPU detection logic. 2019-03-14 11:16:26 -10:00
Brian Smith
5486a84315 Remove redundant #include <GFp/base.h>. 2019-03-14 10:57:10 -10:00
David Benjamin
f109f20873 Clear out a bunch of -Wextra-semi warnings.
Unfortunately, it's not enough to be able to turn it on thanks to the
PURE_VIRTUAL macro. But it gets us most of the way there.

Change-Id: Ie6ad5119fcfd420115fa49d7312f3586890244f4
Reviewed-on: https://boringssl-review.googlesource.com/c/34949
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2019-02-21 19:12:39 +00:00
Brian Smith
0728827d2e Don't enable -Wmissing-prototypes and -Wmissing-declarations.
These really don't make much sense any more given most calls are from
Rust to C.
2019-02-13 08:28:30 -10:00
Brian Smith
7362d29696 Fix build with GCC. 2019-02-12 11:44:18 -10:00
Brian Smith
c1cee93f28 Mark Fiat-generated files as generated. 2019-02-12 10:30:13 -10:00
Brian Smith
cda8b2dea1 Take BoringSSL 9847cdd: Fix signed left-shifts in curve25519.c. 2019-02-12 10:12:47 -10:00
Brian Smith
96023750fd Merge BoringSSL 899835f: Rename Fiat include files to end in .h 2019-02-12 09:58:33 -10:00
Brian Smith
fd06534dcd Merge BoringSSL 32e59d2: Switch to new fiat pipeline. 2019-02-12 09:56:51 -10:00
Brian Smith
973d209b8b Merge BoringSSL 5590c71: Mark some unmarked array sizes in curve25519.c. 2019-02-12 09:49:53 -10:00