Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

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