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

randombit / botan / 5355576307

23 Jun 2023 11:22AM UTC coverage: 91.735% (-0.001%) from 91.736%
5355576307

Pull #3595

github

web-flow
Merge 92dd5d647 into 92171c524
Pull Request #3595: Improve clang-tidy coverage

78150 of 85191 relevant lines covered (91.74%)

12467959.48 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 uint8_t in[], size_t len) {
1,000✔
12
   const size_t max_bits = 512;
1,000✔
13

14
   if(len < 3 || len > 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 = (len - 1) / 2;
127✔
20

21
   Botan::BigInt x = Botan::BigInt::decode(in + 1, x_len);
127✔
22
   Botan::BigInt y = Botan::BigInt::decode(in + 1 + x_len, len - x_len - 1);
127✔
23

24
   if(signs & 1) {
127✔
25
      x.flip_sign();
68✔
26
   }
27
   if(signs & 2) {
127✔
28
      y.flip_sign();
62✔
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);
70✔
49
   }
50

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

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

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