Skip to content

Commit 46281a2

Browse files
authored
Merge pull request #9287 from douzzer/20251009-more-WOLFSSL_API_PREFIX_MAP
20251009-more-WOLFSSL_API_PREFIX_MAP
2 parents 9633248 + f767bd2 commit 46281a2

12 files changed

Lines changed: 224 additions & 86 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: WOLFSSL_API_PREFIX_MAP
2+
3+
# START OF COMMON SECTION
4+
on:
5+
push:
6+
branches: [ 'master', 'main', 'release/**' ]
7+
pull_request:
8+
branches: [ '*' ]
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
# END OF COMMON SECTION
14+
15+
jobs:
16+
make_and_analyze:
17+
strategy:
18+
matrix:
19+
config: [
20+
'--enable-all --enable-mlkem --enable-mldsa --enable-xmss --enable-lms --enable-acert --with-sys-crypto-policy CFLAGS=-DWOLFSSL_API_PREFIX_MAP'
21+
]
22+
name: make and analyze
23+
if: github.repository_owner == 'wolfssl'
24+
runs-on: ubuntu-22.04
25+
# This should be a safe limit for the tests to run.
26+
timeout-minutes: 6
27+
steps:
28+
- uses: actions/checkout@v4
29+
name: Checkout wolfSSL
30+
31+
- name: Test --enable-opensslcoexist and TEST_OPENSSL_COEXIST
32+
run: |
33+
./autogen.sh || $(exit 2)
34+
./configure ${{ matrix.config }} || $(exit 3)
35+
make -j 4 || $(exit 4)
36+
# ignore properly prefixed symbols, and symbols associated with asm implementations (all internal) regardless of prefix:
37+
readelf --symbols --wide src/.libs/libwolfssl.so | \
38+
awk '
39+
BEGIN {
40+
total_public_symbols = 0;
41+
unprefixed_public_symbols = 0;
42+
}
43+
{
44+
if (($5 == "GLOBAL") && ($6 != "HIDDEN") && ($7 ~ /^[0-9]+$/)) {
45+
++total_public_symbols;
46+
}
47+
}
48+
{
49+
if (($7 !~ /^[0-9]+$/) ||
50+
($8 ~ /^(wc_|wolf|WOLF|__pfx|fe_|sp_[a-zA-Z090-0_]*[0-9])/) ||
51+
($8 ~ /(_avx[12]|_AVX[12]|_sse[12]|_SSE[12]|_aesni|_AESNI|_bmi2|_x64$)/))
52+
{
53+
next;
54+
}
55+
}
56+
{
57+
if (($4 == "FUNC") && ($5 == "GLOBAL") && ($6 == "DEFAULT")) {
58+
++unprefixed_public_symbols;
59+
print;
60+
}
61+
}
62+
END {
63+
if (unprefixed_public_symbols) {
64+
print unprefixed_public_symbols " unprefixed public symbols found, of " total_public_symbols " total." >"/dev/stderr";
65+
exit(1);
66+
} else {
67+
print total_public_symbols " public symbols found in libwolfssl, all OK.";
68+
exit(0);
69+
}
70+
}' || $(exit 5)

