Hello,
I have been trying to implement the Elliptic-curve Diffie–Hellman key exchange using tiny crypt.
As per the API, a random number generator function needs to be passed to create the public and private keys. The random gen function is passed using the setter function uECC_set_rng, I was able to pass the random gen function as a parameter to that function, and further when I call the uECC_make_key and when that function, in turn calls the random gen function for its purpose, the program crashes and reboots. The code has been sown below:
static int random_gen(uint8_t *dest, unsigned size); void main(void) { int rc; uint8_t pk[64]; uint8_t private_key[32]; uint8_t buffer[10]; uECC_set_rng(&random_gen); rc = uECC_make_key(pk, private_key, &curve_secp256r1); if(!rc){ printk("Failed\n"); } else{ printk("Success\n"); } return ; } static int random_gen(uint8_t *dest, unsigned size) { uint8_t buffer[64]; int r = 0; r = sys_csrand_get(dest,size); //crashes here and reboots if (!r){ printk("success!\n"); } return 1; }