| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
| |
Fix a few minor issues found thereby
|
|
|
|
| |
Add a checker script.
|
|
|
|
| |
No real bugs, but pointed out some odd constructs and duplicated logic
|
|
|
|
|
|
|
|
|
|
|
|
| |
In the long ago when I wrote the Barrett code I must have missed that
Barrett works for any input < 2^2k where k is the word size of the
modulus. Fixing this has several nice effects, it is faster because it
replaces a multiprecision comparison with a single size_t compare, and
now the branch does not reveal information about the input or modulus,
but only their word lengths, which is not considered sensitive.
Fixing this allows reverting the change make in a57ce5a4fd2 and now
RSA signing is even slightly faster than in 2.8, rather than 30% slower.
|
|
|
|
| |
As it would leak if an input was > p^2, or just close to it in size.
|
| |
|
|
|
|
|
|
|
|
| |
Was already done in P-256 but not in P-{192,224,384}.
This is a cache-based side channel which would be good to address. It
seems like it would be very difficult to exploit even with perfect
recovery, but crazier things have worked.
|
|
|
|
|
| |
We know the lookup table is some power of 2, unrolling a bit
allows more IPC
|
|\ |
|
| |
| |
| |
| |
| | |
Previous EEA leaked information about the low word of the prime,
which is a problem for RSA.
|
| | |
|
|/
|
|
|
|
| |
Instead require the inputs be reduced already. For RSA-CRT use
Barrett which is const time already. For SRP6 inputs were not reduced,
use the Barrett hook available in DL_Group.
|
|
|
|
| |
This var is not used if we use Baile-PSW instead
|
|
|
|
| |
This is a tiny thing but it saves over 100K cycles for P-384 ECDSA
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
Otherwise we can end up calling the Barrett reducer with an input that
is more than the square of the modulus, which will make it fall back
to the (slow) const time division.
This only affected even moduli, and only when the base was larger than
the modulus.
OSS-Fuzz 11750
|
|
|
|
| |
This is still leaky, but much less than before.
|
| |
|
| |
|
| |
|
| |
|
|
|
|
| |
Previously handled by the early exit
|
|
|
|
| |
Also avoid an early exit in P-521
|
|
|
|
| |
In particular comparisons, calc sig words, and mod_sub are const time now.
|
|
|
|
|
|
|
|
|
|
|
| |
Avoid throwing base Botan::Exception type, as it is difficult to
determine what the error is in that case.
Add Exception::error_code and Exception::error_type which allows
(for error code) more information about the error and (for error type)
allows knowing the error type without requiring a sequence of catches.
See GH #1742
|
|
|
|
|
| |
This is still vulnerable to a cache-based side channel since the
multiple chosen leaks the final carry.
|
|
|
|
| |
Avoid recalculating significant words which slows down reduction
|
| |
|
|
|
|
|
|
|
| |
Avoid doing the comparison against the largest hard coded prime,
when we know the prime table is 16 bits and we already have to
compute the bitsize of n in order to calculate the required number
of Miller-Rabin iterations.
|
|
|
|
|
|
|
|
|
|
| |
This was the original behavior but 5af44a91ad switched the sieve
to always be the size of the hardcoded prime table. But this ends
up being quite a bit slower than necessary. Instead use as many
sieve elements as bits in the desired prime which is probably not
precisely optimal but seems to provide good speedups for both 1024
and 2048 bit prime generation. This is especially notable when generating
strong primes.
|
| |
|
|
|
|
| |
It is the default...
|
|
|
|
|
|
|
|
|
|
| |
It turned out 8 bit was very broken (failed to compile, due to
overload problems with functions taking uint8_t vs word).
16 bit words work aside from a test failure, but is really slow.
Practically speaking we are not in a position to support 16-bit CPUs
very well. And being able to assume sizeof(word) >= sizeof(uint32_t)
allows simplifying some code.
|
| |
|
|
|
|
|
|
|
|
|
|
| |
This eliminates an issue identified in the paper
"Prime and Prejudice: Primality Testing Under Adversarial Conditions"
by Albrecht, Massimo, Paterson and Somorovsky
where DL_Group::verify_group with strong=false would accept a composite
q with probability 1/4096, which is exactly as the error bound is
documented, but still unfortunate.
|
| |
|
|
|
|
|
| |
Avoids computing Barrett params many times and gives option for
more optimizations in future.
|
|
|
|
|
|
|
|
|
|
|
|
| |
When beginning the loop we initialized a value to one (in Montgomery form)
then multiply it by the first element looked up based on the exponent.
But this will always (after Montgomery multiplication) be exactly the
value we looked up in the table. So just assign it directly and avoid
the redundant operation.
Improves RSA verification by 5% or so since the number of multiplications
is so small in that case saving even 1 in useful. For other operations
there is no measurable improvement.
|
|
|
|
|
|
|
|
|
| |
The loop started off by squaring the result value, but at that
point it is always one (or the Montgomery representation thereof).
Avoiding those squarings does not leak any information about the
exponent, because we haven't even looked at the exponent at that point.
Improves RSA verify performance by about 5%, everything else ~1% speedup
|
|
|
|
|
|
|
| |
Otherwise ressol (part of point decompression) can end up in
very long loop.
OSS-Fuzz 9011
|
|
|
|
| |
No known exploit for this but no point taking chances.
|
|
|
|
| |
This would have prevented CVE-2018-12435
|
|
|
|
| |
See #1606 for discussion
|
|
|
|
| |
Instead just assume they are the same size as the prime
|
|
|
|
|
|
| |
-x*n % n would reduce to n instead of zero.
Also some small optimizations and cleanups.
|
|
|
|
|
|
|
|
| |
If x was very small to start with x.size() might be under the
limb count which would cause the final addition to throw because
the destination array was smaller than the P-224 p being added.
Caught by Wycheproof ECDSA tests
|
|
|
|
| |
Using Barrett reduction instead of division is ~10x faster.
|
| |
|
|
|
|
| |
See #1542 and #1569
|
|
|
|
|
|
|
| |
Simplifies the code and makes it easy to see we never use the
weaker bounds even if the application expicitly requested it.
GH #1569
|