12
12
* The Mbed TLS implementation of CTR_DRBG uses AES-256 (default) or AES-128
13
13
* (if \c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is enabled at compile time)
14
14
* as the underlying block cipher, with a derivation function.
15
- * The initial seeding grabs #MBEDTLS_CTR_DRBG_ENTROPY_LEN bytes of entropy.
16
- * See the documentation of mbedtls_ctr_drbg_seed() for more details.
17
- *
18
- * Based on NIST SP 800-90A §10.2.1 table 3 and NIST SP 800-57 part 1 table 2,
19
- * here are the security strengths achieved in typical configuration:
20
- * - 256 bits under the default configuration of the library, with AES-256
21
- * and with #MBEDTLS_CTR_DRBG_ENTROPY_LEN set to 48 or more.
22
- * - 256 bits if AES-256 is used, #MBEDTLS_CTR_DRBG_ENTROPY_LEN is set
23
- * to 32 or more, and the DRBG is initialized with an explicit
24
- * nonce in the \c custom parameter to mbedtls_ctr_drbg_seed().
25
- * - 256 bits if AES-256 is used, #MBEDTLS_CTR_DRBG_ENTROPY_LEN is set
26
- * to 32 or more, and mbedtls_ctr_drbg_set_nonce_len() is called to set
27
- * an entropy nonce length of 16 bytes or more.
28
- * - 128 bits if AES-256 is used but #MBEDTLS_CTR_DRBG_ENTROPY_LEN is
29
- * between 24 and 47 and the DRBG is not initialized with an explicit
30
- * nonce (see mbedtls_ctr_drbg_seed()).
31
- * - 128 bits if AES-128 is used (\c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY enabled)
32
- * and #MBEDTLS_CTR_DRBG_ENTROPY_LEN is set to 24 or more (which is
33
- * always the case unless it is explicitly set to a different value
34
- * in config.h).
35
- * - 128 bits if AES-128 is used (\c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY enabled)
36
- * to 16 or more, and mbedtls_ctr_drbg_set_nonce_len() is called to set
37
- * an entropy nonce length of 8 bytes or more.
38
- *
39
- * Note that the value of #MBEDTLS_CTR_DRBG_ENTROPY_LEN defaults to:
40
- * - \c 48 if the module \c MBEDTLS_SHA512_C is enabled and the symbol
41
- * \c MBEDTLS_ENTROPY_FORCE_SHA256 is disabled at compile time.
42
- * This is the default configuration of the library.
43
- * - \c 32 if the module \c MBEDTLS_SHA512_C is disabled at compile time.
44
- * - \c 32 if \c MBEDTLS_ENTROPY_FORCE_SHA256 is enabled at compile time.
15
+ *
16
+ * The security strength as defined in NIST SP 800-90A is
17
+ * 128 bits when AES-128 is used (\c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY enabled)
18
+ * and 256 bits otherwise, provided that #MBEDTLS_CTR_DRBG_ENTROPY_LEN is
19
+ * kept at its default value (and not overridden in config.h) and that the
20
+ * DRBG instance is set up with default parameters.
21
+ * See the documentation of mbedtls_ctr_drbg_seed() for more
22
+ * information.
45
23
*/
46
24
/*
47
25
* Copyright (C) 2006-2019, Arm Limited (or its affiliates), All Rights Reserved
@@ -232,6 +210,26 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
232
210
* The entropy length is #MBEDTLS_CTR_DRBG_ENTROPY_LEN by default.
233
211
* You can override it by calling mbedtls_ctr_drbg_set_entropy_len().
234
212
*
213
+ * The entropy nonce length is:
214
+ * - \c 0 if the entropy length is at least 3/2 times the entropy length,
215
+ * which guarantees that the security strength is the maximum permitted
216
+ * by the key size and entropy length according to NIST SP 800-90A §10.2.1;
217
+ * - Half the entropy length otherwise.
218
+ * You can override it by calling mbedtls_ctr_drbg_set_nonce_len().
219
+ */
220
+ #if MBEDTLS_CTR_DRBG_ENTROPY_LEN >= MBEDTLS_CTR_DRBG_KEYSIZE * 3 / 2
221
+ /** With the default entropy length, the entropy nonce length is \c 0.
222
+ */
223
+ #elif MBEDTLS_CTR_DRBG_ENTROPY_LEN & 1
224
+ /** With the default entropy length, the entropy nonce length is
225
+ * (#MBEDTLS_CTR_DRBG_ENTROPY_LEN + 1) / 2.
226
+ */
227
+ #else
228
+ /** With the default entropy length, the entropy nonce length is
229
+ * #MBEDTLS_CTR_DRBG_ENTROPY_LEN / 2.
230
+ */
231
+ #endif
232
+ /*
235
233
* You can provide a nonce and personalization string in addition to the
236
234
* entropy source, to make this instantiation as unique as possible.
237
235
* See SP 800-90A §8.6.7 for more details about nonces.
@@ -241,11 +239,18 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
241
239
* is the concatenation of the following strings:
242
240
* - A string obtained by calling \p f_entropy function for the entropy
243
241
* length.
244
- * - A string obtained by calling \p f_entropy function for the nonce
245
- * length set with mbedtls_ctr_drbg_set_nonce_len(). If the entropy
246
- * nonce length is \c 0, this function does not make a second call
247
- * to \p f_entropy.
248
- * - The \p custom string.
242
+ */
243
+ #if MBEDTLS_CTR_DRBG_ENTROPY_LEN >= MBEDTLS_CTR_DRBG_KEYSIZE * 3 / 2
244
+ /* - If mbedtls_ctr_drbg_set_nonce_len() has been called, a string
245
+ * obtained by calling \p f_entropy function for the specified length.
246
+ */
247
+ #else
248
+ /* - A string obtained by calling \p f_entropy function for the entropy nonce
249
+ * length. If the entropy nonce length is \c 0, this function does not
250
+ * make a second call to \p f_entropy.
251
+ */
252
+ #endif
253
+ /* - The \p custom string.
249
254
*
250
255
* \note To achieve the nominal security strength permitted
251
256
* by CTR_DRBG, the entropy length must be:
@@ -256,10 +261,7 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
256
261
*
257
262
* In addition, if you do not pass a nonce in \p custom,
258
263
* the sum of the entropy length
259
- * (#MBEDTLS_CTR_DRBG_ENTROPY_LEN unless overridden with
260
- * mbedtls_ctr_drbg_set_entropy_len())
261
- * and the entropy nonce length (\c 0 unless overridden
262
- * with mbedtls_ctr_drbg_set_nonce_len()) must be:
264
+ * and the entropy nonce length must be:
263
265
* - at least 24 bytes for a 128-bit strength
264
266
* (maximum achievable strength when using AES-128);
265
267
* - at least 48 bytes for a 256-bit strength
0 commit comments