boringssl/crypto
David Benjamin 1741a9d143 Save some mallocs in computing the MAC for e_tls.c.
We can reuse the HMAC_CTX that stores the key. The API is kind of unfortunate
as, in principle, it should be possible to do an allocation-averse HMAC with a
shared key on multiple threads at once (EVP_AEAD_CTX is normally logically
const). At some point it may be worth rethinking those APIs somewhat.  But
these "stateful AEADs" are already stateful in their EVP_CIPHER_CTX, so this is
fine.

Each cipher was run individually to minimize the effect of other ciphers doing
their mallocs. (Although the cost of a malloc is presumably going to depend a
lot on the malloc implementation and what's happened before in the process, so
take these numbers with a bucket of salt. They vary widely even with the same
arguments.)

Taking malloc out of seal/open also helps with the malloc tests. DTLS currently
cannot distinguish a malloc failure (should be fatal) from a decryption failure
(not fatal), so the malloc tests get stuck. But this doesn't completely get us
there since tls_cbc.c mallocs. This also assumes EVP_CIPHER_CTX, EVP_MD_CTX,
and HMAC_CTX are all clever about reusing their allocations when reset (which
they are).

Before:
Did 1315000 AES-128-CBC-SHA1 (16 bytes) seal operations in 1000087us (1314885.6 ops/sec): 21.0 MB/s
Did 181000 AES-128-CBC-SHA1 (1350 bytes) seal operations in 1004918us (180114.2 ops/sec): 243.2 MB/s
Did 34000 AES-128-CBC-SHA1 (8192 bytes) seal operations in 1024250us (33195.0 ops/sec): 271.9 MB/s
After:
Did 1766000 AES-128-CBC-SHA1 (16 bytes) seal operations in 1000319us (1765436.8 ops/sec): 28.2 MB/s
Did 187000 AES-128-CBC-SHA1 (1350 bytes) seal operations in 1004002us (186254.6 ops/sec): 251.4 MB/s
Did 35000 AES-128-CBC-SHA1 (8192 bytes) seal operations in 1014885us (34486.7 ops/sec): 282.5 MB/s

Before:
Did 391000 DES-EDE3-CBC-SHA1 (16 bytes) seal operations in 1000038us (390985.1 ops/sec): 6.3 MB/s
Did 16000 DES-EDE3-CBC-SHA1 (1350 bytes) seal operations in 1060226us (15091.1 ops/sec): 20.4 MB/s
Did 2827 DES-EDE3-CBC-SHA1 (8192 bytes) seal operations in 1035971us (2728.8 ops/sec): 22.4 MB/s
After:
Did 444000 DES-EDE3-CBC-SHA1 (16 bytes) seal operations in 1001814us (443196.0 ops/sec): 7.1 MB/s
Did 17000 DES-EDE3-CBC-SHA1 (1350 bytes) seal operations in 1042535us (16306.4 ops/sec): 22.0 MB/s
Did 2590 DES-EDE3-CBC-SHA1 (8192 bytes) seal operations in 1012378us (2558.3 ops/sec): 21.0 MB/s

Before:
Did 1316000 AES-256-CBC-SHA1 (16 bytes) seal operations in 1000510us (1315329.2 ops/sec): 21.0 MB/s
Did 157000 AES-256-CBC-SHA1 (1350 bytes) seal operations in 1002944us (156539.1 ops/sec): 211.3 MB/s
Did 29000 AES-256-CBC-SHA1 (8192 bytes) seal operations in 1030284us (28147.6 ops/sec): 230.6 MB/s
After:
Did 1645000 AES-256-CBC-SHA1 (16 bytes) seal operations in 1000313us (1644485.3 ops/sec): 26.3 MB/s
Did 162000 AES-256-CBC-SHA1 (1350 bytes) seal operations in 1003060us (161505.8 ops/sec): 218.0 MB/s
Did 36000 AES-256-CBC-SHA1 (8192 bytes) seal operations in 1014819us (35474.3 ops/sec): 290.6 MB/s

Before:
Did 1435000 RC4-SHA1 (16 bytes) seal operations in 1000245us (1434648.5 ops/sec): 23.0 MB/s
Did 207000 RC4-SHA1 (1350 bytes) seal operations in 1004675us (206036.8 ops/sec): 278.1 MB/s
Did 38000 RC4-SHA1 (8192 bytes) seal operations in 1022712us (37156.1 ops/sec): 304.4 MB/s
After:
Did 1853000 RC4-SHA1 (16 bytes) seal operations in 1000433us (1852198.0 ops/sec): 29.6 MB/s
Did 206000 RC4-SHA1 (1350 bytes) seal operations in 1002370us (205512.9 ops/sec): 277.4 MB/s
Did 42000 RC4-SHA1 (8192 bytes) seal operations in 1024209us (41007.3 ops/sec): 335.9 MB/s

