|
22 | 22 | * - 256 bits if AES-256 is used, #MBEDTLS_CTR_DRBG_ENTROPY_LEN is set
|
23 | 23 | * to 32 or more, and the DRBG is initialized with an explicit
|
24 | 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. |
25 | 28 | * - 128 bits if AES-256 is used but #MBEDTLS_CTR_DRBG_ENTROPY_LEN is
|
26 | 29 | * between 24 and 47 and the DRBG is not initialized with an explicit
|
27 | 30 | * nonce (see mbedtls_ctr_drbg_seed()).
|
28 | 31 | * - 128 bits if AES-128 is used (\c MBEDTLS_CTR_DRBG_USE_128_BIT_KEY enabled)
|
29 | 32 | * and #MBEDTLS_CTR_DRBG_ENTROPY_LEN is set to 24 or more (which is
|
30 | 33 | * always the case unless it is explicitly set to a different value
|
31 | 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. |
32 | 38 | *
|
33 | 39 | * Note that the value of #MBEDTLS_CTR_DRBG_ENTROPY_LEN defaults to:
|
34 | 40 | * - \c 48 if the module \c MBEDTLS_SHA512_C is enabled and the symbol
|
@@ -172,7 +178,11 @@ typedef struct mbedtls_ctr_drbg_context
|
172 | 178 | int reseed_counter; /*!< The reseed counter.
|
173 | 179 | * This is the number of requests that have
|
174 | 180 | * been made since the last (re)seeding,
|
175 |
| - * minus one. */ |
| 181 | + * minus one. |
| 182 | + * Before the initial seeding, this field |
| 183 | + * contains the amount of entropy in bytes |
| 184 | + * to use as a nonce for the initial seeding. |
| 185 | + */ |
176 | 186 | int prediction_resistance; /*!< This determines whether prediction
|
177 | 187 | resistance is enabled, that is
|
178 | 188 | whether to systematically reseed before
|
@@ -222,43 +232,45 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
|
222 | 232 | * The entropy length is #MBEDTLS_CTR_DRBG_ENTROPY_LEN by default.
|
223 | 233 | * You can override it by calling mbedtls_ctr_drbg_set_entropy_len().
|
224 | 234 | *
|
225 |
| - * You can provide a personalization string in addition to the |
| 235 | + * You can provide a nonce and personalization string in addition to the |
226 | 236 | * entropy source, to make this instantiation as unique as possible.
|
| 237 | + * See SP 800-90A §8.6.7 for more details about nonces. |
| 238 | + * |
| 239 | + * The _seed_material_ value passed to the derivation function in |
| 240 | + * the CTR_DRBG Instantiate Process described in NIST SP 800-90A §10.2.1.3.2 |
| 241 | + * is the concatenation of the following strings: |
| 242 | + * - A string obtained by calling \p f_entropy function for the entropy |
| 243 | + * 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. |
| 249 | + * |
| 250 | + * \note To achieve the nominal security strength permitted |
| 251 | + * by CTR_DRBG, the entropy length must be: |
| 252 | + * - at least 16 bytes for a 128-bit strength |
| 253 | + * (maximum achievable strength when using AES-128); |
| 254 | + * - at least 32 bytes for a 256-bit strength |
| 255 | + * (maximum achievable strength when using AES-256). |
| 256 | + * |
| 257 | + * In addition, if you do not pass a nonce in \p custom, |
| 258 | + * 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: |
| 263 | + * - at least 24 bytes for a 128-bit strength |
| 264 | + * (maximum achievable strength when using AES-128); |
| 265 | + * - at least 48 bytes for a 256-bit strength |
| 266 | + * (maximum achievable strength when using AES-256). |
227 | 267 | *
|
228 |
| - * \note The _seed_material_ value passed to the derivation |
229 |
| - * function in the CTR_DRBG Instantiate Process |
230 |
| - * described in NIST SP 800-90A §10.2.1.3.2 |
231 |
| - * is the concatenation of the string obtained from |
232 |
| - * calling \p f_entropy and the \p custom string. |
233 |
| - * The origin of the nonce depends on the value of |
234 |
| - * the entropy length relative to the security strength. |
235 |
| - * - If the entropy length is at least 1.5 times the |
236 |
| - * security strength then the nonce is taken from the |
237 |
| - * string obtained with \p f_entropy. |
238 |
| - * - If the entropy length is less than the security |
239 |
| - * strength, then the nonce is taken from \p custom. |
240 |
| - * In this case, for compliance with SP 800-90A, |
241 |
| - * you must pass a unique value of \p custom at |
242 |
| - * each invocation. See SP 800-90A §8.6.7 for more |
243 |
| - * details. |
244 |
| - */ |
245 |
| -#if MBEDTLS_CTR_DRBG_ENTROPY_LEN < MBEDTLS_CTR_DRBG_KEYSIZE * 3 / 2 |
246 |
| -/** \warning When #MBEDTLS_CTR_DRBG_ENTROPY_LEN is less than |
247 |
| - * #MBEDTLS_CTR_DRBG_KEYSIZE * 3 / 2, to achieve the |
248 |
| - * maximum security strength permitted by CTR_DRBG, |
249 |
| - * you must pass a value of \p custom that is a nonce: |
250 |
| - * this value must never be repeated in subsequent |
251 |
| - * runs of the same application or on a different |
252 |
| - * device. |
253 |
| - */ |
254 |
| -#endif |
255 |
| -/** |
256 | 268 | * \param ctx The CTR_DRBG context to seed.
|
257 | 269 | * \param f_entropy The entropy callback, taking as arguments the
|
258 | 270 | * \p p_entropy context, the buffer to fill, and the
|
259 | 271 | * length of the buffer.
|
260 | 272 | * \p f_entropy is always called with a buffer size
|
261 |
| - * equal to the entropy length. |
| 273 | + * less than or equal to the entropy length. |
262 | 274 | * \param p_entropy The entropy context to pass to \p f_entropy.
|
263 | 275 | * \param custom The personalization string.
|
264 | 276 | * This can be \c NULL, in which case the personalization
|
@@ -320,11 +332,35 @@ void mbedtls_ctr_drbg_set_prediction_resistance( mbedtls_ctr_drbg_context *ctx,
|
320 | 332 | *
|
321 | 333 | * \param ctx The CTR_DRBG context.
|
322 | 334 | * \param len The amount of entropy to grab, in bytes.
|
323 |
| - * This must be at most #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT. |
| 335 | + * This must be at most #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT |
| 336 | + * and at most the maximum length accepted by the |
| 337 | + * entropy function that is set in the context. |
324 | 338 | */
|
325 | 339 | void mbedtls_ctr_drbg_set_entropy_len( mbedtls_ctr_drbg_context *ctx,
|
326 | 340 | size_t len );
|
327 | 341 |
|
| 342 | +/** |
| 343 | + * \brief This function sets the amount of entropy grabbed |
| 344 | + * as a nonce for the initial seeding. |
| 345 | + * |
| 346 | + * Call this function before calling mbedtls_ctr_drbg_seed() to read |
| 347 | + * a nonce from the entropy source during the initial seeding. |
| 348 | + * |
| 349 | + * \param ctx The CTR_DRBG context. |
| 350 | + * \param len The amount of entropy to grab for the nonce, in bytes. |
| 351 | + * This must be at most #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT |
| 352 | + * and at most the maximum length accepted by the |
| 353 | + * entropy function that is set in the context. |
| 354 | + * |
| 355 | + * \return \c 0 on success. |
| 356 | + * \return #MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG if \p len is |
| 357 | + * more than #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT. |
| 358 | + * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED |
| 359 | + * if the initial seeding has already taken place. |
| 360 | + */ |
| 361 | +int mbedtls_ctr_drbg_set_nonce_len( mbedtls_ctr_drbg_context *ctx, |
| 362 | + size_t len ); |
| 363 | + |
328 | 364 | /**
|
329 | 365 | * \brief This function sets the reseed interval.
|
330 | 366 | *
|
|
0 commit comments