Skip to content

Commit 5b795dc

Browse files
committed
Use wolfCrypt SSHv2 KDF
1. Switching to use the new SSH-KDF function in wolfCrypt when the correct version of wolfSSL (v5.7.2 at a minimum) is used, when certified version of wolfCrypt is used or Kyber is disabled. 2. Add WOLFSSL_WOLFSSH to the wolfSSL user_settings files for the Zephyr testing.
1 parent bbba8ae commit 5b795dc

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

Diff for: src/internal.c

+33-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <wolfssl/wolfcrypt/ecc.h>
4848
#include <wolfssl/wolfcrypt/hmac.h>
4949
#include <wolfssl/wolfcrypt/signature.h>
50+
#include <wolfssl/wolfcrypt/kdf.h>
5051

5152
#ifdef WOLFSSH_HAVE_LIBOQS
5253
#include <oqs/kem.h>
@@ -453,6 +454,9 @@ const char* GetErrorString(int err)
453454
case WS_AUTH_PENDING:
454455
return "userauth is still pending (callback would block)";
455456

457+
case WS_KDF_E:
458+
return "KDF error";
459+
456460
default:
457461
return "Unknown error code";
458462
}
@@ -2158,6 +2162,32 @@ int GenerateKey(byte hashId, byte keyId,
21582162
const byte* h, word32 hSz,
21592163
const byte* sessionId, word32 sessionIdSz,
21602164
byte doKeyPad)
2165+
#if (LIBWOLFSSL_VERSION_HEX >= WOLFSSL_V5_7_2) \
2166+
&& ((defined(HAVE_FIPS) && FIPS_VERSION_GE(5,2)) \
2167+
|| defined(WOLFSSH_NO_ECDH_NISTP256_KYBER_LEVEL1_SHA256))
2168+
/* Cannot use the SSH KDF with Kyber. With Kyber, doKeyPad must be false,
2169+
* and the FIPS SSH KDF doesn't handle no-padding. Also, the Kyber algorithm
2170+
* isn't in our FIPS boundary. */
2171+
{
2172+
int ret = WS_SUCCESS;
2173+
2174+
if (!doKeyPad) {
2175+
WLOG(WS_LOG_ERROR, "cannot use FIPS KDF with Kyber");
2176+
ret = WS_INVALID_ALGO_ID;
2177+
}
2178+
else {
2179+
PRIVATE_KEY_UNLOCK();
2180+
ret = wc_SSH_KDF(hashId, keyId, key, keySz,
2181+
k, kSz, h, hSz, sessionId, sessionIdSz);
2182+
PRIVATE_KEY_LOCK();
2183+
if (ret != 0) {
2184+
WLOG(WS_LOG_ERROR, "SSH KDF failed (%d)", ret);
2185+
ret = WS_KDF_E;
2186+
}
2187+
}
2188+
return ret;
2189+
}
2190+
#else
21612191
{
21622192
word32 blocks, remainder;
21632193
wc_HashAlg hash;
@@ -2168,12 +2198,13 @@ int GenerateKey(byte hashId, byte keyId,
21682198
int digestSz;
21692199
int ret;
21702200

2201+
WLOG(WS_LOG_DEBUG, "Entering GenerateKey()");
2202+
21712203
if (key == NULL || keySz == 0 ||
21722204
k == NULL || kSz == 0 ||
21732205
h == NULL || hSz == 0 ||
21742206
sessionId == NULL || sessionIdSz == 0) {
21752207

2176-
WLOG(WS_LOG_DEBUG, "GK: bad argument");
21772208
return WS_BAD_ARGUMENT;
21782209
}
21792210

@@ -2268,6 +2299,7 @@ int GenerateKey(byte hashId, byte keyId,
22682299

22692300
return ret;
22702301
}
2302+
#endif /* HAVE_FIPS && LIBWOLFSSL_VERSION_HEX >= WOLFSSL_V5_7_2 */
22712303

22722304

22732305
static int GenerateKeys(WOLFSSH* ssh, byte hashId, byte doKeyPad)

Diff for: wolfssh/error.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ enum WS_ErrorCodes {
135135
WS_MSGID_NOT_ALLOWED_E = -1094, /* Message not allowed before userauth */
136136
WS_ED25519_E = -1095, /* Ed25519 failure */
137137
WS_AUTH_PENDING = -1096, /* User authentication still pending */
138+
WS_KDF_E = -1097, /* KDF error*/
138139

139-
WS_LAST_E = -1096 /* Update this to indicate last error */
140+
WS_LAST_E = -1097 /* Update this to indicate last error */
140141
};
141142

142143

Diff for: wolfssh/internal.h

+1
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,7 @@ enum TerminalModes {
13471347

13481348

13491349
#define WOLFSSL_V5_7_0 0x05007000
1350+
#define WOLFSSL_V5_7_2 0x05007002
13501351

13511352

13521353
#ifdef __cplusplus

Diff for: zephyr/samples/tests/wolfssl_user_settings.h

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ extern "C" {
2828
#undef WOLFSSL_ZEPHYR
2929
#define WOLFSSL_ZEPHYR
3030

31+
#undef WOLFSSL_WOLFSSH
32+
#define WOLFSSL_WOLFSSH
33+
3134
#undef TFM_TIMING_RESISTANT
3235
#define TFM_TIMING_RESISTANT
3336

Diff for: zephyr/samples/tests/wolfssl_user_settings_nofs.h

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ extern "C" {
2828
#undef WOLFSSL_ZEPHYR
2929
#define WOLFSSL_ZEPHYR
3030

31+
#undef WOLFSSL_WOLFSSH
32+
#define WOLFSSL_WOLFSSH
33+
3134
#undef TFM_TIMING_RESISTANT
3235
#define TFM_TIMING_RESISTANT
3336

0 commit comments

Comments
 (0)