/src/botan/src/fuzzer/mp_fuzzers.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * (C) 2023 Jack Lloyd |
3 | | * |
4 | | * Botan is released under the Simplified BSD License (see license.txt) |
5 | | */ |
6 | | |
7 | | #ifndef BOTAN_FUZZER_MP_HELPERS_H_ |
8 | | #define BOTAN_FUZZER_MP_HELPERS_H_ |
9 | | |
10 | | #include "fuzzers.h" |
11 | | #include <botan/internal/mp_core.h> |
12 | | |
13 | | #if BOTAN_MP_WORD_BITS == 64 |
14 | 0 | #define WORD_FORMAT_STRING "%016lX" |
15 | | #else |
16 | | #define WORD_FORMAT_STRING "%08X" |
17 | | #endif |
18 | | |
19 | | using Botan::word; |
20 | | |
21 | | namespace { |
22 | | |
23 | | void dump_word_vec(const char* name, const word x[], size_t x_len) |
24 | 0 | { |
25 | 0 | fprintf(stderr, "%s = ", name); |
26 | 0 | for(size_t i = 0; i != x_len; ++i) |
27 | 0 | { |
28 | 0 | fprintf(stderr, WORD_FORMAT_STRING, x[i]); |
29 | 0 | fprintf(stderr, " "); |
30 | 0 | } |
31 | 0 | fprintf(stderr, "\n"); |
32 | 0 | } Unexecuted instantiation: mp_redc.cpp:(anonymous namespace)::dump_word_vec(char const*, unsigned long const*, unsigned long) Unexecuted instantiation: mp_comba_mul.cpp:(anonymous namespace)::dump_word_vec(char const*, unsigned long const*, unsigned long) Unexecuted instantiation: mp_comba_sqr.cpp:(anonymous namespace)::dump_word_vec(char const*, unsigned long const*, unsigned long) |
33 | | |
34 | | void compare_word_vec(const word x[], size_t x_len, |
35 | | const word y[], size_t y_len, |
36 | | const char* comparing) |
37 | 767 | { |
38 | 767 | const size_t common_words = std::min(x_len, y_len); |
39 | | |
40 | 21.3k | for(size_t i = 0; i != common_words; ++i) |
41 | 20.5k | { |
42 | 20.5k | if(x[i] != y[i]) |
43 | 0 | { |
44 | 0 | dump_word_vec("x", x, x_len); |
45 | 0 | dump_word_vec("y", y, y_len); |
46 | 0 | FUZZER_WRITE_AND_CRASH("Comparison failed " << comparing); |
47 | 0 | } |
48 | 20.5k | } |
49 | | |
50 | | // all other words must be zero |
51 | 767 | for(size_t i = common_words; i != x_len; ++i) |
52 | 0 | { |
53 | 0 | if(x[i] != 0) |
54 | 0 | { |
55 | 0 | dump_word_vec("x", x, x_len); |
56 | 0 | dump_word_vec("y", y, y_len); |
57 | 0 | FUZZER_WRITE_AND_CRASH("Unexpected non-zero in high words of x " << comparing); |
58 | 0 | } |
59 | 0 | } |
60 | 4.44k | for(size_t i = common_words; i != y_len; ++i) |
61 | 3.67k | { |
62 | 3.67k | if(y[i] != 0) |
63 | 0 | { |
64 | 0 | dump_word_vec("x", x, x_len); |
65 | 0 | dump_word_vec("y", y, y_len); |
66 | 0 | FUZZER_WRITE_AND_CRASH("Unexpected non-zero in high words of y " << comparing); |
67 | 0 | } |
68 | 3.67k | } |
69 | 767 | } mp_redc.cpp:(anonymous namespace)::compare_word_vec(unsigned long const*, unsigned long, unsigned long const*, unsigned long, char const*) Line | Count | Source | 37 | 12 | { | 38 | 12 | const size_t common_words = std::min(x_len, y_len); | 39 | | | 40 | 372 | for(size_t i = 0; i != common_words; ++i) | 41 | 360 | { | 42 | 360 | if(x[i] != y[i]) | 43 | 0 | { | 44 | 0 | dump_word_vec("x", x, x_len); | 45 | 0 | dump_word_vec("y", y, y_len); | 46 | 0 | FUZZER_WRITE_AND_CRASH("Comparison failed " << comparing); | 47 | 0 | } | 48 | 360 | } | 49 | | | 50 | | // all other words must be zero | 51 | 12 | for(size_t i = common_words; i != x_len; ++i) | 52 | 0 | { | 53 | 0 | if(x[i] != 0) | 54 | 0 | { | 55 | 0 | dump_word_vec("x", x, x_len); | 56 | 0 | dump_word_vec("y", y, y_len); | 57 | 0 | FUZZER_WRITE_AND_CRASH("Unexpected non-zero in high words of x " << comparing); | 58 | 0 | } | 59 | 0 | } | 60 | 12 | for(size_t i = common_words; i != y_len; ++i) | 61 | 0 | { | 62 | 0 | if(y[i] != 0) | 63 | 0 | { | 64 | 0 | dump_word_vec("x", x, x_len); | 65 | 0 | dump_word_vec("y", y, y_len); | 66 | 0 | FUZZER_WRITE_AND_CRASH("Unexpected non-zero in high words of y " << comparing); | 67 | 0 | } | 68 | 0 | } | 69 | 12 | } |
mp_comba_mul.cpp:(anonymous namespace)::compare_word_vec(unsigned long const*, unsigned long, unsigned long const*, unsigned long, char const*) Line | Count | Source | 37 | 291 | { | 38 | 291 | const size_t common_words = std::min(x_len, y_len); | 39 | | | 40 | 7.73k | for(size_t i = 0; i != common_words; ++i) | 41 | 7.44k | { | 42 | 7.44k | if(x[i] != y[i]) | 43 | 0 | { | 44 | 0 | dump_word_vec("x", x, x_len); | 45 | 0 | dump_word_vec("y", y, y_len); | 46 | 0 | FUZZER_WRITE_AND_CRASH("Comparison failed " << comparing); | 47 | 0 | } | 48 | 7.44k | } | 49 | | | 50 | | // all other words must be zero | 51 | 291 | for(size_t i = common_words; i != x_len; ++i) | 52 | 0 | { | 53 | 0 | if(x[i] != 0) | 54 | 0 | { | 55 | 0 | dump_word_vec("x", x, x_len); | 56 | 0 | dump_word_vec("y", y, y_len); | 57 | 0 | FUZZER_WRITE_AND_CRASH("Unexpected non-zero in high words of x " << comparing); | 58 | 0 | } | 59 | 0 | } | 60 | 2.38k | for(size_t i = common_words; i != y_len; ++i) | 61 | 2.09k | { | 62 | 2.09k | if(y[i] != 0) | 63 | 0 | { | 64 | 0 | dump_word_vec("x", x, x_len); | 65 | 0 | dump_word_vec("y", y, y_len); | 66 | 0 | FUZZER_WRITE_AND_CRASH("Unexpected non-zero in high words of y " << comparing); | 67 | 0 | } | 68 | 2.09k | } | 69 | 291 | } |
mp_comba_sqr.cpp:(anonymous namespace)::compare_word_vec(unsigned long const*, unsigned long, unsigned long const*, unsigned long, char const*) Line | Count | Source | 37 | 464 | { | 38 | 464 | const size_t common_words = std::min(x_len, y_len); | 39 | | | 40 | 13.2k | for(size_t i = 0; i != common_words; ++i) | 41 | 12.7k | { | 42 | 12.7k | if(x[i] != y[i]) | 43 | 0 | { | 44 | 0 | dump_word_vec("x", x, x_len); | 45 | 0 | dump_word_vec("y", y, y_len); | 46 | 0 | FUZZER_WRITE_AND_CRASH("Comparison failed " << comparing); | 47 | 0 | } | 48 | 12.7k | } | 49 | | | 50 | | // all other words must be zero | 51 | 464 | for(size_t i = common_words; i != x_len; ++i) | 52 | 0 | { | 53 | 0 | if(x[i] != 0) | 54 | 0 | { | 55 | 0 | dump_word_vec("x", x, x_len); | 56 | 0 | dump_word_vec("y", y, y_len); | 57 | 0 | FUZZER_WRITE_AND_CRASH("Unexpected non-zero in high words of x " << comparing); | 58 | 0 | } | 59 | 0 | } | 60 | 2.04k | for(size_t i = common_words; i != y_len; ++i) | 61 | 1.58k | { | 62 | 1.58k | if(y[i] != 0) | 63 | 0 | { | 64 | 0 | dump_word_vec("x", x, x_len); | 65 | 0 | dump_word_vec("y", y, y_len); | 66 | 0 | FUZZER_WRITE_AND_CRASH("Unexpected non-zero in high words of y " << comparing); | 67 | 0 | } | 68 | 1.58k | } | 69 | 464 | } |
|
70 | | |
71 | | } |
72 | | |
73 | | #endif |