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