From 8059da8bd3a2f44edac7f6fa0817d97f25f69ad5 Mon Sep 17 00:00:00 2001 From: Franziskus Kiefer Date: Fri, 18 Aug 2017 10:11:07 +0200 Subject: Bug 1334106 - improve mpi fuzzing, r=me --- fuzz/mpi_expmod_target.cc | 4 ++++ fuzz/mpi_helper.cc | 6 ++++++ fuzz/mpi_helper.h | 1 + 3 files changed, 11 insertions(+) (limited to 'fuzz') 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(const_cast(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 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. -- cgit v1.2.1