Modified mbed TLS headers for AES functionality only to reduce build size
Dependents: BLE_Gateway_Linker_fix BLE_Gateway
Fork of mbedtls by
mbedtls/md.h@5:f09f5ed830ca, 2017-07-10 (annotated)
- Committer:
- electronichamsters
- Date:
- Mon Jul 10 04:00:25 2017 +0000
- Revision:
- 5:f09f5ed830ca
- Parent:
- 1:24750b9ad5ef
working gateway
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Christopher Haster |
1:24750b9ad5ef | 1 | /** |
Christopher Haster |
1:24750b9ad5ef | 2 | * \file mbedtls_md.h |
Christopher Haster |
1:24750b9ad5ef | 3 | * |
Christopher Haster |
1:24750b9ad5ef | 4 | * \brief Generic message digest wrapper |
Christopher Haster |
1:24750b9ad5ef | 5 | * |
Christopher Haster |
1:24750b9ad5ef | 6 | * \author Adriaan de Jong <dejong@fox-it.com> |
Christopher Haster |
1:24750b9ad5ef | 7 | * |
Christopher Haster |
1:24750b9ad5ef | 8 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Christopher Haster |
1:24750b9ad5ef | 9 | * SPDX-License-Identifier: Apache-2.0 |
Christopher Haster |
1:24750b9ad5ef | 10 | * |
Christopher Haster |
1:24750b9ad5ef | 11 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
Christopher Haster |
1:24750b9ad5ef | 12 | * not use this file except in compliance with the License. |
Christopher Haster |
1:24750b9ad5ef | 13 | * You may obtain a copy of the License at |
Christopher Haster |
1:24750b9ad5ef | 14 | * |
Christopher Haster |
1:24750b9ad5ef | 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
Christopher Haster |
1:24750b9ad5ef | 16 | * |
Christopher Haster |
1:24750b9ad5ef | 17 | * Unless required by applicable law or agreed to in writing, software |
Christopher Haster |
1:24750b9ad5ef | 18 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
Christopher Haster |
1:24750b9ad5ef | 19 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Christopher Haster |
1:24750b9ad5ef | 20 | * See the License for the specific language governing permissions and |
Christopher Haster |
1:24750b9ad5ef | 21 | * limitations under the License. |
Christopher Haster |
1:24750b9ad5ef | 22 | * |
Christopher Haster |
1:24750b9ad5ef | 23 | * This file is part of mbed TLS (https://tls.mbed.org) |
Christopher Haster |
1:24750b9ad5ef | 24 | */ |
Christopher Haster |
1:24750b9ad5ef | 25 | #ifndef MBEDTLS_MD_H |
Christopher Haster |
1:24750b9ad5ef | 26 | #define MBEDTLS_MD_H |
Christopher Haster |
1:24750b9ad5ef | 27 | |
Christopher Haster |
1:24750b9ad5ef | 28 | #include <stddef.h> |
Christopher Haster |
1:24750b9ad5ef | 29 | |
Christopher Haster |
1:24750b9ad5ef | 30 | #define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080 /**< The selected feature is not available. */ |
Christopher Haster |
1:24750b9ad5ef | 31 | #define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100 /**< Bad input parameters to function. */ |
Christopher Haster |
1:24750b9ad5ef | 32 | #define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180 /**< Failed to allocate memory. */ |
Christopher Haster |
1:24750b9ad5ef | 33 | #define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200 /**< Opening or reading of file failed. */ |
Christopher Haster |
1:24750b9ad5ef | 34 | |
Christopher Haster |
1:24750b9ad5ef | 35 | #ifdef __cplusplus |
Christopher Haster |
1:24750b9ad5ef | 36 | extern "C" { |
Christopher Haster |
1:24750b9ad5ef | 37 | #endif |
Christopher Haster |
1:24750b9ad5ef | 38 | |
Christopher Haster |
1:24750b9ad5ef | 39 | typedef enum { |
Christopher Haster |
1:24750b9ad5ef | 40 | MBEDTLS_MD_NONE=0, |
Christopher Haster |
1:24750b9ad5ef | 41 | MBEDTLS_MD_MD2, |
Christopher Haster |
1:24750b9ad5ef | 42 | MBEDTLS_MD_MD4, |
Christopher Haster |
1:24750b9ad5ef | 43 | MBEDTLS_MD_MD5, |
Christopher Haster |
1:24750b9ad5ef | 44 | MBEDTLS_MD_SHA1, |
Christopher Haster |
1:24750b9ad5ef | 45 | MBEDTLS_MD_SHA224, |
Christopher Haster |
1:24750b9ad5ef | 46 | MBEDTLS_MD_SHA256, |
Christopher Haster |
1:24750b9ad5ef | 47 | MBEDTLS_MD_SHA384, |
Christopher Haster |
1:24750b9ad5ef | 48 | MBEDTLS_MD_SHA512, |
Christopher Haster |
1:24750b9ad5ef | 49 | MBEDTLS_MD_RIPEMD160, |
Christopher Haster |
1:24750b9ad5ef | 50 | } mbedtls_md_type_t; |
Christopher Haster |
1:24750b9ad5ef | 51 | |
Christopher Haster |
1:24750b9ad5ef | 52 | #if defined(MBEDTLS_SHA512_C) |
Christopher Haster |
1:24750b9ad5ef | 53 | #define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */ |
Christopher Haster |
1:24750b9ad5ef | 54 | #else |
Christopher Haster |
1:24750b9ad5ef | 55 | #define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */ |
Christopher Haster |
1:24750b9ad5ef | 56 | #endif |
Christopher Haster |
1:24750b9ad5ef | 57 | |
Christopher Haster |
1:24750b9ad5ef | 58 | /** |
Christopher Haster |
1:24750b9ad5ef | 59 | * Opaque struct defined in md_internal.h |
Christopher Haster |
1:24750b9ad5ef | 60 | */ |
Christopher Haster |
1:24750b9ad5ef | 61 | typedef struct mbedtls_md_info_t mbedtls_md_info_t; |
Christopher Haster |
1:24750b9ad5ef | 62 | |
Christopher Haster |
1:24750b9ad5ef | 63 | /** |
Christopher Haster |
1:24750b9ad5ef | 64 | * Generic message digest context. |
Christopher Haster |
1:24750b9ad5ef | 65 | */ |
Christopher Haster |
1:24750b9ad5ef | 66 | typedef struct { |
Christopher Haster |
1:24750b9ad5ef | 67 | /** Information about the associated message digest */ |
Christopher Haster |
1:24750b9ad5ef | 68 | const mbedtls_md_info_t *md_info; |
Christopher Haster |
1:24750b9ad5ef | 69 | |
Christopher Haster |
1:24750b9ad5ef | 70 | /** Digest-specific context */ |
Christopher Haster |
1:24750b9ad5ef | 71 | void *md_ctx; |
Christopher Haster |
1:24750b9ad5ef | 72 | |
Christopher Haster |
1:24750b9ad5ef | 73 | /** HMAC part of the context */ |
Christopher Haster |
1:24750b9ad5ef | 74 | void *hmac_ctx; |
Christopher Haster |
1:24750b9ad5ef | 75 | } mbedtls_md_context_t; |
Christopher Haster |
1:24750b9ad5ef | 76 | |
Christopher Haster |
1:24750b9ad5ef | 77 | /** |
Christopher Haster |
1:24750b9ad5ef | 78 | * \brief Returns the list of digests supported by the generic digest module. |
Christopher Haster |
1:24750b9ad5ef | 79 | * |
Christopher Haster |
1:24750b9ad5ef | 80 | * \return a statically allocated array of digests, the last entry |
Christopher Haster |
1:24750b9ad5ef | 81 | * is 0. |
Christopher Haster |
1:24750b9ad5ef | 82 | */ |
Christopher Haster |
1:24750b9ad5ef | 83 | const int *mbedtls_md_list( void ); |
Christopher Haster |
1:24750b9ad5ef | 84 | |
Christopher Haster |
1:24750b9ad5ef | 85 | /** |
Christopher Haster |
1:24750b9ad5ef | 86 | * \brief Returns the message digest information associated with the |
Christopher Haster |
1:24750b9ad5ef | 87 | * given digest name. |
Christopher Haster |
1:24750b9ad5ef | 88 | * |
Christopher Haster |
1:24750b9ad5ef | 89 | * \param md_name Name of the digest to search for. |
Christopher Haster |
1:24750b9ad5ef | 90 | * |
Christopher Haster |
1:24750b9ad5ef | 91 | * \return The message digest information associated with md_name or |
Christopher Haster |
1:24750b9ad5ef | 92 | * NULL if not found. |
Christopher Haster |
1:24750b9ad5ef | 93 | */ |
Christopher Haster |
1:24750b9ad5ef | 94 | const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name ); |
Christopher Haster |
1:24750b9ad5ef | 95 | |
Christopher Haster |
1:24750b9ad5ef | 96 | /** |
Christopher Haster |
1:24750b9ad5ef | 97 | * \brief Returns the message digest information associated with the |
Christopher Haster |
1:24750b9ad5ef | 98 | * given digest type. |
Christopher Haster |
1:24750b9ad5ef | 99 | * |
Christopher Haster |
1:24750b9ad5ef | 100 | * \param md_type type of digest to search for. |
Christopher Haster |
1:24750b9ad5ef | 101 | * |
Christopher Haster |
1:24750b9ad5ef | 102 | * \return The message digest information associated with md_type or |
Christopher Haster |
1:24750b9ad5ef | 103 | * NULL if not found. |
Christopher Haster |
1:24750b9ad5ef | 104 | */ |
Christopher Haster |
1:24750b9ad5ef | 105 | const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type ); |
Christopher Haster |
1:24750b9ad5ef | 106 | |
Christopher Haster |
1:24750b9ad5ef | 107 | /** |
Christopher Haster |
1:24750b9ad5ef | 108 | * \brief Initialize a md_context (as NONE) |
Christopher Haster |
1:24750b9ad5ef | 109 | * This should always be called first. |
Christopher Haster |
1:24750b9ad5ef | 110 | * Prepares the context for mbedtls_md_setup() or mbedtls_md_free(). |
Christopher Haster |
1:24750b9ad5ef | 111 | */ |
Christopher Haster |
1:24750b9ad5ef | 112 | void mbedtls_md_init( mbedtls_md_context_t *ctx ); |
Christopher Haster |
1:24750b9ad5ef | 113 | |
Christopher Haster |
1:24750b9ad5ef | 114 | /** |
Christopher Haster |
1:24750b9ad5ef | 115 | * \brief Free and clear the internal structures of ctx. |
Christopher Haster |
1:24750b9ad5ef | 116 | * Can be called at any time after mbedtls_md_init(). |
Christopher Haster |
1:24750b9ad5ef | 117 | * Mandatory once mbedtls_md_setup() has been called. |
Christopher Haster |
1:24750b9ad5ef | 118 | */ |
Christopher Haster |
1:24750b9ad5ef | 119 | void mbedtls_md_free( mbedtls_md_context_t *ctx ); |
Christopher Haster |
1:24750b9ad5ef | 120 | |
Christopher Haster |
1:24750b9ad5ef | 121 | #if ! defined(MBEDTLS_DEPRECATED_REMOVED) |
Christopher Haster |
1:24750b9ad5ef | 122 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
Christopher Haster |
1:24750b9ad5ef | 123 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
Christopher Haster |
1:24750b9ad5ef | 124 | #else |
Christopher Haster |
1:24750b9ad5ef | 125 | #define MBEDTLS_DEPRECATED |
Christopher Haster |
1:24750b9ad5ef | 126 | #endif |
Christopher Haster |
1:24750b9ad5ef | 127 | /** |
Christopher Haster |
1:24750b9ad5ef | 128 | * \brief Select MD to use and allocate internal structures. |
Christopher Haster |
1:24750b9ad5ef | 129 | * Should be called after mbedtls_md_init() or mbedtls_md_free(). |
Christopher Haster |
1:24750b9ad5ef | 130 | * Makes it necessary to call mbedtls_md_free() later. |
Christopher Haster |
1:24750b9ad5ef | 131 | * |
Christopher Haster |
1:24750b9ad5ef | 132 | * \deprecated Superseded by mbedtls_md_setup() in 2.0.0 |
Christopher Haster |
1:24750b9ad5ef | 133 | * |
Christopher Haster |
1:24750b9ad5ef | 134 | * \param ctx Context to set up. |
Christopher Haster |
1:24750b9ad5ef | 135 | * \param md_info Message digest to use. |
Christopher Haster |
1:24750b9ad5ef | 136 | * |
Christopher Haster |
1:24750b9ad5ef | 137 | * \returns \c 0 on success, |
Christopher Haster |
1:24750b9ad5ef | 138 | * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure, |
Christopher Haster |
1:24750b9ad5ef | 139 | * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure. |
Christopher Haster |
1:24750b9ad5ef | 140 | */ |
Christopher Haster |
1:24750b9ad5ef | 141 | int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED; |
Christopher Haster |
1:24750b9ad5ef | 142 | #undef MBEDTLS_DEPRECATED |
Christopher Haster |
1:24750b9ad5ef | 143 | #endif /* MBEDTLS_DEPRECATED_REMOVED */ |
Christopher Haster |
1:24750b9ad5ef | 144 | |
Christopher Haster |
1:24750b9ad5ef | 145 | /** |
Christopher Haster |
1:24750b9ad5ef | 146 | * \brief Select MD to use and allocate internal structures. |
Christopher Haster |
1:24750b9ad5ef | 147 | * Should be called after mbedtls_md_init() or mbedtls_md_free(). |
Christopher Haster |
1:24750b9ad5ef | 148 | * Makes it necessary to call mbedtls_md_free() later. |
Christopher Haster |
1:24750b9ad5ef | 149 | * |
Christopher Haster |
1:24750b9ad5ef | 150 | * \param ctx Context to set up. |
Christopher Haster |
1:24750b9ad5ef | 151 | * \param md_info Message digest to use. |
Christopher Haster |
1:24750b9ad5ef | 152 | * \param hmac 0 to save some memory if HMAC will not be used, |
Christopher Haster |
1:24750b9ad5ef | 153 | * non-zero is HMAC is going to be used with this context. |
Christopher Haster |
1:24750b9ad5ef | 154 | * |
Christopher Haster |
1:24750b9ad5ef | 155 | * \returns \c 0 on success, |
Christopher Haster |
1:24750b9ad5ef | 156 | * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure, |
Christopher Haster |
1:24750b9ad5ef | 157 | * \c MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure. |
Christopher Haster |
1:24750b9ad5ef | 158 | */ |
Christopher Haster |
1:24750b9ad5ef | 159 | int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac ); |
Christopher Haster |
1:24750b9ad5ef | 160 | |
Christopher Haster |
1:24750b9ad5ef | 161 | /** |
Christopher Haster |
1:24750b9ad5ef | 162 | * \brief Clone the state of an MD context |
Christopher Haster |
1:24750b9ad5ef | 163 | * |
Christopher Haster |
1:24750b9ad5ef | 164 | * \note The two contexts must have been setup to the same type |
Christopher Haster |
1:24750b9ad5ef | 165 | * (cloning from SHA-256 to SHA-512 make no sense). |
Christopher Haster |
1:24750b9ad5ef | 166 | * |
Christopher Haster |
1:24750b9ad5ef | 167 | * \warning Only clones the MD state, not the HMAC state! (for now) |
Christopher Haster |
1:24750b9ad5ef | 168 | * |
Christopher Haster |
1:24750b9ad5ef | 169 | * \param dst The destination context |
Christopher Haster |
1:24750b9ad5ef | 170 | * \param src The context to be cloned |
Christopher Haster |
1:24750b9ad5ef | 171 | * |
Christopher Haster |
1:24750b9ad5ef | 172 | * \return \c 0 on success, |
Christopher Haster |
1:24750b9ad5ef | 173 | * \c MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure. |
Christopher Haster |
1:24750b9ad5ef | 174 | */ |
Christopher Haster |
1:24750b9ad5ef | 175 | int mbedtls_md_clone( mbedtls_md_context_t *dst, |
Christopher Haster |
1:24750b9ad5ef | 176 | const mbedtls_md_context_t *src ); |
Christopher Haster |
1:24750b9ad5ef | 177 | |
Christopher Haster |
1:24750b9ad5ef | 178 | /** |
Christopher Haster |
1:24750b9ad5ef | 179 | * \brief Returns the size of the message digest output. |
Christopher Haster |
1:24750b9ad5ef | 180 | * |
Christopher Haster |
1:24750b9ad5ef | 181 | * \param md_info message digest info |
Christopher Haster |
1:24750b9ad5ef | 182 | * |
Christopher Haster |
1:24750b9ad5ef | 183 | * \return size of the message digest output in bytes. |
Christopher Haster |
1:24750b9ad5ef | 184 | */ |
Christopher Haster |
1:24750b9ad5ef | 185 | unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info ); |
Christopher Haster |
1:24750b9ad5ef | 186 | |
Christopher Haster |
1:24750b9ad5ef | 187 | /** |
Christopher Haster |
1:24750b9ad5ef | 188 | * \brief Returns the type of the message digest output. |
Christopher Haster |
1:24750b9ad5ef | 189 | * |
Christopher Haster |
1:24750b9ad5ef | 190 | * \param md_info message digest info |
Christopher Haster |
1:24750b9ad5ef | 191 | * |
Christopher Haster |
1:24750b9ad5ef | 192 | * \return type of the message digest output. |
Christopher Haster |
1:24750b9ad5ef | 193 | */ |
Christopher Haster |
1:24750b9ad5ef | 194 | mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info ); |
Christopher Haster |
1:24750b9ad5ef | 195 | |
Christopher Haster |
1:24750b9ad5ef | 196 | /** |
Christopher Haster |
1:24750b9ad5ef | 197 | * \brief Returns the name of the message digest output. |
Christopher Haster |
1:24750b9ad5ef | 198 | * |
Christopher Haster |
1:24750b9ad5ef | 199 | * \param md_info message digest info |
Christopher Haster |
1:24750b9ad5ef | 200 | * |
Christopher Haster |
1:24750b9ad5ef | 201 | * \return name of the message digest output. |
Christopher Haster |
1:24750b9ad5ef | 202 | */ |
Christopher Haster |
1:24750b9ad5ef | 203 | const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info ); |
Christopher Haster |
1:24750b9ad5ef | 204 | |
Christopher Haster |
1:24750b9ad5ef | 205 | /** |
Christopher Haster |
1:24750b9ad5ef | 206 | * \brief Prepare the context to digest a new message. |
Christopher Haster |
1:24750b9ad5ef | 207 | * Generally called after mbedtls_md_setup() or mbedtls_md_finish(). |
Christopher Haster |
1:24750b9ad5ef | 208 | * Followed by mbedtls_md_update(). |
Christopher Haster |
1:24750b9ad5ef | 209 | * |
Christopher Haster |
1:24750b9ad5ef | 210 | * \param ctx generic message digest context. |
Christopher Haster |
1:24750b9ad5ef | 211 | * |
Christopher Haster |
1:24750b9ad5ef | 212 | * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter |
Christopher Haster |
1:24750b9ad5ef | 213 | * verification fails. |
Christopher Haster |
1:24750b9ad5ef | 214 | */ |
Christopher Haster |
1:24750b9ad5ef | 215 | int mbedtls_md_starts( mbedtls_md_context_t *ctx ); |
Christopher Haster |
1:24750b9ad5ef | 216 | |
Christopher Haster |
1:24750b9ad5ef | 217 | /** |
Christopher Haster |
1:24750b9ad5ef | 218 | * \brief Generic message digest process buffer |
Christopher Haster |
1:24750b9ad5ef | 219 | * Called between mbedtls_md_starts() and mbedtls_md_finish(). |
Christopher Haster |
1:24750b9ad5ef | 220 | * May be called repeatedly. |
Christopher Haster |
1:24750b9ad5ef | 221 | * |
Christopher Haster |
1:24750b9ad5ef | 222 | * \param ctx Generic message digest context |
Christopher Haster |
1:24750b9ad5ef | 223 | * \param input buffer holding the datal |
Christopher Haster |
1:24750b9ad5ef | 224 | * \param ilen length of the input data |
Christopher Haster |
1:24750b9ad5ef | 225 | * |
Christopher Haster |
1:24750b9ad5ef | 226 | * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter |
Christopher Haster |
1:24750b9ad5ef | 227 | * verification fails. |
Christopher Haster |
1:24750b9ad5ef | 228 | */ |
Christopher Haster |
1:24750b9ad5ef | 229 | int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen ); |
Christopher Haster |
1:24750b9ad5ef | 230 | |
Christopher Haster |
1:24750b9ad5ef | 231 | /** |
Christopher Haster |
1:24750b9ad5ef | 232 | * \brief Generic message digest final digest |
Christopher Haster |
1:24750b9ad5ef | 233 | * Called after mbedtls_md_update(). |
Christopher Haster |
1:24750b9ad5ef | 234 | * Usually followed by mbedtls_md_free() or mbedtls_md_starts(). |
Christopher Haster |
1:24750b9ad5ef | 235 | * |
Christopher Haster |
1:24750b9ad5ef | 236 | * \param ctx Generic message digest context |
Christopher Haster |
1:24750b9ad5ef | 237 | * \param output Generic message digest checksum result |
Christopher Haster |
1:24750b9ad5ef | 238 | * |
Christopher Haster |
1:24750b9ad5ef | 239 | * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter |
Christopher Haster |
1:24750b9ad5ef | 240 | * verification fails. |
Christopher Haster |
1:24750b9ad5ef | 241 | */ |
Christopher Haster |
1:24750b9ad5ef | 242 | int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output ); |
Christopher Haster |
1:24750b9ad5ef | 243 | |
Christopher Haster |
1:24750b9ad5ef | 244 | /** |
Christopher Haster |
1:24750b9ad5ef | 245 | * \brief Output = message_digest( input buffer ) |
Christopher Haster |
1:24750b9ad5ef | 246 | * |
Christopher Haster |
1:24750b9ad5ef | 247 | * \param md_info message digest info |
Christopher Haster |
1:24750b9ad5ef | 248 | * \param input buffer holding the data |
Christopher Haster |
1:24750b9ad5ef | 249 | * \param ilen length of the input data |
Christopher Haster |
1:24750b9ad5ef | 250 | * \param output Generic message digest checksum result |
Christopher Haster |
1:24750b9ad5ef | 251 | * |
Christopher Haster |
1:24750b9ad5ef | 252 | * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter |
Christopher Haster |
1:24750b9ad5ef | 253 | * verification fails. |
Christopher Haster |
1:24750b9ad5ef | 254 | */ |
Christopher Haster |
1:24750b9ad5ef | 255 | int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen, |
Christopher Haster |
1:24750b9ad5ef | 256 | unsigned char *output ); |
Christopher Haster |
1:24750b9ad5ef | 257 | |
Christopher Haster |
1:24750b9ad5ef | 258 | #if defined(MBEDTLS_FS_IO) |
Christopher Haster |
1:24750b9ad5ef | 259 | /** |
Christopher Haster |
1:24750b9ad5ef | 260 | * \brief Output = message_digest( file contents ) |
Christopher Haster |
1:24750b9ad5ef | 261 | * |
Christopher Haster |
1:24750b9ad5ef | 262 | * \param md_info message digest info |
Christopher Haster |
1:24750b9ad5ef | 263 | * \param path input file name |
Christopher Haster |
1:24750b9ad5ef | 264 | * \param output generic message digest checksum result |
Christopher Haster |
1:24750b9ad5ef | 265 | * |
Christopher Haster |
1:24750b9ad5ef | 266 | * \return 0 if successful, |
Christopher Haster |
1:24750b9ad5ef | 267 | * MBEDTLS_ERR_MD_FILE_IO_ERROR if file input failed, |
Christopher Haster |
1:24750b9ad5ef | 268 | * MBEDTLS_ERR_MD_BAD_INPUT_DATA if md_info was NULL. |
Christopher Haster |
1:24750b9ad5ef | 269 | */ |
Christopher Haster |
1:24750b9ad5ef | 270 | int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path, |
Christopher Haster |
1:24750b9ad5ef | 271 | unsigned char *output ); |
Christopher Haster |
1:24750b9ad5ef | 272 | #endif /* MBEDTLS_FS_IO */ |
Christopher Haster |
1:24750b9ad5ef | 273 | |
Christopher Haster |
1:24750b9ad5ef | 274 | /** |
Christopher Haster |
1:24750b9ad5ef | 275 | * \brief Set HMAC key and prepare to authenticate a new message. |
Christopher Haster |
1:24750b9ad5ef | 276 | * Usually called after mbedtls_md_setup() or mbedtls_md_hmac_finish(). |
Christopher Haster |
1:24750b9ad5ef | 277 | * |
Christopher Haster |
1:24750b9ad5ef | 278 | * \param ctx HMAC context |
Christopher Haster |
1:24750b9ad5ef | 279 | * \param key HMAC secret key |
Christopher Haster |
1:24750b9ad5ef | 280 | * \param keylen length of the HMAC key in bytes |
Christopher Haster |
1:24750b9ad5ef | 281 | * |
Christopher Haster |
1:24750b9ad5ef | 282 | * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter |
Christopher Haster |
1:24750b9ad5ef | 283 | * verification fails. |
Christopher Haster |
1:24750b9ad5ef | 284 | */ |
Christopher Haster |
1:24750b9ad5ef | 285 | int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key, |
Christopher Haster |
1:24750b9ad5ef | 286 | size_t keylen ); |
Christopher Haster |
1:24750b9ad5ef | 287 | |
Christopher Haster |
1:24750b9ad5ef | 288 | /** |
Christopher Haster |
1:24750b9ad5ef | 289 | * \brief Generic HMAC process buffer. |
Christopher Haster |
1:24750b9ad5ef | 290 | * Called between mbedtls_md_hmac_starts() or mbedtls_md_hmac_reset() |
Christopher Haster |
1:24750b9ad5ef | 291 | * and mbedtls_md_hmac_finish(). |
Christopher Haster |
1:24750b9ad5ef | 292 | * May be called repeatedly. |
Christopher Haster |
1:24750b9ad5ef | 293 | * |
Christopher Haster |
1:24750b9ad5ef | 294 | * \param ctx HMAC context |
Christopher Haster |
1:24750b9ad5ef | 295 | * \param input buffer holding the data |
Christopher Haster |
1:24750b9ad5ef | 296 | * \param ilen length of the input data |
Christopher Haster |
1:24750b9ad5ef | 297 | * |
Christopher Haster |
1:24750b9ad5ef | 298 | * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter |
Christopher Haster |
1:24750b9ad5ef | 299 | * verification fails. |
Christopher Haster |
1:24750b9ad5ef | 300 | */ |
Christopher Haster |
1:24750b9ad5ef | 301 | int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input, |
Christopher Haster |
1:24750b9ad5ef | 302 | size_t ilen ); |
Christopher Haster |
1:24750b9ad5ef | 303 | |
Christopher Haster |
1:24750b9ad5ef | 304 | /** |
Christopher Haster |
1:24750b9ad5ef | 305 | * \brief Output HMAC. |
Christopher Haster |
1:24750b9ad5ef | 306 | * Called after mbedtls_md_hmac_update(). |
Christopher Haster |
1:24750b9ad5ef | 307 | * Usually followed my mbedtls_md_hmac_reset(), mbedtls_md_hmac_starts(), |
Christopher Haster |
1:24750b9ad5ef | 308 | * or mbedtls_md_free(). |
Christopher Haster |
1:24750b9ad5ef | 309 | * |
Christopher Haster |
1:24750b9ad5ef | 310 | * \param ctx HMAC context |
Christopher Haster |
1:24750b9ad5ef | 311 | * \param output Generic HMAC checksum result |
Christopher Haster |
1:24750b9ad5ef | 312 | * |
Christopher Haster |
1:24750b9ad5ef | 313 | * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter |
Christopher Haster |
1:24750b9ad5ef | 314 | * verification fails. |
Christopher Haster |
1:24750b9ad5ef | 315 | */ |
Christopher Haster |
1:24750b9ad5ef | 316 | int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output); |
Christopher Haster |
1:24750b9ad5ef | 317 | |
Christopher Haster |
1:24750b9ad5ef | 318 | /** |
Christopher Haster |
1:24750b9ad5ef | 319 | * \brief Prepare to authenticate a new message with the same key. |
Christopher Haster |
1:24750b9ad5ef | 320 | * Called after mbedtls_md_hmac_finish() and before mbedtls_md_hmac_update(). |
Christopher Haster |
1:24750b9ad5ef | 321 | * |
Christopher Haster |
1:24750b9ad5ef | 322 | * \param ctx HMAC context to be reset |
Christopher Haster |
1:24750b9ad5ef | 323 | * |
Christopher Haster |
1:24750b9ad5ef | 324 | * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter |
Christopher Haster |
1:24750b9ad5ef | 325 | * verification fails. |
Christopher Haster |
1:24750b9ad5ef | 326 | */ |
Christopher Haster |
1:24750b9ad5ef | 327 | int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx ); |
Christopher Haster |
1:24750b9ad5ef | 328 | |
Christopher Haster |
1:24750b9ad5ef | 329 | /** |
Christopher Haster |
1:24750b9ad5ef | 330 | * \brief Output = Generic_HMAC( hmac key, input buffer ) |
Christopher Haster |
1:24750b9ad5ef | 331 | * |
Christopher Haster |
1:24750b9ad5ef | 332 | * \param md_info message digest info |
Christopher Haster |
1:24750b9ad5ef | 333 | * \param key HMAC secret key |
Christopher Haster |
1:24750b9ad5ef | 334 | * \param keylen length of the HMAC key in bytes |
Christopher Haster |
1:24750b9ad5ef | 335 | * \param input buffer holding the data |
Christopher Haster |
1:24750b9ad5ef | 336 | * \param ilen length of the input data |
Christopher Haster |
1:24750b9ad5ef | 337 | * \param output Generic HMAC-result |
Christopher Haster |
1:24750b9ad5ef | 338 | * |
Christopher Haster |
1:24750b9ad5ef | 339 | * \returns 0 on success, MBEDTLS_ERR_MD_BAD_INPUT_DATA if parameter |
Christopher Haster |
1:24750b9ad5ef | 340 | * verification fails. |
Christopher Haster |
1:24750b9ad5ef | 341 | */ |
Christopher Haster |
1:24750b9ad5ef | 342 | int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen, |
Christopher Haster |
1:24750b9ad5ef | 343 | const unsigned char *input, size_t ilen, |
Christopher Haster |
1:24750b9ad5ef | 344 | unsigned char *output ); |
Christopher Haster |
1:24750b9ad5ef | 345 | |
Christopher Haster |
1:24750b9ad5ef | 346 | /* Internal use */ |
Christopher Haster |
1:24750b9ad5ef | 347 | int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data ); |
Christopher Haster |
1:24750b9ad5ef | 348 | |
Christopher Haster |
1:24750b9ad5ef | 349 | #ifdef __cplusplus |
Christopher Haster |
1:24750b9ad5ef | 350 | } |
Christopher Haster |
1:24750b9ad5ef | 351 | #endif |
Christopher Haster |
1:24750b9ad5ef | 352 | |
Christopher Haster |
1:24750b9ad5ef | 353 | #endif /* MBEDTLS_MD_H */ |