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