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 | * |
| 8 | * Copyright (C) 2006-2010, Brainspark B.V. |
| 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" |
| 35 | #include "polarssl/md2.h" |
| 36 | #include "polarssl/md4.h" |
| 37 | #include "polarssl/md5.h" |
| 38 | #include "polarssl/sha1.h" |
| 39 | #include "polarssl/sha2.h" |
| 40 | #include "polarssl/sha4.h" |
| 41 | |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 42 | #include <stdlib.h> |
| 43 | |
| 44 | #if defined(POLARSSL_MD2_C) |
| 45 | |
| 46 | static void md2_starts_wrap( void *ctx ) |
| 47 | { |
| 48 | md2_starts( (md2_context *) ctx ); |
| 49 | } |
| 50 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 51 | 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] | 52 | { |
| 53 | md2_update( (md2_context *) ctx, input, ilen ); |
| 54 | } |
| 55 | |
| 56 | static void md2_finish_wrap( void *ctx, unsigned char *output ) |
| 57 | { |
| 58 | md2_finish( (md2_context *) ctx, output ); |
| 59 | } |
| 60 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 61 | 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] | 62 | { |
| 63 | md2_hmac_starts( (md2_context *) ctx, key, keylen ); |
| 64 | } |
| 65 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 66 | 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] | 67 | { |
| 68 | md2_hmac_update( (md2_context *) ctx, input, ilen ); |
| 69 | } |
| 70 | |
| 71 | static void md2_hmac_finish_wrap( void *ctx, unsigned char *output ) |
| 72 | { |
| 73 | md2_hmac_finish( (md2_context *) ctx, output ); |
| 74 | } |
| 75 | |
| 76 | static void md2_hmac_reset_wrap( void *ctx ) |
| 77 | { |
| 78 | md2_hmac_reset( (md2_context *) ctx ); |
| 79 | } |
| 80 | |
| 81 | static void * md2_ctx_alloc( void ) |
| 82 | { |
| 83 | return malloc( sizeof( md2_context ) ); |
| 84 | } |
| 85 | |
| 86 | static void md2_ctx_free( void *ctx ) |
| 87 | { |
| 88 | free( ctx ); |
| 89 | } |
| 90 | |
| 91 | const md_info_t md2_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 92 | POLARSSL_MD_MD2, |
| 93 | "MD2", |
| 94 | 16, |
| 95 | md2_starts_wrap, |
| 96 | md2_update_wrap, |
| 97 | md2_finish_wrap, |
| 98 | md2, |
| 99 | md2_file, |
| 100 | md2_hmac_starts_wrap, |
| 101 | md2_hmac_update_wrap, |
| 102 | md2_hmac_finish_wrap, |
| 103 | md2_hmac_reset_wrap, |
| 104 | md2_hmac, |
| 105 | md2_ctx_alloc, |
| 106 | md2_ctx_free, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | #endif |
| 110 | |
| 111 | #if defined(POLARSSL_MD4_C) |
| 112 | |
| 113 | void md4_starts_wrap( void *ctx ) |
| 114 | { |
| 115 | md4_starts( (md4_context *) ctx ); |
| 116 | } |
| 117 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 118 | 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] | 119 | { |
| 120 | md4_update( (md4_context *) ctx, input, ilen ); |
| 121 | } |
| 122 | |
| 123 | void md4_finish_wrap( void *ctx, unsigned char *output ) |
| 124 | { |
| 125 | md4_finish( (md4_context *) ctx, output ); |
| 126 | } |
| 127 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 128 | 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] | 129 | { |
| 130 | md4_hmac_starts( (md4_context *) ctx, key, keylen ); |
| 131 | } |
| 132 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 133 | 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] | 134 | { |
| 135 | md4_hmac_update( (md4_context *) ctx, input, ilen ); |
| 136 | } |
| 137 | |
| 138 | void md4_hmac_finish_wrap( void *ctx, unsigned char *output ) |
| 139 | { |
| 140 | md4_hmac_finish( (md4_context *) ctx, output ); |
| 141 | } |
| 142 | |
| 143 | void md4_hmac_reset_wrap( void *ctx ) |
| 144 | { |
| 145 | md4_hmac_reset( (md4_context *) ctx ); |
| 146 | } |
| 147 | |
| 148 | void *md4_ctx_alloc( void ) |
| 149 | { |
| 150 | return malloc( sizeof( md4_context ) ); |
| 151 | } |
| 152 | |
| 153 | void md4_ctx_free( void *ctx ) |
| 154 | { |
| 155 | free( ctx ); |
| 156 | } |
| 157 | |
| 158 | const md_info_t md4_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 159 | POLARSSL_MD_MD4, |
| 160 | "MD4", |
| 161 | 16, |
| 162 | md4_starts_wrap, |
| 163 | md4_update_wrap, |
| 164 | md4_finish_wrap, |
| 165 | md4, |
| 166 | md4_file, |
| 167 | md4_hmac_starts_wrap, |
| 168 | md4_hmac_update_wrap, |
| 169 | md4_hmac_finish_wrap, |
| 170 | md4_hmac_reset_wrap, |
| 171 | md4_hmac, |
| 172 | md4_ctx_alloc, |
| 173 | md4_ctx_free, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | #endif |
| 177 | |
| 178 | #if defined(POLARSSL_MD5_C) |
| 179 | |
| 180 | static void md5_starts_wrap( void *ctx ) |
| 181 | { |
| 182 | md5_starts( (md5_context *) ctx ); |
| 183 | } |
| 184 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 185 | 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] | 186 | { |
| 187 | md5_update( (md5_context *) ctx, input, ilen ); |
| 188 | } |
| 189 | |
| 190 | static void md5_finish_wrap( void *ctx, unsigned char *output ) |
| 191 | { |
| 192 | md5_finish( (md5_context *) ctx, output ); |
| 193 | } |
| 194 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 195 | 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] | 196 | { |
| 197 | md5_hmac_starts( (md5_context *) ctx, key, keylen ); |
| 198 | } |
| 199 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 200 | 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] | 201 | { |
| 202 | md5_hmac_update( (md5_context *) ctx, input, ilen ); |
| 203 | } |
| 204 | |
| 205 | static void md5_hmac_finish_wrap( void *ctx, unsigned char *output ) |
| 206 | { |
| 207 | md5_hmac_finish( (md5_context *) ctx, output ); |
| 208 | } |
| 209 | |
| 210 | static void md5_hmac_reset_wrap( void *ctx ) |
| 211 | { |
| 212 | md5_hmac_reset( (md5_context *) ctx ); |
| 213 | } |
| 214 | |
| 215 | static void * md5_ctx_alloc( void ) |
| 216 | { |
| 217 | return malloc( sizeof( md5_context ) ); |
| 218 | } |
| 219 | |
| 220 | static void md5_ctx_free( void *ctx ) |
| 221 | { |
| 222 | free( ctx ); |
| 223 | } |
| 224 | |
| 225 | const md_info_t md5_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 226 | POLARSSL_MD_MD5, |
| 227 | "MD5", |
| 228 | 16, |
| 229 | md5_starts_wrap, |
| 230 | md5_update_wrap, |
| 231 | md5_finish_wrap, |
| 232 | md5, |
| 233 | md5_file, |
| 234 | md5_hmac_starts_wrap, |
| 235 | md5_hmac_update_wrap, |
| 236 | md5_hmac_finish_wrap, |
| 237 | md5_hmac_reset_wrap, |
| 238 | md5_hmac, |
| 239 | md5_ctx_alloc, |
| 240 | md5_ctx_free, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 241 | }; |
| 242 | |
| 243 | #endif |
| 244 | |
| 245 | #if defined(POLARSSL_SHA1_C) |
| 246 | |
| 247 | void sha1_starts_wrap( void *ctx ) |
| 248 | { |
| 249 | sha1_starts( (sha1_context *) ctx ); |
| 250 | } |
| 251 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 252 | 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] | 253 | { |
| 254 | sha1_update( (sha1_context *) ctx, input, ilen ); |
| 255 | } |
| 256 | |
| 257 | void sha1_finish_wrap( void *ctx, unsigned char *output ) |
| 258 | { |
| 259 | sha1_finish( (sha1_context *) ctx, output ); |
| 260 | } |
| 261 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 262 | 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] | 263 | { |
| 264 | sha1_hmac_starts( (sha1_context *) ctx, key, keylen ); |
| 265 | } |
| 266 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 267 | 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] | 268 | { |
| 269 | sha1_hmac_update( (sha1_context *) ctx, input, ilen ); |
| 270 | } |
| 271 | |
| 272 | void sha1_hmac_finish_wrap( void *ctx, unsigned char *output ) |
| 273 | { |
| 274 | sha1_hmac_finish( (sha1_context *) ctx, output ); |
| 275 | } |
| 276 | |
| 277 | void sha1_hmac_reset_wrap( void *ctx ) |
| 278 | { |
| 279 | sha1_hmac_reset( (sha1_context *) ctx ); |
| 280 | } |
| 281 | |
| 282 | void * sha1_ctx_alloc( void ) |
| 283 | { |
| 284 | return malloc( sizeof( sha1_context ) ); |
| 285 | } |
| 286 | |
| 287 | void sha1_ctx_free( void *ctx ) |
| 288 | { |
| 289 | free( ctx ); |
| 290 | } |
| 291 | |
| 292 | const md_info_t sha1_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 293 | POLARSSL_MD_SHA1, |
| 294 | "SHA1", |
| 295 | 20, |
| 296 | sha1_starts_wrap, |
| 297 | sha1_update_wrap, |
| 298 | sha1_finish_wrap, |
| 299 | sha1, |
| 300 | sha1_file, |
| 301 | sha1_hmac_starts_wrap, |
| 302 | sha1_hmac_update_wrap, |
| 303 | sha1_hmac_finish_wrap, |
| 304 | sha1_hmac_reset_wrap, |
| 305 | sha1_hmac, |
| 306 | sha1_ctx_alloc, |
| 307 | sha1_ctx_free, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 308 | }; |
| 309 | |
| 310 | #endif |
| 311 | |
| 312 | /* |
| 313 | * Wrappers for generic message digests |
| 314 | */ |
| 315 | #if defined(POLARSSL_SHA2_C) |
| 316 | |
| 317 | void sha224_starts_wrap( void *ctx ) |
| 318 | { |
| 319 | sha2_starts( (sha2_context *) ctx, 1 ); |
| 320 | } |
| 321 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 322 | 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] | 323 | { |
| 324 | sha2_update( (sha2_context *) ctx, input, ilen ); |
| 325 | } |
| 326 | |
| 327 | void sha224_finish_wrap( void *ctx, unsigned char *output ) |
| 328 | { |
| 329 | sha2_finish( (sha2_context *) ctx, output ); |
| 330 | } |
| 331 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 332 | void sha224_wrap( const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 333 | unsigned char *output ) |
| 334 | { |
| 335 | sha2( input, ilen, output, 1 ); |
| 336 | } |
| 337 | |
| 338 | int sha224_file_wrap( const char *path, unsigned char *output ) |
| 339 | { |
| 340 | return sha2_file( path, output, 1 ); |
| 341 | } |
| 342 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 343 | 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] | 344 | { |
| 345 | sha2_hmac_starts( (sha2_context *) ctx, key, keylen, 1 ); |
| 346 | } |
| 347 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 348 | 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] | 349 | { |
| 350 | sha2_hmac_update( (sha2_context *) ctx, input, ilen ); |
| 351 | } |
| 352 | |
| 353 | void sha224_hmac_finish_wrap( void *ctx, unsigned char *output ) |
| 354 | { |
| 355 | sha2_hmac_finish( (sha2_context *) ctx, output ); |
| 356 | } |
| 357 | |
| 358 | void sha224_hmac_reset_wrap( void *ctx ) |
| 359 | { |
| 360 | sha2_hmac_reset( (sha2_context *) ctx ); |
| 361 | } |
| 362 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 363 | void sha224_hmac_wrap( const unsigned char *key, size_t keylen, |
| 364 | const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 365 | unsigned char *output ) |
| 366 | { |
| 367 | sha2_hmac( key, keylen, input, ilen, output, 1 ); |
| 368 | } |
| 369 | |
| 370 | void * sha224_ctx_alloc( void ) |
| 371 | { |
| 372 | return malloc( sizeof( sha2_context ) ); |
| 373 | } |
| 374 | |
| 375 | void sha224_ctx_free( void *ctx ) |
| 376 | { |
| 377 | free( ctx ); |
| 378 | } |
| 379 | |
| 380 | const md_info_t sha224_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 381 | POLARSSL_MD_SHA224, |
| 382 | "SHA224", |
| 383 | 28, |
| 384 | sha224_starts_wrap, |
| 385 | sha224_update_wrap, |
| 386 | sha224_finish_wrap, |
| 387 | sha224_wrap, |
| 388 | sha224_file_wrap, |
| 389 | sha224_hmac_starts_wrap, |
| 390 | sha224_hmac_update_wrap, |
| 391 | sha224_hmac_finish_wrap, |
| 392 | sha224_hmac_reset_wrap, |
| 393 | sha224_hmac_wrap, |
| 394 | sha224_ctx_alloc, |
| 395 | sha224_ctx_free, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 396 | }; |
| 397 | |
| 398 | void sha256_starts_wrap( void *ctx ) |
| 399 | { |
| 400 | sha2_starts( (sha2_context *) ctx, 0 ); |
| 401 | } |
| 402 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 403 | 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] | 404 | { |
| 405 | sha2_update( (sha2_context *) ctx, input, ilen ); |
| 406 | } |
| 407 | |
| 408 | void sha256_finish_wrap( void *ctx, unsigned char *output ) |
| 409 | { |
| 410 | sha2_finish( (sha2_context *) ctx, output ); |
| 411 | } |
| 412 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 413 | void sha256_wrap( const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 414 | unsigned char *output ) |
| 415 | { |
| 416 | sha2( input, ilen, output, 0 ); |
| 417 | } |
| 418 | |
| 419 | int sha256_file_wrap( const char *path, unsigned char *output ) |
| 420 | { |
| 421 | return sha2_file( path, output, 0 ); |
| 422 | } |
| 423 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 424 | 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] | 425 | { |
| 426 | sha2_hmac_starts( (sha2_context *) ctx, key, keylen, 0 ); |
| 427 | } |
| 428 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 429 | 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] | 430 | { |
| 431 | sha2_hmac_update( (sha2_context *) ctx, input, ilen ); |
| 432 | } |
| 433 | |
| 434 | void sha256_hmac_finish_wrap( void *ctx, unsigned char *output ) |
| 435 | { |
| 436 | sha2_hmac_finish( (sha2_context *) ctx, output ); |
| 437 | } |
| 438 | |
| 439 | void sha256_hmac_reset_wrap( void *ctx ) |
| 440 | { |
| 441 | sha2_hmac_reset( (sha2_context *) ctx ); |
| 442 | } |
| 443 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 444 | void sha256_hmac_wrap( const unsigned char *key, size_t keylen, |
| 445 | const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 446 | unsigned char *output ) |
| 447 | { |
| 448 | sha2_hmac( key, keylen, input, ilen, output, 0 ); |
| 449 | } |
| 450 | |
| 451 | void * sha256_ctx_alloc( void ) |
| 452 | { |
Paul Bakker | 6d46812 | 2011-01-06 15:35:45 +0000 | [diff] [blame] | 453 | return malloc( sizeof( sha2_context ) ); |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | void sha256_ctx_free( void *ctx ) |
| 457 | { |
| 458 | free( ctx ); |
| 459 | } |
| 460 | |
| 461 | const md_info_t sha256_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 462 | POLARSSL_MD_SHA256, |
| 463 | "SHA256", |
| 464 | 32, |
| 465 | sha256_starts_wrap, |
| 466 | sha256_update_wrap, |
| 467 | sha256_finish_wrap, |
| 468 | sha256_wrap, |
| 469 | sha256_file_wrap, |
| 470 | sha256_hmac_starts_wrap, |
| 471 | sha256_hmac_update_wrap, |
| 472 | sha256_hmac_finish_wrap, |
| 473 | sha256_hmac_reset_wrap, |
| 474 | sha256_hmac_wrap, |
| 475 | sha256_ctx_alloc, |
| 476 | sha256_ctx_free, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 477 | }; |
| 478 | |
| 479 | #endif |
| 480 | |
| 481 | #if defined(POLARSSL_SHA4_C) |
| 482 | |
| 483 | void sha384_starts_wrap( void *ctx ) |
| 484 | { |
| 485 | sha4_starts( (sha4_context *) ctx, 1 ); |
| 486 | } |
| 487 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 488 | 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] | 489 | { |
| 490 | sha4_update( (sha4_context *) ctx, input, ilen ); |
| 491 | } |
| 492 | |
| 493 | void sha384_finish_wrap( void *ctx, unsigned char *output ) |
| 494 | { |
| 495 | sha4_finish( (sha4_context *) ctx, output ); |
| 496 | } |
| 497 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 498 | void sha384_wrap( const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 499 | unsigned char *output ) |
| 500 | { |
| 501 | sha4( input, ilen, output, 1 ); |
| 502 | } |
| 503 | |
| 504 | int sha384_file_wrap( const char *path, unsigned char *output ) |
| 505 | { |
| 506 | return sha4_file( path, output, 1 ); |
| 507 | } |
| 508 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 509 | 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] | 510 | { |
| 511 | sha4_hmac_starts( (sha4_context *) ctx, key, keylen, 1 ); |
| 512 | } |
| 513 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 514 | 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] | 515 | { |
| 516 | sha4_hmac_update( (sha4_context *) ctx, input, ilen ); |
| 517 | } |
| 518 | |
| 519 | void sha384_hmac_finish_wrap( void *ctx, unsigned char *output ) |
| 520 | { |
| 521 | sha4_hmac_finish( (sha4_context *) ctx, output ); |
| 522 | } |
| 523 | |
| 524 | void sha384_hmac_reset_wrap( void *ctx ) |
| 525 | { |
| 526 | sha4_hmac_reset( (sha4_context *) ctx ); |
| 527 | } |
| 528 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 529 | void sha384_hmac_wrap( const unsigned char *key, size_t keylen, |
| 530 | const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 531 | unsigned char *output ) |
| 532 | { |
| 533 | sha4_hmac( key, keylen, input, ilen, output, 1 ); |
| 534 | } |
| 535 | |
| 536 | void * sha384_ctx_alloc( void ) |
| 537 | { |
| 538 | return malloc( sizeof( sha4_context ) ); |
| 539 | } |
| 540 | |
| 541 | void sha384_ctx_free( void *ctx ) |
| 542 | { |
| 543 | free( ctx ); |
| 544 | } |
| 545 | |
| 546 | const md_info_t sha384_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 547 | POLARSSL_MD_SHA384, |
| 548 | "SHA384", |
| 549 | 48, |
| 550 | sha384_starts_wrap, |
| 551 | sha384_update_wrap, |
| 552 | sha384_finish_wrap, |
| 553 | sha384_wrap, |
| 554 | sha384_file_wrap, |
| 555 | sha384_hmac_starts_wrap, |
| 556 | sha384_hmac_update_wrap, |
| 557 | sha384_hmac_finish_wrap, |
| 558 | sha384_hmac_reset_wrap, |
| 559 | sha384_hmac_wrap, |
| 560 | sha384_ctx_alloc, |
| 561 | sha384_ctx_free, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 562 | }; |
| 563 | |
| 564 | void sha512_starts_wrap( void *ctx ) |
| 565 | { |
| 566 | sha4_starts( (sha4_context *) ctx, 0 ); |
| 567 | } |
| 568 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 569 | 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] | 570 | { |
| 571 | sha4_update( (sha4_context *) ctx, input, ilen ); |
| 572 | } |
| 573 | |
| 574 | void sha512_finish_wrap( void *ctx, unsigned char *output ) |
| 575 | { |
| 576 | sha4_finish( (sha4_context *) ctx, output ); |
| 577 | } |
| 578 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 579 | void sha512_wrap( const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 580 | unsigned char *output ) |
| 581 | { |
| 582 | sha4( input, ilen, output, 0 ); |
| 583 | } |
| 584 | |
| 585 | int sha512_file_wrap( const char *path, unsigned char *output ) |
| 586 | { |
| 587 | return sha4_file( path, output, 0 ); |
| 588 | } |
| 589 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 590 | 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] | 591 | { |
| 592 | sha4_hmac_starts( (sha4_context *) ctx, key, keylen, 0 ); |
| 593 | } |
| 594 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 595 | 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] | 596 | { |
| 597 | sha4_hmac_update( (sha4_context *) ctx, input, ilen ); |
| 598 | } |
| 599 | |
| 600 | void sha512_hmac_finish_wrap( void *ctx, unsigned char *output ) |
| 601 | { |
| 602 | sha4_hmac_finish( (sha4_context *) ctx, output ); |
| 603 | } |
| 604 | |
| 605 | void sha512_hmac_reset_wrap( void *ctx ) |
| 606 | { |
| 607 | sha4_hmac_reset( (sha4_context *) ctx ); |
| 608 | } |
| 609 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 610 | void sha512_hmac_wrap( const unsigned char *key, size_t keylen, |
| 611 | const unsigned char *input, size_t ilen, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 612 | unsigned char *output ) |
| 613 | { |
| 614 | sha4_hmac( key, keylen, input, ilen, output, 0 ); |
| 615 | } |
| 616 | |
| 617 | void * sha512_ctx_alloc( void ) |
| 618 | { |
| 619 | return malloc( sizeof( sha4_context ) ); |
| 620 | } |
| 621 | |
| 622 | void sha512_ctx_free( void *ctx ) |
| 623 | { |
| 624 | free( ctx ); |
| 625 | } |
| 626 | |
| 627 | const md_info_t sha512_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame^] | 628 | POLARSSL_MD_SHA512, |
| 629 | "SHA512", |
| 630 | 64, |
| 631 | sha512_starts_wrap, |
| 632 | sha512_update_wrap, |
| 633 | sha512_finish_wrap, |
| 634 | sha512_wrap, |
| 635 | sha512_file_wrap, |
| 636 | sha512_hmac_starts_wrap, |
| 637 | sha512_hmac_update_wrap, |
| 638 | sha512_hmac_finish_wrap, |
| 639 | sha512_hmac_reset_wrap, |
| 640 | sha512_hmac_wrap, |
| 641 | sha512_ctx_alloc, |
| 642 | sha512_ctx_free, |
Paul Bakker | 1737385 | 2011-01-06 14:20:01 +0000 | [diff] [blame] | 643 | }; |
| 644 | |
| 645 | #endif |
| 646 | |
| 647 | #endif |