mbedtls ported to mbed-classic

Fork of mbedtls by Christopher Haster

Committer:
Christopher Haster
Date:
Fri Jan 22 16:44:49 2016 -0600
Revision:
1:24750b9ad5ef
Initial move of mbedtls to mercurial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Christopher Haster 1:24750b9ad5ef 1 /**
Christopher Haster 1:24750b9ad5ef 2 * \file md_wrap.c
Christopher Haster 1:24750b9ad5ef 3 *
Christopher Haster 1:24750b9ad5ef 4 * \brief Generic message digest wrapper for mbed TLS
Christopher Haster 1:24750b9ad5ef 5 *
Christopher Haster 1:24750b9ad5ef 6 * \author Adriaan de Jong <dejong@fox-it.com>
Christopher Haster 1:24750b9ad5ef 7 *
Christopher Haster 1:24750b9ad5ef 8 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Christopher Haster 1:24750b9ad5ef 9 * SPDX-License-Identifier: Apache-2.0
Christopher Haster 1:24750b9ad5ef 10 *
Christopher Haster 1:24750b9ad5ef 11 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Christopher Haster 1:24750b9ad5ef 12 * not use this file except in compliance with the License.
Christopher Haster 1:24750b9ad5ef 13 * You may obtain a copy of the License at
Christopher Haster 1:24750b9ad5ef 14 *
Christopher Haster 1:24750b9ad5ef 15 * http://www.apache.org/licenses/LICENSE-2.0
Christopher Haster 1:24750b9ad5ef 16 *
Christopher Haster 1:24750b9ad5ef 17 * Unless required by applicable law or agreed to in writing, software
Christopher Haster 1:24750b9ad5ef 18 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Christopher Haster 1:24750b9ad5ef 19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Christopher Haster 1:24750b9ad5ef 20 * See the License for the specific language governing permissions and
Christopher Haster 1:24750b9ad5ef 21 * limitations under the License.
Christopher Haster 1:24750b9ad5ef 22 *
Christopher Haster 1:24750b9ad5ef 23 * This file is part of mbed TLS (https://tls.mbed.org)
Christopher Haster 1:24750b9ad5ef 24 */
Christopher Haster 1:24750b9ad5ef 25
Christopher Haster 1:24750b9ad5ef 26 #if !defined(MBEDTLS_CONFIG_FILE)
Christopher Haster 1:24750b9ad5ef 27 #include "mbedtls/config.h"
Christopher Haster 1:24750b9ad5ef 28 #else
Christopher Haster 1:24750b9ad5ef 29 #include MBEDTLS_CONFIG_FILE
Christopher Haster 1:24750b9ad5ef 30 #endif
Christopher Haster 1:24750b9ad5ef 31
Christopher Haster 1:24750b9ad5ef 32 #if defined(MBEDTLS_MD_C)
Christopher Haster 1:24750b9ad5ef 33
Christopher Haster 1:24750b9ad5ef 34 #include "mbedtls/md_internal.h"
Christopher Haster 1:24750b9ad5ef 35
Christopher Haster 1:24750b9ad5ef 36 #if defined(MBEDTLS_MD2_C)
Christopher Haster 1:24750b9ad5ef 37 #include "mbedtls/md2.h"
Christopher Haster 1:24750b9ad5ef 38 #endif
Christopher Haster 1:24750b9ad5ef 39
Christopher Haster 1:24750b9ad5ef 40 #if defined(MBEDTLS_MD4_C)
Christopher Haster 1:24750b9ad5ef 41 #include "mbedtls/md4.h"
Christopher Haster 1:24750b9ad5ef 42 #endif
Christopher Haster 1:24750b9ad5ef 43
Christopher Haster 1:24750b9ad5ef 44 #if defined(MBEDTLS_MD5_C)
Christopher Haster 1:24750b9ad5ef 45 #include "mbedtls/md5.h"
Christopher Haster 1:24750b9ad5ef 46 #endif
Christopher Haster 1:24750b9ad5ef 47
Christopher Haster 1:24750b9ad5ef 48 #if defined(MBEDTLS_RIPEMD160_C)
Christopher Haster 1:24750b9ad5ef 49 #include "mbedtls/ripemd160.h"
Christopher Haster 1:24750b9ad5ef 50 #endif
Christopher Haster 1:24750b9ad5ef 51
Christopher Haster 1:24750b9ad5ef 52 #if defined(MBEDTLS_SHA1_C)
Christopher Haster 1:24750b9ad5ef 53 #include "mbedtls/sha1.h"
Christopher Haster 1:24750b9ad5ef 54 #endif
Christopher Haster 1:24750b9ad5ef 55
Christopher Haster 1:24750b9ad5ef 56 #if defined(MBEDTLS_SHA256_C)
Christopher Haster 1:24750b9ad5ef 57 #include "mbedtls/sha256.h"
Christopher Haster 1:24750b9ad5ef 58 #endif
Christopher Haster 1:24750b9ad5ef 59
Christopher Haster 1:24750b9ad5ef 60 #if defined(MBEDTLS_SHA512_C)
Christopher Haster 1:24750b9ad5ef 61 #include "mbedtls/sha512.h"
Christopher Haster 1:24750b9ad5ef 62 #endif
Christopher Haster 1:24750b9ad5ef 63
Christopher Haster 1:24750b9ad5ef 64 #if defined(MBEDTLS_PLATFORM_C)
Christopher Haster 1:24750b9ad5ef 65 #include "mbedtls/platform.h"
Christopher Haster 1:24750b9ad5ef 66 #else
Christopher Haster 1:24750b9ad5ef 67 #include <stdlib.h>
Christopher Haster 1:24750b9ad5ef 68 #define mbedtls_calloc calloc
Christopher Haster 1:24750b9ad5ef 69 #define mbedtls_free free
Christopher Haster 1:24750b9ad5ef 70 #endif
Christopher Haster 1:24750b9ad5ef 71
Christopher Haster 1:24750b9ad5ef 72 #if defined(MBEDTLS_MD2_C)
Christopher Haster 1:24750b9ad5ef 73
Christopher Haster 1:24750b9ad5ef 74 static void md2_starts_wrap( void *ctx )
Christopher Haster 1:24750b9ad5ef 75 {
Christopher Haster 1:24750b9ad5ef 76 mbedtls_md2_starts( (mbedtls_md2_context *) ctx );
Christopher Haster 1:24750b9ad5ef 77 }
Christopher Haster 1:24750b9ad5ef 78
Christopher Haster 1:24750b9ad5ef 79 static void md2_update_wrap( void *ctx, const unsigned char *input,
Christopher Haster 1:24750b9ad5ef 80 size_t ilen )
Christopher Haster 1:24750b9ad5ef 81 {
Christopher Haster 1:24750b9ad5ef 82 mbedtls_md2_update( (mbedtls_md2_context *) ctx, input, ilen );
Christopher Haster 1:24750b9ad5ef 83 }
Christopher Haster 1:24750b9ad5ef 84
Christopher Haster 1:24750b9ad5ef 85 static void md2_finish_wrap( void *ctx, unsigned char *output )
Christopher Haster 1:24750b9ad5ef 86 {
Christopher Haster 1:24750b9ad5ef 87 mbedtls_md2_finish( (mbedtls_md2_context *) ctx, output );
Christopher Haster 1:24750b9ad5ef 88 }
Christopher Haster 1:24750b9ad5ef 89
Christopher Haster 1:24750b9ad5ef 90 static void *md2_ctx_alloc( void )
Christopher Haster 1:24750b9ad5ef 91 {
Christopher Haster 1:24750b9ad5ef 92 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md2_context ) );
Christopher Haster 1:24750b9ad5ef 93
Christopher Haster 1:24750b9ad5ef 94 if( ctx != NULL )
Christopher Haster 1:24750b9ad5ef 95 mbedtls_md2_init( (mbedtls_md2_context *) ctx );
Christopher Haster 1:24750b9ad5ef 96
Christopher Haster 1:24750b9ad5ef 97 return( ctx );
Christopher Haster 1:24750b9ad5ef 98 }
Christopher Haster 1:24750b9ad5ef 99
Christopher Haster 1:24750b9ad5ef 100 static void md2_ctx_free( void *ctx )
Christopher Haster 1:24750b9ad5ef 101 {
Christopher Haster 1:24750b9ad5ef 102 mbedtls_md2_free( (mbedtls_md2_context *) ctx );
Christopher Haster 1:24750b9ad5ef 103 mbedtls_free( ctx );
Christopher Haster 1:24750b9ad5ef 104 }
Christopher Haster 1:24750b9ad5ef 105
Christopher Haster 1:24750b9ad5ef 106 static void md2_clone_wrap( void *dst, const void *src )
Christopher Haster 1:24750b9ad5ef 107 {
Christopher Haster 1:24750b9ad5ef 108 mbedtls_md2_clone( (mbedtls_md2_context *) dst,
Christopher Haster 1:24750b9ad5ef 109 (const mbedtls_md2_context *) src );
Christopher Haster 1:24750b9ad5ef 110 }
Christopher Haster 1:24750b9ad5ef 111
Christopher Haster 1:24750b9ad5ef 112 static void md2_process_wrap( void *ctx, const unsigned char *data )
Christopher Haster 1:24750b9ad5ef 113 {
Christopher Haster 1:24750b9ad5ef 114 ((void) data);
Christopher Haster 1:24750b9ad5ef 115
Christopher Haster 1:24750b9ad5ef 116 mbedtls_md2_process( (mbedtls_md2_context *) ctx );
Christopher Haster 1:24750b9ad5ef 117 }
Christopher Haster 1:24750b9ad5ef 118
Christopher Haster 1:24750b9ad5ef 119 const mbedtls_md_info_t mbedtls_md2_info = {
Christopher Haster 1:24750b9ad5ef 120 MBEDTLS_MD_MD2,
Christopher Haster 1:24750b9ad5ef 121 "MD2",
Christopher Haster 1:24750b9ad5ef 122 16,
Christopher Haster 1:24750b9ad5ef 123 16,
Christopher Haster 1:24750b9ad5ef 124 md2_starts_wrap,
Christopher Haster 1:24750b9ad5ef 125 md2_update_wrap,
Christopher Haster 1:24750b9ad5ef 126 md2_finish_wrap,
Christopher Haster 1:24750b9ad5ef 127 mbedtls_md2,
Christopher Haster 1:24750b9ad5ef 128 md2_ctx_alloc,
Christopher Haster 1:24750b9ad5ef 129 md2_ctx_free,
Christopher Haster 1:24750b9ad5ef 130 md2_clone_wrap,
Christopher Haster 1:24750b9ad5ef 131 md2_process_wrap,
Christopher Haster 1:24750b9ad5ef 132 };
Christopher Haster 1:24750b9ad5ef 133
Christopher Haster 1:24750b9ad5ef 134 #endif /* MBEDTLS_MD2_C */
Christopher Haster 1:24750b9ad5ef 135
Christopher Haster 1:24750b9ad5ef 136 #if defined(MBEDTLS_MD4_C)
Christopher Haster 1:24750b9ad5ef 137
Christopher Haster 1:24750b9ad5ef 138 static void md4_starts_wrap( void *ctx )
Christopher Haster 1:24750b9ad5ef 139 {
Christopher Haster 1:24750b9ad5ef 140 mbedtls_md4_starts( (mbedtls_md4_context *) ctx );
Christopher Haster 1:24750b9ad5ef 141 }
Christopher Haster 1:24750b9ad5ef 142
Christopher Haster 1:24750b9ad5ef 143 static void md4_update_wrap( void *ctx, const unsigned char *input,
Christopher Haster 1:24750b9ad5ef 144 size_t ilen )
Christopher Haster 1:24750b9ad5ef 145 {
Christopher Haster 1:24750b9ad5ef 146 mbedtls_md4_update( (mbedtls_md4_context *) ctx, input, ilen );
Christopher Haster 1:24750b9ad5ef 147 }
Christopher Haster 1:24750b9ad5ef 148
Christopher Haster 1:24750b9ad5ef 149 static void md4_finish_wrap( void *ctx, unsigned char *output )
Christopher Haster 1:24750b9ad5ef 150 {
Christopher Haster 1:24750b9ad5ef 151 mbedtls_md4_finish( (mbedtls_md4_context *) ctx, output );
Christopher Haster 1:24750b9ad5ef 152 }
Christopher Haster 1:24750b9ad5ef 153
Christopher Haster 1:24750b9ad5ef 154 static void *md4_ctx_alloc( void )
Christopher Haster 1:24750b9ad5ef 155 {
Christopher Haster 1:24750b9ad5ef 156 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md4_context ) );
Christopher Haster 1:24750b9ad5ef 157
Christopher Haster 1:24750b9ad5ef 158 if( ctx != NULL )
Christopher Haster 1:24750b9ad5ef 159 mbedtls_md4_init( (mbedtls_md4_context *) ctx );
Christopher Haster 1:24750b9ad5ef 160
Christopher Haster 1:24750b9ad5ef 161 return( ctx );
Christopher Haster 1:24750b9ad5ef 162 }
Christopher Haster 1:24750b9ad5ef 163
Christopher Haster 1:24750b9ad5ef 164 static void md4_ctx_free( void *ctx )
Christopher Haster 1:24750b9ad5ef 165 {
Christopher Haster 1:24750b9ad5ef 166 mbedtls_md4_free( (mbedtls_md4_context *) ctx );
Christopher Haster 1:24750b9ad5ef 167 mbedtls_free( ctx );
Christopher Haster 1:24750b9ad5ef 168 }
Christopher Haster 1:24750b9ad5ef 169
Christopher Haster 1:24750b9ad5ef 170 static void md4_clone_wrap( void *dst, const void *src )
Christopher Haster 1:24750b9ad5ef 171 {
Christopher Haster 1:24750b9ad5ef 172 mbedtls_md4_clone( (mbedtls_md4_context *) dst,
Christopher Haster 1:24750b9ad5ef 173 (const mbedtls_md4_context *) src );
Christopher Haster 1:24750b9ad5ef 174 }
Christopher Haster 1:24750b9ad5ef 175
Christopher Haster 1:24750b9ad5ef 176 static void md4_process_wrap( void *ctx, const unsigned char *data )
Christopher Haster 1:24750b9ad5ef 177 {
Christopher Haster 1:24750b9ad5ef 178 mbedtls_md4_process( (mbedtls_md4_context *) ctx, data );
Christopher Haster 1:24750b9ad5ef 179 }
Christopher Haster 1:24750b9ad5ef 180
Christopher Haster 1:24750b9ad5ef 181 const mbedtls_md_info_t mbedtls_md4_info = {
Christopher Haster 1:24750b9ad5ef 182 MBEDTLS_MD_MD4,
Christopher Haster 1:24750b9ad5ef 183 "MD4",
Christopher Haster 1:24750b9ad5ef 184 16,
Christopher Haster 1:24750b9ad5ef 185 64,
Christopher Haster 1:24750b9ad5ef 186 md4_starts_wrap,
Christopher Haster 1:24750b9ad5ef 187 md4_update_wrap,
Christopher Haster 1:24750b9ad5ef 188 md4_finish_wrap,
Christopher Haster 1:24750b9ad5ef 189 mbedtls_md4,
Christopher Haster 1:24750b9ad5ef 190 md4_ctx_alloc,
Christopher Haster 1:24750b9ad5ef 191 md4_ctx_free,
Christopher Haster 1:24750b9ad5ef 192 md4_clone_wrap,
Christopher Haster 1:24750b9ad5ef 193 md4_process_wrap,
Christopher Haster 1:24750b9ad5ef 194 };
Christopher Haster 1:24750b9ad5ef 195
Christopher Haster 1:24750b9ad5ef 196 #endif /* MBEDTLS_MD4_C */
Christopher Haster 1:24750b9ad5ef 197
Christopher Haster 1:24750b9ad5ef 198 #if defined(MBEDTLS_MD5_C)
Christopher Haster 1:24750b9ad5ef 199
Christopher Haster 1:24750b9ad5ef 200 static void md5_starts_wrap( void *ctx )
Christopher Haster 1:24750b9ad5ef 201 {
Christopher Haster 1:24750b9ad5ef 202 mbedtls_md5_starts( (mbedtls_md5_context *) ctx );
Christopher Haster 1:24750b9ad5ef 203 }
Christopher Haster 1:24750b9ad5ef 204
Christopher Haster 1:24750b9ad5ef 205 static void md5_update_wrap( void *ctx, const unsigned char *input,
Christopher Haster 1:24750b9ad5ef 206 size_t ilen )
Christopher Haster 1:24750b9ad5ef 207 {
Christopher Haster 1:24750b9ad5ef 208 mbedtls_md5_update( (mbedtls_md5_context *) ctx, input, ilen );
Christopher Haster 1:24750b9ad5ef 209 }
Christopher Haster 1:24750b9ad5ef 210
Christopher Haster 1:24750b9ad5ef 211 static void md5_finish_wrap( void *ctx, unsigned char *output )
Christopher Haster 1:24750b9ad5ef 212 {
Christopher Haster 1:24750b9ad5ef 213 mbedtls_md5_finish( (mbedtls_md5_context *) ctx, output );
Christopher Haster 1:24750b9ad5ef 214 }
Christopher Haster 1:24750b9ad5ef 215
Christopher Haster 1:24750b9ad5ef 216 static void *md5_ctx_alloc( void )
Christopher Haster 1:24750b9ad5ef 217 {
Christopher Haster 1:24750b9ad5ef 218 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md5_context ) );
Christopher Haster 1:24750b9ad5ef 219
Christopher Haster 1:24750b9ad5ef 220 if( ctx != NULL )
Christopher Haster 1:24750b9ad5ef 221 mbedtls_md5_init( (mbedtls_md5_context *) ctx );
Christopher Haster 1:24750b9ad5ef 222
Christopher Haster 1:24750b9ad5ef 223 return( ctx );
Christopher Haster 1:24750b9ad5ef 224 }
Christopher Haster 1:24750b9ad5ef 225
Christopher Haster 1:24750b9ad5ef 226 static void md5_ctx_free( void *ctx )
Christopher Haster 1:24750b9ad5ef 227 {
Christopher Haster 1:24750b9ad5ef 228 mbedtls_md5_free( (mbedtls_md5_context *) ctx );
Christopher Haster 1:24750b9ad5ef 229 mbedtls_free( ctx );
Christopher Haster 1:24750b9ad5ef 230 }
Christopher Haster 1:24750b9ad5ef 231
Christopher Haster 1:24750b9ad5ef 232 static void md5_clone_wrap( void *dst, const void *src )
Christopher Haster 1:24750b9ad5ef 233 {
Christopher Haster 1:24750b9ad5ef 234 mbedtls_md5_clone( (mbedtls_md5_context *) dst,
Christopher Haster 1:24750b9ad5ef 235 (const mbedtls_md5_context *) src );
Christopher Haster 1:24750b9ad5ef 236 }
Christopher Haster 1:24750b9ad5ef 237
Christopher Haster 1:24750b9ad5ef 238 static void md5_process_wrap( void *ctx, const unsigned char *data )
Christopher Haster 1:24750b9ad5ef 239 {
Christopher Haster 1:24750b9ad5ef 240 mbedtls_md5_process( (mbedtls_md5_context *) ctx, data );
Christopher Haster 1:24750b9ad5ef 241 }
Christopher Haster 1:24750b9ad5ef 242
Christopher Haster 1:24750b9ad5ef 243 const mbedtls_md_info_t mbedtls_md5_info = {
Christopher Haster 1:24750b9ad5ef 244 MBEDTLS_MD_MD5,
Christopher Haster 1:24750b9ad5ef 245 "MD5",
Christopher Haster 1:24750b9ad5ef 246 16,
Christopher Haster 1:24750b9ad5ef 247 64,
Christopher Haster 1:24750b9ad5ef 248 md5_starts_wrap,
Christopher Haster 1:24750b9ad5ef 249 md5_update_wrap,
Christopher Haster 1:24750b9ad5ef 250 md5_finish_wrap,
Christopher Haster 1:24750b9ad5ef 251 mbedtls_md5,
Christopher Haster 1:24750b9ad5ef 252 md5_ctx_alloc,
Christopher Haster 1:24750b9ad5ef 253 md5_ctx_free,
Christopher Haster 1:24750b9ad5ef 254 md5_clone_wrap,
Christopher Haster 1:24750b9ad5ef 255 md5_process_wrap,
Christopher Haster 1:24750b9ad5ef 256 };
Christopher Haster 1:24750b9ad5ef 257
Christopher Haster 1:24750b9ad5ef 258 #endif /* MBEDTLS_MD5_C */
Christopher Haster 1:24750b9ad5ef 259
Christopher Haster 1:24750b9ad5ef 260 #if defined(MBEDTLS_RIPEMD160_C)
Christopher Haster 1:24750b9ad5ef 261
Christopher Haster 1:24750b9ad5ef 262 static void ripemd160_starts_wrap( void *ctx )
Christopher Haster 1:24750b9ad5ef 263 {
Christopher Haster 1:24750b9ad5ef 264 mbedtls_ripemd160_starts( (mbedtls_ripemd160_context *) ctx );
Christopher Haster 1:24750b9ad5ef 265 }
Christopher Haster 1:24750b9ad5ef 266
Christopher Haster 1:24750b9ad5ef 267 static void ripemd160_update_wrap( void *ctx, const unsigned char *input,
Christopher Haster 1:24750b9ad5ef 268 size_t ilen )
Christopher Haster 1:24750b9ad5ef 269 {
Christopher Haster 1:24750b9ad5ef 270 mbedtls_ripemd160_update( (mbedtls_ripemd160_context *) ctx, input, ilen );
Christopher Haster 1:24750b9ad5ef 271 }
Christopher Haster 1:24750b9ad5ef 272
Christopher Haster 1:24750b9ad5ef 273 static void ripemd160_finish_wrap( void *ctx, unsigned char *output )
Christopher Haster 1:24750b9ad5ef 274 {
Christopher Haster 1:24750b9ad5ef 275 mbedtls_ripemd160_finish( (mbedtls_ripemd160_context *) ctx, output );
Christopher Haster 1:24750b9ad5ef 276 }
Christopher Haster 1:24750b9ad5ef 277
Christopher Haster 1:24750b9ad5ef 278 static void *ripemd160_ctx_alloc( void )
Christopher Haster 1:24750b9ad5ef 279 {
Christopher Haster 1:24750b9ad5ef 280 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ripemd160_context ) );
Christopher Haster 1:24750b9ad5ef 281
Christopher Haster 1:24750b9ad5ef 282 if( ctx != NULL )
Christopher Haster 1:24750b9ad5ef 283 mbedtls_ripemd160_init( (mbedtls_ripemd160_context *) ctx );
Christopher Haster 1:24750b9ad5ef 284
Christopher Haster 1:24750b9ad5ef 285 return( ctx );
Christopher Haster 1:24750b9ad5ef 286 }
Christopher Haster 1:24750b9ad5ef 287
Christopher Haster 1:24750b9ad5ef 288 static void ripemd160_ctx_free( void *ctx )
Christopher Haster 1:24750b9ad5ef 289 {
Christopher Haster 1:24750b9ad5ef 290 mbedtls_ripemd160_free( (mbedtls_ripemd160_context *) ctx );
Christopher Haster 1:24750b9ad5ef 291 mbedtls_free( ctx );
Christopher Haster 1:24750b9ad5ef 292 }
Christopher Haster 1:24750b9ad5ef 293
Christopher Haster 1:24750b9ad5ef 294 static void ripemd160_clone_wrap( void *dst, const void *src )
Christopher Haster 1:24750b9ad5ef 295 {
Christopher Haster 1:24750b9ad5ef 296 mbedtls_ripemd160_clone( (mbedtls_ripemd160_context *) dst,
Christopher Haster 1:24750b9ad5ef 297 (const mbedtls_ripemd160_context *) src );
Christopher Haster 1:24750b9ad5ef 298 }
Christopher Haster 1:24750b9ad5ef 299
Christopher Haster 1:24750b9ad5ef 300 static void ripemd160_process_wrap( void *ctx, const unsigned char *data )
Christopher Haster 1:24750b9ad5ef 301 {
Christopher Haster 1:24750b9ad5ef 302 mbedtls_ripemd160_process( (mbedtls_ripemd160_context *) ctx, data );
Christopher Haster 1:24750b9ad5ef 303 }
Christopher Haster 1:24750b9ad5ef 304
Christopher Haster 1:24750b9ad5ef 305 const mbedtls_md_info_t mbedtls_ripemd160_info = {
Christopher Haster 1:24750b9ad5ef 306 MBEDTLS_MD_RIPEMD160,
Christopher Haster 1:24750b9ad5ef 307 "RIPEMD160",
Christopher Haster 1:24750b9ad5ef 308 20,
Christopher Haster 1:24750b9ad5ef 309 64,
Christopher Haster 1:24750b9ad5ef 310 ripemd160_starts_wrap,
Christopher Haster 1:24750b9ad5ef 311 ripemd160_update_wrap,
Christopher Haster 1:24750b9ad5ef 312 ripemd160_finish_wrap,
Christopher Haster 1:24750b9ad5ef 313 mbedtls_ripemd160,
Christopher Haster 1:24750b9ad5ef 314 ripemd160_ctx_alloc,
Christopher Haster 1:24750b9ad5ef 315 ripemd160_ctx_free,
Christopher Haster 1:24750b9ad5ef 316 ripemd160_clone_wrap,
Christopher Haster 1:24750b9ad5ef 317 ripemd160_process_wrap,
Christopher Haster 1:24750b9ad5ef 318 };
Christopher Haster 1:24750b9ad5ef 319
Christopher Haster 1:24750b9ad5ef 320 #endif /* MBEDTLS_RIPEMD160_C */
Christopher Haster 1:24750b9ad5ef 321
Christopher Haster 1:24750b9ad5ef 322 #if defined(MBEDTLS_SHA1_C)
Christopher Haster 1:24750b9ad5ef 323
Christopher Haster 1:24750b9ad5ef 324 static void sha1_starts_wrap( void *ctx )
Christopher Haster 1:24750b9ad5ef 325 {
Christopher Haster 1:24750b9ad5ef 326 mbedtls_sha1_starts( (mbedtls_sha1_context *) ctx );
Christopher Haster 1:24750b9ad5ef 327 }
Christopher Haster 1:24750b9ad5ef 328
Christopher Haster 1:24750b9ad5ef 329 static void sha1_update_wrap( void *ctx, const unsigned char *input,
Christopher Haster 1:24750b9ad5ef 330 size_t ilen )
Christopher Haster 1:24750b9ad5ef 331 {
Christopher Haster 1:24750b9ad5ef 332 mbedtls_sha1_update( (mbedtls_sha1_context *) ctx, input, ilen );
Christopher Haster 1:24750b9ad5ef 333 }
Christopher Haster 1:24750b9ad5ef 334
Christopher Haster 1:24750b9ad5ef 335 static void sha1_finish_wrap( void *ctx, unsigned char *output )
Christopher Haster 1:24750b9ad5ef 336 {
Christopher Haster 1:24750b9ad5ef 337 mbedtls_sha1_finish( (mbedtls_sha1_context *) ctx, output );
Christopher Haster 1:24750b9ad5ef 338 }
Christopher Haster 1:24750b9ad5ef 339
Christopher Haster 1:24750b9ad5ef 340 static void *sha1_ctx_alloc( void )
Christopher Haster 1:24750b9ad5ef 341 {
Christopher Haster 1:24750b9ad5ef 342 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha1_context ) );
Christopher Haster 1:24750b9ad5ef 343
Christopher Haster 1:24750b9ad5ef 344 if( ctx != NULL )
Christopher Haster 1:24750b9ad5ef 345 mbedtls_sha1_init( (mbedtls_sha1_context *) ctx );
Christopher Haster 1:24750b9ad5ef 346
Christopher Haster 1:24750b9ad5ef 347 return( ctx );
Christopher Haster 1:24750b9ad5ef 348 }
Christopher Haster 1:24750b9ad5ef 349
Christopher Haster 1:24750b9ad5ef 350 static void sha1_clone_wrap( void *dst, const void *src )
Christopher Haster 1:24750b9ad5ef 351 {
Christopher Haster 1:24750b9ad5ef 352 mbedtls_sha1_clone( (mbedtls_sha1_context *) dst,
Christopher Haster 1:24750b9ad5ef 353 (const mbedtls_sha1_context *) src );
Christopher Haster 1:24750b9ad5ef 354 }
Christopher Haster 1:24750b9ad5ef 355
Christopher Haster 1:24750b9ad5ef 356 static void sha1_ctx_free( void *ctx )
Christopher Haster 1:24750b9ad5ef 357 {
Christopher Haster 1:24750b9ad5ef 358 mbedtls_sha1_free( (mbedtls_sha1_context *) ctx );
Christopher Haster 1:24750b9ad5ef 359 mbedtls_free( ctx );
Christopher Haster 1:24750b9ad5ef 360 }
Christopher Haster 1:24750b9ad5ef 361
Christopher Haster 1:24750b9ad5ef 362 static void sha1_process_wrap( void *ctx, const unsigned char *data )
Christopher Haster 1:24750b9ad5ef 363 {
Christopher Haster 1:24750b9ad5ef 364 mbedtls_sha1_process( (mbedtls_sha1_context *) ctx, data );
Christopher Haster 1:24750b9ad5ef 365 }
Christopher Haster 1:24750b9ad5ef 366
Christopher Haster 1:24750b9ad5ef 367 const mbedtls_md_info_t mbedtls_sha1_info = {
Christopher Haster 1:24750b9ad5ef 368 MBEDTLS_MD_SHA1,
Christopher Haster 1:24750b9ad5ef 369 "SHA1",
Christopher Haster 1:24750b9ad5ef 370 20,
Christopher Haster 1:24750b9ad5ef 371 64,
Christopher Haster 1:24750b9ad5ef 372 sha1_starts_wrap,
Christopher Haster 1:24750b9ad5ef 373 sha1_update_wrap,
Christopher Haster 1:24750b9ad5ef 374 sha1_finish_wrap,
Christopher Haster 1:24750b9ad5ef 375 mbedtls_sha1,
Christopher Haster 1:24750b9ad5ef 376 sha1_ctx_alloc,
Christopher Haster 1:24750b9ad5ef 377 sha1_ctx_free,
Christopher Haster 1:24750b9ad5ef 378 sha1_clone_wrap,
Christopher Haster 1:24750b9ad5ef 379 sha1_process_wrap,
Christopher Haster 1:24750b9ad5ef 380 };
Christopher Haster 1:24750b9ad5ef 381
Christopher Haster 1:24750b9ad5ef 382 #endif /* MBEDTLS_SHA1_C */
Christopher Haster 1:24750b9ad5ef 383
Christopher Haster 1:24750b9ad5ef 384 /*
Christopher Haster 1:24750b9ad5ef 385 * Wrappers for generic message digests
Christopher Haster 1:24750b9ad5ef 386 */
Christopher Haster 1:24750b9ad5ef 387 #if defined(MBEDTLS_SHA256_C)
Christopher Haster 1:24750b9ad5ef 388
Christopher Haster 1:24750b9ad5ef 389 static void sha224_starts_wrap( void *ctx )
Christopher Haster 1:24750b9ad5ef 390 {
Christopher Haster 1:24750b9ad5ef 391 mbedtls_sha256_starts( (mbedtls_sha256_context *) ctx, 1 );
Christopher Haster 1:24750b9ad5ef 392 }
Christopher Haster 1:24750b9ad5ef 393
Christopher Haster 1:24750b9ad5ef 394 static void sha224_update_wrap( void *ctx, const unsigned char *input,
Christopher Haster 1:24750b9ad5ef 395 size_t ilen )
Christopher Haster 1:24750b9ad5ef 396 {
Christopher Haster 1:24750b9ad5ef 397 mbedtls_sha256_update( (mbedtls_sha256_context *) ctx, input, ilen );
Christopher Haster 1:24750b9ad5ef 398 }
Christopher Haster 1:24750b9ad5ef 399
Christopher Haster 1:24750b9ad5ef 400 static void sha224_finish_wrap( void *ctx, unsigned char *output )
Christopher Haster 1:24750b9ad5ef 401 {
Christopher Haster 1:24750b9ad5ef 402 mbedtls_sha256_finish( (mbedtls_sha256_context *) ctx, output );
Christopher Haster 1:24750b9ad5ef 403 }
Christopher Haster 1:24750b9ad5ef 404
Christopher Haster 1:24750b9ad5ef 405 static void sha224_wrap( const unsigned char *input, size_t ilen,
Christopher Haster 1:24750b9ad5ef 406 unsigned char *output )
Christopher Haster 1:24750b9ad5ef 407 {
Christopher Haster 1:24750b9ad5ef 408 mbedtls_sha256( input, ilen, output, 1 );
Christopher Haster 1:24750b9ad5ef 409 }
Christopher Haster 1:24750b9ad5ef 410
Christopher Haster 1:24750b9ad5ef 411 static void *sha224_ctx_alloc( void )
Christopher Haster 1:24750b9ad5ef 412 {
Christopher Haster 1:24750b9ad5ef 413 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha256_context ) );
Christopher Haster 1:24750b9ad5ef 414
Christopher Haster 1:24750b9ad5ef 415 if( ctx != NULL )
Christopher Haster 1:24750b9ad5ef 416 mbedtls_sha256_init( (mbedtls_sha256_context *) ctx );
Christopher Haster 1:24750b9ad5ef 417
Christopher Haster 1:24750b9ad5ef 418 return( ctx );
Christopher Haster 1:24750b9ad5ef 419 }
Christopher Haster 1:24750b9ad5ef 420
Christopher Haster 1:24750b9ad5ef 421 static void sha224_ctx_free( void *ctx )
Christopher Haster 1:24750b9ad5ef 422 {
Christopher Haster 1:24750b9ad5ef 423 mbedtls_sha256_free( (mbedtls_sha256_context *) ctx );
Christopher Haster 1:24750b9ad5ef 424 mbedtls_free( ctx );
Christopher Haster 1:24750b9ad5ef 425 }
Christopher Haster 1:24750b9ad5ef 426
Christopher Haster 1:24750b9ad5ef 427 static void sha224_clone_wrap( void *dst, const void *src )
Christopher Haster 1:24750b9ad5ef 428 {
Christopher Haster 1:24750b9ad5ef 429 mbedtls_sha256_clone( (mbedtls_sha256_context *) dst,
Christopher Haster 1:24750b9ad5ef 430 (const mbedtls_sha256_context *) src );
Christopher Haster 1:24750b9ad5ef 431 }
Christopher Haster 1:24750b9ad5ef 432
Christopher Haster 1:24750b9ad5ef 433 static void sha224_process_wrap( void *ctx, const unsigned char *data )
Christopher Haster 1:24750b9ad5ef 434 {
Christopher Haster 1:24750b9ad5ef 435 mbedtls_sha256_process( (mbedtls_sha256_context *) ctx, data );
Christopher Haster 1:24750b9ad5ef 436 }
Christopher Haster 1:24750b9ad5ef 437
Christopher Haster 1:24750b9ad5ef 438 const mbedtls_md_info_t mbedtls_sha224_info = {
Christopher Haster 1:24750b9ad5ef 439 MBEDTLS_MD_SHA224,
Christopher Haster 1:24750b9ad5ef 440 "SHA224",
Christopher Haster 1:24750b9ad5ef 441 28,
Christopher Haster 1:24750b9ad5ef 442 64,
Christopher Haster 1:24750b9ad5ef 443 sha224_starts_wrap,
Christopher Haster 1:24750b9ad5ef 444 sha224_update_wrap,
Christopher Haster 1:24750b9ad5ef 445 sha224_finish_wrap,
Christopher Haster 1:24750b9ad5ef 446 sha224_wrap,
Christopher Haster 1:24750b9ad5ef 447 sha224_ctx_alloc,
Christopher Haster 1:24750b9ad5ef 448 sha224_ctx_free,
Christopher Haster 1:24750b9ad5ef 449 sha224_clone_wrap,
Christopher Haster 1:24750b9ad5ef 450 sha224_process_wrap,
Christopher Haster 1:24750b9ad5ef 451 };
Christopher Haster 1:24750b9ad5ef 452
Christopher Haster 1:24750b9ad5ef 453 static void sha256_starts_wrap( void *ctx )
Christopher Haster 1:24750b9ad5ef 454 {
Christopher Haster 1:24750b9ad5ef 455 mbedtls_sha256_starts( (mbedtls_sha256_context *) ctx, 0 );
Christopher Haster 1:24750b9ad5ef 456 }
Christopher Haster 1:24750b9ad5ef 457
Christopher Haster 1:24750b9ad5ef 458 static void sha256_wrap( const unsigned char *input, size_t ilen,
Christopher Haster 1:24750b9ad5ef 459 unsigned char *output )
Christopher Haster 1:24750b9ad5ef 460 {
Christopher Haster 1:24750b9ad5ef 461 mbedtls_sha256( input, ilen, output, 0 );
Christopher Haster 1:24750b9ad5ef 462 }
Christopher Haster 1:24750b9ad5ef 463
Christopher Haster 1:24750b9ad5ef 464 const mbedtls_md_info_t mbedtls_sha256_info = {
Christopher Haster 1:24750b9ad5ef 465 MBEDTLS_MD_SHA256,
Christopher Haster 1:24750b9ad5ef 466 "SHA256",
Christopher Haster 1:24750b9ad5ef 467 32,
Christopher Haster 1:24750b9ad5ef 468 64,
Christopher Haster 1:24750b9ad5ef 469 sha256_starts_wrap,
Christopher Haster 1:24750b9ad5ef 470 sha224_update_wrap,
Christopher Haster 1:24750b9ad5ef 471 sha224_finish_wrap,
Christopher Haster 1:24750b9ad5ef 472 sha256_wrap,
Christopher Haster 1:24750b9ad5ef 473 sha224_ctx_alloc,
Christopher Haster 1:24750b9ad5ef 474 sha224_ctx_free,
Christopher Haster 1:24750b9ad5ef 475 sha224_clone_wrap,
Christopher Haster 1:24750b9ad5ef 476 sha224_process_wrap,
Christopher Haster 1:24750b9ad5ef 477 };
Christopher Haster 1:24750b9ad5ef 478
Christopher Haster 1:24750b9ad5ef 479 #endif /* MBEDTLS_SHA256_C */
Christopher Haster 1:24750b9ad5ef 480
Christopher Haster 1:24750b9ad5ef 481 #if defined(MBEDTLS_SHA512_C)
Christopher Haster 1:24750b9ad5ef 482
Christopher Haster 1:24750b9ad5ef 483 static void sha384_starts_wrap( void *ctx )
Christopher Haster 1:24750b9ad5ef 484 {
Christopher Haster 1:24750b9ad5ef 485 mbedtls_sha512_starts( (mbedtls_sha512_context *) ctx, 1 );
Christopher Haster 1:24750b9ad5ef 486 }
Christopher Haster 1:24750b9ad5ef 487
Christopher Haster 1:24750b9ad5ef 488 static void sha384_update_wrap( void *ctx, const unsigned char *input,
Christopher Haster 1:24750b9ad5ef 489 size_t ilen )
Christopher Haster 1:24750b9ad5ef 490 {
Christopher Haster 1:24750b9ad5ef 491 mbedtls_sha512_update( (mbedtls_sha512_context *) ctx, input, ilen );
Christopher Haster 1:24750b9ad5ef 492 }
Christopher Haster 1:24750b9ad5ef 493
Christopher Haster 1:24750b9ad5ef 494 static void sha384_finish_wrap( void *ctx, unsigned char *output )
Christopher Haster 1:24750b9ad5ef 495 {
Christopher Haster 1:24750b9ad5ef 496 mbedtls_sha512_finish( (mbedtls_sha512_context *) ctx, output );
Christopher Haster 1:24750b9ad5ef 497 }
Christopher Haster 1:24750b9ad5ef 498
Christopher Haster 1:24750b9ad5ef 499 static void sha384_wrap( const unsigned char *input, size_t ilen,
Christopher Haster 1:24750b9ad5ef 500 unsigned char *output )
Christopher Haster 1:24750b9ad5ef 501 {
Christopher Haster 1:24750b9ad5ef 502 mbedtls_sha512( input, ilen, output, 1 );
Christopher Haster 1:24750b9ad5ef 503 }
Christopher Haster 1:24750b9ad5ef 504
Christopher Haster 1:24750b9ad5ef 505 static void *sha384_ctx_alloc( void )
Christopher Haster 1:24750b9ad5ef 506 {
Christopher Haster 1:24750b9ad5ef 507 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha512_context ) );
Christopher Haster 1:24750b9ad5ef 508
Christopher Haster 1:24750b9ad5ef 509 if( ctx != NULL )
Christopher Haster 1:24750b9ad5ef 510 mbedtls_sha512_init( (mbedtls_sha512_context *) ctx );
Christopher Haster 1:24750b9ad5ef 511
Christopher Haster 1:24750b9ad5ef 512 return( ctx );
Christopher Haster 1:24750b9ad5ef 513 }
Christopher Haster 1:24750b9ad5ef 514
Christopher Haster 1:24750b9ad5ef 515 static void sha384_ctx_free( void *ctx )
Christopher Haster 1:24750b9ad5ef 516 {
Christopher Haster 1:24750b9ad5ef 517 mbedtls_sha512_free( (mbedtls_sha512_context *) ctx );
Christopher Haster 1:24750b9ad5ef 518 mbedtls_free( ctx );
Christopher Haster 1:24750b9ad5ef 519 }
Christopher Haster 1:24750b9ad5ef 520
Christopher Haster 1:24750b9ad5ef 521 static void sha384_clone_wrap( void *dst, const void *src )
Christopher Haster 1:24750b9ad5ef 522 {
Christopher Haster 1:24750b9ad5ef 523 mbedtls_sha512_clone( (mbedtls_sha512_context *) dst,
Christopher Haster 1:24750b9ad5ef 524 (const mbedtls_sha512_context *) src );
Christopher Haster 1:24750b9ad5ef 525 }
Christopher Haster 1:24750b9ad5ef 526
Christopher Haster 1:24750b9ad5ef 527 static void sha384_process_wrap( void *ctx, const unsigned char *data )
Christopher Haster 1:24750b9ad5ef 528 {
Christopher Haster 1:24750b9ad5ef 529 mbedtls_sha512_process( (mbedtls_sha512_context *) ctx, data );
Christopher Haster 1:24750b9ad5ef 530 }
Christopher Haster 1:24750b9ad5ef 531
Christopher Haster 1:24750b9ad5ef 532 const mbedtls_md_info_t mbedtls_sha384_info = {
Christopher Haster 1:24750b9ad5ef 533 MBEDTLS_MD_SHA384,
Christopher Haster 1:24750b9ad5ef 534 "SHA384",
Christopher Haster 1:24750b9ad5ef 535 48,
Christopher Haster 1:24750b9ad5ef 536 128,
Christopher Haster 1:24750b9ad5ef 537 sha384_starts_wrap,
Christopher Haster 1:24750b9ad5ef 538 sha384_update_wrap,
Christopher Haster 1:24750b9ad5ef 539 sha384_finish_wrap,
Christopher Haster 1:24750b9ad5ef 540 sha384_wrap,
Christopher Haster 1:24750b9ad5ef 541 sha384_ctx_alloc,
Christopher Haster 1:24750b9ad5ef 542 sha384_ctx_free,
Christopher Haster 1:24750b9ad5ef 543 sha384_clone_wrap,
Christopher Haster 1:24750b9ad5ef 544 sha384_process_wrap,
Christopher Haster 1:24750b9ad5ef 545 };
Christopher Haster 1:24750b9ad5ef 546
Christopher Haster 1:24750b9ad5ef 547 static void sha512_starts_wrap( void *ctx )
Christopher Haster 1:24750b9ad5ef 548 {
Christopher Haster 1:24750b9ad5ef 549 mbedtls_sha512_starts( (mbedtls_sha512_context *) ctx, 0 );
Christopher Haster 1:24750b9ad5ef 550 }
Christopher Haster 1:24750b9ad5ef 551
Christopher Haster 1:24750b9ad5ef 552 static void sha512_wrap( const unsigned char *input, size_t ilen,
Christopher Haster 1:24750b9ad5ef 553 unsigned char *output )
Christopher Haster 1:24750b9ad5ef 554 {
Christopher Haster 1:24750b9ad5ef 555 mbedtls_sha512( input, ilen, output, 0 );
Christopher Haster 1:24750b9ad5ef 556 }
Christopher Haster 1:24750b9ad5ef 557
Christopher Haster 1:24750b9ad5ef 558 const mbedtls_md_info_t mbedtls_sha512_info = {
Christopher Haster 1:24750b9ad5ef 559 MBEDTLS_MD_SHA512,
Christopher Haster 1:24750b9ad5ef 560 "SHA512",
Christopher Haster 1:24750b9ad5ef 561 64,
Christopher Haster 1:24750b9ad5ef 562 128,
Christopher Haster 1:24750b9ad5ef 563 sha512_starts_wrap,
Christopher Haster 1:24750b9ad5ef 564 sha384_update_wrap,
Christopher Haster 1:24750b9ad5ef 565 sha384_finish_wrap,
Christopher Haster 1:24750b9ad5ef 566 sha512_wrap,
Christopher Haster 1:24750b9ad5ef 567 sha384_ctx_alloc,
Christopher Haster 1:24750b9ad5ef 568 sha384_ctx_free,
Christopher Haster 1:24750b9ad5ef 569 sha384_clone_wrap,
Christopher Haster 1:24750b9ad5ef 570 sha384_process_wrap,
Christopher Haster 1:24750b9ad5ef 571 };
Christopher Haster 1:24750b9ad5ef 572
Christopher Haster 1:24750b9ad5ef 573 #endif /* MBEDTLS_SHA512_C */
Christopher Haster 1:24750b9ad5ef 574
Christopher Haster 1:24750b9ad5ef 575 #endif /* MBEDTLS_MD_C */