Skip to content

Commit 76ba904

Browse files
committed
Fixes for all FIPS 140-3 cases.
1 parent fba8e78 commit 76ba904

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

src/internal.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3248,10 +3248,16 @@ static int DoKexDhReply(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
32483248
ssh->kSz = MAX_KEX_KEY_SZ;
32493249
if (!ssh->handshake->useEcc) {
32503250
#ifndef WOLFSSH_NO_DH
3251+
#ifdef PRIVATE_KEY_UNLOCK
3252+
PRIVATE_KEY_UNLOCK();
3253+
#endif
32513254
ret = wc_DhAgree(&ssh->handshake->privKey.dh,
32523255
ssh->k, &ssh->kSz,
32533256
ssh->handshake->x, ssh->handshake->xSz,
32543257
f, fSz);
3258+
#ifdef PRIVATE_KEY_LOCK
3259+
PRIVATE_KEY_LOCK();
3260+
#endif
32553261
ForceZero(ssh->handshake->x, ssh->handshake->xSz);
32563262
wc_FreeDhKey(&ssh->handshake->privKey.dh);
32573263
if (ret != 0) {
@@ -7262,9 +7268,16 @@ int SendKexDhReply(WOLFSSH* ssh)
72627268
if (ret == 0)
72637269
ret = wc_DhGenerateKeyPair(privKey, ssh->rng,
72647270
y_ptr, &ySz, f_ptr, &fSz);
7265-
if (ret == 0)
7271+
if (ret == 0) {
7272+
#ifdef PRIVATE_KEY_UNLOCK
7273+
PRIVATE_KEY_UNLOCK();
7274+
#endif
72667275
ret = wc_DhAgree(privKey, ssh->k, &ssh->kSz, y_ptr, ySz,
72677276
ssh->handshake->e, ssh->handshake->eSz);
7277+
#ifdef PRIVATE_KEY_LOCK
7278+
PRIVATE_KEY_LOCK();
7279+
#endif
7280+
}
72687281
ForceZero(y_ptr, ySz);
72697282
wc_FreeDhKey(privKey);
72707283
}
@@ -7952,8 +7965,15 @@ int SendKexDhInit(WOLFSSH* ssh)
79527965
ret = wc_ecc_make_key_ex(ssh->rng,
79537966
wc_ecc_get_curve_size_from_id(primeId),
79547967
privKey, primeId);
7955-
if (ret == 0)
7968+
if (ret == 0) {
7969+
#ifdef PRIVATE_KEY_UNLOCK
7970+
PRIVATE_KEY_UNLOCK();
7971+
#endif
79567972
ret = wc_ecc_export_x963(privKey, e, &eSz);
7973+
#ifdef PRIVATE_KEY_LOCK
7974+
PRIVATE_KEY_LOCK();
7975+
#endif
7976+
}
79577977
#else
79587978
ret = WS_INVALID_ALGO_ID;
79597979
#endif /* !defined(WOLFSSH_NO_ECDH) */

src/ssh.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <wolfssh/internal.h>
3333
#include <wolfssh/log.h>
3434
#include <wolfssl/wolfcrypt/wc_port.h>
35+
#include <wolfssl/wolfcrypt/error-crypt.h>
36+
#include <wolfssl/wolfcrypt/random.h>
3537

3638
#ifdef NO_INLINE
3739
#include <wolfssh/misc.h>
@@ -40,6 +42,19 @@
4042
#include "src/misc.c"
4143
#endif
4244

45+
#ifdef HAVE_FIPS
46+
static void myFipsCb(int ok, int err, const char* hash)
47+
{
48+
printf("in my Fips callback, ok = %d, err = %d\n", ok, err);
49+
printf("message = %s\n", wc_GetErrorString(err));
50+
printf("hash = %s\n", hash);
51+
52+
if (err == IN_CORE_FIPS_E) {
53+
printf("In core integrity hash check failure, copy above hash\n");
54+
printf("into verifyCore[] in fips_test.c and rebuild\n");
55+
}
56+
}
57+
#endif /* HAVE_FIPS */
4358

4459
int wolfSSH_Init(void)
4560
{
@@ -49,6 +64,13 @@ int wolfSSH_Init(void)
4964
if (wolfCrypt_Init() != 0)
5065
ret = WS_CRYPTO_FAILED;
5166

67+
#ifdef HAVE_FIPS
68+
wolfCrypt_SetCb_fips(myFipsCb);
69+
#endif
70+
#ifdef WC_RNG_SEED_CB
71+
wc_SetSeed_Cb(wc_GenerateSeed);
72+
#endif
73+
5274
WLOG(WS_LOG_DEBUG, "Leaving wolfSSH_Init(), returning %d", ret);
5375
return ret;
5476
}

tests/testsuite.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@ int TestsuiteTest(int argc, char** argv)
103103

104104
WSTARTTCP();
105105

106-
wolfSSH_Init();
107106
#if defined(DEBUG_WOLFSSH)
108107
wolfSSH_Debugging_ON();
109108
#endif
109+
110+
wolfSSH_Init();
110111
#if !defined(WOLFSSL_TIRTOS)
111112
ChangeToWolfSshRoot();
112113
#endif

0 commit comments

Comments
 (0)