Skip to content

Commit 8c30cfb

Browse files
committed
Add tests for async with static memory. Fix issue with mixed-declaration in SP ECC non-blocking.
1 parent e9b711e commit 8c30cfb

12 files changed

Lines changed: 203 additions & 101 deletions

File tree

.github/workflows/async-examples.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,22 @@ jobs:
1515
if: github.repository_owner == 'wolfssl'
1616
runs-on: ubuntu-24.04
1717
timeout-minutes: 10
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
extra_cflags:
22+
- ''
23+
- '-DWOLFSSL_SMALL_CERT_VERIFY'
24+
- '-DWOLFSSL_STATIC_MEMORY'
25+
name: Async Examples (${{ matrix.extra_cflags || 'default' }})
1826
steps:
1927
- uses: actions/checkout@v4
2028
name: Checkout wolfSSL
2129

2230
- name: Build async examples (no configure)
2331
run: |
2432
make -C examples/async clean
25-
make -C examples/async
33+
make -C examples/async EXTRA_CFLAGS="${{ matrix.extra_cflags }}"
2634
2735
- name: Run async examples
2836
run: |

examples/async/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CFLAGS += -Wall -Wextra -Wpedantic -Werror
1414
CFLAGS += -DWOLFSSL_USER_SETTINGS
1515
CFLAGS += -DHAVE_SYS_TIME_H
1616
CFLAGS += -DUSE_CERT_BUFFERS_256
17+
CFLAGS += $(EXTRA_CFLAGS)
1718

1819
LDFLAGS ?=
1920
LDLIBS ?=

examples/async/async_client.c

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ int client_async_test(int argc, char** argv)
232232
#ifdef WOLFSSL_DEBUG_NONBLOCK
233233
int wouldblock_count = 0;
234234
int pending_count = 0;
235+
#endif
236+
#ifdef WOLFSSL_STATIC_MEMORY
237+
static byte memory[300000];
238+
static byte memoryIO[34500];
239+
#if !defined(WOLFSSL_STATIC_MEMORY_LEAN)
240+
WOLFSSL_MEM_CONN_STATS ssl_stats;
241+
#endif
235242
#endif
236243
const char* host = NULL;
237244
int port = 0;
@@ -273,12 +280,36 @@ int client_async_test(int argc, char** argv)
273280
}
274281
#endif
275282

276-
#ifndef WOLFSSL_NO_TLS12
283+
#ifdef WOLFSSL_STATIC_MEMORY
284+
{
285+
wolfSSL_method_func method;
286+
#ifndef WOLFSSL_NO_TLS12
287+
if (tls12)
288+
method = wolfTLSv1_2_client_method_ex;
289+
else
290+
#endif
291+
method = wolfSSLv23_client_method_ex;
292+
if (wolfSSL_CTX_load_static_memory(&ctx, method, memory,
293+
sizeof(memory), 0, 1) != WOLFSSL_SUCCESS) {
294+
fprintf(stderr, "ERROR: unable to load static memory\n");
295+
goto out;
296+
}
297+
if (wolfSSL_CTX_load_static_memory(&ctx, NULL, memoryIO,
298+
sizeof(memoryIO),
299+
WOLFMEM_IO_POOL_FIXED | WOLFMEM_TRACK_STATS, 1)
300+
!= WOLFSSL_SUCCESS) {
301+
fprintf(stderr, "ERROR: unable to load static IO memory\n");
302+
goto out;
303+
}
304+
}
305+
#else
306+
#ifndef WOLFSSL_NO_TLS12
277307
if (tls12)
278308
ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
279309
else
280-
#endif
310+
#endif
281311
ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
312+
#endif /* WOLFSSL_STATIC_MEMORY */
282313
if (ctx == NULL) {
283314
goto out;
284315
}
@@ -495,6 +526,21 @@ int client_async_test(int argc, char** argv)
495526
ret = 0;
496527

