Skip to content

Commit 71f9210

Browse files
committed
Add tests for async with crypto callbacks and non-blocking ECC/Curve25519
1 parent 1b05b26 commit 71f9210

File tree

5 files changed

+64
-3
lines changed

5 files changed

+64
-3
lines changed

examples/async/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ Tested with:
1414
* `./configure --enable-asynccrypt --enable-pkcallbacks --enable-rsa --disable-ecc`
1515
* `./configure --enable-asynccrypt --enable-pkcallbacks --disable-rsa --enable-ecc`
1616

17+
## Crypto Callback Testing
18+
19+
The async examples include a crypto callback implementation (`AsyncTlsCryptoCb`) that
20+
simulates hardware crypto delays by returning `WC_PENDING_E` for a configurable number
21+
of iterations before completing the operation in software.
22+
23+
When built with `WOLF_CRYPTO_CB` enabled (default in `user_settings.h`), the callback
24+
is automatically registered and will be invoked for all cryptographic operations.
25+
This tests the `WOLFSSL_ASYNC_CRYPT + WOLF_CRYPTO_CB + WC_ECC_NONBLOCK` combination.
26+
27+
To adjust the simulated pending count (default is 2), define `TEST_PEND_COUNT`:
28+
```
29+
make -C examples/async CFLAGS="-DTEST_PEND_COUNT=5"
30+
```
31+
32+
To enable crypto callback debug output, uncomment `DEBUG_CRYPTOCB` in `user_settings.h`.
33+
1734
```
1835
make -C examples/async
1936
./examples/async/async_server --ecc

examples/async/async_client.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
#include <wolfssl/ssl.h>
5353
#include <wolfssl/wolfio.h>
5454
#include <wolfssl/wolfcrypt/error-crypt.h>
55+
#ifdef WOLF_CRYPTO_CB
56+
#include <wolfssl/wolfcrypt/cryptocb.h>
57+
#endif
5558
#include <wolfssl/certs_test.h>
5659
#include "examples/async/async_tls.h"
5760

@@ -233,6 +236,9 @@ int client_async_test(int argc, char** argv)
233236
int wouldblock_count = 0;
234237
int pending_count = 0;
235238
#endif
239+
#ifdef WOLF_CRYPTO_CB
240+
AsyncTlsCryptoCbCtx cryptoCbCtx;
241+
#endif
236242
#ifdef WOLFSSL_STATIC_MEMORY
237243
static byte memory[300000];
238244
static byte memoryIO[34500];
@@ -279,6 +285,13 @@ int client_async_test(int argc, char** argv)
279285
goto out;
280286
}
281287
#endif
288+
#ifdef WOLF_CRYPTO_CB
289+
XMEMSET(&cryptoCbCtx, 0, sizeof(cryptoCbCtx));
290+
if (wc_CryptoCb_RegisterDevice(devId, AsyncTlsCryptoCb, &cryptoCbCtx) != 0) {
291+
fprintf(stderr, "ERROR: wc_CryptoCb_RegisterDevice failed\n");
292+
goto out;
293+
}
294+
#endif
282295

283296
#ifdef WOLFSSL_STATIC_MEMORY
284297
{
@@ -548,6 +561,9 @@ int client_async_test(int argc, char** argv)
548561
if (ctx != NULL) {
549562
wolfSSL_CTX_free(ctx);
550563
}
564+
#ifdef WOLF_CRYPTO_CB
565+
wc_CryptoCb_UnRegisterDevice(devId);
566+
#endif
551567
#ifdef WOLFSSL_ASYNC_CRYPT
552568
if (devId != INVALID_DEVID) {
553569
wolfAsync_DevClose(&devId);

examples/async/async_server.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
#include <wolfssl/ssl.h>
5858
#include <wolfssl/wolfio.h>
5959
#include <wolfssl/wolfcrypt/error-crypt.h>
60+
#ifdef WOLF_CRYPTO_CB
61+
#include <wolfssl/wolfcrypt/cryptocb.h>
62+
#endif
6063
#include <wolfssl/certs_test.h>
6164
#include "examples/async/async_tls.h"
6265

@@ -191,6 +194,9 @@ int server_async_test(int argc, char** argv)
191194
int wouldblock_count = 0;
192195
int pending_count = 0;
193196
#endif
197+
#ifdef WOLF_CRYPTO_CB
198+
AsyncTlsCryptoCbCtx cryptoCbCtx;
199+
#endif
194200
#ifdef WOLFSSL_STATIC_MEMORY
195201
static byte memory[300000];
196202
static byte memoryIO[34500];
@@ -284,6 +290,13 @@ int server_async_test(int argc, char** argv)
284290
goto exit;
285291
}
286292
#endif
293+
#ifdef WOLF_CRYPTO_CB
294+
XMEMSET(&cryptoCbCtx, 0, sizeof(cryptoCbCtx));
295+
if (wc_CryptoCb_RegisterDevice(devId, AsyncTlsCryptoCb, &cryptoCbCtx) != 0) {
296+
fprintf(stderr, "ERROR: wc_CryptoCb_RegisterDevice failed\n");
297+
goto exit;
298+
}
299+
#endif
287300

288301
/* Create and initialize WOLFSSL_CTX */
289302
#ifdef WOLFSSL_STATIC_MEMORY
@@ -613,6 +626,9 @@ int server_async_test(int argc, char** argv)
613626
}
614627
if (ctx)
615628
wolfSSL_CTX_free(ctx);
629+
#ifdef WOLF_CRYPTO_CB
630+
wc_CryptoCb_UnRegisterDevice(devId);
631+
#endif
616632
#ifdef WOLFSSL_ASYNC_CRYPT
617633
if (devId != INVALID_DEVID) {
618634
wolfAsync_DevClose(&devId);

examples/async/async_tls.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
#include <config.h>
2424
#endif
2525

26-
#ifndef WOLFSSL_USER_SETTINGS
27-
#include <wolfssl/options.h>
26+
#ifdef WOLFSSL_USER_SETTINGS
27+
#include "user_settings.h"
28+
#else
29+
#include <wolfssl/options.h>
2830
#endif
2931
#include "examples/async/async_tls.h"
3032
#include <wolfssl/ssl.h>

examples/async/user_settings.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,23 @@
4545
#define WC_X25519_NONBLOCK
4646

4747
#define WOLFSSL_ASYNC_CRYPT
48-
#define WOLFSSL_ASYNC_CRYPT_SW
4948
#define WC_NO_ASYNC_THREADING
5049
#define HAVE_WOLF_BIGINT
5150

51+
#define WOLF_CRYPTO_CB
52+
/* #define DEBUG_CRYPTOCB */
53+
/* Note: WOLFSSL_ASYNC_CRYPT_SW is mutually exclusive with WOLF_CRYPTO_CB
54+
* because the async polling code uses #elif between them. When using
55+
* crypto callbacks for async operations, do not define WOLFSSL_ASYNC_CRYPT_SW.
56+
*/
57+
#ifndef WOLF_CRYPTO_CB
58+
#define WOLFSSL_ASYNC_CRYPT_SW
59+
#endif
60+
5261
#define HAVE_AESGCM
5362

5463
#define WOLFSSL_SHA512
64+
#define WOLFSSL_HASH_FLAGS
5565

5666
#define WOLFSSL_TLS13
5767
#define HAVE_HKDF

0 commit comments

Comments
 (0)