You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2021/02/22 09:38:22 UTC

[GitHub] [mynewt-core] utzig commented on a change in pull request #2494: Fix STM32 HASH stream support

utzig commented on a change in pull request #2494:
URL: https://github.com/apache/mynewt-core/pull/2494#discussion_r580104290



##########
File path: apps/hash_test/src/main.c
##########
@@ -275,50 +299,133 @@ run_varlength_sha256_test(struct hash_dev *hash)
         "The crownless again shall be king.",
     };
 
-    uint8_t digest[SHA256_DIGEST_LEN] = "\x83\x6c\x57\x9d\x0c\x13\xec\x71"
-                                        "\x9f\x1d\x38\xf7\x34\xeb\x09\x4f"
-                                        "\x83\x6e\xe9\x06\xc7\xda\x78\x71"
-                                        "\x04\x87\x2b\xcf\x2d\x09\x84\x3d";
+    for (j = 0; j < sizeof varlengths /sizeof varlengths[0]; j++) {
+        varlength = &varlengths[j];
+        printf("%s: ", varlength->name);
+        algo = varlength->algo;
 
-    algo = HASH_ALGO_SHA256;
+        if (!hash_has_support(hash, algo)) {
+            printf("unsupported\n");
+            continue;
+        }
 
-    if (!hash_has_support(hash, algo)) {
-        printf("unsupported\n");
-        return;
-    }
+        rc = hash_custom_start(hash, &ctx, algo);
+        if (rc) {
+            printf("failure\n");
+            continue;
+        }
 
-    rc = hash_custom_start(hash, &ctx, algo);
-    if (rc) {
-        printf("failure\n");
-        return;
-    }
+        printf("\n");
+        for (i = 0; i < sizeof strings / sizeof strings[0]; i++) {
+            string = strings[i];
+            printf("  %s\n", string);
 
-    for (i = 0; i < sizeof strings / sizeof strings[0]; i++) {
-        string = strings[i];
-        printf("  %s: ", string);
+            rc = hash_custom_update(hash, &ctx, algo, string, strlen(string));
+            if (rc) {
+                break;
+            }
+        }
 
-        rc = hash_custom_update(hash, &ctx, algo, string, strlen(string));
         if (rc) {
             printf("failure\n");
-            return;
+            continue;
         } else {
             printf("ok\n");
         }
-    }
 
-    rc = hash_custom_finish(hash, &ctx, algo, outbuf);
-    if (rc) {
-        printf("failure\n");
-        return;
+        rc = hash_custom_finish(hash, &ctx, algo, outbuf);
+        if (rc) {
+            printf("failure\n");
+            break;
+        }
+
+        printf("DIGEST: ");
+        if (memcmp(outbuf, varlength->digest, varlength->digestlen) == 0) {
+            printf("valid\n");
+        } else {
+            printf("invalid\n");
+        }
     }
+}
+
+static struct stream_data bytewrites[] = {
+    {
+        .name = "SHA-224",
+        .algo = HASH_ALGO_SHA224,
+        .digestlen = SHA224_DIGEST_LEN,
+        .digest = "\x13\xb3\x1a\xd9\x15\xd8\x44\x69"
+                  "\x51\x9f\xad\xba\xd4\xa2\xc8\x52"
+                  "\xb5\x29\x18\xaa\xd5\xdb\xa3\x5f"
+                  "\x91\xbb\x62\xe1",
+    },
+    {
+        .name = "SHA-256",
+        .algo = HASH_ALGO_SHA256,
+        .digestlen = SHA256_DIGEST_LEN,
+        .digest = "\xe8\xd9\x5c\xc2\xb4\xbc\x19\x8c"
+                  "\x54\xb4\x0b\xd2\x14\xdf\x95\x8a"
+                  "\xfb\x65\xf5\xe7\x3d\x2c\x2e\xaf"
+                  "\xe0\x59\x3c\xf5\xc6\x35\xc1\xf0",
+    },
+};
+
+void
+run_bytewrite_test(struct hash_dev *hash)
+{
+    struct hash_generic_context ctx;
+    int i, j;
+    int rc;
+    uint8_t outbuf[HASH_MAX_DIGEST_LEN];
+    struct stream_data *bytewrite;
+    uint16_t algo;
+
+    char byte = 'a';
+
+    for (j = 0; j < sizeof bytewrites /sizeof bytewrites[0]; j++) {

Review comment:
       Fixed.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org