Skip to content

Commit b02a233

Browse files
Note that mbedtls_ctr_drbg_seed() must not be called twice
You can't reuse a CTR_DRBG context without free()ing it and re-init()ing it. This generally happened to work, but was never guaranteed. It could have failed with alternative implementations of the AES module because mbedtls_ctr_drbg_seed() calls mbedtls_aes_init() on a context which is already initialized if mbedtls_ctr_drbg_seed() hasn't been called before, plausibly causing a memory leak. Calling free() and seed() with no intervening init fails when MBEDTLS_THREADING_C is enabled and all-bits-zero is not a valid mutex representation.
1 parent f4c0dbc commit b02a233

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

include/mbedtls/ctr_drbg.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
249249
#endif
250250
/**
251251
* \param ctx The CTR_DRBG context to seed.
252+
* It must have been initialized with
253+
* mbedtls_ctr_drbg_init().
254+
* After a successful call to mbedtls_ctr_drbg_seed(),
255+
* you may not call mbedtls_ctr_drbg_seed() again on
256+
* the same context unless you call
257+
* mbedtls_ctr_drbg_free() and mbedtls_ctr_drbg_init()
258+
* again first.
252259
* \param f_entropy The entropy callback, taking as arguments the
253260
* \p p_entropy context, the buffer to fill, and the
254261
* length of the buffer.

0 commit comments

Comments
 (0)