Skip to content

Commit 975283f

Browse files
Merge pull request #401 from ejohnstown/more-guards
Preprocessor Guards
2 parents dadccc8 + b34f144 commit 975283f

10 files changed

Lines changed: 51 additions & 43 deletions

File tree

examples/client/client.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define WOLFSSH_TEST_CLIENT
2626

2727
#include <wolfssh/ssh.h>
28+
#include <wolfssh/internal.h>
2829
#include <wolfssh/test.h>
2930
#ifdef WOLFSSH_AGENT
3031
#include <wolfssh/agent.h>
@@ -197,7 +198,7 @@ static word32 userPrivateKeyTypeSz = 0;
197198
static byte isPrivate = 0;
198199

199200

200-
#ifndef NO_RSA
201+
#ifndef WOLFSSH_NO_RSA
201202
static const char* hanselPublicRsa =
202203
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9P3ZFowOsONXHD5MwWiCciXytBRZGho"
203204
"MNiisWSgUs5HdHcACuHYPi2W6Z1PBFmBWT9odOrGRjoZXJfDDoPi+j8SSfDGsc/hsCmc3G"
@@ -311,8 +312,8 @@ static const unsigned int hanselPrivateRsaSz = 1191;
311312
#endif
312313

313314

314-
#ifdef HAVE_ECC
315-
#ifndef NO_ECC256
315+
#ifndef WOLFSSH_NO_ECC
316+
#ifndef WOLFSSH_NO_ECDSA_SHA2_NISTP256
316317
static const char* hanselPublicEcc =
317318
"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAA"
318319
"BBBNkI5JTP6D0lF42tbxX19cE87hztUS6FSDoGvPfiU0CgeNSbI+aFdKIzTP5CQEJSvm25"
@@ -331,7 +332,7 @@ static const byte hanselPrivateEcc[] = {
331332
0xf9
332333
};
333334
static const unsigned int hanselPrivateEccSz = 121;
334-
#elif defined(HAVE_ECC521)
335+
#elif !defined(WOLFSSH_NO_ECDSA_SHA2_NISTP521)
335336
static const char* hanselPublicEcc =
336337
"ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAA"
337338
"CFBAET/BOzBb9Jx9b52VIHFP4g/uk5KceDpz2M+/Ln9WiDjsMfb4NgNCAB+EMNJUX/TNBL"
@@ -553,7 +554,7 @@ static THREAD_RET readInput(void* in)
553554
return THREAD_RET_SUCCESS;
554555
}
555556
}
556-
#if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
557+
#if !defined(WOLFSSH_NO_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
557558
wc_ecc_fp_free(); /* free per thread cache */
558559
#endif
559560
return THREAD_RET_SUCCESS;
@@ -674,7 +675,7 @@ static THREAD_RET readPeer(void* in)
674675
}
675676
wc_UnLockMutex(&args->lock);
676677
}
677-
#if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
678+
#if !defined(WOLFSSH_NO_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
678679
wc_ecc_fp_free(); /* free per thread cache */
679680
#endif
680681

@@ -924,7 +925,7 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
924925
if (username == NULL)
925926
err_sys("client requires a username parameter.");
926927

927-
#ifdef NO_RSA
928+
#ifdef WOLFSSH_NO_RSA
928929
userEcc = 1;
929930
#endif
930931

@@ -939,14 +940,14 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
939940

