Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -9955,7 +9955,11 @@ int AllocKey(WOLFSSL* ssl, int type, void** pKey)
return ret;
}

#if (!defined(NO_CERTS) || !defined(WOLFSSL_NO_TLS12)) && \
/* Callers: ProcessPeerCerts() (client, or server verifying client certs) and
* the TLS 1.2 key exchange peer keys. */
#if ((!defined(NO_CERTS) && \
(!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH))) || \
!defined(WOLFSSL_NO_TLS12)) && \
(!defined(NO_RSA) || defined(HAVE_ECC) || defined(HAVE_ED25519) || \
defined(HAVE_CURVE25519) || defined(HAVE_ED448) || \
defined(HAVE_CURVE448) || defined(HAVE_FALCON) || \
Expand Down
2 changes: 2 additions & 0 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -19271,7 +19271,9 @@ static int test_wolfSSL_Tls13_ECH_tls12_downgrade(void)
#endif

/* session ID and ticket from the rejected connection are ignored */
#ifndef NO_SESSION_CACHE
ExpectIntEQ(wolfSSL_SessionIsSetup(test_ctx.c_ssl->session), 0);
#endif
#if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
ExpectIntEQ(test_ctx.c_ssl->msgsReceived.got_session_ticket, 1);
ExpectIntEQ(wolfSSL_get_SessionTicket(test_ctx.c_ssl, NULL, &ticketLen),
Expand Down
5 changes: 4 additions & 1 deletion tests/api/test_dtls13.c
Original file line number Diff line number Diff line change
Expand Up @@ -2615,7 +2615,10 @@ int test_dtls13_plaintext_ack_after_handshake(void)
int test_dtls13_plaintext_ack_during_handshake(void)
{
EXPECT_DECLS;
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
/* Without a clock (NO_ASN_TIME) retransmissions are not rate limited, so the
* server flight is resent at points this sequence does not expect. */
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) && \
!defined(NO_ASN_TIME)
struct test_memio_ctx test_ctx;
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
Expand Down
5 changes: 4 additions & 1 deletion tests/api/test_ssl_cert.c
Original file line number Diff line number Diff line change
Expand Up @@ -4059,11 +4059,13 @@ static int test_chain_holds_only_peer(WOLFSSL* ssl)
(XMEMCMP(der, wolfSSL_get_chain_cert(chain, 0),
(size_t)derSz) == 0);
}
#ifndef NO_SESSION_CACHE
/* Before the stack: building it on a server replaces the session peer. */
if (ret) {
ret = test_chain_x509_is(wolfSSL_SESSION_get0_peer(ssl->session), der,
derSz);
}
#endif
if (ret && (ssl->options.side == WOLFSSL_CLIENT_END)) {
ret = test_chain_x509_is(wolfSSL_sk_X509_value(
wolfSSL_get_peer_cert_chain(ssl), 0), der, derSz);
Expand Down Expand Up @@ -4251,7 +4253,8 @@ int test_wolfSSL_SESSION_get0_peer_full_chain(void)
{
EXPECT_DECLS;
#if defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA)
defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA) && \
!defined(NO_SESSION_CACHE)
WOLFSSL_SESSION* sess = NULL;
WOLFSSL_X509* peer = NULL;
const byte* der = NULL;
Expand Down
3 changes: 2 additions & 1 deletion tests/api/test_tls_bounds.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
* fixture plus the test(s) that use it, so the condition is written once
* and the region and the in-body guard cannot drift apart. */
#if defined(WOLFSSL_TEST_STATIC_BUILD) && \
defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) && !defined(NO_CERTS)
defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) && !defined(NO_CERTS) && \
!defined(NO_WOLFSSL_CLIENT)
#define TEST_TLS_BOUNDS_CSR2_REQUESTS
#endif
#if defined(WOLFSSL_TEST_STATIC_BUILD) && defined(WOLFSSL_TLS13) && \
Expand Down
19 changes: 11 additions & 8 deletions tests/api/test_tls_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ int test_TLSX_ALPN_parse(void)
wolfSSL_CTX_free(ctx);
ctx = NULL;

