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 | 63 | 
1 files changed, 24 insertions, 39 deletions
diff --git a/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.h b/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.h index 934de44009..cbb0f83f8c 100644 --- a/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.h +++ b/src/regress/lib/libcrypto/mlkem/mlkem_tests_util.h  | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | /* $OpenBSD: mlkem_tests_util.h,v 1.2 2024/12/14 19:16:24 tb Exp $ */ | 1 | /* $OpenBSD: mlkem_tests_util.h,v 1.3 2024/12/20 00:07:12 tb Exp $ */ | 
| 2 | /* | 2 | /* | 
| 3 | * Copyright (c) 2024, Bob Beck <beck@obtuse.com> | 3 | * Copyright (c) 2024 Bob Beck <beck@obtuse.com> | 
| 4 | * Copyright (c) 2024 Theo Buehler <tb@openbsd.org> | ||
| 4 | * | 5 | * | 
| 5 | * Permission to use, copy, modify, and/or distribute this software for any | 6 | * Permission to use, copy, modify, and/or distribute this software for any | 
| 6 | * purpose with or without fee is hereby granted, provided that the above | 7 | * purpose with or without fee is hereby granted, provided that the above | 
| @@ -18,47 +19,31 @@ | |||
| 18 | #ifndef MLKEM_TEST_UTIL_H | 19 | #ifndef MLKEM_TEST_UTIL_H | 
| 19 | #define MLKEM_TEST_UTIL_H | 20 | #define MLKEM_TEST_UTIL_H | 
| 20 | 21 | ||
| 22 | #include <stddef.h> | ||
| 21 | #include <stdint.h> | 23 | #include <stdint.h> | 
| 22 | #include <stdio.h> | ||
| 23 | #include <stdlib.h> | ||
| 24 | #include <string.h> | ||
| 25 | 24 | ||
| 26 | #include <openssl/bytestring.h> | 25 | #include "bytestring.h" | 
| 27 | 26 | ||
| 28 | #define TEST(cond, msg) do { \ | 27 | struct MLKEM1024_private_key; | 
| 29 | if ((cond)) { \ | 28 | struct MLKEM1024_public_key; | 
| 30 | failure = 1; \ | 29 | struct MLKEM768_private_key; | 
| 31 | fprintf(stderr, "FAIL: %s:%d - Test %d: %s\n", \ | 30 | struct MLKEM768_public_key; | 
| 32 | __FILE__, __LINE__, test_number, msg); \ | ||
| 33 | } \ | ||
| 34 | } while(0) | ||
| 35 | 31 | ||
| 36 | #define MALLOC(A, B) do { \ | 32 | /* XXX - return values of the two compare functions are inconsistent */ | 
| 37 | if (((A) = malloc(B)) == NULL) { \ | 33 | int compare_data(const uint8_t *want, const uint8_t *got, size_t len, | 
| 38 | failure = 1; \ | 34 | size_t line, const char *msg); | 
| 39 | fprintf(stderr, "FAIL: %s:%d - Test %d: malloc\n", \ | 35 | int compare_length(size_t want, size_t got, size_t line, const char *msg); | 
| 40 | __FILE__, __LINE__, test_number); \ | ||
| 41 | exit(1); \ | ||
| 42 | } \ | ||
| 43 | } while(0) | ||
| 44 | 36 | ||
| 45 | #define TEST_DATAEQ(values, expected, len, msg) do { \ | 37 | void hex_decode_cbs(CBS *cbs, CBB *cbb, size_t line, const char *msg); | 
| 46 | if (memcmp((values), (expected), (len)) != 0) { \ | 38 | int get_string_cbs(CBS *cbs, const char *str, size_t line, const char *msg); | 
| 47 | failure = 1; \ | ||
| 48 | fprintf(stderr, "FAIL: %s:%d - Test %d: %s differs\n", \ | ||
| 49 | __FILE__, __LINE__, test_number, msg); \ | ||
| 50 | fprintf(stderr, "values:\n"); \ | ||
| 51 | hexdump(values, len, expected); \ | ||
| 52 | fprintf(stderr, "expected:\n"); \ | ||
| 53 | hexdump(expected, len, values); \ | ||
| 54 | fprintf(stderr, "\n"); \ | ||
| 55 | } \ | ||
| 56 | } while(0) | ||
| 57 | 39 | ||
| 58 | extern int failure, test_number; | 40 | int mlkem768_encode_private_key(const struct MLKEM768_private_key *priv, | 
| 41 | uint8_t **out_buf, size_t *out_len); | ||
| 42 | int mlkem768_encode_public_key(const struct MLKEM768_public_key *pub, | ||
| 43 | uint8_t **out_buf, size_t *out_len); | ||
| 44 | int mlkem1024_encode_private_key(const struct MLKEM1024_private_key *priv, | ||
| 45 | uint8_t **out_buf, size_t *out_len); | ||
| 46 | int mlkem1024_encode_public_key(const struct MLKEM1024_public_key *pub, | ||
| 47 | uint8_t **out_buf, size_t *out_len); | ||
| 59 | 48 | ||
| 60 | void hexdump(const uint8_t *buf, size_t len, const uint8_t *compare); | 49 | #endif /* MLKEM_TEST_UTIL_H */ | 
| 61 | int hex_decode(char *buf, size_t len, uint8_t **out_buf, size_t *out_len); | ||
| 62 | void grab_data(CBS *cbs, char *buf, size_t offset); | ||
| 63 | |||
| 64 | #endif | ||
