I am trying to figure out if the below code is expected to execute within the time I'm measuring or if I have something set up wrong and it's making it very slow. This code is part of a function that generates a Public Key from given private key using kCASPER_ECC_P256.
The below code uses a GPIO toggle to measure execution time. Between the Set and Clear GPIO calls, it takes 337mS. Which seems slow for hardware accelerated math for this operation. Is this expected? My MCU has a core clock of 148MHz. Is there a way to choose the clock source for the CASPER engine to speed this up?
/* Base Generator Point G(x, y) for secp256r1 in 32-bit Little-Endian word arrays */
static const uint32_t G_x_le[8] = {
0xD898C296, 0xF4A13945, 0x2DEB33A0, 0x77037D81,
0x63A440F2, 0xF8BCE6E5, 0xE12C4247, 0x6B17D1F2
};
static const uint32_t G_y_le[8] = {
0x37BF51F5, 0xCBB64068, 0x6B315ECE, 0x2BCE3357,
0x7C0F9E16, 0x8EE7EB4A, 0xFE1A7F9B, 0x4FE342E2
};
uint32_t scalar_le[8];
uint32_t Q_x_le[8];
uint32_t Q_y_le[8];
/* Copy Big-Endian private scalar and convert to Little-Endian for CASPER */
memcpy(scalar_le, key_buffer, 32);
swap_endian_32((uint8_t *)scalar_le);
/* 1. Initialize CASPER coprocessor */
CASPER_Init(CASPER);
CASPER_ecc_init(kCASPER_ECC_P256);
HW_DB_PinSet();
/* 2. Compute Q = d * G using CASPER hardware */
CASPER_ECC_SECP256R1_Mul(
CASPER,
Q_x_le, Q_y_le,
G_x_le, G_y_le,
scalar_le
);
HW_DB_PinClear();