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

randombit / botan / 14607601421

23 Apr 2025 12:59AM UTC coverage: 91.387% (+0.07%) from 91.316%
14607601421

Pull #4835

github

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

95773 of 104799 relevant lines covered (91.39%)

12982398.04 hits per line

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

93.33
/src/fuzzer/ressol.cpp
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

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

12
void fuzz(std::span<const uint8_t> in) {
1,000✔
13
   // Ressol is mostly used for ECC point decompression so best to test smaller sizes
14
   static const size_t p_bits = 256;
1,000✔
15
   // Use p == 1 mod 4 since sqrt modulo p == 3 mod 4 is a fast case
16
   static const Botan::BigInt p = random_prime(fuzzer_rng(), p_bits, 0, 1, 4);
1,000✔
17
   static auto mod_p = Botan::Barrett_Reduction::for_public_modulus(p);
1,000✔
18

19
   if(in.size() > p_bits / 8) {
1,000✔
20
      return;
21
   }
22

23
   try {
33✔
24
      const Botan::BigInt a = Botan::BigInt::from_bytes(in);
33✔
25
      Botan::BigInt a_sqrt = Botan::sqrt_modulo_prime(a, p);
33✔
26

27
      if(a_sqrt > 0) {
33✔
28
         const Botan::BigInt a_redc = mod_p.reduce(a);
13✔
29
         const Botan::BigInt z = mod_p.square(a_sqrt);
13✔
30

31
         if(z != a_redc) {
13✔
32
            FUZZER_WRITE_AND_CRASH("A = " << a.to_hex_string() << "\n"
×
33
                                          << "P = " << p.to_hex_string() << "\n"
34
                                          << "R = " << a_sqrt.to_hex_string() << "\n"
35
                                          << "Z = " << z.to_hex_string() << "\n");
36
         }
37
      }
13✔
38
   } catch(Botan::Exception& e) {}
33✔
39
}
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