Modular Exponentiation
modexp(x, y, n) = xy mod N
Basic operation widely used in public key cryptography.
(RSA, Diffie Hellman, ECC)
Optimization for RSA signatures using some precomputed values that are commonly part of the private key.
Given the input, the public key and a single signature where one of the calculations went wrong we can calculate the private key.
A single faulty modular exponentiation can leak the private key.
Guaranteeing 100% correctness of calculations is hard.
Not just software bugs, also hardware failures like Rowhammer.
To protect against this attack it's recommended to always verify signatures before exposing them.
This may seem unrelated, but we'll get back to crypto soon.
Original:
{"name":"Smith","phone":[{"type":"home","no":"555-1234"}]}
Fuzzing:
{"nam":"Smith","phone":[{"type":"home","no":"555-1234"}]} {"name�:"Smith","phone":[{"type":"home","no":"555-1234"}]} {"oooooooooooooooooooooooonamee":"home","ns":555-1234"}]} {"n����������ame":"Smith","phone"home","no":"555-1234"}]} {"name":"Smith","phone":[{"typ�":"home" {"name":"Smith","phone":[{"type"1111111111111111:-home","no":"555-123E"}]} {"name":"Smith","pho�e":[{"ty`ee":[{"type":"home","no":555":"home","no":}]}
Just perform random modifications on an input file.
This will obviously only find shallow bugs.
Bugs triggered by rare inputs can't be found with dumb fuzzing (e.g. 1 out of 2128 inputs).
Create a fuzzer that "knows" something about its inputs.
Examples:
Lots of work.
This does not scale very well.
Like afl, but targets functions instead of executables.
In-process fuzzing, therefore much faster.
Bug in 1 out of 1128 inputs.
You can't hit this bug by chance.
BN_sqr(r1, x);
BN_mul(r2, x, x, ctx);
assert(BN_cmp(r1, r2)==0);
"This will never work, but I should try it"
(Ralph-Philipp Weinmann at Black Hat 2015)
It actually works!
AFL is really good at finding bignum bugs
Calculate same function with two different implementations, compare results.
Several of the devices with RSA-CRT bugs Florian Weimer discovered were using MatrixSSL.
The test input I reported to MatrixSSL had a modulus size unusual for crypto.
"Fix": MatrixSSL restricted the modulus size to common values (e. g. 2048).
So I had to find another input causing miscalculations with a 2048 bit modulus.
Why is fuzzing effective at finding bugs that can't be hit by chance?
E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E3 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E6 67 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 C7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7 E7
05 05 05 05 05 052 mod 41 41 41 41 41 41 41 41 41 41 41 27 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05
80FC mod 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0E ED 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 7C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
PointP256(FF FF FF FF 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF FF FF FF FF 00 1C 2C 00, 97 31 27 5B 8E 97 3C EA FD 8A BF 5A 6E 16 A1 77 F0 5A 34 51 14 FB C7 52 7B 3A 60 BC 65 FE 60 6A) · 1
Later Google's oss-fuzz project found another bug in BN_mod_exp in Openssl with LibFuzzer (CVE-2017-3732).
Take known math implementation bug and try to find it with fuzzing.
This usually works.
These can be found with LibFuzzer in seconds.
Open question: Are there such bugs where Fuzzing fails?
Academic: | Academics aren't very interested in crypto fuzzing, because you can't find all the bugs with it. |
Me: | That may be true, but you can't do that with formal verification either. At least you haven't done it yet. |
I have to admit something: I don't know a whole lot about formal verification.
These things are hardly controversial: