Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file md.h |
| 3 | * |
| 4 | * \brief This file contains the generic message-digest wrapper. |
| 5 | * |
| 6 | * \author Adriaan de Jong <dejong@fox-it.com> |
| 7 | */ |
| 8 | /* |
| 9 | * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved |
| 10 | * SPDX-License-Identifier: Apache-2.0 |
| 11 | * |
| 12 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 13 | * not use this file except in compliance with the License. |
| 14 | * You may obtain a copy of the License at |
| 15 | * |
| 16 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 17 | * |
| 18 | * Unless required by applicable law or agreed to in writing, software |
| 19 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 21 | * See the License for the specific language governing permissions and |
| 22 | * limitations under the License. |
| 23 | * |
| 24 | * This file is part of Mbed TLS (https://tls.mbed.org) |
| 25 | */ |
| 26 | |
| 27 | #ifndef MBEDTLS_MD_INTERNAL_H |
| 28 | #define MBEDTLS_MD_INTERNAL_H |
| 29 | |
| 30 | #if defined(MBEDTLS_MD2_C) |
| 31 | #include "mbedtls/md2.h" |
| 32 | #endif |
| 33 | |
| 34 | #if defined(MBEDTLS_MD4_C) |
| 35 | #include "mbedtls/md4.h" |
| 36 | #endif |
| 37 | |
| 38 | #if defined(MBEDTLS_MD5_C) |
| 39 | #include "mbedtls/md5.h" |
| 40 | #endif |
| 41 | |
| 42 | #if defined(MBEDTLS_RIPEMD160_C) |
| 43 | #include "mbedtls/ripemd160.h" |
| 44 | #endif |
| 45 | |
| 46 | #if defined(MBEDTLS_SHA1_C) |
| 47 | #include "mbedtls/sha1.h" |
| 48 | #endif |
| 49 | |
| 50 | #if defined(MBEDTLS_SHA256_C) |
| 51 | #include "mbedtls/sha256.h" |
| 52 | #endif |
| 53 | |
| 54 | #if defined(MBEDTLS_SHA512_C) |
| 55 | #include "mbedtls/sha512.h" |
| 56 | #endif |
| 57 | |
| 58 | #include "mbedtls/platform_util.h" |
| 59 | |
| 60 | #if defined(MBEDTLS_PLATFORM_C) |
| 61 | #include "mbedtls/platform.h" |
| 62 | #else |
| 63 | #include <stdlib.h> |
| 64 | #define mbedtls_calloc calloc |
| 65 | #define mbedtls_free free |
| 66 | #endif |
| 67 | |
| 68 | #ifdef __cplusplus |
| 69 | extern "C" { |
| 70 | #endif |
| 71 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 72 | #define MBEDTLS_MD_WRAPPER MBEDTLS_ALWAYS_INLINE static inline |
| 73 | |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 74 | /* |
| 75 | * Message-digest information macro definition |
| 76 | */ |
| 77 | |
Hanno Becker | 7a7b722 | 2019-09-04 12:47:48 +0100 | [diff] [blame] | 78 | /* Dummy definition to keep check-names.sh happy - don't uncomment */ |
| 79 | //#define MBEDTLS_MD_INFO_SHA256 |
| 80 | |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 81 | /* SHA-256 */ |
| 82 | #define MBEDTLS_MD_INFO_SHA256_TYPE MBEDTLS_MD_SHA256 |
Hanno Becker | 6deddf7 | 2019-09-05 11:17:30 +0100 | [diff] [blame^] | 83 | #define MBEDTLS_MD_INFO_SHA256_CTX_TYPE mbedtls_sha256_context |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 84 | #define MBEDTLS_MD_INFO_SHA256_NAME "SHA256" |
| 85 | #define MBEDTLS_MD_INFO_SHA256_SIZE 32 |
| 86 | #define MBEDTLS_MD_INFO_SHA256_BLOCKSIZE 64 |
| 87 | #define MBEDTLS_MD_INFO_SHA256_STARTS_FUNC mbedtls_sha256_starts_wrap |
| 88 | #define MBEDTLS_MD_INFO_SHA256_UPDATE_FUNC mbedtls_sha224_update_wrap |
| 89 | #define MBEDTLS_MD_INFO_SHA256_FINISH_FUNC mbedtls_sha224_finish_wrap |
| 90 | #define MBEDTLS_MD_INFO_SHA256_DIGEST_FUNC mbedtls_sha256_wrap |
| 91 | #define MBEDTLS_MD_INFO_SHA256_ALLOC_FUNC mbedtls_sha224_ctx_alloc |
| 92 | #define MBEDTLS_MD_INFO_SHA256_FREE_FUNC mbedtls_sha224_ctx_free |
| 93 | #define MBEDTLS_MD_INFO_SHA256_CLONE_FUNC mbedtls_sha224_clone_wrap |
| 94 | #define MBEDTLS_MD_INFO_SHA256_PROCESS_FUNC mbedtls_sha224_process_wrap |
| 95 | |
| 96 | /* |
| 97 | * Helper macros to extract fields from ciphersuites. |
| 98 | */ |
| 99 | |
Hanno Becker | 6deddf7 | 2019-09-05 11:17:30 +0100 | [diff] [blame^] | 100 | #define MBEDTLS_MD_INFO_CTX_TYPE_T( MD ) MD ## _CTX_TYPE |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 101 | #define MBEDTLS_MD_INFO_TYPE_T( MD ) MD ## _TYPE |
| 102 | #define MBEDTLS_MD_INFO_NAME_T( MD ) MD ## _NAME |
| 103 | #define MBEDTLS_MD_INFO_SIZE_T( MD ) MD ## _SIZE |
| 104 | #define MBEDTLS_MD_INFO_BLOCKSIZE_T( MD ) MD ## _BLOCKSIZE |
| 105 | #define MBEDTLS_MD_INFO_STARTS_FUNC_T( MD ) MD ## _STARTS_FUNC |
| 106 | #define MBEDTLS_MD_INFO_UPDATE_FUNC_T( MD ) MD ## _UPDATE_FUNC |
| 107 | #define MBEDTLS_MD_INFO_FINISH_FUNC_T( MD ) MD ## _FINISH_FUNC |
| 108 | #define MBEDTLS_MD_INFO_DIGEST_FUNC_T( MD ) MD ## _DIGEST_FUNC |
| 109 | #define MBEDTLS_MD_INFO_ALLOC_FUNC_T( MD ) MD ## _ALLOC_FUNC |
| 110 | #define MBEDTLS_MD_INFO_FREE_FUNC_T( MD ) MD ## _FREE_FUNC |
| 111 | #define MBEDTLS_MD_INFO_CLONE_FUNC_T( MD ) MD ## _CLONE_FUNC |
| 112 | #define MBEDTLS_MD_INFO_PROCESS_FUNC_T( MD ) MD ## _PROCESS_FUNC |
| 113 | |
| 114 | /* Wrapper around MBEDTLS_MD_INFO_XXX_T() which makes sure that |
| 115 | * the argument is macro-expanded before concatenated with the |
| 116 | * field name. This allows to call these macros as |
| 117 | * MBEDTLS_MD_INFO_XXX( MBEDTLS_MD_SINGLE_HASH ). |
| 118 | * where MBEDTLS_MD_SINGLE_HASH expands to MBEDTLS_MD_INFO_XXX. */ |
Hanno Becker | 6deddf7 | 2019-09-05 11:17:30 +0100 | [diff] [blame^] | 119 | #define MBEDTLS_MD_INFO_CTX_TYPE( MD ) MBEDTLS_MD_INFO_CTX_TYPE_T( MD ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 120 | #define MBEDTLS_MD_INFO_TYPE( MD ) MBEDTLS_MD_INFO_TYPE_T( MD ) |
| 121 | #define MBEDTLS_MD_INFO_NAME( MD ) MBEDTLS_MD_INFO_NAME_T( MD ) |
| 122 | #define MBEDTLS_MD_INFO_SIZE( MD ) MBEDTLS_MD_INFO_SIZE_T( MD ) |
| 123 | #define MBEDTLS_MD_INFO_BLOCKSIZE( MD ) MBEDTLS_MD_INFO_BLOCKSIZE_T( MD ) |
| 124 | #define MBEDTLS_MD_INFO_STARTS_FUNC( MD ) MBEDTLS_MD_INFO_STARTS_FUNC_T( MD ) |
| 125 | #define MBEDTLS_MD_INFO_UPDATE_FUNC( MD ) MBEDTLS_MD_INFO_UPDATE_FUNC_T( MD ) |
| 126 | #define MBEDTLS_MD_INFO_FINISH_FUNC( MD ) MBEDTLS_MD_INFO_FINISH_FUNC_T( MD ) |
| 127 | #define MBEDTLS_MD_INFO_DIGEST_FUNC( MD ) MBEDTLS_MD_INFO_DIGEST_FUNC_T( MD ) |
| 128 | #define MBEDTLS_MD_INFO_ALLOC_FUNC( MD ) MBEDTLS_MD_INFO_ALLOC_FUNC_T( MD ) |
| 129 | #define MBEDTLS_MD_INFO_FREE_FUNC( MD ) MBEDTLS_MD_INFO_FREE_FUNC_T( MD ) |
| 130 | #define MBEDTLS_MD_INFO_CLONE_FUNC( MD ) MBEDTLS_MD_INFO_CLONE_FUNC_T( MD ) |
| 131 | #define MBEDTLS_MD_INFO_PROCESS_FUNC( MD ) MBEDTLS_MD_INFO_PROCESS_FUNC_T( MD ) |
| 132 | |
| 133 | /** |
| 134 | * Message digest information. |
| 135 | * Allows message digest functions to be called in a generic way. |
| 136 | */ |
| 137 | |
| 138 | typedef int mbedtls_md_starts_func_t( void *ctx ); |
| 139 | typedef int mbedtls_md_update_func_t( void *ctx, |
| 140 | const unsigned char *input, |
| 141 | size_t ilen ); |
| 142 | typedef int mbedtls_md_finish_func_t( void *ctx, unsigned char *output ); |
| 143 | typedef int mbedtls_md_digest_func_t( const unsigned char *input, |
| 144 | size_t ilen, |
| 145 | unsigned char *output ); |
| 146 | typedef void* mbedtls_md_ctx_alloc_func_t( void ); |
| 147 | typedef void mbedtls_md_ctx_free_func_t( void *ctx ); |
| 148 | typedef void mbedtls_md_clone_func_t( void *st, const void *src ); |
| 149 | typedef int mbedtls_md_process_func_t( void *ctx, |
| 150 | const unsigned char *input ); |
| 151 | |
| 152 | #if !defined(MBEDTLS_MD_SINGLE_HASH) |
| 153 | struct mbedtls_md_info_t |
| 154 | { |
| 155 | /** Digest identifier */ |
| 156 | mbedtls_md_type_t type; |
| 157 | |
| 158 | /** Name of the message digest */ |
| 159 | const char * name; |
| 160 | |
| 161 | /** Output length of the digest function in bytes */ |
| 162 | int size; |
| 163 | |
| 164 | /** Block length of the digest function in bytes */ |
| 165 | int block_size; |
| 166 | |
| 167 | /** Digest initialisation function */ |
| 168 | mbedtls_md_starts_func_t *starts_func; |
| 169 | |
| 170 | /** Digest update function */ |
| 171 | mbedtls_md_update_func_t *update_func; |
| 172 | |
| 173 | /** Digest finalisation function */ |
| 174 | mbedtls_md_finish_func_t *finish_func; |
| 175 | |
| 176 | /** Generic digest function */ |
| 177 | mbedtls_md_digest_func_t *digest_func; |
| 178 | |
| 179 | /** Allocate a new context */ |
| 180 | mbedtls_md_ctx_alloc_func_t *ctx_alloc_func; |
| 181 | |
| 182 | /** Free the given context */ |
| 183 | mbedtls_md_ctx_free_func_t *ctx_free_func; |
| 184 | |
| 185 | /** Clone state from a context */ |
| 186 | mbedtls_md_clone_func_t *clone_func; |
| 187 | |
| 188 | /** Internal use only */ |
| 189 | mbedtls_md_process_func_t *process_func; |
| 190 | }; |
| 191 | |
| 192 | /** |
| 193 | * \brief This macro builds an instance of ::mbedtls_md_info_t |
| 194 | * from an \c MBEDTLS_MD_INFO_XXX identifier. |
| 195 | */ |
| 196 | #define MBEDTLS_MD_INFO( MD ) \ |
| 197 | { MBEDTLS_MD_INFO_TYPE( MD ), \ |
| 198 | MBEDTLS_MD_INFO_NAME( MD ), \ |
| 199 | MBEDTLS_MD_INFO_SIZE( MD ), \ |
| 200 | MBEDTLS_MD_INFO_BLOCKSIZE( MD ), \ |
| 201 | MBEDTLS_MD_INFO_STARTS_FUNC( MD ), \ |
| 202 | MBEDTLS_MD_INFO_UPDATE_FUNC( MD ), \ |
| 203 | MBEDTLS_MD_INFO_FINISH_FUNC( MD ), \ |
| 204 | MBEDTLS_MD_INFO_DIGEST_FUNC( MD ), \ |
| 205 | MBEDTLS_MD_INFO_ALLOC_FUNC( MD ), \ |
| 206 | MBEDTLS_MD_INFO_FREE_FUNC( MD ), \ |
| 207 | MBEDTLS_MD_INFO_CLONE_FUNC( MD ), \ |
| 208 | MBEDTLS_MD_INFO_PROCESS_FUNC( MD ) } |
| 209 | |
| 210 | #endif /* !MBEDTLS_MD_SINGLE_HASH */ |
| 211 | |
| 212 | /* |
| 213 | * |
| 214 | * Definitions of MD information structures for various digests. |
| 215 | * |
| 216 | */ |
| 217 | |
| 218 | /* |
| 219 | * MD-2 |
| 220 | */ |
| 221 | |
| 222 | #if defined(MBEDTLS_MD2_C) |
| 223 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 224 | MBEDTLS_MD_WRAPPER int mbedtls_md2_starts_wrap( void *ctx ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 225 | { |
| 226 | return( mbedtls_md2_starts_ret( (mbedtls_md2_context *) ctx ) ); |
| 227 | } |
| 228 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 229 | MBEDTLS_MD_WRAPPER int mbedtls_md2_update_wrap( void *ctx, const unsigned char *input, |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 230 | size_t ilen ) |
| 231 | { |
| 232 | return( mbedtls_md2_update_ret( (mbedtls_md2_context *) ctx, input, ilen ) ); |
| 233 | } |
| 234 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 235 | MBEDTLS_MD_WRAPPER int mbedtls_md2_finish_wrap( void *ctx, unsigned char *output ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 236 | { |
| 237 | return( mbedtls_md2_finish_ret( (mbedtls_md2_context *) ctx, output ) ); |
| 238 | } |
| 239 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 240 | MBEDTLS_MD_WRAPPER void* mbedtls_md2_ctx_alloc( void ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 241 | { |
| 242 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md2_context ) ); |
| 243 | |
| 244 | if( ctx != NULL ) |
| 245 | mbedtls_md2_init( (mbedtls_md2_context *) ctx ); |
| 246 | |
| 247 | return( ctx ); |
| 248 | } |
| 249 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 250 | MBEDTLS_MD_WRAPPER void mbedtls_md2_ctx_free( void *ctx ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 251 | { |
| 252 | mbedtls_md2_free( (mbedtls_md2_context *) ctx ); |
| 253 | mbedtls_free( ctx ); |
| 254 | } |
| 255 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 256 | MBEDTLS_MD_WRAPPER void mbedtls_md2_clone_wrap( void *dst, const void *src ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 257 | { |
| 258 | mbedtls_md2_clone( (mbedtls_md2_context *) dst, |
| 259 | (const mbedtls_md2_context *) src ); |
| 260 | } |
| 261 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 262 | MBEDTLS_MD_WRAPPER int mbedtls_md2_process_wrap( void *ctx, const unsigned char *data ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 263 | { |
| 264 | ((void) data); |
| 265 | |
| 266 | return( mbedtls_internal_md2_process( (mbedtls_md2_context *) ctx ) ); |
| 267 | } |
| 268 | |
| 269 | #endif /* MBEDTLS_MD2_C */ |
| 270 | |
| 271 | /* |
| 272 | * MD-4 |
| 273 | */ |
| 274 | |
| 275 | #if defined(MBEDTLS_MD4_C) |
| 276 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 277 | MBEDTLS_MD_WRAPPER int mbedtls_md4_starts_wrap( void *ctx ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 278 | { |
| 279 | return( mbedtls_md4_starts_ret( (mbedtls_md4_context *) ctx ) ); |
| 280 | } |
| 281 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 282 | MBEDTLS_MD_WRAPPER int mbedtls_md4_update_wrap( void *ctx, const unsigned char *input, |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 283 | size_t ilen ) |
| 284 | { |
| 285 | return( mbedtls_md4_update_ret( (mbedtls_md4_context *) ctx, input, ilen ) ); |
| 286 | } |
| 287 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 288 | MBEDTLS_MD_WRAPPER int mbedtls_md4_finish_wrap( void *ctx, unsigned char *output ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 289 | { |
| 290 | return( mbedtls_md4_finish_ret( (mbedtls_md4_context *) ctx, output ) ); |
| 291 | } |
| 292 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 293 | MBEDTLS_MD_WRAPPER void* mbedtls_md4_ctx_alloc( void ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 294 | { |
| 295 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md4_context ) ); |
| 296 | |
| 297 | if( ctx != NULL ) |
| 298 | mbedtls_md4_init( (mbedtls_md4_context *) ctx ); |
| 299 | |
| 300 | return( ctx ); |
| 301 | } |
| 302 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 303 | MBEDTLS_MD_WRAPPER void mbedtls_md4_ctx_free( void *ctx ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 304 | { |
| 305 | mbedtls_md4_free( (mbedtls_md4_context *) ctx ); |
| 306 | mbedtls_free( ctx ); |
| 307 | } |
| 308 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 309 | MBEDTLS_MD_WRAPPER void mbedtls_md4_clone_wrap( void *dst, const void *src ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 310 | { |
| 311 | mbedtls_md4_clone( (mbedtls_md4_context *) dst, |
| 312 | (const mbedtls_md4_context *) src ); |
| 313 | } |
| 314 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 315 | MBEDTLS_MD_WRAPPER int mbedtls_md4_process_wrap( void *ctx, const unsigned char *data ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 316 | { |
| 317 | return( mbedtls_internal_md4_process( (mbedtls_md4_context *) ctx, data ) ); |
| 318 | } |
| 319 | |
| 320 | #endif /* MBEDTLS_MD4_C */ |
| 321 | |
| 322 | /* |
| 323 | * MD-5 |
| 324 | */ |
| 325 | |
| 326 | #if defined(MBEDTLS_MD5_C) |
| 327 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 328 | MBEDTLS_MD_WRAPPER int mbedtls_md5_starts_wrap( void *ctx ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 329 | { |
| 330 | return( mbedtls_md5_starts_ret( (mbedtls_md5_context *) ctx ) ); |
| 331 | } |
| 332 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 333 | MBEDTLS_MD_WRAPPER int mbedtls_md5_update_wrap( void *ctx, const unsigned char *input, |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 334 | size_t ilen ) |
| 335 | { |
| 336 | return( mbedtls_md5_update_ret( (mbedtls_md5_context *) ctx, input, ilen ) ); |
| 337 | } |
| 338 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 339 | MBEDTLS_MD_WRAPPER int mbedtls_md5_finish_wrap( void *ctx, unsigned char *output ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 340 | { |
| 341 | return( mbedtls_md5_finish_ret( (mbedtls_md5_context *) ctx, output ) ); |
| 342 | } |
| 343 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 344 | MBEDTLS_MD_WRAPPER void* mbedtls_md5_ctx_alloc( void ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 345 | { |
| 346 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md5_context ) ); |
| 347 | |
| 348 | if( ctx != NULL ) |
| 349 | mbedtls_md5_init( (mbedtls_md5_context *) ctx ); |
| 350 | |
| 351 | return( ctx ); |
| 352 | } |
| 353 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 354 | MBEDTLS_MD_WRAPPER void mbedtls_md5_ctx_free( void *ctx ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 355 | { |
| 356 | mbedtls_md5_free( (mbedtls_md5_context *) ctx ); |
| 357 | mbedtls_free( ctx ); |
| 358 | } |
| 359 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 360 | MBEDTLS_MD_WRAPPER void mbedtls_md5_clone_wrap( void *dst, const void *src ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 361 | { |
| 362 | mbedtls_md5_clone( (mbedtls_md5_context *) dst, |
| 363 | (const mbedtls_md5_context *) src ); |
| 364 | } |
| 365 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 366 | MBEDTLS_MD_WRAPPER int mbedtls_md5_process_wrap( void *ctx, const unsigned char *data ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 367 | { |
| 368 | return( mbedtls_internal_md5_process( (mbedtls_md5_context *) ctx, data ) ); |
| 369 | } |
| 370 | |
| 371 | #endif /* MBEDTLS_MD5_C */ |
| 372 | |
| 373 | /* |
| 374 | * RIPEMD-160 |
| 375 | */ |
| 376 | |
| 377 | #if defined(MBEDTLS_RIPEMD160_C) |
| 378 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 379 | MBEDTLS_MD_WRAPPER int mbedtls_ripemd160_starts_wrap( void *ctx ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 380 | { |
| 381 | return( mbedtls_ripemd160_starts_ret( (mbedtls_ripemd160_context *) ctx ) ); |
| 382 | } |
| 383 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 384 | MBEDTLS_MD_WRAPPER int mbedtls_ripemd160_update_wrap( void *ctx, const unsigned char *input, |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 385 | size_t ilen ) |
| 386 | { |
| 387 | return( mbedtls_ripemd160_update_ret( (mbedtls_ripemd160_context *) ctx, |
| 388 | input, ilen ) ); |
| 389 | } |
| 390 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 391 | MBEDTLS_MD_WRAPPER int mbedtls_ripemd160_finish_wrap( void *ctx, unsigned char *output ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 392 | { |
| 393 | return( mbedtls_ripemd160_finish_ret( (mbedtls_ripemd160_context *) ctx, |
| 394 | output ) ); |
| 395 | } |
| 396 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 397 | MBEDTLS_MD_WRAPPER void* mbedtls_ripemd160_ctx_alloc( void ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 398 | { |
| 399 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ripemd160_context ) ); |
| 400 | |
| 401 | if( ctx != NULL ) |
| 402 | mbedtls_ripemd160_init( (mbedtls_ripemd160_context *) ctx ); |
| 403 | |
| 404 | return( ctx ); |
| 405 | } |
| 406 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 407 | MBEDTLS_MD_WRAPPER void mbedtls_ripemd160_ctx_free( void *ctx ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 408 | { |
| 409 | mbedtls_ripemd160_free( (mbedtls_ripemd160_context *) ctx ); |
| 410 | mbedtls_free( ctx ); |
| 411 | } |
| 412 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 413 | MBEDTLS_MD_WRAPPER void mbedtls_ripemd160_clone_wrap( void *dst, const void *src ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 414 | { |
| 415 | mbedtls_ripemd160_clone( (mbedtls_ripemd160_context *) dst, |
| 416 | (const mbedtls_ripemd160_context *) src ); |
| 417 | } |
| 418 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 419 | MBEDTLS_MD_WRAPPER int mbedtls_ripemd160_process_wrap( void *ctx, const unsigned char *data ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 420 | { |
| 421 | return( mbedtls_internal_ripemd160_process( |
| 422 | (mbedtls_ripemd160_context *) ctx, data ) ); |
| 423 | } |
| 424 | |
| 425 | #endif /* MBEDTLS_RIPEMD160_C */ |
| 426 | |
| 427 | /* |
| 428 | * SHA-1 |
| 429 | */ |
| 430 | |
| 431 | #if defined(MBEDTLS_SHA1_C) |
| 432 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 433 | MBEDTLS_MD_WRAPPER int mbedtls_sha1_starts_wrap( void *ctx ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 434 | { |
| 435 | return( mbedtls_sha1_starts_ret( (mbedtls_sha1_context *) ctx ) ); |
| 436 | } |
| 437 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 438 | MBEDTLS_MD_WRAPPER int mbedtls_sha1_update_wrap( void *ctx, const unsigned char *input, |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 439 | size_t ilen ) |
| 440 | { |
| 441 | return( mbedtls_sha1_update_ret( (mbedtls_sha1_context *) ctx, |
| 442 | input, ilen ) ); |
| 443 | } |
| 444 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 445 | MBEDTLS_MD_WRAPPER int mbedtls_sha1_finish_wrap( void *ctx, unsigned char *output ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 446 | { |
| 447 | return( mbedtls_sha1_finish_ret( (mbedtls_sha1_context *) ctx, output ) ); |
| 448 | } |
| 449 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 450 | MBEDTLS_MD_WRAPPER void* mbedtls_sha1_ctx_alloc( void ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 451 | { |
| 452 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha1_context ) ); |
| 453 | |
| 454 | if( ctx != NULL ) |
| 455 | mbedtls_sha1_init( (mbedtls_sha1_context *) ctx ); |
| 456 | |
| 457 | return( ctx ); |
| 458 | } |
| 459 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 460 | MBEDTLS_MD_WRAPPER void mbedtls_sha1_clone_wrap( void *dst, const void *src ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 461 | { |
| 462 | mbedtls_sha1_clone( (mbedtls_sha1_context *) dst, |
| 463 | (const mbedtls_sha1_context *) src ); |
| 464 | } |
| 465 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 466 | MBEDTLS_MD_WRAPPER void mbedtls_sha1_ctx_free( void *ctx ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 467 | { |
| 468 | mbedtls_sha1_free( (mbedtls_sha1_context *) ctx ); |
| 469 | mbedtls_free( ctx ); |
| 470 | } |
| 471 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 472 | MBEDTLS_MD_WRAPPER int mbedtls_sha1_process_wrap( void *ctx, const unsigned char *data ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 473 | { |
| 474 | return( mbedtls_internal_sha1_process( (mbedtls_sha1_context *) ctx, |
| 475 | data ) ); |
| 476 | } |
| 477 | |
| 478 | #endif /* MBEDTLS_SHA1_C */ |
| 479 | |
| 480 | /* |
| 481 | * SHA-224 and SHA-256 |
| 482 | */ |
| 483 | |
| 484 | #if defined(MBEDTLS_SHA256_C) |
| 485 | |
| 486 | #if !defined(MBEDTLS_SHA256_NO_SHA224) |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 487 | MBEDTLS_MD_WRAPPER int mbedtls_sha224_starts_wrap( void *ctx ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 488 | { |
| 489 | return( mbedtls_sha256_starts_ret( (mbedtls_sha256_context *) ctx, 1 ) ); |
| 490 | } |
| 491 | #endif /* !MBEDTLS_SHA256_NO_SHA224 */ |
| 492 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 493 | MBEDTLS_MD_WRAPPER int mbedtls_sha224_update_wrap( void *ctx, const unsigned char *input, |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 494 | size_t ilen ) |
| 495 | { |
| 496 | return( mbedtls_sha256_update_ret( (mbedtls_sha256_context *) ctx, |
| 497 | input, ilen ) ); |
| 498 | } |
| 499 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 500 | MBEDTLS_MD_WRAPPER int mbedtls_sha224_finish_wrap( void *ctx, unsigned char *output ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 501 | { |
| 502 | return( mbedtls_sha256_finish_ret( (mbedtls_sha256_context *) ctx, |
| 503 | output ) ); |
| 504 | } |
| 505 | |
| 506 | #if !defined(MBEDTLS_SHA256_NO_SHA224) |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 507 | MBEDTLS_MD_WRAPPER int mbedtls_sha224_wrap( const unsigned char *input, size_t ilen, |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 508 | unsigned char *output ) |
| 509 | { |
| 510 | return( mbedtls_sha256_ret( input, ilen, output, 1 ) ); |
| 511 | } |
| 512 | #endif /* !MBEDTLS_SHA256_NO_SHA224 */ |
| 513 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 514 | MBEDTLS_MD_WRAPPER void* mbedtls_sha224_ctx_alloc( void ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 515 | { |
| 516 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha256_context ) ); |
| 517 | |
| 518 | if( ctx != NULL ) |
| 519 | mbedtls_sha256_init( (mbedtls_sha256_context *) ctx ); |
| 520 | |
| 521 | return( ctx ); |
| 522 | } |
| 523 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 524 | MBEDTLS_MD_WRAPPER void mbedtls_sha224_ctx_free( void *ctx ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 525 | { |
| 526 | mbedtls_sha256_free( (mbedtls_sha256_context *) ctx ); |
| 527 | mbedtls_free( ctx ); |
| 528 | } |
| 529 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 530 | MBEDTLS_MD_WRAPPER void mbedtls_sha224_clone_wrap( void *dst, const void *src ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 531 | { |
| 532 | mbedtls_sha256_clone( (mbedtls_sha256_context *) dst, |
| 533 | (const mbedtls_sha256_context *) src ); |
| 534 | } |
| 535 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 536 | MBEDTLS_MD_WRAPPER int mbedtls_sha224_process_wrap( void *ctx, const unsigned char *data ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 537 | { |
| 538 | return( mbedtls_internal_sha256_process( (mbedtls_sha256_context *) ctx, |
| 539 | data ) ); |
| 540 | } |
| 541 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 542 | MBEDTLS_MD_WRAPPER int mbedtls_sha256_starts_wrap( void *ctx ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 543 | { |
| 544 | return( mbedtls_sha256_starts_ret( (mbedtls_sha256_context *) ctx, 0 ) ); |
| 545 | } |
| 546 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 547 | MBEDTLS_MD_WRAPPER int mbedtls_sha256_wrap( const unsigned char *input, size_t ilen, |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 548 | unsigned char *output ) |
| 549 | { |
| 550 | return( mbedtls_sha256_ret( input, ilen, output, 0 ) ); |
| 551 | } |
| 552 | |
| 553 | #endif /* MBEDTLS_SHA256_C */ |
| 554 | |
| 555 | /* |
| 556 | * SHA-384 and SHA-512 |
| 557 | */ |
| 558 | |
| 559 | #if defined(MBEDTLS_SHA512_C) |
| 560 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 561 | MBEDTLS_MD_WRAPPER int mbedtls_sha384_starts_wrap( void *ctx ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 562 | { |
| 563 | return( mbedtls_sha512_starts_ret( (mbedtls_sha512_context *) ctx, 1 ) ); |
| 564 | } |
| 565 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 566 | MBEDTLS_MD_WRAPPER int mbedtls_sha384_update_wrap( void *ctx, const unsigned char *input, |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 567 | size_t ilen ) |
| 568 | { |
| 569 | return( mbedtls_sha512_update_ret( (mbedtls_sha512_context *) ctx, |
| 570 | input, ilen ) ); |
| 571 | } |
| 572 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 573 | MBEDTLS_MD_WRAPPER int mbedtls_sha384_finish_wrap( void *ctx, unsigned char *output ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 574 | { |
| 575 | return( mbedtls_sha512_finish_ret( (mbedtls_sha512_context *) ctx, |
| 576 | output ) ); |
| 577 | } |
| 578 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 579 | MBEDTLS_MD_WRAPPER int mbedtls_sha384_wrap( const unsigned char *input, size_t ilen, |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 580 | unsigned char *output ) |
| 581 | { |
| 582 | return( mbedtls_sha512_ret( input, ilen, output, 1 ) ); |
| 583 | } |
| 584 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 585 | MBEDTLS_MD_WRAPPER void* mbedtls_sha384_ctx_alloc( void ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 586 | { |
| 587 | void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha512_context ) ); |
| 588 | |
| 589 | if( ctx != NULL ) |
| 590 | mbedtls_sha512_init( (mbedtls_sha512_context *) ctx ); |
| 591 | |
| 592 | return( ctx ); |
| 593 | } |
| 594 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 595 | MBEDTLS_MD_WRAPPER void mbedtls_sha384_ctx_free( void *ctx ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 596 | { |
| 597 | mbedtls_sha512_free( (mbedtls_sha512_context *) ctx ); |
| 598 | mbedtls_free( ctx ); |
| 599 | } |
| 600 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 601 | MBEDTLS_MD_WRAPPER void mbedtls_sha384_clone_wrap( void *dst, const void *src ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 602 | { |
| 603 | mbedtls_sha512_clone( (mbedtls_sha512_context *) dst, |
| 604 | (const mbedtls_sha512_context *) src ); |
| 605 | } |
| 606 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 607 | MBEDTLS_MD_WRAPPER int mbedtls_sha384_process_wrap( void *ctx, const unsigned char *data ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 608 | { |
| 609 | return( mbedtls_internal_sha512_process( (mbedtls_sha512_context *) ctx, |
| 610 | data ) ); |
| 611 | } |
| 612 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 613 | MBEDTLS_MD_WRAPPER int mbedtls_sha512_starts_wrap( void *ctx ) |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 614 | { |
| 615 | return( mbedtls_sha512_starts_ret( (mbedtls_sha512_context *) ctx, 0 ) ); |
| 616 | } |
| 617 | |
Hanno Becker | 7a78fe4 | 2019-09-04 15:41:21 +0100 | [diff] [blame] | 618 | MBEDTLS_MD_WRAPPER int mbedtls_sha512_wrap( const unsigned char *input, size_t ilen, |
Hanno Becker | c4e4210 | 2019-09-04 12:43:22 +0100 | [diff] [blame] | 619 | unsigned char *output ) |
| 620 | { |
| 621 | return( mbedtls_sha512_ret( input, ilen, output, 0 ) ); |
| 622 | } |
| 623 | |
| 624 | #endif /* MBEDTLS_SHA512_C */ |
| 625 | |
| 626 | /* |
| 627 | * Getter functions for MD info structure. |
| 628 | */ |
| 629 | |
| 630 | #if !defined(MBEDTLS_MD_SINGLE_HASH) |
| 631 | |
| 632 | MBEDTLS_ALWAYS_INLINE static inline mbedtls_md_type_t mbedtls_md_info_type( |
| 633 | mbedtls_md_handle_t info ) |
| 634 | { |
| 635 | return( info->type ); |
| 636 | } |
| 637 | |
| 638 | MBEDTLS_ALWAYS_INLINE static inline const char * mbedtls_md_info_name( |
| 639 | mbedtls_md_handle_t info ) |
| 640 | { |
| 641 | return( info->name ); |
| 642 | } |
| 643 | |
| 644 | MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_size( |
| 645 | mbedtls_md_handle_t info ) |
| 646 | { |
| 647 | return( info->size ); |
| 648 | } |
| 649 | |
| 650 | MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_block_size( |
| 651 | mbedtls_md_handle_t info ) |
| 652 | { |
| 653 | return( info->block_size ); |
| 654 | } |
| 655 | |
| 656 | MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_starts( |
| 657 | mbedtls_md_handle_t info, |
| 658 | void *ctx ) |
| 659 | { |
| 660 | return( info->starts_func( ctx ) ); |
| 661 | } |
| 662 | |
| 663 | MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_update( |
| 664 | mbedtls_md_handle_t info, |
| 665 | void *ctx, |
| 666 | const unsigned char *input, |
| 667 | size_t ilen ) |
| 668 | { |
| 669 | return( info->update_func( ctx, input, ilen ) ); |
| 670 | } |
| 671 | |
| 672 | MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_finish( |
| 673 | mbedtls_md_handle_t info, |
| 674 | void *ctx, |
| 675 | unsigned char *output ) |
| 676 | { |
| 677 | return( info->finish_func( ctx, output ) ); |
| 678 | } |
| 679 | |
| 680 | MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_digest( |
| 681 | mbedtls_md_handle_t info, |
| 682 | const unsigned char *input, |
| 683 | size_t ilen, |
| 684 | unsigned char *output ) |
| 685 | { |
| 686 | return( info->digest_func( input, ilen, output ) ); |
| 687 | } |
| 688 | |
| 689 | MBEDTLS_ALWAYS_INLINE static inline void* mbedtls_md_info_ctx_alloc( |
| 690 | mbedtls_md_handle_t info ) |
| 691 | { |
| 692 | return( info->ctx_alloc_func() ); |
| 693 | } |
| 694 | |
| 695 | MBEDTLS_ALWAYS_INLINE static inline void mbedtls_md_info_ctx_free( |
| 696 | mbedtls_md_handle_t info, |
| 697 | void *ctx ) |
| 698 | { |
| 699 | info->ctx_free_func( ctx ); |
| 700 | } |
| 701 | |
| 702 | MBEDTLS_ALWAYS_INLINE static inline void mbedtls_md_info_clone( |
| 703 | mbedtls_md_handle_t info, |
| 704 | void *dst, |
| 705 | const void *src ) |
| 706 | { |
| 707 | info->clone_func( dst, src ); |
| 708 | } |
| 709 | |
| 710 | MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_process( |
| 711 | mbedtls_md_handle_t info, |
| 712 | void *ctx, |
| 713 | const unsigned char *input ) |
| 714 | { |
| 715 | return( info->process_func( ctx, input ) ); |
| 716 | } |
| 717 | |
| 718 | #else /* !MBEDTLS_MD_SINGLE_HASH */ |
| 719 | |
| 720 | MBEDTLS_ALWAYS_INLINE static inline mbedtls_md_type_t mbedtls_md_info_type( |
| 721 | mbedtls_md_handle_t info ) |
| 722 | { |
| 723 | ((void) info); |
| 724 | return( MBEDTLS_MD_INFO_TYPE( MBEDTLS_MD_SINGLE_HASH ) ); |
| 725 | } |
| 726 | |
| 727 | MBEDTLS_ALWAYS_INLINE static inline const char * mbedtls_md_info_name( |
| 728 | mbedtls_md_handle_t info ) |
| 729 | { |
| 730 | ((void) info); |
| 731 | return( MBEDTLS_MD_INFO_NAME( MBEDTLS_MD_SINGLE_HASH ) ); |
| 732 | } |
| 733 | |
| 734 | MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_size( |
| 735 | mbedtls_md_handle_t info ) |
| 736 | { |
| 737 | ((void) info); |
| 738 | return( MBEDTLS_MD_INFO_SIZE( MBEDTLS_MD_SINGLE_HASH ) ); |
| 739 | } |
| 740 | |
| 741 | MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_block_size( |
| 742 | mbedtls_md_handle_t info ) |
| 743 | { |
| 744 | ((void) info); |
| 745 | return( MBEDTLS_MD_INFO_BLOCKSIZE( MBEDTLS_MD_SINGLE_HASH ) ); |
| 746 | } |
| 747 | |
| 748 | MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_starts( |
| 749 | mbedtls_md_handle_t info, |
| 750 | void *ctx ) |
| 751 | { |
| 752 | ((void) info); |
| 753 | return( MBEDTLS_MD_INFO_STARTS_FUNC( MBEDTLS_MD_SINGLE_HASH )( ctx ) ); |
| 754 | } |
| 755 | |
| 756 | MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_update( |
| 757 | mbedtls_md_handle_t info, |
| 758 | void *ctx, |
| 759 | const unsigned char *input, |
| 760 | size_t ilen ) |
| 761 | { |
| 762 | ((void) info); |
| 763 | return( MBEDTLS_MD_INFO_UPDATE_FUNC( MBEDTLS_MD_SINGLE_HASH ) |
| 764 | ( ctx, input, ilen ) ); |
| 765 | } |
| 766 | |
| 767 | MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_finish( |
| 768 | mbedtls_md_handle_t info, |
| 769 | void *ctx, |
| 770 | unsigned char *output ) |
| 771 | { |
| 772 | ((void) info); |
| 773 | return( MBEDTLS_MD_INFO_FINISH_FUNC( MBEDTLS_MD_SINGLE_HASH ) |
| 774 | ( ctx, output ) ); |
| 775 | } |
| 776 | |
| 777 | MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_digest( |
| 778 | mbedtls_md_handle_t info, |
| 779 | const unsigned char *input, |
| 780 | size_t ilen, |
| 781 | unsigned char *output ) |
| 782 | { |
| 783 | ((void) info); |
| 784 | return( MBEDTLS_MD_INFO_DIGEST_FUNC( MBEDTLS_MD_SINGLE_HASH ) |
| 785 | ( input, ilen, output ) ); |
| 786 | } |
| 787 | |
| 788 | MBEDTLS_ALWAYS_INLINE static inline void* mbedtls_md_info_ctx_alloc( |
| 789 | mbedtls_md_handle_t info ) |
| 790 | { |
| 791 | ((void) info); |
| 792 | return( MBEDTLS_MD_INFO_ALLOC_FUNC( MBEDTLS_MD_SINGLE_HASH )() ); |
| 793 | } |
| 794 | |
| 795 | MBEDTLS_ALWAYS_INLINE static inline void mbedtls_md_info_ctx_free( |
| 796 | mbedtls_md_handle_t info, |
| 797 | void *ctx ) |
| 798 | { |
| 799 | ((void) info); |
| 800 | MBEDTLS_MD_INFO_FREE_FUNC( MBEDTLS_MD_SINGLE_HASH )( ctx ); |
| 801 | } |
| 802 | |
| 803 | MBEDTLS_ALWAYS_INLINE static inline void mbedtls_md_info_clone( |
| 804 | mbedtls_md_handle_t info, |
| 805 | void *dst, |
| 806 | const void *src ) |
| 807 | { |
| 808 | ((void) info); |
| 809 | MBEDTLS_MD_INFO_CLONE_FUNC( MBEDTLS_MD_SINGLE_HASH )( dst, src ); |
| 810 | } |
| 811 | |
| 812 | MBEDTLS_ALWAYS_INLINE static inline int mbedtls_md_info_process( |
| 813 | mbedtls_md_handle_t info, |
| 814 | void *ctx, |
| 815 | const unsigned char *input ) |
| 816 | { |
| 817 | ((void) info); |
| 818 | return( MBEDTLS_MD_INFO_PROCESS_FUNC( MBEDTLS_MD_SINGLE_HASH ) |
| 819 | ( ctx, input ) ); |
| 820 | } |
| 821 | |
| 822 | #endif /* MBEDTLS_MD_SINGLE_HASH */ |
| 823 | |
| 824 | #ifdef __cplusplus |
| 825 | } |
| 826 | #endif |
| 827 | |
| 828 | #endif /* MBEDTLS_MD_INTERNAL_H */ |