Skip to content

Commit 23f5955

Browse files
Fix building with --enable-keygen --enable-rsavfy.
1 parent 1f33b99 commit 23f5955

6 files changed

Lines changed: 45 additions & 29 deletions

File tree

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

@@ -34074,7 +34078,7 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3407434078
{
3407534079
switch(ssl->specs.kea)
3407634080
{
34077-
#ifndef NO_RSA
34081+
#if !defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
3407834082
case rsa_kea:
3407934083
{
3408034084
ret = RsaEnc(ssl,
@@ -34090,7 +34094,7 @@ int SendClientKeyExchange(WOLFSSL* ssl)
3409034094

3409134095
break;
3409234096
}
34093-
#endif /* !NO_RSA */
34097+
#endif /* !NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY */
3409434098
#ifndef NO_DH
3409534099
case diffie_hellman_kea:
3409634100
{
@@ -34921,7 +34925,8 @@ int SendCertificateVerify(WOLFSSL* ssl)
3492134925
);
3492234926
}
3492334927
#endif /* HAVE_ED448 && !NO_ED448_CLIENT_AUTH */
34924-
#ifndef NO_RSA
34928+
#if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
34929+
!defined(WOLFSSL_RSA_VERIFY_ONLY)
3492534930
if (ssl->hsType == DYNAMIC_TYPE_RSA) {
3492634931
RsaKey* key = (RsaKey*)ssl->hsKey;
3492734932

@@ -34935,7 +34940,7 @@ int SendCertificateVerify(WOLFSSL* ssl)
3493534940
ssl->buffers.key
3493634941
);
3493734942
}
34938-
#endif /* !NO_RSA */
34943+
#endif /* !NO_RSA && !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
3493934944

3494034945
/* Check for error */
3494134946
if (ret != 0) {
@@ -36999,7 +37004,9 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3699937004
/* Sign hash to create signature */
3700037005
switch (ssl->options.sigAlgo)
3700137006
{
37002-
#ifndef NO_RSA
37007+
#if !defined(NO_RSA) && \
37008+
!defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
37009+
!defined(WOLFSSL_RSA_VERIFY_ONLY)
3700337010
#ifdef WC_RSA_PSS
3700437011
case rsa_pss_sa_algo:
3700537012
#endif
@@ -37018,7 +37025,8 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3701837025
);
3701937026
break;
3702037027
}
37021-
#endif /* !NO_RSA */
37028+
#endif /* !NO_RSA && !WOLFSSL_RSA_PUBLIC_ONLY
37029+
&& !WOLFSSL_RSA_VERIFY_ONLY */
3702237030
#ifdef HAVE_ECC
3702337031
#if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)
3702437032
case sm2_sa_algo:
@@ -37112,7 +37120,9 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3711237120
/* Sign hash to create signature */
3711337121
switch (ssl->options.sigAlgo)
3711437122
{
37115-
#ifndef NO_RSA
37123+
#if !defined(NO_RSA) && \
37124+
!defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
37125+
!defined(WOLFSSL_RSA_VERIFY_ONLY)
3711637126
#ifdef WC_RSA_PSS
3711737127
case rsa_pss_sa_algo:
3711837128
#endif
@@ -37135,7 +37145,8 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3713537145
);
3713637146
break;
3713737147
}
37138-
#endif /* NO_RSA */
37148+
#endif /* !NO_RSA && !WOLFSSL_RSA_PUBLIC_ONLY
37149+
&& !WOLFSSL_RSA_VERIFY_ONLY */
3713937150
default:
3714037151
break;
3714137152
} /* switch (ssl->options.sigAlgo) */
@@ -41815,7 +41826,7 @@ static int DefTicketEncCb(WOLFSSL* ssl, byte key_name[WOLFSSL_TICKET_NAME_SZ],
4181541826
case TLS_ASYNC_DO:
4181641827
{
4181741828
switch (ssl->specs.kea) {
41818-
#ifndef NO_RSA
41829+
#if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
4181941830
case rsa_kea:
4182041831
{
4182141832
RsaKey* key = (RsaKey*)ssl->hsKey;
@@ -41851,7 +41862,7 @@ static int DefTicketEncCb(WOLFSSL* ssl, byte key_name[WOLFSSL_TICKET_NAME_SZ],
4185141862
ret = 0;
4185241863
break;
4185341864
} /* rsa_kea */
41854-
#endif /* !NO_RSA */
41865+
#endif /* !NO_RSA && !WOLFSSL_RSA_PUBLIC_ONLY */
4185541866
#ifndef NO_PSK
4185641867
case psk_kea:
4185741868
{

src/tls13.c

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

95749575
/* Check for error */
95759576
if (ret != 0) {
@@ -9602,7 +9603,8 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
96029603
);
96039604
}
96049605
#endif /* HAVE_ECC */
9605-
#ifndef NO_RSA
9606+
#if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
9607+
!defined(WOLFSSL_RSA_VERIFY_ONLY)
96069608
if (ssl->hsAltType == DYNAMIC_TYPE_RSA) {
96079609
args->toSign = rsaSigBuf->buffer;
96089610
args->toSignSz = (word32)rsaSigBuf->length;
@@ -9624,7 +9626,7 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
96249626
XMEMCPY(args->altSigData, sigOut, args->altSigLen);
96259627
}
96269628
}
9627-
#endif /* !NO_RSA */
9629+
#endif /* !NO_RSA && !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
96289630
#if defined(HAVE_FALCON)
96299631
if (ssl->hsAltType == DYNAMIC_TYPE_FALCON) {
96309632
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)