Change-Id: I0edb89bddf146cf91a8e7a99c56b2278c8f38094
Reviewed-on: https://boringssl-review.googlesource.com/6751
Reviewed-by: Adam Langley <agl@google.com>
2015-12-16 23:56:28 +00:00
..
aes Fix the shared builders by exporting GCM symbols. 2015-10-26 23:26:40 +00:00
asn1 Limit depth of ASN1 parse printing. 2015-12-15 19:06:04 +00:00
base64 Add a run_tests target to run all tests. 2015-10-26 20:33:44 +00:00
bio Test for underflow before subtraction. 2015-11-11 22:20:04 +00:00
bn Switch unrolled loop in BN_usub with memcpy. 2015-12-16 17:38:48 +00:00
buf Make |BUF_memdup| look for zero length, not NULL. 2015-10-06 18:11:33 -07:00
bytestring Make CBB_len relative to its argument. 2015-12-16 21:16:12 +00:00
chacha Change |CRYPTO_chacha_20| to use 96-bit nonces, 32-bit counters. 2015-10-26 23:58:46 +00:00
cipher Save some mallocs in computing the MAC for e_tls.c. 2015-12-16 23:56:28 +00:00
cmac Add a run_tests target to run all tests. 2015-10-26 20:33:44 +00:00
conf Move arm_arch.h and fix up lots of include paths. 2015-08-26 01:57:59 +00:00
curve25519 Register the *25519 tests as dependencies of all_tests. 2015-11-19 01:09:09 +00:00
des Use the straight-forward ROTATE macro. 2015-12-16 19:57:31 +00:00
dh Remove the CRYPTO_EX_new callback. 2015-12-15 21:29:46 +00:00
digest Fix build. 2015-12-16 21:26:12 +00:00
dsa Fix memory leak in DSA redo case. 2015-12-16 21:17:09 +00:00
ec Slightly tweak some array allocations. 2015-12-16 21:19:32 +00:00
ecdh Clean up |ECDH_compute_key|. 2015-10-27 17:00:25 +00:00
ecdsa Add |EC_GROUP_get0_order| to replace |EC_GROUP_get_order|. 2015-12-15 18:18:13 +00:00
engine Unwind DH_METHOD and DSA_METHOD. 2015-11-03 22:54:36 +00:00
err Reset ssl error codes. 2015-12-16 18:38:20 +00:00
evp Remove DH EVP_PKEY hooks. 2015-12-16 17:38:06 +00:00
hkdf Add a run_tests target to run all tests. 2015-10-26 20:33:44 +00:00
hmac Remove condition which always evaluates to true (size_t >= 0). 2015-11-11 22:20:19 +00:00
lhash Add a run_tests target to run all tests. 2015-10-26 20:33:44 +00:00
md4 Make HOST_l2c return void. 2015-12-16 20:02:37 +00:00
md5 Make HOST_l2c return void. 2015-12-16 20:02:37 +00:00
modes Use UINT64_C instead of OPENSSL_U64. 2015-11-16 23:18:00 +00:00
obj Move arm_arch.h and fix up lots of include paths. 2015-08-26 01:57:59 +00:00
pem Fix all sign/unsigned warnings with Clang and GCC. 2015-10-27 22:48:00 +00:00
perlasm Get rid of all compiler version checks in perlasm files. 2015-10-28 19:33:04 +00:00
pkcs8 Check for overflow when parsing a CBS with d2i_*. 2015-11-16 23:17:42 +00:00
poly1305 Remove stl_compat.h. 2015-11-11 22:19:36 +00:00
rand Don't abort in |init_once| if |fcntl| returns ENOSYS 2015-12-15 18:10:40 +00:00
rc4 Fix a couple more signed/unsigned compares. 2015-10-27 16:07:26 -07:00
rsa Remove the CRYPTO_EX_new callback. 2015-12-15 21:29:46 +00:00
sha Remove asm __asm__ define. 2015-12-16 20:03:17 +00:00
stack Move arm_arch.h and fix up lots of include paths. 2015-08-26 01:57:59 +00:00
test Remove stl_compat.h. 2015-11-11 22:19:36 +00:00
x509 Remove the CRYPTO_EX_new callback. 2015-12-15 21:29:46 +00:00
x509v3 Become partially -Wmissing-variable-declarations-clean. 2015-11-12 20:09:20 +00:00
CMakeLists.txt Add X25519 and Ed25519 support. 2015-11-17 21:56:12 +00:00
constant_time_test.c
cpu-arm-asm.S
cpu-arm.c Allow |CRYPTO_is_NEON_capable| to be known at compile time, if possible. 2015-11-19 00:15:11 +00:00
cpu-intel.c Surround immintrin.h includes with warning pragmas. 2015-07-20 20:08:26 +00:00
crypto.c Make CRYPTO_library_init use a CRYPTO_once_t. 2015-11-19 18:05:22 +00:00
directory_posix.c
directory_win.c
directory.h
ex_data.c Skip free callbacks on empty CRYPTO_EX_DATAs. 2015-12-15 21:32:14 +00:00
internal.h Remove the CRYPTO_EX_new callback. 2015-12-15 21:29:46 +00:00
mem.c Fix some typos in license headers. 2015-07-29 19:23:51 +00:00
refcount_c11.c
refcount_lock.c
refcount_test.c
thread_none.c
thread_pthread.c Make sure pthread_once() succeeds. 2015-11-17 21:44:40 +00:00
thread_test.c Use the correct case for Windows headers. 2015-06-09 21:38:04 +00:00
thread_win.c
thread.c
time_support.c