Skip to content

Commit 755c39b

Browse files
Merge pull request #6751 from ejohnstown/merge-fips-builds
FIPS 140-3 Pilot Program Check-in
2 parents 51cb80b + 344e166 commit 755c39b

9 files changed

Lines changed: 77 additions & 13 deletions

File tree

wolfcrypt/src/aes.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4570,6 +4570,19 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
45704570
return 0;
45714571
}
45724572

4573+
int wc_AesCtrSetKey(Aes* aes, const byte* key, word32 len,
4574+
const byte* iv, int dir)
4575+
{
4576+
if (aes == NULL) {
4577+
return BAD_FUNC_ARG;
4578+
}
4579+
if (len > sizeof(aes->key)) {
4580+
return BAD_FUNC_ARG;
4581+
}
4582+
4583+
return wc_AesSetKeyLocal(aes, key, len, iv, dir, 0);
4584+
}
4585+
45734586
#endif /* NEED_AES_CTR_SOFT */
45744587

45754588
#endif /* WOLFSSL_AES_COUNTER */

wolfcrypt/src/dh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ static int GeneratePublicDh(DhKey* key, byte* priv, word32 privSz,
13521352
*pubSz = (word32)mp_unsigned_bin_size(y);
13531353

13541354
mp_clear(y);
1355-
mp_clear(x);
1355+
mp_forcezero(x);
13561356
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
13571357
XFREE(y, key->heap, DYNAMIC_TYPE_DH);
13581358
XFREE(x, key->heap, DYNAMIC_TYPE_DH);

wolfcrypt/src/hmac.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,8 @@ void wc_HmacFree(Hmac* hmac)
11731173
default:
11741174
break;
11751175
}
1176+
1177+
ForceZero(hmac, sizeof(*hmac));
11761178
}
11771179
#endif /* WOLFSSL_KCAPI_HMAC */
11781180

wolfcrypt/src/port/arm/armv8-aes.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,13 @@ int wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
14521452
return 0;
14531453
}
14541454

1455+
int wc_AesCtrSetKey(Aes* aes, const byte* key, word32 len,
1456+
const byte* iv, int dir)
1457+
{
1458+
(void)dir;
1459+
return wc_AesSetKey(aes, key, len, iv, AES_ENCRYPTION);
1460+
}
1461+
14551462
#endif /* WOLFSSL_AES_COUNTER */
14561463

14571464
#ifdef HAVE_AESGCM
@@ -4212,6 +4219,13 @@ int wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
42124219
return 0;
42134220
}
42144221

4222+
int wc_AesCtrSetKey(Aes* aes, const byte* key, word32 len,
4223+
const byte* iv, int dir)
4224+
{
4225+
(void)dir;
4226+
return wc_AesSetKey(aes, key, len, iv, AES_ENCRYPTION);
4227+
}
4228+
42154229
#endif /* WOLFSSL_AES_COUNTER */
42164230

42174231
#ifdef HAVE_AESGCM
@@ -5719,6 +5733,13 @@ int wc_AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
57195733
}
57205734
return 0;
57215735
}
5736+
5737+
int wc_AesCtrSetKey(Aes* aes, const byte* key, word32 len,
5738+
const byte* iv, int dir)
5739+
{
5740+
(void)dir;
5741+
return wc_AesSetKey(aes, key, len, iv, AES_ENCRYPTION);
5742+
}
57225743
#endif /* WOLFSSL_AES_COUNTER */
57235744

57245745
#ifdef HAVE_AESCCM

wolfcrypt/src/port/arm/armv8-sha256.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ static int InitSha256(wc_Sha256* sha256)
8585
sha256->loLen = 0;
8686
sha256->hiLen = 0;
8787

88+
#ifdef WOLFSSL_HASH_FLAGS
89+
sha256->flags = 0;
90+
#endif
91+
8892
return ret;
8993
}
9094

@@ -1575,6 +1579,9 @@ int wc_Sha256Transform(wc_Sha256* sha256, const unsigned char* data)
15751579
sha224->loLen = 0;
15761580
sha224->hiLen = 0;
15771581

1582+
#ifdef WOLFSSL_HASH_FLAGS
1583+
sha224->flags = 0;
1584+
#endif
15781585
return ret;
15791586
}
15801587

wolfcrypt/src/sha256.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,7 @@ static int InitSha256(wc_Sha256* sha256)
931931
}
932932

