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