Coverage Report

Created: 2021-06-10 10:30

/src/botan/src/fuzzer/gcd.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
* (C) 2021 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
10
namespace {
11
12
Botan::BigInt ref_gcd(Botan::BigInt a,
13
                      Botan::BigInt b)
14
982
   {
15
982
   Botan::BigInt t;
16
68.0k
   while(b != 0)
17
67.0k
      {
18
67.0k
      t = a % b;
19
67.0k
      t.swap(b);
20
67.0k
      t.swap(a);
21
67.0k
      }
22
982
   return a;
23
982
   }
24
25
}
26
27
void fuzz(const uint8_t in[], size_t len)
28
1.00k
   {
29
1.00k
   static const size_t max_bits = 4096;
30
31
1.00k
   if(2*len*8 > max_bits)
32
21
      return;
33
34
982
   const Botan::BigInt x = Botan::BigInt::decode(in, len / 2);
35
982
   const Botan::BigInt y = Botan::BigInt::decode(in + len / 2, len - (len / 2));
36
37
982
   const Botan::BigInt ref = ref_gcd(x, y);
38
982
   const Botan::BigInt lib = Botan::gcd(x, y);
39
40
982
   if(ref != lib)
41
0
      {
42
0
      FUZZER_WRITE_AND_CRASH("X = " << x << "\n"
43
0
                             << "Y = " << y << "\n"
44
0
                             << "L = " << lib << "\n"
45
0
                             << "R = " << ref << "\n");
46
0
      }
47
982
   }