Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file md_wrap.c |
| 3 | |
| 4 | * \brief Generic message digest wrapper for PolarSSL |
| 5 | * |
| 6 | * \author Adriaan de Jong <dejong@fox-it.com> |
| 7 | * |
Paul Bakker | b6c5d2e | 2013-06-25 16:25:17 +0200 | [diff] [blame] | 8 | * Copyright (C) 2006-2013, Brainspark B.V. |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 9 | * |
| 10 | * This file is part of PolarSSL (http://www.polarssl.org) |
| 11 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
| 12 | * |
| 13 | * All rights reserved. |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or modify |
| 16 | * it under the terms of the GNU General Public License as published by |
| 17 | * the Free Software Foundation; either version 2 of the License, or |
| 18 | * (at your option) any later version. |
| 19 | * |
| 20 | * This program is distributed in the hope that it will be useful, |
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | * GNU General Public License for more details. |
| 24 | * |
| 25 | * You should have received a copy of the GNU General Public License along |
| 26 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 27 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 28 | */ |
| 29 | |
| 30 | #include "polarssl/config.h" |
| 31 | |
| 32 | #if defined(POLARSSL_MD_C) |
| 33 | |
| 34 | #include "polarssl/md_wrap.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 35 | |
| 36 | #if defined(POLARSSL_MD2_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 37 | #include "polarssl/md2.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 38 | #endif |
| 39 | |
| 40 | #if defined(POLARSSL_MD4_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 41 | #include "polarssl/md4.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 42 | #endif |
| 43 | |
| 44 | #if defined(POLARSSL_MD5_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 45 | #include "polarssl/md5.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 46 | #endif |
| 47 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 48 | #if defined(POLARSSL_RIPEMD160_C) |
| 49 | #include "polarssl/ripemd160.h" |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 50 | #endif |
| 51 | |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 52 | #if defined(POLARSSL_SHA1_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 53 | #include "polarssl/sha1.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 54 | #endif |
| 55 | |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 56 | #if defined(POLARSSL_SHA256_C) |
Paul Bakker | d2681d8 | 2013-06-30 14:49:12 +0200 | [diff] [blame] | 57 | #include "polarssl/sha256.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 58 | #endif |
| 59 | |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 60 | #if defined(POLARSSL_SHA512_C) |
Paul Bakker | d2681d8 | 2013-06-30 14:49:12 +0200 | [diff] [blame] | 61 | #include "polarssl/sha512.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 62 | #endif |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 63 | |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 64 | #if defined(POLARSSL_MEMORY_C) |
| 65 | #include "polarssl/memory.h" |
| 66 | #else |
| 67 | #define polarssl_malloc malloc |
| 68 | #define polarssl_free free |
| 69 | #endif |
| 70 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 71 | #include <stdlib.h> |
| 72 | |
| 73 | #if defined(POLARSSL_MD2_C) |
| 74 | |
| 75 | static void md2_starts_wrap( void *ctx ) |
| 76 | { |
| 77 | md2_starts( (md2_context *) ctx ); |
| 78 | } |
| 79 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 80 | static void md2_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 81 | { |
| 82 | md2_update( (md2_context *) ctx, input, ilen ); |
| 83 | } |
| 84 | |
| 85 | static void md2_finish_wrap( void *ctx, unsigned char *output ) |
| 86 | { |
| 87 | md2_finish( (md2_context *) ctx, output ); |
| 88 | } |
| 89 | |
Paul Bakker | b6c5d2e | 2013-06-25 16:25:17 +0200 | [diff] [blame] | 90 | static int md2_file_wrap( const char *path, unsigned char *output ) |
Paul Bakker | 335db3f | 2011-04-25 15:28:35 +0000 | [diff] [blame] | 91 | { |
| 92 | #if defined(POLARSSL_FS_IO) |
| 93 | return md2_file( path, output ); |
| 94 | #else |
| 95 | ((void) path); |
| 96 | ((void) output); |
| 97 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
| 98 | #endif |
| 99 | } |
| 100 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 101 | static void md2_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 102 | { |
| 103 | md2_hmac_starts( (md2_context *) ctx, key, keylen ); |
| 104 | } |
| 105 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 106 | static void md2_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 107 | { |
| 108 | md2_hmac_update( (md2_context *) ctx, input, ilen ); |
| 109 | } |
| 110 | |
| 111 | static void md2_hmac_finish_wrap( void *ctx, unsigned char *output ) |
| 112 | { |
| 113 | md2_hmac_finish( (md2_context *) ctx, output ); |
| 114 | } |
| 115 | |
| 116 | static void md2_hmac_reset_wrap( void *ctx ) |
| 117 | { |
| 118 | md2_hmac_reset( (md2_context *) ctx ); |
| 119 | } |
| 120 | |
| 121 | static void * md2_ctx_alloc( void ) |
| 122 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 123 | return polarssl_malloc( sizeof( md2_context ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static void md2_ctx_free( void *ctx ) |
| 127 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 128 | polarssl_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 131 | static void md2_process_wrap( void *ctx, const unsigned char *data ) |
| 132 | { |
| 133 | ((void) data); |
| 134 | |
| 135 | md2_process( (md2_context *) ctx ); |
| 136 | } |
| 137 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 138 | const md_info_t md2_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 139 | POLARSSL_MD_MD2, |
| 140 | "MD2", |
| 141 | 16, |
| 142 | md2_starts_wrap, |
| 143 | md2_update_wrap, |
| 144 | md2_finish_wrap, |
| 145 | md2, |
Paul Bakker | 335db3f | 2011-04-25 15:28:35 +0000 | [diff] [blame] | 146 | md2_file_wrap, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 147 | md2_hmac_starts_wrap, |
| 148 | md2_hmac_update_wrap, |
| 149 | md2_hmac_finish_wrap, |
| 150 | md2_hmac_reset_wrap, |
| 151 | md2_hmac, |
| 152 | md2_ctx_alloc, |
| 153 | md2_ctx_free, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 154 | md2_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | #endif |
| 158 | |
| 159 | #if defined(POLARSSL_MD4_C) |
| 160 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 161 | static void md4_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 162 | { |
| 163 | md4_starts( (md4_context *) ctx ); |
| 164 | } |
| 165 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 166 | static void md4_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 167 | { |
| 168 | md4_update( (md4_context *) ctx, input, ilen ); |
| 169 | } |
| 170 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 171 | static void md4_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 172 | { |
| 173 | md4_finish( (md4_context *) ctx, output ); |
| 174 | } |
| 175 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 176 | static int md4_file_wrap( const char *path, unsigned char *output ) |
Paul Bakker | 335db3f | 2011-04-25 15:28:35 +0000 | [diff] [blame] | 177 | { |
| 178 | #if defined(POLARSSL_FS_IO) |
| 179 | return md4_file( path, output ); |
| 180 | #else |
| 181 | ((void) path); |
| 182 | ((void) output); |
| 183 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
| 184 | #endif |
| 185 | } |
| 186 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 187 | static void md4_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 188 | { |
| 189 | md4_hmac_starts( (md4_context *) ctx, key, keylen ); |
| 190 | } |
| 191 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 192 | static void md4_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 193 | { |
| 194 | md4_hmac_update( (md4_context *) ctx, input, ilen ); |
| 195 | } |
| 196 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 197 | static void md4_hmac_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 198 | { |
| 199 | md4_hmac_finish( (md4_context *) ctx, output ); |
| 200 | } |
| 201 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 202 | static void md4_hmac_reset_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 203 | { |
| 204 | md4_hmac_reset( (md4_context *) ctx ); |
| 205 | } |
| 206 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 207 | static void *md4_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 208 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 209 | return polarssl_malloc( sizeof( md4_context ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 212 | static void md4_ctx_free( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 213 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 214 | polarssl_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 217 | static void md4_process_wrap( void *ctx, const unsigned char *data ) |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 218 | { |
| 219 | md4_process( (md4_context *) ctx, data ); |
| 220 | } |
| 221 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 222 | const md_info_t md4_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 223 | POLARSSL_MD_MD4, |
| 224 | "MD4", |
| 225 | 16, |
| 226 | md4_starts_wrap, |
| 227 | md4_update_wrap, |
| 228 | md4_finish_wrap, |
| 229 | md4, |
Paul Bakker | 335db3f | 2011-04-25 15:28:35 +0000 | [diff] [blame] | 230 | md4_file_wrap, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 231 | md4_hmac_starts_wrap, |
| 232 | md4_hmac_update_wrap, |
| 233 | md4_hmac_finish_wrap, |
| 234 | md4_hmac_reset_wrap, |
| 235 | md4_hmac, |
| 236 | md4_ctx_alloc, |
| 237 | md4_ctx_free, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 238 | md4_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 239 | }; |
| 240 | |
| 241 | #endif |
| 242 | |
| 243 | #if defined(POLARSSL_MD5_C) |
| 244 | |
| 245 | static void md5_starts_wrap( void *ctx ) |
| 246 | { |
| 247 | md5_starts( (md5_context *) ctx ); |
| 248 | } |
| 249 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 250 | static void md5_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 251 | { |
| 252 | md5_update( (md5_context *) ctx, input, ilen ); |
| 253 | } |
| 254 | |
| 255 | static void md5_finish_wrap( void *ctx, unsigned char *output ) |
| 256 | { |
| 257 | md5_finish( (md5_context *) ctx, output ); |
| 258 | } |
| 259 | |
Paul Bakker | b6c5d2e | 2013-06-25 16:25:17 +0200 | [diff] [blame] | 260 | static int md5_file_wrap( const char *path, unsigned char *output ) |
Paul Bakker | 335db3f | 2011-04-25 15:28:35 +0000 | [diff] [blame] | 261 | { |
| 262 | #if defined(POLARSSL_FS_IO) |
| 263 | return md5_file( path, output ); |
| 264 | #else |
| 265 | ((void) path); |
| 266 | ((void) output); |
| 267 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
| 268 | #endif |
| 269 | } |
| 270 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 271 | static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 272 | { |
| 273 | md5_hmac_starts( (md5_context *) ctx, key, keylen ); |
| 274 | } |
| 275 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 276 | static void md5_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 277 | { |
| 278 | md5_hmac_update( (md5_context *) ctx, input, ilen ); |
| 279 | } |
| 280 | |
| 281 | static void md5_hmac_finish_wrap( void *ctx, unsigned char *output ) |
| 282 | { |
| 283 | md5_hmac_finish( (md5_context *) ctx, output ); |
| 284 | } |
| 285 | |
| 286 | static void md5_hmac_reset_wrap( void *ctx ) |
| 287 | { |
| 288 | md5_hmac_reset( (md5_context *) ctx ); |
| 289 | } |
| 290 | |
| 291 | static void * md5_ctx_alloc( void ) |
| 292 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 293 | return polarssl_malloc( sizeof( md5_context ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | static void md5_ctx_free( void *ctx ) |
| 297 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 298 | polarssl_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 301 | static void md5_process_wrap( void *ctx, const unsigned char *data ) |
| 302 | { |
| 303 | md5_process( (md5_context *) ctx, data ); |
| 304 | } |
| 305 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 306 | const md_info_t md5_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 307 | POLARSSL_MD_MD5, |
| 308 | "MD5", |
| 309 | 16, |
| 310 | md5_starts_wrap, |
| 311 | md5_update_wrap, |
| 312 | md5_finish_wrap, |
| 313 | md5, |
Paul Bakker | 335db3f | 2011-04-25 15:28:35 +0000 | [diff] [blame] | 314 | md5_file_wrap, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 315 | md5_hmac_starts_wrap, |
| 316 | md5_hmac_update_wrap, |
| 317 | md5_hmac_finish_wrap, |
| 318 | md5_hmac_reset_wrap, |
| 319 | md5_hmac, |
| 320 | md5_ctx_alloc, |
| 321 | md5_ctx_free, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 322 | md5_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 323 | }; |
| 324 | |
| 325 | #endif |
| 326 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 327 | #if defined(POLARSSL_RIPEMD160_C) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 328 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 329 | static void ripemd160_starts_wrap( void *ctx ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 330 | { |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 331 | ripemd160_starts( (ripemd160_context *) ctx ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 332 | } |
| 333 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 334 | static void ripemd160_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 335 | { |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 336 | ripemd160_update( (ripemd160_context *) ctx, input, ilen ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 337 | } |
| 338 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 339 | static void ripemd160_finish_wrap( void *ctx, unsigned char *output ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 340 | { |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 341 | ripemd160_finish( (ripemd160_context *) ctx, output ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 342 | } |
| 343 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 344 | static int ripemd160_file_wrap( const char *path, unsigned char *output ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 345 | { |
| 346 | #if defined(POLARSSL_FS_IO) |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 347 | return ripemd160_file( path, output ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 348 | #else |
| 349 | ((void) path); |
| 350 | ((void) output); |
| 351 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
| 352 | #endif |
| 353 | } |
| 354 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 355 | static void ripemd160_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 356 | { |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 357 | ripemd160_hmac_starts( (ripemd160_context *) ctx, key, keylen ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 358 | } |
| 359 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 360 | static void ripemd160_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 361 | { |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 362 | ripemd160_hmac_update( (ripemd160_context *) ctx, input, ilen ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 363 | } |
| 364 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 365 | static void ripemd160_hmac_finish_wrap( void *ctx, unsigned char *output ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 366 | { |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 367 | ripemd160_hmac_finish( (ripemd160_context *) ctx, output ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 368 | } |
| 369 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 370 | static void ripemd160_hmac_reset_wrap( void *ctx ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 371 | { |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 372 | ripemd160_hmac_reset( (ripemd160_context *) ctx ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 373 | } |
| 374 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 375 | static void * ripemd160_ctx_alloc( void ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 376 | { |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 377 | return polarssl_malloc( sizeof( ripemd160_context ) ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 378 | } |
| 379 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 380 | static void ripemd160_ctx_free( void *ctx ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 381 | { |
| 382 | polarssl_free( ctx ); |
| 383 | } |
| 384 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 385 | static void ripemd160_process_wrap( void *ctx, const unsigned char *data ) |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 386 | { |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 387 | ripemd160_process( (ripemd160_context *) ctx, data ); |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 388 | } |
| 389 | |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 390 | const md_info_t ripemd160_info = { |
| 391 | POLARSSL_MD_RIPEMD160, |
| 392 | "RIPEMD160", |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 393 | 20, |
Paul Bakker | 61b699e | 2014-01-22 13:35:29 +0100 | [diff] [blame] | 394 | ripemd160_starts_wrap, |
| 395 | ripemd160_update_wrap, |
| 396 | ripemd160_finish_wrap, |
| 397 | ripemd160, |
| 398 | ripemd160_file_wrap, |
| 399 | ripemd160_hmac_starts_wrap, |
| 400 | ripemd160_hmac_update_wrap, |
| 401 | ripemd160_hmac_finish_wrap, |
| 402 | ripemd160_hmac_reset_wrap, |
| 403 | ripemd160_hmac, |
| 404 | ripemd160_ctx_alloc, |
| 405 | ripemd160_ctx_free, |
| 406 | ripemd160_process_wrap, |
Manuel Pégourié-Gonnard | e4d47a6 | 2014-01-17 20:41:32 +0100 | [diff] [blame] | 407 | }; |
| 408 | |
| 409 | #endif |
| 410 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 411 | #if defined(POLARSSL_SHA1_C) |
| 412 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 413 | static void sha1_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 414 | { |
| 415 | sha1_starts( (sha1_context *) ctx ); |
| 416 | } |
| 417 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 418 | static void sha1_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 419 | { |
| 420 | sha1_update( (sha1_context *) ctx, input, ilen ); |
| 421 | } |
| 422 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 423 | static void sha1_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 424 | { |
| 425 | sha1_finish( (sha1_context *) ctx, output ); |
| 426 | } |
| 427 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 428 | static int sha1_file_wrap( const char *path, unsigned char *output ) |
Paul Bakker | 335db3f | 2011-04-25 15:28:35 +0000 | [diff] [blame] | 429 | { |
| 430 | #if defined(POLARSSL_FS_IO) |
| 431 | return sha1_file( path, output ); |
| 432 | #else |
| 433 | ((void) path); |
| 434 | ((void) output); |
| 435 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
| 436 | #endif |
| 437 | } |
| 438 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 439 | static void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 440 | { |
| 441 | sha1_hmac_starts( (sha1_context *) ctx, key, keylen ); |
| 442 | } |
| 443 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 444 | static void sha1_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 445 | { |
| 446 | sha1_hmac_update( (sha1_context *) ctx, input, ilen ); |
| 447 | } |
| 448 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 449 | static void sha1_hmac_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 450 | { |
| 451 | sha1_hmac_finish( (sha1_context *) ctx, output ); |
| 452 | } |
| 453 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 454 | static void sha1_hmac_reset_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 455 | { |
| 456 | sha1_hmac_reset( (sha1_context *) ctx ); |
| 457 | } |
| 458 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 459 | static void * sha1_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 460 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 461 | return polarssl_malloc( sizeof( sha1_context ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 464 | static void sha1_ctx_free( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 465 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 466 | polarssl_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 467 | } |
| 468 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 469 | static void sha1_process_wrap( void *ctx, const unsigned char *data ) |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 470 | { |
| 471 | sha1_process( (sha1_context *) ctx, data ); |
| 472 | } |
| 473 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 474 | const md_info_t sha1_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 475 | POLARSSL_MD_SHA1, |
| 476 | "SHA1", |
| 477 | 20, |
| 478 | sha1_starts_wrap, |
| 479 | sha1_update_wrap, |
| 480 | sha1_finish_wrap, |
| 481 | sha1, |
Paul Bakker | 335db3f | 2011-04-25 15:28:35 +0000 | [diff] [blame] | 482 | sha1_file_wrap, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 483 | sha1_hmac_starts_wrap, |
| 484 | sha1_hmac_update_wrap, |
| 485 | sha1_hmac_finish_wrap, |
| 486 | sha1_hmac_reset_wrap, |
| 487 | sha1_hmac, |
| 488 | sha1_ctx_alloc, |
| 489 | sha1_ctx_free, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 490 | sha1_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 491 | }; |
| 492 | |
| 493 | #endif |
| 494 | |
| 495 | /* |
| 496 | * Wrappers for generic message digests |
| 497 | */ |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 498 | #if defined(POLARSSL_SHA256_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 499 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 500 | static void sha224_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 501 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 502 | sha256_starts( (sha256_context *) ctx, 1 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 503 | } |
| 504 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 505 | static void sha224_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 506 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 507 | sha256_update( (sha256_context *) ctx, input, ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 510 | static void sha224_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 511 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 512 | sha256_finish( (sha256_context *) ctx, output ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 515 | static void sha224_wrap( const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 516 | unsigned char *output ) |
| 517 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 518 | sha256( input, ilen, output, 1 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 521 | static int sha224_file_wrap( const char *path, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 522 | { |
Paul Bakker | 335db3f | 2011-04-25 15:28:35 +0000 | [diff] [blame] | 523 | #if defined(POLARSSL_FS_IO) |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 524 | return sha256_file( path, output, 1 ); |
Paul Bakker | 335db3f | 2011-04-25 15:28:35 +0000 | [diff] [blame] | 525 | #else |
| 526 | ((void) path); |
| 527 | ((void) output); |
| 528 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
| 529 | #endif |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 532 | static void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 533 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 534 | sha256_hmac_starts( (sha256_context *) ctx, key, keylen, 1 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 535 | } |
| 536 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 537 | static void sha224_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 538 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 539 | sha256_hmac_update( (sha256_context *) ctx, input, ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 540 | } |
| 541 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 542 | static void sha224_hmac_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 543 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 544 | sha256_hmac_finish( (sha256_context *) ctx, output ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 547 | static void sha224_hmac_reset_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 548 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 549 | sha256_hmac_reset( (sha256_context *) ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 552 | static void sha224_hmac_wrap( const unsigned char *key, size_t keylen, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 553 | const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 554 | unsigned char *output ) |
| 555 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 556 | sha256_hmac( key, keylen, input, ilen, output, 1 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 557 | } |
| 558 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 559 | static void * sha224_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 560 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 561 | return polarssl_malloc( sizeof( sha256_context ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 564 | static void sha224_ctx_free( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 565 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 566 | polarssl_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 569 | static void sha224_process_wrap( void *ctx, const unsigned char *data ) |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 570 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 571 | sha256_process( (sha256_context *) ctx, data ); |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 572 | } |
| 573 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 574 | const md_info_t sha224_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 575 | POLARSSL_MD_SHA224, |
| 576 | "SHA224", |
| 577 | 28, |
| 578 | sha224_starts_wrap, |
| 579 | sha224_update_wrap, |
| 580 | sha224_finish_wrap, |
| 581 | sha224_wrap, |
| 582 | sha224_file_wrap, |
| 583 | sha224_hmac_starts_wrap, |
| 584 | sha224_hmac_update_wrap, |
| 585 | sha224_hmac_finish_wrap, |
| 586 | sha224_hmac_reset_wrap, |
| 587 | sha224_hmac_wrap, |
| 588 | sha224_ctx_alloc, |
| 589 | sha224_ctx_free, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 590 | sha224_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 591 | }; |
| 592 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 593 | static void sha256_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 594 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 595 | sha256_starts( (sha256_context *) ctx, 0 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 596 | } |
| 597 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 598 | static void sha256_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 599 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 600 | sha256_update( (sha256_context *) ctx, input, ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 601 | } |
| 602 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 603 | static void sha256_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 604 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 605 | sha256_finish( (sha256_context *) ctx, output ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 608 | static void sha256_wrap( const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 609 | unsigned char *output ) |
| 610 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 611 | sha256( input, ilen, output, 0 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 612 | } |
| 613 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 614 | static int sha256_file_wrap( const char *path, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 615 | { |
Paul Bakker | 335db3f | 2011-04-25 15:28:35 +0000 | [diff] [blame] | 616 | #if defined(POLARSSL_FS_IO) |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 617 | return sha256_file( path, output, 0 ); |
Paul Bakker | 335db3f | 2011-04-25 15:28:35 +0000 | [diff] [blame] | 618 | #else |
| 619 | ((void) path); |
| 620 | ((void) output); |
| 621 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
| 622 | #endif |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 623 | } |
| 624 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 625 | static void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 626 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 627 | sha256_hmac_starts( (sha256_context *) ctx, key, keylen, 0 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 628 | } |
| 629 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 630 | static void sha256_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 631 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 632 | sha256_hmac_update( (sha256_context *) ctx, input, ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 633 | } |
| 634 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 635 | static void sha256_hmac_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 636 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 637 | sha256_hmac_finish( (sha256_context *) ctx, output ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 638 | } |
| 639 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 640 | static void sha256_hmac_reset_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 641 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 642 | sha256_hmac_reset( (sha256_context *) ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 643 | } |
| 644 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 645 | static void sha256_hmac_wrap( const unsigned char *key, size_t keylen, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 646 | const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 647 | unsigned char *output ) |
| 648 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 649 | sha256_hmac( key, keylen, input, ilen, output, 0 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 652 | static void * sha256_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 653 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 654 | return polarssl_malloc( sizeof( sha256_context ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 655 | } |
| 656 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 657 | static void sha256_ctx_free( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 658 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 659 | polarssl_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 660 | } |
| 661 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 662 | static void sha256_process_wrap( void *ctx, const unsigned char *data ) |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 663 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 664 | sha256_process( (sha256_context *) ctx, data ); |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 665 | } |
| 666 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 667 | const md_info_t sha256_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 668 | POLARSSL_MD_SHA256, |
| 669 | "SHA256", |
| 670 | 32, |
| 671 | sha256_starts_wrap, |
| 672 | sha256_update_wrap, |
| 673 | sha256_finish_wrap, |
| 674 | sha256_wrap, |
| 675 | sha256_file_wrap, |
| 676 | sha256_hmac_starts_wrap, |
| 677 | sha256_hmac_update_wrap, |
| 678 | sha256_hmac_finish_wrap, |
| 679 | sha256_hmac_reset_wrap, |
| 680 | sha256_hmac_wrap, |
| 681 | sha256_ctx_alloc, |
| 682 | sha256_ctx_free, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 683 | sha256_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 684 | }; |
| 685 | |
| 686 | #endif |
| 687 | |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 688 | #if defined(POLARSSL_SHA512_C) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 689 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 690 | static void sha384_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 691 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 692 | sha512_starts( (sha512_context *) ctx, 1 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 693 | } |
| 694 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 695 | static void sha384_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 696 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 697 | sha512_update( (sha512_context *) ctx, input, ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 698 | } |
| 699 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 700 | static void sha384_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 701 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 702 | sha512_finish( (sha512_context *) ctx, output ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 703 | } |
| 704 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 705 | static void sha384_wrap( const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 706 | unsigned char *output ) |
| 707 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 708 | sha512( input, ilen, output, 1 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 709 | } |
| 710 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 711 | static int sha384_file_wrap( const char *path, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 712 | { |
Paul Bakker | 335db3f | 2011-04-25 15:28:35 +0000 | [diff] [blame] | 713 | #if defined(POLARSSL_FS_IO) |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 714 | return sha512_file( path, output, 1 ); |
Paul Bakker | 335db3f | 2011-04-25 15:28:35 +0000 | [diff] [blame] | 715 | #else |
| 716 | ((void) path); |
| 717 | ((void) output); |
| 718 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
| 719 | #endif |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 720 | } |
| 721 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 722 | static void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 723 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 724 | sha512_hmac_starts( (sha512_context *) ctx, key, keylen, 1 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 725 | } |
| 726 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 727 | static void sha384_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 728 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 729 | sha512_hmac_update( (sha512_context *) ctx, input, ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 730 | } |
| 731 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 732 | static void sha384_hmac_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 733 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 734 | sha512_hmac_finish( (sha512_context *) ctx, output ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 735 | } |
| 736 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 737 | static void sha384_hmac_reset_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 738 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 739 | sha512_hmac_reset( (sha512_context *) ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 740 | } |
| 741 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 742 | static void sha384_hmac_wrap( const unsigned char *key, size_t keylen, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 743 | const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 744 | unsigned char *output ) |
| 745 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 746 | sha512_hmac( key, keylen, input, ilen, output, 1 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 747 | } |
| 748 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 749 | static void * sha384_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 750 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 751 | return polarssl_malloc( sizeof( sha512_context ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 752 | } |
| 753 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 754 | static void sha384_ctx_free( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 755 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 756 | polarssl_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 757 | } |
| 758 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 759 | static void sha384_process_wrap( void *ctx, const unsigned char *data ) |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 760 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 761 | sha512_process( (sha512_context *) ctx, data ); |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 762 | } |
| 763 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 764 | const md_info_t sha384_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 765 | POLARSSL_MD_SHA384, |
| 766 | "SHA384", |
| 767 | 48, |
| 768 | sha384_starts_wrap, |
| 769 | sha384_update_wrap, |
| 770 | sha384_finish_wrap, |
| 771 | sha384_wrap, |
| 772 | sha384_file_wrap, |
| 773 | sha384_hmac_starts_wrap, |
| 774 | sha384_hmac_update_wrap, |
| 775 | sha384_hmac_finish_wrap, |
| 776 | sha384_hmac_reset_wrap, |
| 777 | sha384_hmac_wrap, |
| 778 | sha384_ctx_alloc, |
| 779 | sha384_ctx_free, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 780 | sha384_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 781 | }; |
| 782 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 783 | static void sha512_starts_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 784 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 785 | sha512_starts( (sha512_context *) ctx, 0 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 786 | } |
| 787 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 788 | static void sha512_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 789 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 790 | sha512_update( (sha512_context *) ctx, input, ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 791 | } |
| 792 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 793 | static void sha512_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 794 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 795 | sha512_finish( (sha512_context *) ctx, output ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 796 | } |
| 797 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 798 | static void sha512_wrap( const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 799 | unsigned char *output ) |
| 800 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 801 | sha512( input, ilen, output, 0 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 802 | } |
| 803 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 804 | static int sha512_file_wrap( const char *path, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 805 | { |
Paul Bakker | 335db3f | 2011-04-25 15:28:35 +0000 | [diff] [blame] | 806 | #if defined(POLARSSL_FS_IO) |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 807 | return sha512_file( path, output, 0 ); |
Paul Bakker | 335db3f | 2011-04-25 15:28:35 +0000 | [diff] [blame] | 808 | #else |
| 809 | ((void) path); |
| 810 | ((void) output); |
| 811 | return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; |
| 812 | #endif |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 813 | } |
| 814 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 815 | static void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 816 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 817 | sha512_hmac_starts( (sha512_context *) ctx, key, keylen, 0 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 818 | } |
| 819 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 820 | static void sha512_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 821 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 822 | sha512_hmac_update( (sha512_context *) ctx, input, ilen ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 823 | } |
| 824 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 825 | static void sha512_hmac_finish_wrap( void *ctx, unsigned char *output ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 826 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 827 | sha512_hmac_finish( (sha512_context *) ctx, output ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 828 | } |
| 829 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 830 | static void sha512_hmac_reset_wrap( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 831 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 832 | sha512_hmac_reset( (sha512_context *) ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 833 | } |
| 834 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 835 | static void sha512_hmac_wrap( const unsigned char *key, size_t keylen, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 836 | const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 837 | unsigned char *output ) |
| 838 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 839 | sha512_hmac( key, keylen, input, ilen, output, 0 ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 840 | } |
| 841 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 842 | static void * sha512_ctx_alloc( void ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 843 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 844 | return polarssl_malloc( sizeof( sha512_context ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 847 | static void sha512_ctx_free( void *ctx ) |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 848 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 849 | polarssl_free( ctx ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 850 | } |
| 851 | |
Paul Bakker | d1df02a | 2013-03-13 10:31:31 +0100 | [diff] [blame] | 852 | static void sha512_process_wrap( void *ctx, const unsigned char *data ) |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 853 | { |
Paul Bakker | 9e36f04 | 2013-06-30 14:34:05 +0200 | [diff] [blame] | 854 | sha512_process( (sha512_context *) ctx, data ); |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 855 | } |
| 856 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 857 | const md_info_t sha512_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 858 | POLARSSL_MD_SHA512, |
| 859 | "SHA512", |
| 860 | 64, |
| 861 | sha512_starts_wrap, |
| 862 | sha512_update_wrap, |
| 863 | sha512_finish_wrap, |
| 864 | sha512_wrap, |
| 865 | sha512_file_wrap, |
| 866 | sha512_hmac_starts_wrap, |
| 867 | sha512_hmac_update_wrap, |
| 868 | sha512_hmac_finish_wrap, |
| 869 | sha512_hmac_reset_wrap, |
| 870 | sha512_hmac_wrap, |
| 871 | sha512_ctx_alloc, |
| 872 | sha512_ctx_free, |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 873 | sha512_process_wrap, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 874 | }; |
| 875 | |
| 876 | #endif |
| 877 | |
| 878 | #endif |