Only use SP for RSA private operations if P and Q half bits

This commit is contained in:
Sean Parkinson
2020-05-07 08:46:48 +10:00
parent be3c39ed1c
commit c4af5db4b9

View File

@ -2038,12 +2038,16 @@ static int wc_RsaFunctionSync(const byte* in, word32 inLen, byte* out,
return MISSING_RNG_E; return MISSING_RNG_E;
#endif #endif
#ifndef RSA_LOW_MEM #ifndef RSA_LOW_MEM
return sp_RsaPrivate_2048(in, inLen, &key->d, &key->p, &key->q, if ((mp_count_bits(&key->p) == 1024) &&
&key->dP, &key->dQ, &key->u, &key->n, (mp_count_bits(&key->q) == 1024)) {
out, outLen); return sp_RsaPrivate_2048(in, inLen, &key->d, &key->p, &key->q,
&key->dP, &key->dQ, &key->u, &key->n,
out, outLen);
}
break;
#else #else
return sp_RsaPrivate_2048(in, inLen, &key->d, &key->p, &key->q, return sp_RsaPrivate_2048(in, inLen, &key->d, NULL, NULL, NULL,
NULL, NULL, NULL, &key->n, out, outLen); NULL, NULL, &key->n, out, outLen);
#endif #endif
#endif #endif
case RSA_PUBLIC_ENCRYPT: case RSA_PUBLIC_ENCRYPT:
@ -2063,12 +2067,16 @@ static int wc_RsaFunctionSync(const byte* in, word32 inLen, byte* out,
return MISSING_RNG_E; return MISSING_RNG_E;
#endif #endif
#ifndef RSA_LOW_MEM #ifndef RSA_LOW_MEM
return sp_RsaPrivate_3072(in, inLen, &key->d, &key->p, &key->q, if ((mp_count_bits(&key->p) == 1536) &&
&key->dP, &key->dQ, &key->u, &key->n, (mp_count_bits(&key->q) == 1536)) {
out, outLen); return sp_RsaPrivate_3072(in, inLen, &key->d, &key->p, &key->q,
&key->dP, &key->dQ, &key->u, &key->n,
out, outLen);
}
break;
#else #else
return sp_RsaPrivate_3072(in, inLen, &key->d, &key->p, &key->q, return sp_RsaPrivate_3072(in, inLen, &key->d, NULL, NULL, NULL,
NULL, NULL, NULL, &key->n, out, outLen); NULL, NULL, &key->n, out, outLen);
#endif #endif
#endif #endif
case RSA_PUBLIC_ENCRYPT: case RSA_PUBLIC_ENCRYPT:
@ -2088,12 +2096,16 @@ static int wc_RsaFunctionSync(const byte* in, word32 inLen, byte* out,
return MISSING_RNG_E; return MISSING_RNG_E;
#endif #endif
#ifndef RSA_LOW_MEM #ifndef RSA_LOW_MEM
return sp_RsaPrivate_4096(in, inLen, &key->d, &key->p, &key->q, if ((mp_count_bits(&key->p) == 2048) &&
&key->dP, &key->dQ, &key->u, &key->n, (mp_count_bits(&key->q) == 2048)) {
out, outLen); return sp_RsaPrivate_4096(in, inLen, &key->d, &key->p, &key->q,
&key->dP, &key->dQ, &key->u, &key->n,
out, outLen);
}
break;
#else #else
return sp_RsaPrivate_4096(in, inLen, &key->d, &key->p, &key->q, return sp_RsaPrivate_4096(in, inLen, &key->d, NULL, NULL, NULL,
NULL, NULL, NULL, &key->n, out, outLen); NULL, NULL, &key->n, out, outLen);
#endif #endif
#endif #endif
case RSA_PUBLIC_ENCRYPT: case RSA_PUBLIC_ENCRYPT: