[Cryptech-Commits] [core/platform/novena] 01/01: Added support in tc7 for dumping raw data to std out.

git at cryptech.is git at cryptech.is
Thu Apr 2 10:46:23 UTC 2015


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

joachim at secworks.se pushed a commit to branch master
in repository core/platform/novena.

commit aea9e93e560b1468bf0ff2cf5b61e5409ce60dc5
Author: Joachim Strömbergson <joachim at secworks.se>
Date:   Thu Apr 2 12:46:17 2015 +0200

    Added support in tc7 for dumping raw data to std out.
---
 eim/sw/trng_tester_eim.c | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/eim/sw/trng_tester_eim.c b/eim/sw/trng_tester_eim.c
index f60aeec..0cb9312 100644
--- a/eim/sw/trng_tester_eim.c
+++ b/eim/sw/trng_tester_eim.c
@@ -55,6 +55,7 @@
 int debug = 0;
 int quiet = 0;
 int repeat = 0;
+int dump_data = 1;
 int num_words = 10;
 
 /* ---------------- sanity test case ---------------- */
@@ -230,32 +231,50 @@ int TC6(void)
 /* TC7: Read random data from trng_csprng. */
 int TC7(void)
 {
-    int i, n;
-    unsigned long random;
+    int i;
+#ifdef WAIT_STATS
+    int n;
+#endif
+    uint32_t random;
 
     if (!quiet)
         printf("TC7: Read random data from trng_csprng.\n");
 
     for (i = 0; i < num_words; ++i) {
         /* check status */
-	n = 0;
-        if (tc_wait(CSPRNG_ADDR_STATUS, CSPRNG_STATUS_VALID, &n) != 0)
+#ifdef WAIT_STATS
+        if ((n = tc_wait(CSPRNG_ADDR_STATUS, CSPRNG_STATUS_VALID)) < 0)
+#else
+        if (tc_wait(CSPRNG_ADDR_STATUS, CSPRNG_STATUS_VALID) != 0)
+#endif
             return 1;
         /* read random data */
         if (tc_read(CSPRNG_ADDR_RANDOM, (uint8_t *)&random, 4) != 0)
             return 1;
         /* display random data */
-        if (!debug)
+        if (!debug) {
+	  if (dump_data) {
+	    // Raw data output to std out.
+	    printf("%c%c%c%c", (int8_t)(random >> 24 & 0xff),
+				(int8_t)(random >> 16 & 0xff),
+				(int8_t)(random >> 8 & 0xff),
+		   (int8_t)(random & 0xff));
+	  }
+	  else
+	    {
 #ifdef WAIT_STATS
-            printf("%08lx %d\n", random, n);
+            printf("0x%08x %d\n", random, n);
 #else
-            printf("%08lx\n", random);
+            printf("0x%08x\n", random);
 #endif
+	    }
+	}
     }
 
     return 0;
 }
 
+
 /* ---------------- main ---------------- */
 
 /* signal handler for ctrl-c to end repeat testing */



More information about the Commits mailing list