Skip to content
Draft
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
22 changes: 22 additions & 0 deletions .github/workflows/async-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,25 @@ jobs:
cat "$f"
fi
done

# Crypto-callback record-cipher poll completion (WOLF_CRYPTO_CB_ASYNC_POLL):
# build the unit test with the feature macro and run the async test group.
cryptocb_async_poll:
if: ${{ (github.repository_owner == 'wolfssl') && (github.event_name != 'pull_request' || github.event.pull_request.draft == false) }}
runs-on: ubuntu-24.04
timeout-minutes: 15
name: Crypto-cb async poll completion
steps:
- uses: actions/checkout@v5
name: Checkout wolfSSL

- name: Build with WOLF_CRYPTO_CB_ASYNC_POLL
run: |
./autogen.sh
./configure --enable-asynccrypt --enable-cryptocb --enable-tls13 \
--enable-des3 --enable-aesccm --enable-aesctr \
CPPFLAGS=-DWOLF_CRYPTO_CB_ASYNC_POLL
make

- name: Run async unit tests
run: ./tests/unit.test --group async
1 change: 1 addition & 0 deletions .wolfssl_known_macro_extras
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,7 @@ WOLFSSL_XILINX_PATCH
WOLFSSL_XIL_MSG_NO_SLEEP
WOLFSSL_ZEPHYR
WOLF_ALLOW_BUILTIN
WOLF_CRYPTO_CB_ASYNC_POLL
WOLF_CRYPTO_CB_CMD
WOLF_CRYPTO_DEV
WOLF_NO_TRAILING_ENUM_COMMAS
Expand Down
17 changes: 17 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -11290,6 +11290,23 @@ then
fi
fi

# Crypto callbacks with async crypt may not work for TLS unless
# WOLF_CRYPTO_CB_ASYNC_POLL is defined. Warn once here and silence the
# source-level #warning.
if test "$ENABLED_ASYNCCRYPT" = "yes" && test "x$ENABLED_CRYPTOCB" != "xno" &&
test "x$ENABLED_ASYNCCRYPT_SW" != "xyes" &&
test "x$ENABLED_CAVIUM" != "xyes" && test "x$ENABLED_INTEL_QA" != "xyes"
then
case "$CPPFLAGS $CFLAGS $AM_CFLAGS" in
*WOLF_CRYPTO_CB_ASYNC_POLL*)
;;
*)
AC_MSG_WARN([crypto callbacks with async crypt may not work for TLS. Define WOLF_CRYPTO_CB_ASYNC_POLL to enable it.])
AM_CFLAGS="$AM_CFLAGS -DWOLF_CRYPTO_CB_ASYNC_NO_WARN"
;;
esac
fi

# check for async if using Intel QuckAssist or Cavium
if test "x$ENABLED_INTEL_QA" = "xyes" || test "x$ENABLED_CAVIUM" = "xyes" ; then
if test "x$ENABLED_ASYNCCRYPT" = "xno" ; then
Expand Down
5 changes: 5 additions & 0 deletions examples/async/user_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
#define NO_FILESYSTEM
#define WOLFSSL_IGNORE_FILE_WARN

#ifdef WOLF_CRYPTO_CB
/* PK-only offload: silence pending-bulk-cipher warning. */
#define WOLF_CRYPTO_CB_ASYNC_NO_WARN
#endif

#define HAVE_ECC
#define WC_ECC_NONBLOCK
#define WC_ECC_NONBLOCK_ONLY
Expand Down
32 changes: 27 additions & 5 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -21583,7 +21583,16 @@ static WC_INLINE int Encrypt(WOLFSSL* ssl, byte* out, const byte* input,
#ifdef WOLFSSL_ASYNC_CRYPT
/* If pending, then leave and return will resume below */
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
#if defined(WOLF_CRYPTO_CB) && \
!defined(WOLF_CRYPTO_CB_ASYNC_POLL) && \
!defined(WOLFSSL_ASYNC_CRYPT_SW) && \
!defined(HAVE_INTEL_QA) && !defined(HAVE_CAVIUM)
/* No completion path for a pending bulk cipher op. */
WOLFSSL_ERROR_VERBOSE(ASYNC_OP_E);
return ASYNC_OP_E;
#else
return ret;
#endif
}
#endif
}
Expand Down Expand Up @@ -22085,7 +22094,16 @@ static int DecryptTls(WOLFSSL* ssl, byte* plain, const byte* input, word16 sz)
#ifdef WOLFSSL_ASYNC_CRYPT
/* If pending, leave and return below */
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
#if defined(WOLF_CRYPTO_CB) && \
!defined(WOLF_CRYPTO_CB_ASYNC_POLL) && \
!defined(WOLFSSL_ASYNC_CRYPT_SW) && \
!defined(HAVE_INTEL_QA) && !defined(HAVE_CAVIUM)
/* No completion path for a pending bulk cipher op. */
WOLFSSL_ERROR_VERBOSE(ASYNC_OP_E);
return ASYNC_OP_E;
#else
return ret;
#endif
}
#endif
}
Expand Down Expand Up @@ -27850,10 +27868,8 @@ int SendData(WOLFSSL* ssl, const void* data, size_t sz)
#endif
}
if (sendSz < 0) {
#ifdef WOLFSSL_ASYNC_CRYPT
if (sendSz == WC_NO_ERR_TRACE(WC_PENDING_E))
ssl->error = sendSz;
#endif
/* Preserve the reason for wolfSSL_get_error(). */
ssl->error = sendSz;
return BUILD_MSG_ERROR;
}

