Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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