summaryrefslogtreecommitdiff
path: root/src/regress/lib/libcrypto/mlkem/parse_test_file.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/regress/lib/libcrypto/mlkem/parse_test_file.h')
-rw-r--r--src/regress/lib/libcrypto/mlkem/parse_test_file.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/regress/lib/libcrypto/mlkem/parse_test_file.h b/src/regress/lib/libcrypto/mlkem/parse_test_file.h
new file mode 100644
index 0000000000..772b7f6232
--- /dev/null
+++ b/src/regress/lib/libcrypto/mlkem/parse_test_file.h
@@ -0,0 +1,83 @@
1/* $OpenBSD: parse_test_file.h,v 1.1 2024/12/26 00:04:24 tb Exp $ */
2
3/*
4 * Copyright (c) 2024 Theo Buehler <tb@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#ifndef PARSE_TEST_FILE_H
20#define PARSE_TEST_FILE_H
21
22#include <stdint.h>
23#include <stdio.h>
24
25#include "bytestring.h"
26
27#if defined(__cplusplus)
28extern "C" {
29#endif
30
31struct parse;
32
33enum line {
34 LINE_STRING_MATCH, /* Checks if string after label matches. */
35 LINE_HEX, /* Parses hex into cbb from type2cbb. */
36};
37
38struct line_spec {
39 int state;
40 enum line type;
41 const char *name;
42 const char *label; /* followed by ": " or " = " */
43 const char *match; /* only for LINE_STRING_MATCH */
44};
45
46struct test_parse {
47 const struct line_spec *states;
48 size_t num_states;
49
50 const struct line_spec *instructions;
51 size_t num_instructions;
52
53 int (*init)(void *ctx, void *parse_ctx);
54 void (*finish)(void *ctx);
55
56 int (*run_test_case)(void *ctx);
57};
58
59int parse_test_file(const char *fn, const struct test_parse *lctx, void *ctx);
60
61int parse_get_int(struct parse *p, size_t idx, int *out);
62int parse_get_cbs(struct parse *p, size_t idx, CBS *out);
63
64int parse_instruction_get_int(struct parse *p, size_t idx, int *out);
65int parse_instruction_get_cbs(struct parse *p, size_t idx, CBS *out);
66
67int parse_length_equal(struct parse *p, const char *descr, size_t want, size_t got);
68int parse_data_equal(struct parse *p, const char *descr, CBS *want,
69 const uint8_t *got, size_t len);
70
71void parse_info(struct parse *ctx, const char *fmt, ...)
72 __attribute__((__format__ (printf, 2, 3)))
73 __attribute__((__nonnull__ (2)));
74void parse_errx(struct parse *ctx, const char *fmt, ...)
75 __attribute__((__format__ (printf, 2, 3)))
76 __attribute__((__nonnull__ (2)))
77 __attribute__((__noreturn__));
78
79#ifdef __cplusplus
80}
81#endif
82
83#endif /* PARSE_TEST_FILE_H */