• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 5111374265

29 May 2023 11:19AM UTC coverage: 92.227% (+0.5%) from 91.723%
5111374265

push

github

randombit
Next release will be 3.1.0. Update release notes

75588 of 81959 relevant lines covered (92.23%)

11886470.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.67
/src/fuzzer/pow_mod.cpp
1
/*
2
* (C) 2016,2018 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "fuzzers.h"
8

9
#include <botan/numthry.h>
10
#include <botan/reducer.h>
11

12
namespace {
13

14
Botan::BigInt simple_power_mod(Botan::BigInt x, Botan::BigInt n, const Botan::BigInt& p) {
33✔
15
   if(n == 0) {
33✔
16
      if(p == 1)
1✔
17
         return 0;
×
18
      return 1;
1✔
19
   }
20

21
   Botan::Modular_Reducer mod_p(p);
32✔
22
   Botan::BigInt y = 1;
32✔
23

24
   while(n > 1) {
11,226✔
25
      if(n.is_odd()) {
22,388✔
26
         y = mod_p.multiply(x, y);
11,252✔
27
      }
28
      x = mod_p.square(x);
11,194✔
29
      n >>= 1;
11,194✔
30
   }
31
   return mod_p.multiply(x, y);
32✔
32
}
32✔
33

34
}  // namespace
35

36
void fuzz(const uint8_t in[], size_t len) {
100✔
37
   static const size_t max_bits = 2048;
100✔
38

39
   if(len % 3 != 0)
100✔
40
      return;
67✔
41

42
   const size_t part_size = len / 3;
33✔
43

44
   if(part_size * 8 > max_bits)
33✔
45
      return;
46

47
   const Botan::BigInt g = Botan::BigInt::decode(in, part_size);
33✔
48
   const Botan::BigInt x = Botan::BigInt::decode(in + part_size, part_size);
33✔
49
   const Botan::BigInt p = Botan::BigInt::decode(in + 2 * part_size, part_size);
33✔
50

51
   try {
33✔
52
      const Botan::BigInt ref = simple_power_mod(g, x, p);
66✔
53
      const Botan::BigInt z = Botan::power_mod(g, x, p);
33✔
54

55
      if(ref != z) {
33✔
56
         FUZZER_WRITE_AND_CRASH("G = " << g << "\n"
33✔
57
                                       << "X = " << x << "\n"
58
                                       << "P = " << p << "\n"
59
                                       << "Z = " << z << "\n"
60
                                       << "R = " << ref << "\n");
61
      }
62
   } catch(Botan::Exception& e) {}
66✔
63
}
97✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc