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