[Cryptech-Commits] [core/platform/novena] 01/01: Adding a bigger testcase with 128 bit operands for modexp_tester. Increasing limit for ready and valid.

git at cryptech.is git at cryptech.is
Wed May 20 14:40:57 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 e858d01d5a6a455ff99b38c71447f001bb285e87
Author: Joachim Strömbergson <joachim at secworks.se>
Date:   Wed May 20 16:40:46 2015 +0200

    Adding a bigger testcase with 128 bit operands for modexp_tester. Increasing limit for ready and valid.
---
 sw/modexp_tester.c | 105 ++++++++++++++++++++++++++++++++++++++++-------------
 sw/tc_eim.c        |   4 +-
 2 files changed, 81 insertions(+), 28 deletions(-)

diff --git a/sw/modexp_tester.c b/sw/modexp_tester.c
index 21bebbd..e07f147 100644
--- a/sw/modexp_tester.c
+++ b/sw/modexp_tester.c
@@ -121,13 +121,13 @@ static void check_modulus_mem(void)
 {
   uint8_t i;
   uint32_t j;
-
+  
   printf("Testing modulus mem access.\n");
 
   tc_w32(MODEXP_MODULUS_PTR_RST, 0x00000000);
   // Write test data to modulus mempory.
   for (i = 0 ; i < 64; i = i + 1) {
-    j = ((i * 4 + 3) << 24) + ((i * 4 + 2) << 16) +
+    j = ((i * 4 + 3) << 24) + ((i * 4 + 2) << 16) + 
       ((i * 4 + 1) << 8) + i * 4;
     tc_w32(MODEXP_MODULUS_DATA, j);
   }
@@ -153,13 +153,13 @@ static void check_exponent_mem(void)
 {
   uint8_t i;
   uint32_t j;
-
+  
   printf("Testing exponent mem access.\n");
 
   tc_w32(MODEXP_EXPONENT_PTR_RST, 0x00000000);
   // Write test data to exponent memory.
   for (i = 0 ; i < 64; i = i + 1) {
-    j = ((i * 4 + 3) << 24) + ((i * 4 + 2) << 16) +
+    j = ((i * 4 + 3) << 24) + ((i * 4 + 2) << 16) + 
       ((i * 4 + 1) << 8) + i * 4;
     tc_w32(MODEXP_EXPONENT_DATA, j);
   }
@@ -186,13 +186,13 @@ static void check_message_mem(void)
 {
   uint8_t i;
   uint32_t j;
-
+  
   printf("Testing message mem access.\n");
 
   tc_w32(MODEXP_MESSAGE_PTR_RST, 0x00000000);
   // Write test data to message memory.
   for (i = 0 ; i < 64; i = i + 1) {
-    j = ((i * 4 + 3) << 24) + ((i * 4 + 2) << 16) +
+    j = ((i * 4 + 3) << 24) + ((i * 4 + 2) << 16) + 
       ((i * 4 + 1) << 8) + i * 4;
     tc_w32(MODEXP_MESSAGE_DATA, j);
   }
@@ -226,7 +226,7 @@ static void clear_mems()
     tc_w32(MODEXP_EXPONENT_DATA, 0x00000000);
     tc_w32(MODEXP_MODULUS_DATA,  0x00000000);
   }
-
+  
   tc_w32(MODEXP_MESSAGE_PTR_RST,  0x00000000);
   tc_w32(MODEXP_EXPONENT_PTR_RST, 0x00000000);
   tc_w32(MODEXP_MODULUS_PTR_RST,  0x00000000);
@@ -263,7 +263,7 @@ static void dump_mems()
   printf("0x%08x 0x%08x 0x%08x 0x%08x\n",
 	 tc_r32(MODEXP_RESULT_DATA), tc_r32(MODEXP_RESULT_DATA),
 	 tc_r32(MODEXP_RESULT_DATA), tc_r32(MODEXP_RESULT_DATA));
-
+  
   tc_w32(MODEXP_MESSAGE_PTR_RST, 0x00000000);
   tc_w32(MODEXP_EXPONENT_PTR_RST, 0x00000000);
   tc_w32(MODEXP_MODULUS_PTR_RST, 0x00000000);
@@ -290,15 +290,15 @@ static void tc1()
   tc_w32(MODEXP_MESSAGE_PTR_RST, 0x00000000);
   tc_w32(MODEXP_MESSAGE_DATA, 0x00000003);
   tc_w32(MODEXP_LENGTH, 0x00000001);
-
+  
   tc_w32(MODEXP_EXPONENT_PTR_RST, 0x00000000);
   tc_w32(MODEXP_EXPONENT_DATA, 0x00000007);
   tc_w32(MODEXP_EXPONENT_LENGTH, 0x00000001);
-
+  
   tc_w32(MODEXP_MODULUS_PTR_RST, 0x00000000);
   tc_w32(MODEXP_MODULUS_DATA, 0x0000000b);
   tc_w32(MODEXP_MODULUS_LENGTH, 0x00000001);
-
+  
   // Start processing and wait for ready.
   tc_w32(MODEXP_ADDR_CTRL, 0x00000001);
   check(tc_wait_ready(MODEXP_ADDR_STATUS));
@@ -333,23 +333,23 @@ static void tc2()
   tc_w32(MODEXP_MESSAGE_DATA, 0x000000fb);
   tc_w32(MODEXP_MESSAGE_DATA, 0x00000000);
   tc_w32(MODEXP_LENGTH, 0x00000001);
-
+  
   tc_w32(MODEXP_EXPONENT_PTR_RST, 0x00000000);
   tc_w32(MODEXP_EXPONENT_DATA, 0x000000fb);
   tc_w32(MODEXP_EXPONENT_DATA, 0x00000000);
   tc_w32(MODEXP_EXPONENT_LENGTH, 0x00000001);
-
+  
   tc_w32(MODEXP_MODULUS_PTR_RST, 0x00000000);
   tc_w32(MODEXP_MODULUS_DATA, 0x00000101);
   tc_w32(MODEXP_MODULUS_DATA, 0x00000000);
   tc_w32(MODEXP_MODULUS_LENGTH, 0x00000001);
-
+  
   // Start processing and wait for ready.
   printf("TC2: Starting processing. Waiting for ready...\n");
   tc_w32(MODEXP_ADDR_CTRL, 0x00000001);
   check(tc_wait_ready(MODEXP_ADDR_STATUS));
   printf("TC2: Ready seen.\n");
-
+  
   // Check result with expected value.
   tc_w32(MODEXP_RESULT_PTR_RST, 0x00000000);
   result = tc_r32(MODEXP_RESULT_DATA);
@@ -373,27 +373,25 @@ static void tc3()
 {
   uint32_t result;
 
-  clear_mems();
-
   printf("Running TC3: 0x81 ** 0x41 mod 0x87 = 0x36\n");
 
   // Write operands and set associated lengths.
   tc_w32(MODEXP_MESSAGE_PTR_RST, 0x00000000);
   tc_w32(MODEXP_MESSAGE_DATA, 0x00000081);
   tc_w32(MODEXP_LENGTH, 0x00000001);
-
+  
   tc_w32(MODEXP_EXPONENT_PTR_RST, 0x00000000);
   tc_w32(MODEXP_EXPONENT_DATA, 0x00000041);
   tc_w32(MODEXP_EXPONENT_LENGTH, 0x00000001);
-
+  
   tc_w32(MODEXP_MODULUS_PTR_RST, 0x00000000);
   tc_w32(MODEXP_MODULUS_DATA, 0x00000087);
   tc_w32(MODEXP_MODULUS_LENGTH, 0x00000001);
-
+  
   // Start processing and wait for ready.
   tc_w32(MODEXP_ADDR_CTRL, 0x00000001);
   check(tc_wait_ready(MODEXP_ADDR_STATUS));
-
+  
   // Check result with expected value.
   tc_w32(MODEXP_RESULT_PTR_RST, 0x00000000);
   result = tc_r32(MODEXP_RESULT_DATA);
@@ -418,6 +416,7 @@ static void tc3()
 static void tc4()
 {
   uint32_t result0, result1;
+  uint32_t ready = 0;
 
   printf("Running TC4: 0x00000001946473e1 ** 0xh000000010e85e74f mod 0x0000000170754797 = 0x000000007761ed4f\n");
 
@@ -426,7 +425,7 @@ static void tc4()
   tc_w32(MODEXP_MESSAGE_DATA, 0x00000001);
   tc_w32(MODEXP_MESSAGE_DATA, 0x946473e1);
   tc_w32(MODEXP_LENGTH, 0x00000002);
-
+  
   tc_w32(MODEXP_EXPONENT_PTR_RST, 0x00000000);
   tc_w32(MODEXP_EXPONENT_DATA, 0x00000001);
   tc_w32(MODEXP_EXPONENT_DATA, 0x0e85e74f);
@@ -436,10 +435,12 @@ static void tc4()
   tc_w32(MODEXP_MODULUS_DATA, 0x00000001);
   tc_w32(MODEXP_MODULUS_DATA, 0x70754797);
   tc_w32(MODEXP_MODULUS_LENGTH, 0x00000002);
-
+  
   // Start processing and wait for ready.
   tc_w32(MODEXP_ADDR_CTRL, 0x00000001);
-  check(tc_wait_ready(MODEXP_ADDR_STATUS));
+
+  while (!ready)
+    ready = tc_r32(MODEXP_ADDR_STATUS);
 
   // Check result with expected value.
   tc_w32(MODEXP_RESULT_PTR_RST, 0x00000000);
@@ -448,18 +449,70 @@ static void tc4()
   if ((result0 == 0x00000000) && (result1 == 0x7761ed4f))
     printf("TC4: OK\n");
   else
-    printf("TC4: Error. Expected 0x000000007761ed4f, got 0x%08x%08x\n",
+    printf("TC4: Error. Expected 0x000000007761ed4f, got 0x%08x%08x\n", 
 	   result0, result1);
 }
 
 
 //------------------------------------------------------------------
+// tc5()
+//
+// c = m ** e % N with 128 bit operands.
+//------------------------------------------------------------------
+static void tc5()
+{
+  uint32_t result0, result1, result2, result3;
+
+  printf("Running TC5: 128 bit operands.\n");
+
+  // Write operands and set associated lengths.
+  tc_w32(MODEXP_MESSAGE_PTR_RST, 0x00000000);
+  tc_w32(MODEXP_MESSAGE_DATA, 0x29462882);
+  tc_w32(MODEXP_MESSAGE_DATA, 0x12caa2d5);
+  tc_w32(MODEXP_MESSAGE_DATA, 0xb80e1c66);
+  tc_w32(MODEXP_MESSAGE_DATA, 0x1006807f);
+  
+  tc_w32(MODEXP_EXPONENT_PTR_RST, 0x00000000);
+  tc_w32(MODEXP_EXPONENT_DATA, 0x3285c343);
+  tc_w32(MODEXP_EXPONENT_DATA, 0x2acbcb0f);
+  tc_w32(MODEXP_EXPONENT_DATA, 0x4d023228);
+  tc_w32(MODEXP_EXPONENT_DATA, 0x2ecc73db);
+  
+  tc_w32(MODEXP_MODULUS_PTR_RST, 0x00000000);
+  tc_w32(MODEXP_MODULUS_DATA, 0x267d2f2e);
+  tc_w32(MODEXP_MODULUS_DATA, 0x51c216a7);
+  tc_w32(MODEXP_MODULUS_DATA, 0xda752ead);
+  tc_w32(MODEXP_MODULUS_DATA, 0x48d22d89);
+
+  tc_w32(MODEXP_EXPONENT_LENGTH, 0x00000004);
+  tc_w32(MODEXP_MODULUS_LENGTH, 0x00000004);
+  
+  // Start processing and wait for ready.
+  tc_w32(MODEXP_ADDR_CTRL, 0x00000001);
+  check(tc_wait_ready(MODEXP_ADDR_STATUS));
+
+  // Check result with expected value.
+  tc_w32(MODEXP_RESULT_PTR_RST, 0x00000000);
+  result0 = tc_r32(MODEXP_RESULT_DATA);
+  result1 = tc_r32(MODEXP_RESULT_DATA);
+  result2 = tc_r32(MODEXP_RESULT_DATA);
+  result3 = tc_r32(MODEXP_RESULT_DATA);
+  if ((result0 == 0x0ddc404d) && (result1 == 0x91600596) &&
+      (result2 == 0x7425a8d8) && (result3 == 0xa066ca56))
+    printf("TC5: OK\n");
+  else
+    printf("TC5: Error. Expected 0x0ddc404d 0x91600596 0x7425a8d8 0xa066ca56, got 0x%08x %08x0x %08x %08x\n", 
+	   result0, result1, result2, result3);
+}
+
+
+//------------------------------------------------------------------
 // main()
 //------------------------------------------------------------------
 int main(void)
 {
   check_modexp_access();
-  tc_set_debug(1);
+  //  tc_set_debug(1);
 
 //  check_modulus_mem();
 //  check_exponent_mem();
diff --git a/sw/tc_eim.c b/sw/tc_eim.c
index c812478..8ef4f06 100644
--- a/sw/tc_eim.c
+++ b/sw/tc_eim.c
@@ -197,12 +197,12 @@ int tc_wait(off_t offset, uint8_t status, int *count)
 
 int tc_wait_ready(off_t offset)
 {
-    int limit = 256;
+    int limit = 100000000;
     return tc_wait(offset, STATUS_READY, &limit);
 }
 
 int tc_wait_valid(off_t offset)
 {
-    int limit = 256;
+    int limit = 100000000;
     return tc_wait(offset, STATUS_VALID, &limit);
 }



More information about the Commits mailing list