Hannes Tschofenig
/
aes-gcm-test-program
Example program to test AES-GCM functionality. Used for a workshop
SSL/include/polarssl/hmac_drbg.h@0:796d0f61a05b, 2018-09-27 (annotated)
- Committer:
- HannesTschofenig
- Date:
- Thu Sep 27 06:34:22 2018 +0000
- Revision:
- 0:796d0f61a05b
Example AES-GCM test program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
HannesTschofenig | 0:796d0f61a05b | 1 | /** |
HannesTschofenig | 0:796d0f61a05b | 2 | * \file hmac_drbg.h |
HannesTschofenig | 0:796d0f61a05b | 3 | * |
HannesTschofenig | 0:796d0f61a05b | 4 | * \brief HMAC_DRBG (NIST SP 800-90A) |
HannesTschofenig | 0:796d0f61a05b | 5 | * |
HannesTschofenig | 0:796d0f61a05b | 6 | * Copyright (C) 2014, Brainspark B.V. |
HannesTschofenig | 0:796d0f61a05b | 7 | * |
HannesTschofenig | 0:796d0f61a05b | 8 | * This file is part of PolarSSL (http://www.polarssl.org) |
HannesTschofenig | 0:796d0f61a05b | 9 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
HannesTschofenig | 0:796d0f61a05b | 10 | * |
HannesTschofenig | 0:796d0f61a05b | 11 | * All rights reserved. |
HannesTschofenig | 0:796d0f61a05b | 12 | * |
HannesTschofenig | 0:796d0f61a05b | 13 | * This program is free software; you can redistribute it and/or modify |
HannesTschofenig | 0:796d0f61a05b | 14 | * it under the terms of the GNU General Public License as published by |
HannesTschofenig | 0:796d0f61a05b | 15 | * the Free Software Foundation; either version 2 of the License, or |
HannesTschofenig | 0:796d0f61a05b | 16 | * (at your option) any later version. |
HannesTschofenig | 0:796d0f61a05b | 17 | * |
HannesTschofenig | 0:796d0f61a05b | 18 | * This program is distributed in the hope that it will be useful, |
HannesTschofenig | 0:796d0f61a05b | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
HannesTschofenig | 0:796d0f61a05b | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
HannesTschofenig | 0:796d0f61a05b | 21 | * GNU General Public License for more details. |
HannesTschofenig | 0:796d0f61a05b | 22 | * |
HannesTschofenig | 0:796d0f61a05b | 23 | * You should have received a copy of the GNU General Public License along |
HannesTschofenig | 0:796d0f61a05b | 24 | * with this program; if not, write to the Free Software Foundation, Inc., |
HannesTschofenig | 0:796d0f61a05b | 25 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
HannesTschofenig | 0:796d0f61a05b | 26 | */ |
HannesTschofenig | 0:796d0f61a05b | 27 | #ifndef POLARSSL_HMAC_DRBG_H |
HannesTschofenig | 0:796d0f61a05b | 28 | #define POLARSSL_HMAC_DRBG_H |
HannesTschofenig | 0:796d0f61a05b | 29 | |
HannesTschofenig | 0:796d0f61a05b | 30 | #include "md.h" |
HannesTschofenig | 0:796d0f61a05b | 31 | |
HannesTschofenig | 0:796d0f61a05b | 32 | /* |
HannesTschofenig | 0:796d0f61a05b | 33 | * Error codes |
HannesTschofenig | 0:796d0f61a05b | 34 | */ |
HannesTschofenig | 0:796d0f61a05b | 35 | #define POLARSSL_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003 /**< Too many random requested in single call. */ |
HannesTschofenig | 0:796d0f61a05b | 36 | #define POLARSSL_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005 /**< Input too large (Entropy + additional). */ |
HannesTschofenig | 0:796d0f61a05b | 37 | #define POLARSSL_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007 /**< Read/write error in file. */ |
HannesTschofenig | 0:796d0f61a05b | 38 | #define POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009 /**< The entropy source failed. */ |
HannesTschofenig | 0:796d0f61a05b | 39 | |
HannesTschofenig | 0:796d0f61a05b | 40 | /** |
HannesTschofenig | 0:796d0f61a05b | 41 | * \name SECTION: Module settings |
HannesTschofenig | 0:796d0f61a05b | 42 | * |
HannesTschofenig | 0:796d0f61a05b | 43 | * The configuration options you can set for this module are in this section. |
HannesTschofenig | 0:796d0f61a05b | 44 | * Either change them in config.h or define them on the compiler command line. |
HannesTschofenig | 0:796d0f61a05b | 45 | * \{ |
HannesTschofenig | 0:796d0f61a05b | 46 | */ |
HannesTschofenig | 0:796d0f61a05b | 47 | |
HannesTschofenig | 0:796d0f61a05b | 48 | #if !defined(POLARSSL_HMAC_DRBG_RESEED_INTERVAL) |
HannesTschofenig | 0:796d0f61a05b | 49 | #define POLARSSL_HMAC_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */ |
HannesTschofenig | 0:796d0f61a05b | 50 | #endif |
HannesTschofenig | 0:796d0f61a05b | 51 | |
HannesTschofenig | 0:796d0f61a05b | 52 | #if !defined(POLARSSL_HMAC_DRBG_MAX_INPUT) |
HannesTschofenig | 0:796d0f61a05b | 53 | #define POLARSSL_HMAC_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */ |
HannesTschofenig | 0:796d0f61a05b | 54 | #endif |
HannesTschofenig | 0:796d0f61a05b | 55 | |
HannesTschofenig | 0:796d0f61a05b | 56 | #if !defined(POLARSSL_HMAC_DRBG_MAX_REQUEST) |
HannesTschofenig | 0:796d0f61a05b | 57 | #define POLARSSL_HMAC_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */ |
HannesTschofenig | 0:796d0f61a05b | 58 | #endif |
HannesTschofenig | 0:796d0f61a05b | 59 | |
HannesTschofenig | 0:796d0f61a05b | 60 | #if !defined(POLARSSL_HMAC_DRBG_MAX_SEED_INPUT) |
HannesTschofenig | 0:796d0f61a05b | 61 | #define POLARSSL_HMAC_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */ |
HannesTschofenig | 0:796d0f61a05b | 62 | #endif |
HannesTschofenig | 0:796d0f61a05b | 63 | |
HannesTschofenig | 0:796d0f61a05b | 64 | /* \} name SECTION: Module settings */ |
HannesTschofenig | 0:796d0f61a05b | 65 | |
HannesTschofenig | 0:796d0f61a05b | 66 | #define POLARSSL_HMAC_DRBG_PR_OFF 0 /**< No prediction resistance */ |
HannesTschofenig | 0:796d0f61a05b | 67 | #define POLARSSL_HMAC_DRBG_PR_ON 1 /**< Prediction resistance enabled */ |
HannesTschofenig | 0:796d0f61a05b | 68 | |
HannesTschofenig | 0:796d0f61a05b | 69 | #ifdef __cplusplus |
HannesTschofenig | 0:796d0f61a05b | 70 | extern "C" { |
HannesTschofenig | 0:796d0f61a05b | 71 | #endif |
HannesTschofenig | 0:796d0f61a05b | 72 | |
HannesTschofenig | 0:796d0f61a05b | 73 | /** |
HannesTschofenig | 0:796d0f61a05b | 74 | * HMAC_DRBG context. |
HannesTschofenig | 0:796d0f61a05b | 75 | */ |
HannesTschofenig | 0:796d0f61a05b | 76 | typedef struct |
HannesTschofenig | 0:796d0f61a05b | 77 | { |
HannesTschofenig | 0:796d0f61a05b | 78 | /* Working state: the key K is not stored explicitely, |
HannesTschofenig | 0:796d0f61a05b | 79 | * but is implied by the HMAC context */ |
HannesTschofenig | 0:796d0f61a05b | 80 | md_context_t md_ctx; /*!< HMAC context (inc. K) */ |
HannesTschofenig | 0:796d0f61a05b | 81 | unsigned char V[POLARSSL_MD_MAX_SIZE]; /*!< V in the spec */ |
HannesTschofenig | 0:796d0f61a05b | 82 | int reseed_counter; /*!< reseed counter */ |
HannesTschofenig | 0:796d0f61a05b | 83 | |
HannesTschofenig | 0:796d0f61a05b | 84 | /* Administrative state */ |
HannesTschofenig | 0:796d0f61a05b | 85 | size_t entropy_len; /*!< entropy bytes grabbed on each (re)seed */ |
HannesTschofenig | 0:796d0f61a05b | 86 | int prediction_resistance; /*!< enable prediction resistance (Automatic |
HannesTschofenig | 0:796d0f61a05b | 87 | reseed before every random generation) */ |
HannesTschofenig | 0:796d0f61a05b | 88 | int reseed_interval; /*!< reseed interval */ |
HannesTschofenig | 0:796d0f61a05b | 89 | |
HannesTschofenig | 0:796d0f61a05b | 90 | /* Callbacks */ |
HannesTschofenig | 0:796d0f61a05b | 91 | int (*f_entropy)(void *, unsigned char *, size_t); /*!< entropy function */ |
HannesTschofenig | 0:796d0f61a05b | 92 | void *p_entropy; /*!< context for the entropy function */ |
HannesTschofenig | 0:796d0f61a05b | 93 | } hmac_drbg_context; |
HannesTschofenig | 0:796d0f61a05b | 94 | |
HannesTschofenig | 0:796d0f61a05b | 95 | /** |
HannesTschofenig | 0:796d0f61a05b | 96 | * \brief HMAC_DRBG initialisation |
HannesTschofenig | 0:796d0f61a05b | 97 | * |
HannesTschofenig | 0:796d0f61a05b | 98 | * \param ctx HMAC_DRBG context to be initialised |
HannesTschofenig | 0:796d0f61a05b | 99 | * \param md_info MD algorithm to use for HMAC_DRBG |
HannesTschofenig | 0:796d0f61a05b | 100 | * \param f_entropy Entropy callback (p_entropy, buffer to fill, buffer |
HannesTschofenig | 0:796d0f61a05b | 101 | * length) |
HannesTschofenig | 0:796d0f61a05b | 102 | * \param p_entropy Entropy context |
HannesTschofenig | 0:796d0f61a05b | 103 | * \param custom Personalization data (Device specific identifiers) |
HannesTschofenig | 0:796d0f61a05b | 104 | * (Can be NULL) |
HannesTschofenig | 0:796d0f61a05b | 105 | * \param len Length of personalization data |
HannesTschofenig | 0:796d0f61a05b | 106 | * |
HannesTschofenig | 0:796d0f61a05b | 107 | * \note The "security strength" as defined by NIST is set to: |
HannesTschofenig | 0:796d0f61a05b | 108 | * 128 bits if md_alg is SHA-1, |
HannesTschofenig | 0:796d0f61a05b | 109 | * 192 bits if md_alg is SHA-224, |
HannesTschofenig | 0:796d0f61a05b | 110 | * 256 bits if md_alg is SHA-256 or higher. |
HannesTschofenig | 0:796d0f61a05b | 111 | * Note that SHA-256 is just as efficient as SHA-224. |
HannesTschofenig | 0:796d0f61a05b | 112 | * |
HannesTschofenig | 0:796d0f61a05b | 113 | * \return 0 if successful, or |
HannesTschofenig | 0:796d0f61a05b | 114 | * POLARSSL_ERR_MD_BAD_INPUT_DATA, or |
HannesTschofenig | 0:796d0f61a05b | 115 | * POLARSSL_ERR_MD_ALLOC_FAILED, or |
HannesTschofenig | 0:796d0f61a05b | 116 | * POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED. |
HannesTschofenig | 0:796d0f61a05b | 117 | */ |
HannesTschofenig | 0:796d0f61a05b | 118 | int hmac_drbg_init( hmac_drbg_context *ctx, |
HannesTschofenig | 0:796d0f61a05b | 119 | const md_info_t * md_info, |
HannesTschofenig | 0:796d0f61a05b | 120 | int (*f_entropy)(void *, unsigned char *, size_t), |
HannesTschofenig | 0:796d0f61a05b | 121 | void *p_entropy, |
HannesTschofenig | 0:796d0f61a05b | 122 | const unsigned char *custom, |
HannesTschofenig | 0:796d0f61a05b | 123 | size_t len ); |
HannesTschofenig | 0:796d0f61a05b | 124 | |
HannesTschofenig | 0:796d0f61a05b | 125 | /** |
HannesTschofenig | 0:796d0f61a05b | 126 | * \brief Initilisation of simpified HMAC_DRBG (never reseeds). |
HannesTschofenig | 0:796d0f61a05b | 127 | * (For use with deterministic ECDSA.) |
HannesTschofenig | 0:796d0f61a05b | 128 | * |
HannesTschofenig | 0:796d0f61a05b | 129 | * \param ctx HMAC_DRBG context to be initialised |
HannesTschofenig | 0:796d0f61a05b | 130 | * \param md_info MD algorithm to use for HMAC_DRBG |
HannesTschofenig | 0:796d0f61a05b | 131 | * \param data Concatenation of entropy string and additional data |
HannesTschofenig | 0:796d0f61a05b | 132 | * \param data_len Length of data in bytes |
HannesTschofenig | 0:796d0f61a05b | 133 | * |
HannesTschofenig | 0:796d0f61a05b | 134 | * \return 0 if successful, or |
HannesTschofenig | 0:796d0f61a05b | 135 | * POLARSSL_ERR_MD_BAD_INPUT_DATA, or |
HannesTschofenig | 0:796d0f61a05b | 136 | * POLARSSL_ERR_MD_ALLOC_FAILED. |
HannesTschofenig | 0:796d0f61a05b | 137 | */ |
HannesTschofenig | 0:796d0f61a05b | 138 | int hmac_drbg_init_buf( hmac_drbg_context *ctx, |
HannesTschofenig | 0:796d0f61a05b | 139 | const md_info_t * md_info, |
HannesTschofenig | 0:796d0f61a05b | 140 | const unsigned char *data, size_t data_len ); |
HannesTschofenig | 0:796d0f61a05b | 141 | |
HannesTschofenig | 0:796d0f61a05b | 142 | /** |
HannesTschofenig | 0:796d0f61a05b | 143 | * \brief Enable / disable prediction resistance (Default: Off) |
HannesTschofenig | 0:796d0f61a05b | 144 | * |
HannesTschofenig | 0:796d0f61a05b | 145 | * Note: If enabled, entropy is used for ctx->entropy_len before each call! |
HannesTschofenig | 0:796d0f61a05b | 146 | * Only use this if you have ample supply of good entropy! |
HannesTschofenig | 0:796d0f61a05b | 147 | * |
HannesTschofenig | 0:796d0f61a05b | 148 | * \param ctx HMAC_DRBG context |
HannesTschofenig | 0:796d0f61a05b | 149 | * \param resistance POLARSSL_HMAC_DRBG_PR_ON or POLARSSL_HMAC_DRBG_PR_OFF |
HannesTschofenig | 0:796d0f61a05b | 150 | */ |
HannesTschofenig | 0:796d0f61a05b | 151 | void hmac_drbg_set_prediction_resistance( hmac_drbg_context *ctx, |
HannesTschofenig | 0:796d0f61a05b | 152 | int resistance ); |
HannesTschofenig | 0:796d0f61a05b | 153 | |
HannesTschofenig | 0:796d0f61a05b | 154 | /** |
HannesTschofenig | 0:796d0f61a05b | 155 | * \brief Set the amount of entropy grabbed on each reseed |
HannesTschofenig | 0:796d0f61a05b | 156 | * (Default: given by the security strength, which |
HannesTschofenig | 0:796d0f61a05b | 157 | * depends on the hash used, see \c hmac_drbg_init() ) |
HannesTschofenig | 0:796d0f61a05b | 158 | * |
HannesTschofenig | 0:796d0f61a05b | 159 | * \param ctx HMAC_DRBG context |
HannesTschofenig | 0:796d0f61a05b | 160 | * \param len Amount of entropy to grab, in bytes |
HannesTschofenig | 0:796d0f61a05b | 161 | */ |
HannesTschofenig | 0:796d0f61a05b | 162 | void hmac_drbg_set_entropy_len( hmac_drbg_context *ctx, |
HannesTschofenig | 0:796d0f61a05b | 163 | size_t len ); |
HannesTschofenig | 0:796d0f61a05b | 164 | |
HannesTschofenig | 0:796d0f61a05b | 165 | /** |
HannesTschofenig | 0:796d0f61a05b | 166 | * \brief Set the reseed interval |
HannesTschofenig | 0:796d0f61a05b | 167 | * (Default: POLARSSL_HMAC_DRBG_RESEED_INTERVAL) |
HannesTschofenig | 0:796d0f61a05b | 168 | * |
HannesTschofenig | 0:796d0f61a05b | 169 | * \param ctx HMAC_DRBG context |
HannesTschofenig | 0:796d0f61a05b | 170 | * \param interval Reseed interval |
HannesTschofenig | 0:796d0f61a05b | 171 | */ |
HannesTschofenig | 0:796d0f61a05b | 172 | void hmac_drbg_set_reseed_interval( hmac_drbg_context *ctx, |
HannesTschofenig | 0:796d0f61a05b | 173 | int interval ); |
HannesTschofenig | 0:796d0f61a05b | 174 | |
HannesTschofenig | 0:796d0f61a05b | 175 | /** |
HannesTschofenig | 0:796d0f61a05b | 176 | * \brief HMAC_DRBG update state |
HannesTschofenig | 0:796d0f61a05b | 177 | * |
HannesTschofenig | 0:796d0f61a05b | 178 | * \param ctx HMAC_DRBG context |
HannesTschofenig | 0:796d0f61a05b | 179 | * \param additional Additional data to update state with, or NULL |
HannesTschofenig | 0:796d0f61a05b | 180 | * \param add_len Length of additional data, or 0 |
HannesTschofenig | 0:796d0f61a05b | 181 | * |
HannesTschofenig | 0:796d0f61a05b | 182 | * \note Additional data is optional, pass NULL and 0 as second |
HannesTschofenig | 0:796d0f61a05b | 183 | * third argument if no additional data is being used. |
HannesTschofenig | 0:796d0f61a05b | 184 | */ |
HannesTschofenig | 0:796d0f61a05b | 185 | void hmac_drbg_update( hmac_drbg_context *ctx, |
HannesTschofenig | 0:796d0f61a05b | 186 | const unsigned char *additional, size_t add_len ); |
HannesTschofenig | 0:796d0f61a05b | 187 | |
HannesTschofenig | 0:796d0f61a05b | 188 | /** |
HannesTschofenig | 0:796d0f61a05b | 189 | * \brief HMAC_DRBG reseeding (extracts data from entropy source) |
HannesTschofenig | 0:796d0f61a05b | 190 | * |
HannesTschofenig | 0:796d0f61a05b | 191 | * \param ctx HMAC_DRBG context |
HannesTschofenig | 0:796d0f61a05b | 192 | * \param additional Additional data to add to state (Can be NULL) |
HannesTschofenig | 0:796d0f61a05b | 193 | * \param len Length of additional data |
HannesTschofenig | 0:796d0f61a05b | 194 | * |
HannesTschofenig | 0:796d0f61a05b | 195 | * \return 0 if successful, or |
HannesTschofenig | 0:796d0f61a05b | 196 | * POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED |
HannesTschofenig | 0:796d0f61a05b | 197 | */ |
HannesTschofenig | 0:796d0f61a05b | 198 | int hmac_drbg_reseed( hmac_drbg_context *ctx, |
HannesTschofenig | 0:796d0f61a05b | 199 | const unsigned char *additional, size_t len ); |
HannesTschofenig | 0:796d0f61a05b | 200 | |
HannesTschofenig | 0:796d0f61a05b | 201 | /** |
HannesTschofenig | 0:796d0f61a05b | 202 | * \brief HMAC_DRBG generate random with additional update input |
HannesTschofenig | 0:796d0f61a05b | 203 | * |
HannesTschofenig | 0:796d0f61a05b | 204 | * Note: Automatically reseeds if reseed_counter is reached or PR is enabled. |
HannesTschofenig | 0:796d0f61a05b | 205 | * |
HannesTschofenig | 0:796d0f61a05b | 206 | * \param p_rng HMAC_DRBG context |
HannesTschofenig | 0:796d0f61a05b | 207 | * \param output Buffer to fill |
HannesTschofenig | 0:796d0f61a05b | 208 | * \param output_len Length of the buffer |
HannesTschofenig | 0:796d0f61a05b | 209 | * \param additional Additional data to update with (can be NULL) |
HannesTschofenig | 0:796d0f61a05b | 210 | * \param add_len Length of additional data (can be 0) |
HannesTschofenig | 0:796d0f61a05b | 211 | * |
HannesTschofenig | 0:796d0f61a05b | 212 | * \return 0 if successful, or |
HannesTschofenig | 0:796d0f61a05b | 213 | * POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED, or |
HannesTschofenig | 0:796d0f61a05b | 214 | * POLARSSL_ERR_HMAC_DRBG_REQUEST_TOO_BIG, or |
HannesTschofenig | 0:796d0f61a05b | 215 | * POLARSSL_ERR_HMAC_DRBG_INPUT_TOO_BIG. |
HannesTschofenig | 0:796d0f61a05b | 216 | */ |
HannesTschofenig | 0:796d0f61a05b | 217 | int hmac_drbg_random_with_add( void *p_rng, |
HannesTschofenig | 0:796d0f61a05b | 218 | unsigned char *output, size_t output_len, |
HannesTschofenig | 0:796d0f61a05b | 219 | const unsigned char *additional, |
HannesTschofenig | 0:796d0f61a05b | 220 | size_t add_len ); |
HannesTschofenig | 0:796d0f61a05b | 221 | |
HannesTschofenig | 0:796d0f61a05b | 222 | /** |
HannesTschofenig | 0:796d0f61a05b | 223 | * \brief HMAC_DRBG generate random |
HannesTschofenig | 0:796d0f61a05b | 224 | * |
HannesTschofenig | 0:796d0f61a05b | 225 | * Note: Automatically reseeds if reseed_counter is reached or PR is enabled. |
HannesTschofenig | 0:796d0f61a05b | 226 | * |
HannesTschofenig | 0:796d0f61a05b | 227 | * \param p_rng HMAC_DRBG context |
HannesTschofenig | 0:796d0f61a05b | 228 | * \param output Buffer to fill |
HannesTschofenig | 0:796d0f61a05b | 229 | * \param out_len Length of the buffer |
HannesTschofenig | 0:796d0f61a05b | 230 | * |
HannesTschofenig | 0:796d0f61a05b | 231 | * \return 0 if successful, or |
HannesTschofenig | 0:796d0f61a05b | 232 | * POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED, or |
HannesTschofenig | 0:796d0f61a05b | 233 | * POLARSSL_ERR_HMAC_DRBG_REQUEST_TOO_BIG |
HannesTschofenig | 0:796d0f61a05b | 234 | */ |
HannesTschofenig | 0:796d0f61a05b | 235 | int hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len ); |
HannesTschofenig | 0:796d0f61a05b | 236 | |
HannesTschofenig | 0:796d0f61a05b | 237 | /** |
HannesTschofenig | 0:796d0f61a05b | 238 | * \brief Free an HMAC_DRBG context |
HannesTschofenig | 0:796d0f61a05b | 239 | * |
HannesTschofenig | 0:796d0f61a05b | 240 | * \param ctx HMAC_DRBG context to free. |
HannesTschofenig | 0:796d0f61a05b | 241 | */ |
HannesTschofenig | 0:796d0f61a05b | 242 | void hmac_drbg_free( hmac_drbg_context *ctx ); |
HannesTschofenig | 0:796d0f61a05b | 243 | |
HannesTschofenig | 0:796d0f61a05b | 244 | #if defined(POLARSSL_FS_IO) |
HannesTschofenig | 0:796d0f61a05b | 245 | /** |
HannesTschofenig | 0:796d0f61a05b | 246 | * \brief Write a seed file |
HannesTschofenig | 0:796d0f61a05b | 247 | * |
HannesTschofenig | 0:796d0f61a05b | 248 | * \param ctx HMAC_DRBG context |
HannesTschofenig | 0:796d0f61a05b | 249 | * \param path Name of the file |
HannesTschofenig | 0:796d0f61a05b | 250 | * |
HannesTschofenig | 0:796d0f61a05b | 251 | * \return 0 if successful, 1 on file error, or |
HannesTschofenig | 0:796d0f61a05b | 252 | * POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED |
HannesTschofenig | 0:796d0f61a05b | 253 | */ |
HannesTschofenig | 0:796d0f61a05b | 254 | int hmac_drbg_write_seed_file( hmac_drbg_context *ctx, const char *path ); |
HannesTschofenig | 0:796d0f61a05b | 255 | |
HannesTschofenig | 0:796d0f61a05b | 256 | /** |
HannesTschofenig | 0:796d0f61a05b | 257 | * \brief Read and update a seed file. Seed is added to this |
HannesTschofenig | 0:796d0f61a05b | 258 | * instance |
HannesTschofenig | 0:796d0f61a05b | 259 | * |
HannesTschofenig | 0:796d0f61a05b | 260 | * \param ctx HMAC_DRBG context |
HannesTschofenig | 0:796d0f61a05b | 261 | * \param path Name of the file |
HannesTschofenig | 0:796d0f61a05b | 262 | * |
HannesTschofenig | 0:796d0f61a05b | 263 | * \return 0 if successful, 1 on file error, |
HannesTschofenig | 0:796d0f61a05b | 264 | * POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED or |
HannesTschofenig | 0:796d0f61a05b | 265 | * POLARSSL_ERR_HMAC_DRBG_INPUT_TOO_BIG |
HannesTschofenig | 0:796d0f61a05b | 266 | */ |
HannesTschofenig | 0:796d0f61a05b | 267 | int hmac_drbg_update_seed_file( hmac_drbg_context *ctx, const char *path ); |
HannesTschofenig | 0:796d0f61a05b | 268 | #endif /* POLARSSL_FS_IO */ |
HannesTschofenig | 0:796d0f61a05b | 269 | |
HannesTschofenig | 0:796d0f61a05b | 270 | |
HannesTschofenig | 0:796d0f61a05b | 271 | #if defined(POLARSSL_SELF_TEST) |
HannesTschofenig | 0:796d0f61a05b | 272 | /** |
HannesTschofenig | 0:796d0f61a05b | 273 | * \brief Checkup routine |
HannesTschofenig | 0:796d0f61a05b | 274 | * |
HannesTschofenig | 0:796d0f61a05b | 275 | * \return 0 if successful, or 1 if the test failed |
HannesTschofenig | 0:796d0f61a05b | 276 | */ |
HannesTschofenig | 0:796d0f61a05b | 277 | int hmac_drbg_self_test( int verbose ); |
HannesTschofenig | 0:796d0f61a05b | 278 | #endif |
HannesTschofenig | 0:796d0f61a05b | 279 | |
HannesTschofenig | 0:796d0f61a05b | 280 | #ifdef __cplusplus |
HannesTschofenig | 0:796d0f61a05b | 281 | } |
HannesTschofenig | 0:796d0f61a05b | 282 | #endif |
HannesTschofenig | 0:796d0f61a05b | 283 | |
HannesTschofenig | 0:796d0f61a05b | 284 | #endif /* hmac_drbg.h */ |
HannesTschofenig | 0:796d0f61a05b | 285 | |
HannesTschofenig | 0:796d0f61a05b | 286 |