Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file ctr_drbg.h |
| 3 | * |
Gilles Peskine | ec51dd1 | 2019-09-30 15:01:02 +0200 | [diff] [blame] | 4 | * \brief This file contains definitions and functions for the |
| 5 | * CTR_DRBG pseudorandom generator. |
Rose Zadik | c9474eb | 2018-03-27 10:58:22 +0100 | [diff] [blame] | 6 | * |
Rose Zadik | f25eb6e | 2018-04-16 14:51:52 +0100 | [diff] [blame] | 7 | * CTR_DRBG is a standardized way of building a PRNG from a block-cipher |
| 8 | * in counter mode operation, as defined in <em>NIST SP 800-90A: |
| 9 | * Recommendation for Random Number Generation Using Deterministic Random |
| 10 | * Bit Generators</em>. |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 11 | * |
Nir Sonnenschein | eb73f7a | 2018-07-30 17:46:49 +0300 | [diff] [blame] | 12 | * The Mbed TLS implementation of CTR_DRBG uses AES-256 (default) or AES-128 |
Gilles Peskine | 223deea | 2019-09-24 14:48:53 +0200 | [diff] [blame] | 13 | * as the underlying block cipher, with a derivation function. The security |
| 14 | * strength is: |
| 15 | * - 256 bits under the default configuration of the library, with AES-256 |
| 16 | * (`MBEDTLS_CTR_DRBG_USE_128_BIT_KEY` not set) and |
| 17 | * with #MBEDTLS_CTR_DRBG_ENTROPY_LEN set to 48 or more. |
| 18 | * - 256 bits if AES-256 is used, #MBEDTLS_CTR_DRBG_ENTROPY_LEN is set |
| 19 | * to 32 or more, and the DRBG is initialized with an explicit |
| 20 | * nonce in the \c custom parameter to mbedtls_ctr_drbg_seed(). |
| 21 | * - 128 bits if AES-256 is used but #MBEDTLS_CTR_DRBG_ENTROPY_LEN is |
| 22 | * between 24 and 47 and the DRBG is not initialized with an explicit |
| 23 | * nonce (see mbedtls_ctr_drbg_seed()). |
| 24 | * - 128 bits if AES-128 is used (`MBEDTLS_CTR_DRBG_USE_128_BIT_KEY` set) |
| 25 | * and #MBEDTLS_CTR_DRBG_ENTROPY_LEN is set to 24 or more (which is |
| 26 | * always the case unless it is explicitly set to a different value |
| 27 | * in `config.h`). |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 28 | */ |
| 29 | /* |
Gilles Peskine | 08875d4 | 2019-09-24 14:40:40 +0200 | [diff] [blame] | 30 | * Copyright (C) 2006-2019, Arm Limited (or its affiliates), All Rights Reserved |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 31 | * SPDX-License-Identifier: Apache-2.0 |
| 32 | * |
| 33 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 34 | * not use this file except in compliance with the License. |
| 35 | * You may obtain a copy of the License at |
| 36 | * |
| 37 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 38 | * |
| 39 | * Unless required by applicable law or agreed to in writing, software |
| 40 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 41 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 42 | * See the License for the specific language governing permissions and |
| 43 | * limitations under the License. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 44 | * |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 45 | * This file is part of Mbed TLS (https://tls.mbed.org) |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 46 | */ |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 47 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 48 | #ifndef MBEDTLS_CTR_DRBG_H |
| 49 | #define MBEDTLS_CTR_DRBG_H |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 50 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 51 | #if !defined(MBEDTLS_CONFIG_FILE) |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 52 | #include "mbedtls/config.h" |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 53 | #else |
| 54 | #include MBEDTLS_CONFIG_FILE |
| 55 | #endif |
| 56 | |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 57 | #include "mbedtls/aes.h" |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 58 | |
Manuel Pégourié-Gonnard | 0a4fb09 | 2015-05-07 12:50:31 +0100 | [diff] [blame] | 59 | #if defined(MBEDTLS_THREADING_C) |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 60 | #include "mbedtls/threading.h" |
Manuel Pégourié-Gonnard | 0a4fb09 | 2015-05-07 12:50:31 +0100 | [diff] [blame] | 61 | #endif |
| 62 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 63 | #define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034 /**< The entropy source failed. */ |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 64 | #define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036 /**< The requested random buffer length is too big. */ |
| 65 | #define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038 /**< The input (entropy + additional data) is too large. */ |
| 66 | #define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A /**< Read or write error in file. */ |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 67 | |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 68 | #define MBEDTLS_CTR_DRBG_BLOCKSIZE 16 /**< The block size used by the cipher. */ |
Nir Sonnenschein | ce266e4 | 2018-08-29 10:11:46 +0300 | [diff] [blame] | 69 | |
Nir Sonnenschein | 43e4ff0 | 2018-09-03 14:15:46 +0300 | [diff] [blame] | 70 | #if defined(MBEDTLS_CTR_DRBG_USE_128_BIT_KEY) |
Gilles Peskine | 08875d4 | 2019-09-24 14:40:40 +0200 | [diff] [blame] | 71 | #define MBEDTLS_CTR_DRBG_KEYSIZE 16 |
| 72 | /**< The key size in bytes used by the cipher. |
| 73 | * |
| 74 | * Compile-time choice: 16 bytes (128 bits) |
| 75 | * because #MBEDTLS_CTR_DRBG_USE_128_BIT_KEY is set. |
| 76 | */ |
Nir Sonnenschein | eb73f7a | 2018-07-30 17:46:49 +0300 | [diff] [blame] | 77 | #else |
Gilles Peskine | 08875d4 | 2019-09-24 14:40:40 +0200 | [diff] [blame] | 78 | #define MBEDTLS_CTR_DRBG_KEYSIZE 32 |
| 79 | /**< The key size in bytes used by the cipher. |
| 80 | * |
| 81 | * Compile-time choice: 32 bytes (256 bits) |
| 82 | * because `MBEDTLS_CTR_DRBG_USE_128_BIT_KEY` is not set. |
| 83 | */ |
Nir Sonnenschein | a4588d4 | 2018-07-30 16:59:36 +0300 | [diff] [blame] | 84 | #endif |
Nir Sonnenschein | 43e4ff0 | 2018-09-03 14:15:46 +0300 | [diff] [blame] | 85 | |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 86 | #define MBEDTLS_CTR_DRBG_KEYBITS ( MBEDTLS_CTR_DRBG_KEYSIZE * 8 ) /**< The key size for the DRBG operation, in bits. */ |
| 87 | #define MBEDTLS_CTR_DRBG_SEEDLEN ( MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE ) /**< The seed length, calculated as (counter + AES key). */ |
Paul Bakker | 9bcf16c | 2013-06-24 19:31:17 +0200 | [diff] [blame] | 88 | |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 89 | /** |
| 90 | * \name SECTION: Module settings |
| 91 | * |
| 92 | * The configuration options you can set for this module are in this section. |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 93 | * Either change them in config.h or define them using the compiler command |
| 94 | * line. |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 95 | * \{ |
| 96 | */ |
| 97 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 98 | #if !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) |
| 99 | #if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256) |
Gilles Peskine | 08875d4 | 2019-09-24 14:40:40 +0200 | [diff] [blame] | 100 | /** The amount of entropy used per seed by default. |
| 101 | * |
| 102 | * This is 48 bytes because the entropy module uses SHA-512 |
| 103 | * (`MBEDTLS_ENTROPY_FORCE_SHA256` is not set). |
| 104 | * |
| 105 | * \note See mbedtls_ctr_drbg_set_entropy_len() regarding what values are |
| 106 | * acceptable. |
| 107 | */ |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 108 | #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48 |
Paul Bakker | fb08fd2 | 2013-08-27 15:06:26 +0200 | [diff] [blame] | 109 | #else |
Gilles Peskine | 08875d4 | 2019-09-24 14:40:40 +0200 | [diff] [blame] | 110 | /** The amount of entropy used per seed by default. |
| 111 | * |
| 112 | * This is 32 bytes because the entropy module uses SHA-256 |
| 113 | * (the SHA-512 module is disabled or `MBEDTLS_ENTROPY_FORCE_SHA256` is set). |
| 114 | * |
| 115 | * \note See mbedtls_ctr_drbg_set_entropy_len() regarding what values are |
| 116 | * acceptable. |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 117 | */ |
Gilles Peskine | 08875d4 | 2019-09-24 14:40:40 +0200 | [diff] [blame] | 118 | #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 32 |
Paul Bakker | fb08fd2 | 2013-08-27 15:06:26 +0200 | [diff] [blame] | 119 | #endif |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 120 | #endif |
| 121 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 122 | #if !defined(MBEDTLS_CTR_DRBG_RESEED_INTERVAL) |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 123 | #define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000 |
| 124 | /**< The interval before reseed is performed by default. */ |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 125 | #endif |
| 126 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 127 | #if !defined(MBEDTLS_CTR_DRBG_MAX_INPUT) |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 128 | #define MBEDTLS_CTR_DRBG_MAX_INPUT 256 |
| 129 | /**< The maximum number of additional input Bytes. */ |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 130 | #endif |
| 131 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 132 | #if !defined(MBEDTLS_CTR_DRBG_MAX_REQUEST) |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 133 | #define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024 |
| 134 | /**< The maximum number of requested Bytes per call. */ |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 135 | #endif |
| 136 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 137 | #if !defined(MBEDTLS_CTR_DRBG_MAX_SEED_INPUT) |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 138 | #define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384 |
Gilles Peskine | 08875d4 | 2019-09-24 14:40:40 +0200 | [diff] [blame] | 139 | /**< The maximum size of seed or reseed buffer in bytes. */ |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 140 | #endif |
| 141 | |
| 142 | /* \} name SECTION: Module settings */ |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 143 | |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 144 | #define MBEDTLS_CTR_DRBG_PR_OFF 0 |
| 145 | /**< Prediction resistance is disabled. */ |
| 146 | #define MBEDTLS_CTR_DRBG_PR_ON 1 |
| 147 | /**< Prediction resistance is enabled. */ |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 148 | |
| 149 | #ifdef __cplusplus |
| 150 | extern "C" { |
| 151 | #endif |
| 152 | |
| 153 | /** |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 154 | * \brief The CTR_DRBG context structure. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 155 | */ |
Dawid Drozd | 428cc52 | 2018-07-24 10:02:47 +0200 | [diff] [blame] | 156 | typedef struct mbedtls_ctr_drbg_context |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 157 | { |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 158 | unsigned char counter[16]; /*!< The counter (V). */ |
| 159 | int reseed_counter; /*!< The reseed counter. */ |
| 160 | int prediction_resistance; /*!< This determines whether prediction |
| 161 | resistance is enabled, that is |
| 162 | whether to systematically reseed before |
| 163 | each random generation. */ |
| 164 | size_t entropy_len; /*!< The amount of entropy grabbed on each |
| 165 | seed or reseed operation. */ |
| 166 | int reseed_interval; /*!< The reseed interval. */ |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 167 | |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 168 | mbedtls_aes_context aes_ctx; /*!< The AES context. */ |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 169 | |
| 170 | /* |
| 171 | * Callbacks (Entropy) |
| 172 | */ |
| 173 | int (*f_entropy)(void *, unsigned char *, size_t); |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 174 | /*!< The entropy callback function. */ |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 175 | |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 176 | void *p_entropy; /*!< The context for the entropy function. */ |
Manuel Pégourié-Gonnard | 0a4fb09 | 2015-05-07 12:50:31 +0100 | [diff] [blame] | 177 | |
| 178 | #if defined(MBEDTLS_THREADING_C) |
| 179 | mbedtls_threading_mutex_t mutex; |
| 180 | #endif |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 181 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 182 | mbedtls_ctr_drbg_context; |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 183 | |
| 184 | /** |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 185 | * \brief This function initializes the CTR_DRBG context, |
| 186 | * and prepares it for mbedtls_ctr_drbg_seed() |
| 187 | * or mbedtls_ctr_drbg_free(). |
Manuel Pégourié-Gonnard | 8d128ef | 2015-04-28 22:38:08 +0200 | [diff] [blame] | 188 | * |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 189 | * \param ctx The CTR_DRBG context to initialize. |
Manuel Pégourié-Gonnard | 8d128ef | 2015-04-28 22:38:08 +0200 | [diff] [blame] | 190 | */ |
| 191 | void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx ); |
| 192 | |
| 193 | /** |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 194 | * \brief This function seeds and sets up the CTR_DRBG |
| 195 | * entropy source for future reseeds. |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 196 | * |
Gilles Peskine | 223deea | 2019-09-24 14:48:53 +0200 | [diff] [blame] | 197 | * A typical choice for the \p f_entropy and \p p_entropy parameters is |
| 198 | * to use the entropy module: |
| 199 | * - \p f_entropy is mbedtls_entropy_func(); |
| 200 | * - \p p_entropy is an instance of ::mbedtls_entropy_context initialized |
| 201 | * with mbedtls_entropy_init() (which registers the platform's default |
| 202 | * entropy sources). |
| 203 | * |
Gilles Peskine | ec51dd1 | 2019-09-30 15:01:02 +0200 | [diff] [blame] | 204 | * \p f_entropy is always called with a buffer size equal to the entropy |
| 205 | * length described in the documentation of mbedtls_ctr_drbg_set_entropy_len(). |
| 206 | * |
Gilles Peskine | 217b815 | 2019-10-01 18:39:45 +0200 | [diff] [blame] | 207 | * You can provide a personalization string in addition to the |
Gilles Peskine | 223deea | 2019-09-24 14:48:53 +0200 | [diff] [blame] | 208 | * entropy source, to make this instantiation as unique as possible. |
| 209 | * |
| 210 | * \note The _seed_material_ value passed to the derivation |
| 211 | * function in the CTR_DRBG Instantiate Process |
| 212 | * described in NIST SP 800-90A §10.2.1.3.2 |
| 213 | * is the concatenation of the string obtained from |
| 214 | * calling \p f_entropy and the \p custom string. |
| 215 | * The origin of the nonce depends on the value of |
| 216 | * the entropy length relative to the security strength. |
| 217 | * See the documentation of |
| 218 | * mbedtls_ctr_drbg_set_entropy_len() for information |
| 219 | * about the entropy length. |
| 220 | * - If the entropy length is at least 1.5 times the |
| 221 | * security strength then the nonce is taken from the |
| 222 | * string obtained with \p f_entropy. |
| 223 | * - If the entropy length is less than the security |
| 224 | * strength, then the nonce is taken from \p custom. |
| 225 | * In this case, for compliance with SP 800-90A, |
| 226 | * you must pass a unique value of \p custom at |
| 227 | * each invocation. See SP 800-90A §8.6.7 for more |
| 228 | * details. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 229 | * |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 230 | * \param ctx The CTR_DRBG context to seed. |
| 231 | * \param f_entropy The entropy callback, taking as arguments the |
| 232 | * \p p_entropy context, the buffer to fill, and the |
Gilles Peskine | 08875d4 | 2019-09-24 14:40:40 +0200 | [diff] [blame] | 233 | * length of the buffer. |
Gilles Peskine | ec51dd1 | 2019-09-30 15:01:02 +0200 | [diff] [blame] | 234 | * \param p_entropy The entropy context to pass to \p f_entropy. |
Gilles Peskine | 217b815 | 2019-10-01 18:39:45 +0200 | [diff] [blame] | 235 | * \param custom The personalization string. |
| 236 | * This can be \c NULL, in which case the personalization |
| 237 | * string is empty regardless of the value of \p len. |
| 238 | * \param len The length of the personalization string. |
Gilles Peskine | 944bc58 | 2019-09-24 14:48:30 +0200 | [diff] [blame] | 239 | * This must be at most |
| 240 | * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT |
| 241 | * - #MBEDTLS_CTR_DRBG_ENTROPY_LEN. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 242 | * |
Rose Zadik | c9474eb | 2018-03-27 10:58:22 +0100 | [diff] [blame] | 243 | * \return \c 0 on success. |
| 244 | * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 245 | */ |
Manuel Pégourié-Gonnard | 8d128ef | 2015-04-28 22:38:08 +0200 | [diff] [blame] | 246 | int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *ctx, |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 247 | int (*f_entropy)(void *, unsigned char *, size_t), |
| 248 | void *p_entropy, |
Paul Bakker | 1bc9efc | 2011-12-03 11:29:32 +0000 | [diff] [blame] | 249 | const unsigned char *custom, |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 250 | size_t len ); |
| 251 | |
| 252 | /** |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 253 | * \brief This function clears CTR_CRBG context data. |
Paul Bakker | fff0366 | 2014-06-18 16:21:25 +0200 | [diff] [blame] | 254 | * |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 255 | * \param ctx The CTR_DRBG context to clear. |
Paul Bakker | fff0366 | 2014-06-18 16:21:25 +0200 | [diff] [blame] | 256 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 257 | void mbedtls_ctr_drbg_free( mbedtls_ctr_drbg_context *ctx ); |
Paul Bakker | fff0366 | 2014-06-18 16:21:25 +0200 | [diff] [blame] | 258 | |
| 259 | /** |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 260 | * \brief This function turns prediction resistance on or off. |
| 261 | * The default value is off. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 262 | * |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 263 | * \note If enabled, entropy is gathered at the beginning of |
Gilles Peskine | ec51dd1 | 2019-09-30 15:01:02 +0200 | [diff] [blame] | 264 | * every call to mbedtls_ctr_drbg_random_with_add() |
| 265 | * or mbedtls_ctr_drbg_random(). |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 266 | * Only use this if your entropy source has sufficient |
| 267 | * throughput. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 268 | * |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 269 | * \param ctx The CTR_DRBG context. |
| 270 | * \param resistance #MBEDTLS_CTR_DRBG_PR_ON or #MBEDTLS_CTR_DRBG_PR_OFF. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 271 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 272 | void mbedtls_ctr_drbg_set_prediction_resistance( mbedtls_ctr_drbg_context *ctx, |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 273 | int resistance ); |
| 274 | |
| 275 | /** |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 276 | * \brief This function sets the amount of entropy grabbed on each |
Gilles Peskine | ec51dd1 | 2019-09-30 15:01:02 +0200 | [diff] [blame] | 277 | * seed or reseed. |
| 278 | * |
| 279 | * The default value is #MBEDTLS_CTR_DRBG_ENTROPY_LEN. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 280 | * |
Gilles Peskine | 223deea | 2019-09-24 14:48:53 +0200 | [diff] [blame] | 281 | * \note For compliance with NIST SP 800-90A, the entropy length |
Gilles Peskine | 6fdf0b3 | 2019-09-25 20:22:40 +0200 | [diff] [blame] | 282 | * (\p len bytes = \p len * 8 bits) |
| 283 | * must be at least the security strength. |
| 284 | * Furthermore, if the entropy input is used to provide |
| 285 | * the nonce, the entropy length must be 1.5 times |
| 286 | * the security strength. |
| 287 | * Per NIST SP 800-57A table 2, the achievable security |
| 288 | * strength is 128 bits if using AES-128 and |
| 289 | * 256 bits if using AES-256. |
| 290 | * Therefore, to provide full security, |
| 291 | * the entropy input must be at least: |
| 292 | * - 24 bytes if using AES-128 and the \p custom |
| 293 | * argument to mbedtls_ctr_drbg_seed() may repeat |
| 294 | * (for example because it is empty, or more generally |
| 295 | * constant); |
| 296 | * - 48 bytes if using AES-256 and the \p custom |
| 297 | * argument to mbedtls_ctr_drbg_seed() may repeat |
| 298 | * (for example because it is empty, or more generally |
| 299 | * constant); |
| 300 | * - 16 bytes if using AES-128 and the \p custom |
| 301 | * argument to mbedtls_ctr_drbg_seed() includes |
| 302 | * a nonce; |
| 303 | * - 32 bytes if using AES-256 and the \p custom |
| 304 | * argument to mbedtls_ctr_drbg_seed() includes |
| 305 | * a nonce. |
Gilles Peskine | 223deea | 2019-09-24 14:48:53 +0200 | [diff] [blame] | 306 | * |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 307 | * \param ctx The CTR_DRBG context. |
Gilles Peskine | 08875d4 | 2019-09-24 14:40:40 +0200 | [diff] [blame] | 308 | * \param len The amount of entropy to grab, in bytes. |
Gilles Peskine | 944bc58 | 2019-09-24 14:48:30 +0200 | [diff] [blame] | 309 | * This must be at most #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 310 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 311 | void mbedtls_ctr_drbg_set_entropy_len( mbedtls_ctr_drbg_context *ctx, |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 312 | size_t len ); |
| 313 | |
| 314 | /** |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 315 | * \brief This function sets the reseed interval. |
Gilles Peskine | ec51dd1 | 2019-09-30 15:01:02 +0200 | [diff] [blame] | 316 | * |
| 317 | * The reseed interval is the number of calls to mbedtls_ctr_drbg_random() |
| 318 | * or mbedtls_ctr_drbg_random_with_add() after which the entropy function |
| 319 | * is called again. |
| 320 | * |
| 321 | * The default value is #MBEDTLS_CTR_DRBG_RESEED_INTERVAL. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 322 | * |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 323 | * \param ctx The CTR_DRBG context. |
| 324 | * \param interval The reseed interval. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 325 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 326 | void mbedtls_ctr_drbg_set_reseed_interval( mbedtls_ctr_drbg_context *ctx, |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 327 | int interval ); |
| 328 | |
| 329 | /** |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 330 | * \brief This function reseeds the CTR_DRBG context, that is |
| 331 | * extracts data from the entropy source. |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 332 | * |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 333 | * \param ctx The CTR_DRBG context. |
Gilles Peskine | 10f16ac | 2019-10-01 18:30:02 +0200 | [diff] [blame] | 334 | * \param additional Additional data to add to the state. Can be \c NULL. |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 335 | * \param len The length of the additional data. |
Gilles Peskine | 944bc58 | 2019-09-24 14:48:30 +0200 | [diff] [blame] | 336 | * This must be less than |
| 337 | * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - \c entropy_len |
| 338 | * where \c entropy_len is the entropy length |
| 339 | * configured for the context. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 340 | * |
Rose Zadik | c9474eb | 2018-03-27 10:58:22 +0100 | [diff] [blame] | 341 | * \return \c 0 on success. |
| 342 | * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 343 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 344 | int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx, |
Paul Bakker | 1bc9efc | 2011-12-03 11:29:32 +0000 | [diff] [blame] | 345 | const unsigned char *additional, size_t len ); |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 346 | |
| 347 | /** |
Rose Zadik | c9474eb | 2018-03-27 10:58:22 +0100 | [diff] [blame] | 348 | * \brief This function updates the state of the CTR_DRBG context. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 349 | * |
Rose Zadik | c9474eb | 2018-03-27 10:58:22 +0100 | [diff] [blame] | 350 | * \param ctx The CTR_DRBG context. |
Gilles Peskine | 08875d4 | 2019-09-24 14:40:40 +0200 | [diff] [blame] | 351 | * \param additional The data to update the state with. This must not be |
Gilles Peskine | 10f16ac | 2019-10-01 18:30:02 +0200 | [diff] [blame] | 352 | * \c NULL unless \p add_len is \c 0. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 353 | * \param add_len Length of \p additional in bytes. This must be at |
| 354 | * most #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT. |
Rose Zadik | c9474eb | 2018-03-27 10:58:22 +0100 | [diff] [blame] | 355 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 356 | * \return \c 0 on success. |
| 357 | * \return #MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG if |
| 358 | * \p add_len is more than |
| 359 | * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT. |
| 360 | * \return An error from the underlying AES cipher on failure. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 361 | */ |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 362 | int mbedtls_ctr_drbg_update_ret( mbedtls_ctr_drbg_context *ctx, |
| 363 | const unsigned char *additional, |
| 364 | size_t add_len ); |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 365 | |
| 366 | /** |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 367 | * \brief This function updates a CTR_DRBG instance with additional |
| 368 | * data and uses it to generate random data. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 369 | * |
Gilles Peskine | 2d8f069 | 2019-10-01 18:31:28 +0200 | [diff] [blame] | 370 | * This function automatically reseeds if the reseed counter is exceeded |
| 371 | * or prediction resistance is enabled. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 372 | * |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 373 | * \param p_rng The CTR_DRBG context. This must be a pointer to a |
| 374 | * #mbedtls_ctr_drbg_context structure. |
| 375 | * \param output The buffer to fill. |
Gilles Peskine | ec51dd1 | 2019-09-30 15:01:02 +0200 | [diff] [blame] | 376 | * \param output_len The length of the buffer in bytes. |
Gilles Peskine | 10f16ac | 2019-10-01 18:30:02 +0200 | [diff] [blame] | 377 | * \param additional Additional data to update. Can be \c NULL, in which |
Gilles Peskine | 08875d4 | 2019-09-24 14:40:40 +0200 | [diff] [blame] | 378 | * case the additional data is empty regardless of |
| 379 | * the value of \p add_len. |
| 380 | * \param add_len The length of the additional data |
Gilles Peskine | 10f16ac | 2019-10-01 18:30:02 +0200 | [diff] [blame] | 381 | * if \p additional is not \c NULL. |
Gilles Peskine | 944bc58 | 2019-09-24 14:48:30 +0200 | [diff] [blame] | 382 | * This must be less than #MBEDTLS_CTR_DRBG_MAX_INPUT |
| 383 | * and less than |
| 384 | * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - \c entropy_len |
| 385 | * where \c entropy_len is the entropy length |
| 386 | * configured for the context. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 387 | * |
Rose Zadik | c9474eb | 2018-03-27 10:58:22 +0100 | [diff] [blame] | 388 | * \return \c 0 on success. |
| 389 | * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 390 | * #MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG on failure. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 391 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 392 | int mbedtls_ctr_drbg_random_with_add( void *p_rng, |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 393 | unsigned char *output, size_t output_len, |
Paul Bakker | 1bc9efc | 2011-12-03 11:29:32 +0000 | [diff] [blame] | 394 | const unsigned char *additional, size_t add_len ); |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 395 | |
| 396 | /** |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 397 | * \brief This function uses CTR_DRBG to generate random data. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 398 | * |
Gilles Peskine | 2d8f069 | 2019-10-01 18:31:28 +0200 | [diff] [blame] | 399 | * This function automatically reseeds if the reseed counter is exceeded |
| 400 | * or prediction resistance is enabled. |
| 401 | * |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 402 | * |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 403 | * \param p_rng The CTR_DRBG context. This must be a pointer to a |
| 404 | * #mbedtls_ctr_drbg_context structure. |
| 405 | * \param output The buffer to fill. |
Gilles Peskine | 944bc58 | 2019-09-24 14:48:30 +0200 | [diff] [blame] | 406 | * \param output_len The length of the buffer in bytes. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 407 | * |
Rose Zadik | c9474eb | 2018-03-27 10:58:22 +0100 | [diff] [blame] | 408 | * \return \c 0 on success. |
| 409 | * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 410 | * #MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG on failure. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 411 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 412 | int mbedtls_ctr_drbg_random( void *p_rng, |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 413 | unsigned char *output, size_t output_len ); |
| 414 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 415 | |
| 416 | #if ! defined(MBEDTLS_DEPRECATED_REMOVED) |
| 417 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 418 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 419 | #else |
| 420 | #define MBEDTLS_DEPRECATED |
| 421 | #endif |
| 422 | /** |
| 423 | * \brief This function updates the state of the CTR_DRBG context. |
| 424 | * |
| 425 | * \deprecated Superseded by mbedtls_ctr_drbg_update_ret() |
| 426 | * in 2.16.0. |
| 427 | * |
| 428 | * \note If \p add_len is greater than |
| 429 | * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT, only the first |
| 430 | * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT Bytes are used. |
| 431 | * The remaining Bytes are silently discarded. |
| 432 | * |
| 433 | * \param ctx The CTR_DRBG context. |
| 434 | * \param additional The data to update the state with. |
| 435 | * \param add_len Length of \p additional data. |
| 436 | */ |
| 437 | MBEDTLS_DEPRECATED void mbedtls_ctr_drbg_update( |
| 438 | mbedtls_ctr_drbg_context *ctx, |
| 439 | const unsigned char *additional, |
| 440 | size_t add_len ); |
| 441 | #undef MBEDTLS_DEPRECATED |
| 442 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
| 443 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 444 | #if defined(MBEDTLS_FS_IO) |
Paul Bakker | fc754a9 | 2011-12-05 13:23:51 +0000 | [diff] [blame] | 445 | /** |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 446 | * \brief This function writes a seed file. |
Paul Bakker | fc754a9 | 2011-12-05 13:23:51 +0000 | [diff] [blame] | 447 | * |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 448 | * \param ctx The CTR_DRBG context. |
| 449 | * \param path The name of the file. |
Paul Bakker | fc754a9 | 2011-12-05 13:23:51 +0000 | [diff] [blame] | 450 | * |
Rose Zadik | c9474eb | 2018-03-27 10:58:22 +0100 | [diff] [blame] | 451 | * \return \c 0 on success. |
Rose Zadik | f25eb6e | 2018-04-16 14:51:52 +0100 | [diff] [blame] | 452 | * \return #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error. |
Gilles Peskine | ec51dd1 | 2019-09-30 15:01:02 +0200 | [diff] [blame] | 453 | * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on reseed |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 454 | * failure. |
Paul Bakker | fc754a9 | 2011-12-05 13:23:51 +0000 | [diff] [blame] | 455 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 456 | int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path ); |
Paul Bakker | fc754a9 | 2011-12-05 13:23:51 +0000 | [diff] [blame] | 457 | |
| 458 | /** |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 459 | * \brief This function reads and updates a seed file. The seed |
| 460 | * is added to this instance. |
Paul Bakker | fc754a9 | 2011-12-05 13:23:51 +0000 | [diff] [blame] | 461 | * |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 462 | * \param ctx The CTR_DRBG context. |
| 463 | * \param path The name of the file. |
Paul Bakker | fc754a9 | 2011-12-05 13:23:51 +0000 | [diff] [blame] | 464 | * |
Rose Zadik | c9474eb | 2018-03-27 10:58:22 +0100 | [diff] [blame] | 465 | * \return \c 0 on success. |
| 466 | * \return #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error. |
Gilles Peskine | ec51dd1 | 2019-09-30 15:01:02 +0200 | [diff] [blame] | 467 | * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on |
| 468 | * reseed failure. |
| 469 | * \return #MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG if the existing |
| 470 | * seed file is too large. |
Paul Bakker | fc754a9 | 2011-12-05 13:23:51 +0000 | [diff] [blame] | 471 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 472 | int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path ); |
| 473 | #endif /* MBEDTLS_FS_IO */ |
Paul Bakker | fc754a9 | 2011-12-05 13:23:51 +0000 | [diff] [blame] | 474 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 475 | #if defined(MBEDTLS_SELF_TEST) |
| 476 | |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 477 | /** |
Rose Zadik | 2f8163d | 2018-01-25 21:55:14 +0000 | [diff] [blame] | 478 | * \brief The CTR_DRBG checkup routine. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 479 | * |
Rose Zadik | c9474eb | 2018-03-27 10:58:22 +0100 | [diff] [blame] | 480 | * \return \c 0 on success. |
| 481 | * \return \c 1 on failure. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 482 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 483 | int mbedtls_ctr_drbg_self_test( int verbose ); |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 484 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 485 | #endif /* MBEDTLS_SELF_TEST */ |
| 486 | |
Paul Bakker | 534f82c | 2013-06-25 16:47:55 +0200 | [diff] [blame] | 487 | /* Internal functions (do not call directly) */ |
Manuel Pégourié-Gonnard | 8d128ef | 2015-04-28 22:38:08 +0200 | [diff] [blame] | 488 | int mbedtls_ctr_drbg_seed_entropy_len( mbedtls_ctr_drbg_context *, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 489 | int (*)(void *, unsigned char *, size_t), void *, |
| 490 | const unsigned char *, size_t, size_t ); |
Paul Bakker | 534f82c | 2013-06-25 16:47:55 +0200 | [diff] [blame] | 491 | |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 492 | #ifdef __cplusplus |
| 493 | } |
| 494 | #endif |
| 495 | |
| 496 | #endif /* ctr_drbg.h */ |