aboutsummaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
Diffstat (limited to 'sw')
-rw-r--r--sw/modexp_tester.c123
1 files changed, 92 insertions, 31 deletions
diff --git a/sw/modexp_tester.c b/sw/modexp_tester.c
index 26249d1..2389640 100644
--- a/sw/modexp_tester.c
+++ b/sw/modexp_tester.c
@@ -305,7 +305,7 @@ uint8_t testrunner(uint32_t exp_len, uint32_t *exponent,
for (i = 0 ; i < mod_len ; i++) {
result = tc_r32(MODEXP_RESULT_DATA);
if (result != expected[i]) {
- printf("TC1: Error. Expected 0x%08x, got 0x%08x\n", expected[i], result);
+ printf("Error. Expected 0x%08x, got 0x%08x\n", expected[i], result);
correct = 0;
}
}
@@ -325,16 +325,16 @@ uint8_t testrunner(uint32_t exp_len, uint32_t *exponent,
//------------------------------------------------------------------
static void tc1()
{
- uint32_t exponent[1] = {0x00000007};
- uint32_t modulus[1] = {0x0000000b};
- uint32_t message[1] = {0x00000003};
- uint32_t expected[1] = {0x00000009};
+ uint32_t exponent[] = {0x00000007};
+ uint32_t modulus[] = {0x0000000b};
+ uint32_t message[] = {0x00000003};
+ uint32_t expected[] = {0x00000009};
uint8_t result;
printf("Running TC1: 0x03 ** 0x07 mod 0x0b = 0x09\n");
- result = testrunner(1, &exponent[0], 1, &modulus[0],
- &message[0], &expected[0]);
+ result = testrunner(1, exponent, 1, modulus, message, expected);
+
if (result)
printf("TC1: OK\n");
else
@@ -353,16 +353,17 @@ static void tc1()
//------------------------------------------------------------------
static void tc2()
{
- uint32_t exponent[1] = {0x000000fb};
- uint32_t modulus[1] = {0x00000101};
- uint32_t message[1] = {0x000000fb};
- uint32_t expected[1] = {0x000000b7};
+ uint32_t exponent[] = {0x000000fb};
+ uint32_t modulus[] = {0x00000101};
+ uint32_t message[] = {0x000000fb};
+ uint32_t expected[] = {0x000000b7};
uint8_t result;
printf("Running TC2: 0xfb ** 0xfb mod 0x101 = 0xb7\n");
- result = testrunner(1, &exponent[0], 1, &modulus[0],
- &message[0], &expected[0]);
+
+ result = testrunner(1, exponent, 1, modulus, message, expected);
+
if (result)
printf("TC2: OK\n");
else
@@ -381,16 +382,16 @@ static void tc2()
//------------------------------------------------------------------
static void tc3()
{
- uint32_t exponent[1] = {0x00000041};
- uint32_t modulus[1] = {0x00000087};
- uint32_t message[1] = {0x00000081};
- uint32_t expected[1] = {0x00000036};
+ uint32_t exponent[] = {0x00000041};
+ uint32_t modulus[] = {0x00000087};
+ uint32_t message[] = {0x00000081};
+ uint32_t expected[] = {0x00000036};
uint8_t result;
printf("Running TC3: 0x81 ** 0x41 mod 0x87 = 0x36\n");
- result = testrunner(1, &exponent[0], 1, &modulus[0],
- &message[0], &expected[0]);
+ result = testrunner(1, exponent, 1, modulus, message, expected);
+
if (result)
printf("TC3: OK\n");
else
@@ -411,16 +412,16 @@ static void tc3()
//------------------------------------------------------------------
static void tc4()
{
- uint32_t exponent[2] = {0x00000001, 0x0e85e74f};
- uint32_t modulus[2] = {0x00000001, 0x70754797};
- uint32_t message[2] = {0x00000001, 0x946473e1};
- uint32_t expected[2] = {0x00000000, 0x7761ed4f};
+ uint32_t exponent[] = {0x00000001, 0x0e85e74f};
+ uint32_t modulus[] = {0x00000001, 0x70754797};
+ uint32_t message[] = {0x00000001, 0x946473e1};
+ uint32_t expected[] = {0x00000000, 0x7761ed4f};
uint8_t result;
printf("Running TC4: 0x00000001946473e1 ** 0xh000000010e85e74f mod 0x0000000170754797 = 0x000000007761ed4f\n");
- result = testrunner(2, &exponent[0], 2, &modulus[0],
- &message[0], &expected[0]);
+ result = testrunner(2, exponent, 2, modulus, message, expected);
+
if (result)
printf("TC4: OK\n");
else
@@ -435,16 +436,16 @@ static void tc4()
//------------------------------------------------------------------
static void tc5()
{
- 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};
+ uint32_t exponent[] = {0x3285c343, 0x2acbcb0f, 0x4d023228, 0x2ecc73db};
+ uint32_t modulus[] = {0x267d2f2e, 0x51c216a7, 0xda752ead, 0x48d22d89};
+ uint32_t message[] = {0x29462882, 0x12caa2d5, 0xb80e1c66, 0x1006807f};
+ uint32_t expected[] = {0x0ddc404d, 0x91600596, 0x7425a8d8, 0xa066ca56};
uint8_t result;
printf("Running TC5: 128 bit operands\n");
- result = testrunner(4, &exponent[0], 4, &modulus[0],
- &message[0], &expected[0]);
+ result = testrunner(4, exponent, 4, modulus, message, expected);
+
if (result)
printf("TC5: OK\n");
else
@@ -453,6 +454,64 @@ static void tc5()
//------------------------------------------------------------------
+// tc6()
+//
+// e = 65537 and message, modulus are 64 bit oprerands.
+//------------------------------------------------------------------
+static void tc6()
+{
+ uint32_t message[] = {0x00000000, 0xdb5a7e09, 0x86b98bfb};
+
+ uint32_t exponent[] = {0x00000000, 0x00000000, 0x00010001};
+
+ uint32_t modulus[] = {0x00000000, 0xb3164743, 0xe1de267d};
+
+ uint32_t expected[] = {0x00000000, 0x9fc7f328, 0x3ba0ae18};
+ uint8_t result;
+
+ printf("Running TC6: e=65537 and 64 bit operands\n");
+
+ result = testrunner(3, exponent, 3, modulus, message, expected);
+
+ if (result)
+ printf("TC6: OK\n");
+ else
+ printf("TC6: NOT OK\n");
+}
+
+
+//------------------------------------------------------------------
+// tc7()
+//
+// e = 65537 and message, modulus are 256 bit oprerands.
+//------------------------------------------------------------------
+static void tc7()
+{
+ uint32_t message[] = {0x00000000, 0xbd589a51, 0x2ba97013, 0xc4736649, 0xe233fd5c,
+ 0x39fcc5e5, 0x2d60b324, 0x1112f2d0, 0x1177c62b};
+
+ uint32_t exponent[] = {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00010001};
+
+ uint32_t modulus[] = {0x00000000, 0xf169d36e, 0xbe2ce61d, 0xc2e87809, 0x4fed15c3,
+ 0x7c70eac5, 0xa123e643, 0x299b36d2, 0x788e583b};
+
+ uint32_t expected[] = {0x00000000, 0x7c5f0fee, 0x73028fc5, 0xc4fe57c4, 0x91a6f5be,
+ 0x33a5c174, 0x2d2c2bcd, 0xda80e7d6, 0xfb4c889f};
+ uint8_t result;
+
+ printf("Running TC7: e=65537 and 256 bit operands\n");
+
+ result = testrunner(9, exponent, 9, modulus, message, expected);
+
+ if (result)
+ printf("TC7: OK\n");
+ else
+ printf("TC7: NOT OK\n");
+}
+
+
+//------------------------------------------------------------------
// main()
//------------------------------------------------------------------
int main(void)
@@ -469,6 +528,8 @@ int main(void)
tc3();
tc4();
tc5();
+ tc6();
+ tc7();
return 0;
}