diff options
author | Jack Lloyd <[email protected]> | 2018-02-26 16:34:44 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-02-26 16:44:49 -0500 |
commit | 72b12e25bfdacc2e9553f64b3d87a48cb46bd682 (patch) | |
tree | e3f3a326c8db2219e86d1f530e1cd8735659a404 | |
parent | 3b84e568bd591a9a76d8d3778d90a8d761c1698b (diff) |
Remove use of redc_helper in fuzzers
This runs into the same weird UbSan issue as in #1370
-rw-r--r-- | src/fuzzer/redc_helper.h | 34 | ||||
-rw-r--r-- | src/fuzzer/redc_p192.cpp | 13 | ||||
-rw-r--r-- | src/fuzzer/redc_p224.cpp | 16 | ||||
-rw-r--r-- | src/fuzzer/redc_p256.cpp | 13 | ||||
-rw-r--r-- | src/fuzzer/redc_p384.cpp | 13 | ||||
-rw-r--r-- | src/fuzzer/redc_p521.cpp | 13 |
6 files changed, 48 insertions, 54 deletions
diff --git a/src/fuzzer/redc_helper.h b/src/fuzzer/redc_helper.h deleted file mode 100644 index f08df3656..000000000 --- a/src/fuzzer/redc_helper.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -* (C) 2015,2016 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_FUZZ_REDC_HELPERS_H_ -#define BOTAN_FUZZ_REDC_HELPERS_H_ - -#include "fuzzers.h" -#include <botan/reducer.h> -#include <functional> - -namespace { - -void check_redc(std::function<void (Botan::BigInt&, Botan::secure_vector<Botan::word>&)> redc_fn, - const Botan::Modular_Reducer& redc, - const Botan::BigInt& prime, - const Botan::BigInt& x) - { - const Botan::BigInt v1 = x % prime; - const Botan::BigInt v2 = redc.reduce(x); - - Botan::secure_vector<Botan::word> ws; - Botan::BigInt v3 = x; - redc_fn(v3, ws); - - FUZZER_ASSERT_EQUAL(v1, v2); - FUZZER_ASSERT_EQUAL(v2, v3); - } - -} - -#endif diff --git a/src/fuzzer/redc_p192.cpp b/src/fuzzer/redc_p192.cpp index e1f7c753f..6898cdbb9 100644 --- a/src/fuzzer/redc_p192.cpp +++ b/src/fuzzer/redc_p192.cpp @@ -5,7 +5,7 @@ */ #include "fuzzers.h" -#include "redc_helper.h" +#include <botan/reducer.h> #include <botan/curve_nistp.h> void fuzz(const uint8_t in[], size_t len) @@ -17,10 +17,15 @@ void fuzz(const uint8_t in[], size_t len) static const Botan::BigInt prime_2 = prime * prime; static Botan::Modular_Reducer prime_redc(prime); - Botan::BigInt x = Botan::BigInt::decode(in, len); + Botan::BigInt input = Botan::BigInt::decode(in, len); - if(x < prime_2) + if(input < prime_2) { - check_redc(Botan::redc_p192, prime_redc, prime, x); + const Botan::BigInt ref = prime_redc.reduce(input); + + Botan::secure_vector<Botan::word> ws; + Botan::redc_p192(input, ws); + + FUZZER_ASSERT_EQUAL(ref, input); } } diff --git a/src/fuzzer/redc_p224.cpp b/src/fuzzer/redc_p224.cpp index a8a4d5d72..b2dbac16e 100644 --- a/src/fuzzer/redc_p224.cpp +++ b/src/fuzzer/redc_p224.cpp @@ -5,19 +5,27 @@ */ #include "fuzzers.h" -#include "redc_helper.h" +#include <botan/reducer.h> #include <botan/curve_nistp.h> void fuzz(const uint8_t in[], size_t len) { + if(len > 2*224/8) + return; + static const Botan::BigInt& prime = Botan::prime_p224(); static const Botan::BigInt prime_2 = prime * prime; static Botan::Modular_Reducer prime_redc(prime); - Botan::BigInt x = Botan::BigInt::decode(in, len); + Botan::BigInt input = Botan::BigInt::decode(in, len); - if(x < prime_2) + if(input < prime_2) { - check_redc(Botan::redc_p224, prime_redc, prime, x); + const Botan::BigInt ref = prime_redc.reduce(input); + + Botan::secure_vector<Botan::word> ws; + Botan::redc_p224(input, ws); + + FUZZER_ASSERT_EQUAL(ref, input); } } diff --git a/src/fuzzer/redc_p256.cpp b/src/fuzzer/redc_p256.cpp index b8d78e7bb..4c3809f08 100644 --- a/src/fuzzer/redc_p256.cpp +++ b/src/fuzzer/redc_p256.cpp @@ -5,7 +5,7 @@ */ #include "fuzzers.h" -#include "redc_helper.h" +#include <botan/reducer.h> #include <botan/curve_nistp.h> void fuzz(const uint8_t in[], size_t len) @@ -17,10 +17,15 @@ void fuzz(const uint8_t in[], size_t len) static const Botan::BigInt prime_2 = prime * prime; static Botan::Modular_Reducer prime_redc(prime); - Botan::BigInt x = Botan::BigInt::decode(in, len); + Botan::BigInt input = Botan::BigInt::decode(in, len); - if(x < prime_2) + if(input < prime_2) { - check_redc(Botan::redc_p256, prime_redc, prime, x); + const Botan::BigInt ref = prime_redc.reduce(input); + + Botan::secure_vector<Botan::word> ws; + Botan::redc_p256(input, ws); + + FUZZER_ASSERT_EQUAL(ref, input); } } diff --git a/src/fuzzer/redc_p384.cpp b/src/fuzzer/redc_p384.cpp index 35e3ccfee..1c3a777a0 100644 --- a/src/fuzzer/redc_p384.cpp +++ b/src/fuzzer/redc_p384.cpp @@ -5,7 +5,7 @@ */ #include "fuzzers.h" -#include "redc_helper.h" +#include <botan/reducer.h> #include <botan/curve_nistp.h> void fuzz(const uint8_t in[], size_t len) @@ -17,10 +17,15 @@ void fuzz(const uint8_t in[], size_t len) static const Botan::BigInt prime_2 = prime * prime; static Botan::Modular_Reducer prime_redc(prime); - Botan::BigInt x = Botan::BigInt::decode(in, len); + Botan::BigInt input = Botan::BigInt::decode(in, len); - if(x < prime_2) + if(input < prime_2) { - check_redc(Botan::redc_p384, prime_redc, prime, x); + const Botan::BigInt ref = prime_redc.reduce(input); + + Botan::secure_vector<Botan::word> ws; + Botan::redc_p384(input, ws); + + FUZZER_ASSERT_EQUAL(ref, input); } } diff --git a/src/fuzzer/redc_p521.cpp b/src/fuzzer/redc_p521.cpp index c6c5d262b..e148c94bb 100644 --- a/src/fuzzer/redc_p521.cpp +++ b/src/fuzzer/redc_p521.cpp @@ -5,7 +5,7 @@ */ #include "fuzzers.h" -#include "redc_helper.h" +#include <botan/reducer.h> #include <botan/curve_nistp.h> void fuzz(const uint8_t in[], size_t len) @@ -17,10 +17,15 @@ void fuzz(const uint8_t in[], size_t len) static const Botan::BigInt prime_2 = prime * prime; static Botan::Modular_Reducer prime_redc(prime); - Botan::BigInt x = Botan::BigInt::decode(in, len); + Botan::BigInt input = Botan::BigInt::decode(in, len); - if(x < prime_2) + if(input < prime_2) { - check_redc(Botan::redc_p521, prime_redc, prime, x); + const Botan::BigInt ref = prime_redc.reduce(input); + + Botan::secure_vector<Botan::word> ws; + Botan::redc_p521(input, ws); + + FUZZER_ASSERT_EQUAL(ref, input); } } |