5932 Commits
Author SHA1 Message Date
Adam Langley 5f14300d2b Fix GRND_NONBLOCK flag when calling getrandom.
I screwed up in 56b6c714c9 and got the direction of this condition
backwards. This doesn't cause a security problem because:
  a) wait_for_entropy will ensure that the pool is initialised.
  b) if GRNG_NONBLOCK is set when not expected, any EAGAIN will
     cause an abort anyway.

However, when coupled with opportunistic entropy collection on platforms
with RDRAND, this could cause an unexpected blocking getrandom call.

This this change, `strace -e getrandom bssl rand 1` shows two getrandom
calls with GRNG_NONBLOCK set, as expected. (The first being the probe to
check whether the kernel supports getrandom, and the second being the
opportunistic entropy gathering to augment RDRAND.)

Bug: chromium:1016811
Change-Id: I98ed1cef90df510f24cf2df1fba9b886fcbf3355
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/38204
Commit-Queue: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
(cherry picked from commit f3bd757ee5)
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/38504
2019-10-23 19:32:27 +00:00
David Benjamin bc4c09df64 Add a function to derive an EC key from some input secret.
Chrome sync folks need to do this. Add a function for it. There doesn't
seem to be a standard way to do it, so pick something arbitrary.

Bug: chromium:1010968
Change-Id: Ib55456e4af5849cd9da33f397e8f12deb6f02917
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/38144
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-10-11 21:17:19 +00:00
David Benjamin 7458ded264 Fix run_android_tests.go with shared library builds.
In particular, the FIPS builds use shared libraries.

Change-Id: I4ca3a289ad3af8ab24c4bf1aecd5de67f9496f15
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/38147
Commit-Queue: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-10-11 21:16:38 +00:00
David Benjamin 86ee70b6ff No-op change to test new builders.
Change-Id: I3f715b35968168e4e80fb643e28d4169797c0898
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/38146
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2019-10-11 18:44:38 +00:00
Adam Langley c48c8b6f64 Move no-exec-stack sections outside of #ifs.
When building with |OPENSSL_NO_ASM|, the section that marks assembly
files as no-exec-stack will currently be omitted. That results in an
empty assembly file but that's still enough to trigger warnings:

warning: crypto_tests/trampoline-x86_64.o: missing .note.GNU-stack section implies executable stack

This change makes it so that the section marker will always be emitted,
even if the file is otherwise empty.

Change-Id: I2d08d34ed9dbe9e9592c88dcd42d3ba4fa3d7652
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/38084
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2019-10-10 17:27:51 +00:00
Alessandro Ghedini 12049fd3ad Add |SSL_get_min_proto_version| and |SSL_get_max_proto_version|
This makes it possible to fetch the min and max versions configured
directly on SSL objects (as opposed to SSL_CTX ones).

This is useful when configuring supported TLS versions on per-connection
basis.

Change-Id: Ibccc92c5f7668e9a7be5a01d6f84089608382407
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/38104
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2019-10-10 16:56:41 +00:00
Adam Langley 4ca15d5dcb Make FIPS build work for Android cross-compile.
Change-Id: I67db234ad80fa1eb4af4e28ac7b5236dd6ec4b63
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/38065
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2019-10-09 20:16:11 +00:00
Pete Bentley 56b6c714c9 Enable optional GRND_RANDOM flag to be passed to getrandom on Android.
Introduces optional extra flags for getrandom which are ORed in when
reading a FIPS seed.  Setting the Android read-only system property
ro.boringcrypto.hwrand to true will set the extra flags to GRND_RANDOM.

Testing: Built and tested on AOSP as http://r.android.com/1134926
and verified behaviour via the extra printfs in that CL and also
observing the flags passed to getrandom using strace.

Change-Id: Idd782df65ba0d49b8b1357b346caa4ef747587f1
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/38024
Reviewed-by: David Benjamin <davidben@google.com>
2019-10-09 19:46:17 +00:00
David Benjamin 8fe1584023 Switch cert_compression_algs to GrowableArray.
It's much less typing than STACK_OF(T).

Change-Id: Idda99549ba35ff8d02fb6e3790f30f6566236076
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/38044
Reviewed-by: Dan McArdle <dmcardle@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2019-10-08 21:41:56 +00:00
Daniel McArdle ff746c103f Add GrowableArray<T> to ssl/internal.h.
Change-Id: I07aced6d2830dd5a2a04c296b1ffe7e8557369fe
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37504
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2019-10-08 21:23:05 +00:00
Goutam Tamvada 49de1fc291 Fixed quic_method lookup in TLS 1.3 server side handshake.
Commit 3cbb0299a allows for quic_method to be configured
per-connection. However, before this, do_send_new_session_ticket()
in ssl/tls13_server.cc read quic_method from the underlying
SSL context.

Change-Id: I04ea2be23dc8e32b3232b8f59e266bd381e8f3c4
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/38004
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2019-10-04 22:09:32 +00:00
David Benjamin 9c49713ba8 Add .note.GNU-stack at the source level.
GNU-based toolchains on ELF platforms default the stack to executable
and rely on a .note.GNU-stack section in *each* object file to flip it
off. The compiler knows to do this for its object files, but assembly
does everything by hand. See this link for details:
https://www.airs.com/blog/archives/518

We do this in the cmake build by passing -Wa,--noexecstack to the
assembler. However, since we have to deal with many buildsystems, it
would be more robust to put it in the source.

It's unclear whether this should be gated on ELF or Linux. The Gentoo
and Ubuntu documents recommend checking for Linux with gas, but only ELF
with NASM.
https://wiki.gentoo.org/wiki/Hardened/GNU_stack_quickstart
https://wiki.ubuntu.com/SecurityTeam/Roadmap/ExecutableStacks

At the same time, these links suggest it is an ELF-wide issue and not
just Linux:
https://github.com/golang/go/issues/5392
https://reviews.freebsd.org/D11033

https://github.com/openssl/openssl/issues/4575 also discusses this but
the rationale lists both ELF and non-ELF platforms, so it's unclear.

Treat it as ELF-wide for now. We can revisit this if necessary.

Update-Note: If there is a build failure due to .note.GNU-stack, holler.
Change-Id: Ic59096aa1fc2bf5380a412c9991de22cb46c0faf
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37984
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2019-10-03 22:10:36 +00:00
Adam Langley 6a2609dae2 -Wno-vla -> -Wvla
Advice from the build folks changed. See b/141974065.

Change-Id: Ib981018ed49ef04d1f87a91b0ef8f7bc4bd524f7
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37964
Commit-Queue: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2019-10-03 21:31:43 +00:00
David Benjamin 0e7dbd579b Add an option for explicit renegotiations.
Chromium's renegotiation handling currently relies on reads being the only
thing that can discover a renegotiation. However, for a number of reasons, we
would like to eagerly drive the read loop after a handshake:

- 0-RTT + HTTP/1.1 will otherwise not pick up ServerHellos until after we send
  a request. In particular, if we preconnect a 0-RTT socket sufficiently in
  advance, such that the ServerHello comes in by the time we use it, we should
  send 1-RTT data rather than 0-RTT.

- In TLS 1.2 False Start, if HTTP/1.1 or preconnect, we will not pick up the
  server Finished and NewSessionTicket until later. This way we pick it up
  sooner.

- If the server does not implement
  https://boringssl-review.googlesource.com/c/boringssl/+/34948, this plugs the
  theoretical deadlock on the client end. The False Start and 0-RTT scenarios
  above also have theoretical deadlocks and cannot be mitigated on the server.

- TLS 1.3 client certificate alerts interact badly with TCP reset. Eagerly
  reading from the socket makes it behave slightly better, though it's still
  not reliable unless the server defers closing the socket.

So we can SSL_peek without triggering a renegotiation, add an
ssl_renegotiate_explicit mode to defer processing the renegotiation.

Bug: chromium:950706, chromium:958638
Change-Id: I78242d93d651b7a32a5c4c24ea9032ef63a027cf
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37944
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-10-03 21:12:43 +00:00
Zola Bridges f10ea55e91 tool: add -json flag to |speed|
Add a flag to speed.cc to generate machine-readable benchmark results.

