This is a fork due to permission issues

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of 6_songs-from-the-cloud by MakingMusicWorkshop

Committer:
maclobdell
Date:
Wed May 18 19:06:32 2016 +0000
Revision:
0:f7c60d3e7b8a
clean version

Who changed what in which revision?

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