blob: bca5ab2b639ac5dfbd2d8f6d3c4ef3a65e2880f7 [file] [log] [blame]
Paul Bakker17373852011-01-06 14:20:01 +00001/**
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 Bakkerb6c5d2e2013-06-25 16:25:17 +02008 * Copyright (C) 2006-2013, Brainspark B.V.
Paul Bakker17373852011-01-06 14:20:01 +00009 *
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 Bakkerf6543712012-03-05 14:01:29 +000035
36#if defined(POLARSSL_MD2_C)
Paul Bakker17373852011-01-06 14:20:01 +000037#include "polarssl/md2.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000038#endif
39
40#if defined(POLARSSL_MD4_C)
Paul Bakker17373852011-01-06 14:20:01 +000041#include "polarssl/md4.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000042#endif
43
44#if defined(POLARSSL_MD5_C)
Paul Bakker17373852011-01-06 14:20:01 +000045#include "polarssl/md5.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000046#endif
47
Paul Bakker61b699e2014-01-22 13:35:29 +010048#if defined(POLARSSL_RIPEMD160_C)
49#include "polarssl/ripemd160.h"
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +010050#endif
51
Paul Bakkerf6543712012-03-05 14:01:29 +000052#if defined(POLARSSL_SHA1_C)
Paul Bakker17373852011-01-06 14:20:01 +000053#include "polarssl/sha1.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000054#endif
55
Paul Bakker9e36f042013-06-30 14:34:05 +020056#if defined(POLARSSL_SHA256_C)
Paul Bakkerd2681d82013-06-30 14:49:12 +020057#include "polarssl/sha256.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000058#endif
59
Paul Bakker9e36f042013-06-30 14:34:05 +020060#if defined(POLARSSL_SHA512_C)
Paul Bakkerd2681d82013-06-30 14:49:12 +020061#include "polarssl/sha512.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000062#endif
Paul Bakker17373852011-01-06 14:20:01 +000063
Paul Bakker6e339b52013-07-03 13:37:05 +020064#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 Bakker17373852011-01-06 14:20:01 +000071#include <stdlib.h>
72
73#if defined(POLARSSL_MD2_C)
74
75static void md2_starts_wrap( void *ctx )
76{
77 md2_starts( (md2_context *) ctx );
78}
79
Paul Bakker23986e52011-04-24 08:57:21 +000080static void md2_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +000081{
82 md2_update( (md2_context *) ctx, input, ilen );
83}
84
85static void md2_finish_wrap( void *ctx, unsigned char *output )
86{
87 md2_finish( (md2_context *) ctx, output );
88}
89
Paul Bakkerb6c5d2e2013-06-25 16:25:17 +020090static int md2_file_wrap( const char *path, unsigned char *output )
Paul Bakker335db3f2011-04-25 15:28:35 +000091{
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 Bakker23986e52011-04-24 08:57:21 +0000101static void md2_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000102{
103 md2_hmac_starts( (md2_context *) ctx, key, keylen );
104}
105
Paul Bakker23986e52011-04-24 08:57:21 +0000106static void md2_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000107{
108 md2_hmac_update( (md2_context *) ctx, input, ilen );
109}
110
111static void md2_hmac_finish_wrap( void *ctx, unsigned char *output )
112{
113 md2_hmac_finish( (md2_context *) ctx, output );
114}
115
116static void md2_hmac_reset_wrap( void *ctx )
117{
118 md2_hmac_reset( (md2_context *) ctx );
119}
120
121static void * md2_ctx_alloc( void )
122{
Paul Bakker6e339b52013-07-03 13:37:05 +0200123 return polarssl_malloc( sizeof( md2_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000124}
125
126static void md2_ctx_free( void *ctx )
127{
Paul Bakker6e339b52013-07-03 13:37:05 +0200128 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000129}
130
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100131static void md2_process_wrap( void *ctx, const unsigned char *data )
132{
133 ((void) data);
134
135 md2_process( (md2_context *) ctx );
136}
137
Paul Bakker17373852011-01-06 14:20:01 +0000138const md_info_t md2_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000139 POLARSSL_MD_MD2,
140 "MD2",
141 16,
142 md2_starts_wrap,
143 md2_update_wrap,
144 md2_finish_wrap,
145 md2,
Paul Bakker335db3f2011-04-25 15:28:35 +0000146 md2_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000147 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 Bakker1bd3ae82013-03-13 10:26:44 +0100154 md2_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000155};
156
157#endif
158
159#if defined(POLARSSL_MD4_C)
160
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100161static void md4_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000162{
163 md4_starts( (md4_context *) ctx );
164}
165
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100166static void md4_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000167{
168 md4_update( (md4_context *) ctx, input, ilen );
169}
170
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100171static void md4_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000172{
173 md4_finish( (md4_context *) ctx, output );
174}
175
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100176static int md4_file_wrap( const char *path, unsigned char *output )
Paul Bakker335db3f2011-04-25 15:28:35 +0000177{
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 Bakkerd1df02a2013-03-13 10:31:31 +0100187static void md4_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000188{
189 md4_hmac_starts( (md4_context *) ctx, key, keylen );
190}
191
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100192static void md4_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000193{
194 md4_hmac_update( (md4_context *) ctx, input, ilen );
195}
196
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100197static void md4_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000198{
199 md4_hmac_finish( (md4_context *) ctx, output );
200}
201
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100202static void md4_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000203{
204 md4_hmac_reset( (md4_context *) ctx );
205}
206
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100207static void *md4_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000208{
Paul Bakker6e339b52013-07-03 13:37:05 +0200209 return polarssl_malloc( sizeof( md4_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000210}
211
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100212static void md4_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000213{
Paul Bakker6e339b52013-07-03 13:37:05 +0200214 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000215}
216
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100217static void md4_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100218{
219 md4_process( (md4_context *) ctx, data );
220}
221
Paul Bakker17373852011-01-06 14:20:01 +0000222const md_info_t md4_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000223 POLARSSL_MD_MD4,
224 "MD4",
225 16,
226 md4_starts_wrap,
227 md4_update_wrap,
228 md4_finish_wrap,
229 md4,
Paul Bakker335db3f2011-04-25 15:28:35 +0000230 md4_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000231 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 Bakker1bd3ae82013-03-13 10:26:44 +0100238 md4_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000239};
240
241#endif
242
243#if defined(POLARSSL_MD5_C)
244
245static void md5_starts_wrap( void *ctx )
246{
247 md5_starts( (md5_context *) ctx );
248}
249
Paul Bakker23986e52011-04-24 08:57:21 +0000250static void md5_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000251{
252 md5_update( (md5_context *) ctx, input, ilen );
253}
254
255static void md5_finish_wrap( void *ctx, unsigned char *output )
256{
257 md5_finish( (md5_context *) ctx, output );
258}
259
Paul Bakkerb6c5d2e2013-06-25 16:25:17 +0200260static int md5_file_wrap( const char *path, unsigned char *output )
Paul Bakker335db3f2011-04-25 15:28:35 +0000261{
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 Bakker23986e52011-04-24 08:57:21 +0000271static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000272{
273 md5_hmac_starts( (md5_context *) ctx, key, keylen );
274}
275
Paul Bakker23986e52011-04-24 08:57:21 +0000276static void md5_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000277{
278 md5_hmac_update( (md5_context *) ctx, input, ilen );
279}
280
281static void md5_hmac_finish_wrap( void *ctx, unsigned char *output )
282{
283 md5_hmac_finish( (md5_context *) ctx, output );
284}
285
286static void md5_hmac_reset_wrap( void *ctx )
287{
288 md5_hmac_reset( (md5_context *) ctx );
289}
290
291static void * md5_ctx_alloc( void )
292{
Paul Bakker6e339b52013-07-03 13:37:05 +0200293 return polarssl_malloc( sizeof( md5_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000294}
295
296static void md5_ctx_free( void *ctx )
297{
Paul Bakker6e339b52013-07-03 13:37:05 +0200298 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000299}
300
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100301static void md5_process_wrap( void *ctx, const unsigned char *data )
302{
303 md5_process( (md5_context *) ctx, data );
304}
305
Paul Bakker17373852011-01-06 14:20:01 +0000306const md_info_t md5_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000307 POLARSSL_MD_MD5,
308 "MD5",
309 16,
310 md5_starts_wrap,
311 md5_update_wrap,
312 md5_finish_wrap,
313 md5,
Paul Bakker335db3f2011-04-25 15:28:35 +0000314 md5_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000315 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 Bakker1bd3ae82013-03-13 10:26:44 +0100322 md5_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000323};
324
325#endif
326
Paul Bakker61b699e2014-01-22 13:35:29 +0100327#if defined(POLARSSL_RIPEMD160_C)
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100328
Paul Bakker61b699e2014-01-22 13:35:29 +0100329static void ripemd160_starts_wrap( void *ctx )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100330{
Paul Bakker61b699e2014-01-22 13:35:29 +0100331 ripemd160_starts( (ripemd160_context *) ctx );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100332}
333
Paul Bakker61b699e2014-01-22 13:35:29 +0100334static void ripemd160_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100335{
Paul Bakker61b699e2014-01-22 13:35:29 +0100336 ripemd160_update( (ripemd160_context *) ctx, input, ilen );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100337}
338
Paul Bakker61b699e2014-01-22 13:35:29 +0100339static void ripemd160_finish_wrap( void *ctx, unsigned char *output )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100340{
Paul Bakker61b699e2014-01-22 13:35:29 +0100341 ripemd160_finish( (ripemd160_context *) ctx, output );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100342}
343
Paul Bakker61b699e2014-01-22 13:35:29 +0100344static int ripemd160_file_wrap( const char *path, unsigned char *output )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100345{
346#if defined(POLARSSL_FS_IO)
Paul Bakker61b699e2014-01-22 13:35:29 +0100347 return ripemd160_file( path, output );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100348#else
349 ((void) path);
350 ((void) output);
351 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
352#endif
353}
354
Paul Bakker61b699e2014-01-22 13:35:29 +0100355static void ripemd160_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100356{
Paul Bakker61b699e2014-01-22 13:35:29 +0100357 ripemd160_hmac_starts( (ripemd160_context *) ctx, key, keylen );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100358}
359
Paul Bakker61b699e2014-01-22 13:35:29 +0100360static void ripemd160_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100361{
Paul Bakker61b699e2014-01-22 13:35:29 +0100362 ripemd160_hmac_update( (ripemd160_context *) ctx, input, ilen );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100363}
364
Paul Bakker61b699e2014-01-22 13:35:29 +0100365static void ripemd160_hmac_finish_wrap( void *ctx, unsigned char *output )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100366{
Paul Bakker61b699e2014-01-22 13:35:29 +0100367 ripemd160_hmac_finish( (ripemd160_context *) ctx, output );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100368}
369
Paul Bakker61b699e2014-01-22 13:35:29 +0100370static void ripemd160_hmac_reset_wrap( void *ctx )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100371{
Paul Bakker61b699e2014-01-22 13:35:29 +0100372 ripemd160_hmac_reset( (ripemd160_context *) ctx );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100373}
374
Paul Bakker61b699e2014-01-22 13:35:29 +0100375static void * ripemd160_ctx_alloc( void )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100376{
Paul Bakker61b699e2014-01-22 13:35:29 +0100377 return polarssl_malloc( sizeof( ripemd160_context ) );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100378}
379
Paul Bakker61b699e2014-01-22 13:35:29 +0100380static void ripemd160_ctx_free( void *ctx )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100381{
382 polarssl_free( ctx );
383}
384
Paul Bakker61b699e2014-01-22 13:35:29 +0100385static void ripemd160_process_wrap( void *ctx, const unsigned char *data )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100386{
Paul Bakker61b699e2014-01-22 13:35:29 +0100387 ripemd160_process( (ripemd160_context *) ctx, data );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100388}
389
Paul Bakker61b699e2014-01-22 13:35:29 +0100390const md_info_t ripemd160_info = {
391 POLARSSL_MD_RIPEMD160,
392 "RIPEMD160",
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100393 20,
Paul Bakker61b699e2014-01-22 13:35:29 +0100394 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é-Gonnarde4d47a62014-01-17 20:41:32 +0100407};
408
409#endif
410
Paul Bakker17373852011-01-06 14:20:01 +0000411#if defined(POLARSSL_SHA1_C)
412
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100413static void sha1_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000414{
415 sha1_starts( (sha1_context *) ctx );
416}
417
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100418static void sha1_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000419{
420 sha1_update( (sha1_context *) ctx, input, ilen );
421}
422
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100423static void sha1_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000424{
425 sha1_finish( (sha1_context *) ctx, output );
426}
427
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100428static int sha1_file_wrap( const char *path, unsigned char *output )
Paul Bakker335db3f2011-04-25 15:28:35 +0000429{
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 Bakkerd1df02a2013-03-13 10:31:31 +0100439static void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000440{
441 sha1_hmac_starts( (sha1_context *) ctx, key, keylen );
442}
443
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100444static void sha1_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000445{
446 sha1_hmac_update( (sha1_context *) ctx, input, ilen );
447}
448
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100449static void sha1_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000450{
451 sha1_hmac_finish( (sha1_context *) ctx, output );
452}
453
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100454static void sha1_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000455{
456 sha1_hmac_reset( (sha1_context *) ctx );
457}
458
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100459static void * sha1_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000460{
Paul Bakker6e339b52013-07-03 13:37:05 +0200461 return polarssl_malloc( sizeof( sha1_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000462}
463
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100464static void sha1_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000465{
Paul Bakker6e339b52013-07-03 13:37:05 +0200466 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000467}
468
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100469static void sha1_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100470{
471 sha1_process( (sha1_context *) ctx, data );
472}
473
Paul Bakker17373852011-01-06 14:20:01 +0000474const md_info_t sha1_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000475 POLARSSL_MD_SHA1,
476 "SHA1",
477 20,
478 sha1_starts_wrap,
479 sha1_update_wrap,
480 sha1_finish_wrap,
481 sha1,
Paul Bakker335db3f2011-04-25 15:28:35 +0000482 sha1_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000483 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 Bakker1bd3ae82013-03-13 10:26:44 +0100490 sha1_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000491};
492
493#endif
494
495/*
496 * Wrappers for generic message digests
497 */
Paul Bakker9e36f042013-06-30 14:34:05 +0200498#if defined(POLARSSL_SHA256_C)
Paul Bakker17373852011-01-06 14:20:01 +0000499
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100500static void sha224_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000501{
Paul Bakker9e36f042013-06-30 14:34:05 +0200502 sha256_starts( (sha256_context *) ctx, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000503}
504
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100505static void sha224_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000506{
Paul Bakker9e36f042013-06-30 14:34:05 +0200507 sha256_update( (sha256_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000508}
509
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100510static void sha224_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000511{
Paul Bakker9e36f042013-06-30 14:34:05 +0200512 sha256_finish( (sha256_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000513}
514
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100515static void sha224_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000516 unsigned char *output )
517{
Paul Bakker9e36f042013-06-30 14:34:05 +0200518 sha256( input, ilen, output, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000519}
520
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100521static int sha224_file_wrap( const char *path, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000522{
Paul Bakker335db3f2011-04-25 15:28:35 +0000523#if defined(POLARSSL_FS_IO)
Paul Bakker9e36f042013-06-30 14:34:05 +0200524 return sha256_file( path, output, 1 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000525#else
526 ((void) path);
527 ((void) output);
528 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
529#endif
Paul Bakker17373852011-01-06 14:20:01 +0000530}
531
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100532static void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000533{
Paul Bakker9e36f042013-06-30 14:34:05 +0200534 sha256_hmac_starts( (sha256_context *) ctx, key, keylen, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000535}
536
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100537static void sha224_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000538{
Paul Bakker9e36f042013-06-30 14:34:05 +0200539 sha256_hmac_update( (sha256_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000540}
541
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100542static void sha224_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000543{
Paul Bakker9e36f042013-06-30 14:34:05 +0200544 sha256_hmac_finish( (sha256_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000545}
546
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100547static void sha224_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000548{
Paul Bakker9e36f042013-06-30 14:34:05 +0200549 sha256_hmac_reset( (sha256_context *) ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000550}
551
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100552static void sha224_hmac_wrap( const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000553 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000554 unsigned char *output )
555{
Paul Bakker9e36f042013-06-30 14:34:05 +0200556 sha256_hmac( key, keylen, input, ilen, output, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000557}
558
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100559static void * sha224_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000560{
Paul Bakker6e339b52013-07-03 13:37:05 +0200561 return polarssl_malloc( sizeof( sha256_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000562}
563
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100564static void sha224_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000565{
Paul Bakker6e339b52013-07-03 13:37:05 +0200566 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000567}
568
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100569static void sha224_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100570{
Paul Bakker9e36f042013-06-30 14:34:05 +0200571 sha256_process( (sha256_context *) ctx, data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100572}
573
Paul Bakker17373852011-01-06 14:20:01 +0000574const md_info_t sha224_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000575 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 Bakker1bd3ae82013-03-13 10:26:44 +0100590 sha224_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000591};
592
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100593static void sha256_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000594{
Paul Bakker9e36f042013-06-30 14:34:05 +0200595 sha256_starts( (sha256_context *) ctx, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000596}
597
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100598static void sha256_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000599{
Paul Bakker9e36f042013-06-30 14:34:05 +0200600 sha256_update( (sha256_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000601}
602
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100603static void sha256_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000604{
Paul Bakker9e36f042013-06-30 14:34:05 +0200605 sha256_finish( (sha256_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000606}
607
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100608static void sha256_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000609 unsigned char *output )
610{
Paul Bakker9e36f042013-06-30 14:34:05 +0200611 sha256( input, ilen, output, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000612}
613
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100614static int sha256_file_wrap( const char *path, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000615{
Paul Bakker335db3f2011-04-25 15:28:35 +0000616#if defined(POLARSSL_FS_IO)
Paul Bakker9e36f042013-06-30 14:34:05 +0200617 return sha256_file( path, output, 0 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000618#else
619 ((void) path);
620 ((void) output);
621 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
622#endif
Paul Bakker17373852011-01-06 14:20:01 +0000623}
624
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100625static void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000626{
Paul Bakker9e36f042013-06-30 14:34:05 +0200627 sha256_hmac_starts( (sha256_context *) ctx, key, keylen, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000628}
629
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100630static void sha256_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000631{
Paul Bakker9e36f042013-06-30 14:34:05 +0200632 sha256_hmac_update( (sha256_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000633}
634
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100635static void sha256_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000636{
Paul Bakker9e36f042013-06-30 14:34:05 +0200637 sha256_hmac_finish( (sha256_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000638}
639
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100640static void sha256_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000641{
Paul Bakker9e36f042013-06-30 14:34:05 +0200642 sha256_hmac_reset( (sha256_context *) ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000643}
644
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100645static void sha256_hmac_wrap( const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000646 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000647 unsigned char *output )
648{
Paul Bakker9e36f042013-06-30 14:34:05 +0200649 sha256_hmac( key, keylen, input, ilen, output, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000650}
651
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100652static void * sha256_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000653{
Paul Bakker6e339b52013-07-03 13:37:05 +0200654 return polarssl_malloc( sizeof( sha256_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000655}
656
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100657static void sha256_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000658{
Paul Bakker6e339b52013-07-03 13:37:05 +0200659 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000660}
661
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100662static void sha256_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100663{
Paul Bakker9e36f042013-06-30 14:34:05 +0200664 sha256_process( (sha256_context *) ctx, data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100665}
666
Paul Bakker17373852011-01-06 14:20:01 +0000667const md_info_t sha256_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000668 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 Bakker1bd3ae82013-03-13 10:26:44 +0100683 sha256_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000684};
685
686#endif
687
Paul Bakker9e36f042013-06-30 14:34:05 +0200688#if defined(POLARSSL_SHA512_C)
Paul Bakker17373852011-01-06 14:20:01 +0000689
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100690static void sha384_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000691{
Paul Bakker9e36f042013-06-30 14:34:05 +0200692 sha512_starts( (sha512_context *) ctx, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000693}
694
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100695static void sha384_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000696{
Paul Bakker9e36f042013-06-30 14:34:05 +0200697 sha512_update( (sha512_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000698}
699
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100700static void sha384_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000701{
Paul Bakker9e36f042013-06-30 14:34:05 +0200702 sha512_finish( (sha512_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000703}
704
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100705static void sha384_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000706 unsigned char *output )
707{
Paul Bakker9e36f042013-06-30 14:34:05 +0200708 sha512( input, ilen, output, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000709}
710
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100711static int sha384_file_wrap( const char *path, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000712{
Paul Bakker335db3f2011-04-25 15:28:35 +0000713#if defined(POLARSSL_FS_IO)
Paul Bakker9e36f042013-06-30 14:34:05 +0200714 return sha512_file( path, output, 1 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000715#else
716 ((void) path);
717 ((void) output);
718 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
719#endif
Paul Bakker17373852011-01-06 14:20:01 +0000720}
721
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100722static void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000723{
Paul Bakker9e36f042013-06-30 14:34:05 +0200724 sha512_hmac_starts( (sha512_context *) ctx, key, keylen, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000725}
726
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100727static void sha384_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000728{
Paul Bakker9e36f042013-06-30 14:34:05 +0200729 sha512_hmac_update( (sha512_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000730}
731
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100732static void sha384_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000733{
Paul Bakker9e36f042013-06-30 14:34:05 +0200734 sha512_hmac_finish( (sha512_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000735}
736
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100737static void sha384_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000738{
Paul Bakker9e36f042013-06-30 14:34:05 +0200739 sha512_hmac_reset( (sha512_context *) ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000740}
741
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100742static void sha384_hmac_wrap( const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000743 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000744 unsigned char *output )
745{
Paul Bakker9e36f042013-06-30 14:34:05 +0200746 sha512_hmac( key, keylen, input, ilen, output, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000747}
748
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100749static void * sha384_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000750{
Paul Bakker6e339b52013-07-03 13:37:05 +0200751 return polarssl_malloc( sizeof( sha512_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000752}
753
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100754static void sha384_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000755{
Paul Bakker6e339b52013-07-03 13:37:05 +0200756 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000757}
758
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100759static void sha384_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100760{
Paul Bakker9e36f042013-06-30 14:34:05 +0200761 sha512_process( (sha512_context *) ctx, data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100762}
763
Paul Bakker17373852011-01-06 14:20:01 +0000764const md_info_t sha384_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000765 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 Bakker1bd3ae82013-03-13 10:26:44 +0100780 sha384_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000781};
782
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100783static void sha512_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000784{
Paul Bakker9e36f042013-06-30 14:34:05 +0200785 sha512_starts( (sha512_context *) ctx, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000786}
787
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100788static void sha512_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000789{
Paul Bakker9e36f042013-06-30 14:34:05 +0200790 sha512_update( (sha512_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000791}
792
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100793static void sha512_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000794{
Paul Bakker9e36f042013-06-30 14:34:05 +0200795 sha512_finish( (sha512_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000796}
797
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100798static void sha512_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000799 unsigned char *output )
800{
Paul Bakker9e36f042013-06-30 14:34:05 +0200801 sha512( input, ilen, output, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000802}
803
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100804static int sha512_file_wrap( const char *path, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000805{
Paul Bakker335db3f2011-04-25 15:28:35 +0000806#if defined(POLARSSL_FS_IO)
Paul Bakker9e36f042013-06-30 14:34:05 +0200807 return sha512_file( path, output, 0 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000808#else
809 ((void) path);
810 ((void) output);
811 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
812#endif
Paul Bakker17373852011-01-06 14:20:01 +0000813}
814
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100815static void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000816{
Paul Bakker9e36f042013-06-30 14:34:05 +0200817 sha512_hmac_starts( (sha512_context *) ctx, key, keylen, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000818}
819
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100820static void sha512_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000821{
Paul Bakker9e36f042013-06-30 14:34:05 +0200822 sha512_hmac_update( (sha512_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000823}
824
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100825static void sha512_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000826{
Paul Bakker9e36f042013-06-30 14:34:05 +0200827 sha512_hmac_finish( (sha512_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000828}
829
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100830static void sha512_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000831{
Paul Bakker9e36f042013-06-30 14:34:05 +0200832 sha512_hmac_reset( (sha512_context *) ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000833}
834
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100835static void sha512_hmac_wrap( const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000836 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000837 unsigned char *output )
838{
Paul Bakker9e36f042013-06-30 14:34:05 +0200839 sha512_hmac( key, keylen, input, ilen, output, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000840}
841
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100842static void * sha512_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000843{
Paul Bakker6e339b52013-07-03 13:37:05 +0200844 return polarssl_malloc( sizeof( sha512_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000845}
846
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100847static void sha512_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000848{
Paul Bakker6e339b52013-07-03 13:37:05 +0200849 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000850}
851
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100852static void sha512_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100853{
Paul Bakker9e36f042013-06-30 14:34:05 +0200854 sha512_process( (sha512_context *) ctx, data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100855}
856
Paul Bakker17373852011-01-06 14:20:01 +0000857const md_info_t sha512_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000858 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 Bakker1bd3ae82013-03-13 10:26:44 +0100873 sha512_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000874};
875
876#endif
877
878#endif