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

randombit / botan / 22573131044

02 Mar 2026 11:04AM UTC coverage: 90.309% (-0.008%) from 90.317%
22573131044

Pull #5402

github

web-flow
Merge 441448f4f into 20cc7dbce
Pull Request #5402: Refactor: CMake Module now uses mostly hard-coded paths

103494 of 114600 relevant lines covered (90.31%)

11497040.15 hits per line

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

95.0
/src/fuzzer/bn_cmp.cpp
1
/*
2
* (C) 2021 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/bigint.h>
10

11
void fuzz(const std::span<const uint8_t> in) {
1,000✔
12
   const size_t max_bits = 512;
1,000✔
13

14
   if(in.size() < 3 || in.size() > 1 + 2 * (max_bits / 8)) {
1,000✔
15
      return;
873✔
16
   }
17

18
   const uint8_t signs = in[0];
127✔
19
   const size_t x_len = (in.size() - 1) / 2;
127✔
20

21
   Botan::BigInt x = Botan::BigInt::from_bytes(in.subspan(1, x_len));
127✔
22
   Botan::BigInt y = Botan::BigInt::from_bytes(in.subspan(1 + x_len, in.size() - x_len - 1));
127✔
23

24
   if((signs & 1) != 0) {
127✔
25
      x.flip_sign();
53✔
26
   }
27
   if((signs & 2) != 0) {
127✔
28
      y.flip_sign();
75✔
29
   }
30

31
   const Botan::BigInt d1 = x - y;
127✔
32
   const Botan::BigInt d2 = y - x;
127✔
33

34
   FUZZER_ASSERT_TRUE(d1.cmp(d2, false) == 0);
127✔
35

36
   const bool is_eq = (x == y);
127✔
37
   const bool is_lt = (x < y);
127✔
38
   const bool is_gt = (x > y);
127✔
39
   const bool is_lte = (x <= y);
127✔
40
   const bool is_gte = (x >= y);
127✔
41

42
   if(is_eq) {
127✔
43
      FUZZER_ASSERT_TRUE(d1.is_zero());
×
44
      FUZZER_ASSERT_TRUE(d2.is_zero());
×
45
   }
46

47
   if(is_lte) {
127✔
48
      FUZZER_ASSERT_TRUE(is_lt || is_eq);
48✔
49
   }
50

51
   if(is_gte) {
127✔
52
      FUZZER_ASSERT_TRUE(is_gt || is_eq);
79✔
53
   }
54

55
   if(is_lt) {
127✔
56
      FUZZER_ASSERT_TRUE(!is_gt);
48✔
57
      FUZZER_ASSERT_TRUE(d1.is_nonzero());
48✔
58
      FUZZER_ASSERT_TRUE(d2.is_nonzero());
96✔
59
      FUZZER_ASSERT_TRUE(d1.is_negative());
48✔
60
      FUZZER_ASSERT_TRUE(d2.is_positive());
48✔
61
   }
62

63
   if(is_gt) {
127✔
64
      FUZZER_ASSERT_TRUE(!is_lt);
79✔
65
      FUZZER_ASSERT_TRUE(d1.is_nonzero());
158✔
66
      FUZZER_ASSERT_TRUE(d2.is_nonzero());
79✔
67
      FUZZER_ASSERT_TRUE(d1.is_positive());
79✔
68
      FUZZER_ASSERT_TRUE(d2.is_negative());
79✔
69
   }
70
}
127✔
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