blob: 9627878aa4a0c431ced10414cc51021128b853cd [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 Bakkerb9e4e2c2014-05-01 14:18:25 +020084static void md2_update_wrap( void *ctx, const unsigned char *input,
85 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +000086{
87 md2_update( (md2_context *) ctx, input, ilen );
88}
89
90static void md2_finish_wrap( void *ctx, unsigned char *output )
91{
92 md2_finish( (md2_context *) ctx, output );
93}
94
Paul Bakkerb6c5d2e2013-06-25 16:25:17 +020095static int md2_file_wrap( const char *path, unsigned char *output )
Paul Bakker335db3f2011-04-25 15:28:35 +000096{
97#if defined(POLARSSL_FS_IO)
98 return md2_file( path, output );
99#else
100 ((void) path);
101 ((void) output);
102 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
103#endif
104}
105
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200106static void md2_hmac_starts_wrap( void *ctx, const unsigned char *key,
107 size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000108{
109 md2_hmac_starts( (md2_context *) ctx, key, keylen );
110}
111
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200112static void md2_hmac_update_wrap( void *ctx, const unsigned char *input,
113 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000114{
115 md2_hmac_update( (md2_context *) ctx, input, ilen );
116}
117
118static void md2_hmac_finish_wrap( void *ctx, unsigned char *output )
119{
120 md2_hmac_finish( (md2_context *) ctx, output );
121}
122
123static void md2_hmac_reset_wrap( void *ctx )
124{
125 md2_hmac_reset( (md2_context *) ctx );
126}
127
128static void * md2_ctx_alloc( void )
129{
Paul Bakker6e339b52013-07-03 13:37:05 +0200130 return polarssl_malloc( sizeof( md2_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000131}
132
133static void md2_ctx_free( void *ctx )
134{
Paul Bakker6e339b52013-07-03 13:37:05 +0200135 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000136}
137
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100138static void md2_process_wrap( void *ctx, const unsigned char *data )
139{
140 ((void) data);
141
142 md2_process( (md2_context *) ctx );
143}
144
Paul Bakker17373852011-01-06 14:20:01 +0000145const md_info_t md2_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000146 POLARSSL_MD_MD2,
147 "MD2",
148 16,
149 md2_starts_wrap,
150 md2_update_wrap,
151 md2_finish_wrap,
152 md2,
Paul Bakker335db3f2011-04-25 15:28:35 +0000153 md2_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000154 md2_hmac_starts_wrap,
155 md2_hmac_update_wrap,
156 md2_hmac_finish_wrap,
157 md2_hmac_reset_wrap,
158 md2_hmac,
159 md2_ctx_alloc,
160 md2_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100161 md2_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000162};
163
Paul Bakker9af723c2014-05-01 13:03:14 +0200164#endif /* POLARSSL_MD2_C */
Paul Bakker17373852011-01-06 14:20:01 +0000165
166#if defined(POLARSSL_MD4_C)
167
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100168static void md4_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000169{
170 md4_starts( (md4_context *) ctx );
171}
172
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200173static void md4_update_wrap( void *ctx, const unsigned char *input,
174 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000175{
176 md4_update( (md4_context *) ctx, input, ilen );
177}
178
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100179static void md4_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000180{
181 md4_finish( (md4_context *) ctx, output );
182}
183
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100184static int md4_file_wrap( const char *path, unsigned char *output )
Paul Bakker335db3f2011-04-25 15:28:35 +0000185{
186#if defined(POLARSSL_FS_IO)
187 return md4_file( path, output );
188#else
189 ((void) path);
190 ((void) output);
191 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
192#endif
193}
194
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200195static void md4_hmac_starts_wrap( void *ctx, const unsigned char *key,
196 size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000197{
198 md4_hmac_starts( (md4_context *) ctx, key, keylen );
199}
200
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200201static void md4_hmac_update_wrap( void *ctx, const unsigned char *input,
202 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000203{
204 md4_hmac_update( (md4_context *) ctx, input, ilen );
205}
206
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100207static void md4_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000208{
209 md4_hmac_finish( (md4_context *) ctx, output );
210}
211
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100212static void md4_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000213{
214 md4_hmac_reset( (md4_context *) ctx );
215}
216
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100217static void *md4_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000218{
Paul Bakker6e339b52013-07-03 13:37:05 +0200219 return polarssl_malloc( sizeof( md4_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000220}
221
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100222static void md4_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000223{
Paul Bakker6e339b52013-07-03 13:37:05 +0200224 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000225}
226
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100227static void md4_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100228{
229 md4_process( (md4_context *) ctx, data );
230}
231
Paul Bakker17373852011-01-06 14:20:01 +0000232const md_info_t md4_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000233 POLARSSL_MD_MD4,
234 "MD4",
235 16,
236 md4_starts_wrap,
237 md4_update_wrap,
238 md4_finish_wrap,
239 md4,
Paul Bakker335db3f2011-04-25 15:28:35 +0000240 md4_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000241 md4_hmac_starts_wrap,
242 md4_hmac_update_wrap,
243 md4_hmac_finish_wrap,
244 md4_hmac_reset_wrap,
245 md4_hmac,
246 md4_ctx_alloc,
247 md4_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100248 md4_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000249};
250
Paul Bakker9af723c2014-05-01 13:03:14 +0200251#endif /* POLARSSL_MD4_C */
Paul Bakker17373852011-01-06 14:20:01 +0000252
253#if defined(POLARSSL_MD5_C)
254
255static void md5_starts_wrap( void *ctx )
256{
257 md5_starts( (md5_context *) ctx );
258}
259
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200260static void md5_update_wrap( void *ctx, const unsigned char *input,
261 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000262{
263 md5_update( (md5_context *) ctx, input, ilen );
264}
265
266static void md5_finish_wrap( void *ctx, unsigned char *output )
267{
268 md5_finish( (md5_context *) ctx, output );
269}
270
Paul Bakkerb6c5d2e2013-06-25 16:25:17 +0200271static int md5_file_wrap( const char *path, unsigned char *output )
Paul Bakker335db3f2011-04-25 15:28:35 +0000272{
273#if defined(POLARSSL_FS_IO)
274 return md5_file( path, output );
275#else
276 ((void) path);
277 ((void) output);
278 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
279#endif
280}
281
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200282static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key,
283 size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000284{
285 md5_hmac_starts( (md5_context *) ctx, key, keylen );
286}
287
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200288static void md5_hmac_update_wrap( void *ctx, const unsigned char *input,
289 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000290{
291 md5_hmac_update( (md5_context *) ctx, input, ilen );
292}
293
294static void md5_hmac_finish_wrap( void *ctx, unsigned char *output )
295{
296 md5_hmac_finish( (md5_context *) ctx, output );
297}
298
299static void md5_hmac_reset_wrap( void *ctx )
300{
301 md5_hmac_reset( (md5_context *) ctx );
302}
303
304static void * md5_ctx_alloc( void )
305{
Paul Bakker6e339b52013-07-03 13:37:05 +0200306 return polarssl_malloc( sizeof( md5_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000307}
308
309static void md5_ctx_free( void *ctx )
310{
Paul Bakker6e339b52013-07-03 13:37:05 +0200311 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000312}
313
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100314static void md5_process_wrap( void *ctx, const unsigned char *data )
315{
316 md5_process( (md5_context *) ctx, data );
317}
318
Paul Bakker17373852011-01-06 14:20:01 +0000319const md_info_t md5_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000320 POLARSSL_MD_MD5,
321 "MD5",
322 16,
323 md5_starts_wrap,
324 md5_update_wrap,
325 md5_finish_wrap,
326 md5,
Paul Bakker335db3f2011-04-25 15:28:35 +0000327 md5_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000328 md5_hmac_starts_wrap,
329 md5_hmac_update_wrap,
330 md5_hmac_finish_wrap,
331 md5_hmac_reset_wrap,
332 md5_hmac,
333 md5_ctx_alloc,
334 md5_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100335 md5_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000336};
337
Paul Bakker9af723c2014-05-01 13:03:14 +0200338#endif /* POLARSSL_MD5_C */
Paul Bakker17373852011-01-06 14:20:01 +0000339
Paul Bakker61b699e2014-01-22 13:35:29 +0100340#if defined(POLARSSL_RIPEMD160_C)
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100341
Paul Bakker61b699e2014-01-22 13:35:29 +0100342static void ripemd160_starts_wrap( void *ctx )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100343{
Paul Bakker61b699e2014-01-22 13:35:29 +0100344 ripemd160_starts( (ripemd160_context *) ctx );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100345}
346
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200347static void ripemd160_update_wrap( void *ctx, const unsigned char *input,
348 size_t ilen )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100349{
Paul Bakker61b699e2014-01-22 13:35:29 +0100350 ripemd160_update( (ripemd160_context *) ctx, input, ilen );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100351}
352
Paul Bakker61b699e2014-01-22 13:35:29 +0100353static void ripemd160_finish_wrap( void *ctx, unsigned char *output )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100354{
Paul Bakker61b699e2014-01-22 13:35:29 +0100355 ripemd160_finish( (ripemd160_context *) ctx, output );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100356}
357
Paul Bakker61b699e2014-01-22 13:35:29 +0100358static int ripemd160_file_wrap( const char *path, unsigned char *output )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100359{
360#if defined(POLARSSL_FS_IO)
Paul Bakker61b699e2014-01-22 13:35:29 +0100361 return ripemd160_file( path, output );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100362#else
363 ((void) path);
364 ((void) output);
365 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
366#endif
367}
368
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200369static void ripemd160_hmac_starts_wrap( void *ctx, const unsigned char *key,
370 size_t keylen )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100371{
Paul Bakker61b699e2014-01-22 13:35:29 +0100372 ripemd160_hmac_starts( (ripemd160_context *) ctx, key, keylen );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100373}
374
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200375static void ripemd160_hmac_update_wrap( void *ctx, const unsigned char *input,
376 size_t ilen )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100377{
Paul Bakker61b699e2014-01-22 13:35:29 +0100378 ripemd160_hmac_update( (ripemd160_context *) ctx, input, ilen );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100379}
380
Paul Bakker61b699e2014-01-22 13:35:29 +0100381static void ripemd160_hmac_finish_wrap( void *ctx, unsigned char *output )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100382{
Paul Bakker61b699e2014-01-22 13:35:29 +0100383 ripemd160_hmac_finish( (ripemd160_context *) ctx, output );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100384}
385
Paul Bakker61b699e2014-01-22 13:35:29 +0100386static void ripemd160_hmac_reset_wrap( void *ctx )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100387{
Paul Bakker61b699e2014-01-22 13:35:29 +0100388 ripemd160_hmac_reset( (ripemd160_context *) ctx );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100389}
390
Paul Bakker61b699e2014-01-22 13:35:29 +0100391static void * ripemd160_ctx_alloc( void )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100392{
Paul Bakker61b699e2014-01-22 13:35:29 +0100393 return polarssl_malloc( sizeof( ripemd160_context ) );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100394}
395
Paul Bakker61b699e2014-01-22 13:35:29 +0100396static void ripemd160_ctx_free( void *ctx )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100397{
398 polarssl_free( ctx );
399}
400
Paul Bakker61b699e2014-01-22 13:35:29 +0100401static void ripemd160_process_wrap( void *ctx, const unsigned char *data )
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100402{
Paul Bakker61b699e2014-01-22 13:35:29 +0100403 ripemd160_process( (ripemd160_context *) ctx, data );
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100404}
405
Paul Bakker61b699e2014-01-22 13:35:29 +0100406const md_info_t ripemd160_info = {
407 POLARSSL_MD_RIPEMD160,
408 "RIPEMD160",
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100409 20,
Paul Bakker61b699e2014-01-22 13:35:29 +0100410 ripemd160_starts_wrap,
411 ripemd160_update_wrap,
412 ripemd160_finish_wrap,
413 ripemd160,
414 ripemd160_file_wrap,
415 ripemd160_hmac_starts_wrap,
416 ripemd160_hmac_update_wrap,
417 ripemd160_hmac_finish_wrap,
418 ripemd160_hmac_reset_wrap,
419 ripemd160_hmac,
420 ripemd160_ctx_alloc,
421 ripemd160_ctx_free,
422 ripemd160_process_wrap,
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100423};
424
Paul Bakker9af723c2014-05-01 13:03:14 +0200425#endif /* POLARSSL_RIPEMD160_C */
Manuel Pégourié-Gonnarde4d47a62014-01-17 20:41:32 +0100426
Paul Bakker17373852011-01-06 14:20:01 +0000427#if defined(POLARSSL_SHA1_C)
428
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100429static void sha1_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000430{
431 sha1_starts( (sha1_context *) ctx );
432}
433
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200434static void sha1_update_wrap( void *ctx, const unsigned char *input,
435 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000436{
437 sha1_update( (sha1_context *) ctx, input, ilen );
438}
439
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100440static void sha1_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000441{
442 sha1_finish( (sha1_context *) ctx, output );
443}
444
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100445static int sha1_file_wrap( const char *path, unsigned char *output )
Paul Bakker335db3f2011-04-25 15:28:35 +0000446{
447#if defined(POLARSSL_FS_IO)
448 return sha1_file( path, output );
449#else
450 ((void) path);
451 ((void) output);
452 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
453#endif
454}
455
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200456static void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key,
457 size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000458{
459 sha1_hmac_starts( (sha1_context *) ctx, key, keylen );
460}
461
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200462static void sha1_hmac_update_wrap( void *ctx, const unsigned char *input,
463 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000464{
465 sha1_hmac_update( (sha1_context *) ctx, input, ilen );
466}
467
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100468static void sha1_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000469{
470 sha1_hmac_finish( (sha1_context *) ctx, output );
471}
472
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100473static void sha1_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000474{
475 sha1_hmac_reset( (sha1_context *) ctx );
476}
477
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100478static void * sha1_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000479{
Paul Bakker6e339b52013-07-03 13:37:05 +0200480 return polarssl_malloc( sizeof( sha1_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000481}
482
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100483static void sha1_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000484{
Paul Bakker6e339b52013-07-03 13:37:05 +0200485 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000486}
487
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100488static void sha1_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100489{
490 sha1_process( (sha1_context *) ctx, data );
491}
492
Paul Bakker17373852011-01-06 14:20:01 +0000493const md_info_t sha1_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000494 POLARSSL_MD_SHA1,
495 "SHA1",
496 20,
497 sha1_starts_wrap,
498 sha1_update_wrap,
499 sha1_finish_wrap,
500 sha1,
Paul Bakker335db3f2011-04-25 15:28:35 +0000501 sha1_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000502 sha1_hmac_starts_wrap,
503 sha1_hmac_update_wrap,
504 sha1_hmac_finish_wrap,
505 sha1_hmac_reset_wrap,
506 sha1_hmac,
507 sha1_ctx_alloc,
508 sha1_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100509 sha1_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000510};
511
Paul Bakker9af723c2014-05-01 13:03:14 +0200512#endif /* POLARSSL_SHA1_C */
Paul Bakker17373852011-01-06 14:20:01 +0000513
514/*
515 * Wrappers for generic message digests
516 */
Paul Bakker9e36f042013-06-30 14:34:05 +0200517#if defined(POLARSSL_SHA256_C)
Paul Bakker17373852011-01-06 14:20:01 +0000518
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100519static void sha224_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000520{
Paul Bakker9e36f042013-06-30 14:34:05 +0200521 sha256_starts( (sha256_context *) ctx, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000522}
523
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200524static void sha224_update_wrap( void *ctx, const unsigned char *input,
525 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000526{
Paul Bakker9e36f042013-06-30 14:34:05 +0200527 sha256_update( (sha256_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000528}
529
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100530static void sha224_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000531{
Paul Bakker9e36f042013-06-30 14:34:05 +0200532 sha256_finish( (sha256_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000533}
534
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100535static void sha224_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000536 unsigned char *output )
537{
Paul Bakker9e36f042013-06-30 14:34:05 +0200538 sha256( input, ilen, output, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000539}
540
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100541static int sha224_file_wrap( const char *path, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000542{
Paul Bakker335db3f2011-04-25 15:28:35 +0000543#if defined(POLARSSL_FS_IO)
Paul Bakker9e36f042013-06-30 14:34:05 +0200544 return sha256_file( path, output, 1 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000545#else
546 ((void) path);
547 ((void) output);
548 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
549#endif
Paul Bakker17373852011-01-06 14:20:01 +0000550}
551
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200552static void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key,
553 size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000554{
Paul Bakker9e36f042013-06-30 14:34:05 +0200555 sha256_hmac_starts( (sha256_context *) ctx, key, keylen, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000556}
557
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200558static void sha224_hmac_update_wrap( void *ctx, const unsigned char *input,
559 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000560{
Paul Bakker9e36f042013-06-30 14:34:05 +0200561 sha256_hmac_update( (sha256_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000562}
563
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100564static void sha224_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000565{
Paul Bakker9e36f042013-06-30 14:34:05 +0200566 sha256_hmac_finish( (sha256_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000567}
568
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100569static void sha224_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000570{
Paul Bakker9e36f042013-06-30 14:34:05 +0200571 sha256_hmac_reset( (sha256_context *) ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000572}
573
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100574static void sha224_hmac_wrap( const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000575 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000576 unsigned char *output )
577{
Paul Bakker9e36f042013-06-30 14:34:05 +0200578 sha256_hmac( key, keylen, input, ilen, output, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000579}
580
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100581static void * sha224_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000582{
Paul Bakker6e339b52013-07-03 13:37:05 +0200583 return polarssl_malloc( sizeof( sha256_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000584}
585
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100586static void sha224_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000587{
Paul Bakker6e339b52013-07-03 13:37:05 +0200588 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000589}
590
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100591static void sha224_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100592{
Paul Bakker9e36f042013-06-30 14:34:05 +0200593 sha256_process( (sha256_context *) ctx, data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100594}
595
Paul Bakker17373852011-01-06 14:20:01 +0000596const md_info_t sha224_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000597 POLARSSL_MD_SHA224,
598 "SHA224",
599 28,
600 sha224_starts_wrap,
601 sha224_update_wrap,
602 sha224_finish_wrap,
603 sha224_wrap,
604 sha224_file_wrap,
605 sha224_hmac_starts_wrap,
606 sha224_hmac_update_wrap,
607 sha224_hmac_finish_wrap,
608 sha224_hmac_reset_wrap,
609 sha224_hmac_wrap,
610 sha224_ctx_alloc,
611 sha224_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100612 sha224_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000613};
614
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100615static void sha256_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000616{
Paul Bakker9e36f042013-06-30 14:34:05 +0200617 sha256_starts( (sha256_context *) ctx, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000618}
619
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200620static void sha256_update_wrap( void *ctx, const unsigned char *input,
621 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000622{
Paul Bakker9e36f042013-06-30 14:34:05 +0200623 sha256_update( (sha256_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000624}
625
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100626static void sha256_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000627{
Paul Bakker9e36f042013-06-30 14:34:05 +0200628 sha256_finish( (sha256_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000629}
630
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100631static void sha256_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000632 unsigned char *output )
633{
Paul Bakker9e36f042013-06-30 14:34:05 +0200634 sha256( input, ilen, output, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000635}
636
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100637static int sha256_file_wrap( const char *path, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000638{
Paul Bakker335db3f2011-04-25 15:28:35 +0000639#if defined(POLARSSL_FS_IO)
Paul Bakker9e36f042013-06-30 14:34:05 +0200640 return sha256_file( path, output, 0 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000641#else
642 ((void) path);
643 ((void) output);
644 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
645#endif
Paul Bakker17373852011-01-06 14:20:01 +0000646}
647
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200648static void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key,
649 size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000650{
Paul Bakker9e36f042013-06-30 14:34:05 +0200651 sha256_hmac_starts( (sha256_context *) ctx, key, keylen, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000652}
653
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200654static void sha256_hmac_update_wrap( void *ctx, const unsigned char *input,
655 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000656{
Paul Bakker9e36f042013-06-30 14:34:05 +0200657 sha256_hmac_update( (sha256_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000658}
659
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100660static void sha256_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000661{
Paul Bakker9e36f042013-06-30 14:34:05 +0200662 sha256_hmac_finish( (sha256_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000663}
664
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100665static void sha256_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000666{
Paul Bakker9e36f042013-06-30 14:34:05 +0200667 sha256_hmac_reset( (sha256_context *) ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000668}
669
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100670static void sha256_hmac_wrap( const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000671 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000672 unsigned char *output )
673{
Paul Bakker9e36f042013-06-30 14:34:05 +0200674 sha256_hmac( key, keylen, input, ilen, output, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000675}
676
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100677static void * sha256_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000678{
Paul Bakker6e339b52013-07-03 13:37:05 +0200679 return polarssl_malloc( sizeof( sha256_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000680}
681
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100682static void sha256_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000683{
Paul Bakker6e339b52013-07-03 13:37:05 +0200684 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000685}
686
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100687static void sha256_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100688{
Paul Bakker9e36f042013-06-30 14:34:05 +0200689 sha256_process( (sha256_context *) ctx, data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100690}
691
Paul Bakker17373852011-01-06 14:20:01 +0000692const md_info_t sha256_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000693 POLARSSL_MD_SHA256,
694 "SHA256",
695 32,
696 sha256_starts_wrap,
697 sha256_update_wrap,
698 sha256_finish_wrap,
699 sha256_wrap,
700 sha256_file_wrap,
701 sha256_hmac_starts_wrap,
702 sha256_hmac_update_wrap,
703 sha256_hmac_finish_wrap,
704 sha256_hmac_reset_wrap,
705 sha256_hmac_wrap,
706 sha256_ctx_alloc,
707 sha256_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100708 sha256_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000709};
710
Paul Bakker9af723c2014-05-01 13:03:14 +0200711#endif /* POLARSSL_SHA256_C */
Paul Bakker17373852011-01-06 14:20:01 +0000712
Paul Bakker9e36f042013-06-30 14:34:05 +0200713#if defined(POLARSSL_SHA512_C)
Paul Bakker17373852011-01-06 14:20:01 +0000714
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100715static void sha384_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000716{
Paul Bakker9e36f042013-06-30 14:34:05 +0200717 sha512_starts( (sha512_context *) ctx, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000718}
719
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200720static void sha384_update_wrap( void *ctx, const unsigned char *input,
721 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000722{
Paul Bakker9e36f042013-06-30 14:34:05 +0200723 sha512_update( (sha512_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000724}
725
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100726static void sha384_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000727{
Paul Bakker9e36f042013-06-30 14:34:05 +0200728 sha512_finish( (sha512_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000729}
730
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100731static void sha384_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000732 unsigned char *output )
733{
Paul Bakker9e36f042013-06-30 14:34:05 +0200734 sha512( input, ilen, output, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000735}
736
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100737static int sha384_file_wrap( const char *path, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000738{
Paul Bakker335db3f2011-04-25 15:28:35 +0000739#if defined(POLARSSL_FS_IO)
Paul Bakker9e36f042013-06-30 14:34:05 +0200740 return sha512_file( path, output, 1 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000741#else
742 ((void) path);
743 ((void) output);
744 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
745#endif
Paul Bakker17373852011-01-06 14:20:01 +0000746}
747
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200748static void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key,
749 size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000750{
Paul Bakker9e36f042013-06-30 14:34:05 +0200751 sha512_hmac_starts( (sha512_context *) ctx, key, keylen, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000752}
753
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200754static void sha384_hmac_update_wrap( void *ctx, const unsigned char *input,
755 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000756{
Paul Bakker9e36f042013-06-30 14:34:05 +0200757 sha512_hmac_update( (sha512_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000758}
759
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100760static void sha384_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000761{
Paul Bakker9e36f042013-06-30 14:34:05 +0200762 sha512_hmac_finish( (sha512_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000763}
764
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100765static void sha384_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000766{
Paul Bakker9e36f042013-06-30 14:34:05 +0200767 sha512_hmac_reset( (sha512_context *) ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000768}
769
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100770static void sha384_hmac_wrap( const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000771 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000772 unsigned char *output )
773{
Paul Bakker9e36f042013-06-30 14:34:05 +0200774 sha512_hmac( key, keylen, input, ilen, output, 1 );
Paul Bakker17373852011-01-06 14:20:01 +0000775}
776
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100777static void * sha384_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000778{
Paul Bakker6e339b52013-07-03 13:37:05 +0200779 return polarssl_malloc( sizeof( sha512_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000780}
781
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100782static void sha384_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000783{
Paul Bakker6e339b52013-07-03 13:37:05 +0200784 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000785}
786
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100787static void sha384_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100788{
Paul Bakker9e36f042013-06-30 14:34:05 +0200789 sha512_process( (sha512_context *) ctx, data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100790}
791
Paul Bakker17373852011-01-06 14:20:01 +0000792const md_info_t sha384_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000793 POLARSSL_MD_SHA384,
794 "SHA384",
795 48,
796 sha384_starts_wrap,
797 sha384_update_wrap,
798 sha384_finish_wrap,
799 sha384_wrap,
800 sha384_file_wrap,
801 sha384_hmac_starts_wrap,
802 sha384_hmac_update_wrap,
803 sha384_hmac_finish_wrap,
804 sha384_hmac_reset_wrap,
805 sha384_hmac_wrap,
806 sha384_ctx_alloc,
807 sha384_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100808 sha384_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000809};
810
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100811static void sha512_starts_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000812{
Paul Bakker9e36f042013-06-30 14:34:05 +0200813 sha512_starts( (sha512_context *) ctx, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000814}
815
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200816static void sha512_update_wrap( void *ctx, const unsigned char *input,
817 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000818{
Paul Bakker9e36f042013-06-30 14:34:05 +0200819 sha512_update( (sha512_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000820}
821
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100822static void sha512_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000823{
Paul Bakker9e36f042013-06-30 14:34:05 +0200824 sha512_finish( (sha512_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000825}
826
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100827static void sha512_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000828 unsigned char *output )
829{
Paul Bakker9e36f042013-06-30 14:34:05 +0200830 sha512( input, ilen, output, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000831}
832
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100833static int sha512_file_wrap( const char *path, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000834{
Paul Bakker335db3f2011-04-25 15:28:35 +0000835#if defined(POLARSSL_FS_IO)
Paul Bakker9e36f042013-06-30 14:34:05 +0200836 return sha512_file( path, output, 0 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000837#else
838 ((void) path);
839 ((void) output);
840 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
841#endif
Paul Bakker17373852011-01-06 14:20:01 +0000842}
843
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200844static void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key,
845 size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000846{
Paul Bakker9e36f042013-06-30 14:34:05 +0200847 sha512_hmac_starts( (sha512_context *) ctx, key, keylen, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000848}
849
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200850static void sha512_hmac_update_wrap( void *ctx, const unsigned char *input,
851 size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000852{
Paul Bakker9e36f042013-06-30 14:34:05 +0200853 sha512_hmac_update( (sha512_context *) ctx, input, ilen );
Paul Bakker17373852011-01-06 14:20:01 +0000854}
855
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100856static void sha512_hmac_finish_wrap( void *ctx, unsigned char *output )
Paul Bakker17373852011-01-06 14:20:01 +0000857{
Paul Bakker9e36f042013-06-30 14:34:05 +0200858 sha512_hmac_finish( (sha512_context *) ctx, output );
Paul Bakker17373852011-01-06 14:20:01 +0000859}
860
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100861static void sha512_hmac_reset_wrap( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000862{
Paul Bakker9e36f042013-06-30 14:34:05 +0200863 sha512_hmac_reset( (sha512_context *) ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000864}
865
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100866static void sha512_hmac_wrap( const unsigned char *key, size_t keylen,
Paul Bakker23986e52011-04-24 08:57:21 +0000867 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000868 unsigned char *output )
869{
Paul Bakker9e36f042013-06-30 14:34:05 +0200870 sha512_hmac( key, keylen, input, ilen, output, 0 );
Paul Bakker17373852011-01-06 14:20:01 +0000871}
872
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100873static void * sha512_ctx_alloc( void )
Paul Bakker17373852011-01-06 14:20:01 +0000874{
Paul Bakker6e339b52013-07-03 13:37:05 +0200875 return polarssl_malloc( sizeof( sha512_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000876}
877
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100878static void sha512_ctx_free( void *ctx )
Paul Bakker17373852011-01-06 14:20:01 +0000879{
Paul Bakker6e339b52013-07-03 13:37:05 +0200880 polarssl_free( ctx );
Paul Bakker17373852011-01-06 14:20:01 +0000881}
882
Paul Bakkerd1df02a2013-03-13 10:31:31 +0100883static void sha512_process_wrap( void *ctx, const unsigned char *data )
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100884{
Paul Bakker9e36f042013-06-30 14:34:05 +0200885 sha512_process( (sha512_context *) ctx, data );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100886}
887
Paul Bakker17373852011-01-06 14:20:01 +0000888const md_info_t sha512_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000889 POLARSSL_MD_SHA512,
890 "SHA512",
891 64,
892 sha512_starts_wrap,
893 sha512_update_wrap,
894 sha512_finish_wrap,
895 sha512_wrap,
896 sha512_file_wrap,
897 sha512_hmac_starts_wrap,
898 sha512_hmac_update_wrap,
899 sha512_hmac_finish_wrap,
900 sha512_hmac_reset_wrap,
901 sha512_hmac_wrap,
902 sha512_ctx_alloc,
903 sha512_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100904 sha512_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000905};
906
Paul Bakker9af723c2014-05-01 13:03:14 +0200907#endif /* POLARSSL_SHA512_C */
Paul Bakker17373852011-01-06 14:20:01 +0000908
Paul Bakker9af723c2014-05-01 13:03:14 +0200909#endif /* POLARSSL_MD_C */