Coverage Report

Created: 2022-09-23 06:05

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