933933
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_SMALL_STACK_CACHE)
934+
ForceZero(W, sizeof(word32) * WC_SHA256_BLOCK_SIZE);
934935
XFREE(W, NULL, DYNAMIC_TYPE_TMP_BUFFER);
935936
#endif
936937
return 0;
@@ -1690,10 +1691,11 @@ static int InitSha256(wc_Sha256* sha256)
16901691
return;
16911692

16921693
#ifdef WOLFSSL_SMALL_STACK_CACHE
1693-
if (sha224->W != NULL) {
1694-
XFREE(sha224->W, NULL, DYNAMIC_TYPE_DIGEST);
1695-
sha224->W = NULL;
1696-
}
1694+
if (sha224->W != NULL) {
1695+
ForceZero(sha224->W, sizeof(word32) * WC_SHA224_BLOCK_SIZE);
1696+
XFREE(sha224->W, NULL, DYNAMIC_TYPE_DIGEST);
1697+
sha224->W = NULL;
1698+
}
16971699
#endif
16981700

16991701
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA224)
@@ -1707,11 +1709,13 @@ static int InitSha256(wc_Sha256* sha256)
17071709
KcapiHashFree(&sha224->kcapi);
17081710
#endif
17091711
#if defined(WOLFSSL_RENESAS_RX64_HASH)
1710-
if (sha224->msg != NULL) {
1711-
XFREE(sha224->msg, sha224->heap, DYNAMIC_TYPE_TMP_BUFFER);
1712-
sha224->msg = NULL;
1713-
}
1712+
if (sha224->msg != NULL) {
1713+
ForceZero(sha224->msg, sha224->len);
1714+
XFREE(sha224->msg, sha224->heap, DYNAMIC_TYPE_TMP_BUFFER);
1715+
sha224->msg = NULL;
1716+
}
17141717
#endif
1718+
ForceZero(sha224, sizeof(*sha224));
17151719
}
17161720
#endif /* WOLFSSL_SHA224 */
17171721
#endif /* !defined(WOLFSSL_HAVE_PSA) || defined(WOLFSSL_PSA_NO_HASH) */
@@ -1737,6 +1741,7 @@ void wc_Sha256Free(wc_Sha256* sha256)
17371741

17381742
#ifdef WOLFSSL_SMALL_STACK_CACHE
17391743
if (sha256->W != NULL) {
1744+
ForceZero(sha256->W, sizeof(word32) * WC_SHA256_BLOCK_SIZE);
17401745
XFREE(sha256->W, NULL, DYNAMIC_TYPE_DIGEST);
17411746
sha256->W = NULL;
17421747
}
@@ -1772,6 +1777,7 @@ void wc_Sha256Free(wc_Sha256* sha256)
17721777
defined(WOLFSSL_HASH_KEEP)
17731778

17741779
if (sha256->msg != NULL) {
1780+
ForceZero(sha256->msg, sha256->len);
17751781
XFREE(sha256->msg, sha256->heap, DYNAMIC_TYPE_TMP_BUFFER);
17761782
sha256->msg = NULL;
17771783
}
@@ -1813,6 +1819,7 @@ void wc_Sha256Free(wc_Sha256* sha256)
18131819
ESP_LOGV(TAG, "Hardware unlock not needed in wc_Sha256Free.");
18141820
}
18151821
#endif
1822+
ForceZero(sha256, sizeof(*sha256));
18161823
}
18171824

18181825
#endif /* !defined(WOLFSSL_HAVE_PSA) || defined(WOLFSSL_PSA_NO_HASH) */

wolfcrypt/src/sha512.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,7 @@ void wc_Sha512Free(wc_Sha512* sha512)
11261126

11271127
#ifdef WOLFSSL_SMALL_STACK_CACHE
11281128
if (sha512->W != NULL) {
1129+
ForceZero(sha512->W, sizeof(word64) * 16);
11291130
XFREE(sha512->W, sha512->heap, DYNAMIC_TYPE_TMP_BUFFER);
11301131
sha512->W = NULL;
11311132
}
@@ -1137,6 +1138,7 @@ void wc_Sha512Free(wc_Sha512* sha512)
11371138

