diff options
Diffstat (limited to 'src/regress/lib/libcrypto/mlkem/mlkem_tests_util.h')
-rw-r--r-- | src/regress/lib/libcrypto/mlkem/mlkem_tests_util.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.h b/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.h new file mode 100644 index 0000000000..6666097577 --- /dev/null +++ b/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.h | |||
@@ -0,0 +1,56 @@ | |||
1 | /* Copyright (c) 2024, Bob Beck <beck@obtuse.com> | ||
2 | * | ||
3 | * Permission to use, copy, modify, and/or distribute this software for any | ||
4 | * purpose with or without fee is hereby granted, provided that the above | ||
5 | * copyright notice and this permission notice appear in all copies. | ||
6 | * | ||
7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ | ||
14 | |||
15 | #ifndef MLKEM_TEST_UTIL_H | ||
16 | #define MLKEM_TEST_UTIL_H | ||
17 | |||
18 | #include "bytestring.h" | ||
19 | |||
20 | #define TEST(cond, msg) do { \ | ||
21 | if ((cond)) { \ | ||
22 | failure = 1; \ | ||
23 | fprintf(stderr, "FAIL: %s:%d - Test %d: %s\n", \ | ||
24 | __FILE__, __LINE__, test_number, msg); \ | ||
25 | } \ | ||
26 | } while(0) | ||
27 | |||
28 | #define MALLOC(A, B) do { \ | ||
29 | if (((A) = malloc(B)) == NULL) { \ | ||
30 | failure = 1; \ | ||
31 | fprintf(stderr, "FAIL: %s:%d - Test %d: malloc\n", \ | ||
32 | __FILE__, __LINE__, test_number); \ | ||
33 | exit(1); \ | ||
34 | } \ | ||
35 | } while(0) | ||
36 | |||
37 | #define TEST_DATAEQ(values, expected, len, msg) do { \ | ||
38 | if (memcmp((values), (expected), (len)) != 0) { \ | ||
39 | failure = 1; \ | ||
40 | fprintf(stderr, "FAIL: %s:%d - Test %d: %s differs\n", \ | ||
41 | __FILE__, __LINE__, test_number, msg); \ | ||
42 | fprintf(stderr, "values:\n"); \ | ||
43 | hexdump(values, len, expected); \ | ||
44 | fprintf(stderr, "expected:\n"); \ | ||
45 | hexdump(expected, len, values); \ | ||
46 | fprintf(stderr, "\n"); \ | ||
47 | } \ | ||
48 | } while(0) | ||
49 | |||
50 | extern int failure, test_number; | ||
51 | |||
52 | void hexdump(const uint8_t *buf, size_t len, const uint8_t *compare); | ||
53 | int hex_decode(char *buf, size_t len, uint8_t **out_buf, size_t *out_len); | ||
54 | void grab_data(CBS *cbs, char *buf, size_t offset); | ||
55 | |||
56 | #endif | ||