Compare commits

...

4 Commits

Author SHA1 Message Date
25357e14eb Remove DH_GEN_PUB macro requirement 2025-05-09 15:49:43 -06:00
f82bcabb19 Pulling in wc_DhGeneratePublic API 2025-04-29 17:03:41 -06:00
6075b44e7e Module v5.2.3 STM32 PAA 2025-01-06 13:26:53 -07:00
844e961ff5 Check-in FIPS 140-3 PILOT changes 2023-08-28 15:43:24 -07:00
10 changed files with 67 additions and 11 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_AesSetKey(aes, key, len, iv, dir);
}
#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);
@ -1348,6 +1348,36 @@ static int GeneratePublicDh(DhKey* key, byte* priv, word32 privSz,
return ret;
}
/**
* Given a DhKey with set params and a priv key, generate the corresponding
* public key. If fips, does pub key validation.
* */
WOLFSSL_API int wc_DhGeneratePublic(DhKey* key, byte* priv, word32 privSz,
byte* pub, word32* pubSz)
{
int ret = 0;
if (key == NULL || priv == NULL || privSz == 0 ||
pub == NULL || pubSz == NULL) {
return BAD_FUNC_ARG;
}
SAVE_VECTOR_REGISTERS(return _svr_ret;);
ret = GeneratePublicDh(key, priv, privSz, pub, pubSz);
#if FIPS_VERSION_GE(5,0) || defined(WOLFSSL_VALIDATE_DH_KEYGEN)
if (ret == 0)
ret = _ffc_validate_public_key(key, pub, *pubSz, NULL, 0, 0);
if (ret == 0)
ret = _ffc_pairwise_consistency_test(key, pub, *pubSz, priv, privSz);
#endif /* FIPS V5 or later || WOLFSSL_VALIDATE_DH_KEYGEN */
RESTORE_VECTOR_REGISTERS();
return ret;
}
static int wc_DhGenerateKeyPair_Sync(DhKey* key, WC_RNG* rng,
byte* priv, word32* privSz, byte* pub, word32* pubSz)
{
@ -2340,8 +2370,8 @@ int wc_DhExportKeyPair(DhKey* key, byte* priv, word32* pPrivSz,
#endif /* WOLFSSL_DH_EXTRA */
static int _DhSetKey(DhKey* key, const byte* p, word32 pSz, const byte* g,
word32 gSz, const byte* q, word32 qSz, int trusted,
WC_RNG* rng)
word32 gSz, const byte* q, word32 qSz, int trusted,
WC_RNG* rng)
{
int ret = 0;
mp_int* keyP = NULL;

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

@ -1972,6 +1972,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
{
int ret;
word32 retVal;
RNG_HandleTypeDef hrng;
word32 i = 0;
(void)os;
@ -2004,7 +2005,9 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
}
else {
/* Use native 32 instruction */
if (HAL_RNG_GenerateRandomNumber(&hrng, (uint32_t*)&output[i]) != HAL_OK) {
retVal = HAL_RNG_GenerateRandomNumber(&hrng,
(uint32_t*)&output[i]);
if (retVal != HAL_OK) {
wolfSSL_CryptHwMutexUnLock();
return RAN_BLOCK_E;
}

View File

@ -137,7 +137,7 @@
ret = wolfSSL_CryptHwMutexLock();
if (ret == 0) {
ret = wc_Stm32_Hash_Update(&sha->stmCtx, HASH_AlgoSelection_SHA1,
data, len);
data, len, WC_SHA_BLOCK_SIZE);
wolfSSL_CryptHwMutexUnLock();
}
return ret;

View File

@ -553,7 +553,7 @@ static int InitSha256(wc_Sha256* sha256)
ret = wolfSSL_CryptHwMutexLock();
if (ret == 0) {
ret = wc_Stm32_Hash_Update(&sha256->stmCtx,
HASH_AlgoSelection_SHA256, data, len);
HASH_AlgoSelection_SHA256, data, len, WC_SHA256_BLOCK_SIZE);
wolfSSL_CryptHwMutexUnLock();
}
return ret;
@ -1384,7 +1384,7 @@ static int InitSha256(wc_Sha256* sha256)
ret = wolfSSL_CryptHwMutexLock();
if (ret == 0) {
ret = wc_Stm32_Hash_Update(&sha224->stmCtx,
HASH_AlgoSelection_SHA224, data, len);
HASH_AlgoSelection_SHA224, data, len, WC_SHA224_BLOCK_SIZE);
wolfSSL_CryptHwMutexUnLock();
}
return ret;

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

@ -112,6 +112,8 @@ WOLFSSL_API const DhParams* wc_Dh_ffdhe8192_Get(void);
WOLFSSL_API int wc_InitDhKey(DhKey* key);
WOLFSSL_API int wc_InitDhKey_ex(DhKey* key, void* heap, int devId);
WOLFSSL_API int wc_FreeDhKey(DhKey* key);
WOLFSSL_API int wc_DhGeneratePublic(DhKey* key, byte* priv, word32 privSz,
byte* pub, word32* pubSz);
WOLFSSL_API int wc_DhGenerateKeyPair(DhKey* key, WC_RNG* rng, byte* priv,
word32* privSz, byte* pub, word32* pubSz);

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" */