Coverage Report

Created: 2024-05-20 06:23

/src/nss/fuzz/mpi_expmod_target.cc
Line
Count
Source (jump to first uncovered line)
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.75k
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.75k
  if (size < 3) {
15
2
    return 0;
16
2
  }
17
23.7k
  INIT_FOUR_NUMBERS
18
19
23.7k
  auto modulus = get_modulus(data, size, ctx);
20
  // Compare with OpenSSL exp mod
21
23.7k
  m1 = &std::get<1>(modulus);
22
  // The exponent b (B) can get really big. Make it smaller if necessary.
23
23.7k
  if (MP_USED(&b) > 100) {
24
0
    size_t shift = (MP_USED(&b) - 100) * MP_DIGIT_BIT;
25
0
    mp_div_2d(&b, shift, &b, nullptr);
26
0
    BN_rshift(B, B, shift);
27
0
  }
28
23.7k
  check_equal(A, &a, max_size);
29
23.7k
  check_equal(B, &b, max_size);
30
23.7k
  check_equal(std::get<0>(modulus), m1, 3 * max_size);
31
23.7k
  assert(mp_exptmod(&a, &b, m1, &c) == MP_OKAY);
32
4.75k
  (void)BN_mod_exp(C, A, B, std::get<0>(modulus), ctx);
33
4.75k
  check_equal(C, &c, 2 * max_size);
34
35
4.75k
  CLEANUP_AND_RETURN
36
23.7k
}