Change-Id: I24a4324c5195b15494dc6d9471aa91c27b9f881d
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37865
Reviewed-by: Adam Langley <alangley@gmail.com>
Reviewed-by: Zola Bridges <zbrid@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2019-10-02 19:30:10 +00:00
Adam Langley 95017b9bf4 Set -Wno-vla.
Would have avoided 6e7255c17e.

Change-Id: I94eeea70f6ee0b48c1a15b512d652579d65d0edf
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37924
Commit-Queue: Adam Langley <alangley@gmail.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2019-10-02 19:15:49 +00:00
Pete Bentley 6e7255c17e Use a pointer to module_hash in boringssl_fips_self_test() args.
1) Matches signature in internal.h
2) Works around presubmit build errors in Trusty: b/141974065

Nit: Should probably be const uint8_t *const module_hash
Change-Id: Id16ceea8442f4e8e588f84a8ef45e2320435809b
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37904
Commit-Queue: Pete Bentley <prb@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-10-02 13:39:35 +00:00
Adam Langley 9638f8fba9 Use a smaller hex digest in FIPS flag files when SHA-256 used.
1458b49a9e switched to using HMAC-SHA256 for FIPS integrity checks on
Android. However, the flag file was named after a full 64-byte hex
digest. The additional 32 bytes weren't uninitialised, but are still
superfluous. This change gets rid of them.

Change-Id: I192af9eb2b94833cdea3620a153d4fd05c7265b9
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37864
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2019-10-01 19:18:33 +00:00
Adam Langley 1458b49a9e Switch to using SHA-256 for FIPS integrity check on Android.
SHA-256 is likely to be faster on these devices given that a) some will
be 32-bit and b) some will have SHA-256 instructions.

BUG=141710485

Change-Id: I3a3fbb2b8db4f1a4d3059b39b188aee0e0462dd4
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37845
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2019-09-30 21:51:37 +00:00
David Benjamin 40633ac196 Use getentropy on macOS 10.12 and later.
Bug: 287
Change-Id: I40760bdba8dcaab9c5c38d52d6479138f52eccbd
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37284
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-09-30 18:30:23 +00:00
Matthew Braithwaite 6f80629b6c Move #include of "internal.h", which defines |OPENSSL_URANDOM|.
Change-Id: Ib8f8f3ae49342478def9233716a49eed1398b355
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37844
Commit-Queue: Matt Braithwaite <mab@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2019-09-30 18:10:13 +00:00
David Benjamin b9a8fd766e Style nit.
Output parameters should be prefixed with out_.

Change-Id: I7ba9ef6f666301140127fdf5d747cfe3755cf53e
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37788
Reviewed-by: Adam Langley <agl@google.com>
2019-09-30 18:06:10 +00:00
David Benjamin 45610f9afb Assert that BN_CTX_end is actually called.
If a function forgets to BN_CTX_end, everything will work but we'll use
more memory than intended. Catch such errors by asserting in
BN_CTX_free.

Update-Note: BN_CTX is exposed publicly. Some callers may have been
using it wrong and trip this assert. If so, add the missing BN_CTX_end
calls.

Change-Id: I9c38431376a256e5176fd295c0114a10a7f588bd
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37787
Reviewed-by: Adam Langley <agl@google.com>
2019-09-30 18:05:44 +00:00
David Benjamin 6784dc718c Test some known large primes.
Extracted from openssl genrsa.

Change-Id: Ida17de016ce589172cba4a4a030770d208701c9c
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37786
Reviewed-by: Adam Langley <agl@google.com>
2019-09-30 18:05:09 +00:00
David Benjamin e7e5a23b4e Test some Euler pseudoprimes.
The Miller-Rabin test is an extension of the Fermat test (in addition to
looking for a^(n-1) != 1, it also looks for a non-trivial square root of
unity). It thus seems prudent to sanity-check we indeed reject Fermat
pseudoprimes. Euler pseudoprimes are a stronger constraint, so test
those.

Change-Id: I959769de2da3f8579403621bcf893e7c9247ca33
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37785
Reviewed-by: Adam Langley <agl@google.com>
2019-09-30 18:03:50 +00:00
David Benjamin 6dfb479755 Be consistent about Miller-Rabin vs Rabin-Miller.
We mostly say Miller-Rabin but sometimes say Rabin-Miller. git log -S
suggests this is mostly my fault for picking the less common order.
Miller-Rabin is also the more common order according to the internet, so
use that.

