Hi @Kaleb,
I do not believe my problem lies in the wc_GenerateSeed function as my RSA keys are generated successfully - according to WolfCrypt. The problem is that only the public key parts are available and not the private key
When generating a RSA keypair - using cryptocell the following function is called (from wolfcrypt/src/rsa.c):
int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
{
#ifndef WC_NO_RNG
mp_int p, q, tmp1, tmp2, tmp3;
int err, i, failCount, primeSz, isPrime = 0;
byte* buf = NULL;
if (key == NULL || rng == NULL)
return BAD_FUNC_ARG;
if (!RsaSizeCheck(size))
return BAD_FUNC_ARG;
if (e < 3 || (e & 1) == 0)
return BAD_FUNC_ARG;
#if defined(WOLFSSL_CRYPTOCELL)
return cc310_RSA_GenerateKeyPair(key, size, e);
#endif /*WOLFSSL_CRYPTOCELL*/
The following cryptocell function is then called:
cc310_RSA_GenerateKeyPair (in wolfcrypt/src/rsa.c) then executes :
ret = CRYS_RSA_KG_GenerateKeyPair(&wc_rndState,
wc_rndGenVectFunc,
(byte*)&e,
3*sizeof(uint8_t),
size,
&key->ctx.privKey,
&key->ctx.pubKey,
&KeyGenData,
&FipsCtx);
if (ret != SA_SILIB_RET_OK){
WOLFSSL_MSG("CRYS_RSA_KG_GenerateKeyPair failed");
return ret;
}
ret = CRYS_RSA_Get_PubKey(&key->ctx.pubKey, ex, &eSz, n, &nSz);
if (ret != SA_SILIB_RET_OK){
WOLFSSL_MSG("CRYS_RSA_Get_PubKey failed");
return ret;
}
ret = wc_RsaPublicKeyDecodeRaw(n, nSz, ex, eSz, key);
key->type = RSA_PRIVATE;
From this code section only the public key elements ( &key->ctx.pubKey) are decoded into the original "struct RsaKey" and not the &key->ctx.privKey.
This means if a key is generated using cryptocell - only the public key elements can be used in the rest of the wolfcrypt RSA API functions like wc_RsaKeyToDer and then subsequently wc_RsaPrivateKeyDecode.
Then for some reason the key->type is set to RSA_PRIVATE
How can I get the private key from &key->ctx.privKey into a compatible RSA struct to use in wc_RsaKeyToDer