diff options
Diffstat (limited to 'src/regress/lib/libcrypto/test/test_util.c')
-rw-r--r-- | src/regress/lib/libcrypto/test/test_util.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/regress/lib/libcrypto/test/test_util.c b/src/regress/lib/libcrypto/test/test_util.c new file mode 100644 index 0000000000..6ecb574788 --- /dev/null +++ b/src/regress/lib/libcrypto/test/test_util.c | |||
@@ -0,0 +1,51 @@ | |||
1 | /* $OpenBSD: test_util.c,v 1.1 2025/05/21 08:57:13 joshua Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2017 Joel Sing <jsing@openbsd.org> | ||
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 | #include <stdio.h> | ||
20 | #include <stdint.h> | ||
21 | |||
22 | #include "test.h" | ||
23 | |||
24 | void | ||
25 | test_hexdump(struct test *t, const unsigned char *buf, size_t len) | ||
26 | { | ||
27 | size_t i; | ||
28 | |||
29 | for (i = 1; i <= len; i++) | ||
30 | test_printf(t, " 0x%02x,%s", buf[i - 1], i % 8 ? "" : "\n"); | ||
31 | |||
32 | if ((len % 8) != 0) | ||
33 | test_printf(t, "\n"); | ||
34 | } | ||
35 | |||
36 | void | ||
37 | test_hexdiff(struct test *t, const uint8_t *buf, size_t len, const uint8_t *compare) | ||
38 | { | ||
39 | const char *mark = "", *newline; | ||
40 | size_t i; | ||
41 | |||
42 | for (i = 1; i <= len; i++) { | ||
43 | if (compare != NULL) | ||
44 | mark = (buf[i - 1] != compare[i - 1]) ? "*" : " "; | ||
45 | newline = i % 8 ? "" : "\n"; | ||
46 | test_printf(t, " %s0x%02x,%s", mark, buf[i - 1], newline); | ||
47 | } | ||
48 | |||
49 | if ((len % 8) != 0) | ||
50 | test_printf(t, "\n"); | ||
51 | } | ||