no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / security / nss / fuzz / mpi_add_target.cc
blob3ebad370d02ce7c8ab026c5429080ca21875510c
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/. */
5 /*
6 * This target fuzzes NSS mpi against openssl bignum.
7 * It therefore requires openssl to be installed.
8 */
10 #include "mpi_helper.h"
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;
17 INIT_FOUR_NUMBERS
19 // Compare with OpenSSL addition
20 assert(mp_add(&a, &b, &c) == MP_OKAY);
21 (void)BN_add(C, A, B);
22 check_equal(C, &c, max_size);
24 // Check a + b == a - -b
25 mp_neg(&b, &b);
26 assert(mp_sub(&a, &b, &r) == MP_OKAY);
27 bool eq = mp_cmp(&r, &c) == 0;
28 if (!eq) {
29 char rC[max_size], cC[max_size], aC[max_size], bC[max_size];
30 mp_tohex(&r, rC);
31 mp_tohex(&c, cC);
32 mp_tohex(&a, aC);
33 mp_tohex(&b, bC);
34 std::cout << "a = " << std::hex << aC << std::endl;
35 std::cout << "-b = " << std::hex << bC << std::endl;
36 std::cout << "a + b = " << std::hex << cC << std::endl;
37 std::cout << "a - -b = " << std::hex << rC << std::endl;
39 assert(eq);
41 CLEANUP_AND_RETURN