boringssl/crypto/fipsmodule/ec
David Benjamin eda47f5d98 Make generic point arithmetic slightly less variable-time.
The generic code special-cases affine points, but this leaks
information. (Of course, the generic code also doesn't have a
constant-time multiply and other problems, but one thing at a time.)

The optimization in point doubling is not useful. Point multiplication
more-or-less never doubles an affine point. The optimization in point
addition *is* useful because the wNAF code converts the tables to
affine. Accordingly, align with the P-256 code which adds a 'mixed'
parameter.

(I haven't aligned the formally-verified point formulas themselves yet;
initial testing suggests that the large number of temporaries take a
perf hit with BIGNUM. I'll check the results in EC_FELEM, which will be
stack-allocated, to see if we still need to help the compiler out.)

Strangly, it actually got a bit faster with this change. I'm guessing
because now it doesn't need to bother with unnecessary comparisons and
maybe was kinder to the branch predictor?

Before:
Did 2201 ECDH P-384 operations in 3068341us (717.3 ops/sec)
Did 4092 ECDSA P-384 signing operations in 3076981us (1329.9 ops/sec)
Did 3503 ECDSA P-384 verify operations in 3024753us (1158.1 ops/sec)
Did 992 ECDH P-521 operations in 3017884us (328.7 ops/sec)
Did 1798 ECDSA P-521 signing operations in 3059000us (587.8 ops/sec)
Did 1581 ECDSA P-521 verify operations in 3033142us (521.2 ops/sec)

After:
Did 2310 ECDH P-384 operations in 3092648us (746.9 ops/sec)
Did 4080 ECDSA P-384 signing operations in 3044588us (1340.1 ops/sec)
Did 3520 ECDSA P-384 verify operations in 3056070us (1151.8 ops/sec)
Did 992 ECDH P-521 operations in 3012779us (329.3 ops/sec)
Did 1792 ECDSA P-521 signing operations in 3019459us (593.5 ops/sec)
Did 1600 ECDSA P-521 verify operations in 3047749us (525.0 ops/sec)

Bug: 239
Change-Id: If5d13825fc98e4c58bdd1580cf0245bf7ce93a82
Reviewed-on: https://boringssl-review.googlesource.com/27004
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
2018-04-04 21:33:22 +00:00
..
asm
ec_key.c
ec_montgomery.c
ec_scalar_base_mult_tests.txt Add some EC base point multiplication test vectors. 2018-03-27 23:33:24 +00:00
ec_test.cc Add test coverage for the a != -3 case. 2018-04-02 18:25:08 +00:00
ec.c Make generic point arithmetic slightly less variable-time. 2018-04-04 21:33:22 +00:00
internal.h Make generic point arithmetic slightly less variable-time. 2018-04-04 21:33:22 +00:00
make_ec_scalar_base_mult_tests.go Add some EC base point multiplication test vectors. 2018-03-27 23:33:24 +00:00
make_p256-x86_64-table.go
oct.c Name constant-time functions more consistently. 2018-03-29 23:30:55 +00:00
p224-64.c Implement field_{mul,sqr} in p224-64.c with p224_felems. 2018-04-02 18:27:45 +00:00
p256-x86_64_test.cc
p256-x86_64_tests.txt
p256-x86_64-table.h
p256-x86_64.c
p256-x86_64.h
simple.c Make generic point arithmetic slightly less variable-time. 2018-04-04 21:33:22 +00:00
util.c
wnaf.c Make generic point arithmetic slightly less variable-time. 2018-04-04 21:33:22 +00:00