From 55441ea7a30bedcf532bc8e0abd3b19ad9c3dfff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Sun, 24 May 2015 22:15:41 +0200 Subject: Adding a testrunner function. Changed TC1 to use the testrunner. Automagically cleaned up trailing whitespace. --- sw/modexp_tester.c | 120 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 74 insertions(+), 46 deletions(-) (limited to 'sw') diff --git a/sw/modexp_tester.c b/sw/modexp_tester.c index e07f147..de6168d 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); @@ -271,6 +271,48 @@ static void dump_mems() } +//------------------------------------------------------------------ +// testrunner() +//------------------------------------------------------------------ +uint8_t testrunner(uint32_t exp_len, uint32_t *exponent, + uint32_t mod_len, uint32_t *modulus, + uint32_t *message, uint32_t *expected) +{ + uint32_t i; + uint32_t result; + uint8_t correct; + + tc_w32(MODEXP_EXPONENT_LENGTH, exp_len); + tc_w32(MODEXP_EXPONENT_PTR_RST, 0x00000000); + for (i = 0 ; i < mod_len ; i++) { + tc_w32(MODEXP_EXPONENT_DATA, exponent[i]); + } + + tc_w32(MODEXP_MODULUS_LENGTH, mod_len); + tc_w32(MODEXP_MESSAGE_PTR_RST, 0x00000000); + tc_w32(MODEXP_MODULUS_PTR_RST, 0x00000000); + for (i = 0 ; i < mod_len ; i++) { + tc_w32(MODEXP_MESSAGE_DATA, message[i]); + tc_w32(MODEXP_MODULUS_DATA, modulus[i]); + } + + tc_w32(MODEXP_ADDR_CTRL, 0x00000001); + check(tc_wait_ready(MODEXP_ADDR_STATUS)); + + correct = 1; + + for (i = 0 ; i < mod_len ; i++) { + result = tc_r32(MODEXP_RESULT_DATA); + if (result != expected[i]) { + printf("TC1: Error. Expected 0x00000009, got 0x%08x\n", result); + correct = 0; + } + } + + return correct; +} + + //------------------------------------------------------------------ // tc1() // @@ -282,34 +324,20 @@ static void dump_mems() //------------------------------------------------------------------ static void tc1() { - uint32_t result; + uint32_t exponent[1] = {0x00000007}; + uint32_t modulus[1] = {0x0000000b}; + uint32_t message[1] = {0x00000003}; + uint32_t expected[1] = {0x00000009}; + uint8_t result; printf("Running TC1: 0x03 ** 0x07 mod 0x0b = 0x09\n"); - // Write operands and set associated lengths. - 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)); - - // Check result with expected value. - tc_w32(MODEXP_RESULT_PTR_RST, 0x00000000); - result = tc_r32(MODEXP_RESULT_DATA); - if (result == 0x00000009) + result = testrunner(1, &exponent[0], 1, &modulus[0], + &message[0], &expected[0]); + if (result) printf("TC1: OK\n"); else - printf("TC1: Error. Expected 0x00000009, got 0x%08x\n", result); + printf("TC1: NOT OK\n"); } @@ -333,23 +361,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); @@ -379,19 +407,19 @@ static void tc3() 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); @@ -425,7 +453,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); @@ -435,7 +463,7 @@ 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); @@ -449,7 +477,7 @@ 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); } @@ -471,13 +499,13 @@ static void tc5() 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); @@ -486,7 +514,7 @@ static void tc5() 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)); @@ -501,7 +529,7 @@ static void tc5() (result2 == 0x7425a8d8) && (result3 == 0xa066ca56)) printf("TC5: OK\n"); else - printf("TC5: Error. Expected 0x0ddc404d 0x91600596 0x7425a8d8 0xa066ca56, got 0x%08x %08x0x %08x %08x\n", + printf("TC5: Error. Expected 0x0ddc404d 0x91600596 0x7425a8d8 0xa066ca56, got 0x%08x %08x0x %08x %08x\n", result0, result1, result2, result3); } -- cgit v1.2.3