Skip to content

Commit a043b7a

Browse files
committed
wolfcrypt/src/rng_bank.c, wolfssl/wolfcrypt/rng_bank.h, wolfcrypt/test/test.c:
* add WC_RNG_BANK_STATIC to WC_RNG_BANK_SUPPORT, supporting WOLFSSL_NO_MALLOC; * in random_bank_test(), fix gate around _NO_VECTOR_OPS sha256.sha_method test (WOLFSSL_SMALL_STACK_CACHE, and USE_INTEL_SPEEDUP not WC_HAVE_VECTOR_SPEEDUPS); * in definition of struct wc_rng_bank_inst, accommodate WOLFSSL_NO_ATOMICS builds; wolfssl/wolfcrypt/random.h: in definition of struct WC_RNG, add gate to avoid empty union in !HAVE_HASHDRBG configs.
1 parent a091ed9 commit a043b7a

4 files changed

Lines changed: 241 additions & 86 deletions

File tree

wolfcrypt/src/rng_bank.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,16 @@ WOLFSSL_API int wc_rng_bank_init(
5050
ctx->flags = flags | WC_RNG_BANK_FLAG_INITED;
5151
ctx->heap = heap;
5252

53+
#ifdef WC_RNG_BANK_STATIC
54+
if (n_rngs > WC_RNG_BANK_STATIC_SIZE)
55+
return BAD_LENGTH_E;
56+
#else
5357
ctx->rngs = (struct wc_rng_bank_inst *)
5458
XMALLOC(sizeof(*ctx->rngs) * (size_t)n_rngs,
5559
heap, DYNAMIC_TYPE_RNG);
5660
if (! ctx->rngs)
5761
ret = MEMORY_E;
62+
#endif
5863

5964
if (ret == 0) {
6065
XMEMSET(ctx->rngs, 0, sizeof(*ctx->rngs) * (size_t)n_rngs);
@@ -116,6 +121,7 @@ WOLFSSL_API int wc_rng_bank_init(
116121
return ret;
117122
}
118123

124+
#ifndef WC_RNG_BANK_STATIC
119125
WOLFSSL_API int wc_rng_bank_new(
120126
struct wc_rng_bank **ctx,
121127
int n_rngs,
@@ -142,6 +148,7 @@ WOLFSSL_API int wc_rng_bank_new(
142148

143149
return ret;
144150
}
151+
#endif /* !WC_RNG_BANK_STATIC */
145152

146153
WOLFSSL_API int wc_rng_bank_set_affinity_handlers(
147154
struct wc_rng_bank *ctx,
@@ -181,7 +188,10 @@ WOLFSSL_API int wc_rng_bank_fini(struct wc_rng_bank *ctx) {
181188
if (wolfSSL_RefCur(ctx->refcount) > 1)
182189
return BUSY_E;
183190

184-
if (ctx->rngs) {
191+
#ifndef WC_RNG_BANK_STATIC
192+
if (ctx->rngs)
193+
#endif
194+
{
185195
for (i = 0; i < ctx->n_rngs; ++i) {
186196
if (ctx->rngs[i].lock != 0) {
187197
/* better to leak than to crash. */
@@ -198,8 +208,10 @@ WOLFSSL_API int wc_rng_bank_fini(struct wc_rng_bank *ctx) {
198208
wc_FreeRng(&ctx->rngs[i].rng);
199209
}
200210

211+
#ifndef WC_RNG_BANK_STATIC
201212
XFREE(ctx->rngs, ctx->heap, DYNAMIC_TYPE_RNG);
202213
ctx->rngs = NULL;
214+
#endif
203215
ctx->n_rngs = 0;
204216
}
205217

@@ -211,6 +223,7 @@ WOLFSSL_API int wc_rng_bank_fini(struct wc_rng_bank *ctx) {
211223
return 0;
212224
}
213225

226+
#ifndef WC_RNG_BANK_STATIC
214227
WOLFSSL_API int wc_rng_bank_free(struct wc_rng_bank **ctx) {
215228
int ret;
216229
void *heap;
@@ -232,6 +245,7 @@ WOLFSSL_API int wc_rng_bank_free(struct wc_rng_bank **ctx) {
232245

233246
return ret;
234247
}
248+
#endif /* !WC_RNG_BANK_STATIC */
235249

236250
/* wc_rng_bank_checkout() uses atomic operations to get exclusive ownership of a
237251
* DRBG without delay. It expects to be called in uninterruptible context,
@@ -694,6 +708,7 @@ WOLFSSL_API int wc_BankRef_Release(WC_RNG *rng)
694708
return ret;
695709
}
696710

711+
#ifndef WC_RNG_BANK_STATIC
697712
WOLFSSL_API int wc_rng_new_bankref(struct wc_rng_bank *bank, WC_RNG **rng) {
698713
int ret;
699714

@@ -717,6 +732,7 @@ WOLFSSL_API int wc_rng_new_bankref(struct wc_rng_bank *bank, WC_RNG **rng) {
717732

718733
return ret;
719734
}
735+
#endif /* !WC_RNG_BANK_STATIC */
720736

721737
#endif /* WC_DRBG_BANKREF */
722738

0 commit comments

Comments
 (0)