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

randombit / botan / 14606431966

22 Apr 2025 11:19PM UTC coverage: 91.416% (+0.1%) from 91.316%
14606431966

Pull #4835

github

web-flow
Merge f63084710 into 4c413a8ac
Pull Request #4835: New Barrett Reduction implementation

95800 of 104796 relevant lines covered (91.42%)

13215574.08 hits per line

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

89.47
/src/fuzzer/barrett.cpp
1
/*
2
* (C) 2018,2020 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/internal/barrett.h>
11
#include <botan/internal/divide.h>
12

13
void fuzz(std::span<const uint8_t> in) {
1,000✔
14
   static const size_t max_bits = 4096;
1,000✔
15

16
   if(in.size() <= 4) {
1,000✔
17
      return;
5✔
18
   }
19

20
   if(in.size() > 2 * (max_bits / 8)) {
995✔
21
      return;
22
   }
23

24
   const size_t x_len = 2 * in.size() / 3;
995✔
25

26
   Botan::BigInt x = Botan::BigInt::from_bytes(in.subspan(0, x_len));
995✔
27
   const Botan::BigInt p = Botan::BigInt::from_bytes(in.subspan(x_len, in.size() - x_len));
995✔
28

29
   if(p.is_zero()) {
1,990✔
30
      return;
×
31
   }
32

33
   try {
995✔
34
      const auto mod_p = Botan::Barrett_Reduction::for_public_modulus(p);
995✔
35
      const Botan::BigInt z = mod_p.reduce(x);
995✔
36

37
      const Botan::BigInt ref = x % p;
995✔
38
      const Botan::BigInt ct = ct_modulo(x, p);
995✔
39

40
      if(ref != z || ref != ct) {
1,990✔
41
         FUZZER_WRITE_AND_CRASH("X = " << x.to_hex_string() << "\n"
×
42
                                       << "P = " << p.to_hex_string() << "\n"
43
                                       << "Barrett = " << z.to_hex_string() << "\n"
44
                                       << "Ct = " << ct.to_hex_string() << "\n"
45
                                       << "Ref = " << ref.to_hex_string() << "\n");
46
      }
47
   } catch(Botan::Invalid_Argument&) {}
1,990✔
48
}
995✔
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