a838f9dc7e
None of the asymmetric crypto we inherented from OpenSSL is
constant-time because of BIGNUM. BIGNUM chops leading zeros off the
front of everything, so we end up leaking information about the first
word, in theory. BIGNUM functions additionally tend to take the full
range of inputs and then call into BN_nnmod at various points.
All our secret values should be acted on in constant-time, but k in
ECDSA is a particularly sensitive value. So, ecdsa_sign_setup, in an
attempt to mitigate the BIGNUM leaks, would add a couple copies of the
order.
This does not work at all. k is used to compute two values: k^-1 and kG.
The first operation when computing k^-1 is to call BN_nnmod if k is out
of range. The entry point to our tuned constant-time curve
implementations is to call BN_nnmod if the scalar has too many bits,
which this causes. The result is both corrections are immediately undone
but cause us to do more variable-time work in the meantime.
Replace all these computations around k with the word-based functions
added in the various preceding CLs. In doing so, replace the BN_mod_mul
calls (which internally call BN_nnmod) with Montgomery reduction. We can
avoid taking k^-1 out of Montgomery form, which combines nicely with
Brian Smith's trick in
|
||
---|---|---|
.. | ||
asm | ||
add.c | ||
bn_test_to_fuzzer.go | ||
bn_test.cc | ||
bn_tests.txt | ||
bn.c | ||
bytes.c | ||
check_bn_tests.go | ||
cmp.c | ||
ctx.c | ||
div.c | ||
exponentiation.c | ||
gcd.c | ||
generic.c | ||
internal.h | ||
jacobi.c | ||
montgomery_inv.c | ||
montgomery.c | ||
mul.c | ||
prime.c | ||
random.c | ||
rsaz_exp.c | ||
rsaz_exp.h | ||
shift.c | ||
sqrt.c |