blob: 5a32843152c52b5f18dddf4b2bf622ca20dd2d36 [file] [log] [blame]
Paul Bakker0e04d0e2011-11-27 14:46:59 +00001/**
2 * \file ctr_drbg.h
3 *
Rose Zadik2f8163d2018-01-25 21:55:14 +00004 * \brief CTR_DRBG is based on AES-256, as defined in <em>NIST SP 800-90A:
5 * Recommendation for Random Number Generation Using Deterministic
6 * Random Bit Generators</em>.
7 *
Darryl Greena40a1012018-01-05 15:33:17 +00008 */
9/*
Rose Zadik2f8163d2018-01-25 21:55:14 +000010 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020011 * SPDX-License-Identifier: Apache-2.0
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License"); you may
14 * not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
21 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
Paul Bakker0e04d0e2011-11-27 14:46:59 +000024 *
Rose Zadik2f8163d2018-01-25 21:55:14 +000025 * This file is part of Mbed TLS (https://tls.mbed.org)
Paul Bakker0e04d0e2011-11-27 14:46:59 +000026 */
Rose Zadik2f8163d2018-01-25 21:55:14 +000027
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#ifndef MBEDTLS_CTR_DRBG_H
29#define MBEDTLS_CTR_DRBG_H
Paul Bakker0e04d0e2011-11-27 14:46:59 +000030
Ron Eldor0559c662018-02-14 16:02:41 +020031#if !defined(MBEDTLS_CONFIG_FILE)
32#include "config.h"
33#else
34#include MBEDTLS_CONFIG_FILE
35#endif
36
Paul Bakker0e04d0e2011-11-27 14:46:59 +000037#include "aes.h"
38
Manuel Pégourié-Gonnard0a4fb092015-05-07 12:50:31 +010039#if defined(MBEDTLS_THREADING_C)
Ron Eldordf9b93e2017-05-14 16:17:33 +030040#include "threading.h"
Manuel Pégourié-Gonnard0a4fb092015-05-07 12:50:31 +010041#endif
42
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020043#define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034 /**< The entropy source failed. */
Rose Zadik2f8163d2018-01-25 21:55:14 +000044#define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036 /**< The requested random buffer length is too big. */
45#define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038 /**< The input (entropy + additional data) is too large. */
46#define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A /**< Read or write error in file. */
Paul Bakker0e04d0e2011-11-27 14:46:59 +000047
Rose Zadik2f8163d2018-01-25 21:55:14 +000048#define MBEDTLS_CTR_DRBG_BLOCKSIZE 16 /**< The block size used by the cipher. */
49#define MBEDTLS_CTR_DRBG_KEYSIZE 32 /**< The key size used by the cipher. */
50#define MBEDTLS_CTR_DRBG_KEYBITS ( MBEDTLS_CTR_DRBG_KEYSIZE * 8 ) /**< The key size for the DRBG operation, in bits. */
51#define MBEDTLS_CTR_DRBG_SEEDLEN ( MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE ) /**< The seed length, calculated as (counter + AES key). */
Paul Bakker9bcf16c2013-06-24 19:31:17 +020052
Paul Bakker088c5c52014-04-25 11:11:10 +020053/**
54 * \name SECTION: Module settings
55 *
56 * The configuration options you can set for this module are in this section.
Rose Zadik2f8163d2018-01-25 21:55:14 +000057 * Either change them in config.h or define them using the compiler command
58 * line.
Paul Bakker088c5c52014-04-25 11:11:10 +020059 * \{
60 */
61
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020062#if !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN)
63#if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256)
Rose Zadik2f8163d2018-01-25 21:55:14 +000064#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48
65/**< The amount of entropy used per seed by default:
66 * <ul><li>48 with SHA-512.</li>
67 * <li>32 with SHA-256.</li></ul>
68 */
Paul Bakkerfb08fd22013-08-27 15:06:26 +020069#else
Rose Zadik2f8163d2018-01-25 21:55:14 +000070#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 32
71/**< Amount of entropy used per seed by default:
72 * <ul><li>48 with SHA-512.</li>
73 * <li>32 with SHA-256.</li></ul>
74 */
Paul Bakkerfb08fd22013-08-27 15:06:26 +020075#endif
Paul Bakker088c5c52014-04-25 11:11:10 +020076#endif
77
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020078#if !defined(MBEDTLS_CTR_DRBG_RESEED_INTERVAL)
Rose Zadik2f8163d2018-01-25 21:55:14 +000079#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000
80/**< The interval before reseed is performed by default. */
Paul Bakker088c5c52014-04-25 11:11:10 +020081#endif
82
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083#if !defined(MBEDTLS_CTR_DRBG_MAX_INPUT)
Rose Zadik2f8163d2018-01-25 21:55:14 +000084#define MBEDTLS_CTR_DRBG_MAX_INPUT 256
85/**< The maximum number of additional input Bytes. */
Paul Bakker088c5c52014-04-25 11:11:10 +020086#endif
87
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088#if !defined(MBEDTLS_CTR_DRBG_MAX_REQUEST)
Rose Zadik2f8163d2018-01-25 21:55:14 +000089#define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024
90/**< The maximum number of requested Bytes per call. */
Paul Bakker088c5c52014-04-25 11:11:10 +020091#endif
92
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020093#if !defined(MBEDTLS_CTR_DRBG_MAX_SEED_INPUT)
Rose Zadik2f8163d2018-01-25 21:55:14 +000094#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384
95/**< The maximum size of seed or reseed buffer. */
Paul Bakker088c5c52014-04-25 11:11:10 +020096#endif
97
98/* \} name SECTION: Module settings */
Paul Bakker0e04d0e2011-11-27 14:46:59 +000099
Rose Zadik2f8163d2018-01-25 21:55:14 +0000100#define MBEDTLS_CTR_DRBG_PR_OFF 0
101/**< Prediction resistance is disabled. */
102#define MBEDTLS_CTR_DRBG_PR_ON 1
103/**< Prediction resistance is enabled. */
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000104
105#ifdef __cplusplus
106extern "C" {
107#endif
108
109/**
Rose Zadik2f8163d2018-01-25 21:55:14 +0000110 * \brief The CTR_DRBG context structure.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000111 */
112typedef struct
113{
Rose Zadik2f8163d2018-01-25 21:55:14 +0000114 unsigned char counter[16]; /*!< The counter (V). */
115 int reseed_counter; /*!< The reseed counter. */
116 int prediction_resistance; /*!< This determines whether prediction
117 resistance is enabled, that is
118 whether to systematically reseed before
119 each random generation. */
120 size_t entropy_len; /*!< The amount of entropy grabbed on each
121 seed or reseed operation. */
122 int reseed_interval; /*!< The reseed interval. */
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000123
Rose Zadik2f8163d2018-01-25 21:55:14 +0000124 mbedtls_aes_context aes_ctx; /*!< The AES context. */
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000125
126 /*
127 * Callbacks (Entropy)
128 */
129 int (*f_entropy)(void *, unsigned char *, size_t);
Rose Zadik2f8163d2018-01-25 21:55:14 +0000130 /*!< The entropy callback function. */
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000131
Rose Zadik2f8163d2018-01-25 21:55:14 +0000132 void *p_entropy; /*!< The context for the entropy function. */
Manuel Pégourié-Gonnard0a4fb092015-05-07 12:50:31 +0100133
134#if defined(MBEDTLS_THREADING_C)
135 mbedtls_threading_mutex_t mutex;
136#endif
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000137}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200138mbedtls_ctr_drbg_context;
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000139
140/**
Rose Zadik2f8163d2018-01-25 21:55:14 +0000141 * \brief This function initializes the CTR_DRBG context,
142 * and prepares it for mbedtls_ctr_drbg_seed()
143 * or mbedtls_ctr_drbg_free().
Manuel Pégourié-Gonnard8d128ef2015-04-28 22:38:08 +0200144 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000145 * \param ctx The CTR_DRBG context to initialize.
Manuel Pégourié-Gonnard8d128ef2015-04-28 22:38:08 +0200146 */
147void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
148
149/**
Rose Zadik2f8163d2018-01-25 21:55:14 +0000150 * \brief This function seeds and sets up the CTR_DRBG
151 * entropy source for future reseeds.
Paul Bakker9af723c2014-05-01 13:03:14 +0200152 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000153 * \note Personalization data can be provided in addition to the more generic
154 * entropy source, to make this instantiation as unique as possible.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000155 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000156 * \param ctx The CTR_DRBG context to seed.
157 * \param f_entropy The entropy callback, taking as arguments the
158 * \p p_entropy context, the buffer to fill, and the
159 length of the buffer.
160 * \param p_entropy The entropy context.
161 * \param custom Personalization data, that is device-specific
162 identifiers. Can be NULL.
163 * \param len The length of the personalization data.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000164 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000165 * \return \c 0 on success, or
166 * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000167 */
Manuel Pégourié-Gonnard8d128ef2015-04-28 22:38:08 +0200168int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *ctx,
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000169 int (*f_entropy)(void *, unsigned char *, size_t),
170 void *p_entropy,
Paul Bakker1bc9efc2011-12-03 11:29:32 +0000171 const unsigned char *custom,
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000172 size_t len );
173
174/**
Rose Zadik2f8163d2018-01-25 21:55:14 +0000175 * \brief This function clears CTR_CRBG context data.
Paul Bakkerfff03662014-06-18 16:21:25 +0200176 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000177 * \param ctx The CTR_DRBG context to clear.
Paul Bakkerfff03662014-06-18 16:21:25 +0200178 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200179void mbedtls_ctr_drbg_free( mbedtls_ctr_drbg_context *ctx );
Paul Bakkerfff03662014-06-18 16:21:25 +0200180
181/**
Rose Zadik2f8163d2018-01-25 21:55:14 +0000182 * \brief This function turns prediction resistance on or off.
183 * The default value is off.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000184 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000185 * \note If enabled, entropy is gathered at the beginning of
186 * every call to mbedtls_ctr_drbg_random_with_add().
187 * Only use this if your entropy source has sufficient
188 * throughput.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000189 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000190 * \param ctx The CTR_DRBG context.
191 * \param resistance #MBEDTLS_CTR_DRBG_PR_ON or #MBEDTLS_CTR_DRBG_PR_OFF.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000192 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200193void mbedtls_ctr_drbg_set_prediction_resistance( mbedtls_ctr_drbg_context *ctx,
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000194 int resistance );
195
196/**
Rose Zadik2f8163d2018-01-25 21:55:14 +0000197 * \brief This function sets the amount of entropy grabbed on each
198 * seed or reseed. The default value is
199 * #MBEDTLS_CTR_DRBG_ENTROPY_LEN.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000200 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000201 * \param ctx The CTR_DRBG context.
202 * \param len The amount of entropy to grab.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000203 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200204void mbedtls_ctr_drbg_set_entropy_len( mbedtls_ctr_drbg_context *ctx,
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000205 size_t len );
206
207/**
Rose Zadik2f8163d2018-01-25 21:55:14 +0000208 * \brief This function sets the reseed interval.
209 * The default value is #MBEDTLS_CTR_DRBG_RESEED_INTERVAL.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000210 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000211 * \param ctx The CTR_DRBG context.
212 * \param interval The reseed interval.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000213 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200214void mbedtls_ctr_drbg_set_reseed_interval( mbedtls_ctr_drbg_context *ctx,
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000215 int interval );
216
217/**
Rose Zadik2f8163d2018-01-25 21:55:14 +0000218 * \brief This function reseeds the CTR_DRBG context, that is
219 * extracts data from the entropy source.
Paul Bakker9af723c2014-05-01 13:03:14 +0200220 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000221 * \param ctx The CTR_DRBG context.
222 * \param additional Additional data to add to the state. Can be NULL.
223 * \param len The length of the additional data.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000224 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000225 * \return \c 0 on success, or
226 * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000227 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200228int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx,
Paul Bakker1bc9efc2011-12-03 11:29:32 +0000229 const unsigned char *additional, size_t len );
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000230
231/**
Rose Zadik2f8163d2018-01-25 21:55:14 +0000232 * \brief This function updates the state of the CTR_DRBG context.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000233 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000234 * \param ctx The CTR_DRBG context.
235 * \param additional The data to update the state with.
Gilles Peskine9ce29722018-09-11 16:41:54 +0200236 * \param add_len Length of \p additional in bytes. This must be at
237 * most #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT.
Manuel Pégourié-Gonnard5cb4b312014-11-25 17:41:50 +0100238 *
Gilles Peskine9ce29722018-09-11 16:41:54 +0200239 * \return \c 0 on success.
240 * \return #MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG if
241 * \p add_len is more than
242 * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT.
243 * \return An error from the underlying AES cipher on failure.
244 */
245int mbedtls_ctr_drbg_update_ret( mbedtls_ctr_drbg_context *ctx,
246 const unsigned char *additional,
247 size_t add_len );
248
249/**
250 * \brief This function updates the state of the CTR_DRBG context.
251 *
252 * \warning This function cannot report errors. You should use
253 * mbedtls_ctr_drbg_update_ret() instead.
254 *
255 * \note If \p add_len is greater than
256 * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT, only the first
257 * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT Bytes are used.
258 * The remaining Bytes are silently discarded.
259 *
260 * \param ctx The CTR_DRBG context.
261 * \param additional The data to update the state with.
262 * \param add_len Length of \p additional data.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000263 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200264void mbedtls_ctr_drbg_update( mbedtls_ctr_drbg_context *ctx,
Gilles Peskine9ce29722018-09-11 16:41:54 +0200265 const unsigned char *additional,
266 size_t add_len );
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000267
268/**
Rose Zadik2f8163d2018-01-25 21:55:14 +0000269 * \brief This function updates a CTR_DRBG instance with additional
270 * data and uses it to generate random data.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000271 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000272 * \note The function automatically reseeds if the reseed counter is exceeded.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000273 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000274 * \param p_rng The CTR_DRBG context. This must be a pointer to a
275 * #mbedtls_ctr_drbg_context structure.
276 * \param output The buffer to fill.
277 * \param output_len The length of the buffer.
278 * \param additional Additional data to update. Can be NULL.
279 * \param add_len The length of the additional data.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000280 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000281 * \return \c 0 on success, or
282 * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
283 * #MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG on failure.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000284 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200285int mbedtls_ctr_drbg_random_with_add( void *p_rng,
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000286 unsigned char *output, size_t output_len,
Paul Bakker1bc9efc2011-12-03 11:29:32 +0000287 const unsigned char *additional, size_t add_len );
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000288
289/**
Rose Zadik2f8163d2018-01-25 21:55:14 +0000290 * \brief This function uses CTR_DRBG to generate random data.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000291 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000292 * \note The function automatically reseeds if the reseed counter is exceeded.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000293 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000294 * \param p_rng The CTR_DRBG context. This must be a pointer to a
295 * #mbedtls_ctr_drbg_context structure.
296 * \param output The buffer to fill.
297 * \param output_len The length of the buffer.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000298 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000299 * \return \c 0 on success, or
300 * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
301 * #MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG on failure.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000302 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200303int mbedtls_ctr_drbg_random( void *p_rng,
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000304 unsigned char *output, size_t output_len );
305
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200306#if defined(MBEDTLS_FS_IO)
Paul Bakkerfc754a92011-12-05 13:23:51 +0000307/**
Rose Zadik2f8163d2018-01-25 21:55:14 +0000308 * \brief This function writes a seed file.
Paul Bakkerfc754a92011-12-05 13:23:51 +0000309 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000310 * \param ctx The CTR_DRBG context.
311 * \param path The name of the file.
Paul Bakkerfc754a92011-12-05 13:23:51 +0000312 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000313 * \return \c 0 on success,
314 * #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error, or
315 * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on
316 * failure.
Paul Bakkerfc754a92011-12-05 13:23:51 +0000317 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200318int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
Paul Bakkerfc754a92011-12-05 13:23:51 +0000319
320/**
Rose Zadik2f8163d2018-01-25 21:55:14 +0000321 * \brief This function reads and updates a seed file. The seed
322 * is added to this instance.
Paul Bakkerfc754a92011-12-05 13:23:51 +0000323 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000324 * \param ctx The CTR_DRBG context.
325 * \param path The name of the file.
Paul Bakkerfc754a92011-12-05 13:23:51 +0000326 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000327 * \return \c 0 on success,
328 * #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error,
329 * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
330 * #MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG on failure.
Paul Bakkerfc754a92011-12-05 13:23:51 +0000331 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200332int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
333#endif /* MBEDTLS_FS_IO */
Paul Bakkerfc754a92011-12-05 13:23:51 +0000334
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000335/**
Rose Zadik2f8163d2018-01-25 21:55:14 +0000336 * \brief The CTR_DRBG checkup routine.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000337 *
Rose Zadik2f8163d2018-01-25 21:55:14 +0000338 * \return \c 0 on success, or \c 1 on failure.
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000339 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200340int mbedtls_ctr_drbg_self_test( int verbose );
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000341
Paul Bakker534f82c2013-06-25 16:47:55 +0200342/* Internal functions (do not call directly) */
Manuel Pégourié-Gonnard8d128ef2015-04-28 22:38:08 +0200343int mbedtls_ctr_drbg_seed_entropy_len( mbedtls_ctr_drbg_context *,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200344 int (*)(void *, unsigned char *, size_t), void *,
345 const unsigned char *, size_t, size_t );
Paul Bakker534f82c2013-06-25 16:47:55 +0200346
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000347#ifdef __cplusplus
348}
349#endif
350
351#endif /* ctr_drbg.h */