Compare commits

...

2 Commits

Author SHA1 Message Date
Lealem Amedie
064aace824 Add ability to switch to STD RSA method 2025-07-02 10:03:28 -06:00
kaleb-himes
844e961ff5 Check-in FIPS 140-3 PILOT changes 2023-08-28 15:43:24 -07:00
7 changed files with 45 additions and 9 deletions

View File

@@ -4385,6 +4385,19 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
return 0;
}
int wc_AesCtrSetKey(Aes* aes, const byte* key, word32 len,
const byte* iv, int dir)
{
if (aes == NULL) {
return BAD_FUNC_ARG;
}
if (len > sizeof(aes->key)) {
return BAD_FUNC_ARG;
}
return wc_AesSetKeyLocal(aes, key, len, iv, dir, 0);
}
#endif /* NEED_AES_CTR_SOFT */
#endif /* WOLFSSL_AES_COUNTER */

View File

@@ -1336,7 +1336,7 @@ static int GeneratePublicDh(DhKey* key, byte* priv, word32 privSz,
*pubSz = binSz;
mp_clear(y);
mp_clear(x);
mp_forcezero(x);
#ifdef WOLFSSL_SMALL_STACK
XFREE(y, key->heap, DYNAMIC_TYPE_DH);
XFREE(x, key->heap, DYNAMIC_TYPE_DH);

View File

@@ -1196,6 +1196,7 @@ int wolfSSL_GetHmacMaxSize(void)
ret = wc_HmacUpdate(&myHmac, inKey, inKeySz);
if (ret == 0)
ret = wc_HmacFinal(&myHmac, out);
ForceZero(&myHmac, sizeof(myHmac));
wc_HmacFree(&myHmac);
}
@@ -1261,6 +1262,7 @@ int wolfSSL_GetHmacMaxSize(void)
n++;
}
ForceZero(&myHmac, sizeof(myHmac));
wc_HmacFree(&myHmac);
return ret;

View File

@@ -734,6 +734,7 @@ int wc_SSH_KDF(byte hashId, byte keyId, byte* key, word32 keySz,
}
}
ForceZero(&hash, sizeof(hash));
_HashFree(enmhashId, &hash);
return ret;

View File

@@ -2271,7 +2271,10 @@ static int wc_RsaFunctionSync(const byte* in, word32 inLen, byte* out,
#endif
#ifndef RSA_LOW_MEM
if ((mp_count_bits(&key->p) == 1024) &&
(mp_count_bits(&key->q) == 1024)) {
(mp_count_bits(&key->q) == 1024) &&
(mp_count_bits(&key->dP) > 0) &&
(mp_count_bits(&key->dQ) > 0) &&
(mp_count_bits(&key->u) > 0)) {
return sp_RsaPrivate_2048(in, inLen, &key->d, &key->p, &key->q,
&key->dP, &key->dQ, &key->u, &key->n,
out, outLen);
@@ -2302,7 +2305,10 @@ static int wc_RsaFunctionSync(const byte* in, word32 inLen, byte* out,
#endif
#ifndef RSA_LOW_MEM
if ((mp_count_bits(&key->p) == 1536) &&
(mp_count_bits(&key->q) == 1536)) {
(mp_count_bits(&key->q) == 1536) &&
(mp_count_bits(&key->dP) > 0) &&
(mp_count_bits(&key->dQ) > 0) &&
(mp_count_bits(&key->u) > 0)) {
return sp_RsaPrivate_3072(in, inLen, &key->d, &key->p, &key->q,
&key->dP, &key->dQ, &key->u, &key->n,
out, outLen);
@@ -2333,7 +2339,10 @@ static int wc_RsaFunctionSync(const byte* in, word32 inLen, byte* out,
#endif
#ifndef RSA_LOW_MEM
if ((mp_count_bits(&key->p) == 2048) &&
(mp_count_bits(&key->q) == 2048)) {
(mp_count_bits(&key->q) == 2048) &&
(mp_count_bits(&key->dP) > 0) &&
(mp_count_bits(&key->dQ) > 0) &&
(mp_count_bits(&key->u) > 0)) {
return sp_RsaPrivate_4096(in, inLen, &key->d, &key->p, &key->q,
&key->dP, &key->dQ, &key->u, &key->n,
out, outLen);
@@ -2434,7 +2443,13 @@ static int wc_RsaFunctionSync(const byte* in, word32 inLen, byte* out,
if (ret == 0 && mp_exptmod(tmp, &key->d, &key->n, tmp) != MP_OKAY)
ret = MP_EXPTMOD_E;
#else
if (ret == 0) {
if (ret == 0 && (mp_iszero(&key->p) || mp_iszero(&key->q) ||
mp_iszero(&key->dP) || mp_iszero(&key->dQ))) {
if (mp_exptmod(tmp, &key->d, &key->n, tmp) != MP_OKAY) {
ret = MP_EXPTMOD_E;
}
}
else if (ret == 0) {
#ifdef WOLFSSL_SMALL_STACK
mp_int* tmpa;
mp_int* tmpb = NULL;

View File

@@ -367,6 +367,9 @@ WOLFSSL_API int wc_AesEcbDecrypt(Aes* aes, byte* out,
#ifdef WOLFSSL_AES_COUNTER
WOLFSSL_API int wc_AesCtrEncrypt(Aes* aes, byte* out,
const byte* in, word32 sz);
WOLFSSL_API int wc_AesCtrSetKey(Aes* aes, const byte* key, word32 len,
const byte* iv, int dir);
#endif
/* AES-DIRECT */
#if defined(WOLFSSL_AES_DIRECT)

View File

@@ -58,10 +58,10 @@ enum FipsCastStateId {
};
enum FipsModeId {
FIPS_MODE_INIT,
FIPS_MODE_NORMAL,
FIPS_MODE_DEGRADED,
FIPS_MODE_FAILED
FIPS_MODE_INIT = 0,
FIPS_MODE_NORMAL = 1,
FIPS_MODE_DEGRADED = 2,
FIPS_MODE_FAILED = 3
};
@@ -73,6 +73,7 @@ WOLFSSL_API int wolfCrypt_SetCb_fips(wolfCrypt_fips_cb cbf);
/* Public get status functions */
WOLFSSL_API int wolfCrypt_GetStatus_fips(void);
WOLFSSL_API int wolfCrypt_GetMode_fips(void);
WOLFSSL_API const char* wolfCrypt_GetCoreHash_fips(void);
#ifdef HAVE_FORCE_FIPS_FAILURE
@@ -87,6 +88,7 @@ WOLFSSL_LOCAL int DoKnownAnswerTests(char*, int); /* FIPSv1 and FIPSv2 */
WOLFSSL_API int wc_RunCast_fips(int);
WOLFSSL_API int wc_GetCastStatus_fips(int);
WOLFSSL_API int wc_RunAllCast_fips(void);
#ifdef __cplusplus
} /* extern "C" */