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