summaryrefslogtreecommitdiffstats
path: root/testsuites/libtests/sha/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'testsuites/libtests/sha/init.c')
-rw-r--r--testsuites/libtests/sha/init.c217
1 files changed, 212 insertions, 5 deletions
diff --git a/testsuites/libtests/sha/init.c b/testsuites/libtests/sha/init.c
index c65517253a..7d8c4ada3e 100644
--- a/testsuites/libtests/sha/init.c
+++ b/testsuites/libtests/sha/init.c
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
- * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ * Copyright (c) 2014 embedded brains GmbH & Co. KG
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -29,8 +29,11 @@
#include "config.h"
#endif
+#include <sha224.h>
#include <sha256.h>
+#include <sha384.h>
#include <sha512.h>
+#include <sha512t.h>
#include <stdio.h>
#include <string.h>
@@ -49,7 +52,32 @@ static const char *const test_vectors[] = {
};
static const unsigned char
-test_sha256_results[RTEMS_ARRAY_SIZE(test_vectors)][32] = {
+test_sha224_results[RTEMS_ARRAY_SIZE(test_vectors)][SHA224_DIGEST_LENGTH] = {
+ {
+ 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
+ }, {
+ 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
+ }, {
+ 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
+ }, {
+ 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
+ }
+};
+
+static const unsigned char
+test_sha256_results[RTEMS_ARRAY_SIZE(test_vectors)][SHA256_DIGEST_LENGTH] = {
{
0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
@@ -74,7 +102,40 @@ test_sha256_results[RTEMS_ARRAY_SIZE(test_vectors)][32] = {
};
static const unsigned char
-test_sha512_results[RTEMS_ARRAY_SIZE(test_vectors)][64] = {
+test_sha384_results[RTEMS_ARRAY_SIZE(test_vectors)][SHA384_DIGEST_LENGTH] = {
+ {
+ 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
+ }, {
+ 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
+ }, {
+ 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
+ }, {
+ 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
+ }
+};
+
+static const unsigned char
+test_sha512_results[RTEMS_ARRAY_SIZE(test_vectors)][SHA512_DIGEST_LENGTH] = {
{
0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba,
0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31,
@@ -114,6 +175,56 @@ test_sha512_results[RTEMS_ARRAY_SIZE(test_vectors)][64] = {
}
};
+static const unsigned char test_sha512_224_results
+[RTEMS_ARRAY_SIZE(test_vectors)][SHA512_224_DIGEST_LENGTH] = {
+ {
+ 0x46, 0x34, 0x27, 0x0f, 0x70, 0x7b, 0x6a, 0x54,
+ 0xda, 0xae, 0x75, 0x30, 0x46, 0x08, 0x42, 0xe2,
+ 0x0e, 0x37, 0xed, 0x26, 0x5c, 0xee, 0xe9, 0xa4,
+ 0x3e, 0x89, 0x24, 0xaa
+ }, {
+ 0x6e, 0xd0, 0xdd, 0x02, 0x80, 0x6f, 0xa8, 0x9e,
+ 0x25, 0xde, 0x06, 0x0c, 0x19, 0xd3, 0xac, 0x86,
+ 0xca, 0xbb, 0x87, 0xd6, 0xa0, 0xdd, 0xd0, 0x5c,
+ 0x33, 0x3b, 0x84, 0xf4
+ }, {
+ 0xe5, 0x30, 0x2d, 0x6d, 0x54, 0xbb, 0x24, 0x22,
+ 0x75, 0xd1, 0xe7, 0x62, 0x2d, 0x68, 0xdf, 0x6e,
+ 0xb0, 0x2d, 0xed, 0xd1, 0x3f, 0x56, 0x4c, 0x13,
+ 0xdb, 0xda, 0x21, 0x74
+ }, {
+ 0x23, 0xfe, 0xc5, 0xbb, 0x94, 0xd6, 0x0b, 0x23,
+ 0x30, 0x81, 0x92, 0x64, 0x0b, 0x0c, 0x45, 0x33,
+ 0x35, 0xd6, 0x64, 0x73, 0x4f, 0xe4, 0x0e, 0x72,
+ 0x68, 0x67, 0x4a, 0xf9
+ }
+};
+
+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)
{
size_t i;
@@ -133,6 +244,29 @@ static void print_result(const unsigned char *r, size_t n)
printf("\n");
}
+static void test_sha224(void)
+{
+ size_t i;
+
+ printf("test SHA224\n");
+
+ for (i = 0; i < RTEMS_ARRAY_SIZE(test_vectors); ++i) {
+ SHA224_CTX ctx;
+ unsigned char r[SHA224_DIGEST_LENGTH];
+ const char *s = test_vectors[i];
+
+ SHA224_Init(&ctx);
+ SHA224_Update(&ctx, s, strlen(s));
+ SHA224_Final(r, &ctx);
+
+ print_result(&r[0], sizeof(r));
+
+ rtems_test_assert(
+ memcmp(&r[0], &test_sha224_results[i][0], sizeof(r)) == 0
+ );
+ }
+}
+
static void test_sha256(void)
{
size_t i;
@@ -141,7 +275,7 @@ static void test_sha256(void)
for (i = 0; i < RTEMS_ARRAY_SIZE(test_vectors); ++i) {
SHA256_CTX ctx;
- unsigned char r[32];
+ unsigned char r[SHA256_DIGEST_LENGTH];
const char *s = test_vectors[i];
SHA256_Init(&ctx);
@@ -156,6 +290,29 @@ static void test_sha256(void)
}
}
+static void test_sha384(void)
+{
+ size_t i;
+
+ printf("test SHA384\n");
+
+ for (i = 0; i < RTEMS_ARRAY_SIZE(test_vectors); ++i) {
+ SHA384_CTX ctx;
+ unsigned char r[SHA384_DIGEST_LENGTH];
+ const char *s = test_vectors[i];
+
+ SHA384_Init(&ctx);
+ SHA384_Update(&ctx, s, strlen(s));
+ SHA384_Final(r, &ctx);
+
+ print_result(&r[0], sizeof(r));
+
+ rtems_test_assert(
+ memcmp(&r[0], &test_sha384_results[i][0], sizeof(r)) == 0
+ );
+ }
+}
+
static void test_sha512(void)
{
size_t i;
@@ -164,7 +321,7 @@ static void test_sha512(void)
for (i = 0; i < RTEMS_ARRAY_SIZE(test_vectors); ++i) {
SHA512_CTX ctx;
- unsigned char r[64];
+ unsigned char r[SHA512_DIGEST_LENGTH];
const char *s = test_vectors[i];
SHA512_Init(&ctx);
@@ -179,12 +336,62 @@ static void test_sha512(void)
}
}
+static void test_sha512_224(void)
+{
+ size_t i;
+
+ printf("test SHA512-224\n");
+
+ for (i = 0; i < RTEMS_ARRAY_SIZE(test_vectors); ++i) {
+ SHA512_CTX ctx;
+ unsigned char r[SHA512_224_DIGEST_LENGTH];
+ const char *s = test_vectors[i];
+
+ SHA512_224_Init(&ctx);
+ SHA512_224_Update(&ctx, s, strlen(s));
+ SHA512_224_Final(r, &ctx);
+
+ print_result(&r[0], sizeof(r));
+
+ rtems_test_assert(
+ memcmp(&r[0], &test_sha512_224_results[i][0], sizeof(r)) == 0
+ );
+ }
+}
+
+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)
{
TEST_BEGIN();
+ test_sha224();
test_sha256();
+ test_sha384();
test_sha512();
+ test_sha512_224();
+ test_sha512_256();
rtems_stack_checker_report_usage();
TEST_END();