aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoachim StroĢˆmbergson <joachim@secworks.se>2015-05-24 22:35:53 +0200
committerJoachim StroĢˆmbergson <joachim@secworks.se>2015-05-24 22:35:53 +0200
commitffa12c3d3dc9d4d7b16d02562486b99bcbbace8e (patch)
tree28dd9c50df5e5db7a3067282565e0812fcaab24b
parent55441ea7a30bedcf532bc8e0abd3b19ad9c3dfff (diff)
Changed all tests to use the testrunner.
-rw-r--r--sw/modexp_tester.c158
1 files changed, 38 insertions, 120 deletions
diff --git a/sw/modexp_tester.c b/sw/modexp_tester.c
index de6168d..023bc67 100644
--- a/sw/modexp_tester.c
+++ b/sw/modexp_tester.c
@@ -352,39 +352,20 @@ static void tc1()
//------------------------------------------------------------------
static void tc2()
{
- uint32_t result;
+ uint32_t exponent[1] = {0x000000fb};
+ uint32_t modulus[1] = {0x00000101};
+ uint32_t message[1] = {0x000000fb};
+ uint32_t expected[1] = {0x000000b7};
+ uint8_t result;
printf("Running TC2: 0xfb ** 0xfb mod 0x101 = 0xb7\n");
- // Write operands and set associated lengths.
- tc_w32(MODEXP_MESSAGE_PTR_RST, 0x00000000);
- 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);
- if (result == 0x000000b7)
+ result = testrunner(1, &exponent[0], 1, &modulus[0],
+ &message[0], &expected[0]);
+ if (result)
printf("TC2: OK\n");
else
- printf("TC2: Error. Expected 0x000000b7, got 0x%08x\n", result);
+ printf("TC2: NOT OK\n");
}
@@ -399,34 +380,20 @@ static void tc2()
//------------------------------------------------------------------
static void tc3()
{
- uint32_t result;
+ uint32_t exponent[1] = {0x00000041};
+ uint32_t modulus[1] = {0x00000087};
+ uint32_t message[1] = {0x00000081};
+ uint32_t expected[1] = {0x00000036};
+ uint8_t result;
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);
- if (result == 0x00000036)
+ result = testrunner(1, &exponent[0], 1, &modulus[0],
+ &message[0], &expected[0]);
+ if (result)
printf("TC3: OK\n");
else
- printf("TC3: Error. Expected 0x00000036, got 0x%08x\n", result);
+ printf("TC3: NOT OK\n");
}
@@ -443,42 +410,20 @@ static void tc3()
//------------------------------------------------------------------
static void tc4()
{
- uint32_t result0, result1;
- uint32_t ready = 0;
+ uint32_t exponent[2] = {0x00000001, 0x0e85e74f};
+ uint32_t modulus[2] = {0x00000001, 0x70754797};
+ uint32_t message[2] = {0x00000001, 0x946473e1};
+ uint32_t expected[2] = {0x00000000, 0x7761ed4f};
+ uint8_t result;
printf("Running TC4: 0x00000001946473e1 ** 0xh000000010e85e74f mod 0x0000000170754797 = 0x000000007761ed4f\n");
- // Write operands and set associated lengths.
- tc_w32(MODEXP_MESSAGE_PTR_RST, 0x00000000);
- 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);
- tc_w32(MODEXP_EXPONENT_LENGTH, 0x00000002);
-
- tc_w32(MODEXP_MODULUS_PTR_RST, 0x00000000);
- 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);
-
- while (!ready)
- ready = tc_r32(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);
- if ((result0 == 0x00000000) && (result1 == 0x7761ed4f))
+ result = testrunner(2, &exponent[0], 2, &modulus[0],
+ &message[0], &expected[0]);
+ if (result)
printf("TC4: OK\n");
else
- printf("TC4: Error. Expected 0x000000007761ed4f, got 0x%08x%08x\n",
- result0, result1);
+ printf("TC4: NOT OK\n");
}
@@ -489,48 +434,20 @@ static void tc4()
//------------------------------------------------------------------
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);
+ uint32_t exponent[4] = {0x3285c343, 0x2acbcb0f, 0x4d023228, 0x2ecc73db};
+ uint32_t modulus[4] = {0x267d2f2e, 0x51c216a7, 0xda752ead, 0x48d22d89};
+ uint32_t message[4] = {0x29462882, 0x12caa2d5, 0xb80e1c66, 0x1006807f};
+ uint32_t expected[4] = {0x0ddc404d, 0x91600596, 0x7425a8d8, 0xa066ca56};
+ uint8_t result;
- // Start processing and wait for ready.
- tc_w32(MODEXP_ADDR_CTRL, 0x00000001);
- check(tc_wait_ready(MODEXP_ADDR_STATUS));
+ printf("Running TC5: 128 bit operands\n");
- // 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))
+ result = testrunner(4, &exponent[0], 4, &modulus[0],
+ &message[0], &expected[0]);
+ if (result)
printf("TC5: OK\n");
else
- printf("TC5: Error. Expected 0x0ddc404d 0x91600596 0x7425a8d8 0xa066ca56, got 0x%08x %08x0x %08x %08x\n",
- result0, result1, result2, result3);
+ printf("TC5: NOT OK\n");
}
@@ -550,6 +467,7 @@ int main(void)
tc2();
tc3();
tc4();
+ tc5();
return 0;
}