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/20 14:29:44 UTC

[GitHub] [mynewt-core] utzig opened a new pull request #2494: Fix STM32 HASH stream support

utzig opened a new pull request #2494:
URL: https://github.com/apache/mynewt-core/pull/2494


   apps: hash_test: add single byte multi-write test - Expand string stream test to also run on SHA-224 (when available). Add new single byte multi-write test, where a single "a" is written 256 times, running on both SHA-224 and SHA-256 (where available).
   
   hw: drivers: hash_stm32: fix stream support - The STM32 HASH HW is configured to work on a word (32-bit) write, and the only write that can be less than 4-bytes is the last write (_finish()). To be compatible with streams that are non word-boundary sized, a new pad (aka state) was added that caches writes that are less than 4 byte, so only words are ever written in an _update(), and _finish() flushes the remaining bytes that were less than 4-bytes.


----------------------------------------------------------------
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



[GitHub] [mynewt-core] apache-mynewt-bot removed a comment on pull request #2494: Fix STM32 HASH stream support

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot removed a comment on pull request #2494:
URL: https://github.com/apache/mynewt-core/pull/2494#issuecomment-782691098


   
   <!-- style-bot -->
   
   ## Style check summary
   
   #### No suggestions at this time!
   


----------------------------------------------------------------
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



[GitHub] [mynewt-core] apache-mynewt-bot removed a comment on pull request #2494: Fix STM32 HASH stream support

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot removed a comment on pull request #2494:
URL: https://github.com/apache/mynewt-core/pull/2494#issuecomment-782690314


   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### hw/drivers/hash/hash_stm32/src/hash_stm32.c
   <details>
   
   ```diff
   @@ -70,7 +70,7 @@
    
    static int
    stm32_hash_update(struct hash_dev *hash, void *ctx, uint16_t algo,
   -        const void *inbuf, uint32_t inlen)
   +                  const void *inbuf, uint32_t inlen)
    {
        uint32_t *u32p;
        uint8_t *u8p;
   ```
   
   </details>


----------------------------------------------------------------
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



[GitHub] [mynewt-core] apache-mynewt-bot commented on pull request #2494: Fix STM32 HASH stream support

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot commented on pull request #2494:
URL: https://github.com/apache/mynewt-core/pull/2494#issuecomment-782690314


   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### hw/drivers/hash/hash_stm32/src/hash_stm32.c
   <details>
   
   ```diff
   @@ -70,7 +70,7 @@
    
    static int
    stm32_hash_update(struct hash_dev *hash, void *ctx, uint16_t algo,
   -        const void *inbuf, uint32_t inlen)
   +                  const void *inbuf, uint32_t inlen)
    {
        uint32_t *u32p;
        uint8_t *u8p;
   ```
   
   </details>


----------------------------------------------------------------
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



[GitHub] [mynewt-core] apache-mynewt-bot commented on pull request #2494: Fix STM32 HASH stream support

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot commented on pull request #2494:
URL: https://github.com/apache/mynewt-core/pull/2494#issuecomment-782733316


   
   <!-- style-bot -->
   
   ## Style check summary
   
   #### No suggestions at this time!
   


----------------------------------------------------------------
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



[GitHub] [mynewt-core] apache-mynewt-bot commented on pull request #2494: Fix STM32 HASH stream support

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot commented on pull request #2494:
URL: https://github.com/apache/mynewt-core/pull/2494#issuecomment-782691098


   
   <!-- style-bot -->
   
   ## Style check summary
   
   #### No suggestions at this time!
   


----------------------------------------------------------------
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



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

Posted by GitBox <gi...@apache.org>.
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



[GitHub] [mynewt-core] utzig merged pull request #2494: Fix STM32 HASH stream support

Posted by GitBox <gi...@apache.org>.
utzig merged pull request #2494:
URL: https://github.com/apache/mynewt-core/pull/2494


   


----------------------------------------------------------------
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



[GitHub] [mynewt-core] apache-mynewt-bot commented on pull request #2494: Fix STM32 HASH stream support

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot commented on pull request #2494:
URL: https://github.com/apache/mynewt-core/pull/2494#issuecomment-783239148


   
   <!-- style-bot -->
   
   ## Style check summary
   
   #### No suggestions at this time!
   


----------------------------------------------------------------
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



[GitHub] [mynewt-core] apache-mynewt-bot removed a comment on pull request #2494: Fix STM32 HASH stream support

Posted by GitBox <gi...@apache.org>.
apache-mynewt-bot removed a comment on pull request #2494:
URL: https://github.com/apache/mynewt-core/pull/2494#issuecomment-782733316


   
   <!-- style-bot -->
   
   ## Style check summary
   
   #### No suggestions at this time!
   


----------------------------------------------------------------
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



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

Posted by GitBox <gi...@apache.org>.
kasjer commented on a change in pull request #2494:
URL: https://github.com/apache/mynewt-core/pull/2494#discussion_r580049699



##########
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:
       missing space after /, which should be detected by style check
   os/kernel/util.h has ARRAY_SIZE which could be used




----------------------------------------------------------------
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