1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 /*
6  * This target fuzzes NSS mpi against openssl bignum.
7  * It therefore requires openssl to be installed.
8  */
9 
10 #include "mpi_helper.h"
11 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)12 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
13   // We require at least size 3 to get two integers from Data.
14   if (size < 3) {
15     return 0;
16   }
17   INIT_FOUR_NUMBERS
18 
19   auto modulus = get_modulus(data, size, ctx);
20   // Compare with OpenSSL mul mod
21   m1 = &std::get<1>(modulus);
22   assert(mp_mulmod(&a, &b, m1, &c) == MP_OKAY);
23   (void)BN_mod_mul(C, A, B, std::get<0>(modulus), ctx);
24   check_equal(C, &c, max_size);
25 
26   CLEANUP_AND_RETURN
27 }
28