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

randombit / botan / 13191583423

07 Feb 2025 01:52AM UTC coverage: 91.249% (+0.01%) from 91.237%
13191583423

push

github

web-flow
Merge pull request #4623 from randombit/jack/unrolled-monty-for-pcurves

Change mp Montgomery reduction functions to be 3 operand

94412 of 103466 relevant lines covered (91.25%)

11135774.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.37
/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(std::span<const uint8_t> in) {
6✔
13
   FUZZER_ASSERT_EQUAL(in.size(), (N * 3 + 1) * sizeof(word));
6✔
14

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

17
   word r_script[N] = {0};
6✔
18
   word r_ref[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.data(), sizeof(z));
6✔
25
   std::memcpy(p, in.data() + sizeof(z), sizeof(p));
6✔
26
   std::memcpy(&p_dash, in.data() + sizeof(z) + sizeof(p), sizeof(p_dash));
6✔
27

28
   if(N == 4) {
29
      Botan::bigint_monty_redc_4(r_script, z, p, p_dash, ws);
1✔
30
   } else if(N == 6) {
31
      Botan::bigint_monty_redc_6(r_script, z, p, p_dash, ws);
1✔
32
   } else if(N == 8) {
33
      Botan::bigint_monty_redc_8(r_script, z, p, p_dash, ws);
1✔
34
   } else if(N == 16) {
35
      Botan::bigint_monty_redc_16(r_script, z, p, p_dash, ws);
1✔
36
   } else if(N == 24) {
37
      Botan::bigint_monty_redc_24(r_script, z, p, p_dash, ws);
1✔
38
   } else if(N == 32) {
39
      Botan::bigint_monty_redc_32(r_script, z, p, p_dash, ws);
1✔
40
   } else {
41
      std::abort();
42
   }
43

44
   Botan::bigint_monty_redc_generic(r_ref, z, 2 * N, p, N, p_dash, ws);
6✔
45

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

59
}  // namespace
60

61
void fuzz(std::span<const uint8_t> in) {
1,000✔
62
   if(in.empty() || in.size() % sizeof(word) != 0) {
1,000✔
63
      return;
64
   }
65

66
   const size_t words = in.size() / sizeof(word);
124✔
67

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

© 2026 Coveralls, Inc