[Cryptech-Commits] [core/novena_eim] 01/01: display the state of sha1 after round 0

git at cryptech.is git at cryptech.is
Thu Jan 15 00:07:37 UTC 2015


This is an automated email from the git hooks/post-receive script.

paul at psgd.org pushed a commit to branch gothenburg_test
in repository core/novena_eim.

commit 9461104ac8ad6ed678403af80d5c5bfbf5e3ab74
Author: Paul Selkirk <paul at psgd.org>
Date:   Wed Jan 14 19:07:09 2015 -0500

    display the state of sha1 after round 0
---
 src/sw/hash_tester.c | 65 +++++++++++++++++++++++++++++++++-------------------
 1 file changed, 42 insertions(+), 23 deletions(-)

diff --git a/src/sw/hash_tester.c b/src/sw/hash_tester.c
index 191138c..7a35248 100644
--- a/src/sw/hash_tester.c
+++ b/src/sw/hash_tester.c
@@ -87,6 +87,9 @@ int repeat = 0;
 #define SHA1_BLOCK_LEN          512 / 8
 #define SHA1_DIGEST_LEN         160 / 8
 
+#define SHA1_ADDR_ROUND_DEBUG	SHA1_ADDR_BASE + 0xFC
+#define SHA1_ADDR_STATE_DEBUG   SHA1_ADDR_BASE + 0x100
+
 #define SHA256_ADDR_BASE        0x3000
 #define SHA256_ADDR_NAME0       SHA256_ADDR_BASE + ADDR_NAME0
 #define SHA256_ADDR_NAME1       SHA256_ADDR_BASE + ADDR_NAME1
@@ -631,18 +634,26 @@ int TC2(void)
 {
     const uint8_t *block = NIST_512_SINGLE;
     const uint8_t *expected = SHA1_SINGLE_DIGEST;
+    uint8_t round[4] = {0,0,0,1};
+    int ret;
 
     if (!quiet)
 	printf("TC2: Single block message test for SHA-1.\n");
 
-    return
-        /* Write block to SHA-1. */
-        tc_write(SHA1_ADDR_BLOCK, block, SHA1_BLOCK_LEN) ||
-        /* Start initial block hashing, wait and check status. */
-        tc_init(SHA1_ADDR_CTRL) ||
-        tc_wait_valid(SHA1_ADDR_STATUS) ||
-        /* Extract the digest. */
-        tc_expected(SHA1_ADDR_DIGEST, expected, SHA1_DIGEST_LEN);
+    /* Write block to SHA-1. */
+    tc_write(SHA1_ADDR_BLOCK, block, SHA1_BLOCK_LEN);
+    tc_write(SHA1_ADDR_ROUND_DEBUG, round, 4);
+    /* Start initial block hashing, wait and check status. */
+    tc_init(SHA1_ADDR_CTRL);
+    tc_wait_valid(SHA1_ADDR_STATUS);
+    /* Extract the digest. */
+    ret = tc_expected(SHA1_ADDR_DIGEST, expected, SHA1_DIGEST_LEN);
+    if (debug) {
+	uint8_t buf[SHA1_DIGEST_LEN];
+	eim_copy((void *)buf, (void *)(mem_8 + SHA1_ADDR_STATE_DEBUG), SHA1_DIGEST_LEN);
+	dump("state ", buf, SHA1_DIGEST_LEN);
+    }
+    return ret;
 }
 
 /* TC3: SHA-1 Double block message test as specified by NIST. */
@@ -654,25 +665,33 @@ int TC3(void)
           0x04, 0x08, 0xF5, 0x81, 0x84, 0x67, 0x71, 0x48,
           0x4A, 0x56, 0x65, 0x72 };
     const uint8_t *expected = SHA1_DOUBLE_DIGEST;
+    uint8_t round[4] = {0,0,0,1};
+    int ret;
 
     if (!quiet)
 	printf("TC3: Double block message test for SHA-1.\n");
 
-    return
-        /* Write first block to SHA-1. */
-        tc_write(SHA1_ADDR_BLOCK, block[0], SHA1_BLOCK_LEN) ||
-        /* Start initial block hashing, wait and check status. */
-        tc_init(SHA1_ADDR_CTRL) ||
-        tc_wait_valid(SHA1_ADDR_STATUS) ||
-        /* Extract the first digest. */
-        tc_expected(SHA1_ADDR_DIGEST, block0_expected, SHA1_DIGEST_LEN) ||
-        /* Write second block to SHA-1. */
-        tc_write(SHA1_ADDR_BLOCK, block[1], SHA1_BLOCK_LEN) ||
-        /* Start next block hashing, wait and check status. */
-        tc_next(SHA1_ADDR_CTRL) ||
-        tc_wait_valid(SHA1_ADDR_STATUS) ||
-        /* Extract the second digest. */
-        tc_expected(SHA1_ADDR_DIGEST, expected, SHA1_DIGEST_LEN);
+    /* Write first block to SHA-1. */
+    tc_write(SHA1_ADDR_BLOCK, block[0], SHA1_BLOCK_LEN);
+    tc_write(SHA1_ADDR_ROUND_DEBUG, round, 4);
+    /* Start initial block hashing, wait and check status. */
+    tc_init(SHA1_ADDR_CTRL);
+    tc_wait_valid(SHA1_ADDR_STATUS);
+    /* Extract the first digest. */
+    tc_expected(SHA1_ADDR_DIGEST, block0_expected, SHA1_DIGEST_LEN);
+    /* Write second block to SHA-1. */
+    tc_write(SHA1_ADDR_BLOCK, block[1], SHA1_BLOCK_LEN);
+    /* Start next block hashing, wait and check status. */
+    tc_next(SHA1_ADDR_CTRL);
+    tc_wait_valid(SHA1_ADDR_STATUS);
+    /* Extract the second digest. */
+    ret = tc_expected(SHA1_ADDR_DIGEST, expected, SHA1_DIGEST_LEN);
+    if (debug) {
+	uint8_t buf[SHA1_DIGEST_LEN];
+	eim_copy((void *)buf, (void *)(mem_8 + SHA1_ADDR_STATE_DEBUG), SHA1_DIGEST_LEN);
+	dump("state ", buf, SHA1_DIGEST_LEN);
+    }
+    return ret;
 }
 
 /* ---------------- SHA-256 test cases ---------------- */



More information about the Commits mailing list