Coverage Report

Created: 2020-02-14 15:38

/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
624
   {
13
624
   // Ressol is mostly used for ECC point decompression so best to test smaller sizes
14
624
   static const size_t p_bits = 256;
15
624
   static const Botan::BigInt p = random_prime(fuzzer_rng(), p_bits);
16
624
   static const Botan::Modular_Reducer mod_p(p);
17
624
18
624
   if(len > p_bits / 8)
19
24
      return;
20
600
21
600
   try
22
600
      {
23
600
      const Botan::BigInt a = Botan::BigInt::decode(in, len);
24
600
      Botan::BigInt a_sqrt = Botan::ressol(a, p);
25
600
26
600
      if(a_sqrt > 0)
27
362
         {
28
362
         const Botan::BigInt a_redc = mod_p.reduce(a);
29
362
         const Botan::BigInt z = mod_p.square(a_sqrt);
30
362
31
362
         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
362
         }
39
600
      }
40
600
   catch(Botan::Exception& e) {}
41
600
42
600
   return;
43
600
   }
44