Skip to content

Commit 14b6fe2

Browse files
committed
Fix guards on the sp_int.c invmod helpers and the ACME encoder
sp_invmod() is built whenever WOLFSSL_SP_INVMOD is set, which settings.h does for OPENSSL_EXTRA and DSA as well as ECC and RSA private keys. The functions it and sp_div() call, _sp_cmp_abs(), _sp_set(), _sp_sub_off(), sp_lshb(), sp_div(), sp_mod(), sp_mul(), sp_sub() and sp_rshb(), were built only for MATH_ALL, DH, ECC or RSA, so a WOLFSSL_SP_MATH build with OPENSSL_EXTRA and without DH or ECC (no RSA, or RSA public-only or verify-only) failed on implicit declarations or undefined symbols. Add WOLFSSL_SP_INVMOD to their guards and to the sp_div() prototype and prefix-map rename. _sp_cmp() had OPENSSL_EXTRA in its guard although none of its callers are built for it, which left it unused in the same builds, so drop that term. The ACME identifier extension data in struct Cert and DerCert is under WOLFSSL_CERT_EXT, but the code in EncodeExtensions(), the original ASN encoder and its API test was guarded by WOLFSSL_ACME_OID alone, so WOLFSSL_CERT_GEN with WOLFSSL_ACME_OID and without WOLFSSL_CERT_EXT did not compile. Guard them with both. test_wc_CheckPrivateKey_RSA_pub_only calls wc_CheckPrivateKey(), which is WOLFSSL_LOCAL, so a shared --enable-rsapub build did not link the unit test. Build it only with WOLFSSL_TEST_STATIC_BUILD, like the other tests of local functions. Add os-check legs for these builds, the ACME one also through the original ASN encoder, and for the WOLFSSL_PUBLIC_MP and IGNORE_NETSCAPE_CERT_TYPE builds fixed earlier on this branch.
1 parent d4cbe22 commit 14b6fe2

6 files changed

Lines changed: 55 additions & 26 deletions

File tree

‎.github/configs/os-check-linux.json‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,5 +664,28 @@
664664
{"name": "sp-math-sakke",
665665
"comment": "SAKKE on WOLFSSL_SP_MATH without RSA, DH, or ECCSI: its blinded RSK inverse needs sp_mulmod, which nothing else builds in this shape.",
666666
"configure": ["--enable-cryptonly", "--enable-sp-math", "--enable-sp",
667-
"--disable-rsa", "--disable-dh", "--enable-sakke"]}
667+
"--disable-rsa", "--disable-dh", "--enable-sakke"]},
668+
{"name": "sp-math-public-mp-no-pk",
669+
"comment": "WOLFSSL_PUBLIC_MP on WOLFSSL_SP_MATH without RSA, DH or ECC: mp_toradix needs _sp_copy, which nothing else builds in this shape.",
670+
"configure": ["--enable-cryptonly", "--enable-sp-math", "--disable-rsa",
671+
"--disable-dh", "--disable-ecc", "CPPFLAGS=-DWOLFSSL_PUBLIC_MP"]},
672+
{"name": "sp-math-opensslextra-rsapub",
673+
"comment": "OPENSSL_EXTRA builds sp_invmod on WOLFSSL_SP_MATH even when RSA is public-only and there is no DH or ECC.",
674+
"configure": ["--enable-cryptonly", "--enable-sp-math", "--enable-opensslextra",
675+
"--disable-dh", "--disable-ecc", "--enable-rsapub"]},
676+
{"name": "sp-math-opensslextra-no-rsa",
677+
"comment": "As sp-math-opensslextra-rsapub, with no RSA at all.",
678+
"configure": ["--enable-cryptonly", "--enable-sp-math", "--enable-opensslextra",
679+
"--disable-dh", "--disable-ecc", "--disable-rsa"]},
680+
{"name": "certgen-acme-no-certext",
681+
"comment": "The ACME identifier extension data lives under WOLFSSL_CERT_EXT, so WOLFSSL_ACME_OID alone must not reach it.",
682+
"configure": ["--enable-certgen", "--disable-certext", "CPPFLAGS=-DWOLFSSL_ACME_OID"]},
683+
{"name": "certgen-acme-no-certext-asn-original",
684+
"comment": "As certgen-acme-no-certext, through the original ASN encoder.",
685+
"configure": ["--enable-asn=original", "--enable-certgen", "--disable-certext",
686+
"CPPFLAGS=-DWOLFSSL_ACME_OID"]},
687+
{"name": "certext-ignore-netscape",
688+
"comment": "Certificate extensions without the Netscape certificate type.",
689+
"configure": ["--enable-certgen", "--enable-certext",
690+
"CPPFLAGS=-DIGNORE_NETSCAPE_CERT_TYPE"]}
668691
]

