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