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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 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
   if(N == 4)
32
      Botan::bigint_monty_redc_4(z_script, p, p_dash, ws);
1✔
33
   else if(N == 6)
34
      Botan::bigint_monty_redc_6(z_script, p, p_dash, ws);
1✔
35
   else if(N == 8)
36
      Botan::bigint_monty_redc_8(z_script, p, p_dash, ws);
1✔
37
   else if(N == 16)
38
      Botan::bigint_monty_redc_16(z_script, p, p_dash, ws);
1✔
39
   else if(N == 24)
40
      Botan::bigint_monty_redc_24(z_script, p, p_dash, ws);
1✔
41
   else if(N == 32)
42
      Botan::bigint_monty_redc_32(z_script, p, p_dash, ws);
1✔
43
   else
44
      std::abort();
45

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

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

61
}
62

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

67
   const size_t words = len / sizeof(word);
124✔
68

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