• 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

86.05
/src/fuzzer/mp_redc.cpp
1
/*
2
* (C) 2023 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "mp_fuzzers.h"
8

9
namespace {
10

11
template <size_t N>
12
void fuzz_mp_redc(const uint8_t in[], size_t in_len) {
6✔
13
   FUZZER_ASSERT_EQUAL(in_len, (N * 3 + 1) * sizeof(word));
6✔
14

15
   word z[2 * N] = {0};
16

17
   word z_script[2 * N] = {0};
6✔
18
   word z_ref[2 * N] = {0};
6✔
19
   word p[N] = {0};
20
   word p_dash = 0;
21

22
   word ws[2 * (N + 1)] = {0};
6✔
23

24
   std::memcpy(z, in, sizeof(z));
6✔
25
   std::memcpy(p, in + sizeof(z), sizeof(p));
6✔
26
   std::memcpy(&p_dash, in + sizeof(z) + sizeof(p), sizeof(p_dash));
6✔
27

28
   for(size_t i = 0; i != 2 * N; ++i) {
186✔
29
      z_script[i] = z_ref[i] = z[i];
180✔
30
   }
31

32
   if(N == 4) {
33
      Botan::bigint_monty_redc_4(z_script, p, p_dash, ws);
1✔
34
   } else if(N == 6) {
35
      Botan::bigint_monty_redc_6(z_script, p, p_dash, ws);
1✔
36
   } else if(N == 8) {
37
      Botan::bigint_monty_redc_8(z_script, p, p_dash, ws);
1✔
38
   } else if(N == 16) {
39
      Botan::bigint_monty_redc_16(z_script, p, p_dash, ws);
1✔
40
   } else if(N == 24) {
41
      Botan::bigint_monty_redc_24(z_script, p, p_dash, ws);
1✔
42
   } else if(N == 32) {
43
      Botan::bigint_monty_redc_32(z_script, p, p_dash, ws);
1✔
44
   } else {
45
      std::abort();
46
   }
47

48
   Botan::bigint_monty_redc_generic(z_ref, 2 * N, p, N, p_dash, ws);
6✔
49

50
   for(size_t i = 0; i != 2 * N; ++i) {
186✔
51
      if(z_script[i] != z_ref[i]) {
180✔
52
         dump_word_vec("input", z, 2 * N);
×
53
         dump_word_vec("z_script", z_script, 2 * N);
×
54
         dump_word_vec("z_ref", z_ref, 2 * N);
×
55
         dump_word_vec("p", p, N);
×
56
         dump_word_vec("p_dash", &p_dash, 1);
×
57
         std::abort();
×
58
      }
59
   }
60
   compare_word_vec(z_script, 2 * N, z_ref, 2 * N, "redc generic vs specialized");
6✔
61
}
6✔
62

63
}  // namespace
64

65
void fuzz(const uint8_t in[], size_t len) {
1,000✔
66
   if(len == 0 || len % sizeof(word) != 0) {
1,000✔
67
      return;
68
   }
69

70
   const size_t words = len / sizeof(word);
124✔
71

72
   switch(words) {
124✔
73
      case 4 * 3 + 1:
1✔
74
         return fuzz_mp_redc<4>(in, len);
1✔
75
      case 6 * 3 + 1:
1✔
76
         return fuzz_mp_redc<6>(in, len);
1✔
77
      case 8 * 3 + 1:
1✔
78
         return fuzz_mp_redc<8>(in, len);
1✔
79
      case 16 * 3 + 1:
1✔
80
         return fuzz_mp_redc<16>(in, len);
1✔
81
      case 24 * 3 + 1:
1✔
82
         return fuzz_mp_redc<24>(in, len);
1✔
83
      case 32 * 3 + 1:
1✔
84
         return fuzz_mp_redc<32>(in, len);
1✔
85
      default:
86
         return;
87
   }
88
}
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