11381139
#if defined(WOLFSSL_HASH_KEEP)
11391140
if (sha512->msg != NULL) {
1141+
ForceZero(sha512->msg, sha512->len);
11401142
XFREE(sha512->msg, sha512->heap, DYNAMIC_TYPE_TMP_BUFFER);
11411143
sha512->msg = NULL;
11421144
}
@@ -1145,6 +1147,8 @@ void wc_Sha512Free(wc_Sha512* sha512)
11451147
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512)
11461148
wolfAsync_DevCtxFree(&sha512->asyncDev, WOLFSSL_ASYNC_MARKER_SHA512);
11471149
#endif /* WOLFSSL_ASYNC_CRYPT */
1150+
1151+
ForceZero(sha512, sizeof(*sha512));
11481152
}
11491153
#if (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) \
11501154
&& !defined(WOLFSSL_KCAPI_HASH)
@@ -1197,6 +1201,7 @@ int wc_Sha512Transform(wc_Sha512* sha, const unsigned char* data)
11971201

11981202
XMEMCPY(sha->buffer, buffer, WC_SHA512_BLOCK_SIZE);
11991203
#ifdef WOLFSSL_SMALL_STACK
1204+
ForceZero(buffer, WC_SHA512_BLOCK_SIZE);
12001205
XFREE(buffer, sha->heap, DYNAMIC_TYPE_TMP_BUFFER);
12011206
#endif
12021207
return ret;
@@ -1446,6 +1451,7 @@ void wc_Sha384Free(wc_Sha384* sha384)
14461451

14471452
#ifdef WOLFSSL_SMALL_STACK_CACHE
14481453
if (sha384->W != NULL) {
1454+
ForceZero(sha384->W, sizeof(word64) * 16);
14491455
XFREE(sha384->W, sha384->heap, DYNAMIC_TYPE_TMP_BUFFER);
14501456
sha384->W = NULL;
14511457
}
@@ -1457,6 +1463,7 @@ void wc_Sha384Free(wc_Sha384* sha384)
14571463

14581464
#if defined(WOLFSSL_HASH_KEEP)
14591465
if (sha384->msg != NULL) {
1466+
ForceZero(sha384->msg, sha384->len);
14601467
XFREE(sha384->msg, sha384->heap, DYNAMIC_TYPE_TMP_BUFFER);
14611468
sha384->msg = NULL;
14621469
}
@@ -1476,6 +1483,8 @@ void wc_Sha384Free(wc_Sha384* sha384)
14761483
sha384->hSession = NULL;
14771484
}
14781485
#endif
1486+
1487+
ForceZero(sha384, sizeof(*sha384));
14791488
}
14801489

14811490
#endif /* WOLFSSL_SHA384 */

wolfssl/wolfcrypt/aes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,9 @@ WOLFSSL_API int wc_AesEcbDecrypt(Aes* aes, byte* out,
415415
#ifdef WOLFSSL_AES_COUNTER
416416
WOLFSSL_API int wc_AesCtrEncrypt(Aes* aes, byte* out,
417417
const byte* in, word32 sz);
418+
WOLFSSL_API int wc_AesCtrSetKey(Aes* aes, const byte* key, word32 len,
419+
const byte* iv, int dir);
420+
418421
#endif
419422
/* AES-DIRECT */
420423
#if defined(WOLFSSL_AES_DIRECT)

wolfssl/wolfcrypt/fips_test.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ enum FipsCastStateId {
7777
};
7878

7979
enum FipsModeId {
80-
FIPS_MODE_INIT,
81-
FIPS_MODE_NORMAL,
82-
FIPS_MODE_DEGRADED,
83-
FIPS_MODE_FAILED
80+
FIPS_MODE_INIT = 0,
81+
FIPS_MODE_NORMAL = 1,
82+
FIPS_MODE_DEGRADED = 2,
83+
FIPS_MODE_FAILED = 3
8484
};
8585

8686

@@ -92,6 +92,7 @@ WOLFSSL_API int wolfCrypt_SetCb_fips(wolfCrypt_fips_cb cbf);
9292

9393
/* Public get status functions */
9494
WOLFSSL_API int wolfCrypt_GetStatus_fips(void);
95+
WOLFSSL_API int wolfCrypt_GetMode_fips(void);
9596
WOLFSSL_API const char* wolfCrypt_GetCoreHash_fips(void);
9697

9798
#ifdef HAVE_FORCE_FIPS_FAILURE
@@ -105,6 +106,7 @@ WOLFSSL_LOCAL int DoKnownAnswerTests(char* base16_hash, int base16_hashSz); /* F
105106

106107
WOLFSSL_API int wc_RunCast_fips(int type);
107108
WOLFSSL_API int wc_GetCastStatus_fips(int type);
109+
WOLFSSL_API int wc_RunAllCast_fips(void);
108110

109111
#ifdef __cplusplus
110112
} /* extern "C" */

0 commit comments

Comments
 (0)