blob: 0b091e3c51a8855060d6b63428932d727f2375fb [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 Bakker7dc4c442014-02-01 22:50:26 +01008 * Copyright (C) 2006-2014, 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
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker17373852011-01-06 14:20:01 +000031#include "polarssl/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020032#else
33#include POLARSSL_CONFIG_FILE
34#endif
Paul Bakker17373852011-01-06 14:20:01 +000035
36#if defined(POLARSSL_MD_C)
37
38#include "polarssl/md_wrap.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000039
40#if defined(POLARSSL_MD2_C)
Paul Bakker17373852011-01-06 14:20:01 +000041#include "polarssl/md2.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000042#endif
43
44#if defined(POLARSSL_MD4_C)
Paul Bakker17373852011-01-06 14:20:01 +000045#include "polarssl/md4.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000046#endif
47
48#if defined(POLARSSL_MD5_C)
Paul Bakker17373852011-01-06 14:20:01 +000049#include "polarssl/md5.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000050#endif
51
Paul Bakker61b699e2014-01-22 13:35:29 +010052#if defined(POLARSSL_RIPEMD160_C)
53#include "polarssl/ripemd160.h"
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +010054#endif
55
Paul Bakkerf6543712012-03-05 14:01:29 +000056#if defined(POLARSSL_SHA1_C)
Paul Bakker17373852011-01-06 14:20:01 +000057#include "polarssl/sha1.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000058#endif
59
Paul Bakker9e36f042013-06-30 14:34:05 +020060#if defined(POLARSSL_SHA256_C)
Paul Bakkerd2681d82013-06-30 14:49:12 +020061#include "polarssl/sha256.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000062#endif
63
Paul Bakker9e36f042013-06-30 14:34:05 +020064#if defined(POLARSSL_SHA512_C)
Paul Bakkerd2681d82013-06-30 14:49:12 +020065#include "polarssl/sha512.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000066#endif
Paul Bakker17373852011-01-06 14:20:01 +000067
Paul Bakker7dc4c442014-02-01 22:50:26 +010068#if defined(POLARSSL_PLATFORM_C)
69#include "polarssl/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020070#else
71#define polarssl_malloc malloc
72#define polarssl_free free
73#endif
74
Paul Bakker17373852011-01-06 14:20:01 +000075#include <stdlib.h>
76
77#if defined(POLARSSL_MD2_C)
78
79static void md2_starts_wrap( void *ctx )
80{
81 md2_starts( (md2_context *) ctx );
82}
83
Paul Bakker23986e52011-04-24 08:57:21 +000084static void md2_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +000085{
86 md2_update( (md2_context *) ctx, input, ilen );
87}
88
89static void md2_finish_wrap( void *ctx, unsigned char *output )
90{
91 md2_finish( (md2_context *) ctx, output );
92}
93
Paul Bakkerb6c5d2e2013-06-25 16:25:17 +020094static int md2_file_wrap( const char *path, unsigned char *output )
Paul Bakker335db3f2011-04-25 15:28:35 +000095{
96#if defined(POLARSSL_FS_IO)
97 return md2_file( path, output );
98#else
99 ((void) path);
100 ((void) output);
101 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
102#endif
103}
104
Paul Bakker23986e52011-04-24 08:57:21 +0000105static void md2_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000106{
107 md2_hmac_starts( (md2_context *) ctx, key, keylen );
108}
109
Paul Bakker23986e52011-04-24 08:57:21 +0000110static void md2_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000111{
112 md2_hmac_update( (md2_context *) ctx, input, ilen );
113}
114
115static void md2_hmac_finish_wrap( void *ctx, unsigned char *output )
116{
117 md2_hmac_finish( (md2_context *) ctx, output );
118}
119
120static void md2_hmac_reset_wrap( void *ctx )
121{
122 md2_hmac_reset( (md2_context *) ctx );
123}
124
125static void * md2_ctx_alloc( void )
126{
Paul Bakker6e339b52013-07-03 13:37:05 +0200127 return polarssl_malloc( sizeof( md2_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000128}
129
130static void md2_ctx_free( void *ctx )
131{
Paul Bakker6e339b52013-07-03 13:37:05 +0200132 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000133}
134
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100135static void md2_process_wrap( void *ctx, const unsigned char *data )
136{
137 ((void) data);
138
139 md2_process( (md2_context *) ctx );
140}
141
Paul Bakker17373852011-01-06 14:20:01 +0000142const md_info_t md2_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000143 POLARSSL_MD_MD2,
144 "MD2",
145 16,
146 md2_starts_wrap,
147 md2_update_wrap,
148 md2_finish_wrap,
149 md2,
Paul Bakker335db3f2011-04-25 15:28:35 +0000150 md2_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000151 md2_hmac_starts_wrap,
152 md2_hmac_update_wrap,
153 md2_hmac_finish_wrap,
154 md2_hmac_reset_wrap,
155 md2_hmac,
156 md2_ctx_alloc,
157 md2_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100158 md2_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000159};
160
161#endif
162
163#if defined(POLARSSL_MD4_C)
164
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100165static void md4_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000166{
167 md4_starts( (md4_context *) ctx );
168}
169
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100170static void md4_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000171{
172 md4_update( (md4_context *) ctx, input, ilen );
173}
174
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100175static void md4_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000176{
177 md4_finish( (md4_context *) ctx, output );
178}
179
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100180static int md4_file_wrap( const char *path, unsigned char *output )
Paul Bakker335db3f2011-04-25 15:28:35 +0000181{
182#if defined(POLARSSL_FS_IO)
183 return md4_file( path, output );
184#else
185 ((void) path);
186 ((void) output);
187 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
188#endif
189}
190
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100191static void md4_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000192{
193 md4_hmac_starts( (md4_context *) ctx, key, keylen );
194}
195
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100196static void md4_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000197{
198 md4_hmac_update( (md4_context *) ctx, input, ilen );
199}
200
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100201static void md4_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000202{
203 md4_hmac_finish( (md4_context *) ctx, output );
204}
205
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100206static void md4_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000207{
208 md4_hmac_reset( (md4_context *) ctx );
209}
210
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100211static void *md4_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000212{
Paul Bakker6e339b52013-07-03 13:37:05 +0200213 return polarssl_malloc( sizeof( md4_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000214}
215
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100216static void md4_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000217{
Paul Bakker6e339b52013-07-03 13:37:05 +0200218 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000219}
220
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100221static void md4_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100222{
223 md4_process( (md4_context *) ctx, data );
224}
225
Paul Bakker17373852011-01-06 14:20:01 +0000226const md_info_t md4_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000227 POLARSSL_MD_MD4,
228 "MD4",
229 16,
230 md4_starts_wrap,
231 md4_update_wrap,
232 md4_finish_wrap,
233 md4,
Paul Bakker335db3f2011-04-25 15:28:35 +0000234 md4_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000235 md4_hmac_starts_wrap,
236 md4_hmac_update_wrap,
237 md4_hmac_finish_wrap,
238 md4_hmac_reset_wrap,
239 md4_hmac,
240 md4_ctx_alloc,
241 md4_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100242 md4_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000243};
244
245#endif
246
247#if defined(POLARSSL_MD5_C)
248
249static void md5_starts_wrap( void *ctx )
250{
251 md5_starts( (md5_context *) ctx );
252}
253
Paul Bakker23986e52011-04-24 08:57:21 +0000254static void md5_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000255{
256 md5_update( (md5_context *) ctx, input, ilen );
257}
258
259static void md5_finish_wrap( void *ctx, unsigned char *output )
260{
261 md5_finish( (md5_context *) ctx, output );
262}
263
Paul Bakkerb6c5d2e2013-06-25 16:25:17 +0200264static int md5_file_wrap( const char *path, unsigned char *output )
Paul Bakker335db3f2011-04-25 15:28:35 +0000265{
266#if defined(POLARSSL_FS_IO)
267 return md5_file( path, output );
268#else
269 ((void) path);
270 ((void) output);
271 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
272#endif
273}
274
Paul Bakker23986e52011-04-24 08:57:21 +0000275static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000276{
277 md5_hmac_starts( (md5_context *) ctx, key, keylen );
278}
279
Paul Bakker23986e52011-04-24 08:57:21 +0000280static void md5_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000281{
282 md5_hmac_update( (md5_context *) ctx, input, ilen );
283}
284
285static void md5_hmac_finish_wrap( void *ctx, unsigned char *output )
286{
287 md5_hmac_finish( (md5_context *) ctx, output );
288}
289
290static void md5_hmac_reset_wrap( void *ctx )
291{
292 md5_hmac_reset( (md5_context *) ctx );
293}
294
295static void * md5_ctx_alloc( void )
296{
Paul Bakker6e339b52013-07-03 13:37:05 +0200297 return polarssl_malloc( sizeof( md5_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000298}
299
300static void md5_ctx_free( void *ctx )
301{
Paul Bakker6e339b52013-07-03 13:37:05 +0200302 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000303}
304
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100305static void md5_process_wrap( void *ctx, const unsigned char *data )
306{
307 md5_process( (md5_context *) ctx, data );
308}
309
Paul Bakker17373852011-01-06 14:20:01 +0000310const md_info_t md5_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000311 POLARSSL_MD_MD5,
312 "MD5",
313 16,
314 md5_starts_wrap,
315 md5_update_wrap,
316 md5_finish_wrap,
317 md5,
Paul Bakker335db3f2011-04-25 15:28:35 +0000318 md5_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000319 md5_hmac_starts_wrap,
320 md5_hmac_update_wrap,
321 md5_hmac_finish_wrap,
322 md5_hmac_reset_wrap,
323 md5_hmac,
324 md5_ctx_alloc,
325 md5_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100326 md5_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000327};
328
329#endif
330
Paul Bakker61b699e2014-01-22 13:35:29 +0100331#if defined(POLARSSL_RIPEMD160_C)
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100332
Paul Bakker61b699e2014-01-22 13:35:29 +0100333static void ripemd160_starts_wrap( void *ctx )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100334{
Paul Bakker61b699e2014-01-22 13:35:29 +0100335 ripemd160_starts( (ripemd160_context *) ctx );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100336}
337
Paul Bakker61b699e2014-01-22 13:35:29 +0100338static void ripemd160_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100339{
Paul Bakker61b699e2014-01-22 13:35:29 +0100340 ripemd160_update( (ripemd160_context *) ctx, input, ilen );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100341}
342
Paul Bakker61b699e2014-01-22 13:35:29 +0100343static void ripemd160_finish_wrap( void *ctx, unsigned char *output )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100344{
Paul Bakker61b699e2014-01-22 13:35:29 +0100345 ripemd160_finish( (ripemd160_context *) ctx, output );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100346}
347
Paul Bakker61b699e2014-01-22 13:35:29 +0100348static int ripemd160_file_wrap( const char *path, unsigned char *output )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100349{
350#if defined(POLARSSL_FS_IO)
Paul Bakker61b699e2014-01-22 13:35:29 +0100351 return ripemd160_file( path, output );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100352#else
353 ((void) path);
354 ((void) output);
355 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
356#endif
357}
358
Paul Bakker61b699e2014-01-22 13:35:29 +0100359static void ripemd160_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100360{
Paul Bakker61b699e2014-01-22 13:35:29 +0100361 ripemd160_hmac_starts( (ripemd160_context *) ctx, key, keylen );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100362}
363
Paul Bakker61b699e2014-01-22 13:35:29 +0100364static void ripemd160_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100365{
Paul Bakker61b699e2014-01-22 13:35:29 +0100366 ripemd160_hmac_update( (ripemd160_context *) ctx, input, ilen );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100367}
368
Paul Bakker61b699e2014-01-22 13:35:29 +0100369static void ripemd160_hmac_finish_wrap( void *ctx, unsigned char *output )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100370{
Paul Bakker61b699e2014-01-22 13:35:29 +0100371 ripemd160_hmac_finish( (ripemd160_context *) ctx, output );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100372}
373
Paul Bakker61b699e2014-01-22 13:35:29 +0100374static void ripemd160_hmac_reset_wrap( void *ctx )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100375{
Paul Bakker61b699e2014-01-22 13:35:29 +0100376 ripemd160_hmac_reset( (ripemd160_context *) ctx );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100377}
378
Paul Bakker61b699e2014-01-22 13:35:29 +0100379static void * ripemd160_ctx_alloc( void )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100380{
Paul Bakker61b699e2014-01-22 13:35:29 +0100381 return polarssl_malloc( sizeof( ripemd160_context ) );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100382}
383
Paul Bakker61b699e2014-01-22 13:35:29 +0100384static void ripemd160_ctx_free( void *ctx )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100385{
386 polarssl_free( ctx );
387}
388
Paul Bakker61b699e2014-01-22 13:35:29 +0100389static void ripemd160_process_wrap( void *ctx, const unsigned char *data )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100390{
Paul Bakker61b699e2014-01-22 13:35:29 +0100391 ripemd160_process( (ripemd160_context *) ctx, data );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100392}
393
Paul Bakker61b699e2014-01-22 13:35:29 +0100394const md_info_t ripemd160_info = {
395 POLARSSL_MD_RIPEMD160,
396 "RIPEMD160",
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100397 20,
Paul Bakker61b699e2014-01-22 13:35:29 +0100398 ripemd160_starts_wrap,
399 ripemd160_update_wrap,
400 ripemd160_finish_wrap,
401 ripemd160,
402 ripemd160_file_wrap,
403 ripemd160_hmac_starts_wrap,
404 ripemd160_hmac_update_wrap,
405 ripemd160_hmac_finish_wrap,
406 ripemd160_hmac_reset_wrap,
407 ripemd160_hmac,
408 ripemd160_ctx_alloc,
409 ripemd160_ctx_free,
410 ripemd160_process_wrap,
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100411};
412
413#endif
414
Paul Bakker17373852011-01-06 14:20:01 +0000415#if defined(POLARSSL_SHA1_C)
416
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100417static void sha1_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000418{
419 sha1_starts( (sha1_context *) ctx );
420}
421
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100422static void sha1_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000423{
424 sha1_update( (sha1_context *) ctx, input, ilen );
425}
426
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100427static void sha1_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000428{
429 sha1_finish( (sha1_context *) ctx, output );
430}
431
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100432static int sha1_file_wrap( const char *path, unsigned char *output )
Paul Bakker335db3f2011-04-25 15:28:35 +0000433{
434#if defined(POLARSSL_FS_IO)
435 return sha1_file( path, output );
436#else
437 ((void) path);
438 ((void) output);
439 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
440#endif
441}
442
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100443static void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000444{
445 sha1_hmac_starts( (sha1_context *) ctx, key, keylen );
446}
447
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100448static void sha1_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000449{
450 sha1_hmac_update( (sha1_context *) ctx, input, ilen );
451}
452
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100453static void sha1_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000454{
455 sha1_hmac_finish( (sha1_context *) ctx, output );
456}
457
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100458static void sha1_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000459{
460 sha1_hmac_reset( (sha1_context *) ctx );
461}
462
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100463static void * sha1_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000464{
Paul Bakker6e339b52013-07-03 13:37:05 +0200465 return polarssl_malloc( sizeof( sha1_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000466}
467
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100468static void sha1_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000469{
Paul Bakker6e339b52013-07-03 13:37:05 +0200470 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000471}
472
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100473static void sha1_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100474{
475 sha1_process( (sha1_context *) ctx, data );
476}
477
Paul Bakker17373852011-01-06 14:20:01 +0000478const md_info_t sha1_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000479 POLARSSL_MD_SHA1,
480 "SHA1",
481 20,
482 sha1_starts_wrap,
483 sha1_update_wrap,
484 sha1_finish_wrap,
485 sha1,
Paul Bakker335db3f2011-04-25 15:28:35 +0000486 sha1_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000487 sha1_hmac_starts_wrap,
488 sha1_hmac_update_wrap,
489 sha1_hmac_finish_wrap,
490 sha1_hmac_reset_wrap,
491 sha1_hmac,
492 sha1_ctx_alloc,
493 sha1_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100494 sha1_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000495};
496
497#endif
498
499/*
500 * Wrappers for generic message digests
501 */
Paul Bakker9e36f042013-06-30 14:34:05 +0200502#if defined(POLARSSL_SHA256_C)
Paul Bakker17373852011-01-06 14:20:01 +0000503
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100504static void sha224_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000505{
Paul Bakker9e36f042013-06-30 14:34:05 +0200506 sha256_starts( (sha256_context *) ctx, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000507}
508
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100509static void sha224_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000510{
Paul Bakker9e36f042013-06-30 14:34:05 +0200511 sha256_update( (sha256_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000512}
513
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100514static void sha224_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000515{
Paul Bakker9e36f042013-06-30 14:34:05 +0200516 sha256_finish( (sha256_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000517}
518
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100519static void sha224_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000520 unsigned char *output )
521{
Paul Bakker9e36f042013-06-30 14:34:05 +0200522 sha256( input, ilen, output, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000523}
524
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100525static int sha224_file_wrap( const char *path, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000526{
Paul Bakker335db3f2011-04-25 15:28:35 +0000527#if defined(POLARSSL_FS_IO)
Paul Bakker9e36f042013-06-30 14:34:05 +0200528 return sha256_file( path, output, 1 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000529#else
530 ((void) path);
531 ((void) output);
532 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
533#endif
Paul Bakker17373852011-01-06 14:20:01 +0000534}
535
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100536static void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000537{
Paul Bakker9e36f042013-06-30 14:34:05 +0200538 sha256_hmac_starts( (sha256_context *) ctx, key, keylen, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000539}
540
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100541static void sha224_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000542{
Paul Bakker9e36f042013-06-30 14:34:05 +0200543 sha256_hmac_update( (sha256_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000544}
545
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100546static void sha224_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000547{
Paul Bakker9e36f042013-06-30 14:34:05 +0200548 sha256_hmac_finish( (sha256_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000549}
550
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100551static void sha224_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000552{
Paul Bakker9e36f042013-06-30 14:34:05 +0200553 sha256_hmac_reset( (sha256_context *) ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000554}
555
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100556static void sha224_hmac_wrap( const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000557 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000558 unsigned char *output )
559{
Paul Bakker9e36f042013-06-30 14:34:05 +0200560 sha256_hmac( key, keylen, input, ilen, output, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000561}
562
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100563static void * sha224_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000564{
Paul Bakker6e339b52013-07-03 13:37:05 +0200565 return polarssl_malloc( sizeof( sha256_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000566}
567
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100568static void sha224_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000569{
Paul Bakker6e339b52013-07-03 13:37:05 +0200570 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000571}
572
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100573static void sha224_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100574{
Paul Bakker9e36f042013-06-30 14:34:05 +0200575 sha256_process( (sha256_context *) ctx, data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100576}
577
Paul Bakker17373852011-01-06 14:20:01 +0000578const md_info_t sha224_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000579 POLARSSL_MD_SHA224,
580 "SHA224",
581 28,
582 sha224_starts_wrap,
583 sha224_update_wrap,
584 sha224_finish_wrap,
585 sha224_wrap,
586 sha224_file_wrap,
587 sha224_hmac_starts_wrap,
588 sha224_hmac_update_wrap,
589 sha224_hmac_finish_wrap,
590 sha224_hmac_reset_wrap,
591 sha224_hmac_wrap,
592 sha224_ctx_alloc,
593 sha224_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100594 sha224_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000595};
596
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100597static void sha256_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000598{
Paul Bakker9e36f042013-06-30 14:34:05 +0200599 sha256_starts( (sha256_context *) ctx, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000600}
601
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100602static void sha256_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000603{
Paul Bakker9e36f042013-06-30 14:34:05 +0200604 sha256_update( (sha256_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000605}
606
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100607static void sha256_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000608{
Paul Bakker9e36f042013-06-30 14:34:05 +0200609 sha256_finish( (sha256_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000610}
611
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100612static void sha256_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000613 unsigned char *output )
614{
Paul Bakker9e36f042013-06-30 14:34:05 +0200615 sha256( input, ilen, output, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000616}
617
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100618static int sha256_file_wrap( const char *path, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000619{
Paul Bakker335db3f2011-04-25 15:28:35 +0000620#if defined(POLARSSL_FS_IO)
Paul Bakker9e36f042013-06-30 14:34:05 +0200621 return sha256_file( path, output, 0 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000622#else
623 ((void) path);
624 ((void) output);
625 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
626#endif
Paul Bakker17373852011-01-06 14:20:01 +0000627}
628
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100629static void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000630{
Paul Bakker9e36f042013-06-30 14:34:05 +0200631 sha256_hmac_starts( (sha256_context *) ctx, key, keylen, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000632}
633
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100634static void sha256_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000635{
Paul Bakker9e36f042013-06-30 14:34:05 +0200636 sha256_hmac_update( (sha256_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000637}
638
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100639static void sha256_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000640{
Paul Bakker9e36f042013-06-30 14:34:05 +0200641 sha256_hmac_finish( (sha256_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000642}
643
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100644static void sha256_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000645{
Paul Bakker9e36f042013-06-30 14:34:05 +0200646 sha256_hmac_reset( (sha256_context *) ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000647}
648
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100649static void sha256_hmac_wrap( const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000650 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000651 unsigned char *output )
652{
Paul Bakker9e36f042013-06-30 14:34:05 +0200653 sha256_hmac( key, keylen, input, ilen, output, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000654}
655
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100656static void * sha256_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000657{
Paul Bakker6e339b52013-07-03 13:37:05 +0200658 return polarssl_malloc( sizeof( sha256_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000659}
660
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100661static void sha256_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000662{
Paul Bakker6e339b52013-07-03 13:37:05 +0200663 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000664}
665
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100666static void sha256_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100667{
Paul Bakker9e36f042013-06-30 14:34:05 +0200668 sha256_process( (sha256_context *) ctx, data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100669}
670
Paul Bakker17373852011-01-06 14:20:01 +0000671const md_info_t sha256_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000672 POLARSSL_MD_SHA256,
673 "SHA256",
674 32,
675 sha256_starts_wrap,
676 sha256_update_wrap,
677 sha256_finish_wrap,
678 sha256_wrap,
679 sha256_file_wrap,
680 sha256_hmac_starts_wrap,
681 sha256_hmac_update_wrap,
682 sha256_hmac_finish_wrap,
683 sha256_hmac_reset_wrap,
684 sha256_hmac_wrap,
685 sha256_ctx_alloc,
686 sha256_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100687 sha256_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000688};
689
690#endif
691
Paul Bakker9e36f042013-06-30 14:34:05 +0200692#if defined(POLARSSL_SHA512_C)
Paul Bakker17373852011-01-06 14:20:01 +0000693
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100694static void sha384_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000695{
Paul Bakker9e36f042013-06-30 14:34:05 +0200696 sha512_starts( (sha512_context *) ctx, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000697}
698
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100699static void sha384_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000700{
Paul Bakker9e36f042013-06-30 14:34:05 +0200701 sha512_update( (sha512_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000702}
703
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100704static void sha384_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000705{
Paul Bakker9e36f042013-06-30 14:34:05 +0200706 sha512_finish( (sha512_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000707}
708
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100709static void sha384_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000710 unsigned char *output )
711{
Paul Bakker9e36f042013-06-30 14:34:05 +0200712 sha512( input, ilen, output, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000713}
714
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100715static int sha384_file_wrap( const char *path, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000716{
Paul Bakker335db3f2011-04-25 15:28:35 +0000717#if defined(POLARSSL_FS_IO)
Paul Bakker9e36f042013-06-30 14:34:05 +0200718 return sha512_file( path, output, 1 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000719#else
720 ((void) path);
721 ((void) output);
722 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
723#endif
Paul Bakker17373852011-01-06 14:20:01 +0000724}
725
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100726static void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000727{
Paul Bakker9e36f042013-06-30 14:34:05 +0200728 sha512_hmac_starts( (sha512_context *) ctx, key, keylen, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000729}
730
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100731static void sha384_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000732{
Paul Bakker9e36f042013-06-30 14:34:05 +0200733 sha512_hmac_update( (sha512_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000734}
735
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100736static void sha384_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000737{
Paul Bakker9e36f042013-06-30 14:34:05 +0200738 sha512_hmac_finish( (sha512_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000739}
740
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100741static void sha384_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000742{
Paul Bakker9e36f042013-06-30 14:34:05 +0200743 sha512_hmac_reset( (sha512_context *) ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000744}
745
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100746static void sha384_hmac_wrap( const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000747 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000748 unsigned char *output )
749{
Paul Bakker9e36f042013-06-30 14:34:05 +0200750 sha512_hmac( key, keylen, input, ilen, output, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000751}
752
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100753static void * sha384_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000754{
Paul Bakker6e339b52013-07-03 13:37:05 +0200755 return polarssl_malloc( sizeof( sha512_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000756}
757
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100758static void sha384_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000759{
Paul Bakker6e339b52013-07-03 13:37:05 +0200760 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000761}
762
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100763static void sha384_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100764{
Paul Bakker9e36f042013-06-30 14:34:05 +0200765 sha512_process( (sha512_context *) ctx, data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100766}
767
Paul Bakker17373852011-01-06 14:20:01 +0000768const md_info_t sha384_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000769 POLARSSL_MD_SHA384,
770 "SHA384",
771 48,
772 sha384_starts_wrap,
773 sha384_update_wrap,
774 sha384_finish_wrap,
775 sha384_wrap,
776 sha384_file_wrap,
777 sha384_hmac_starts_wrap,
778 sha384_hmac_update_wrap,
779 sha384_hmac_finish_wrap,
780 sha384_hmac_reset_wrap,
781 sha384_hmac_wrap,
782 sha384_ctx_alloc,
783 sha384_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100784 sha384_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000785};
786
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100787static void sha512_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000788{
Paul Bakker9e36f042013-06-30 14:34:05 +0200789 sha512_starts( (sha512_context *) ctx, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000790}
791
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100792static void sha512_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000793{
Paul Bakker9e36f042013-06-30 14:34:05 +0200794 sha512_update( (sha512_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000795}
796
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100797static void sha512_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000798{
Paul Bakker9e36f042013-06-30 14:34:05 +0200799 sha512_finish( (sha512_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000800}
801
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100802static void sha512_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000803 unsigned char *output )
804{
Paul Bakker9e36f042013-06-30 14:34:05 +0200805 sha512( input, ilen, output, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000806}
807
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100808static int sha512_file_wrap( const char *path, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000809{
Paul Bakker335db3f2011-04-25 15:28:35 +0000810#if defined(POLARSSL_FS_IO)
Paul Bakker9e36f042013-06-30 14:34:05 +0200811 return sha512_file( path, output, 0 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000812#else
813 ((void) path);
814 ((void) output);
815 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
816#endif
Paul Bakker17373852011-01-06 14:20:01 +0000817}
818
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100819static void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000820{
Paul Bakker9e36f042013-06-30 14:34:05 +0200821 sha512_hmac_starts( (sha512_context *) ctx, key, keylen, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000822}
823
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100824static void sha512_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000825{
Paul Bakker9e36f042013-06-30 14:34:05 +0200826 sha512_hmac_update( (sha512_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000827}
828
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100829static void sha512_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000830{
Paul Bakker9e36f042013-06-30 14:34:05 +0200831 sha512_hmac_finish( (sha512_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000832}
833
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100834static void sha512_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000835{
Paul Bakker9e36f042013-06-30 14:34:05 +0200836 sha512_hmac_reset( (sha512_context *) ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000837}
838
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100839static void sha512_hmac_wrap( const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000840 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000841 unsigned char *output )
842{
Paul Bakker9e36f042013-06-30 14:34:05 +0200843 sha512_hmac( key, keylen, input, ilen, output, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000844}
845
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100846static void * sha512_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000847{
Paul Bakker6e339b52013-07-03 13:37:05 +0200848 return polarssl_malloc( sizeof( sha512_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000849}
850
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100851static void sha512_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000852{
Paul Bakker6e339b52013-07-03 13:37:05 +0200853 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000854}
855
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100856static void sha512_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100857{
Paul Bakker9e36f042013-06-30 14:34:05 +0200858 sha512_process( (sha512_context *) ctx, data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100859}
860
Paul Bakker17373852011-01-06 14:20:01 +0000861const md_info_t sha512_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000862 POLARSSL_MD_SHA512,
863 "SHA512",
864 64,
865 sha512_starts_wrap,
866 sha512_update_wrap,
867 sha512_finish_wrap,
868 sha512_wrap,
869 sha512_file_wrap,
870 sha512_hmac_starts_wrap,
871 sha512_hmac_update_wrap,
872 sha512_hmac_finish_wrap,
873 sha512_hmac_reset_wrap,
874 sha512_hmac_wrap,
875 sha512_ctx_alloc,
876 sha512_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100877 sha512_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000878};
879
880#endif
881
882#endif