From c12bf79e5692bdb228d189eb272d26092beec416 Mon Sep 17 00:00:00 2001 From: Andras Fekete Date: Tue, 19 Sep 2023 10:28:34 -0400 Subject: [PATCH 1/2] Clean up double enum This was necessary to have https://github.com/wolfSSL/wolfAsyncCrypt/pull/70 be able to merge --- wolfssl/wolfcrypt/error-crypt.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wolfssl/wolfcrypt/error-crypt.h b/wolfssl/wolfcrypt/error-crypt.h index 3d7a74be2..39d63eb35 100644 --- a/wolfssl/wolfcrypt/error-crypt.h +++ b/wolfssl/wolfcrypt/error-crypt.h @@ -49,8 +49,7 @@ enum { BAD_MUTEX_E = -106, /* Bad mutex operation */ WC_TIMEOUT_E = -107, /* timeout error */ WC_PENDING_E = -108, /* wolfCrypt operation pending (would block) */ - WC_NOT_PENDING_E = -109, /* wolfCrypt operation not pending */ - WC_NO_PENDING_E = -109, /* no asynchronous operation not pending */ + WC_NO_PENDING_E = -109, /* no asynchronous operation pending */ MP_INIT_E = -110, /* mp_init error state */ MP_READ_E = -111, /* mp_read error state */ From 2af5ae89a2c1c7831e0655810dd740a4ef07889a Mon Sep 17 00:00:00 2001 From: Andras Fekete Date: Fri, 15 Sep 2023 15:16:51 -0400 Subject: [PATCH 2/2] Rename enum to protect the innocent WC_NO_PENDING_E indicates that there really isn't any asynchronous task that is pending. --- src/internal.c | 28 ++++++++++++++-------------- src/sniffer.c | 4 ++-- src/tls.c | 2 +- src/tls13.c | 20 ++++++++++---------- wolfcrypt/src/error.c | 2 +- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/internal.c b/src/internal.c index 6efbfb823..392ed8871 100644 --- a/src/internal.c +++ b/src/internal.c @@ -13696,7 +13696,7 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx, args = (ProcPeerCertArgs*)ssl->async->args; #ifdef WOLFSSL_ASYNC_CRYPT ret = wolfSSL_AsyncPop(ssl, &ssl->options.asyncState); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* Check for error */ if (ret < 0) goto exit_ppc; @@ -13708,7 +13708,7 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx, /* Re-entry after non-blocking OCSP */ #ifdef WOLFSSL_ASYNC_CRYPT /* if async operationg not pending, reset error code */ - if (ret == WC_NOT_PENDING_E) + if (ret == WC_NO_PENDING_E) ret = 0; #endif } @@ -18709,7 +18709,7 @@ static int DecryptTls(WOLFSSL* ssl, byte* plain, const byte* input, word16 sz) #ifdef WOLFSSL_ASYNC_CRYPT ret = wolfSSL_AsyncPop(ssl, &ssl->decrypt.state); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* check for still pending */ if (ret == WC_PENDING_E) return ret; @@ -21656,7 +21656,7 @@ int BuildMessage(WOLFSSL* ssl, byte* output, int outSz, const byte* input, #endif #ifdef WOLFSSL_ASYNC_CRYPT - ret = WC_NOT_PENDING_E; + ret = WC_NO_PENDING_E; if (asyncOkay) { if (ssl->async == NULL) { return BAD_FUNC_ARG; @@ -21664,7 +21664,7 @@ int BuildMessage(WOLFSSL* ssl, byte* output, int outSz, const byte* input, args = &ssl->async->buildArgs; ret = wolfSSL_AsyncPop(ssl, &ssl->options.buildMsgState); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* Check for error */ if (ret < 0) goto exit_buildmsg; @@ -21678,7 +21678,7 @@ int BuildMessage(WOLFSSL* ssl, byte* output, int outSz, const byte* input, /* Reset state */ #ifdef WOLFSSL_ASYNC_CRYPT - if (ret == WC_NOT_PENDING_E) + if (ret == WC_NO_PENDING_E) #endif { ret = 0; @@ -29017,7 +29017,7 @@ static int DoServerKeyExchange(WOLFSSL* ssl, const byte* input, args = (DskeArgs*)ssl->async->args; ret = wolfSSL_AsyncPop(ssl, &ssl->options.asyncState); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* Check for error */ if (ret < 0) goto exit_dske; @@ -30100,7 +30100,7 @@ int SendClientKeyExchange(WOLFSSL* ssl) #ifdef WOLFSSL_ASYNC_CRYPT ret = wolfSSL_AsyncPop(ssl, &ssl->options.asyncState); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* Check for error */ if (ret < 0) goto exit_scke; @@ -31369,7 +31369,7 @@ int SendCertificateVerify(WOLFSSL* ssl) if (ssl->error != WC_PENDING_E || ssl->options.asyncState != TLS_ASYNC_END) ret = wolfSSL_AsyncPop(ssl, &ssl->options.asyncState); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* Check for error */ if (ret < 0) goto exit_scv; @@ -32460,7 +32460,7 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx, args = (SskeArgs*)ssl->async->args; #ifdef WOLFSSL_ASYNC_CRYPT ret = wolfSSL_AsyncPop(ssl, &ssl->options.asyncState); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* Check for error */ if (ret < 0) goto exit_sske; @@ -35312,7 +35312,7 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx, args = (DcvArgs*)ssl->async->args; ret = wolfSSL_AsyncPop(ssl, &ssl->options.asyncState); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* Check for error */ if (ret < 0) goto exit_dcv; @@ -37464,7 +37464,7 @@ static int DefTicketEncCb(WOLFSSL* ssl, byte key_name[WOLFSSL_TICKET_NAME_SZ], args = (DckeArgs*)ssl->async->args; ret = wolfSSL_AsyncPop(ssl, &ssl->options.asyncState); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* Check for error */ if (ret < 0) goto exit_dcke; @@ -38730,7 +38730,7 @@ int wolfSSL_AsyncPop(WOLFSSL* ssl, byte* state) event = &asyncDev->event; ret = wolfAsync_EventPop(event, WOLF_EVENT_TYPE_ASYNC_WOLFSSL); - if (ret != WC_NOT_PENDING_E && ret != WC_PENDING_E) { + if (ret != WC_NO_PENDING_E && ret != WC_PENDING_E) { /* advance key share state if doesn't need called again */ if (state && (asyncDev->event.flags & WC_ASYNC_FLAG_CALL_AGAIN) == 0) { @@ -38745,7 +38745,7 @@ int wolfSSL_AsyncPop(WOLFSSL* ssl, byte* state) } } else { - ret = WC_NOT_PENDING_E; + ret = WC_NO_PENDING_E; } WOLFSSL_LEAVE("wolfSSL_AsyncPop", ret); diff --git a/src/sniffer.c b/src/sniffer.c index b70da7634..ddcb54033 100644 --- a/src/sniffer.c +++ b/src/sniffer.c @@ -2474,7 +2474,7 @@ static int SetupKeys(const byte* input, int* sslBytes, SnifferSession* session, args = (SetupKeysArgs*)ssl->async->args; ret = wolfSSL_AsyncPop(ssl, &ssl->options.asyncState); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* Check for error */ if (ret < 0) goto exit_sk; @@ -4877,7 +4877,7 @@ static int DecryptTls(WOLFSSL* ssl, byte* plain, const byte* input, #ifdef WOLFSSL_ASYNC_CRYPT if (ssl->decrypt.state != CIPHER_STATE_BEGIN) { ret = wolfSSL_AsyncPop(ssl, &ssl->decrypt.state); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* check for still pending */ if (ret == WC_PENDING_E) return ret; diff --git a/src/tls.c b/src/tls.c index 633f8442e..92bac11b5 100644 --- a/src/tls.c +++ b/src/tls.c @@ -9669,7 +9669,7 @@ int TLSX_KeyShare_DeriveSecret(WOLFSSL *ssl) #ifdef WOLFSSL_ASYNC_CRYPT ret = wolfSSL_AsyncPop(ssl, NULL); /* Check for error */ - if (ret != WC_NOT_PENDING_E && ret < 0) { + if (ret != WC_NO_PENDING_E && ret < 0) { return ret; } #endif diff --git a/src/tls13.c b/src/tls13.c index ec16c6ae2..88eb67b10 100644 --- a/src/tls13.c +++ b/src/tls13.c @@ -2945,7 +2945,7 @@ int DecryptTls13(WOLFSSL* ssl, byte* output, const byte* input, word16 sz, #ifdef WOLFSSL_ASYNC_CRYPT ret = wolfSSL_AsyncPop(ssl, &ssl->decrypt.state); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* check for still pending */ if (ret == WC_PENDING_E) return ret; @@ -3208,7 +3208,7 @@ int BuildTls13Message(WOLFSSL* ssl, byte* output, int outSz, const byte* input, WOLFSSL_ENTER("BuildTls13Message"); #ifdef WOLFSSL_ASYNC_CRYPT - ret = WC_NOT_PENDING_E; + ret = WC_NO_PENDING_E; if (asyncOkay) { WOLFSSL_ASSERT_SIZEOF_GE(ssl->async->args, *args); @@ -3222,7 +3222,7 @@ int BuildTls13Message(WOLFSSL* ssl, byte* output, int outSz, const byte* input, args = (BuildMsg13Args*)ssl->async->args; ret = wolfSSL_AsyncPop(ssl, &ssl->options.buildMsgState); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* Check for error */ if (ret < 0) goto exit_buildmsg; @@ -3236,7 +3236,7 @@ int BuildTls13Message(WOLFSSL* ssl, byte* output, int outSz, const byte* input, /* Reset state */ #ifdef WOLFSSL_ASYNC_CRYPT - if (ret == WC_NOT_PENDING_E) + if (ret == WC_NO_PENDING_E) #endif { ret = 0; @@ -4285,7 +4285,7 @@ int SendTls13ClientHello(WOLFSSL* ssl) args = (Sch13Args*)ssl->async->args; ret = wolfSSL_AsyncPop(ssl, &ssl->options.asyncState); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* Check for error */ if (ret < 0) return ret; @@ -4995,7 +4995,7 @@ int DoTls13ServerHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx, args = (Dsh13Args*)ssl->async->args; ret = wolfSSL_AsyncPop(ssl, &ssl->options.asyncState); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* Check for error */ if (ret < 0) { if (ret == WC_PENDING_E) { @@ -6608,7 +6608,7 @@ int DoTls13ClientHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx, args = (Dch13Args*)ssl->async->args; ret = wolfSSL_AsyncPop(ssl, &ssl->options.asyncState); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* Check for error */ if (ret < 0) { goto exit_dch; @@ -8512,7 +8512,7 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl) args = (Scv13Args*)ssl->async->args; ret = wolfSSL_AsyncPop(ssl, &ssl->options.asyncState); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* Check for error */ if (ret < 0) goto exit_scv; @@ -9141,7 +9141,7 @@ static int DoTls13CertificateVerify(WOLFSSL* ssl, byte* input, args = (Dcv13Args*)ssl->async->args; ret = wolfSSL_AsyncPop(ssl, &ssl->options.asyncState); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* Check for error */ if (ret < 0) goto exit_dcv; @@ -12341,7 +12341,7 @@ int wolfSSL_UseKeyShare(WOLFSSL* ssl, word16 group) #ifdef WOLFSSL_ASYNC_CRYPT ret = wolfSSL_AsyncPop(ssl, NULL); - if (ret != WC_NOT_PENDING_E) { + if (ret != WC_NO_PENDING_E) { /* Check for error */ if (ret < 0) return ret; diff --git a/wolfcrypt/src/error.c b/wolfcrypt/src/error.c index 6ad73d77c..46dd7f300 100644 --- a/wolfcrypt/src/error.c +++ b/wolfcrypt/src/error.c @@ -63,7 +63,7 @@ const char* wc_GetErrorString(int error) case WC_PENDING_E: return "wolfCrypt Operation Pending (would block / eagain) error"; - case WC_NOT_PENDING_E: + case WC_NO_PENDING_E: return "wolfCrypt operation not pending error"; case MP_INIT_E :