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

randombit / botan / 6441040938

07 Oct 2023 12:08PM UTC coverage: 91.692% (-0.003%) from 91.695%
6441040938

push

github

web-flow
Merge pull request #3736 from randombit/fix/ub_in_alignment_buffer

79964 of 87209 relevant lines covered (91.69%)

8498879.53 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

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

24
   const size_t x_len = 2 * ((len + 2) / 3);
995✔
25

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

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

33
   const size_t x_bits = x.bits();
995✔
34
   if(x_bits % 8 == 0 && x_bits / 8 == x_len) {
995✔
35
      x.flip_sign();
494✔
36
   }
37

38
   const Botan::BigInt ref = x % p;
995✔
39

40
   const Botan::Modular_Reducer mod_p(p);
995✔
41
   const Botan::BigInt z = mod_p.reduce(x);
995✔
42

43
   const Botan::BigInt ct = ct_modulo(x, p);
995✔
44

45
   if(ref != z || ref != ct) {
1,990✔
46
      FUZZER_WRITE_AND_CRASH("X = " << x << "\n"
995✔
47
                                    << "P = " << p << "\n"
48
                                    << "Barrett = " << z << "\n"
49
                                    << "Ct = " << ct << "\n"
50
                                    << "Ref = " << ref << "\n");
51
   }
52
}
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