Coverage Report

Created: 2019-09-11 14:12

/src/botan/src/fuzzer/invert.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
* (C) 2015,2016 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6
#include "fuzzers.h"
7
#include <botan/numthry.h>
8
9
void fuzz(const uint8_t in[], size_t len)
10
714
   {
11
714
   if(len % 2 == 1 || len > 2*4096/8)
12
19
      return;
13
695
14
695
   const size_t part_len = len / 2;
15
695
16
695
   const Botan::BigInt x = Botan::BigInt::decode(in, part_len);
17
695
   Botan::BigInt mod = Botan::BigInt::decode(in + part_len, part_len);
18
695
19
695
   mod.set_bit(0);
20
695
21
695
   if(mod < 3 || x >= mod)
22
5
      return;
23
690
24
690
   const Botan::BigInt ref = Botan::inverse_euclid(x, mod);
25
690
   const Botan::BigInt ct = Botan::ct_inverse_mod_odd_modulus(x, mod);
26
690
   //Botan::BigInt mon = Botan::normalized_montgomery_inverse(x, mod);
27
690
28
690
   if(ref != ct)
29
0
      {
30
0
      FUZZER_WRITE_AND_CRASH("X = " << x << "\n"
31
0
                             << "P = " << mod << "\n"
32
0
                             << "GCD = " << gcd(x, mod) << "\n"
33
0
                             << "Ref = " << ref << "\n"
34
0
                             << "CT  = " << ct << "\n"
35
0
                             << "RefCheck = " << (ref*ref)%mod << "\n"
36
0
                             << "CTCheck  = " << (ct*ct)%mod << "\n");
37
0
      }
38
690
   }
39