libtests/sha: Add tests for SHA512-256

This commit is contained in:
Sebastian Huber
2022-09-08 14:31:07 +02:00
parent fdbf89fee7
commit ac31e2f993

View File

@@ -200,6 +200,31 @@ static const unsigned char test_sha512_224_results
} }
}; };
static const unsigned char test_sha512_256_results
[RTEMS_ARRAY_SIZE(test_vectors)][SHA512_256_DIGEST_LENGTH] = {
{
0x53, 0x04, 0x8e, 0x26, 0x81, 0x94, 0x1e, 0xf9,
0x9b, 0x2e, 0x29, 0xb7, 0x6b, 0x4c, 0x7d, 0xab,
0xe4, 0xc2, 0xd0, 0xc6, 0x34, 0xfc, 0x6d, 0x46,
0xe0, 0xe2, 0xf1, 0x31, 0x07, 0xe7, 0xaf, 0x23
}, {
0xc6, 0x72, 0xb8, 0xd1, 0xef, 0x56, 0xed, 0x28,
0xab, 0x87, 0xc3, 0x62, 0x2c, 0x51, 0x14, 0x06,
0x9b, 0xdd, 0x3a, 0xd7, 0xb8, 0xf9, 0x73, 0x74,
0x98, 0xd0, 0xc0, 0x1e, 0xce, 0xf0, 0x96, 0x7a
}, {
0xbd, 0xe8, 0xe1, 0xf9, 0xf1, 0x9b, 0xb9, 0xfd,
0x34, 0x06, 0xc9, 0x0e, 0xc6, 0xbc, 0x47, 0xbd,
0x36, 0xd8, 0xad, 0xa9, 0xf1, 0x18, 0x80, 0xdb,
0xc8, 0xa2, 0x2a, 0x70, 0x78, 0xb6, 0xa4, 0x61
}, {
0x39, 0x28, 0xe1, 0x84, 0xfb, 0x86, 0x90, 0xf8,
0x40, 0xda, 0x39, 0x88, 0x12, 0x1d, 0x31, 0xbe,
0x65, 0xcb, 0x9d, 0x3e, 0xf8, 0x3e, 0xe6, 0x14,
0x6f, 0xea, 0xc8, 0x61, 0xe1, 0x9b, 0x56, 0x3a
}
};
static void print_result(const unsigned char *r, size_t n) static void print_result(const unsigned char *r, size_t n)
{ {
size_t i; size_t i;
@@ -334,6 +359,29 @@ static void test_sha512_224(void)
} }
} }
static void test_sha512_256(void)
{
size_t i;
printf("test SHA512-256\n");
for (i = 0; i < RTEMS_ARRAY_SIZE(test_vectors); ++i) {
SHA512_CTX ctx;
unsigned char r[SHA512_256_DIGEST_LENGTH];
const char *s = test_vectors[i];
SHA512_256_Init(&ctx);
SHA512_256_Update(&ctx, s, strlen(s));
SHA512_256_Final(r, &ctx);
print_result(&r[0], sizeof(r));
rtems_test_assert(
memcmp(&r[0], &test_sha512_256_results[i][0], sizeof(r)) == 0
);
}
}
static void Init(rtems_task_argument arg) static void Init(rtems_task_argument arg)
{ {
TEST_BEGIN(); TEST_BEGIN();
@@ -343,6 +391,7 @@ static void Init(rtems_task_argument arg)
test_sha384(); test_sha384();
test_sha512(); test_sha512();
test_sha512_224(); test_sha512_224();
test_sha512_256();
rtems_stack_checker_report_usage(); rtems_stack_checker_report_usage();
TEST_END(); TEST_END();