940941
if (privKeyName == NULL) {
941942
if (userEcc) {
942-
#ifdef HAVE_ECC
943+
#ifndef WOLFSSH_NO_ECC
943944
ret = wolfSSH_ReadKey_buffer(hanselPrivateEcc, hanselPrivateEccSz,
944945
WOLFSSH_FORMAT_ASN1, &userPrivateKey, &userPrivateKeySz,
945946
&userPrivateKeyType, &userPrivateKeyTypeSz, NULL);
946947
#endif
947948
}
948949
else {
949-
#ifndef NO_RSA
950+
#ifndef WOLFSSH_NO_RSA
950951
ret = wolfSSH_ReadKey_buffer(hanselPrivateRsa, hanselPrivateRsaSz,
951952
WOLFSSH_FORMAT_ASN1, &userPrivateKey, &userPrivateKeySz,
952953
&userPrivateKeyType, &userPrivateKeyTypeSz, NULL);
@@ -974,15 +975,15 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
974975
userPublicKeySz = sizeof(userPublicKeyBuf);
975976

976977
if (userEcc) {
977-
#ifdef HAVE_ECC
978+
#ifndef WOLFSSH_NO_ECC
978979
ret = wolfSSH_ReadKey_buffer((const byte*)hanselPublicEcc,
979980
(word32)strlen(hanselPublicEcc), WOLFSSH_FORMAT_SSH,
980981
&p, &userPublicKeySz,
981982
&userPublicKeyType, &userPublicKeyTypeSz, NULL);
982983
#endif
983984
}
984985
else {
985-
#ifndef NO_RSA
986+
#ifndef WOLFSSH_NO_RSA
986987
ret = wolfSSH_ReadKey_buffer((const byte*)hanselPublicRsa,
987988
(word32)strlen(hanselPublicRsa), WOLFSSH_FORMAT_SSH,
988989
&p, &userPublicKeySz,
@@ -1169,7 +1170,7 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
11691170
if (privKeyName != NULL && userPrivateKey != NULL) {
11701171
WFREE(userPrivateKey, NULL, DYNTYPE_PRIVKEY);
11711172
}
1172-
#if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
1173+
#if !defined(WOLFSSH_NO_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
11731174
wc_ecc_fp_free(); /* free per thread cache */
11741175
#endif
11751176

examples/echoserver/echoserver.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <wolfssl/wolfcrypt/coding.h>
3636
#include <wolfssl/wolfcrypt/wc_port.h>
3737
#include <wolfssh/ssh.h>
38+
#include <wolfssh/internal.h>
3839
#include <wolfssh/wolfsftp.h>
3940
#include <wolfssh/agent.h>
4041
#include <wolfssh/test.h>
@@ -1339,7 +1340,7 @@ static int load_file(const char* fileName, byte* buf, word32* bufSz)
13391340
}
13401341
#endif /* NO_FILESYSTEM */
13411342

1342-
#ifdef HAVE_ECC521
1343+
#ifdef WOLFSSH_NO_ECDSA_SHA2_NISTP256
13431344
#define ECC_PATH "./keys/server-key-ecc-521.der"
13441345
#else
13451346
#define ECC_PATH "./keys/server-key-ecc.der"
@@ -1439,16 +1440,16 @@ static const char samplePasswordBuffer[] =
14391440
"jack:fetchapail\n";
14401441

14411442

1442-
#ifdef HAVE_ECC
1443-
#ifndef NO_ECC256
1443+
#ifndef WOLFSSH_NO_ECC
1444+
#ifndef WOLFSSH_NO_ECDSA_SHA2_NISTP256
14441445
static const char samplePublicKeyEccBuffer[] =
14451446
"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAA"
14461447
"BBBNkI5JTP6D0lF42tbxX19cE87hztUS6FSDoGvPfiU0CgeNSbI+aFdKIzTP5CQEJSvm25"
14471448
"qUzgDtH7oyaQROUnNvk= hansel\n"
14481449
"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAA"
14491450
"BBBKAtH8cqaDbtJFjtviLobHBmjCtG56DMkP6A4M2H9zX2/YCg1h9bYS7WHd9UQDwXO1Hh"
14501451
"IZzRYecXh7SG9P4GhRY= gretel\n";
1451-
#elif defined(HAVE_ECC521)
1452+
#elif !defined(WOLFSSH_NO_ECDSA_SHA2_NISTP521)
14521453
static const char samplePublicKeyEccBuffer[] =
14531454
"ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAA"
14541455
"CFBAET/BOzBb9Jx9b52VIHFP4g/uk5KceDpz2M+/Ln9WiDjsMfb4NgNCAB+EMNJUX/TNBL"
@@ -1463,7 +1464,7 @@ static const char samplePublicKeyEccBuffer[] =
14631464
#endif
14641465
#endif
14651466

1466-
#ifndef NO_RSA
1467+
#ifndef WOLFSSH_NO_RSA
14671468
static const char samplePublicKeyRsaBuffer[] =
14681469
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9P3ZFowOsONXHD5MwWiCciXytBRZGho"
14691470
"MNiisWSgUs5HdHcACuHYPi2W6Z1PBFmBWT9odOrGRjoZXJfDDoPi+j8SSfDGsc/hsCmc3G"
@@ -1865,12 +1866,12 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
18651866
}
18661867
#endif
18671868

1868-
#ifdef NO_RSA
1869+
#ifdef WOLFSSH_NO_RSA
18691870
/* If wolfCrypt isn't built with RSA, force ECC on. */
18701871
userEcc = 1;
18711872
peerEcc = 1;
18721873
#endif
1873-
#ifndef HAVE_ECC
1874+
#ifdef WOLFSSH_NO_ECC
18741875
/* If wolfCrypt isn't built with ECC, force ECC off. */
18751876
userEcc = 0;
18761877
peerEcc = 0;
@@ -1958,12 +1959,12 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
19581959
LoadPasswordBuffer(keyLoadBuf, bufSz, &pwMapList);
19591960

19601961
if (userEcc) {
1961-
#ifdef HAVE_ECC
1962+
#ifndef WOLFSSH_NO_ECC
19621963
bufName = samplePublicKeyEccBuffer;
19631964
#endif
19641965
}
19651966
else {
1966-
#ifndef NO_RSA
1967+
#ifndef WOLFSSH_NO_RSA
19671968
bufName = samplePublicKeyRsaBuffer;
19681969
#endif
19691970
}
@@ -2138,7 +2139,7 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
21382139
fprintf(stderr, "Couldn't clean up wolfSSH.\n");
21392140
WEXIT(EXIT_FAILURE);
21402141
}
2141-
#if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
2142+
#if !defined(WOLFSSH_NO_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
21422143
wc_ecc_fp_free(); /* free per thread cache */
21432144
#endif
21442145

examples/echoserver/include.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ noinst_HEADERS += examples/echoserver/echoserver.h
77
examples_echoserver_echoserver_SOURCES = examples/echoserver/echoserver.c
88
examples_echoserver_echoserver_LDADD = src/libwolfssh.la
99
examples_echoserver_echoserver_DEPENDENCIES = src/libwolfssh.la
10+
examples_echoserver_echoserver_CFLAGS = $(AM_CFLAGS)
1011
endif
1112

1213
DISTCLEANFILES+= examples/echoserver/.libs/echoserver

examples/portfwd/portfwd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <sys/select.h>
3636
#endif
3737
#include <wolfssh/ssh.h>
38+
#include <wolfssh/internal.h>
3839
#include <wolfssh/test.h>
3940
#include <wolfssh/port.h>
4041
#include <wolfssl/wolfcrypt/ecc.h>
@@ -487,7 +488,7 @@ THREAD_RETURN WOLFSSH_THREAD portfwd_worker(void* args)
487488
WFREE(appBuffer, NULL, 0);
488489
WFREE(sshBuffer, NULL, 0);
489490
#endif
490-
#if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
491+
#if !defined(WOLFSSH_NO_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
491492
wc_ecc_fp_free(); /* free per thread cache */
492493
#endif
493494

examples/scpclient/scpclient.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@
2929
#include <termios.h>
3030
#endif
3131
#include <wolfssh/ssh.h>
32+
#include <wolfssh/internal.h>
3233
#include <wolfssh/wolfscp.h>
3334
#include <wolfssh/test.h>
3435
#include <wolfssh/port.h>
3536

3637
#ifndef NO_WOLFSSH_CLIENT
37-
#if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
38+
#if !defined(WOLFSSH_NO_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
3839
#include <wolfssl/wolfcrypt/ecc.h>
3940
#endif
4041
#include "examples/scpclient/scpclient.h"
@@ -382,7 +383,7 @@ THREAD_RETURN WOLFSSH_THREAD scp_client(void* args)
382383
if (ret != WS_SUCCESS)
383384
err_sys("Closing scp stream failed. Connection could have been closed by peer");
384385

385-
#if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
386+
#if !defined(WOLFSSH_NO_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
386387
wc_ecc_fp_free(); /* free per thread cache */
387388
#endif
388389

examples/server/server.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <wolfssl/wolfcrypt/sha256.h>
3636
#include <wolfssl/wolfcrypt/coding.h>
3737
#include <wolfssh/ssh.h>
38+
#include <wolfssh/internal.h>
3839
#include <wolfssh/test.h>
3940
#include <wolfssl/wolfcrypt/ecc.h>
4041
#include "examples/server/server.h"
@@ -664,7 +665,7 @@ THREAD_RETURN WOLFSSH_THREAD server_test(void* args)
664665
}
665666
myoptind = 0; /* reset for test cases */
666667

