Hi Gilles Peskine,
I tried the following code from TA and I am getting error. Can you help me understand what is wrong here?
static int myrand(void* rng_state, unsigned char* output, size_t len) { size_t use_len; int rnd;
if (rng_state != NULL) { rng_state = NULL; }
while (len > 0) { use_len = len; if (use_len > sizeof(int)) { use_len = sizeof(int); }
rnd = rand(); memcpy(output, &rnd, use_len); output += use_len; len -= use_len; }
return 0; }
static void testEcdsa() { mbedtls_ecdsa_context ecdsa; const mbedtls_ecp_curve_info* curve_info; size_t sig_len; unsigned char tmp[200]; unsigned char buf[32];
memset(buf, 0x2A, sizeof(buf));
mbedtls_ecdsa_init(&ecdsa);
if (mbedtls_ecdsa_genkey(&ecdsa, MBEDTLS_ECP_DP_BP256R1, myrand, NULL) != 0) { return; }
if (mbedtls_ecdsa_write_signature(&ecdsa, MBEDTLS_MD_SHA256, buf, 256, tmp, sizeof(tmp), &sig_len, myrand, NULL) != 0) { return; }
mbedtls_ecdsa_free(&ecdsa); }
Regards, Arun Lal K M