Hi, Eugene,
In the SDK package for LPC55S69, there is CASPER examples, which includes the RSA example and ECC examples. I copy the screenshot for loading the casper examples in SDK package. there is 256 bits and 384 bits ECC examples.
Hope it can help you
this is part of the code:
/* Begin code to test elliptic curve scalar multiplication. */
{
int i;
int m1, m2;
int errors = 0;
for (i = 0; i < 8; i++)
{
PRINTF("Round: %d\r\n", i);
uint32_t X1[8], Y1[8];
uint32_t *X3 = &test_ecmulans[i][0];
uint32_t *Y3 = &test_ecmulans[i][8];
CASPER_ECC_SECP256R1_Mul(CASPER, X1, Y1, &test_ecmulans[0][0], &test_ecmulans[0][8], test_ecmulscalar[i]);
CASPER_ECC_equal(&m1, X1, X3);
CASPER_ECC_equal(&m2, Y1, Y3);
if (m1 != 0 || m2 != 0)
{
errors++;
}
}
if (errors != 0)
{
PRINTF("Not all EC scalar multipication tests were succesfull.\r\n");
PRINTF("%d / 8 tests failed.\n", errors);
}
else
{
PRINTF("All EC scalar multiplication tests were succesfull.\r\n");
}
}
/* End code to test elliptic curve scalar multiplication. */
/* Begin code to test elliptic curve double scalar multiplication. */
{
int i;
int m1, m2;
int errors = 0;
uint32_t c3[NUM_LIMBS], c4[NUM_LIMBS];
for (i = 0; i < 8; i++)
{
PRINTF("Round: %d\r\n", i);
uint32_t *c1 = &test_ecddoublemul_result[i][0];
uint32_t *c2 = &test_ecddoublemul_result[i][NUM_LIMBS];
CASPER_ECC_SECP256R1_MulAdd(CASPER, c3, c4, &test_ecddoublemul_base[0][0],
&test_ecddoublemul_base[0][NUM_LIMBS], &test_ecddoublemul_scalars[i][0],
&test_ecddoublemul_base[1][0], &test_ecddoublemul_base[1][NUM_LIMBS],
&test_ecddoublemul_scalars[i][NUM_LIMBS]);
CASPER_ECC_equal(&m1, c1, c3);
CASPER_ECC_equal(&m2, c2, c4);
if (m1 != 0 || m2 != 0)
{
errors++;
}
}
if (errors != 0)
{
PRINTF("Not all EC double scalar multipication tests were succesfull.\r\n");
PRINTF("%d / 8 tests failed.\n", errors);
}
else
{
PRINTF("All EC double scalar multiplication tests were succesfull.\r\n");
}
}
/* End code to test elliptic curve double scalar multiplication. */
#elif CASPER_ECC_P384
PRINTF("Casper ECC Demo P384\r\n\r\n");
/* Begin code to test elliptic curve scalar multiplication. */
{
int i;
int m1, m2;
int errors = 0;
for (i = 0; i < 8; i++)
{
PRINTF("Round: %d\r\n", i);
uint32_t X1[12], Y1[12];
uint32_t *X3 = &test_ecmulans[i][0];
uint32_t *Y3 = &test_ecmulans[i][12];
CASPER_ECC_SECP384R1_Mul(CASPER, X1, Y1, &test_ecmulans[0][0], &test_ecmulans[0][12], test_ecmulscalar[i]);
CASPER_ECC_equal(&m1, X1, X3);
CASPER_ECC_equal(&m2, Y1, Y3);
if (m1 != 0 || m2 != 0)
{
errors++;
}
}
if (errors != 0)
{
PRINTF("Not all EC scalar multipication tests were succesfull.\r\n");
PRINTF("%d / 8 tests failed.\r\n", errors);
}
else
{
PRINTF("All EC scalar multiplication tests were succesfull.\r\n");
}
}
/* End code to test elliptic curve scalar multiplication. */
/* Begin code to test elliptic curve double scalar multiplication. */
{
int i;
int m1, m2;
int errors = 0;
uint32_t c3[NUM_LIMBS], c4[NUM_LIMBS];
for (i = 0; i < 8; i++)
{
PRINTF("Round: %d\r\n", i);
uint32_t *c1 = &test_ecddoublemul_result[i][0];
uint32_t *c2 = &test_ecddoublemul_result[i][NUM_LIMBS];
CASPER_ECC_SECP384R1_MulAdd(CASPER, c3, c4, &test_ecddoublemul_base[0][0],
&test_ecddoublemul_base[0][NUM_LIMBS], &test_ecddoublemul_scalars[i][0],
&test_ecddoublemul_base[1][0], &test_ecddoublemul_base[1][NUM_LIMBS],
&test_ecddoublemul_scalars[i][NUM_LIMBS]);
CASPER_ECC_equal(&m1, c3, c1);
CASPER_ECC_equal(&m2, c4, c2);
if (m1 != 0 || m2 != 0)
{
errors++;
}
}
if (errors != 0)
{
PRINTF("Not all EC double scalar multipication tests were succesfull.\r\n");
PRINTF("%d / 128 tests failed.\r\n", errors);
}
else
{
PRINTF("All EC double scalar multiplication tests were succesfull.\r\n");
}
}
/* End code to test elliptic curve scalar multiplication. */
#endif
/* Deinitialize CASPER */
CASPER_Deinit(CASPER);
while (1)
{
}
}