667-
#ifdef NO_RSA
668+
#ifdef WOLFSSH_NO_RSA
668669
/* If wolfCrypt isn't built with RSA, force ECC on. */
669670
useEcc = 1;
670671
#endif
@@ -776,7 +777,7 @@ THREAD_RETURN WOLFSSH_THREAD server_test(void* args)
776777
fprintf(stderr, "Couldn't clean up wolfSSH.\n");
777778
exit(EXIT_FAILURE);
778779
}
779-
#if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
780+
#if !defined(WOLFSSH_NO_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
780781
wc_ecc_fp_free(); /* free per thread cache */
781782
#endif
782783

examples/sftpclient/sftpclient.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define WOLFSSH_TEST_CLIENT
2626

2727
#include <wolfssh/ssh.h>
28+
#include <wolfssh/internal.h>
2829
#include <wolfssh/wolfsftp.h>
2930
#include <wolfssh/test.h>
3031
#include <wolfssh/port.h>
@@ -1384,7 +1385,7 @@ THREAD_RETURN WOLFSSH_THREAD sftpclient_test(void* args)
13841385
if (username == NULL)
13851386
err_sys("client requires a username parameter.");
13861387

1387-
#ifdef NO_RSA
1388+
#ifdef WOLFSSH_NO_RSA
13881389
userEcc = 1;
13891390
/* peerEcc = 1; */
13901391
#endif
@@ -1524,7 +1525,7 @@ THREAD_RETURN WOLFSSH_THREAD sftpclient_test(void* args)
15241525
printf("error %d encountered\n", ret);
15251526
((func_args*)args)->return_code = ret;
15261527
}
1527-
#if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
1528+
#if !defined(WOLFSSH_NO_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
15281529
wc_ecc_fp_free(); /* free per thread cache */
15291530
#endif
15301531

