diff options
author | beck <> | 2024-12-13 00:03:57 +0000 |
---|---|---|
committer | beck <> | 2024-12-13 00:03:57 +0000 |
commit | ed3c5d3a4797d4b1d8f9769cfc43f8e686a59621 (patch) | |
tree | a9ff1c725db56dbeb46224505b3dd6fd05a21777 /src/regress/lib/libcrypto/mlkem/mlkem_tests_util.h | |
parent | fd906c7b27573203602764309c3cf5faaefdf573 (diff) | |
download | openbsd-ed3c5d3a4797d4b1d8f9769cfc43f8e686a59621.tar.gz openbsd-ed3c5d3a4797d4b1d8f9769cfc43f8e686a59621.tar.bz2 openbsd-ed3c5d3a4797d4b1d8f9769cfc43f8e686a59621.zip |
Add ML-KEM 768 from BoringSSL
Changes include conversion from C++, basic KNF, then adaptation to
use our sha3 functions for sha3 and shake instead of the BorinSSL
version. This Adds units tests to run against BoringSSL and NIST test
vectors.
The future public API is the same as Boring's - but is not yet exposed
pending making bytesring.h public (which will happen separately) and
a minor bump
Currently this will just ensure we build and run regress.
ok tb@ to get it into the tree and massage from there.
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 | ||