Skip to content

Commit eda6c18

Browse files
authored
Merge pull request #9219 from kareem-wolfssl/zd20538
Fix building with --enable-keygen --enable-rsavfy.
2 parents b982f86 + 23f5955 commit eda6c18

File tree

6 files changed

+45
-29
lines changed

6 files changed

+45
-29
lines changed

src/internal.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5013,7 +5013,8 @@ int ConvertHashPss(int hashAlgo, enum wc_HashType* hashType, int* mgf)
50135013
}
50145014
#endif
50155015

5016-
#if !defined(NO_WOLFSSL_SERVER) || !defined(WOLFSSL_NO_CLIENT_AUTH)
5016+
#if (!defined(NO_WOLFSSL_SERVER) || !defined(WOLFSSL_NO_CLIENT_AUTH)) && \
5017+
(!defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
50175018
int RsaSign(WOLFSSL* ssl, const byte* in, word32 inSz, byte* out,
50185019
word32* outSz, int sigAlgo, int hashAlgo, RsaKey* key,
50195020
DerBuffer* keyBufInfo)
@@ -5317,7 +5318,8 @@ int VerifyRsaSign(WOLFSSL* ssl, byte* verifySig, word32 sigSz,
53175318

53185319
#ifndef WOLFSSL_NO_TLS12
53195320

5320-
#if !defined(NO_WOLFSSL_SERVER) || !defined(WOLFSSL_NO_CLIENT_AUTH)
5321+
#if (!defined(NO_WOLFSSL_SERVER) || !defined(WOLFSSL_NO_CLIENT_AUTH)) && \
5322+
!defined(WOLFSSL_RSA_PUBLIC_ONLY)
53215323
int RsaDec(WOLFSSL* ssl, byte* in, word32 inSz, byte** out, word32* outSz,
53225324
RsaKey* key, DerBuffer* keyBufInfo)
53235325
{
@@ -5382,6 +5384,7 @@ int RsaDec(WOLFSSL* ssl, byte* in, word32 inSz, byte** out, word32* outSz,
53825384
}
53835385
#endif /* !NO_WOLFSSL_SERVER) || !WOLFSSL_NO_CLIENT_AUTH */
53845386

5387+
#ifndef WOLFSSL_RSA_VERIFY_ONLY
53855388
int RsaEnc(WOLFSSL* ssl, const byte* in, word32 inSz, byte* out, word32* outSz,
53865389
RsaKey* key, buffer* keyBufInfo)
53875390
{
@@ -5441,6 +5444,7 @@ int RsaEnc(WOLFSSL* ssl, const byte* in, word32 inSz, byte* out, word32* outSz,
54415444

54425445
return ret;
54435446
}
5447+
#endif
54445448

54455449
#endif /* !WOLFSSL_NO_TLS12 */
54465450

@@ -33912,7 +33916,7 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3391233916
{
3391333917
switch(ssl->specs.kea)
3391433918
{
33915-
#ifndef NO_RSA
33919+
#if !defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
3391633920
case rsa_kea:
3391733921
{
3391833922
ret = RsaEnc(ssl,
@@ -33928,7 +33932,7 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3392833932

3392933933
break;
3393033934
}
33931-
#endif /* !NO_RSA */
33935+
#endif /* !NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY */
3393233936
#ifndef NO_DH
3393333937
case diffie_hellman_kea:
3393433938
{
@@ -34759,7 +34763,8 @@ int SendCertificateVerify(WOLFSSL* ssl)
3475934763
);
3476034764
}
3476134765
#endif /* HAVE_ED448 && !NO_ED448_CLIENT_AUTH */
34762-
#ifndef NO_RSA
34766+
#if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
34767+
!defined(WOLFSSL_RSA_VERIFY_ONLY)
3476334768
if (ssl->hsType == DYNAMIC_TYPE_RSA) {
3476434769
RsaKey* key = (RsaKey*)ssl->hsKey;
3476534770

@@ -34773,7 +34778,7 @@ int SendCertificateVerify(WOLFSSL* ssl)
3477334778
ssl->buffers.key
3477434779
);
3477534780
}
34776-
#endif /* !NO_RSA */
34781+
#endif /* !NO_RSA && !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
3477734782

3477834783
/* Check for error */
3477934784
if (ret != 0) {
@@ -36837,7 +36842,9 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3683736842
/* Sign hash to create signature */
3683836843
switch (ssl->options.sigAlgo)
3683936844
{
36840-
#ifndef NO_RSA
36845+
#if !defined(NO_RSA) && \
36846+
!defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
36847+
!defined(WOLFSSL_RSA_VERIFY_ONLY)
3684136848
#ifdef WC_RSA_PSS
3684236849
case rsa_pss_sa_algo:
3684336850
#endif
@@ -36856,7 +36863,8 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3685636863
);
3685736864
break;
3685836865
}
36859-
#endif /* !NO_RSA */
36866+
#endif /* !NO_RSA && !WOLFSSL_RSA_PUBLIC_ONLY
36867+
&& !WOLFSSL_RSA_VERIFY_ONLY */
3686036868
#ifdef HAVE_ECC
3686136869
#if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)
3686236870
case sm2_sa_algo:
@@ -36950,7 +36958,9 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3695036958
/* Sign hash to create signature */
3695136959
switch (ssl->options.sigAlgo)
3695236960
{
36953-
#ifndef NO_RSA
36961+
#if !defined(NO_RSA) && \
36962+
!defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
36963+
!defined(WOLFSSL_RSA_VERIFY_ONLY)
3695436964
#ifdef WC_RSA_PSS
3695536965
case rsa_pss_sa_algo:
3695636966
#endif
@@ -36973,7 +36983,8 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3697336983
);
3697436984
break;
3697536985
}
36976-
#endif /* NO_RSA */
36986+
#endif /* !NO_RSA && !WOLFSSL_RSA_PUBLIC_ONLY
36987+
&& !WOLFSSL_RSA_VERIFY_ONLY */
3697736988
default:
3697836989
break;
3697936990
} /* switch (ssl->options.sigAlgo) */
@@ -41653,7 +41664,7 @@ static int DefTicketEncCb(WOLFSSL* ssl, byte key_name[WOLFSSL_TICKET_NAME_SZ],
4165341664
case TLS_ASYNC_DO:
4165441665
{
4165541666
switch (ssl->specs.kea) {
41656-
#ifndef NO_RSA
41667+
#if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
4165741668
case rsa_kea:
4165841669
{
4165941670
RsaKey* key = (RsaKey*)ssl->hsKey;
@@ -41689,7 +41700,7 @@ static int DefTicketEncCb(WOLFSSL* ssl, byte key_name[WOLFSSL_TICKET_NAME_SZ],
4168941700
ret = 0;
4169041701
break;
4169141702
} /* rsa_kea */
41692-
#endif /* !NO_RSA */
41703+
#endif /* !NO_RSA && !WOLFSSL_RSA_PUBLIC_ONLY */
4169341704
#ifndef NO_PSK
4169441705
case psk_kea:
4169541706
{

src/tls13.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9549,7 +9549,8 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
95499549
args->length = (word16)args->sigLen;
95509550
}
95519551
#endif /* HAVE_DILITHIUM */
9552-
#ifndef NO_RSA
9552+
#if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
9553+
!defined(WOLFSSL_RSA_VERIFY_ONLY)
95539554
if (ssl->hsType == DYNAMIC_TYPE_RSA) {
95549555
args->toSign = rsaSigBuf->buffer;
95559556
args->toSignSz = (word32)rsaSigBuf->length;
@@ -9570,7 +9571,7 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
95709571
XMEMCPY(args->sigData, sigOut, args->sigLen);
95719572
}
95729573
}
9573-
#endif /* !NO_RSA */
9574+
#endif /* !NO_RSA && !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
95749575

95759576
/* Check for error */
95769577
if (ret != 0) {
@@ -9603,7 +9604,8 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
96039604
);
96049605
}
96059606
#endif /* HAVE_ECC */
9606-
#ifndef NO_RSA
9607+
#if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
9608+
!defined(WOLFSSL_RSA_VERIFY_ONLY)
96079609
if (ssl->hsAltType == DYNAMIC_TYPE_RSA) {
96089610
args->toSign = rsaSigBuf->buffer;
96099611
args->toSignSz = (word32)rsaSigBuf->length;
@@ -9625,7 +9627,7 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
96259627
XMEMCPY(args->altSigData, sigOut, args->altSigLen);
96269628
}
96279629
}
9628-
#endif /* !NO_RSA */
9630+
#endif /* !NO_RSA && !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
96299631
#if defined(HAVE_FALCON)
96309632
if (ssl->hsAltType == DYNAMIC_TYPE_FALCON) {
96319633
ret = wc_falcon_sign_msg(args->altSigData,

tests/api/test_rsa.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,8 @@ int test_wc_RsaKeyToPublicDer(void)
771771
int test_wc_RsaPublicEncryptDecrypt(void)
772772
{
773773
EXPECT_DECLS;
774-
#if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
774+
#if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
775+
!defined(WOLFSSL_RSA_PUBLIC_ONLY)
775776
RsaKey key;
776777
WC_RNG rng;
777778
const char inStr[] = TEST_STRING;
@@ -840,14 +841,16 @@ int test_wc_RsaPublicEncryptDecrypt_ex(void)
840841
WC_RNG rng;
841842
const char inStr[] = TEST_STRING;
842843
const word32 inLen = (word32)TEST_STRING_SZ;
843-
const word32 plainSz = (word32)TEST_STRING_SZ;
844-
byte* res = NULL;
845844
int idx = 0;
846845
int bits = TEST_RSA_BITS;
847846
const word32 cipherSz = TEST_RSA_BYTES;
847+
#ifndef WOLFSSL_RSA_PUBLIC_ONLY
848+
const word32 plainSz = (word32)TEST_STRING_SZ;
849+
byte* res = NULL;
848850

849-
WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
850851
WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
852+
#endif
853+
WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
851854
WC_DECLARE_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
852855

853856
WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);

wolfcrypt/benchmark/benchmark.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3656,7 +3656,7 @@ static void* benchmarks_do(void* args)
36563656

36573657
#if !defined(NO_RSA) && !defined(WC_NO_RNG)
36583658
#ifndef HAVE_RENESAS_SYNC
3659-
#if defined(WOLFSSL_KEY_GEN)
3659+
#if defined(WOLFSSL_KEY_GEN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
36603660
if (bench_all || (bench_asym_algs & BENCH_RSA_KEYGEN)) {
36613661
#ifndef NO_SW_BENCH
36623662
if (((word32)bench_asym_algs == 0xFFFFFFFFU) ||
@@ -3686,7 +3686,7 @@ static void* benchmarks_do(void* args)
36863686
#endif
36873687
}
36883688

3689-
#ifdef WOLFSSL_KEY_GEN
3689+
#if defined(WOLFSSL_KEY_GEN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
36903690
if (bench_asym_algs & BENCH_RSA_SZ) {
36913691
#ifndef NO_SW_BENCH
36923692
bench_rsa_key(0, bench_size);
@@ -8763,7 +8763,7 @@ void bench_srtpkdf(void)
87638763

87648764
#ifndef NO_RSA
87658765

8766-
#if defined(WOLFSSL_KEY_GEN)
8766+
#if defined(WOLFSSL_KEY_GEN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
87678767
static void bench_rsaKeyGen_helper(int useDeviceID, word32 keySz)
87688768
{
87698769
WC_DECLARE_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
@@ -8871,7 +8871,7 @@ void bench_rsaKeyGen_size(int useDeviceID, word32 keySz)
88718871
{
88728872
bench_rsaKeyGen_helper(useDeviceID, keySz);
88738873
}
8874-
#endif /* WOLFSSL_KEY_GEN */
8874+
#endif /* WOLFSSL_KEY_GEN && !WOLFSSL_RSA_PUBLIC_ONLY */
88758875

88768876
#if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
88778877
!defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
@@ -9341,7 +9341,7 @@ void bench_rsa(int useDeviceID)
93419341
}
93429342

93439343

9344-
#ifdef WOLFSSL_KEY_GEN
9344+
#if defined(WOLFSSL_KEY_GEN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
93459345
/* bench any size of RSA key */
93469346
void bench_rsa_key(int useDeviceID, word32 rsaKeySz)
93479347
{

wolfcrypt/src/rsa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4469,7 +4469,7 @@ int wc_RsaExportKey(RsaKey* key,
44694469
#endif
44704470

44714471

4472-
#ifdef WOLFSSL_KEY_GEN
4472+
#if defined(WOLFSSL_KEY_GEN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
44734473

44744474
/* Check that |p-q| > 2^((size/2)-100) */
44754475
static int wc_CompareDiffPQ(mp_int* p, mp_int* q, int size, int* valid)

wolfcrypt/test/test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19187,7 +19187,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
1918719187
#endif /* !NO_RSA */
1918819188

1918919189
#if !defined(NO_RSA) || !defined(NO_DSA)
19190-
#ifdef WOLFSSL_KEY_GEN
19190+
#if defined(WOLFSSL_KEY_GEN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
1919119191
static const char* keyDerFile = CERT_WRITE_TEMP_DIR "key.der";
1919219192
static const char* keyPemFile = CERT_WRITE_TEMP_DIR "key.pem";
1919319193
#endif
@@ -21927,7 +21927,7 @@ static wc_test_ret_t rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp)
2192721927
}
2192821928
#endif /* !NO_RSA && HAVE_ECC && WOLFSSL_CERT_GEN */
2192921929

21930-
#ifdef WOLFSSL_KEY_GEN
21930+
#if defined(WOLFSSL_KEY_GEN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
2193121931
static wc_test_ret_t rsa_keygen_test(WC_RNG* rng)
2193221932
{
2193321933
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
@@ -22861,7 +22861,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void)
2286122861
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
2286222862
#endif /* WOLFSSL_CERT_EXT */
2286322863

22864-
#ifdef WOLFSSL_KEY_GEN
22864+
#if defined(WOLFSSL_KEY_GEN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
2286522865
ret = rsa_keygen_test(&rng);
2286622866
if (ret != 0)
2286722867
goto exit_rsa;

0 commit comments

Comments
 (0)