Change-Id: Id18853469a641af6d1c37d3ec87c3110e01e6b71
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37784
Reviewed-by: Adam Langley <agl@google.com>
2019-09-30 18:03:08 +00:00
Michel Promonet bd522862a0 fix build with armv6 Error: .size expression for _vpaes_decrypt_consts does not evaluate to a constant
Before change cross compiling with https://sourceforge.net/projects/raspberry-pi-cross-compilers/files/Raspberry%20Pi%20GCC%20Cross-Compiler%20Toolchains/GCC%209.1.0/Raspberry%20Pi%201%2C%20Zero/cross-gcc-9.1.0-pi_0-1.tar.gz
 fails
arm-linux-gnueabihf-gcc  -march=armv6 -mfloat-abi=hard -mfpu=vfp -marm -c vpaes-armv7.S -o vpaes-armv7.o
/tmp/cctW8fgE.s: Assembler messages:
/tmp/cctW8fgE.s: Error: .size expression for _vpaes_decrypt_consts does not evaluate to a constant

Bug: 291
Change-Id: Ib2bf608943bbb406b33181a75f1ade2c4bab09ba
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37824
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2019-09-30 17:20:03 +00:00
David Benjamin 0bb4345bfe Mark ssl_early_data_reason_t values stable.
SSL_get_early_data_reason solely exists for histogramming purposes. To
save everyone a lot of boilerplate, just make the values stable.

Change-Id: I3fd3d294de1a66a8eaea96cd6491495f93b1b117
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37766
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-09-27 20:17:03 +00:00
David Benjamin 0de64a749b Make the dispatch tests opt-in.
The assembly dispatch tests currently assume NDEBUG is consistently
defined between C/C++ and assembly. While this is usually the case for
UNIX, CMake does not pass NDEBUG to NASM. This is giving gRPC some
difficulties in updating BoringSSL, so switch it to an opt-in
-DBORINGSSL_DISPATCH_TEST flag instead.

