10
10
* Bit Generators</em>.
11
11
*
12
12
* The Mbed TLS implementation of CTR_DRBG uses AES-256 (default) or AES-128
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:
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
- * - 128 bits if AES-256 is used but #MBEDTLS_CTR_DRBG_ENTROPY_LEN is
26
- * between 24 and 47 and the DRBG is not initialized with an explicit
27
- * nonce (see mbedtls_ctr_drbg_seed()).
28
- * - 128 bits if AES-128 is used (\c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY set)
29
- * and #MBEDTLS_CTR_DRBG_ENTROPY_LEN is set to 24 or more (which is
30
- * always the case unless it is explicitly set to a different value
31
- * in config.h).
13
+ * (if #MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is enabled at compile time)
14
+ * as the underlying block cipher, with a derivation function. The security
15
+ * strength is the smaller of the AES key size and the entropy length.
32
16
*
33
17
* Note that the value of #MBEDTLS_CTR_DRBG_ENTROPY_LEN defaults to:
34
- * - \c 48 if the module \c MBEDTLS_SHA512_C is enabled and the symbol
35
- * \c MBEDTLS_ENTROPY_FORCE_SHA256 is disabled at compile time.
18
+ * - \c 48 bytes if the module # MBEDTLS_SHA512_C is enabled and the symbol
19
+ * # MBEDTLS_ENTROPY_FORCE_SHA256 is not enabled at compile time.
36
20
* This is the default configuration of the library.
37
- * - \c 32 if the module \c MBEDTLS_SHA512_C is disabled at compile time.
38
- * - \c 32 if \c MBEDTLS_ENTROPY_FORCE_SHA256 is enabled at compile time.
21
+ * - \c 32 bytes if the module #MBEDTLS_SHA512_C is disabled at compile time.
22
+ * - \c 32 bytes if #MBEDTLS_ENTROPY_FORCE_SHA256 is enabled at compile time.
23
+ *
24
+ * This is always sufficient to reach the maximum security strength that can
25
+ * be achieved given the AES key size.
39
26
*/
40
27
/*
41
28
* Copyright (C) 2006-2019, Arm Limited (or its affiliates), All Rights Reserved
123
110
* (the SHA512 module is disabled or
124
111
* \c MBEDTLS_ENTROPY_FORCE_SHA256 is enabled).
125
112
*/
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().
129
- */
130
- #endif /* !defined(MBEDTLS_CTR_DRBG_USE_128_BIT_KEY) */
131
113
#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 32
132
114
#endif /* defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256) */
133
115
#endif /* !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) */
134
116
117
+ /** The length of the nonce for the initial seeding.
118
+ *
119
+ * This implementation always reads a nonce from the entropy source.
120
+ */
121
+ #define MBEDTLS_CTR_DRBG_NONCE_LEN (MBEDTLS_CTR_DRBG_ENTROPY_LEN / 2)
122
+
135
123
#if !defined(MBEDTLS_CTR_DRBG_RESEED_INTERVAL )
136
124
#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000
137
125
/**< The interval before reseed is performed by default. */
@@ -214,41 +202,23 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
214
202
* with mbedtls_entropy_init() (which registers the platform's default
215
203
* entropy sources).
216
204
*
217
- * \p f_entropy is always called with a buffer size equal to the entropy
205
+ * \p f_entropy is always called with a buffer size less or equal to the entropy
218
206
* length. The entropy length is initially #MBEDTLS_CTR_DRBG_ENTROPY_LEN
219
207
* and can be changed by calling mbedtls_ctr_drbg_set_entropy_len().
220
208
*
221
209
* You can provide a personalization string in addition to the
222
210
* entropy source, to make this instantiation as unique as possible.
223
211
*
224
- * \note The _seed_material_ value passed to the derivation
225
- * function in the CTR_DRBG Instantiate Process
226
- * described in NIST SP 800-90A §10.2.1.3.2
227
- * is the concatenation of the string obtained from
228
- * calling \p f_entropy and the \p custom string.
229
- * The origin of the nonce depends on the value of
230
- * the entropy length relative to the security strength.
231
- * - If the entropy length is at least 1.5 times the
232
- * security strength then the nonce is taken from the
233
- * string obtained with \p f_entropy.
234
- * - If the entropy length is less than the security
235
- * strength, then the nonce is taken from \p custom.
236
- * In this case, for compliance with SP 800-90A,
237
- * you must pass a unique value of \p custom at
238
- * each invocation. See SP 800-90A §8.6.7 for more
239
- * details.
240
- */
241
- #if MBEDTLS_CTR_DRBG_ENTROPY_LEN < MBEDTLS_CTR_DRBG_KEYSIZE * 3 / 2
242
- /** \warning When #MBEDTLS_CTR_DRBG_ENTROPY_LEN is less than
243
- * #MBEDTLS_CTR_DRBG_KEYSIZE * 3 / 2, to achieve the
244
- * maximum security strength permitted by CTR_DRBG,
245
- * you must pass a value of \p custom that is a nonce:
246
- * this value must never be repeated in subsequent
247
- * runs of the same application or on a different
248
- * device.
249
- */
250
- #endif
251
- /**
212
+ * The _seed_material_ value passed to the derivation
213
+ * function in the CTR_DRBG Instantiate Process
214
+ * described in NIST SP 800-90A §10.2.1.3.2
215
+ * is the concatenation of:
216
+ * - the entropy input, obtained by calling \p f_entropy for
217
+ * #MBEDTLS_CTR_DRBG_ENTROPY_LEN bytes;
218
+ * - the nonce, obtained by calling \p f_entropy for
219
+ * #MBEDTLS_CTR_DRBG_NONCE_LEN bytes;
220
+ * - the \p custom string.
221
+ *
252
222
* \param ctx The CTR_DRBG context to seed.
253
223
* \param f_entropy The entropy callback, taking as arguments the
254
224
* \p p_entropy context, the buffer to fill, and the
@@ -261,6 +231,7 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
261
231
* This must be at most
262
232
* #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT
263
233
* - #MBEDTLS_CTR_DRBG_ENTROPY_LEN.
234
+ * - #MBEDTLS_CTR_DRBG_NONCE_LEN.
264
235
*
265
236
* \return \c 0 on success.
266
237
* \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure.
@@ -300,22 +271,8 @@ void mbedtls_ctr_drbg_set_prediction_resistance( mbedtls_ctr_drbg_context *ctx,
300
271
*
301
272
* The default value is #MBEDTLS_CTR_DRBG_ENTROPY_LEN.
302
273
*
303
- * \note The security strength of CTR_DRBG is bounded by the
304
- * entropy length. Thus:
305
- * - When using AES-256
306
- * (\c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is disabled,
307
- * which is the default),
308
- * \p len must be at least 32 (in bytes)
309
- * to achieve a 256-bit strength.
310
- * - When using AES-128
311
- * (\c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is enabled)
312
- * \p len must be at least 16 (in bytes)
313
- * to achieve a 128-bit strength.
314
- *
315
- * \note The initial seeding of the CTR_DRBG instance always
316
- * grabs #MBEDTLS_CTR_DRBG_ENTROPY_LEN bytes. See
317
- * the documentation of mbedtls_ctr_drbg_seed()
318
- * for more information.
274
+ * This function has no effect on the initial seeding,
275
+ * even if you call it before mbedtls_ctr_drbg_seed().
319
276
*
320
277
* \param ctx The CTR_DRBG context.
321
278
* \param len The amount of entropy to grab, in bytes.
@@ -500,7 +457,7 @@ int mbedtls_ctr_drbg_self_test( int verbose );
500
457
/* Internal functions (do not call directly) */
501
458
int mbedtls_ctr_drbg_seed_entropy_len ( mbedtls_ctr_drbg_context * ,
502
459
int (* )(void * , unsigned char * , size_t ), void * ,
503
- const unsigned char * , size_t , size_t );
460
+ const unsigned char * , size_t , size_t , size_t );
504
461
505
462
#ifdef __cplusplus
506
463
}
0 commit comments