/src/botan/src/fuzzer/mp_comba_mul.cpp
Line | Count | Source |
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 | 183 | void fuzz(std::span<const uint8_t> in) { |
10 | 183 | const size_t words = (in.size() + sizeof(word) - 1) / sizeof(word); |
11 | | |
12 | 183 | if(in.empty() || words > 2 * 16) { |
13 | 55 | return; |
14 | 55 | } |
15 | 128 | size_t in_len = in.size(); |
16 | | |
17 | 128 | word x[24] = {0}; |
18 | 128 | word y[24] = {0}; |
19 | | |
20 | 128 | std::memcpy(x, in.data(), in_len / 2); |
21 | 128 | std::memcpy(y, in.data() + in_len / 2, in_len - (in_len / 2)); |
22 | | |
23 | 128 | const size_t x_words = ((in_len / 2) + sizeof(word) - 1) / sizeof(word); |
24 | 128 | const size_t y_words = ((in_len - (in_len / 2)) + sizeof(word) - 1) / sizeof(word); |
25 | | |
26 | 128 | word z4[2 * 4] = {0}; |
27 | 128 | word z6[2 * 6] = {0}; |
28 | 128 | word z8[2 * 8] = {0}; |
29 | 128 | word z9[2 * 9] = {0}; |
30 | 128 | word z16[2 * 16] = {0}; |
31 | 128 | word z24[2 * 24] = {0}; |
32 | | |
33 | 128 | word z_ref[2 * 24] = {0}; |
34 | | |
35 | 128 | Botan::basecase_mul(z_ref, 2 * 24, x, x_words, y, y_words); |
36 | | |
37 | 128 | if(words <= 8) { |
38 | 50 | Botan::bigint_comba_mul4(z4, x, y); |
39 | 50 | } |
40 | 128 | if(words <= 12) { |
41 | 62 | Botan::bigint_comba_mul6(z6, x, y); |
42 | 62 | } |
43 | 128 | if(words <= 16) { |
44 | 80 | Botan::bigint_comba_mul8(z8, x, y); |
45 | 80 | } |
46 | 128 | if(words <= 18) { |
47 | 89 | Botan::bigint_comba_mul9(z9, x, y); |
48 | 89 | } |
49 | 128 | if(words <= 32) { |
50 | 114 | Botan::bigint_comba_mul16(z16, x, y); |
51 | 114 | } |
52 | 128 | if(words <= 48) { |
53 | 128 | Botan::bigint_comba_mul24(z24, x, y); |
54 | 128 | } |
55 | | |
56 | 128 | if(words <= 8) { |
57 | 50 | compare_word_vec(z4, 2 * 4, z6, 2 * 6, "mul4 vs mul6"); |
58 | 50 | } |
59 | 128 | if(words <= 12) { |
60 | 62 | compare_word_vec(z6, 2 * 6, z8, 2 * 8, "mul6 vs mul8"); |
61 | 62 | } |
62 | 128 | if(words <= 16) { |
63 | 80 | compare_word_vec(z8, 2 * 8, z9, 2 * 9, "mul8 vs mul9"); |
64 | 80 | } |
65 | 128 | if(words <= 18) { |
66 | 89 | compare_word_vec(z9, 2 * 9, z16, 2 * 16, "mul9 vs mul16"); |
67 | 89 | } |
68 | 128 | if(words <= 32) { |
69 | 114 | compare_word_vec(z16, 2 * 16, z24, 2 * 24, "mul16 vs mul24"); |
70 | 114 | } |
71 | | |
72 | 128 | compare_word_vec(z24, 2 * 24, z_ref, 2 * 24, "mul24 vs basecase mul"); |
73 | 128 | } |