blob: 64476222d510cfb15a6018c3f403d4a1a36402fa [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
Paul Bakker34617722014-06-13 17:20:13 +020077/* Implementation that should never be optimized out by the compiler */
78static void polarssl_zeroize( void *v, size_t n ) {
79 volatile unsigned char *p = v; while( n-- ) *p++ = 0;
80}
81
Paul Bakker17373852011-01-06 14:20:01 +000082#if defined(POLARSSL_MD2_C)
83
84static void md2_starts_wrap( void *ctx )
85{
86 md2_starts( (md2_context *) ctx );
87}
88
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +020089static void md2_update_wrap( void *ctx, const unsigned char *input,
90 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +000091{
92 md2_update( (md2_context *) ctx, input, ilen );
93}
94
95static void md2_finish_wrap( void *ctx, unsigned char *output )
96{
97 md2_finish( (md2_context *) ctx, output );
98}
99
Paul Bakkerb6c5d2e2013-06-25 16:25:17 +0200100static int md2_file_wrap( const char *path, unsigned char *output )
Paul Bakker335db3f2011-04-25 15:28:35 +0000101{
102#if defined(POLARSSL_FS_IO)
103 return md2_file( path, output );
104#else
105 ((void) path);
106 ((void) output);
107 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
108#endif
109}
110
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200111static void md2_hmac_starts_wrap( void *ctx, const unsigned char *key,
112 size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000113{
114 md2_hmac_starts( (md2_context *) ctx, key, keylen );
115}
116
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200117static void md2_hmac_update_wrap( void *ctx, const unsigned char *input,
118 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000119{
120 md2_hmac_update( (md2_context *) ctx, input, ilen );
121}
122
123static void md2_hmac_finish_wrap( void *ctx, unsigned char *output )
124{
125 md2_hmac_finish( (md2_context *) ctx, output );
126}
127
128static void md2_hmac_reset_wrap( void *ctx )
129{
130 md2_hmac_reset( (md2_context *) ctx );
131}
132
133static void * md2_ctx_alloc( void )
134{
Paul Bakker6e339b52013-07-03 13:37:05 +0200135 return polarssl_malloc( sizeof( md2_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000136}
137
138static void md2_ctx_free( void *ctx )
139{
Paul Bakker34617722014-06-13 17:20:13 +0200140 polarssl_zeroize( ctx, sizeof( md2_context ) );
Paul Bakker6e339b52013-07-03 13:37:05 +0200141 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000142}
143
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100144static void md2_process_wrap( void *ctx, const unsigned char *data )
145{
146 ((void) data);
147
148 md2_process( (md2_context *) ctx );
149}
150
Paul Bakker17373852011-01-06 14:20:01 +0000151const md_info_t md2_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000152 POLARSSL_MD_MD2,
153 "MD2",
154 16,
155 md2_starts_wrap,
156 md2_update_wrap,
157 md2_finish_wrap,
158 md2,
Paul Bakker335db3f2011-04-25 15:28:35 +0000159 md2_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000160 md2_hmac_starts_wrap,
161 md2_hmac_update_wrap,
162 md2_hmac_finish_wrap,
163 md2_hmac_reset_wrap,
164 md2_hmac,
165 md2_ctx_alloc,
166 md2_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100167 md2_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000168};
169
Paul Bakker9af723c2014-05-01 13:03:14 +0200170#endif /* POLARSSL_MD2_C */
Paul Bakker17373852011-01-06 14:20:01 +0000171
172#if defined(POLARSSL_MD4_C)
173
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100174static void md4_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000175{
176 md4_starts( (md4_context *) ctx );
177}
178
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200179static void md4_update_wrap( void *ctx, const unsigned char *input,
180 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000181{
182 md4_update( (md4_context *) ctx, input, ilen );
183}
184
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100185static void md4_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000186{
187 md4_finish( (md4_context *) ctx, output );
188}
189
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100190static int md4_file_wrap( const char *path, unsigned char *output )
Paul Bakker335db3f2011-04-25 15:28:35 +0000191{
192#if defined(POLARSSL_FS_IO)
193 return md4_file( path, output );
194#else
195 ((void) path);
196 ((void) output);
197 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
198#endif
199}
200
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200201static void md4_hmac_starts_wrap( void *ctx, const unsigned char *key,
202 size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000203{
204 md4_hmac_starts( (md4_context *) ctx, key, keylen );
205}
206
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200207static void md4_hmac_update_wrap( void *ctx, const unsigned char *input,
208 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000209{
210 md4_hmac_update( (md4_context *) ctx, input, ilen );
211}
212
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100213static void md4_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000214{
215 md4_hmac_finish( (md4_context *) ctx, output );
216}
217
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100218static void md4_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000219{
220 md4_hmac_reset( (md4_context *) ctx );
221}
222
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100223static void *md4_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000224{
Paul Bakker6e339b52013-07-03 13:37:05 +0200225 return polarssl_malloc( sizeof( md4_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000226}
227
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100228static void md4_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000229{
Paul Bakker34617722014-06-13 17:20:13 +0200230 polarssl_zeroize( ctx, sizeof( md4_context ) );
Paul Bakker6e339b52013-07-03 13:37:05 +0200231 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000232}
233
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100234static void md4_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100235{
236 md4_process( (md4_context *) ctx, data );
237}
238
Paul Bakker17373852011-01-06 14:20:01 +0000239const md_info_t md4_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000240 POLARSSL_MD_MD4,
241 "MD4",
242 16,
243 md4_starts_wrap,
244 md4_update_wrap,
245 md4_finish_wrap,
246 md4,
Paul Bakker335db3f2011-04-25 15:28:35 +0000247 md4_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000248 md4_hmac_starts_wrap,
249 md4_hmac_update_wrap,
250 md4_hmac_finish_wrap,
251 md4_hmac_reset_wrap,
252 md4_hmac,
253 md4_ctx_alloc,
254 md4_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100255 md4_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000256};
257
Paul Bakker9af723c2014-05-01 13:03:14 +0200258#endif /* POLARSSL_MD4_C */
Paul Bakker17373852011-01-06 14:20:01 +0000259
260#if defined(POLARSSL_MD5_C)
261
262static void md5_starts_wrap( void *ctx )
263{
264 md5_starts( (md5_context *) ctx );
265}
266
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200267static void md5_update_wrap( void *ctx, const unsigned char *input,
268 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000269{
270 md5_update( (md5_context *) ctx, input, ilen );
271}
272
273static void md5_finish_wrap( void *ctx, unsigned char *output )
274{
275 md5_finish( (md5_context *) ctx, output );
276}
277
Paul Bakkerb6c5d2e2013-06-25 16:25:17 +0200278static int md5_file_wrap( const char *path, unsigned char *output )
Paul Bakker335db3f2011-04-25 15:28:35 +0000279{
280#if defined(POLARSSL_FS_IO)
281 return md5_file( path, output );
282#else
283 ((void) path);
284 ((void) output);
285 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
286#endif
287}
288
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200289static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key,
290 size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000291{
292 md5_hmac_starts( (md5_context *) ctx, key, keylen );
293}
294
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200295static void md5_hmac_update_wrap( void *ctx, const unsigned char *input,
296 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000297{
298 md5_hmac_update( (md5_context *) ctx, input, ilen );
299}
300
301static void md5_hmac_finish_wrap( void *ctx, unsigned char *output )
302{
303 md5_hmac_finish( (md5_context *) ctx, output );
304}
305
306static void md5_hmac_reset_wrap( void *ctx )
307{
308 md5_hmac_reset( (md5_context *) ctx );
309}
310
311static void * md5_ctx_alloc( void )
312{
Paul Bakker6e339b52013-07-03 13:37:05 +0200313 return polarssl_malloc( sizeof( md5_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000314}
315
316static void md5_ctx_free( void *ctx )
317{
Paul Bakker34617722014-06-13 17:20:13 +0200318 polarssl_zeroize( ctx, sizeof( md5_context ) );
Paul Bakker6e339b52013-07-03 13:37:05 +0200319 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000320}
321
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100322static void md5_process_wrap( void *ctx, const unsigned char *data )
323{
324 md5_process( (md5_context *) ctx, data );
325}
326
Paul Bakker17373852011-01-06 14:20:01 +0000327const md_info_t md5_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000328 POLARSSL_MD_MD5,
329 "MD5",
330 16,
331 md5_starts_wrap,
332 md5_update_wrap,
333 md5_finish_wrap,
334 md5,
Paul Bakker335db3f2011-04-25 15:28:35 +0000335 md5_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000336 md5_hmac_starts_wrap,
337 md5_hmac_update_wrap,
338 md5_hmac_finish_wrap,
339 md5_hmac_reset_wrap,
340 md5_hmac,
341 md5_ctx_alloc,
342 md5_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100343 md5_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000344};
345
Paul Bakker9af723c2014-05-01 13:03:14 +0200346#endif /* POLARSSL_MD5_C */
Paul Bakker17373852011-01-06 14:20:01 +0000347
Paul Bakker61b699e2014-01-22 13:35:29 +0100348#if defined(POLARSSL_RIPEMD160_C)
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100349
Paul Bakker61b699e2014-01-22 13:35:29 +0100350static void ripemd160_starts_wrap( void *ctx )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100351{
Paul Bakker61b699e2014-01-22 13:35:29 +0100352 ripemd160_starts( (ripemd160_context *) ctx );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100353}
354
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200355static void ripemd160_update_wrap( void *ctx, const unsigned char *input,
356 size_t ilen )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100357{
Paul Bakker61b699e2014-01-22 13:35:29 +0100358 ripemd160_update( (ripemd160_context *) ctx, input, ilen );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100359}
360
Paul Bakker61b699e2014-01-22 13:35:29 +0100361static void ripemd160_finish_wrap( void *ctx, unsigned char *output )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100362{
Paul Bakker61b699e2014-01-22 13:35:29 +0100363 ripemd160_finish( (ripemd160_context *) ctx, output );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100364}
365
Paul Bakker61b699e2014-01-22 13:35:29 +0100366static int ripemd160_file_wrap( const char *path, unsigned char *output )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100367{
368#if defined(POLARSSL_FS_IO)
Paul Bakker61b699e2014-01-22 13:35:29 +0100369 return ripemd160_file( path, output );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100370#else
371 ((void) path);
372 ((void) output);
373 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
374#endif
375}
376
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200377static void ripemd160_hmac_starts_wrap( void *ctx, const unsigned char *key,
378 size_t keylen )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100379{
Paul Bakker61b699e2014-01-22 13:35:29 +0100380 ripemd160_hmac_starts( (ripemd160_context *) ctx, key, keylen );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100381}
382
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200383static void ripemd160_hmac_update_wrap( void *ctx, const unsigned char *input,
384 size_t ilen )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100385{
Paul Bakker61b699e2014-01-22 13:35:29 +0100386 ripemd160_hmac_update( (ripemd160_context *) ctx, input, ilen );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100387}
388
Paul Bakker61b699e2014-01-22 13:35:29 +0100389static void ripemd160_hmac_finish_wrap( void *ctx, unsigned char *output )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100390{
Paul Bakker61b699e2014-01-22 13:35:29 +0100391 ripemd160_hmac_finish( (ripemd160_context *) ctx, output );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100392}
393
Paul Bakker61b699e2014-01-22 13:35:29 +0100394static void ripemd160_hmac_reset_wrap( void *ctx )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100395{
Paul Bakker61b699e2014-01-22 13:35:29 +0100396 ripemd160_hmac_reset( (ripemd160_context *) ctx );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100397}
398
Paul Bakker61b699e2014-01-22 13:35:29 +0100399static void * ripemd160_ctx_alloc( void )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100400{
Paul Bakker61b699e2014-01-22 13:35:29 +0100401 return polarssl_malloc( sizeof( ripemd160_context ) );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100402}
403
Paul Bakker61b699e2014-01-22 13:35:29 +0100404static void ripemd160_ctx_free( void *ctx )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100405{
Paul Bakker34617722014-06-13 17:20:13 +0200406 polarssl_zeroize( ctx, sizeof( ripemd160_context ) );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100407 polarssl_free( ctx );
408}
409
Paul Bakker61b699e2014-01-22 13:35:29 +0100410static void ripemd160_process_wrap( void *ctx, const unsigned char *data )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100411{
Paul Bakker61b699e2014-01-22 13:35:29 +0100412 ripemd160_process( (ripemd160_context *) ctx, data );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100413}
414
Paul Bakker61b699e2014-01-22 13:35:29 +0100415const md_info_t ripemd160_info = {
416 POLARSSL_MD_RIPEMD160,
417 "RIPEMD160",
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100418 20,
Paul Bakker61b699e2014-01-22 13:35:29 +0100419 ripemd160_starts_wrap,
420 ripemd160_update_wrap,
421 ripemd160_finish_wrap,
422 ripemd160,
423 ripemd160_file_wrap,
424 ripemd160_hmac_starts_wrap,
425 ripemd160_hmac_update_wrap,
426 ripemd160_hmac_finish_wrap,
427 ripemd160_hmac_reset_wrap,
428 ripemd160_hmac,
429 ripemd160_ctx_alloc,
430 ripemd160_ctx_free,
431 ripemd160_process_wrap,
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100432};
433
Paul Bakker9af723c2014-05-01 13:03:14 +0200434#endif /* POLARSSL_RIPEMD160_C */
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100435
Paul Bakker17373852011-01-06 14:20:01 +0000436#if defined(POLARSSL_SHA1_C)
437
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100438static void sha1_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000439{
440 sha1_starts( (sha1_context *) ctx );
441}
442
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200443static void sha1_update_wrap( void *ctx, const unsigned char *input,
444 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000445{
446 sha1_update( (sha1_context *) ctx, input, ilen );
447}
448
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100449static void sha1_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000450{
451 sha1_finish( (sha1_context *) ctx, output );
452}
453
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100454static int sha1_file_wrap( const char *path, unsigned char *output )
Paul Bakker335db3f2011-04-25 15:28:35 +0000455{
456#if defined(POLARSSL_FS_IO)
457 return sha1_file( path, output );
458#else
459 ((void) path);
460 ((void) output);
461 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
462#endif
463}
464
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200465static void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key,
466 size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000467{
468 sha1_hmac_starts( (sha1_context *) ctx, key, keylen );
469}
470
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200471static void sha1_hmac_update_wrap( void *ctx, const unsigned char *input,
472 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000473{
474 sha1_hmac_update( (sha1_context *) ctx, input, ilen );
475}
476
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100477static void sha1_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000478{
479 sha1_hmac_finish( (sha1_context *) ctx, output );
480}
481
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100482static void sha1_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000483{
484 sha1_hmac_reset( (sha1_context *) ctx );
485}
486
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100487static void * sha1_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000488{
Paul Bakker6e339b52013-07-03 13:37:05 +0200489 return polarssl_malloc( sizeof( sha1_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000490}
491
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100492static void sha1_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000493{
Paul Bakker34617722014-06-13 17:20:13 +0200494 polarssl_zeroize( ctx, sizeof( sha1_context ) );
Paul Bakker6e339b52013-07-03 13:37:05 +0200495 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000496}
497
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100498static void sha1_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100499{
500 sha1_process( (sha1_context *) ctx, data );
501}
502
Paul Bakker17373852011-01-06 14:20:01 +0000503const md_info_t sha1_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000504 POLARSSL_MD_SHA1,
505 "SHA1",
506 20,
507 sha1_starts_wrap,
508 sha1_update_wrap,
509 sha1_finish_wrap,
510 sha1,
Paul Bakker335db3f2011-04-25 15:28:35 +0000511 sha1_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000512 sha1_hmac_starts_wrap,
513 sha1_hmac_update_wrap,
514 sha1_hmac_finish_wrap,
515 sha1_hmac_reset_wrap,
516 sha1_hmac,
517 sha1_ctx_alloc,
518 sha1_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100519 sha1_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000520};
521
Paul Bakker9af723c2014-05-01 13:03:14 +0200522#endif /* POLARSSL_SHA1_C */
Paul Bakker17373852011-01-06 14:20:01 +0000523
524/*
525 * Wrappers for generic message digests
526 */
Paul Bakker9e36f042013-06-30 14:34:05 +0200527#if defined(POLARSSL_SHA256_C)
Paul Bakker17373852011-01-06 14:20:01 +0000528
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100529static void sha224_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000530{
Paul Bakker9e36f042013-06-30 14:34:05 +0200531 sha256_starts( (sha256_context *) ctx, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000532}
533
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200534static void sha224_update_wrap( void *ctx, const unsigned char *input,
535 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000536{
Paul Bakker9e36f042013-06-30 14:34:05 +0200537 sha256_update( (sha256_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000538}
539
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100540static void sha224_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000541{
Paul Bakker9e36f042013-06-30 14:34:05 +0200542 sha256_finish( (sha256_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000543}
544
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100545static void sha224_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000546 unsigned char *output )
547{
Paul Bakker9e36f042013-06-30 14:34:05 +0200548 sha256( input, ilen, output, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000549}
550
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100551static int sha224_file_wrap( const char *path, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000552{
Paul Bakker335db3f2011-04-25 15:28:35 +0000553#if defined(POLARSSL_FS_IO)
Paul Bakker9e36f042013-06-30 14:34:05 +0200554 return sha256_file( path, output, 1 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000555#else
556 ((void) path);
557 ((void) output);
558 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
559#endif
Paul Bakker17373852011-01-06 14:20:01 +0000560}
561
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200562static void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key,
563 size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000564{
Paul Bakker9e36f042013-06-30 14:34:05 +0200565 sha256_hmac_starts( (sha256_context *) ctx, key, keylen, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000566}
567
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200568static void sha224_hmac_update_wrap( void *ctx, const unsigned char *input,
569 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000570{
Paul Bakker9e36f042013-06-30 14:34:05 +0200571 sha256_hmac_update( (sha256_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000572}
573
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100574static void sha224_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000575{
Paul Bakker9e36f042013-06-30 14:34:05 +0200576 sha256_hmac_finish( (sha256_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000577}
578
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100579static void sha224_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000580{
Paul Bakker9e36f042013-06-30 14:34:05 +0200581 sha256_hmac_reset( (sha256_context *) ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000582}
583
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100584static void sha224_hmac_wrap( const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000585 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000586 unsigned char *output )
587{
Paul Bakker9e36f042013-06-30 14:34:05 +0200588 sha256_hmac( key, keylen, input, ilen, output, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000589}
590
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100591static void * sha224_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000592{
Paul Bakker6e339b52013-07-03 13:37:05 +0200593 return polarssl_malloc( sizeof( sha256_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000594}
595
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100596static void sha224_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000597{
Paul Bakker34617722014-06-13 17:20:13 +0200598 polarssl_zeroize( ctx, sizeof( sha256_context ) );
Paul Bakker6e339b52013-07-03 13:37:05 +0200599 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000600}
601
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100602static void sha224_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100603{
Paul Bakker9e36f042013-06-30 14:34:05 +0200604 sha256_process( (sha256_context *) ctx, data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100605}
606
Paul Bakker17373852011-01-06 14:20:01 +0000607const md_info_t sha224_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000608 POLARSSL_MD_SHA224,
609 "SHA224",
610 28,
611 sha224_starts_wrap,
612 sha224_update_wrap,
613 sha224_finish_wrap,
614 sha224_wrap,
615 sha224_file_wrap,
616 sha224_hmac_starts_wrap,
617 sha224_hmac_update_wrap,
618 sha224_hmac_finish_wrap,
619 sha224_hmac_reset_wrap,
620 sha224_hmac_wrap,
621 sha224_ctx_alloc,
622 sha224_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100623 sha224_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000624};
625
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100626static void sha256_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000627{
Paul Bakker9e36f042013-06-30 14:34:05 +0200628 sha256_starts( (sha256_context *) ctx, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000629}
630
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200631static void sha256_update_wrap( void *ctx, const unsigned char *input,
632 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000633{
Paul Bakker9e36f042013-06-30 14:34:05 +0200634 sha256_update( (sha256_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000635}
636
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100637static void sha256_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000638{
Paul Bakker9e36f042013-06-30 14:34:05 +0200639 sha256_finish( (sha256_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000640}
641
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100642static void sha256_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000643 unsigned char *output )
644{
Paul Bakker9e36f042013-06-30 14:34:05 +0200645 sha256( input, ilen, output, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000646}
647
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100648static int sha256_file_wrap( const char *path, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000649{
Paul Bakker335db3f2011-04-25 15:28:35 +0000650#if defined(POLARSSL_FS_IO)
Paul Bakker9e36f042013-06-30 14:34:05 +0200651 return sha256_file( path, output, 0 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000652#else
653 ((void) path);
654 ((void) output);
655 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
656#endif
Paul Bakker17373852011-01-06 14:20:01 +0000657}
658
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200659static void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key,
660 size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000661{
Paul Bakker9e36f042013-06-30 14:34:05 +0200662 sha256_hmac_starts( (sha256_context *) ctx, key, keylen, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000663}
664
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200665static void sha256_hmac_update_wrap( void *ctx, const unsigned char *input,
666 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000667{
Paul Bakker9e36f042013-06-30 14:34:05 +0200668 sha256_hmac_update( (sha256_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000669}
670
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100671static void sha256_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000672{
Paul Bakker9e36f042013-06-30 14:34:05 +0200673 sha256_hmac_finish( (sha256_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000674}
675
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100676static void sha256_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000677{
Paul Bakker9e36f042013-06-30 14:34:05 +0200678 sha256_hmac_reset( (sha256_context *) ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000679}
680
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100681static void sha256_hmac_wrap( const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000682 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000683 unsigned char *output )
684{
Paul Bakker9e36f042013-06-30 14:34:05 +0200685 sha256_hmac( key, keylen, input, ilen, output, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000686}
687
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100688static void * sha256_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000689{
Paul Bakker6e339b52013-07-03 13:37:05 +0200690 return polarssl_malloc( sizeof( sha256_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000691}
692
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100693static void sha256_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000694{
Paul Bakker34617722014-06-13 17:20:13 +0200695 polarssl_zeroize( ctx, sizeof( sha256_context ) );
Paul Bakker6e339b52013-07-03 13:37:05 +0200696 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000697}
698
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100699static void sha256_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100700{
Paul Bakker9e36f042013-06-30 14:34:05 +0200701 sha256_process( (sha256_context *) ctx, data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100702}
703
Paul Bakker17373852011-01-06 14:20:01 +0000704const md_info_t sha256_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000705 POLARSSL_MD_SHA256,
706 "SHA256",
707 32,
708 sha256_starts_wrap,
709 sha256_update_wrap,
710 sha256_finish_wrap,
711 sha256_wrap,
712 sha256_file_wrap,
713 sha256_hmac_starts_wrap,
714 sha256_hmac_update_wrap,
715 sha256_hmac_finish_wrap,
716 sha256_hmac_reset_wrap,
717 sha256_hmac_wrap,
718 sha256_ctx_alloc,
719 sha256_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100720 sha256_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000721};
722
Paul Bakker9af723c2014-05-01 13:03:14 +0200723#endif /* POLARSSL_SHA256_C */
Paul Bakker17373852011-01-06 14:20:01 +0000724
Paul Bakker9e36f042013-06-30 14:34:05 +0200725#if defined(POLARSSL_SHA512_C)
Paul Bakker17373852011-01-06 14:20:01 +0000726
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100727static void sha384_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000728{
Paul Bakker9e36f042013-06-30 14:34:05 +0200729 sha512_starts( (sha512_context *) ctx, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000730}
731
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200732static void sha384_update_wrap( void *ctx, const unsigned char *input,
733 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000734{
Paul Bakker9e36f042013-06-30 14:34:05 +0200735 sha512_update( (sha512_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000736}
737
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100738static void sha384_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000739{
Paul Bakker9e36f042013-06-30 14:34:05 +0200740 sha512_finish( (sha512_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000741}
742
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100743static void sha384_wrap( 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( input, ilen, output, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000747}
748
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100749static int sha384_file_wrap( const char *path, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000750{
Paul Bakker335db3f2011-04-25 15:28:35 +0000751#if defined(POLARSSL_FS_IO)
Paul Bakker9e36f042013-06-30 14:34:05 +0200752 return sha512_file( path, output, 1 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000753#else
754 ((void) path);
755 ((void) output);
756 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
757#endif
Paul Bakker17373852011-01-06 14:20:01 +0000758}
759
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200760static void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key,
761 size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000762{
Paul Bakker9e36f042013-06-30 14:34:05 +0200763 sha512_hmac_starts( (sha512_context *) ctx, key, keylen, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000764}
765
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200766static void sha384_hmac_update_wrap( void *ctx, const unsigned char *input,
767 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000768{
Paul Bakker9e36f042013-06-30 14:34:05 +0200769 sha512_hmac_update( (sha512_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000770}
771
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100772static void sha384_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000773{
Paul Bakker9e36f042013-06-30 14:34:05 +0200774 sha512_hmac_finish( (sha512_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000775}
776
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100777static void sha384_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000778{
Paul Bakker9e36f042013-06-30 14:34:05 +0200779 sha512_hmac_reset( (sha512_context *) ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000780}
781
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100782static void sha384_hmac_wrap( const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000783 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000784 unsigned char *output )
785{
Paul Bakker9e36f042013-06-30 14:34:05 +0200786 sha512_hmac( key, keylen, input, ilen, output, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000787}
788
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100789static void * sha384_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000790{
Paul Bakker6e339b52013-07-03 13:37:05 +0200791 return polarssl_malloc( sizeof( sha512_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000792}
793
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100794static void sha384_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000795{
Paul Bakker34617722014-06-13 17:20:13 +0200796 polarssl_zeroize( ctx, sizeof( sha512_context ) );
Paul Bakker6e339b52013-07-03 13:37:05 +0200797 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000798}
799
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100800static void sha384_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100801{
Paul Bakker9e36f042013-06-30 14:34:05 +0200802 sha512_process( (sha512_context *) ctx, data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100803}
804
Paul Bakker17373852011-01-06 14:20:01 +0000805const md_info_t sha384_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000806 POLARSSL_MD_SHA384,
807 "SHA384",
808 48,
809 sha384_starts_wrap,
810 sha384_update_wrap,
811 sha384_finish_wrap,
812 sha384_wrap,
813 sha384_file_wrap,
814 sha384_hmac_starts_wrap,
815 sha384_hmac_update_wrap,
816 sha384_hmac_finish_wrap,
817 sha384_hmac_reset_wrap,
818 sha384_hmac_wrap,
819 sha384_ctx_alloc,
820 sha384_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100821 sha384_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000822};
823
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100824static void sha512_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000825{
Paul Bakker9e36f042013-06-30 14:34:05 +0200826 sha512_starts( (sha512_context *) ctx, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000827}
828
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200829static void sha512_update_wrap( void *ctx, const unsigned char *input,
830 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000831{
Paul Bakker9e36f042013-06-30 14:34:05 +0200832 sha512_update( (sha512_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000833}
834
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100835static void sha512_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000836{
Paul Bakker9e36f042013-06-30 14:34:05 +0200837 sha512_finish( (sha512_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000838}
839
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100840static void sha512_wrap( 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( input, ilen, output, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000844}
845
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100846static int sha512_file_wrap( const char *path, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000847{
Paul Bakker335db3f2011-04-25 15:28:35 +0000848#if defined(POLARSSL_FS_IO)
Paul Bakker9e36f042013-06-30 14:34:05 +0200849 return sha512_file( path, output, 0 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000850#else
851 ((void) path);
852 ((void) output);
853 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
854#endif
Paul Bakker17373852011-01-06 14:20:01 +0000855}
856
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200857static void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key,
858 size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000859{
Paul Bakker9e36f042013-06-30 14:34:05 +0200860 sha512_hmac_starts( (sha512_context *) ctx, key, keylen, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000861}
862
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200863static void sha512_hmac_update_wrap( void *ctx, const unsigned char *input,
864 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000865{
Paul Bakker9e36f042013-06-30 14:34:05 +0200866 sha512_hmac_update( (sha512_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000867}
868
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100869static void sha512_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000870{
Paul Bakker9e36f042013-06-30 14:34:05 +0200871 sha512_hmac_finish( (sha512_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000872}
873
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100874static void sha512_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000875{
Paul Bakker9e36f042013-06-30 14:34:05 +0200876 sha512_hmac_reset( (sha512_context *) ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000877}
878
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100879static void sha512_hmac_wrap( const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000880 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000881 unsigned char *output )
882{
Paul Bakker9e36f042013-06-30 14:34:05 +0200883 sha512_hmac( key, keylen, input, ilen, output, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000884}
885
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100886static void * sha512_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000887{
Paul Bakker6e339b52013-07-03 13:37:05 +0200888 return polarssl_malloc( sizeof( sha512_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000889}
890
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100891static void sha512_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000892{
Paul Bakker34617722014-06-13 17:20:13 +0200893 polarssl_zeroize( ctx, sizeof( sha512_context ) );
Paul Bakker6e339b52013-07-03 13:37:05 +0200894 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000895}
896
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100897static void sha512_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100898{
Paul Bakker9e36f042013-06-30 14:34:05 +0200899 sha512_process( (sha512_context *) ctx, data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100900}
901
Paul Bakker17373852011-01-06 14:20:01 +0000902const md_info_t sha512_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000903 POLARSSL_MD_SHA512,
904 "SHA512",
905 64,
906 sha512_starts_wrap,
907 sha512_update_wrap,
908 sha512_finish_wrap,
909 sha512_wrap,
910 sha512_file_wrap,
911 sha512_hmac_starts_wrap,
912 sha512_hmac_update_wrap,
913 sha512_hmac_finish_wrap,
914 sha512_hmac_reset_wrap,
915 sha512_hmac_wrap,
916 sha512_ctx_alloc,
917 sha512_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100918 sha512_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000919};
920
Paul Bakker9af723c2014-05-01 13:03:14 +0200921#endif /* POLARSSL_SHA512_C */
Paul Bakker17373852011-01-06 14:20:01 +0000922
Paul Bakker9af723c2014-05-01 13:03:14 +0200923#endif /* POLARSSL_MD_C */