summaryrefslogtreecommitdiff
path: root/fuzz
diff options
context:
space:
mode:
authorFranziskus Kiefer <franziskuskiefer@gmail.com>2017-08-18 10:11:07 +0200
committerFranziskus Kiefer <franziskuskiefer@gmail.com>2017-08-18 10:11:07 +0200
commit8059da8bd3a2f44edac7f6fa0817d97f25f69ad5 (patch)
treef9ee3972b288cc42f4568940c25b2a54930184f0 /fuzz
parent08e2e824f7f57ecc1f1c4e6dea99182a51653436 (diff)
downloadnss-hg-8059da8bd3a2f44edac7f6fa0817d97f25f69ad5.tar.gz
Bug 1334106 - improve mpi fuzzing, r=me
Diffstat (limited to 'fuzz')
-rw-r--r--fuzz/mpi_expmod_target.cc4
-rw-r--r--fuzz/mpi_helper.cc6
-rw-r--r--fuzz/mpi_helper.h1
3 files changed, 11 insertions, 0 deletions
diff --git a/fuzz/mpi_expmod_target.cc b/fuzz/mpi_expmod_target.cc
index ed31da354..d61039dc7 100644
--- a/fuzz/mpi_expmod_target.cc
+++ b/fuzz/mpi_expmod_target.cc
@@ -19,6 +19,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
auto modulus = get_modulus(data, size, ctx);
// Compare with OpenSSL exp mod
m1 = &std::get<1>(modulus);
+ check_equal(A, &a, max_size);
+ check_equal(B, &b, max_size);
+ print_bn("A", A);
+ print_bn("B", B);
assert(mp_exptmod(&a, &b, m1, &c) == MP_OKAY);
(void)BN_mod_exp(C, A, B, std::get<0>(modulus), ctx);
check_equal(C, &c, 2 * max_size);
diff --git a/fuzz/mpi_helper.cc b/fuzz/mpi_helper.cc
index 65cf4b9cd..d092fdb11 100644
--- a/fuzz/mpi_helper.cc
+++ b/fuzz/mpi_helper.cc
@@ -12,6 +12,12 @@ char *to_char(const uint8_t *x) {
return reinterpret_cast<char *>(const_cast<unsigned char *>(x));
}
+void print_bn(std::string label, BIGNUM *x) {
+ char *xc = BN_bn2hex(x);
+ std::cout << label << ": " << std::hex << xc << std::endl;
+ OPENSSL_free(xc);
+}
+
// Check that the two numbers are equal.
void check_equal(BIGNUM *b, mp_int *m, size_t max_size) {
char *bnBc = BN_bn2hex(b);
diff --git a/fuzz/mpi_helper.h b/fuzz/mpi_helper.h
index 17383744b..ef7041b25 100644
--- a/fuzz/mpi_helper.h
+++ b/fuzz/mpi_helper.h
@@ -23,6 +23,7 @@ void parse_input(const uint8_t *data, size_t size, BIGNUM *A, BIGNUM *B,
void parse_input(const uint8_t *data, size_t size, BIGNUM *A, mp_int *a);
std::tuple<BIGNUM *, mp_int> get_modulus(const uint8_t *data, size_t size,
BN_CTX *ctx);
+void print_bn(std::string label, BIGNUM *x);
// Initialise MPI and BN variables
// XXX: Also silence unused variable warnings for R.