#ifndef NO_WOLFSSL_SERVER
/* Request direction: server parses and stores a client_hello ALPN
* list. Exercises TLSX_ALPN_ParseAndSet()'s length bookkeeping (shared
* with the response direction) on the request side, including the
Expand Down Expand Up @@ -503,6 +504,7 @@ int test_TLSX_ALPN_parse(void)
ssl = NULL;
wolfSSL_CTX_free(ctx);
ctx = NULL;
#endif /* !NO_WOLFSSL_SERVER */
#endif
return EXPECT_RESULT();
}
Expand Down Expand Up @@ -1572,9 +1574,8 @@ int test_TLSX_PointFormat_parse(void)
(defined(WOLFSSL_TLS13) && defined(HAVE_SUPPORTED_CURVES) && \
!defined(WOLFSSL_NO_SERVER_GROUPS_EXT) && !defined(NO_TLS) && \
!defined(NO_WOLFSSL_SERVER) && defined(WOLFSSL_TEST_STATIC_BUILD) && \
(!defined(NO_RSA) || defined(HAVE_ECC)) && \
((!defined(NO_DH) && !defined(WOLFSSL_NO_TLS12)) || \
defined(HAVE_CURVE25519)))
(!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(WOLFSSL_NO_TLS12) && \
(!defined(NO_DH) || defined(HAVE_CURVE25519)))
byte ext[16];
word16 extLen;
#endif
Expand Down Expand Up @@ -1618,7 +1619,7 @@ int test_TLSX_PointFormat_parse(void)
#if defined(WOLFSSL_TLS13) && defined(HAVE_SUPPORTED_CURVES) && \
!defined(WOLFSSL_NO_SERVER_GROUPS_EXT) && !defined(NO_TLS) && \
!defined(NO_WOLFSSL_SERVER) && defined(WOLFSSL_TEST_STATIC_BUILD) && \
(!defined(NO_RSA) || defined(HAVE_ECC))
(!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(WOLFSSL_NO_TLS12)
/* TLSX_SupportedCurve_Preferred(): checkSupported gating and the
* TLSX_IsGroupSupported() result, driven by a raw (unfiltered) offered
* groups list -- TLSX_SupportedCurve_Parse() records whatever the peer
Expand Down Expand Up @@ -1686,7 +1687,7 @@ int test_TLSX_PointFormat_parse(void)

#if defined(HAVE_SUPPORTED_CURVES) && !defined(NO_TLS) && \
!defined(NO_WOLFSSL_SERVER) && defined(WOLFSSL_TEST_STATIC_BUILD) && \
(!defined(NO_RSA) || defined(HAVE_ECC))
(!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(WOLFSSL_NO_TLS12)
/* TLSX_PointFormat_ValidateResponse(): reached while sizing/writing a
* ServerHello, through the WOLFSSL_LOCAL TLSX_GetResponseSize() rather
* than TLSX_Parse() (there is no wire input on this side). A cipher
Expand Down Expand Up @@ -2658,7 +2659,7 @@ int test_TLSX_KeyShare_gen(void)
{
EXPECT_DECLS;
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_TEST_STATIC_BUILD) && \
defined(HAVE_TLS_EXTENSIONS) && \
defined(HAVE_TLS_EXTENSIONS) && !defined(NO_WOLFSSL_CLIENT) && \
defined(USE_WOLFSSL_MEMORY)
WOLFSSL_CTX* ctx = NULL;
WOLFSSL* ssl = NULL;
Expand Down Expand Up @@ -2972,7 +2973,7 @@ int test_TLSX_KeyShare_freesizewrite(void)
{
EXPECT_DECLS;
#if defined(WOLFSSL_TLS13) && defined(HAVE_SUPPORTED_CURVES) && !defined(NO_DH) && defined(HAVE_FFDHE_2048) && defined(WOLFSSL_TEST_STATIC_BUILD) && \
defined(HAVE_TLS_EXTENSIONS)
defined(HAVE_TLS_EXTENSIONS) && !defined(NO_WOLFSSL_CLIENT)
WOLFSSL_CTX* ctx = NULL;
WOLFSSL* ssl = NULL;

Expand Down Expand Up @@ -3128,7 +3129,7 @@ int test_TLSX_KeyShare_process(void)
{
EXPECT_DECLS;
#if defined(WOLFSSL_TLS13) && defined(HAVE_SUPPORTED_CURVES) && defined(WOLFSSL_TEST_STATIC_BUILD) && \
defined(HAVE_TLS_EXTENSIONS)
defined(HAVE_TLS_EXTENSIONS) && !defined(NO_WOLFSSL_CLIENT)
WOLFSSL_CTX* ctx = NULL;
WOLFSSL* ssl = NULL;

Expand Down Expand Up @@ -3436,6 +3437,8 @@ int test_TLSX_KeyShare_process(void)
wolfSSL_CTX_free(ctx);
ctx = NULL;
#endif /* !NO_DH && HAVE_FFDHE_2048 */
(void)ctx;
(void)ssl;
#endif
return EXPECT_RESULT();
}
4 changes: 3 additions & 1 deletion wolfcrypt/benchmark/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -7365,7 +7365,9 @@ static void bench_aesccm_internal(int useDeviceID, word32 nonceSz,
printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
goto exit;
}
#endif
#endif /* HAVE_AES_DECRYPT */

