aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests.c182
1 files changed, 91 insertions, 91 deletions
diff --git a/tests.c b/tests.c
index a1b94af..29392e8 100644
--- a/tests.c
+++ b/tests.c
@@ -8,6 +8,59 @@
static const struct {
const char * const s;
const size_t n;
+ const uint8_t h[SHA224_HASH_SIZE];
+} SHA224_TESTS[] = {{
+ .s = "",
+ .h = {
+ 0xd1, 0x4a, 0x02, 0x8c, 0x2a, 0x3a, 0x2b, 0xc9,
+ 0x47, 0x61, 0x02, 0xbb, 0x28, 0x82, 0x34, 0xc4,
+ 0x15, 0xa2, 0xb0, 0x1f, 0x82, 0x8e, 0xa6, 0x2a,
+ 0xc5, 0xb3, 0xe4, 0x2f,
+ },
+}, {
+ .s = "abc",
+ .h = {
+ 0x23, 0x09, 0x7d, 0x22, 0x34, 0x05, 0xd8, 0x22,
+ 0x86, 0x42, 0xa4, 0x77, 0xbd, 0xa2, 0x55, 0xb3,
+ 0x2a, 0xad, 0xbc, 0xe4, 0xbd, 0xa0, 0xb3, 0xf7,
+ 0xe3, 0x6c, 0x9d, 0xa7,
+ },
+}, {
+ .s = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+ .h = {
+ 0x75, 0x38, 0x8b, 0x16, 0x51, 0x27, 0x76, 0xcc,
+ 0x5d, 0xba, 0x5d, 0xa1, 0xfd, 0x89, 0x01, 0x50,
+ 0xb0, 0xc6, 0x45, 0x5c, 0xb4, 0xf5, 0x8b, 0x19,
+ 0x52, 0x52, 0x25, 0x25,
+ },
+}, {
+ .s = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
+ .h = {
+ 0xc9, 0x7c, 0xa9, 0xa5, 0x59, 0x85, 0x0c, 0xe9, 0x7a, 0x04, 0xa9,
+ 0x6d, 0xef, 0x6d, 0x99, 0xa9, 0xe0, 0xe0, 0xe2, 0xab, 0x14, 0xe6,
+ 0xb8, 0xdf, 0x26, 0x5f, 0xc0, 0xb3,
+ },
+}, {
+ .s = "a",
+ .n = 1000000,
+ .h = {
+ 0x20, 0x79, 0x46, 0x55, 0x98, 0x0c, 0x91, 0xd8, 0xbb, 0xb4, 0xc1,
+ 0xea, 0x97, 0x61, 0x8a, 0x4b, 0xf0, 0x3f, 0x42, 0x58, 0x19, 0x48,
+ 0xb2, 0xee, 0x4e, 0xe7, 0xad, 0x67,
+ },
+}, {
+ .s = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno",
+ .n = 16777216,
+ .h = {
+ 0xb5, 0x98, 0x97, 0x13, 0xca, 0x4f, 0xe4, 0x7a, 0x00, 0x9f, 0x86,
+ 0x21, 0x98, 0x0b, 0x34, 0xe6, 0xd6, 0x3e, 0xd3, 0x06, 0x3b, 0x2a,
+ 0x0a, 0x2c, 0x86, 0x7d, 0x8a, 0x85,
+ },
+}};
+
+static const struct {
+ const char * const s;
+ const size_t n;
const uint8_t h[SHA256_HASH_SIZE];
} SHA256_TESTS[] = {{
.s = "",
@@ -61,53 +114,62 @@ static const struct {
static const struct {
const char * const s;
const size_t n;
- const uint8_t h[SHA224_HASH_SIZE];
-} SHA224_TESTS[] = {{
+ const uint8_t h[SHA384_HASH_SIZE];
+} SHA384_TESTS[] = {{
.s = "",
.h = {
- 0xd1, 0x4a, 0x02, 0x8c, 0x2a, 0x3a, 0x2b, 0xc9,
- 0x47, 0x61, 0x02, 0xbb, 0x28, 0x82, 0x34, 0xc4,
- 0x15, 0xa2, 0xb0, 0x1f, 0x82, 0x8e, 0xa6, 0x2a,
- 0xc5, 0xb3, 0xe4, 0x2f,
+ 0x38, 0xb0, 0x60, 0xa7, 0x51, 0xac, 0x96, 0x38, 0x4c, 0xd9, 0x32,
+ 0x7e, 0xb1, 0xb1, 0xe3, 0x6a, 0x21, 0xfd, 0xb7, 0x11, 0x14, 0xbe,
+ 0x07, 0x43, 0x4c, 0x0c, 0xc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 0xbc, 0x4e, 0x6f, 0x5f, 0xe9, 0x5b, 0x1f,
+ 0xe3, 0xc8, 0x45, 0x2b,
},
}, {
.s = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
.h = {
- 0xc9, 0x7c, 0xa9, 0xa5, 0x59, 0x85, 0x0c, 0xe9, 0x7a, 0x04, 0xa9,
- 0x6d, 0xef, 0x6d, 0x99, 0xa9, 0xe0, 0xe0, 0xe2, 0xab, 0x14, 0xe6,
- 0xb8, 0xdf, 0x26, 0x5f, 0xc0, 0xb3,
+ 0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8, 0x3d, 0x19, 0x2f,
+ 0xc7, 0x82, 0xcd, 0x1b, 0x47, 0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b,
+ 0x05, 0xd2, 0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12, 0xfc,
+ 0xc7, 0xc7, 0x1a, 0x55, 0x7e, 0x2d, 0xb9, 0x66, 0xc3, 0xe9, 0xfa,
+ 0x91, 0x74, 0x60, 0x39,
},
}, {
.s = "a",
.n = 1000000,
.h = {
- 0x20, 0x79, 0x46, 0x55, 0x98, 0x0c, 0x91, 0xd8, 0xbb, 0xb4, 0xc1,
- 0xea, 0x97, 0x61, 0x8a, 0x4b, 0xf0, 0x3f, 0x42, 0x58, 0x19, 0x48,
- 0xb2, 0xee, 0x4e, 0xe7, 0xad, 0x67,
+ 0x9d, 0x0e, 0x18, 0x09, 0x71, 0x64, 0x74, 0xcb, 0x08, 0x6e, 0x83,
+ 0x4e, 0x31, 0x0a, 0x4a, 0x1c, 0xed, 0x14, 0x9e, 0x9c, 0x00, 0xf2,
+ 0x48, 0x52, 0x79, 0x72, 0xce, 0xc5, 0x70, 0x4c, 0x2a, 0x5b, 0x07,
+ 0xb8, 0xb3, 0xdc, 0x38, 0xec, 0xc4, 0xeb, 0xae, 0x97, 0xdd, 0xd8,
+ 0x7f, 0x3d, 0x89, 0x85,
},
}, {
.s = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno",
.n = 16777216,
.h = {
- 0xb5, 0x98, 0x97, 0x13, 0xca, 0x4f, 0xe4, 0x7a, 0x00, 0x9f, 0x86,
- 0x21, 0x98, 0x0b, 0x34, 0xe6, 0xd6, 0x3e, 0xd3, 0x06, 0x3b, 0x2a,
- 0x0a, 0x2c, 0x86, 0x7d, 0x8a, 0x85,
+ 0x54, 0x41, 0x23, 0x5c, 0xc0, 0x23, 0x53, 0x41, 0xed, 0x80, 0x6a,
+ 0x64, 0xfb, 0x35, 0x47, 0x42, 0xb5, 0xe5, 0xc0, 0x2a, 0x3c, 0x5c,
+ 0xb7, 0x1b, 0x5f, 0x63, 0xfb, 0x79, 0x34, 0x58, 0xd8, 0xfd, 0xae,
+ 0x59, 0x9c, 0x8c, 0xd8, 0x88, 0x49, 0x43, 0xc0, 0x4f, 0x11, 0xb3,
+ 0x1b, 0x89, 0xf0, 0x23,
},
}};
@@ -179,68 +241,6 @@ static const struct {
},
}};
-static const struct {
- const char * const s;
- const size_t n;
- const uint8_t h[SHA384_HASH_SIZE];
-} SHA384_TESTS[] = {{
- .s = "",
- .h = {
- 0x38, 0xb0, 0x60, 0xa7, 0x51, 0xac, 0x96, 0x38, 0x4c, 0xd9, 0x32,
- 0x7e, 0xb1, 0xb1, 0xe3, 0x6a, 0x21, 0xfd, 0xb7, 0x11, 0x14, 0xbe,
- 0x07, 0x43, 0x4c, 0x0c, 0xc7, 0xbf, 0x63, 0xf6, 0xe1, 0xda, 0x27,
- 0x4e, 0xde, 0xbf, 0xe7, 0x6f, 0x65, 0xfb, 0xd5, 0x1a, 0xd2, 0xf1,
- 0x48, 0x98, 0xb9, 0x5b,
- },
-}, {
- .s = "abc",
- .h = {
- 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b, 0xb5, 0xa0, 0x3d,
- 0x69, 0x9a, 0xc6, 0x50, 0x07, 0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde,
- 0xd1, 0x63, 0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed, 0x80,
- 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23, 0x58, 0xba, 0xec, 0xa1,
- 0x34, 0xc8, 0x25, 0xa7,
- },
-}, {
- .s = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
- .h = {
- 0x33, 0x91, 0xfd, 0xdd, 0xfc, 0x8d, 0xc7, 0x39, 0x37, 0x07, 0xa6,
- 0x5b, 0x1b, 0x47, 0x09, 0x39, 0x7c, 0xf8, 0xb1, 0xd1, 0x62, 0xaf,
- 0x05, 0xab, 0xfe, 0x8f, 0x45, 0x0d, 0xe5, 0xf3, 0x6b, 0xc6, 0xb0,
- 0x45, 0x5a, 0x85, 0x20, 0xbc, 0x4e, 0x6f, 0x5f, 0xe9, 0x5b, 0x1f,
- 0xe3, 0xc8, 0x45, 0x2b,
- },
-}, {
- .s = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
- .h = {
- 0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8, 0x3d, 0x19, 0x2f,
- 0xc7, 0x82, 0xcd, 0x1b, 0x47, 0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b,
- 0x05, 0xd2, 0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12, 0xfc,
- 0xc7, 0xc7, 0x1a, 0x55, 0x7e, 0x2d, 0xb9, 0x66, 0xc3, 0xe9, 0xfa,
- 0x91, 0x74, 0x60, 0x39,
- },
-}, {
- .s = "a",
- .n = 1000000,
- .h = {
- 0x9d, 0x0e, 0x18, 0x09, 0x71, 0x64, 0x74, 0xcb, 0x08, 0x6e, 0x83,
- 0x4e, 0x31, 0x0a, 0x4a, 0x1c, 0xed, 0x14, 0x9e, 0x9c, 0x00, 0xf2,
- 0x48, 0x52, 0x79, 0x72, 0xce, 0xc5, 0x70, 0x4c, 0x2a, 0x5b, 0x07,
- 0xb8, 0xb3, 0xdc, 0x38, 0xec, 0xc4, 0xeb, 0xae, 0x97, 0xdd, 0xd8,
- 0x7f, 0x3d, 0x89, 0x85,
- },
-}, {
- .s = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno",
- .n = 16777216,
- .h = {
- 0x54, 0x41, 0x23, 0x5c, 0xc0, 0x23, 0x53, 0x41, 0xed, 0x80, 0x6a,
- 0x64, 0xfb, 0x35, 0x47, 0x42, 0xb5, 0xe5, 0xc0, 0x2a, 0x3c, 0x5c,
- 0xb7, 0x1b, 0x5f, 0x63, 0xfb, 0x79, 0x34, 0x58, 0xd8, 0xfd, 0xae,
- 0x59, 0x9c, 0x8c, 0xd8, 0x88, 0x49, 0x43, 0xc0, 0x4f, 0x11, 0xb3,
- 0x1b, 0x89, 0xf0, 0x23,
- },
-}};
-
#define DEF_TEST_FUNC(size) \
static const size_t NUM_SHA ## size ## _TESTS = \
(sizeof(SHA ## size ## _TESTS) / sizeof(SHA ## size ## _TESTS[0])); \
@@ -277,14 +277,14 @@ static const struct {
return r; \
}
-DEF_TEST_FUNC(256)
DEF_TEST_FUNC(224)
-DEF_TEST_FUNC(512)
+DEF_TEST_FUNC(256)
DEF_TEST_FUNC(384)
+DEF_TEST_FUNC(512)
unsigned int run_tests(test_fail_cb_t on_fail) {
- return test_sha256(on_fail) +
- test_sha224(on_fail) +
- test_sha512(on_fail) +
- test_sha384(on_fail);
+ return test_sha224(on_fail) +
+ test_sha256(on_fail) +
+ test_sha384(on_fail) +
+ test_sha512(on_fail) ;
}