Coverage Report

Created: 2020-11-21 08:34

/src/botan/src/fuzzer/ressol.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
7
#include "fuzzers.h"
8
#include <botan/numthry.h>
9
#include <botan/reducer.h>
10
11
void fuzz(const uint8_t in[], size_t len)
12
742
   {
13
   // Ressol is mostly used for ECC point decompression so best to test smaller sizes
14
742
   static const size_t p_bits = 256;
15
742
   static const Botan::BigInt p = random_prime(fuzzer_rng(), p_bits);
16
742
   static const Botan::Modular_Reducer mod_p(p);
17
18
742
   if(len > p_bits / 8)
19
27
      return;
20
21
715
   try
22
715
      {
23
715
      const Botan::BigInt a = Botan::BigInt::decode(in, len);
24
715
      Botan::BigInt a_sqrt = Botan::ressol(a, p);
25
26
715
      if(a_sqrt > 0)
27
448
         {
28
448
         const Botan::BigInt a_redc = mod_p.reduce(a);
29
448
         const Botan::BigInt z = mod_p.square(a_sqrt);
30
31
448
         if(z != a_redc)
32
0
            {
33
0
            FUZZER_WRITE_AND_CRASH("A = " << a << "\n"
34
0
                                   << "P = " << p << "\n"
35
0
                                   << "R = " << a_sqrt << "\n"
36
0
                                   << "Z = " << z << "\n");
37
0
            }
38
448
         }
39
715
      }
40
2
   catch(Botan::Exception& e) {}
41
42
715
   return;
43
715
   }
44