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

randombit / botan / 5169719599

04 Jun 2023 03:23PM UTC coverage: 91.734% (-0.001%) from 91.735%
5169719599

push

github

randombit
Disable the fast clang-tidy run (GH #3576)

76186 of 83051 relevant lines covered (91.73%)

11804648.7 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
   const uint8_t signs = in[0];
127✔
18
   const size_t x_len = (len - 1) / 2;
127✔
19

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

23
   if(signs & 1)
127✔
24
      x.flip_sign();
56✔
25
   if(signs & 2)
127✔
26
      y.flip_sign();
71✔
27

28
   const Botan::BigInt d1 = x - y;
127✔
29
   const Botan::BigInt d2 = y - x;
127✔
30

31
   FUZZER_ASSERT_TRUE(d1.cmp(d2, false) == 0);
127✔
32

33
   const bool is_eq = (x == y);
127✔
34
   const bool is_lt = (x < y);
127✔
35
   const bool is_gt = (x > y);
127✔
36
   const bool is_lte = (x <= y);
127✔
37
   const bool is_gte = (x >= y);
127✔
38

39
   if(is_eq) {
127✔
40
      FUZZER_ASSERT_TRUE(d1.is_zero());
×
41
      FUZZER_ASSERT_TRUE(d2.is_zero());
×
42
   }
43

44
   if(is_lte) {
127✔
45
      FUZZER_ASSERT_TRUE(is_lt || is_eq);
58✔
46
   }
47

48
   if(is_gte) {
127✔
49
      FUZZER_ASSERT_TRUE(is_gt || is_eq);
69✔
50
   }
51

52
   if(is_lt) {
127✔
53
      FUZZER_ASSERT_TRUE(!is_gt);
58✔
54
      FUZZER_ASSERT_TRUE(d1.is_nonzero());
58✔
55
      FUZZER_ASSERT_TRUE(d2.is_nonzero());
116✔
56
      FUZZER_ASSERT_TRUE(d1.is_negative());
58✔
57
      FUZZER_ASSERT_TRUE(d2.is_positive());
58✔
58
   }
59

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