Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file ctr_drbg.h |
| 3 | * |
| 4 | * \brief CTR_DRBG based on AES-256 (NIST SP 800-90) |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame^] | 5 | */ |
| 6 | /* |
Manuel Pégourié-Gonnard | 6fb8187 | 2015-07-27 11:11:48 +0200 | [diff] [blame] | 7 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: Apache-2.0 |
| 9 | * |
| 10 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 11 | * not use this file except in compliance with the License. |
| 12 | * You may obtain a copy of the License at |
| 13 | * |
| 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | * |
| 16 | * Unless required by applicable law or agreed to in writing, software |
| 17 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 18 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | * See the License for the specific language governing permissions and |
| 20 | * limitations under the License. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 21 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 22 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 23 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 24 | #ifndef MBEDTLS_CTR_DRBG_H |
| 25 | #define MBEDTLS_CTR_DRBG_H |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 26 | |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 27 | #include "aes.h" |
| 28 | |
Manuel Pégourié-Gonnard | 0a4fb09 | 2015-05-07 12:50:31 +0100 | [diff] [blame] | 29 | #if defined(MBEDTLS_THREADING_C) |
| 30 | #include "mbedtls/threading.h" |
| 31 | #endif |
| 32 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 33 | #define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034 /**< The entropy source failed. */ |
| 34 | #define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036 /**< Too many random requested in single call. */ |
| 35 | #define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038 /**< Input too large (Entropy + additional). */ |
| 36 | #define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A /**< Read/write error in file. */ |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 37 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 38 | #define MBEDTLS_CTR_DRBG_BLOCKSIZE 16 /**< Block size used by the cipher */ |
| 39 | #define MBEDTLS_CTR_DRBG_KEYSIZE 32 /**< Key size used by the cipher */ |
| 40 | #define MBEDTLS_CTR_DRBG_KEYBITS ( MBEDTLS_CTR_DRBG_KEYSIZE * 8 ) |
| 41 | #define MBEDTLS_CTR_DRBG_SEEDLEN ( MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE ) |
Paul Bakker | 2bc7cf1 | 2011-11-29 10:50:51 +0000 | [diff] [blame] | 42 | /**< The seed length (counter + AES key) */ |
Paul Bakker | 9bcf16c | 2013-06-24 19:31:17 +0200 | [diff] [blame] | 43 | |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 44 | /** |
| 45 | * \name SECTION: Module settings |
| 46 | * |
| 47 | * The configuration options you can set for this module are in this section. |
| 48 | * Either change them in config.h or define them on the compiler command line. |
| 49 | * \{ |
| 50 | */ |
| 51 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 52 | #if !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) |
| 53 | #if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256) |
| 54 | #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48 /**< Amount of entropy used per seed by default (48 with SHA-512, 32 with SHA-256) */ |
Paul Bakker | fb08fd2 | 2013-08-27 15:06:26 +0200 | [diff] [blame] | 55 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 56 | #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 32 /**< Amount of entropy used per seed by default (48 with SHA-512, 32 with SHA-256) */ |
Paul Bakker | fb08fd2 | 2013-08-27 15:06:26 +0200 | [diff] [blame] | 57 | #endif |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 58 | #endif |
| 59 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 60 | #if !defined(MBEDTLS_CTR_DRBG_RESEED_INTERVAL) |
| 61 | #define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */ |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 62 | #endif |
| 63 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 64 | #if !defined(MBEDTLS_CTR_DRBG_MAX_INPUT) |
| 65 | #define MBEDTLS_CTR_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */ |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 66 | #endif |
| 67 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 68 | #if !defined(MBEDTLS_CTR_DRBG_MAX_REQUEST) |
| 69 | #define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */ |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 70 | #endif |
| 71 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 72 | #if !defined(MBEDTLS_CTR_DRBG_MAX_SEED_INPUT) |
| 73 | #define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */ |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 74 | #endif |
| 75 | |
| 76 | /* \} name SECTION: Module settings */ |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 77 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 78 | #define MBEDTLS_CTR_DRBG_PR_OFF 0 /**< No prediction resistance */ |
| 79 | #define MBEDTLS_CTR_DRBG_PR_ON 1 /**< Prediction resistance enabled */ |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 80 | |
| 81 | #ifdef __cplusplus |
| 82 | extern "C" { |
| 83 | #endif |
| 84 | |
| 85 | /** |
| 86 | * \brief CTR_DRBG context structure |
| 87 | */ |
| 88 | typedef struct |
| 89 | { |
| 90 | unsigned char counter[16]; /*!< counter (V) */ |
| 91 | int reseed_counter; /*!< reseed counter */ |
| 92 | int prediction_resistance; /*!< enable prediction resistance (Automatic |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 93 | reseed before every random generation) */ |
| 94 | size_t entropy_len; /*!< amount of entropy grabbed on each |
| 95 | (re)seed */ |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 96 | int reseed_interval; /*!< reseed interval */ |
| 97 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 98 | mbedtls_aes_context aes_ctx; /*!< AES context */ |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 99 | |
| 100 | /* |
| 101 | * Callbacks (Entropy) |
| 102 | */ |
| 103 | int (*f_entropy)(void *, unsigned char *, size_t); |
| 104 | |
| 105 | void *p_entropy; /*!< context for the entropy function */ |
Manuel Pégourié-Gonnard | 0a4fb09 | 2015-05-07 12:50:31 +0100 | [diff] [blame] | 106 | |
| 107 | #if defined(MBEDTLS_THREADING_C) |
| 108 | mbedtls_threading_mutex_t mutex; |
| 109 | #endif |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 110 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 111 | mbedtls_ctr_drbg_context; |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 112 | |
| 113 | /** |
Manuel Pégourié-Gonnard | 8d128ef | 2015-04-28 22:38:08 +0200 | [diff] [blame] | 114 | * \brief CTR_DRBG context initialization |
Tillmann Karras | 588ad50 | 2015-09-25 04:27:22 +0200 | [diff] [blame] | 115 | * Makes the context ready for mbedtls_ctr_drbg_seed() or |
Manuel Pégourié-Gonnard | 8d128ef | 2015-04-28 22:38:08 +0200 | [diff] [blame] | 116 | * mbedtls_ctr_drbg_free(). |
| 117 | * |
| 118 | * \param ctx CTR_DRBG context to be initialized |
| 119 | */ |
| 120 | void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx ); |
| 121 | |
| 122 | /** |
| 123 | * \brief CTR_DRBG initial seeding |
| 124 | * Seed and setup entropy source for future reseeds. |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 125 | * |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 126 | * Note: Personalization data can be provided in addition to the more generic |
| 127 | * entropy source to make this instantiation as unique as possible. |
| 128 | * |
Manuel Pégourié-Gonnard | 8d128ef | 2015-04-28 22:38:08 +0200 | [diff] [blame] | 129 | * \param ctx CTR_DRBG context to be seeded |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 130 | * \param f_entropy Entropy callback (p_entropy, buffer to fill, buffer |
| 131 | * length) |
| 132 | * \param p_entropy Entropy context |
| 133 | * \param custom Personalization data (Device specific identifiers) |
Paul Bakker | 2bc7cf1 | 2011-11-29 10:50:51 +0000 | [diff] [blame] | 134 | * (Can be NULL) |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 135 | * \param len Length of personalization data |
| 136 | * |
| 137 | * \return 0 if successful, or |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 138 | * MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 139 | */ |
Manuel Pégourié-Gonnard | 8d128ef | 2015-04-28 22:38:08 +0200 | [diff] [blame] | 140 | int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *ctx, |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 141 | int (*f_entropy)(void *, unsigned char *, size_t), |
| 142 | void *p_entropy, |
Paul Bakker | 1bc9efc | 2011-12-03 11:29:32 +0000 | [diff] [blame] | 143 | const unsigned char *custom, |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 144 | size_t len ); |
| 145 | |
| 146 | /** |
Paul Bakker | fff0366 | 2014-06-18 16:21:25 +0200 | [diff] [blame] | 147 | * \brief Clear CTR_CRBG context data |
| 148 | * |
| 149 | * \param ctx CTR_DRBG context to clear |
| 150 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 151 | void mbedtls_ctr_drbg_free( mbedtls_ctr_drbg_context *ctx ); |
Paul Bakker | fff0366 | 2014-06-18 16:21:25 +0200 | [diff] [blame] | 152 | |
| 153 | /** |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 154 | * \brief Enable / disable prediction resistance (Default: Off) |
| 155 | * |
| 156 | * Note: If enabled, entropy is used for ctx->entropy_len before each call! |
| 157 | * Only use this if you have ample supply of good entropy! |
| 158 | * |
| 159 | * \param ctx CTR_DRBG context |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 160 | * \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] | 161 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 162 | void mbedtls_ctr_drbg_set_prediction_resistance( mbedtls_ctr_drbg_context *ctx, |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 163 | int resistance ); |
| 164 | |
| 165 | /** |
| 166 | * \brief Set the amount of entropy grabbed on each (re)seed |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 167 | * (Default: MBEDTLS_CTR_DRBG_ENTROPY_LEN) |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 168 | * |
| 169 | * \param ctx CTR_DRBG context |
| 170 | * \param len Amount of entropy to grab |
| 171 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 172 | void mbedtls_ctr_drbg_set_entropy_len( mbedtls_ctr_drbg_context *ctx, |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 173 | size_t len ); |
| 174 | |
| 175 | /** |
| 176 | * \brief Set the reseed interval |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 177 | * (Default: MBEDTLS_CTR_DRBG_RESEED_INTERVAL) |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 178 | * |
| 179 | * \param ctx CTR_DRBG context |
| 180 | * \param interval Reseed interval |
| 181 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 182 | void mbedtls_ctr_drbg_set_reseed_interval( mbedtls_ctr_drbg_context *ctx, |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 183 | int interval ); |
| 184 | |
| 185 | /** |
| 186 | * \brief CTR_DRBG reseeding (extracts data from entropy source) |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 187 | * |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 188 | * \param ctx CTR_DRBG context |
Paul Bakker | 2bc7cf1 | 2011-11-29 10:50:51 +0000 | [diff] [blame] | 189 | * \param additional Additional data to add to state (Can be NULL) |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 190 | * \param len Length of additional data |
| 191 | * |
| 192 | * \return 0 if successful, or |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 193 | * MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 194 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 195 | int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx, |
Paul Bakker | 1bc9efc | 2011-12-03 11:29:32 +0000 | [diff] [blame] | 196 | const unsigned char *additional, size_t len ); |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 197 | |
| 198 | /** |
| 199 | * \brief CTR_DRBG update state |
| 200 | * |
| 201 | * \param ctx CTR_DRBG context |
Paul Bakker | 1bc9efc | 2011-12-03 11:29:32 +0000 | [diff] [blame] | 202 | * \param additional Additional data to update state with |
| 203 | * \param add_len Length of additional data |
Manuel Pégourié-Gonnard | 5cb4b31 | 2014-11-25 17:41:50 +0100 | [diff] [blame] | 204 | * |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 205 | * \note If add_len is greater than MBEDTLS_CTR_DRBG_MAX_SEED_INPUT, |
| 206 | * only the first MBEDTLS_CTR_DRBG_MAX_SEED_INPUT bytes are used, |
Manuel Pégourié-Gonnard | 5cb4b31 | 2014-11-25 17:41:50 +0100 | [diff] [blame] | 207 | * the remaining ones are silently discarded. |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 208 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 209 | void mbedtls_ctr_drbg_update( mbedtls_ctr_drbg_context *ctx, |
Paul Bakker | fc754a9 | 2011-12-05 13:23:51 +0000 | [diff] [blame] | 210 | const unsigned char *additional, size_t add_len ); |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 211 | |
| 212 | /** |
| 213 | * \brief CTR_DRBG generate random with additional update input |
| 214 | * |
| 215 | * Note: Automatically reseeds if reseed_counter is reached. |
| 216 | * |
| 217 | * \param p_rng CTR_DRBG context |
| 218 | * \param output Buffer to fill |
| 219 | * \param output_len Length of the buffer |
Paul Bakker | 2bc7cf1 | 2011-11-29 10:50:51 +0000 | [diff] [blame] | 220 | * \param additional Additional data to update with (Can be NULL) |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 221 | * \param add_len Length of additional data |
| 222 | * |
| 223 | * \return 0 if successful, or |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 224 | * MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED, or |
| 225 | * MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 226 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 227 | int mbedtls_ctr_drbg_random_with_add( void *p_rng, |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 228 | unsigned char *output, size_t output_len, |
Paul Bakker | 1bc9efc | 2011-12-03 11:29:32 +0000 | [diff] [blame] | 229 | const unsigned char *additional, size_t add_len ); |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 230 | |
| 231 | /** |
| 232 | * \brief CTR_DRBG generate random |
| 233 | * |
| 234 | * Note: Automatically reseeds if reseed_counter is reached. |
| 235 | * |
| 236 | * \param p_rng CTR_DRBG context |
| 237 | * \param output Buffer to fill |
| 238 | * \param output_len Length of the buffer |
| 239 | * |
| 240 | * \return 0 if successful, or |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 241 | * MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED, or |
| 242 | * MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 243 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 244 | int mbedtls_ctr_drbg_random( void *p_rng, |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 245 | unsigned char *output, size_t output_len ); |
| 246 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 247 | #if defined(MBEDTLS_FS_IO) |
Paul Bakker | fc754a9 | 2011-12-05 13:23:51 +0000 | [diff] [blame] | 248 | /** |
| 249 | * \brief Write a seed file |
| 250 | * |
Paul Bakker | dcbfdcc | 2013-09-10 16:16:50 +0200 | [diff] [blame] | 251 | * \param ctx CTR_DRBG context |
Paul Bakker | fc754a9 | 2011-12-05 13:23:51 +0000 | [diff] [blame] | 252 | * \param path Name of the file |
| 253 | * |
Paul Bakker | 766a5d0 | 2014-03-26 11:51:25 +0100 | [diff] [blame] | 254 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 255 | * MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error, or |
| 256 | * MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED |
Paul Bakker | fc754a9 | 2011-12-05 13:23:51 +0000 | [diff] [blame] | 257 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 258 | 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] | 259 | |
| 260 | /** |
| 261 | * \brief Read and update a seed file. Seed is added to this |
| 262 | * instance |
| 263 | * |
Paul Bakker | dcbfdcc | 2013-09-10 16:16:50 +0200 | [diff] [blame] | 264 | * \param ctx CTR_DRBG context |
Paul Bakker | fc754a9 | 2011-12-05 13:23:51 +0000 | [diff] [blame] | 265 | * \param path Name of the file |
| 266 | * |
Paul Bakker | 766a5d0 | 2014-03-26 11:51:25 +0100 | [diff] [blame] | 267 | * \return 0 if successful, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 268 | * MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error, |
| 269 | * MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or |
| 270 | * MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG |
Paul Bakker | fc754a9 | 2011-12-05 13:23:51 +0000 | [diff] [blame] | 271 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 272 | int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path ); |
| 273 | #endif /* MBEDTLS_FS_IO */ |
Paul Bakker | fc754a9 | 2011-12-05 13:23:51 +0000 | [diff] [blame] | 274 | |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 275 | /** |
| 276 | * \brief Checkup routine |
| 277 | * |
| 278 | * \return 0 if successful, or 1 if the test failed |
| 279 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 280 | int mbedtls_ctr_drbg_self_test( int verbose ); |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 281 | |
Paul Bakker | 534f82c | 2013-06-25 16:47:55 +0200 | [diff] [blame] | 282 | /* Internal functions (do not call directly) */ |
Manuel Pégourié-Gonnard | 8d128ef | 2015-04-28 22:38:08 +0200 | [diff] [blame] | 283 | int mbedtls_ctr_drbg_seed_entropy_len( mbedtls_ctr_drbg_context *, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 284 | int (*)(void *, unsigned char *, size_t), void *, |
| 285 | const unsigned char *, size_t, size_t ); |
Paul Bakker | 534f82c | 2013-06-25 16:47:55 +0200 | [diff] [blame] | 286 | |
Paul Bakker | 0e04d0e | 2011-11-27 14:46:59 +0000 | [diff] [blame] | 287 | #ifdef __cplusplus |
| 288 | } |
| 289 | #endif |
| 290 | |
| 291 | #endif /* ctr_drbg.h */ |