Expand Down Expand Up @@ -43928,7 +43944,13 @@ int wolfSSL_AsyncPop(WOLFSSL* ssl, byte* state)
#if (defined(WOLF_CRYPTO_CB) || defined(HAVE_PK_CALLBACKS)) && \
!defined(WOLFSSL_ASYNC_CRYPT_SW) && !defined(HAVE_INTEL_QA) && \
!defined(HAVE_CAVIUM)
else if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
else if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)
#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_ASYNC_POLL)
/* Poll-completed ops stay queued until the poll fills the
* output buffer. */
&& asyncDev->cryptocb.devId == INVALID_DEVID
#endif
) {
/* Allow the underlying crypto API to be called again to trigger the
* crypto or PK callback. The actual callback must be called, since
* the completion is not detected in the poll like Intel QAT or
Expand Down
18 changes: 18 additions & 0 deletions src/tls13.c
Original file line number Diff line number Diff line change
Expand Up @@ -2818,6 +2818,14 @@ static int EncryptTls13(WOLFSSL* ssl, byte* output, const byte* input,

#ifdef WOLFSSL_ASYNC_CRYPT
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
#if defined(WOLF_CRYPTO_CB) && \
!defined(WOLF_CRYPTO_CB_ASYNC_POLL) && \
!defined(WOLFSSL_ASYNC_CRYPT_SW) && \
!defined(HAVE_INTEL_QA) && !defined(HAVE_CAVIUM)
/* No completion path for a pending bulk cipher op. */
WOLFSSL_ERROR_VERBOSE(ASYNC_OP_E);
return ASYNC_OP_E;
#else
/* if async is not okay, then block */
if (!asyncOkay) {
ret = wc_AsyncWait(ret, asyncDev, event_flags);
Expand All @@ -2826,6 +2834,7 @@ static int EncryptTls13(WOLFSSL* ssl, byte* output, const byte* input,
/* If pending, then leave and return will resume below */
return wolfSSL_AsyncPush(ssl, asyncDev);
}
#endif
}
#endif
}
Expand Down Expand Up @@ -3217,7 +3226,16 @@ int DecryptTls13(WOLFSSL* ssl, byte* output, const byte* input, word16 sz,
#ifdef WOLFSSL_ASYNC_CRYPT
/* If pending, leave now */
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
#if defined(WOLF_CRYPTO_CB) && \
!defined(WOLF_CRYPTO_CB_ASYNC_POLL) && \
!defined(WOLFSSL_ASYNC_CRYPT_SW) && \
!defined(HAVE_INTEL_QA) && !defined(HAVE_CAVIUM)
/* No completion path for a pending bulk cipher op. */
WOLFSSL_ERROR_VERBOSE(ASYNC_OP_E);
return ASYNC_OP_E;
#else
return ret;
#endif
}
#endif
}
Expand Down
3 changes: 3 additions & 0 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
#include <tests/api/test_kdf.h>
#include <tests/api/test_she.h>
#include <tests/api/test_des3.h>
#include <tests/api/test_async.h>
#include <tests/api/test_chacha.h>
#include <tests/api/test_poly1305.h>
#include <tests/api/test_chacha20_poly1305.h>
Expand Down Expand Up @@ -37042,6 +37043,8 @@ TEST_CASE testCases[] = {
#endif

/* Cipher */
/* Crypto callback async poll completion */
TEST_ASYNC_DECLS,
/* Triple-DES */
TEST_DES3_DECLS,
/* Chacha20 */
Expand Down
2 changes: 2 additions & 0 deletions tests/api/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tests_unit_test_SOURCES += tests/api/test_kdf.c
# SHE
tests_unit_test_SOURCES += tests/api/test_she.c
# Cipher
tests_unit_test_SOURCES += tests/api/test_async.c
tests_unit_test_SOURCES += tests/api/test_des3.c
tests_unit_test_SOURCES += tests/api/test_chacha.c
tests_unit_test_SOURCES += tests/api/test_poly1305.c
Expand Down Expand Up @@ -145,6 +146,7 @@ EXTRA_DIST += tests/api/test_hmac.h
EXTRA_DIST += tests/api/test_cmac.h
EXTRA_DIST += tests/api/test_kdf.h
EXTRA_DIST += tests/api/test_she.h
EXTRA_DIST += tests/api/test_async.h
EXTRA_DIST += tests/api/test_des3.h
EXTRA_DIST += tests/api/test_chacha.h
EXTRA_DIST += tests/api/test_poly1305.h
Expand Down
Loading