Coverage Report

Created: 2021-05-04 09:02

/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
973
   {
15
973
   Botan::BigInt t;
16
68.2k
   while(b != 0)
17
67.2k
      {
18
67.2k
      t = a % b;
19
67.2k
      t.swap(b);
20
67.2k
      t.swap(a);
21
67.2k
      }
22
973
   return a;
23
973
   }
24
25
}
26
27
void fuzz(const uint8_t in[], size_t len)
28
994
   {
29
994
   static const size_t max_bits = 4096;
30
31
994
   if(2*len*8 > max_bits)
32
21
      return;
33
34
973
   const Botan::BigInt x = Botan::BigInt::decode(in, len / 2);
35
973
   const Botan::BigInt y = Botan::BigInt::decode(in + len / 2, len - (len / 2));
36
37
973
   const Botan::BigInt ref = ref_gcd(x, y);
38
973
   const Botan::BigInt lib = Botan::gcd(x, y);
39
40
973
   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
973
   }