497528
out:
529+
#if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFSSL_STATIC_MEMORY_LEAN)
530+
if (ssl != NULL &&
531+
wolfSSL_is_static_memory(ssl, &ssl_stats) == 1) {
532+
fprintf(stderr, "peak connection memory = %d\n",
533+
ssl_stats.peakMem);
534+
fprintf(stderr, "current memory in use = %d\n",
535+
ssl_stats.curMem);
536+
fprintf(stderr, "peak connection allocs = %d\n",
537+
ssl_stats.peakAlloc);
538+
fprintf(stderr, "total connection allocs = %d\n",
539+
ssl_stats.totalAlloc);
540+
fprintf(stderr, "total connection frees = %d\n",
541+
ssl_stats.totalFr);
542+
}
543+
#endif
498544
if (ssl != NULL) {
499545
wolfSSL_shutdown(ssl);
500546
wolfSSL_free(ssl);

examples/async/async_server.c

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,13 @@ int server_async_test(int argc, char** argv)
191191
int wouldblock_count = 0;
192192
int pending_count = 0;
193193
#endif
194+
#ifdef WOLFSSL_STATIC_MEMORY
195+
static byte memory[300000];
196+
static byte memoryIO[34500];
197+
#if !defined(WOLFSSL_STATIC_MEMORY_LEAN)
198+
WOLFSSL_MEM_CONN_STATS ssl_stats;
199+
#endif
200+
#endif
194201

195202
/* declare wolfSSL objects */
196203
WOLFSSL_CTX* ctx = NULL;
@@ -279,12 +286,36 @@ int server_async_test(int argc, char** argv)
279286
#endif
280287

281288
/* Create and initialize WOLFSSL_CTX */
282-
#ifndef WOLFSSL_NO_TLS12
289+
#ifdef WOLFSSL_STATIC_MEMORY
290+
{
291+
wolfSSL_method_func method;
292+
#ifndef WOLFSSL_NO_TLS12
293+
if (tls12)
294+
method = wolfTLSv1_2_server_method_ex;
295+
else
296+
#endif
297+
method = wolfSSLv23_server_method_ex;
298+
if (wolfSSL_CTX_load_static_memory(&ctx, method, memory,
299+
sizeof(memory), 0, 1) != WOLFSSL_SUCCESS) {
300+
fprintf(stderr, "ERROR: unable to load static memory\n");
301+
goto exit;
302+
}
303+
if (wolfSSL_CTX_load_static_memory(&ctx, NULL, memoryIO,
304+
sizeof(memoryIO),
305+
WOLFMEM_IO_POOL_FIXED | WOLFMEM_TRACK_STATS, 1)
306+
!= WOLFSSL_SUCCESS) {
307+
fprintf(stderr, "ERROR: unable to load static IO memory\n");
308+
goto exit;
309+
}
310+
}
311+
#else
312+
#ifndef WOLFSSL_NO_TLS12
283313
if (tls12)
284314
ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method());
285315
else
286-
#endif
316+
#endif
287317
ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
318+
#endif /* WOLFSSL_STATIC_MEMORY */
288319
if (ctx == NULL) {
289320
fprintf(stderr, "ERROR: failed to create WOLFSSL_CTX\n");
290321
ret = -1;
@@ -535,6 +566,21 @@ int server_async_test(int argc, char** argv)
535566
#endif
536567

537568
/* Cleanup after this connection */
569+
#if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFSSL_STATIC_MEMORY_LEAN)
570+
if (ssl != NULL &&
571+
wolfSSL_is_static_memory(ssl, &ssl_stats) == 1) {
572+
fprintf(stderr, "peak connection memory = %d\n",
573+
ssl_stats.peakMem);
574+
fprintf(stderr, "current memory in use = %d\n",
575+
ssl_stats.curMem);
576+
fprintf(stderr, "peak connection allocs = %d\n",
577+
ssl_stats.peakAlloc);
578+
fprintf(stderr, "total connection allocs = %d\n",
579+
ssl_stats.totalAlloc);
580+
fprintf(stderr, "total connection frees = %d\n",
581+
ssl_stats.totalFr);
582+
}
583+
#endif
538584
wolfSSL_shutdown(ssl);
539585
if (ssl) {
540586
wolfSSL_free(ssl);

examples/configs/include.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ EXTRA_DIST += examples/configs/user_settings_all.h
66
EXTRA_DIST += examples/configs/user_settings_arduino.h
77
EXTRA_DIST += examples/configs/user_settings_baremetal.h
88
EXTRA_DIST += examples/configs/user_settings_ca.h
9+
EXTRA_DIST += examples/configs/user_settings_curve25519nonblock.h
910
EXTRA_DIST += examples/configs/user_settings_dtls13.h
1011
EXTRA_DIST += examples/configs/user_settings_EBSnet.h
1112
EXTRA_DIST += examples/configs/user_settings_eccnonblock.h

wolfcrypt/src/sp_arm32.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74917,16 +74917,16 @@ static int sp_256_proj_point_add_8_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
7491774917
int err = FP_WOULDBLOCK;
7491874918
sp_256_proj_point_add_8_ctx* ctx = (sp_256_proj_point_add_8_ctx*)sp_ctx->data;
7491974919

74920+
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_8_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
74921+
(void)sizeof(ctx_size_test);
74922+
7492074923
/* Ensure only the first point is the same as the result. */
7492174924
if (q == r) {
7492274925
const sp_point_256* a = p;
7492374926
p = q;
7492474927
q = a;
7492574928
}
7492674929

74927-
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_8_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
74928-
(void)sizeof(ctx_size_test);
74929-
7493074930
switch (ctx->state) {
7493174931
case 0: /* INIT */
7493274932
ctx->t6 = t;
@@ -92908,16 +92908,16 @@ static int sp_384_proj_point_add_12_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
9290892908
int err = FP_WOULDBLOCK;
9290992909
sp_384_proj_point_add_12_ctx* ctx = (sp_384_proj_point_add_12_ctx*)sp_ctx->data;
9291092910

92911+
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_12_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
92912+
(void)sizeof(ctx_size_test);
92913+
9291192914
/* Ensure only the first point is the same as the result. */
9291292915
if (q == r) {
9291392916
const sp_point_384* a = p;
9291492917
p = q;
9291592918
q = a;
9291692919
}
9291792920

92918-
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_12_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
92919-
(void)sizeof(ctx_size_test);
92920-
9292192921
switch (ctx->state) {
9292292922
case 0: /* INIT */
9292392923
ctx->t6 = t;
@@ -119987,16 +119987,16 @@ static int sp_521_proj_point_add_17_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
119987119987
int err = FP_WOULDBLOCK;
119988119988
sp_521_proj_point_add_17_ctx* ctx = (sp_521_proj_point_add_17_ctx*)sp_ctx->data;
119989119989

119990+
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_17_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
119991+
(void)sizeof(ctx_size_test);
119992+
119990119993
/* Ensure only the first point is the same as the result. */
119991119994
if (q == r) {
119992119995
const sp_point_521* a = p;
119993119996
p = q;
119994119997
q = a;
119995119998
}
119996119999

119997-
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_17_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
119998-
(void)sizeof(ctx_size_test);
119999-
120000120000
switch (ctx->state) {
120001120001
case 0: /* INIT */
120002120002
ctx->t6 = t;
@@ -150008,16 +150008,16 @@ static int sp_1024_proj_point_add_32_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
150008150008
int err = FP_WOULDBLOCK;
150009150009
sp_1024_proj_point_add_32_ctx* ctx = (sp_1024_proj_point_add_32_ctx*)sp_ctx->data;
150010150010

150011+
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_32_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
150012+
(void)sizeof(ctx_size_test);
150013+
150011150014
/* Ensure only the first point is the same as the result. */
150012150015
if (q == r) {
150013150016
const sp_point_1024* a = p;
150014150017
p = q;
150015150018
q = a;
150016150019
}
150017150020

150018-
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_32_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
150019-
(void)sizeof(ctx_size_test);
150020-
150021150021
switch (ctx->state) {
150022150022
case 0: /* INIT */
150023150023
ctx->t6 = t;

wolfcrypt/src/sp_arm64.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23532,16 +23532,16 @@ static int sp_256_proj_point_add_4_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
2353223532
int err = FP_WOULDBLOCK;
2353323533
sp_256_proj_point_add_4_ctx* ctx = (sp_256_proj_point_add_4_ctx*)sp_ctx->data;
2353423534

23535+
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_4_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
23536+
(void)sizeof(ctx_size_test);
23537+
2353523538
/* Ensure only the first point is the same as the result. */
2353623539
if (q == r) {
2353723540
const sp_point_256* a = p;
2353823541
p = q;
2353923542
q = a;
2354023543
}
2354123544

23542-
typedef char ctx_size_test[sizeof(sp_256_proj_point_add_4_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
23543-
(void)sizeof(ctx_size_test);
23544-
2354523545
switch (ctx->state) {
2354623546
case 0: /* INIT */
2354723547
ctx->t6 = t;
@@ -44108,16 +44108,16 @@ static int sp_384_proj_point_add_6_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
4410844108
int err = FP_WOULDBLOCK;
4410944109
sp_384_proj_point_add_6_ctx* ctx = (sp_384_proj_point_add_6_ctx*)sp_ctx->data;
4411044110

44111+
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_6_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
44112+
(void)sizeof(ctx_size_test);
44113+
4411144114
/* Ensure only the first point is the same as the result. */
4411244115
if (q == r) {
4411344116
const sp_point_384* a = p;
4411444117
p = q;
4411544118
q = a;
4411644119
}
4411744120

44118-
typedef char ctx_size_test[sizeof(sp_384_proj_point_add_6_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
44119-
(void)sizeof(ctx_size_test);
44120-
4412144121
switch (ctx->state) {
4412244122
case 0: /* INIT */
4412344123
ctx->t6 = t;
@@ -72055,16 +72055,16 @@ static int sp_521_proj_point_add_9_nb(sp_ecc_ctx_t* sp_ctx, sp_point_521* r,
7205572055
int err = FP_WOULDBLOCK;
7205672056
sp_521_proj_point_add_9_ctx* ctx = (sp_521_proj_point_add_9_ctx*)sp_ctx->data;
7205772057

72058+
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_9_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
72059+
(void)sizeof(ctx_size_test);
72060+
7205872061
/* Ensure only the first point is the same as the result. */
7205972062
if (q == r) {
7206072063
const sp_point_521* a = p;
7206172064
p = q;
7206272065
q = a;
7206372066
}
7206472067

72065-
typedef char ctx_size_test[sizeof(sp_521_proj_point_add_9_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
72066-
(void)sizeof(ctx_size_test);
72067-
7206872068
switch (ctx->state) {
7206972069
case 0: /* INIT */
7207072070
ctx->t6 = t;
@@ -115721,16 +115721,16 @@ static int sp_1024_proj_point_add_16_nb(sp_ecc_ctx_t* sp_ctx, sp_point_1024* r,
115721115721
int err = FP_WOULDBLOCK;
115722115722
sp_1024_proj_point_add_16_ctx* ctx = (sp_1024_proj_point_add_16_ctx*)sp_ctx->data;
115723115723

115724+
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_16_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
115725+
(void)sizeof(ctx_size_test);
115726+
115724115727
/* Ensure only the first point is the same as the result. */
115725115728
if (q == r) {
115726115729
const sp_point_1024* a = p;
115727115730
p = q;
115728115731
q = a;
115729115732
}
115730115733

115731-
typedef char ctx_size_test[sizeof(sp_1024_proj_point_add_16_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
115732-
(void)sizeof(ctx_size_test);
115733-
115734115734
switch (ctx->state) {
115735115735
case 0: /* INIT */
115736115736
ctx->t6 = t;

0 commit comments

Comments
 (0)