diff options
Diffstat (limited to 'src/regress/lib/libc/hash')
-rw-r--r-- | src/regress/lib/libc/hash/Makefile | 2 | ||||
-rw-r--r-- | src/regress/lib/libc/hash/hash_test.c | 14 |
2 files changed, 5 insertions, 11 deletions
diff --git a/src/regress/lib/libc/hash/Makefile b/src/regress/lib/libc/hash/Makefile index 54e4baace8..9bd69bf8df 100644 --- a/src/regress/lib/libc/hash/Makefile +++ b/src/regress/lib/libc/hash/Makefile | |||
@@ -1,3 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2025/04/14 18:33:56 tb Exp $ | ||
2 | |||
1 | PROG = hash_test | 3 | PROG = hash_test |
2 | 4 | ||
3 | .include <bsd.regress.mk> | 5 | .include <bsd.regress.mk> |
diff --git a/src/regress/lib/libc/hash/hash_test.c b/src/regress/lib/libc/hash/hash_test.c index 67b1f380ed..c04a0458fe 100644 --- a/src/regress/lib/libc/hash/hash_test.c +++ b/src/regress/lib/libc/hash/hash_test.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: hash_test.c,v 1.1.1.1 2025/04/14 17:32:05 tb Exp $ */ | 1 | /* $OpenBSD: hash_test.c,v 1.3 2025/08/02 06:05:13 tb Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2025 Theo Buehler <tb@openbsd.org> | 4 | * Copyright (c) 2025 Theo Buehler <tb@openbsd.org> |
@@ -25,8 +25,6 @@ | |||
25 | #include <stdio.h> | 25 | #include <stdio.h> |
26 | #include <string.h> | 26 | #include <string.h> |
27 | 27 | ||
28 | #define ALL_HASHES_ALLOW_NULL 0 | ||
29 | |||
30 | #define MAX_DIGEST_LENGTH SHA512_DIGEST_LENGTH | 28 | #define MAX_DIGEST_LENGTH SHA512_DIGEST_LENGTH |
31 | 29 | ||
32 | struct hash_test_case { | 30 | struct hash_test_case { |
@@ -48,14 +46,12 @@ enum { | |||
48 | 46 | ||
49 | /* RFC 1321, Appendix A.5 */ | 47 | /* RFC 1321, Appendix A.5 */ |
50 | static const struct hash_test_case md5_tests[] = { | 48 | static const struct hash_test_case md5_tests[] = { |
51 | #if ALL_HASHES_ALLOW_NULL | ||
52 | { | 49 | { |
53 | .out = { | 50 | .out = { |
54 | 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, | 51 | 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, |
55 | 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e, | 52 | 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e, |
56 | }, | 53 | }, |
57 | }, | 54 | }, |
58 | #endif | ||
59 | { | 55 | { |
60 | .in = "", | 56 | .in = "", |
61 | .out = { | 57 | .out = { |
@@ -131,7 +127,6 @@ md5_final(void *digest, void *ctx) | |||
131 | 127 | ||
132 | /* https://homes.esat.kuleuven.be/~bosselae/ripemd160.html */ | 128 | /* https://homes.esat.kuleuven.be/~bosselae/ripemd160.html */ |
133 | static const struct hash_test_case rmd160_tests[] = { | 129 | static const struct hash_test_case rmd160_tests[] = { |
134 | #if ALL_HASHES_ALLOW_NULL | ||
135 | { | 130 | { |
136 | .out = { | 131 | .out = { |
137 | 0x9c, 0x11, 0x85, 0xa5, 0xc5, 0xe9, 0xfc, 0x54, | 132 | 0x9c, 0x11, 0x85, 0xa5, 0xc5, 0xe9, 0xfc, 0x54, |
@@ -139,7 +134,6 @@ static const struct hash_test_case rmd160_tests[] = { | |||
139 | 0xb2, 0x25, 0x8d, 0x31, | 134 | 0xb2, 0x25, 0x8d, 0x31, |
140 | }, | 135 | }, |
141 | }, | 136 | }, |
142 | #endif | ||
143 | { | 137 | { |
144 | .in = "", | 138 | .in = "", |
145 | .out = { | 139 | .out = { |
@@ -231,7 +225,6 @@ rmd160_final(void *digest, void *ctx) | |||
231 | 225 | ||
232 | /* RFC 3174 - Appendix A (plus two zero-length tests) */ | 226 | /* RFC 3174 - Appendix A (plus two zero-length tests) */ |
233 | static const struct hash_test_case sha1_tests[] = { | 227 | static const struct hash_test_case sha1_tests[] = { |
234 | #if ALL_HASHES_ALLOW_NULL | ||
235 | { | 228 | { |
236 | .out = { | 229 | .out = { |
237 | 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, | 230 | 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, |
@@ -239,7 +232,6 @@ static const struct hash_test_case sha1_tests[] = { | |||
239 | 0xaf, 0xd8, 0x07, 0x09, | 232 | 0xaf, 0xd8, 0x07, 0x09, |
240 | }, | 233 | }, |
241 | }, | 234 | }, |
242 | #endif | ||
243 | { | 235 | { |
244 | .in = "", | 236 | .in = "", |
245 | .out = { | 237 | .out = { |
@@ -765,7 +757,7 @@ struct hash_ctx { | |||
765 | void *ctx; | 757 | void *ctx; |
766 | void (*init)(void *); | 758 | void (*init)(void *); |
767 | void (*update)(void *, const uint8_t *, size_t); | 759 | void (*update)(void *, const uint8_t *, size_t); |
768 | void (*final)(void *, void *final); | 760 | void (*final)(void *, void *); |
769 | }; | 761 | }; |
770 | 762 | ||
771 | static const struct hash_tests { | 763 | static const struct hash_tests { |
@@ -822,7 +814,7 @@ hash_test_case(struct hash_ctx *ctx, const struct hash_test_case *tc, | |||
822 | size_t in_len = tc->in != NULL ? strlen(tc->in) : 0; | 814 | size_t in_len = tc->in != NULL ? strlen(tc->in) : 0; |
823 | 815 | ||
824 | ctx->init(ctx->ctx); | 816 | ctx->init(ctx->ctx); |
825 | ctx->update(ctx->ctx, (uint8_t *)tc->in, in_len); | 817 | ctx->update(ctx->ctx, (const uint8_t *)tc->in, in_len); |
826 | ctx->final(ctx->digest, ctx->ctx); | 818 | ctx->final(ctx->digest, ctx->ctx); |
827 | 819 | ||
828 | if (memcmp(tc->out, ctx->digest, ctx->digest_len) != 0) { | 820 | if (memcmp(tc->out, ctx->digest, ctx->digest_len) != 0) { |