Hi,
I’m trying to perform signature generation for RSA PKCS 15 mode.
Here is my call:
rc = mbedtls_rsa_rsassa_pkcs1_v15_sign( &rsa_ctx, mbedtls_ctr_drbg_random, &ctr_drbg, MBEDTLS_RSA_PRIVATE, MBEDTLS_MD_SHA256,
32, hash_result, signature );
The rc value is always != 0. But I don’t see what’s wrong with the parameters I’m passing into the call.
I’ve checked the value of hash_result and it does have correct hashvalue for the message (generated using
mbedtls_md).
rsa_ctx has got all my values that I’ve passed in (P,Q,N,D,E). After I imported values into rsa_ctx, I checked the return value of mbedtls_rsa_complete() and it is 0 (successful).
signature is where my signature is stored.
ctr_drbg snippet is shown below:
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_entropy_context entropy;
const char *pers = "rsa key generation";
mbedtls_ctr_drbg_init( &ctr_drbg );
mbedtls_entropy_init( &entropy );
mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func,
&entropy, (const unsigned char *) pers,
strlen( pers ) );
Tried to verify too:
rc = mbedtls_rsa_rsassa_pkcs1_v15_verify(&rsa_ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_SHA256,
32, hash_result, signature );
This also returns non zero value.
Can anyone please suggest me what’s wrong with my call?
Note: I also tried mbedtls_rsa_rsaes_pkcs1_v15_encrypt() for signature gen and didn’t succeed.