configure.ac

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,14 +1503,14 @@ AC_ARG_WITH([liboqs],
15031503
# MLKEM
15041504
# Used:
15051505
# - SHA3, Shake128 and Shake256
1506-
AC_ARG_ENABLE([kyber],
1507-
[AS_HELP_STRING([--enable-kyber],[Enable Kyber/MLKEM (default: disabled)])],
1506+
AC_ARG_ENABLE([mlkem],
1507+
[AS_HELP_STRING([--enable-mlkem],[Enable MLKEM (default: disabled)])],
15081508
[ ENABLED_MLKEM=$enableval ],
15091509
[ ENABLED_MLKEM=no ]
15101510
)
1511-
# note, inherits default from "kyber" clause above.
1512-
AC_ARG_ENABLE([mlkem],
1513-
[AS_HELP_STRING([--enable-mlkem],[Enable MLKEM (default: disabled)])],
1511+
# note, inherits default from "mlkem" clause above.
1512+
AC_ARG_ENABLE([kyber],
1513+
[AS_HELP_STRING([--enable-kyber],[Enable Kyber/MLKEM (default: disabled)])],
15141514
[ ENABLED_MLKEM=$enableval ]
15151515
)
15161516

@@ -1639,11 +1639,16 @@ fi
16391639

16401640
# Dilithium
16411641
# - SHA3, Shake128, Shake256 and AES-CTR
1642-
AC_ARG_ENABLE([dilithium],
1643-
[AS_HELP_STRING([--enable-dilithium],[Enable DILITHIUM (default: disabled)])],
1642+
AC_ARG_ENABLE([mldsa],
1643+
[AS_HELP_STRING([--enable-mldsa],[Enable MLDSA (default: disabled)])],
16441644
[ ENABLED_DILITHIUM=$enableval ],
16451645
[ ENABLED_DILITHIUM=no ]
16461646
)
1647+
# note, inherits default from "mldsa" clause above.
1648+
AC_ARG_ENABLE([dilithium],
1649+
[AS_HELP_STRING([--enable-dilithium],[Enable Dilithium/MLDSA (default: disabled)])],
1650+
[ ENABLED_DILITHIUM=$enableval ]
1651+
)
16471652

16481653
ENABLED_DILITHIUM_OPTS=$ENABLED_DILITHIUM
16491654
ENABLED_DILITHIUM_MAKE_KEY=no
@@ -4924,15 +4929,6 @@ AC_ARG_ENABLE([tlsv12],
49244929
[ ENABLED_TLSV12=yes ]
49254930
)
49264931

4927-
if test "$ENABLED_CRYPTONLY" = "yes"
4928-
then
4929-
ENABLED_TLSV12=no
4930-
fi
4931-
if test "$ENABLED_TLSV12" = "no"
4932-
then
4933-
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_NO_TLS12 -DNO_OLD_TLS"
4934-
fi
4935-
49364932
# STACK SIZE info for testwolfcrypt and examples
49374933
AC_ARG_ENABLE([stacksize],
49384934
[AS_HELP_STRING([--enable-stacksize],[Enable stack size info on examples (default: disabled)])],

linuxkm/linuxkm_wc_port.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,15 @@
228228

229229
#include <linux/kconfig.h>
230230

231+
#ifdef CONFIG_KASAN
232+
#ifndef WC_SANITIZE_DISABLE
233+
#define WC_SANITIZE_DISABLE() kasan_disable_current()
234+
#endif
235+
#ifndef WC_SANITIZE_ENABLE
236+
#define WC_SANITIZE_ENABLE() kasan_enable_current()
237+
#endif
238+
#endif
239+
231240
#if defined(CONFIG_FORTIFY_SOURCE) && \
232241
!defined(WC_FORCE_LINUXKM_FORTIFY_SOURCE) && \
233242
(defined(HAVE_LINUXKM_PIE_SUPPORT) || \
@@ -1286,12 +1295,13 @@
12861295
#endif /* WOLFSSL_USE_SAVE_VECTOR_REGISTERS */
12871296
#endif /* !BUILDING_WOLFSSL */
12881297

1289-
/* Copied from wc_port.h: For FIPS keep the function names the same */
1290-
#ifdef HAVE_FIPS
1291-
#define wc_InitMutex InitMutex
1292-
#define wc_FreeMutex FreeMutex
1293-
#define wc_LockMutex LockMutex
1294-
#define wc_UnLockMutex UnLockMutex
1298+
/* Copied from wc_port.h */
1299+
#if defined(HAVE_FIPS) && !defined(WOLFSSL_API_PREFIX_MAP)
1300+
/* For FIPS keep the function names the same */
1301+
#define wc_InitMutex InitMutex
1302+
#define wc_FreeMutex FreeMutex
1303+
#define wc_LockMutex LockMutex
1304+
#define wc_UnLockMutex UnLockMutex
12951305
#endif /* HAVE_FIPS */
12961306

12971307
#ifdef WOLFSSL_LINUXKM_USE_MUTEXES

wolfcrypt/src/ge_operations.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9817,4 +9817,17 @@ void ge_tobytes(unsigned char *s,const ge_p2 *h)
98179817
}
98189818

98199819
#endif /* !ED25519_SMALL */
9820+
9821+
/* if HAVE_ED25519 but not HAVE_CURVE25519, and an asm implementation is built,
9822+
* then curve25519() won't get its WOLFSSL_LOCAL attribute unless we dummy-call
9823+
* it here.
9824+
*/
9825+
#if defined(WOLFSSL_API_PREFIX_MAP) && !defined(HAVE_CURVE25519) && \
9826+
!defined(FREESCALE_LTC_ECC)
9827+
WOLFSSL_LOCAL void _wc_curve25519_dummy(void);
9828+
WOLFSSL_LOCAL void _wc_curve25519_dummy(void) {
9829+
(void)curve25519((byte *)0, (byte *)0, (const byte *)0);
9830+
}
9831+
#endif
9832+
98209833
#endif /* HAVE_ED25519 */

wolfcrypt/src/poly1305.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,29 +139,29 @@ static cpuid_flags_t intel_flags = WC_CPUID_INITIALIZER;
139139
* ctx Poly1305 context.
140140
* m One block of message data.
141141
*/
142-
extern void poly1305_block_avx(Poly1305* ctx, const unsigned char *m);
142+
WOLFSSL_LOCAL void poly1305_block_avx(Poly1305* ctx, const unsigned char *m);
143143
/* Process multiple blocks (n * 16 bytes) of data.
144144
*
145145
* ctx Poly1305 context.
146146
* m Blocks of message data.
147147
* bytes The number of bytes to process.
148148
*/
149-
extern void poly1305_blocks_avx(Poly1305* ctx, const unsigned char* m,
149+
WOLFSSL_LOCAL void poly1305_blocks_avx(Poly1305* ctx, const unsigned char* m,
150150
size_t bytes);
151151
/* Set the key to use when processing data.
152152
* Initialize the context.
153153
*
154154
* ctx Poly1305 context.
155155
* key The key data (16 bytes).
156156
*/
157-
extern void poly1305_setkey_avx(Poly1305* ctx, const byte* key);
157+
WOLFSSL_LOCAL void poly1305_setkey_avx(Poly1305* ctx, const byte* key);
158158
/* Calculate the final result - authentication data.
159159
* Zeros out the private data in the context.
160160
*
161161
* ctx Poly1305 context.
162162
* mac Buffer to hold 16 bytes.
163163
*/
164-
extern void poly1305_final_avx(Poly1305* ctx, byte* mac);
164+
WOLFSSL_LOCAL void poly1305_final_avx(Poly1305* ctx, byte* mac);
165165
#endif
166166

167167
#ifdef HAVE_INTEL_AVX2
@@ -171,29 +171,29 @@ extern void poly1305_final_avx(Poly1305* ctx, byte* mac);
171171
* m Blocks of message data.
172172
* bytes The number of bytes to process.
173173
*/
174-
extern void poly1305_blocks_avx2(Poly1305* ctx, const unsigned char* m,
174+
WOLFSSL_LOCAL void poly1305_blocks_avx2(Poly1305* ctx, const unsigned char* m,
175175
size_t bytes);
176176
/* Calculate R^1, R^2, R^3 and R^4 and store them in the context.
177177
*
178178
* ctx Poly1305 context.
179179
*/
180-
extern void poly1305_calc_powers_avx2(Poly1305* ctx);
180+
WOLFSSL_LOCAL void poly1305_calc_powers_avx2(Poly1305* ctx);
181181
/* Set the key to use when processing data.
182182
* Initialize the context.
183183
* Calls AVX set key function as final function calls AVX code.
184184
*
185185
* ctx Poly1305 context.
186186
* key The key data (16 bytes).
187187
*/
188-
extern void poly1305_setkey_avx2(Poly1305* ctx, const byte* key);
188+
WOLFSSL_LOCAL void poly1305_setkey_avx2(Poly1305* ctx, const byte* key);
189189
/* Calculate the final result - authentication data.
190190
* Zeros out the private data in the context.
191191
* Calls AVX final function to quickly process last blocks.
192192
*
193193
* ctx Poly1305 context.
194194
* mac Buffer to hold 16 bytes - authentication data.
195195
*/
196-
extern void poly1305_final_avx2(Poly1305* ctx, byte* mac);
196+
WOLFSSL_LOCAL void poly1305_final_avx2(Poly1305* ctx, byte* mac);
197197
#endif
198198

199199
#ifdef __cplusplus

wolfcrypt/test/test.c

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -608,14 +608,12 @@ static wc_test_ret_t hkdf_test(void);
608608
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hkdf_test(void);
609609
#endif
610610
#endif /* HAVE_HKDF && ! NO_HMAC */
611-
#ifdef WOLFSSL_HAVE_PRF
612-
#if defined(HAVE_HKDF) && !defined(NO_HMAC)
613-
#ifdef WOLFSSL_BASE16
611+
#if defined(WOLFSSL_HAVE_PRF) && defined(HAVE_HKDF) && !defined(NO_HMAC) && \
612+
defined(WOLFSSL_BASE16) && !defined(WOLFSSL_NO_TLS12)
614613
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls12_kdf_test(void);
615-
#endif /* WOLFSSL_BASE16 */
616-
#endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
617-
#endif /* WOLFSSL_HAVE_PRF */
618-
#if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
614+
#endif
615+
#if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && \
616+
defined(WOLFSSL_SHA384) && !defined(WOLFSSL_NO_TLS12)
619617
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prf_test(void);
620618
#endif
621619
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sshkdf_test(void);
@@ -1921,27 +1919,26 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
19211919
PRIVATE_KEY_LOCK();
19221920
#endif /* WOLFSSL_WOLFSSH */
19231921

1924-
#if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
1922+
#if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && \
1923+
defined(WOLFSSL_SHA384) && !defined(WOLFSSL_NO_TLS12)
19251924
PRIVATE_KEY_UNLOCK();
19261925
if ( (ret = prf_test()) != 0)
19271926
TEST_FAIL("PRF test failed!\n", ret);
19281927
else
19291928
TEST_PASS("PRF test passed!\n");
19301929
PRIVATE_KEY_LOCK();
1931-
#endif
1930+
#endif /* WOLFSSL_HAVE_PRF && !NO_HMAC && WOLFSSL_SHA384 && !WOLFSSL_NO_TLS12 */
19321931

1933-
#ifdef WOLFSSL_HAVE_PRF
1934-
#if defined (HAVE_HKDF) && !defined(NO_HMAC)
1935-
#ifdef WOLFSSL_BASE16
1932+
#if defined(WOLFSSL_HAVE_PRF) && defined(HAVE_HKDF) && !defined(NO_HMAC) && \
1933+
defined(WOLFSSL_BASE16) && !defined(WOLFSSL_NO_TLS12)
19361934
PRIVATE_KEY_UNLOCK();
19371935
if ( (ret = tls12_kdf_test()) != 0)
19381936
TEST_FAIL("TLSv1.2 KDF test failed!\n", ret);
19391937
else
19401938
TEST_PASS("TLSv1.2 KDF test passed!\n");
19411939
PRIVATE_KEY_LOCK();
1942-
#endif /* WOLFSSL_BASE16 */
1943-
#endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
1944-
#endif /* WOLFSSL_HAVE_PRF */
1940+
#endif /* WOLFSSL_HAVE_PRF && HAVE_HKDF && !NO_HMAC && */
1941+
/* WOLFSSL_BASE16 && !WOLFSSL_NO_TLS12 */
19451942

19461943
#ifdef WOLFSSL_TLS13
19471944
PRIVATE_KEY_UNLOCK();
@@ -28154,7 +28151,8 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sshkdf_test(void)
2815428151

2815528152
#endif /* WOLFSSL_WOLFSSH */
2815628153

28157-
#if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
28154+
#if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && \
28155+
defined(WOLFSSL_SHA384) && !defined(WOLFSSL_NO_TLS12)
2815828156
#define DIGL 12
2815928157
#define SECL 48
2816028158
#define LBSL 63
@@ -28203,11 +28201,10 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prf_test(void)
2820328201

2820428202
return 0;
2820528203
}
28206-
#endif /* WOLFSSL_HAVE_PRF && !NO_HMAC */
28204+
#endif /* WOLFSSL_HAVE_PRF && !NO_HMAC && WOLFSSL_SHA384 && !WOLFSSL_NO_TLS12 */
2820728205

28208-
#ifdef WOLFSSL_HAVE_PRF
28209-
#if defined(HAVE_HKDF) && !defined(NO_HMAC)
28210-
#ifdef WOLFSSL_BASE16
28206+
#if defined(WOLFSSL_HAVE_PRF) && defined(HAVE_HKDF) && !defined(NO_HMAC) && \
28207+
defined(WOLFSSL_BASE16) && !defined(WOLFSSL_NO_TLS12)
2821128208
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls12_kdf_test(void)
2821228209
{
2821328210
const char* preMasterSecret = "D06F9C19BFF49B1E91E4EFE97345D089"
@@ -28252,16 +28249,15 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls12_kdf_test(void)
2825228249
if (ret == WC_NO_ERR_TRACE(FIPS_PRIVATE_KEY_LOCKED_E)) {
2825328250
printf(" wc_PRF_TLSv12: Private key locked.\n");
2825428251
}
28255-
return WC_TEST_RET_ENC_NC;
28252+
return WC_TEST_RET_ENC_EC(ret);
2825628253
}
2825728254

2825828255
if (XMEMCMP(result, ms, msSz) != 0)
2825928256
return WC_TEST_RET_ENC_NC;
2826028257
return 0;
2826128258
}
28262-
#endif /* WOLFSSL_BASE16 */
28263-
#endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
28264-
#endif /* WOLFSSL_HAVE_PRF */
28259+
#endif /* WOLFSSL_HAVE_PRF && HAVE_HKDF && !NO_HMAC && */
28260+
/* WOLFSSL_BASE16 && !WOLFSSL_NO_TLS12 */
2826528261

2826628262
#ifdef WOLFSSL_TLS13
2826728263

wolfssl/internal.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7000,6 +7000,12 @@ WOLFSSL_LOCAL void DtlsSetSeqNumForReply(WOLFSSL* ssl);
70007000
#endif
70017001

70027002
#ifdef WOLFSSL_DTLS13
7003+
#ifdef WOLFSSL_API_PREFIX_MAP
7004+
#define Dtls13GetEpoch wolfSSL_Dtls13GetEpoch
7005+
#define Dtls13CheckEpoch wolfSSL_Dtls13CheckEpoch
7006+
#define Dtls13WriteAckMessage wolfSSL_Dtls13WriteAckMessage
7007+
#define Dtls13RtxAddAck wolfSSL_Dtls13RtxAddAck
7008+
#endif
70037009

70047010
WOLFSSL_TEST_VIS struct Dtls13Epoch* Dtls13GetEpoch(WOLFSSL* ssl,
70057011
w64wrapper epochNumber);
@@ -7096,6 +7102,9 @@ typedef struct CRYPTO_EX_cb_ctx {
70967102
} CRYPTO_EX_cb_ctx;
70977103

70987104
WOLFSSL_TEST_VIS extern CRYPTO_EX_cb_ctx* crypto_ex_cb_ctx_session;
7105+
#ifdef WOLFSSL_API_PREFIX_MAP
7106+
#define crypto_ex_cb_free wolfSSL_crypto_ex_cb_free
7107+
#endif
70997108
WOLFSSL_TEST_VIS void crypto_ex_cb_free(CRYPTO_EX_cb_ctx* cb_ctx);
71007109
WOLFSSL_LOCAL void crypto_ex_cb_setup_new_data(void *new_obj,
71017110
CRYPTO_EX_cb_ctx* cb_ctx, WOLFSSL_CRYPTO_EX_DATA* ex_data);

wolfssl/ssl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@
4545
#include "wolfssl/wolfcrypt/asn.h"
4646
#endif
4747

48+
#if defined(NO_TLS) && !defined(WOLFSSL_NO_TLS12)
49+
/* in NO_TLS builds, WOLFSSL_NO_TLS12 must be defined in the TLS layer, but
50+
* must not be defined in the crypto layer, to allow building the TLS12
51+
* KDFs.
52+
*/
53+
#define WOLFSSL_NO_TLS12
54+
#endif
55+
4856
/* For the types */
4957
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
5058
#include <wolfssl/openssl/compat_types.h>

0 commit comments

Comments
 (0)