[rtems commit] libtests/sha: Add tests for SHA224

Sebastian Huber sebh at rtems.org
Fri Sep 9 04:43:21 UTC 2022


Module:    rtems
Branch:    master
Commit:    bea7e5a0ff8d46c258c708752b34a2510ee4d369
Changeset: http://git.rtems.org/rtems/commit/?id=bea7e5a0ff8d46c258c708752b34a2510ee4d369

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Sep  8 14:08:03 2022 +0200

libtests/sha: Add tests for SHA224

---

 testsuites/libtests/sha/init.c | 58 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 54 insertions(+), 4 deletions(-)

diff --git a/testsuites/libtests/sha/init.c b/testsuites/libtests/sha/init.c
index c65517253a..49cc17db44 100644
--- a/testsuites/libtests/sha/init.c
+++ b/testsuites/libtests/sha/init.c
@@ -29,6 +29,7 @@
 #include "config.h"
 #endif
 
+#include <sha224.h>
 #include <sha256.h>
 #include <sha512.h>
 #include <stdio.h>
@@ -49,7 +50,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 +100,7 @@ test_sha256_results[RTEMS_ARRAY_SIZE(test_vectors)][32] = {
 };
 
 static const unsigned char
-test_sha512_results[RTEMS_ARRAY_SIZE(test_vectors)][64] = {
+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,
@@ -133,6 +159,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 +190,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);
@@ -164,7 +213,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);
@@ -183,6 +232,7 @@ static void Init(rtems_task_argument arg)
 {
   TEST_BEGIN();
 
+  test_sha224();
   test_sha256();
   test_sha512();
   rtems_stack_checker_report_usage();



More information about the vc mailing list