Update-Note: If you were copying NDEBUG over to assembly files, that's
no longer required (though it's harmless to leave it in). If you want to
run ImplDispatchTest.*, build both C/C++ and assembly with
-DBORINGSSL_DISPATCH_TEST in your debug builds. (Don't enable it in
release builds. It causes assembly to scribble in some globals.)

Change-Id: I9ab3371dc0f0a40b27b44ef93835e007a6346900
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37764
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-09-27 19:02:43 +00:00
David Benjamin 63e96f2a29 Bound the number of API calls in ssl_ctx_api.cc.
By spamming just two bytes, this fuzzer can bounce between
SSL_CTX_use_certificate and SSL_CTX_get0_certificate, which continually
runs d2i_X509 on some certificate.

Doing that nearly 400,000 times is not particularly useful. Bound the
number of API calls. Start with 10,000 and see if the fuzzers are still
unhappy.

Bug: oss-fuzz:17748
Change-Id: I074fa08475fffcb86c02e64dcb9c5c7c69bcda71
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37765
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-09-27 15:52:53 +00:00
Adam Langley 3a3552247e Only attempt to mprotect FIPS module for AArch64.
This need doesn't arise on other Android platforms at the current time.

Change-Id: I38c9b5417ec6717210f5797d86d226ab0d9a4232
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37744
Reviewed-by: Adam Langley <agl@google.com>
2019-09-25 23:18:21 +00:00
David Benjamin 622e46bf27 Opportunistically read entropy from the OS in FIPS mode.
Even if RDRAND works, still mix in /dev/urandom or
getrandom(GRND_NONBLOCK) in the likely case that the entropy pool has
been initialized.

Change-Id: Ia61fc6eb07e90ae725a1781311c0ecc2fdabca87
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37664
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-09-24 17:05:18 +00:00
Matthew Braithwaite 1f1af82f40 Update INSTANTIATE_TEST_SUITE_P calls missing first argument.
This is going to be disallowed, apparently.

Change-Id: I73868e1145f3e4e2438c2a31146ba0767b9f01fe
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37684
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2019-09-24 16:49:29 +00:00
Pete Bentley 15b4fb2acf Ignore build32 and build64 subdirectories.
Used for Conscrypt local builds:
https://github.com/google/conscrypt/blob/master/BUILDING.md

Change-Id: I7eaa225cdc3c79cb5ac4902d222d408169f7ded0
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37724
Commit-Queue: Pete Bentley <prb@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-09-24 16:10:38 +00:00
Pete Bentley 09a9ec0360 Add page protection logic to BCM self test.
On Android only, assume code is compiled for Execute-only memory, so add
Read permission for the duration of the self test and
then mark the pages Execute-only again.

NB if libcrypto is not compiled for Execute-only memory, then attempting
to change the page permissions to PROT_EXEC at the start of the self
test does not cause it to fail, however changing it to PROT_NONE does.

Bug: 134580074
Test: m && flashall
Test: Manual tests described above.

Change-Id: Ibbf8405a5a9b162ce26532127aaf62c539cd9163
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37644
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-09-23 15:50:35 +00:00
David Benjamin 6e8d5f4a4f Disable unwind tests in FIPS mode.
Delocate currently breaks things.

Bug: 289
Change-Id: Ia8c601b954e2dfda9bb4eccdde12dcd64e8559c7
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37624
Commit-Queue: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-09-20 00:10:53 +00:00
Adam Langley 398ca1c3d6 Disable RDRAND on AMD family 0x17, models 0x70–0x7f.
Change-Id: I634a3077beedf40816a1f6179ccf92d853979601
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37604
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2019-09-19 21:40:36 +00:00
Adam Langley bb50783805 Don't allow SGC EKUs for server certificates.
The Server Gated Cryptography EKUs are a left-over from 1990's export
regulations. For historical reaons, the SGC EKUs are accepted as a valid
substitute for a server authentication EKU, but they shouldn't be. This
change makes it so that we ignore them.

Change-Id: Ie184c52f588ae391a95d61c474ee6324bdd8f4f2
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37545
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2019-09-19 19:56:46 +00:00
Adam Langley 04a89c8435 Add |SSL_CIPHER_get_value| to get the IANA number of a cipher suite.
Change-Id: I1d642e0bf319421d49b48f25803280046a85a176
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37585
Commit-Queue: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
2019-09-18 21:55:39 +00:00
Shelley Vohr 98e848aa34 Add XOF compilation compatibility flags
This CL adds compatibility flags for XOF digests in service of easing
compatibility between OpenSSL and BoringSSL. See this logic in Node:
https://github.com/nodejs/node/blob/master/src/node_crypto.cc#L4599-L4611

Change-Id: I7f12bed8fb1ea2d9e49dba14ed0c4c819596c70d
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37564
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2019-09-18 21:38:09 +00:00
David Benjamin 0c4d013916 Replace BIO_printf with ASN1_STRING_print in GENERAL_NAME_print
(Imported from upstream's 8479e9e97354add3c562670db66b5f8151dc3b2e.)

Change-Id: I55843a519b9b361de1b175c09382bbf18d4acfff
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37584
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2019-09-18 21:26:39 +00:00
David Benjamin a7d9ac2af4 Trigger a build on the ARM mode builder.
Checking that it works right.

Change-Id: If27b127bc3d78dc96d6636ba5b4b3c0316366939
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37527
Reviewed-by: David Benjamin <davidben@google.com>
2019-09-16 21:31:16 +00:00
David Benjamin 053880d3f7 Fix vpaes-armv7.pl in ARM mode.
This file runs against the limit of ARMv7's ADR pseudo-instruction. ADR
expands to an ADD or SUB of the pc register to find an address. That
immediate must fit in ARM's encoding scheme: 8 bits of constant and 4
bits of rotation. This means larger values must be more aligned.

ARM additionally has two encodings, ARM and Thumb mode. Our assembly
files may use either encoding (do we actually need to support this?). In
ARM mode, the distances get large enough to require 16-byte alignment.
Moving constants closer to their use resolves most of this, but common
constants in _vpaes_consts are used by the whole file. Affected ADR
instructions must be placed at 8 mod 16 (the pc register is 8 ahead).
Instructions with this constraint have been commented.

For details on ARM's immediate value encoding scheme, see
https://alisdair.mcdiarmid.org/arm-immediate-value-encoding/

Update-Note: See b/141080375
Change-Id: Iadac36d800bb45901b513055fcc28a3a60f9060c
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37524
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
2019-09-16 21:07:01 +00:00
Adam Langley 0142c87a26 Add AES-192-GCM support to EVP_AEAD.
(But don't use it for anything new; interop only.)

Change-Id: I59dfb0d3fd4745b5f8d75aa38f7846431d3348c3
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37444
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
2019-09-16 18:28:31 +00:00
Shelley Vohr 012a444265 Add AES-256 CFB to libdecrepit.
Electron builds Node.js with BoringSSL. They want to match OpenSSL as
much as possible and thus have a patch[1] that adds AES-256 CFB mode.
However, that patch makes libcrypto depend on libdecrepit, which can't
be done in general. This change lands the AES-256 CFB support in
libdecrepit without the libcrypto bit and, in order for BoringSSL to
remain consistent, without advertising support in
EVP_CIPHER_do_all_sorted. This will let Electron reduce the size of
their patch a bit.

[1] https://github.com/electron/electron/blob/master/patches/boringssl/expose_aes-cfb.patch

Change-Id: If628d22a595b354623439c587542e414e43e4045
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37264
Reviewed-by: Adam Langley <agl@google.com>
2019-09-16 18:11:40 +00:00
David Benjamin ec92ec471c Parse explicit EC curves more strictly.
Wycheproof has a series of ECDH tests for whether we reject misspelled
explicit versions of named curves in public keys, including the wrong
cofactor. We pass those tests easily because we reject those in public
keys altogether, consistent with RFC 5480.

However, we do parse explicit curves for private keys, for compatibility
with keys produced by older OpenSSLs with unfortunate defaults. Were
that parser enabled for public keys too, we would trip some of these
Wycheproof tests because we ignore the cofactor.

Tighten the parser up. If the cofactor is not one, ignore the curve.
Also syntax-check the seed, even though we ignore it.

Change-Id: I39936e027a72d2dc5532beb2407575ad8042d4c9
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37484
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2019-09-16 16:55:31 +00:00
David Benjamin b82f945ebc Use the Go 1.13 standard library ed25519.
Less code to carry around.

Change-Id: Ia5397f992e3cbaf0a868ed51c02154c6f5805205
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37465
Reviewed-by: Adam Langley <agl@google.com>
2019-09-13 22:53:24 +00:00
David Benjamin 68489e6da5 Update build tools.
Change-Id: Ifce1fc2802e3d3badb3f08ae65c2bbf3c9434d07
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37464
Reviewed-by: Adam Langley <agl@google.com>
2019-09-13 22:51:54 +00:00
David Benjamin f4d8b96920 Use ScopedEVP_AEAD_CTX in ImplDispatchTest.AEAD_AES_GCM.
EVP_AEAD_CTX_cleanup is often a no-op now that the data is embedded, but
best to be tidy.

Change-Id: I1ba56e5e36d6e69ae1ba07e40c4a7bda7329fa79
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37430
Reviewed-by: Adam Langley <agl@google.com>
2019-09-13 17:48:50 +00:00
David Benjamin ccaee0a64c Use a mix of bsaes and vpaes for CTR on NEON.
tl;dr: AES is now constant-time on 32-bit ARM with NEON. Combined with
all the past work, we now have constant-time AES and GHASH on ARM and
x86 chips, 32-bit and 64-bit, provided NEON (required by Chrome on
Android, aside from https://crbug.com/341598) or SSSE3 (almost all
Chrome on Windows users) is available!

CTR-like bsaes modes is harder to resolve than CBC decryption. They use
both bulk (ctr128_f) and one-off (block128_f) operations. We currently
use ctr128_f of bsaes and block128_f of aes_nohw (not constant-time),
which hits 22.0 MB/s on my test chip.

Implement a vpaes/bsaes hybrid to get the best of both worlds. The key
is kept in vpaes form and, when the input is large enough, we convert
the key to bsaes on-demand. This retains bsaes performance, but with no
variable-time gaps.

Alternatives considered:

- Convert to bsaes form immediately and only use bsaes. This makes the
  one-off block128_f calls very expensive. One 8-block batch of
  bsaes_ctr32_encrypt_blocks costs as much as 5.76 vpaes_encrypt calls.

- Do the above, but fold the one-off calls into bsaes batches because
  GCM is parallelizable. This is a mess with the current internal
  structure and doesn't apply to, e.g., CCM.

- Drop bsaes in favor of vpaes. However, even with
  vpaes_ctr32_encrypt_blocks, vpaes is 15.5 MB/s. The hybrid is a 40%
  win on an important platform.

- Try to narrow the gap, as we did for x86_64, with a "2x" optimization.
  I attempted this here but the register pressure was tricky. (x86_64
  was already tight and NEON can't address memory in vtbl.) If I ignored
  this (gives wrong answer), the gap was still 20-25%. Perf here is
  slower overall (20 MB/s for old ARM vs 120-140 MB/s for old x86_64),
  so that gap is scarier.

I retained vpaes_ctr32_encrypt_blocks because it's fairly compact (only
84 bytes assembled), though it's less important in the bsaes hybrid.

Cortex-A53 (Raspberry Pi 3 Model B+)
Before:
Did 267000 AES-128-GCM (16 bytes) seal operations in 2004871us (133175.7 ops/sec): 2.1 MB/s
Did 135000 AES-128-GCM (256 bytes) seal operations in 2013825us (67036.6 ops/sec): 17.2 MB/s
Did 31000 AES-128-GCM (1350 bytes) seal operations in 2059039us (15055.6 ops/sec): 20.3 MB/s
Did 5565 AES-128-GCM (8192 bytes) seal operations in 2073607us (2683.7 ops/sec): 22.0 MB/s
Did 2709 AES-128-GCM (16384 bytes) seal operations in 2020264us (1340.9 ops/sec): 22.0 MB/s
Did 209000 AES-256-GCM (16 bytes) seal operations in 2005654us (104205.4 ops/sec): 1.7 MB/s
Did 109000 AES-256-GCM (256 bytes) seal operations in 2011293us (54194.0 ops/sec): 13.9 MB/s
Did 25000 AES-256-GCM (1350 bytes) seal operations in 2082385us (12005.5 ops/sec): 16.2 MB/s
Did 4452 AES-256-GCM (8192 bytes) seal operations in 2080729us (2139.6 ops/sec): 17.5 MB/s
Did 2226 AES-256-GCM (16384 bytes) seal operations in 2079819us (1070.3 ops/sec): 17.5 MB/s

After:
Did 542000 AES-128-GCM (16 bytes) seal operations in 2003408us (270539.0 ops/sec): 4.3 MB/s [+104.8%]
Did 124000 AES-128-GCM (256 bytes) seal operations in 2012579us (61612.5 ops/sec): 15.8 MB/s [-8.1%]
Did 30000 AES-128-GCM (1350 bytes) seal operations in 2020636us (14846.8 ops/sec): 20.0 MB/s [-1.5%]
Did 5502 AES-128-GCM (8192 bytes) seal operations in 2068807us (2659.5 ops/sec): 21.8 MB/s [-0.9%]
Did 2772 AES-128-GCM (16384 bytes) seal operations in 2085176us (1329.4 ops/sec): 21.8 MB/s [-0.9%]
Did 459000 AES-256-GCM (16 bytes) seal operations in 2003587us (229089.1 ops/sec): 3.7 MB/s [+117.6%]
Did 100000 AES-256-GCM (256 bytes) seal operations in 2018311us (49546.4 ops/sec): 12.7 MB/s [-8.6%]
Did 24000 AES-256-GCM (1350 bytes) seal operations in 2026975us (11840.3 ops/sec): 16.0 MB/s [-1.2%]
Did 4410 AES-256-GCM (8192 bytes) seal operations in 2079581us (2120.6 ops/sec): 17.4 MB/s [-0.6%]
Did 2226 AES-256-GCM (16384 bytes) seal operations in 2099318us (1060.3 ops/sec): 17.4 MB/s [-0.6%]

Bug: 256
Change-Id: Ib74ab7e63974d3ddae8ce5fc35c9b44e73dce305
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/37429
Reviewed-by: Adam Langley <agl@google.com>
2019-09-13 17:47:18 +00:00