• 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

95.0
/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/reducer.h>
11
#include <botan/internal/divide.h>
12

13
void fuzz(const uint8_t in[], size_t len) {
1,000✔
14
   static const size_t max_bits = 4096;
1,000✔
15

16
   if(len <= 4)
1,000✔
17
      return;
5✔
18

19
   if(len > 2 * (max_bits / 8))
995✔
20
      return;
21

22
   const size_t x_len = 2 * ((len + 2) / 3);
995✔
23

24
   Botan::BigInt x = Botan::BigInt::decode(in, x_len);
995✔
25
   const Botan::BigInt p = Botan::BigInt::decode(in + x_len, len - x_len);
995✔
26

27
   if(p.is_zero())
1,990✔
28
      return;
×
29

30
   const size_t x_bits = x.bits();
995✔
31
   if(x_bits % 8 == 0 && x_bits / 8 == x_len)
995✔
32
      x.flip_sign();
477✔
33

34
   const Botan::BigInt ref = x % p;
995✔
35

36
   const Botan::Modular_Reducer mod_p(p);
995✔
37
   const Botan::BigInt z = mod_p.reduce(x);
995✔
38

39
   const Botan::BigInt ct = ct_modulo(x, p);
995✔
40

41
   if(ref != z || ref != ct) {
1,990✔
42
      FUZZER_WRITE_AND_CRASH("X = " << x << "\n"
995✔
43
                                    << "P = " << p << "\n"
44
                                    << "Barrett = " << z << "\n"
45
                                    << "Ct = " << ct << "\n"
46
                                    << "Ref = " << ref << "\n");
47
   }
48
}
4,980✔
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