‎tests/api.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14306,8 +14306,8 @@ static int test_wc_SetAcmeIdentifierExt(void)
1430614306
{
1430714307
EXPECT_DECLS;
1430814308
#if defined(WOLFSSL_ACME_OID) && defined(WOLFSSL_CERT_GEN) && \
14309-
defined(HAVE_ECC) && !defined(NO_SHA256) && !defined(NO_ASN_TIME) && \
14310-
!defined(WC_NO_RNG) && !defined(NO_RSA)
14309+
defined(WOLFSSL_CERT_EXT) && defined(HAVE_ECC) && !defined(NO_SHA256) && \
14310+
!defined(NO_ASN_TIME) && !defined(WC_NO_RNG) && !defined(NO_RSA)
1431114311
Cert cert;
1431214312
DecodedCert decoded;
1431314313
WC_RNG rng;
@@ -33708,7 +33708,7 @@ static int test_wc_CheckPrivateKey_RSA_pub_only(void)
3370833708
{
3370933709
EXPECT_DECLS;
3371033710
#if !defined(NO_RSA) && !defined(NO_ASN_CRYPT) && \
33711-
!defined(NO_CHECK_PRIVATE_KEY) && \
33711+
!defined(NO_CHECK_PRIVATE_KEY) && defined(WOLFSSL_TEST_STATIC_BUILD) && \
3371233712
(defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_RSA_VERIFY_ONLY))
3371333713
/* With RSA public-only or verify-only, wc_CheckPrivateKey should return
3371433714
* NOT_COMPILED_IN for RSA key types since private key operations are not

‎wolfcrypt/src/asn.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31612,7 +31612,7 @@ static int EncodeExtensions(Cert* cert, byte* output, word32 maxSz,
3161231612
CERTEXTSASN_IDX_CRLINFO_STR);
3161331613
}
3161431614

31615-
#ifdef WOLFSSL_ACME_OID
31615+
#if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ACME_OID)
3161631616
/* id-pe-acmeIdentifier (TLS-ALPN-01 challenge cert).
3161731617
* Always critical=TRUE. */
3161831618
if (cert->acmeIdentifierSz == WC_SHA256_DIGEST_SIZE) {
@@ -31623,7 +31623,7 @@ static int EncodeExtensions(Cert* cert, byte* output, word32 maxSz,
3162331623
cert->acmeIdentifier, (word32)cert->acmeIdentifierSz);
3162431624
}
3162531625
else
31626-
#endif /* WOLFSSL_ACME_OID */
31626+
#endif /* WOLFSSL_CERT_EXT && WOLFSSL_ACME_OID */
3162731627
{
3162831628
/* Don't write out the ACME identifier extension. */
3162931629
SetASNItem_NoOut(dataASN, CERTEXTSASN_IDX_ACMEID_SEQ,

‎wolfcrypt/src/asn_orig.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6486,7 +6486,7 @@ static int EncodeCert(Cert* cert, DerCert* der, RsaKey* rsaKey, ecc_key* eccKey,
64866486
der->certPoliciesSz = 0;
64876487
#endif /* WOLFSSL_CERT_EXT */
64886488

6489-
#ifdef WOLFSSL_ACME_OID
6489+
#if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ACME_OID)
64906490
/* RFC 8737 id-pe-acmeIdentifier (TLS-ALPN-01 challenge cert).
64916491
* Always critical=TRUE. */
64926492
if (cert->acmeIdentifierSz == WC_SHA256_DIGEST_SIZE) {
@@ -6599,7 +6599,7 @@ static int EncodeCert(Cert* cert, DerCert* der, RsaKey* rsaKey, ecc_key* eccKey,
65996599
}
66006600
#endif /* WOLFSSL_CERT_EXT */
66016601

6602-
#ifdef WOLFSSL_ACME_OID
6602+
#if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ACME_OID)
66036603
/* put ACME Identifier */
66046604
if (der->acmeIdSz) {
66056605
ret = SetExtensions(der->extensions, sizeof(der->extensions),

‎wolfcrypt/src/sp_int.c‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5771,7 +5771,7 @@ int sp_abs(const sp_int* a, sp_int* r)
57715771
#endif /* WOLFSSL_SP_INT_NEGATIVE */
57725772

57735773
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
5774-
!defined(NO_RSA)
5774+
!defined(NO_RSA) || defined(WOLFSSL_SP_INVMOD)
57755775
/* Compare absolute value of two multi-precision numbers.
57765776
*
57775777
* @param [in] a SP integer.
@@ -5854,7 +5854,7 @@ int sp_cmp_mag(const sp_int* a, const sp_int* b)
58545854
#endif
58555855

58565856
#if defined(WOLFSSL_SP_MATH_ALL) || defined(HAVE_ECC) || !defined(NO_DSA) || \
5857-
defined(OPENSSL_EXTRA) || !defined(NO_DH) || !defined(NO_RSA)
5857+
!defined(NO_DH) || !defined(NO_RSA)
58585858
/* Compare two multi-precision numbers.
58595859
*
58605860
* Assumes a and b are not NULL.
@@ -6326,7 +6326,7 @@ int sp_2expt(sp_int* a, int e)
63266326
**********************/
63276327

63286328
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_RSA) || !defined(NO_DH) || \
6329-
defined(HAVE_ECC)
6329+
defined(HAVE_ECC) || defined(WOLFSSL_SP_INVMOD)
63306330
/* Set the multi-precision number to be the value of the digit.
63316331
*
63326332
* @param [out] a SP integer to become number.
@@ -7815,7 +7815,7 @@ static void _sp_add_off(const sp_int* a, const sp_int* b, sp_int* r, int o)
78157815

78167816
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_INT_NEGATIVE) || \
78177817
!defined(NO_DH) || defined(HAVE_ECC) || (!defined(NO_RSA) && \
7818-
!defined(WOLFSSL_RSA_VERIFY_ONLY))
7818+
!defined(WOLFSSL_RSA_VERIFY_ONLY)) || defined(WOLFSSL_SP_INVMOD)
78197819
/* Sub offset b from a into r: r = a - (b << (o * SP_WORD_SIZE))
78207820
* a must be greater than b.
78217821
*
@@ -7896,7 +7896,8 @@ static void _sp_sub_off(const sp_int* a, const sp_int* b, sp_int* r,
78967896
sp_clamp(r);
78977897
}
78987898
#endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_SP_INT_NEGATIVE || !NO_DH ||
7899-
* HAVE_ECC || (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) */
7899+
* HAVE_ECC || (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) ||
7900+
* WOLFSSL_SP_INVMOD */
79007901

79017902
#if !defined(WOLFSSL_RSA_VERIFY_ONLY) || defined(WOLFSSL_SP_INVMOD)
79027903
/* Add b to a into r: r = a + b
@@ -7956,7 +7957,8 @@ int sp_add(const sp_int* a, const sp_int* b, sp_int* r)
79567957
#endif /* !WOLFSSL_RSA_VERIFY_ONLY */
79577958

79587959
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
7959-
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
7960+
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
7961+
defined(WOLFSSL_SP_INVMOD)
79607962
/* Subtract b from a into r: r = a - b
79617963
*
79627964
* a must be greater than b unless WOLFSSL_SP_INT_NEGATIVE is defined.
@@ -8022,7 +8024,7 @@ int sp_sub(const sp_int* a, const sp_int* b, sp_int* r)
80228024
return err;
80238025
}
80248026
#endif /* WOLFSSL_SP_MATH_ALL || !NO_DH || HAVE_ECC ||
8025-
* (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY)*/
8027+
* (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) || WOLFSSL_SP_INVMOD */
80268028

80278029
/****************************
80288030
* Add/Subtract mod functions
@@ -8634,7 +8636,7 @@ int sp_lshd(sp_int* a, int s)
86348636

86358637
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
86368638
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
8637-
!defined(WOLFSSL_RSA_PUBLIC_ONLY))
8639+
!defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_SP_INVMOD)
86388640
/* Left shift the multi-precision number by n bits.
86398641
* Bits may be larger than the word size.
86408642
*
@@ -8700,7 +8702,8 @@ static int sp_lshb(sp_int* a, int n)
87008702
return err;
87018703
}
87028704
#endif /* WOLFSSL_SP_MATH_ALL || !NO_DH || HAVE_ECC ||
8703-
* (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) */
8705+
* (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY && !WOLFSSL_RSA_PUBLIC_ONLY) ||
8706+
* WOLFSSL_SP_INVMOD */
87048707

87058708
#ifdef WOLFSSL_SP_MATH_ALL
87068709
/* Shift a right by c digits: a = a >> (c * SP_WORD_SIZE)
@@ -8733,7 +8736,7 @@ void sp_rshd(sp_int* a, int c)
87338736

87348737
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
87358738
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
8736-
defined(WOLFSSL_HAVE_SP_DH)
8739+
defined(WOLFSSL_HAVE_SP_DH) || defined(WOLFSSL_SP_INVMOD)
87378740
/* Shift a right by n bits into r: r = a >> n
87388741
*
87398742
* @param [in] a SP integer to shift.
@@ -8801,11 +8804,12 @@ int sp_rshb(const sp_int* a, int n, sp_int* r)
88018804
return err;
88028805
}
88038806
#endif /* WOLFSSL_SP_MATH_ALL || !NO_DH || HAVE_ECC ||
8804-
* (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) || WOLFSSL_HAVE_SP_DH */
8807+
* (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) || WOLFSSL_HAVE_SP_DH ||
8808+
* WOLFSSL_SP_INVMOD */
88058809

88068810
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
88078811
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
8808-
!defined(WOLFSSL_RSA_PUBLIC_ONLY))
8812+
!defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_SP_INVMOD)
88098813
static void _sp_div_same_size(sp_int* a, const sp_int* d, sp_int* r)
88108814
{
88118815
sp_size_t i;
@@ -9271,11 +9275,12 @@ int sp_div(const sp_int* a, const sp_int* d, sp_int* r, sp_int* rem)
92719275
return err;
92729276
}
92739277
#endif /* WOLFSSL_SP_MATH_ALL || !NO_DH || HAVE_ECC || \
9274-
* (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) */
9278+
* (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY && !WOLFSSL_RSA_PUBLIC_ONLY) ||
9279+
* WOLFSSL_SP_INVMOD */
92759280

92769281
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
92779282
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
9278-
!defined(WOLFSSL_RSA_PUBLIC_ONLY))
9283+
!defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_SP_INVMOD)
92799284
#ifndef FREESCALE_LTC_TFM
92809285
#ifdef WOLFSSL_SP_INT_NEGATIVE
92819286
/* Calculate the remainder of dividing a by m: r = a mod m.
@@ -9367,10 +9372,11 @@ int sp_mod(const sp_int* a, const sp_int* m, sp_int* r)
93679372
}
93689373
#endif /* !FREESCALE_LTC_TFM */
93699374
#endif /* WOLFSSL_SP_MATH_ALL || !NO_DH || HAVE_ECC || \
9370-
* (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY) */
9375+
* (!NO_RSA && !WOLFSSL_RSA_VERIFY_ONLY && !WOLFSSL_RSA_PUBLIC_ONLY) || \
9376+
* WOLFSSL_SP_INVMOD */
93719377

93729378
#if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
9373-
defined(HAVE_ECC) || !defined(NO_RSA)
9379+
defined(HAVE_ECC) || !defined(NO_RSA) || defined(WOLFSSL_SP_INVMOD)
93749380

93759381
/* START SP_MUL implementations. */
93769382
/* This code is generated.

‎wolfssl/wolfcrypt/sp_int.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ typedef sp_int_digit mp_digit;
11331133

11341134
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
11351135
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
1136-
!defined(WOLFSSL_RSA_PUBLIC_ONLY))
1136+
!defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_SP_INVMOD)
11371137
#define sp_div wc_sp_div
11381138
#endif
11391139
#define sp_mod wc_sp_mod
@@ -1287,7 +1287,7 @@ MP_API int sp_rshb(const sp_int* a, int n, sp_int* r);
12871287

12881288
#if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
12891289
(!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
1290-
!defined(WOLFSSL_RSA_PUBLIC_ONLY))
1290+
!defined(WOLFSSL_RSA_PUBLIC_ONLY)) || defined(WOLFSSL_SP_INVMOD)
12911291
MP_API int sp_div(const sp_int* a, const sp_int* d, sp_int* r, sp_int* rem);
12921292
#endif
12931293
MP_API int sp_mod(const sp_int* a, const sp_int* m, sp_int* r);

0 commit comments

Comments
 (0)