(void)decLabel;

exit:

Expand Down
45 changes: 29 additions & 16 deletions wolfcrypt/src/rng_bank.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@
#include <wolfssl/wolfcrypt/random.h>
#include <wolfssl/wolfcrypt/rng_bank.h>

/* Retry timeouts. WC_RNG_BANK_TS_START() is taken before a retry loop and
* WC_RNG_BANK_TS_ELAPSED() is checked once per retry and compared against
* timeout_secs. Without a wall clock (no XTIME, e.g. NO_ASN_TIME) each check
* instead counts one retry, and WC_RNG_BANK_NO_CLOCK_RETRIES_PER_SEC retries
* stand in for a second, so a positive timeout_secs still bounds the loop.
* USER_TIME declares XTIME as a function rather than defining a macro.
*/
#if defined(XTIME) || (defined(USER_TIME) && !defined(NO_ASN_TIME))
#define WC_RNG_BANK_TS_START() XTIME(0)
#define WC_RNG_BANK_TS_ELAPSED(ts1) (XTIME(0) - (ts1))
#else
#ifndef WC_RNG_BANK_NO_CLOCK_RETRIES_PER_SEC
#define WC_RNG_BANK_NO_CLOCK_RETRIES_PER_SEC 1000
#endif
#define WC_RNG_BANK_TS_START() 0
#define WC_RNG_BANK_TS_ELAPSED(ts1) \
(++(ts1) / WC_RNG_BANK_NO_CLOCK_RETRIES_PER_SEC)
#endif

