10
10
* Bit Generators</em>.
11
11
*
12
12
* The Mbed TLS implementation of CTR_DRBG uses AES-256 (default) or AES-128
13
- * as the underlying block cipher, with a derivation function. The security
14
- * strength is:
15
13
* (if \c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is enabled at compile time)
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:
16
20
* - 256 bits under the default configuration of the library, with AES-256
17
21
* and with #MBEDTLS_CTR_DRBG_ENTROPY_LEN set to 48 or more.
18
22
* - 256 bits if AES-256 is used, #MBEDTLS_CTR_DRBG_ENTROPY_LEN is set
102
106
* \{
103
107
*/
104
108
109
+ /** \def MBEDTLS_CTR_DRBG_ENTROPY_LEN
110
+ *
111
+ * \brief The amount of entropy used per seed by default, in bytes.
112
+ */
105
113
#if !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN )
106
114
#if defined(MBEDTLS_SHA512_C ) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256 )
107
- /** The amount of entropy used per seed by default.
108
- *
109
- * This is 48 bytes because the entropy module uses SHA-512
115
+ /** This is 48 bytes because the entropy module uses SHA-512
110
116
* (\c MBEDTLS_ENTROPY_FORCE_SHA256 is disabled).
111
- *
112
- * \note See mbedtls_ctr_drbg_set_entropy_len() regarding what values are
113
- * acceptable.
114
117
*/
115
118
#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48
116
- #else
117
- /** The amount of entropy used per seed by default.
118
- *
119
- * This is 32 bytes because the entropy module uses SHA-256
120
- * (the SHA512 module is disabled or #MBEDTLS_ENTROPY_FORCE_SHA256 is enabled).
121
- *
122
- * \note See mbedtls_ctr_drbg_set_entropy_len() regarding what values are
123
- * acceptable.
119
+
120
+ #else /* defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256) */
121
+
122
+ /** This is 32 bytes because the entropy module uses SHA-256
123
+ * (the SHA512 module is disabled or
124
+ * \c MBEDTLS_ENTROPY_FORCE_SHA256 is enabled).
125
+ */
126
+ #if !defined(MBEDTLS_CTR_DRBG_USE_128_BIT_KEY )
127
+ /** \warning To achieve a 256-bit security strength, you must pass a nonce
128
+ * to mbedtls_ctr_drbg_seed().
124
129
*/
130
+ #endif /* !defined(MBEDTLS_CTR_DRBG_USE_128_BIT_KEY) */
125
131
#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 32
126
- #endif
127
- #endif
132
+ #endif /* defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256) */
133
+ #endif /* !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) */
128
134
129
135
#if !defined(MBEDTLS_CTR_DRBG_RESEED_INTERVAL )
130
136
#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000
@@ -209,7 +215,10 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
209
215
* entropy sources).
210
216
*
211
217
* \p f_entropy is always called with a buffer size equal to the entropy
212
- * length described in the documentation of mbedtls_ctr_drbg_set_entropy_len().
218
+ * length. The entropy length is initially #MBEDTLS_CTR_DRBG_ENTROPY_LEN
219
+ * and this value is always used for the initial seeding. You can change
220
+ * the entropy length for subsequent seeding by calling
221
+ * mbedtls_ctr_drbg_set_entropy_len().
213
222
*
214
223
* You can provide a personalization string in addition to the
215
224
* entropy source, to make this instantiation as unique as possible.
@@ -221,9 +230,6 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
221
230
* calling \p f_entropy and the \p custom string.
222
231
* The origin of the nonce depends on the value of
223
232
* the entropy length relative to the security strength.
224
- * See the documentation of
225
- * mbedtls_ctr_drbg_set_entropy_len() for information
226
- * about the entropy length.
227
233
* - If the entropy length is at least 1.5 times the
228
234
* security strength then the nonce is taken from the
229
235
* string obtained with \p f_entropy.
@@ -233,7 +239,18 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
233
239
* you must pass a unique value of \p custom at
234
240
* each invocation. See SP 800-90A §8.6.7 for more
235
241
* details.
236
- *
242
+ */
243
+ #if MBEDTLS_CTR_DRBG_ENTROPY_LEN < MBEDTLS_CTR_DRBG_KEYSIZE * 3 / 2
244
+ /** \warning When #MBEDTLS_CTR_DRBG_ENTROPY_LEN is less than
245
+ * #MBEDTLS_CTR_DRBG_KEYSIZE * 3 / 2, to achieve the
246
+ * maximum security strength permitted by CTR_DRBG,
247
+ * you must pass a value of \p custom that is a nonce:
248
+ * this value must never be repeated in subsequent
249
+ * runs of the same application or on a different
250
+ * device.
251
+ */
252
+ #endif
253
+ /**
237
254
* \param ctx The CTR_DRBG context to seed.
238
255
* \param f_entropy The entropy callback, taking as arguments the
239
256
* \p p_entropy context, the buffer to fill, and the
@@ -281,37 +298,26 @@ void mbedtls_ctr_drbg_set_prediction_resistance( mbedtls_ctr_drbg_context *ctx,
281
298
282
299
/**
283
300
* \brief This function sets the amount of entropy grabbed on each
284
- * seed or reseed.
301
+ * subsequent reseed.
285
302
*
286
303
* The default value is #MBEDTLS_CTR_DRBG_ENTROPY_LEN.
287
304
*
288
- * \note For compliance with NIST SP 800-90A, the entropy length
289
- * (\p len bytes = \p len * 8 bits)
290
- * must be at least the security strength.
291
- * Furthermore, if the entropy input is used to provide
292
- * the nonce, the entropy length must be 1.5 times
293
- * the security strength.
294
- * Per NIST SP 800-57A table 2, the achievable security
295
- * strength is 128 bits if using AES-128 and
296
- * 256 bits if using AES-256.
297
- *
298
- * To achieve 256-bit security,
299
- * you must use AES-256 and
300
- * the entropy input must be at least:
301
- * - 48 bytes if the \p custom argument to
302
- * mbedtls_ctr_drbg_seed() may repeat (for example
303
- * because it is empty, or more generally constant);
304
- * - 32 bytes if the \p custom argument to
305
- * mbedtls_ctr_drbg_seed() includes a nonce.
306
- *
307
- * To achieve 128-bit security,
308
- * whether AES-128 or AES-256 is used,
309
- * the entropy input must be at least:
310
- * - 24 bytes if the \p custom argument to
311
- * mbedtls_ctr_drbg_seed() may repeat (for example
312
- * because it is empty, or more generally constant);
313
- * - 16 bytes if the \p custom argument to
314
- * mbedtls_ctr_drbg_seed() includes a nonce.
305
+ * \note The security strength of CTR_DRBG is bounded by the
306
+ * entropy length. Thus:
307
+ * - When using AES-256
308
+ * (\c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is disabled,
309
+ * which is the default),
310
+ * \p len must be at least 32 (in bytes)
311
+ * to achieve a 256-bit strength.
312
+ * - When using AES-128
313
+ * (\c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is enabled)
314
+ * \p len must be at least 16 (in bytes)
315
+ * to achieve a 128-bit strength.
316
+ *
317
+ * \note The initial seeding of the CTR_DRBG instance always
318
+ * grabs #MBEDTLS_CTR_DRBG_ENTROPY_LEN bytes. See
319
+ * the documentation of mbedtls_ctr_drbg_seed()
320
+ * for more information.
315
321
*
316
322
* \param ctx The CTR_DRBG context.
317
323
* \param len The amount of entropy to grab, in bytes.
0 commit comments