Skip to content

Commit 40079ed

Browse files
Merge pull request #351 from ejohnstown/fixes
Fix for NO_FILESYSTEM and WOLFSSH_NO_AES_GCM and !HAVE_ECC
2 parents a133043 + 326ae87 commit 40079ed

5 files changed

Lines changed: 31 additions & 11 deletions

File tree

examples/echoserver/echoserver.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,14 +1123,14 @@ static int load_key(byte isEcc, byte* buf, word32 bufSz)
11231123
#else
11241124
/* using buffers instead */
11251125
if (isEcc) {
1126-
if (sizeof_ecc_key_der_256 > bufSz) {
1126+
if ((word32)sizeof_ecc_key_der_256 > bufSz) {
11271127
return 0;
11281128
}
11291129
WMEMCPY(buf, ecc_key_der_256, sizeof_ecc_key_der_256);
11301130
sz = sizeof_ecc_key_der_256;
11311131
}
11321132
else {
1133-
if (sizeof_rsa_key_der_2048 > bufSz) {
1133+
if ((word32)sizeof_rsa_key_der_2048 > bufSz) {
11341134
return 0;
11351135
}
11361136
WMEMCPY(buf, (byte*)rsa_key_der_2048, sizeof_rsa_key_der_2048);

examples/server/server.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,14 @@ static int load_key(byte isEcc, byte* buf, word32 bufSz)
313313
#else
314314
/* using buffers instead */
315315
if (isEcc) {
316-
if (sizeof_ecc_key_der_256 > bufSz) {
316+
if ((word32)sizeof_ecc_key_der_256 > bufSz) {
317317
return 0;
318318
}
319319
WMEMCPY(buf, ecc_key_der_256, sizeof_ecc_key_der_256);
320320
sz = sizeof_ecc_key_der_256;
321321
}
322322
else {
323-
if (sizeof_rsa_key_der_2048 > bufSz) {
323+
if ((word32)sizeof_rsa_key_der_2048 > bufSz) {
324324
return 0;
325325
}
326326
WMEMCPY(buf, rsa_key_der_2048, sizeof_rsa_key_der_2048);

src/internal.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,6 +2281,7 @@ static INLINE enum wc_HashType HashForId(byte id)
22812281
}
22822282

22832283

2284+
#if !defined(WOLFSSH_NO_ECDSA) && !defined(WOLFSSH_NO_ECDH)
22842285
static INLINE int wcPrimeForId(byte id)
22852286
{
22862287
switch (id) {
@@ -2313,7 +2314,6 @@ static INLINE int wcPrimeForId(byte id)
23132314
}
23142315
}
23152316

2316-
#ifndef WOLFSSH_NO_ECDSA
23172317
static INLINE const char *PrimeNameForId(byte id)
23182318
{
23192319
switch (id) {
@@ -2333,7 +2333,7 @@ static INLINE const char *PrimeNameForId(byte id)
23332333
return "unknown";
23342334
}
23352335
}
2336-
#endif
2336+
#endif /* WOLFSSH_NO_ECDSA */
23372337

23382338

23392339
static INLINE byte AeadModeForId(byte id)
@@ -2871,10 +2871,14 @@ static int DoKexDhReply(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
28712871
int ret = WS_SUCCESS;
28722872
int tmpIdx = 0;
28732873
struct wolfSSH_sigKeyBlock *sigKeyBlock_ptr = NULL;
2874+
#ifndef WOLFSSH_NO_ECDH
28742875
ecc_key *key_ptr = NULL;
2876+
#ifndef WOLFSSH_SMALL_STACK
2877+
ecc_key key_s;
2878+
#endif
2879+
#endif
28752880
#ifndef WOLFSSH_SMALL_STACK
28762881
struct wolfSSH_sigKeyBlock s_sigKeyBlock;
2877-
ecc_key key_s;
28782882
#endif
28792883

28802884
WLOG(WS_LOG_DEBUG, "Entering DoKexDhReply()");
@@ -5884,6 +5888,7 @@ static INLINE int VerifyMac(WOLFSSH* ssh, const byte* in, word32 inSz,
58845888
}
58855889

58865890

5891+
#ifndef WOLFSSH_NO_AEAD
58875892
static INLINE void AeadIncrementExpIv(byte* iv)
58885893
{
58895894
int i;
@@ -5896,7 +5901,6 @@ static INLINE void AeadIncrementExpIv(byte* iv)
58965901
}
58975902

58985903

5899-
#ifndef WOLFSSH_NO_AEAD
59005904
static INLINE int EncryptAead(WOLFSSH* ssh, byte* cipher,
59015905
const byte* input, word16 sz,
59025906
byte* authTag, const byte* auth,
@@ -5968,7 +5972,7 @@ static INLINE int DecryptAead(WOLFSSH* ssh, byte* plain,
59685972

59695973
return ret;
59705974
}
5971-
#endif
5975+
#endif /* WOLFSSH_NO_AEAD */
59725976

59735977

59745978
int DoReceive(WOLFSSH* ssh)
@@ -6432,9 +6436,11 @@ static const char cannedKeyAlgoClientNames[] =
64326436
#endif
64336437

64346438
static const char cannedKeyAlgoRsaNames[] = "ssh-rsa";
6439+
#if !defined(WOLFSSH_NO_ECDSA) && !defined(WOLFSSH_NO_ECDH)
64356440
static const char cannedKeyAlgoEcc256Names[] = "ecdsa-sha2-nistp256";
64366441
static const char cannedKeyAlgoEcc384Names[] = "ecdsa-sha2-nistp384";
64376442
static const char cannedKeyAlgoEcc521Names[] = "ecdsa-sha2-nistp521";
6443+
#endif
64386444

64396445
static const char cannedKexAlgoNames[] =
64406446
#if !defined(WOLFSSH_NO_ECDH_SHA2_NISTP521)
@@ -6474,12 +6480,14 @@ static const word32 cannedMacAlgoNamesSz = sizeof(cannedMacAlgoNames) - 2;
64746480
static const word32 cannedKeyAlgoClientNamesSz =
64756481
sizeof(cannedKeyAlgoClientNames) - 2;
64766482
static const word32 cannedKeyAlgoRsaNamesSz = sizeof(cannedKeyAlgoRsaNames) - 1;
6483+
#if !defined(WOLFSSH_NO_ECDSA) && !defined(WOLFSSH_NO_ECDH)
64776484
static const word32 cannedKeyAlgoEcc256NamesSz =
64786485
sizeof(cannedKeyAlgoEcc256Names) - 1;
64796486
static const word32 cannedKeyAlgoEcc384NamesSz =
64806487
sizeof(cannedKeyAlgoEcc384Names) - 1;
64816488
static const word32 cannedKeyAlgoEcc521NamesSz =
64826489
sizeof(cannedKeyAlgoEcc521Names) - 1;
6490+
#endif
64836491
static const word32 cannedKexAlgoNamesSz = sizeof(cannedKexAlgoNames) - 2;
64846492
static const word32 cannedNoneNamesSz = sizeof(cannedNoneNames) - 1;
64856493

@@ -6513,6 +6521,7 @@ int SendKexInit(WOLFSSH* ssh)
65136521
if (ret == WS_SUCCESS) {
65146522
if (ssh->ctx->side == WOLFSSH_ENDPOINT_SERVER) {
65156523
switch (ssh->ctx->useEcc) {
6524+
#if !defined(WOLFSSH_NO_ECDSA) && !defined(WOLFSSH_NO_ECDH)
65166525
case ECC_SECP256R1:
65176526
cannedKeyAlgoNames = cannedKeyAlgoEcc256Names;
65186527
cannedKeyAlgoNamesSz = cannedKeyAlgoEcc256NamesSz;
@@ -6525,6 +6534,7 @@ int SendKexInit(WOLFSSH* ssh)
65256534
cannedKeyAlgoNames = cannedKeyAlgoEcc521Names;
65266535
cannedKeyAlgoNamesSz = cannedKeyAlgoEcc521NamesSz;
65276536
break;
6537+
#endif
65286538
default:
65296539
cannedKeyAlgoNames = cannedKeyAlgoRsaNames;
65306540
cannedKeyAlgoNamesSz = cannedKeyAlgoRsaNamesSz;
@@ -6659,7 +6669,9 @@ int SendKexDhReply(WOLFSSH* ssh)
66596669
{
66606670
int ret = WS_SUCCESS;
66616671
byte *f_ptr = NULL, *sig_ptr = NULL;
6672+
#ifndef WOLFSSH_NO_ECDH
66626673
byte *r_ptr = NULL, *s_ptr = NULL;
6674+
#endif
66636675
byte scratchLen[LENGTH_SZ];
66646676
word32 fSz = KEX_F_SIZE;
66656677
word32 sigSz = KEX_SIG_SIZE;
@@ -7057,6 +7069,7 @@ int SendKexDhReply(WOLFSSH* ssh)
70577069
#endif /* ! WOLFSSH_NO_DH */
70587070
}
70597071
else {
7072+
#if !defined(WOLFSSH_NO_ECDH)
70607073
ecc_key pubKey;
70617074
ecc_key privKey;
70627075
int primeId;
@@ -7092,6 +7105,7 @@ int SendKexDhReply(WOLFSSH* ssh)
70927105
ssh->k, &ssh->kSz);
70937106
wc_ecc_free(&privKey);
70947107
wc_ecc_free(&pubKey);
7108+
#endif /* !defined(WOLFSSH_NO_ECDH) */
70957109
}
70967110
}
70977111

@@ -7655,6 +7669,7 @@ int SendKexDhInit(WOLFSSH* ssh)
76557669
#endif
76567670
}
76577671
else {
7672+
#if !defined(WOLFSSH_NO_ECDH)
76587673
ecc_key* privKey = &ssh->handshake->privKey.ecc;
76597674
int primeId = wcPrimeForId(ssh->handshake->kexId);
76607675

@@ -7674,6 +7689,9 @@ int SendKexDhInit(WOLFSSH* ssh)
76747689
privKey, primeId);
76757690
if (ret == 0)
76767691
ret = wc_ecc_export_x963(privKey, e, &eSz);
7692+
#else
7693+
ret = WS_INVALID_ALGO_ID;
7694+
#endif /* !defined(WOLFSSH_NO_ECDH) */
76777695
}
76787696

76797697
if (ret == 0)

tests/api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ static const char serverKeyEccDer[] =
471471
"45747a834c61f33fad26cf22cda9a3bca561b47ce662d4c2f755439a31fb8011"
472472
"20b5124b24f578d7fd22ef4635f005586b5f63c8da1bc4f569";
473473
static const int serverKeyEccCurveId = ECC_SECP256R1;
474-
#elif defined(WOLFSSH_NO_ECDSA_SHA2_NISTP384)
474+
#elif !defined(WOLFSSH_NO_ECDSA_SHA2_NISTP384)
475475
static const char serverKeyEccDer[] =
476476
"3081a402010104303eadd2bbbf05a7be3a3f7c28151289de5bb3644d7011761d"
477477
"b56f2a0362fba64f98e64ff986dc4fb8efdb2d6b8da57142a00706052b810400"
@@ -480,7 +480,7 @@ static const char serverKeyEccDer[] =
480480
"b4c6a4cf5e97bd7e51e975e3e9217261506eb9cf3c493d3eb88d467b5f27ebab"
481481
"2161c00066febd";
482482
static const int serverKeyEccCurveId = ECC_SECP384R1;
483-
#elif defined(WOLFSSH_NO_ECDSA_SHA2_NISTP521)
483+
#elif !defined(WOLFSSH_NO_ECDSA_SHA2_NISTP521)
484484
static const char serverKeyEccDer[] =
485485
"3081dc0201010442004ca4d86428d9400e7b2df3912eb996c195895043af92e8"
486486
"6de70ae4df46f22a291a6bb2748aae82580df6c39f49b3ed82f1789ece1b657d"

wolfssh/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,9 @@ typedef struct HandshakeInfo {
463463
#ifndef WOLFSSH_NO_DH
464464
DhKey dh;
465465
#endif
466+
#if !defined(WOLFSSH_NO_ECDSA) && !defined(WOLFSSH_NO_ECDH)
466467
ecc_key ecc;
468+
#endif
467469
} privKey;
468470
} HandshakeInfo;
469471

0 commit comments

Comments
 (0)