#ifndef WC_RNG_HAVE_LOCK
/* feature-gap helper declarations */
static int wc_rng_bank_inst_recovery_enter(
Expand Down Expand Up @@ -205,10 +224,9 @@ WOLFSSL_API int wc_rng_bank_init_nonce(
#ifdef WC_VERBOSE_RNG
int nretries = 0;
#endif
time_t ts1 = XTIME(0);
time_t ts1 = WC_RNG_BANK_TS_START();
rng_inst->bank = ctx;
for (;;) {
time_t ts2;
if (flags & WC_RNG_BANK_FLAG_NO_VECTOR_OPS)
need_reenable_vec = (DISABLE_VECTOR_REGISTERS() == 0);

Expand Down Expand Up @@ -264,8 +282,8 @@ WOLFSSL_API int wc_rng_bank_init_nonce(
ret = WC_CHECK_FOR_INTR_SIGNALS();
if (ret == WC_NO_ERR_TRACE(INTERRUPTED_E))
break;
ts2 = XTIME(0);
if ((timeout_secs > 0) && (ts2 - ts1 > timeout_secs)) {
if ((timeout_secs > 0) &&
(WC_RNG_BANK_TS_ELAPSED(ts1) > timeout_secs)) {
ret = WC_TIMEOUT_E;
break;
}
Expand Down Expand Up @@ -781,7 +799,7 @@ WOLFSSL_API int wc_rng_bank_checkout(
{
WC_RNG_lock_arg_t lock_extra_bits = 0;
int ret = 0;
time_t ts1, ts2;
time_t ts1;
int n_rngs_tried = 0;
int diverted_unusable = 0;
WC_ATOMIC_INT_ARG new_refcount;
Expand Down Expand Up @@ -874,7 +892,7 @@ WOLFSSL_API int wc_rng_bank_checkout(
}

if ((timeout_secs > 0) && (flags & WC_RNG_BANK_FLAG_CAN_WAIT))
ts1 = XTIME(0);
ts1 = WC_RNG_BANK_TS_START();
else
ts1 = 0; /* mollify -Wmaybe-uninitialized... */

Expand Down Expand Up @@ -1275,8 +1293,7 @@ WOLFSSL_API int wc_rng_bank_checkout(
break;

if (timeout_secs > 0) {
ts2 = XTIME(0);
if (ts2 - ts1 >= timeout_secs) {
if (WC_RNG_BANK_TS_ELAPSED(ts1) >= timeout_secs) {
ret = WC_TIMEOUT_E;
break;
}
Expand Down Expand Up @@ -2077,7 +2094,7 @@ WOLFSSL_API int wc_rng_bank_inst_reinit(
* it is a safe no-op when called on an already-freed instance.
*/
if ((timeout_secs > 0) && (flags & WC_RNG_BANK_FLAG_CAN_WAIT))
ts1 = XTIME(0);
ts1 = WC_RNG_BANK_TS_START();

#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
devId = rng_inst->rng.devId;
Expand Down Expand Up @@ -2264,8 +2281,7 @@ WOLFSSL_API int wc_rng_bank_inst_reinit(
}

if (timeout_secs > 0) {
time_t ts2 = XTIME(0);
if (ts2 - ts1 >= timeout_secs) {
if (WC_RNG_BANK_TS_ELAPSED(ts1) >= timeout_secs) {
#ifdef WC_VERBOSE_RNG
if (! (bank->flags & WC_RNG_BANK_FLAG_QUIET))
WOLFSSL_DEBUG_PRINTF(
Expand Down Expand Up @@ -2759,7 +2775,7 @@ WOLFSSL_API int wc_rng_bank_reseed_range(struct wc_rng_bank *bank,
#endif

if ((timeout_secs > 0) && (flags & WC_RNG_BANK_FLAG_CAN_WAIT))
ts1 = XTIME(0);
ts1 = WC_RNG_BANK_TS_START();

for (n = last_inst; n >= first_inst; --n) {
struct wc_rng_bank_inst *drbg;
Expand Down Expand Up @@ -2792,8 +2808,6 @@ WOLFSSL_API int wc_rng_bank_reseed_range(struct wc_rng_bank *bank,

if (flags & WC_RNG_BANK_FLAG_CAN_WAIT) {
for (;;) {
time_t ts2;

#ifndef WC_RNG_HAVE_LOCK
/* the pre-lock boundary can't see the inst-side latch:
* mirror the in-boundary _RECOVERING protocol around the
Expand Down Expand Up @@ -2888,8 +2902,7 @@ WOLFSSL_API int wc_rng_bank_reseed_range(struct wc_rng_bank *bank,
if (timeout_secs == 0)
break;
if (timeout_secs > 0) {
ts2 = XTIME(0);
if ((ts2 - ts1 > timeout_secs) &&
if ((WC_RNG_BANK_TS_ELAPSED(ts1) > timeout_secs) &&
!((flags | bank->flags) & WC_RNG_BANK_FLAG_QUIET))
{
#ifdef WC_VERBOSE_RNG
Expand Down
Loading
Loading