Coverage Report

Created: 2020-06-30 13:58

/src/botan/src/fuzzer/barrett.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
* (C) 2018,2020 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6
7
#include "fuzzers.h"
8
#include <botan/numthry.h>
9
#include <botan/reducer.h>
10
#include <botan/divide.h>
11
12
void fuzz(const uint8_t in[], size_t len)
13
842
   {
14
842
   static const size_t max_bits = 4096;
15
842
16
842
   if(len <= 4)
17
4
      return;
18
838
19
838
   if(len > 2*(max_bits/8))
20
19
      return;
21
819
22
819
   const size_t x_len = 2 * ((len + 2) / 3);
23
819
24
819
   Botan::BigInt x = Botan::BigInt::decode(in, x_len);
25
819
   const Botan::BigInt p = Botan::BigInt::decode(in + x_len, len - x_len);
26
819
27
819
   if(p.is_zero())
28
2
      return;
29
817
30
817
   const size_t x_bits = x.bits();
31
817
   if(x_bits % 8 == 0 && x_bits / 8 == x_len)
32
368
      x.flip_sign();
33
817
34
817
   const Botan::BigInt ref = x % p;
35
817
36
817
   const Botan::Modular_Reducer mod_p(p);
37
817
   const Botan::BigInt z = mod_p.reduce(x);
38
817
39
817
   const Botan::BigInt ct = ct_modulo(x, p);
40
817
41
817
   if(ref != z || ref != ct)
42
0
      {
43
0
      FUZZER_WRITE_AND_CRASH("X = " << x << "\n"
44
0
                             << "P = " << p << "\n"
45
0
                             << "Barrett = " << z << "\n"
46
0
                             << "Ct = " << ct << "\n"
47
0
                             << "Ref = " << ref << "\n");
48
0
      }
49
817
   }