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

randombit / botan / 5356326050

23 Jun 2023 01:05PM UTC coverage: 91.728% (-0.008%) from 91.736%
5356326050

Pull #3595

github

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

78163 of 85212 relevant lines covered (91.73%)

12690161.35 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();
62✔
26
   }
27
   if(signs & 2) {
127✔
28
      y.flip_sign();
64✔
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);
67✔
49
   }
50

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

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

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