/src/nss/fuzz/mpi_div_target.cc
Line | Count | Source |
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 | | |
12 | 4.40k | 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 | 4.40k | if (size < 3) { |
15 | 2 | return 0; |
16 | 2 | } |
17 | 22.0k | INIT_FOUR_NUMBERS |
18 | | |
19 | | // We can't divide by 0. |
20 | 22.0k | if (mp_cmp_z(&b) == 0) { |
21 | 18 | CLEANUP_AND_RETURN |
22 | 18 | } |
23 | | |
24 | | // Compare with OpenSSL division |
25 | 4.38k | assert(mp_div(&a, &b, &c, &r) == MP_OKAY); |
26 | 4.38k | BN_div(C, R, A, B, ctx); |
27 | 4.38k | check_equal(C, &c, max_size); |
28 | 4.38k | check_equal(R, &r, max_size); |
29 | | |
30 | | // Check c * b + r == a |
31 | 4.38k | assert(mp_mul(&c, &b, &c) == MP_OKAY); |
32 | 4.38k | assert(mp_add(&c, &r, &c) == MP_OKAY); |
33 | 4.38k | assert(mp_cmp(&c, &a) == 0); |
34 | | |
35 | 4.38k | CLEANUP_AND_RETURN |
36 | 4.38k | } |