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

randombit / botan / 13212092742

08 Feb 2025 12:33AM UTC coverage: 91.658% (-0.004%) from 91.662%
13212092742

push

github

web-flow
Merge pull request #4642 from randombit/jack/target-info-header

Add internal target_info.h header

94839 of 103471 relevant lines covered (91.66%)

11295178.12 hits per line

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

93.33
/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
      }
19
      return 1;
1✔
20
   }
21

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

25
   while(n > 1) {
11,235✔
26
      if(n.is_odd()) {
11,203✔
27
         y = mod_p.multiply(x, y);
5,596✔
28
      }
29
      x = mod_p.square(x);
11,203✔
30
      n >>= 1;
11,203✔
31
   }
32
   return mod_p.multiply(x, y);
32✔
33
}
64✔
34

35
}  // namespace
36

37
void fuzz(std::span<const uint8_t> in) {
100✔
38
   static const size_t max_bits = 2048;
100✔
39

40
   if(in.size() % 3 != 0) {
100✔
41
      return;
67✔
42
   }
43

44
   const size_t part_size = in.size() / 3;
33✔
45

46
   if(part_size * 8 > max_bits) {
33✔
47
      return;
48
   }
49

50
   const Botan::BigInt g = Botan::BigInt::from_bytes(in.subspan(0, part_size));
33✔
51
   const Botan::BigInt x = Botan::BigInt::from_bytes(in.subspan(part_size, part_size));
33✔
52
   const Botan::BigInt p = Botan::BigInt::from_bytes(in.subspan(2 * part_size, part_size));
33✔
53

54
   try {
33✔
55
      const Botan::BigInt ref = simple_power_mod(g, x, p);
33✔
56
      const Botan::BigInt z = Botan::power_mod(g, x, p);
33✔
57

58
      if(ref != z) {
33✔
59
         FUZZER_WRITE_AND_CRASH("G = " << g.to_hex_string() << "\n"
×
60
                                       << "X = " << x.to_hex_string() << "\n"
61
                                       << "P = " << p.to_hex_string() << "\n"
62
                                       << "Z = " << z.to_hex_string() << "\n"
63
                                       << "R = " << ref.to_hex_string() << "\n");
64
      }
65
   } catch(Botan::Exception& e) {}
33✔
66
}
33✔
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

© 2026 Coveralls, Inc