@@ -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
119125WOLFSSL_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
146153WOLFSSL_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
214227WOLFSSL_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,
@@ -631,7 +645,7 @@ WOLFSSL_API int wc_rng_bank_reseed(struct wc_rng_bank *bank,
631645 "ERROR: wc_crng_reseed() wc_RNG_GenerateBlock() "
632646 "for DRBG #%d returned %d." , n , ret );
633647#endif
634- wc_rng_bank_checkin (bank , & drbg );
648+ ( void ) wc_rng_bank_checkin (bank , & drbg );
635649 if (ret == WC_NO_ERR_TRACE (WC_TIMEOUT_E ))
636650 return ret ;
637651 ret = WC_CHECK_FOR_INTR_SIGNALS ();
@@ -640,7 +654,7 @@ WOLFSSL_API int wc_rng_bank_reseed(struct wc_rng_bank *bank,
640654 WC_RELAX_LONG_LOOP ();
641655 }
642656 else {
643- wc_rng_bank_checkin (bank , & drbg );
657+ ( void ) wc_rng_bank_checkin (bank , & drbg );
644658 }
645659 }
646660
@@ -694,6 +708,7 @@ WOLFSSL_API int wc_BankRef_Release(WC_RNG *rng)
694708 return ret ;
695709}
696710
711+ #ifndef WC_RNG_BANK_STATIC
697712WOLFSSL_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