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