src/agent.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,10 @@ static WOLFSSH_AGENT_ID* FindKeyId(WOLFSSH_AGENT_ID* id,
667667
return id;
668668
}
669669

670+
670671
#if !defined(WOLFSSH_NO_SSH_RSA_SHA2_256) || \
671672
!defined(WOLFSSH_NO_SSH_RSA_SHA2_512)
673+
672674
static int SignHashRsa(WOLFSSH_AGENT_KEY_RSA* rawKey, enum wc_HashType hashType,
673675
const byte* digest, word32 digestSz, byte* sig, word32* sigSz,
674676
WC_RNG* rng, void* heap)
@@ -707,7 +709,13 @@ static int SignHashRsa(WOLFSSH_AGENT_KEY_RSA* rawKey, enum wc_HashType hashType,
707709

708710
return ret;
709711
}
710-
#endif
712+
713+
#endif /* WOLFSSH_NO_SSH_RSA_SHA2_256/512 */
714+
715+
716+
#if !defined(WOLFSSH_NO_ECDSA_SHA2_NISTP256) || \
717+
!defined(WOLFSSH_NO_ECDSA_SHA2_NISTP384) || \
718+
!defined(WOLFSSH_NO_ECDSA_SHA2_NISTP521)
711719

712720
static int SignHashEcc(WOLFSSH_AGENT_KEY_ECDSA* rawKey, int curveId,
713721
const byte* digest, word32 digestSz,
@@ -763,6 +771,8 @@ static int SignHashEcc(WOLFSSH_AGENT_KEY_ECDSA* rawKey, int curveId,
763771
return ret;
764772
}
765773

774+
#endif /* WOLFSSH_NO_ECDSA_SHA2_NISTP256/384/521 */
775+
766776

767777
static int PostSignRequest(WOLFSSH_AGENT_CTX* agent,
768778
byte* keyBlob, word32 keyBlobSz, byte* data, word32 dataSz,
@@ -825,7 +835,7 @@ static int PostSignRequest(WOLFSSH_AGENT_CTX* agent,
825835
signEcc = 1;
826836
break;
827837
#endif
828-
#ifndef WOLFSSH_NO_ECDSA_SHA2_NISTP512
838+
#ifndef WOLFSSH_NO_ECDSA_SHA2_NISTP521
829839
case ID_ECDSA_SHA2_NISTP521:
830840
hashType = WC_HASH_TYPE_SHA512;
831841
curveId = ECC_SECP521R1;
@@ -854,7 +864,7 @@ static int PostSignRequest(WOLFSSH_AGENT_CTX* agent,
854864
#endif
855865
#if !defined(WOLFSSH_NO_ECDSA_SHA2_NISTP256) || \
856866
!defined(WOLFSSH_NO_ECDSA_SHA2_NISTP384) || \
857-
!defined(WOLFSSH_NO_ECDSA_SHA2_NISTP512)
867+
!defined(WOLFSSH_NO_ECDSA_SHA2_NISTP521)
858868
if (signEcc)
859869
ret = SignHashEcc(&id->key.ecdsa, curveId, digest, digestSz,
860870
sig, &sigSz, &agent->rng);

src/keygen.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
#include <wolfssl/wolfcrypt/random.h>
4040
#include <wolfssl/wolfcrypt/rsa.h>
41+
#include <wolfssh/internal.h>
4142
#include <wolfssh/error.h>
4243
#include <wolfssh/keygen.h>
4344
#include <wolfssh/log.h>
@@ -57,7 +58,7 @@
5758
int wolfSSH_MakeRsaKey(byte* out, word32 outSz,
5859
word32 size, word32 e)
5960
{
60-
#ifndef NO_RSA
61+
#ifndef WOLFSSH_NO_RSA
6162

6263
int ret = WS_SUCCESS;
6364
WC_RNG rng;

wolfssh/internal.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -507,16 +507,6 @@ struct WS_SFTP_RENAME_STATE;
507507

508508
struct WOLFSSH_AGENT_CTX;
509509

510-
#ifdef WOLFSSH_FWD
511-
typedef enum FwdStates {
512-
FWD_STATE_INIT,
513-
FWD_STATE_LISTEN,
514-
FWD_STATE_CONNECTING,
515-
FWD_STATE_FORWARDING,
516-
FWD_STATE_CLEANUP,
517-
} WS_FwdStates;
518-
#endif /* WOLFSSH_FWD */
519-
520510
/* our wolfSSH session */
521511
struct WOLFSSH {
522512
WOLFSSH_CTX* ctx; /* owner context */

0 commit comments

Comments
 (0)