blob: 64d8bb67399839c334cabd7844fbed7e70a9a85f [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 *
8 * Copyright (C) 2006-2010, Brainspark B.V.
9 *
10 * This file is part of PolarSSL (http://www.polarssl.org)
11 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
12 *
13 * All rights reserved.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 */
29
30#include "polarssl/config.h"
31
32#if defined(POLARSSL_MD_C)
33
34#include "polarssl/md_wrap.h"
35#include "polarssl/md2.h"
36#include "polarssl/md4.h"
37#include "polarssl/md5.h"
38#include "polarssl/sha1.h"
39#include "polarssl/sha2.h"
40#include "polarssl/sha4.h"
41
Paul Bakker17373852011-01-06 14:20:01 +000042#include <stdlib.h>
43
44#if defined(POLARSSL_MD2_C)
45
46static void md2_starts_wrap( void *ctx )
47{
48 md2_starts( (md2_context *) ctx );
49}
50
Paul Bakker23986e52011-04-24 08:57:21 +000051static void md2_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +000052{
53 md2_update( (md2_context *) ctx, input, ilen );
54}
55
56static void md2_finish_wrap( void *ctx, unsigned char *output )
57{
58 md2_finish( (md2_context *) ctx, output );
59}
60
Paul Bakker335db3f2011-04-25 15:28:35 +000061int md2_file_wrap( const char *path, unsigned char *output )
62{
63#if defined(POLARSSL_FS_IO)
64 return md2_file( path, output );
65#else
66 ((void) path);
67 ((void) output);
68 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
69#endif
70}
71
Paul Bakker23986e52011-04-24 08:57:21 +000072static void md2_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +000073{
74 md2_hmac_starts( (md2_context *) ctx, key, keylen );
75}
76
Paul Bakker23986e52011-04-24 08:57:21 +000077static void md2_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +000078{
79 md2_hmac_update( (md2_context *) ctx, input, ilen );
80}
81
82static void md2_hmac_finish_wrap( void *ctx, unsigned char *output )
83{
84 md2_hmac_finish( (md2_context *) ctx, output );
85}
86
87static void md2_hmac_reset_wrap( void *ctx )
88{
89 md2_hmac_reset( (md2_context *) ctx );
90}
91
92static void * md2_ctx_alloc( void )
93{
94 return malloc( sizeof( md2_context ) );
95}
96
97static void md2_ctx_free( void *ctx )
98{
99 free( ctx );
100}
101
102const md_info_t md2_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000103 POLARSSL_MD_MD2,
104 "MD2",
105 16,
106 md2_starts_wrap,
107 md2_update_wrap,
108 md2_finish_wrap,
109 md2,
Paul Bakker335db3f2011-04-25 15:28:35 +0000110 md2_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000111 md2_hmac_starts_wrap,
112 md2_hmac_update_wrap,
113 md2_hmac_finish_wrap,
114 md2_hmac_reset_wrap,
115 md2_hmac,
116 md2_ctx_alloc,
117 md2_ctx_free,
Paul Bakker17373852011-01-06 14:20:01 +0000118};
119
120#endif
121
122#if defined(POLARSSL_MD4_C)
123
124void md4_starts_wrap( void *ctx )
125{
126 md4_starts( (md4_context *) ctx );
127}
128
Paul Bakker23986e52011-04-24 08:57:21 +0000129void md4_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000130{
131 md4_update( (md4_context *) ctx, input, ilen );
132}
133
134void md4_finish_wrap( void *ctx, unsigned char *output )
135{
136 md4_finish( (md4_context *) ctx, output );
137}
138
Paul Bakker335db3f2011-04-25 15:28:35 +0000139int md4_file_wrap( const char *path, unsigned char *output )
140{
141#if defined(POLARSSL_FS_IO)
142 return md4_file( path, output );
143#else
144 ((void) path);
145 ((void) output);
146 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
147#endif
148}
149
Paul Bakker23986e52011-04-24 08:57:21 +0000150void md4_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000151{
152 md4_hmac_starts( (md4_context *) ctx, key, keylen );
153}
154
Paul Bakker23986e52011-04-24 08:57:21 +0000155void md4_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000156{
157 md4_hmac_update( (md4_context *) ctx, input, ilen );
158}
159
160void md4_hmac_finish_wrap( void *ctx, unsigned char *output )
161{
162 md4_hmac_finish( (md4_context *) ctx, output );
163}
164
165void md4_hmac_reset_wrap( void *ctx )
166{
167 md4_hmac_reset( (md4_context *) ctx );
168}
169
170void *md4_ctx_alloc( void )
171{
172 return malloc( sizeof( md4_context ) );
173}
174
175void md4_ctx_free( void *ctx )
176{
177 free( ctx );
178}
179
180const md_info_t md4_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000181 POLARSSL_MD_MD4,
182 "MD4",
183 16,
184 md4_starts_wrap,
185 md4_update_wrap,
186 md4_finish_wrap,
187 md4,
Paul Bakker335db3f2011-04-25 15:28:35 +0000188 md4_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000189 md4_hmac_starts_wrap,
190 md4_hmac_update_wrap,
191 md4_hmac_finish_wrap,
192 md4_hmac_reset_wrap,
193 md4_hmac,
194 md4_ctx_alloc,
195 md4_ctx_free,
Paul Bakker17373852011-01-06 14:20:01 +0000196};
197
198#endif
199
200#if defined(POLARSSL_MD5_C)
201
202static void md5_starts_wrap( void *ctx )
203{
204 md5_starts( (md5_context *) ctx );
205}
206
Paul Bakker23986e52011-04-24 08:57:21 +0000207static void md5_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000208{
209 md5_update( (md5_context *) ctx, input, ilen );
210}
211
212static void md5_finish_wrap( void *ctx, unsigned char *output )
213{
214 md5_finish( (md5_context *) ctx, output );
215}
216
Paul Bakker335db3f2011-04-25 15:28:35 +0000217int md5_file_wrap( const char *path, unsigned char *output )
218{
219#if defined(POLARSSL_FS_IO)
220 return md5_file( path, output );
221#else
222 ((void) path);
223 ((void) output);
224 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
225#endif
226}
227
Paul Bakker23986e52011-04-24 08:57:21 +0000228static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000229{
230 md5_hmac_starts( (md5_context *) ctx, key, keylen );
231}
232
Paul Bakker23986e52011-04-24 08:57:21 +0000233static void md5_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000234{
235 md5_hmac_update( (md5_context *) ctx, input, ilen );
236}
237
238static void md5_hmac_finish_wrap( void *ctx, unsigned char *output )
239{
240 md5_hmac_finish( (md5_context *) ctx, output );
241}
242
243static void md5_hmac_reset_wrap( void *ctx )
244{
245 md5_hmac_reset( (md5_context *) ctx );
246}
247
248static void * md5_ctx_alloc( void )
249{
250 return malloc( sizeof( md5_context ) );
251}
252
253static void md5_ctx_free( void *ctx )
254{
255 free( ctx );
256}
257
258const md_info_t md5_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000259 POLARSSL_MD_MD5,
260 "MD5",
261 16,
262 md5_starts_wrap,
263 md5_update_wrap,
264 md5_finish_wrap,
265 md5,
Paul Bakker335db3f2011-04-25 15:28:35 +0000266 md5_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000267 md5_hmac_starts_wrap,
268 md5_hmac_update_wrap,
269 md5_hmac_finish_wrap,
270 md5_hmac_reset_wrap,
271 md5_hmac,
272 md5_ctx_alloc,
273 md5_ctx_free,
Paul Bakker17373852011-01-06 14:20:01 +0000274};
275
276#endif
277
278#if defined(POLARSSL_SHA1_C)
279
280void sha1_starts_wrap( void *ctx )
281{
282 sha1_starts( (sha1_context *) ctx );
283}
284
Paul Bakker23986e52011-04-24 08:57:21 +0000285void sha1_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000286{
287 sha1_update( (sha1_context *) ctx, input, ilen );
288}
289
290void sha1_finish_wrap( void *ctx, unsigned char *output )
291{
292 sha1_finish( (sha1_context *) ctx, output );
293}
294
Paul Bakker335db3f2011-04-25 15:28:35 +0000295int sha1_file_wrap( const char *path, unsigned char *output )
296{
297#if defined(POLARSSL_FS_IO)
298 return sha1_file( path, output );
299#else
300 ((void) path);
301 ((void) output);
302 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
303#endif
304}
305
Paul Bakker23986e52011-04-24 08:57:21 +0000306void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000307{
308 sha1_hmac_starts( (sha1_context *) ctx, key, keylen );
309}
310
Paul Bakker23986e52011-04-24 08:57:21 +0000311void sha1_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000312{
313 sha1_hmac_update( (sha1_context *) ctx, input, ilen );
314}
315
316void sha1_hmac_finish_wrap( void *ctx, unsigned char *output )
317{
318 sha1_hmac_finish( (sha1_context *) ctx, output );
319}
320
321void sha1_hmac_reset_wrap( void *ctx )
322{
323 sha1_hmac_reset( (sha1_context *) ctx );
324}
325
326void * sha1_ctx_alloc( void )
327{
328 return malloc( sizeof( sha1_context ) );
329}
330
331void sha1_ctx_free( void *ctx )
332{
333 free( ctx );
334}
335
336const md_info_t sha1_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000337 POLARSSL_MD_SHA1,
338 "SHA1",
339 20,
340 sha1_starts_wrap,
341 sha1_update_wrap,
342 sha1_finish_wrap,
343 sha1,
Paul Bakker335db3f2011-04-25 15:28:35 +0000344 sha1_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000345 sha1_hmac_starts_wrap,
346 sha1_hmac_update_wrap,
347 sha1_hmac_finish_wrap,
348 sha1_hmac_reset_wrap,
349 sha1_hmac,
350 sha1_ctx_alloc,
351 sha1_ctx_free,
Paul Bakker17373852011-01-06 14:20:01 +0000352};
353
354#endif
355
356/*
357 * Wrappers for generic message digests
358 */
359#if defined(POLARSSL_SHA2_C)
360
361void sha224_starts_wrap( void *ctx )
362{
363 sha2_starts( (sha2_context *) ctx, 1 );
364}
365
Paul Bakker23986e52011-04-24 08:57:21 +0000366void sha224_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000367{
368 sha2_update( (sha2_context *) ctx, input, ilen );
369}
370
371void sha224_finish_wrap( void *ctx, unsigned char *output )
372{
373 sha2_finish( (sha2_context *) ctx, output );
374}
375
Paul Bakker23986e52011-04-24 08:57:21 +0000376void sha224_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000377 unsigned char *output )
378{
379 sha2( input, ilen, output, 1 );
380}
381
382int sha224_file_wrap( const char *path, unsigned char *output )
383{
Paul Bakker335db3f2011-04-25 15:28:35 +0000384#if defined(POLARSSL_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000385 return sha2_file( path, output, 1 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000386#else
387 ((void) path);
388 ((void) output);
389 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
390#endif
Paul Bakker17373852011-01-06 14:20:01 +0000391}
392
Paul Bakker23986e52011-04-24 08:57:21 +0000393void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000394{
395 sha2_hmac_starts( (sha2_context *) ctx, key, keylen, 1 );
396}
397
Paul Bakker23986e52011-04-24 08:57:21 +0000398void sha224_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000399{
400 sha2_hmac_update( (sha2_context *) ctx, input, ilen );
401}
402
403void sha224_hmac_finish_wrap( void *ctx, unsigned char *output )
404{
405 sha2_hmac_finish( (sha2_context *) ctx, output );
406}
407
408void sha224_hmac_reset_wrap( void *ctx )
409{
410 sha2_hmac_reset( (sha2_context *) ctx );
411}
412
Paul Bakker23986e52011-04-24 08:57:21 +0000413void sha224_hmac_wrap( const unsigned char *key, size_t keylen,
414 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000415 unsigned char *output )
416{
417 sha2_hmac( key, keylen, input, ilen, output, 1 );
418}
419
420void * sha224_ctx_alloc( void )
421{
422 return malloc( sizeof( sha2_context ) );
423}
424
425void sha224_ctx_free( void *ctx )
426{
427 free( ctx );
428}
429
430const md_info_t sha224_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000431 POLARSSL_MD_SHA224,
432 "SHA224",
433 28,
434 sha224_starts_wrap,
435 sha224_update_wrap,
436 sha224_finish_wrap,
437 sha224_wrap,
438 sha224_file_wrap,
439 sha224_hmac_starts_wrap,
440 sha224_hmac_update_wrap,
441 sha224_hmac_finish_wrap,
442 sha224_hmac_reset_wrap,
443 sha224_hmac_wrap,
444 sha224_ctx_alloc,
445 sha224_ctx_free,
Paul Bakker17373852011-01-06 14:20:01 +0000446};
447
448void sha256_starts_wrap( void *ctx )
449{
450 sha2_starts( (sha2_context *) ctx, 0 );
451}
452
Paul Bakker23986e52011-04-24 08:57:21 +0000453void sha256_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000454{
455 sha2_update( (sha2_context *) ctx, input, ilen );
456}
457
458void sha256_finish_wrap( void *ctx, unsigned char *output )
459{
460 sha2_finish( (sha2_context *) ctx, output );
461}
462
Paul Bakker23986e52011-04-24 08:57:21 +0000463void sha256_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000464 unsigned char *output )
465{
466 sha2( input, ilen, output, 0 );
467}
468
469int sha256_file_wrap( const char *path, unsigned char *output )
470{
Paul Bakker335db3f2011-04-25 15:28:35 +0000471#if defined(POLARSSL_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000472 return sha2_file( path, output, 0 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000473#else
474 ((void) path);
475 ((void) output);
476 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
477#endif
Paul Bakker17373852011-01-06 14:20:01 +0000478}
479
Paul Bakker23986e52011-04-24 08:57:21 +0000480void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000481{
482 sha2_hmac_starts( (sha2_context *) ctx, key, keylen, 0 );
483}
484
Paul Bakker23986e52011-04-24 08:57:21 +0000485void sha256_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000486{
487 sha2_hmac_update( (sha2_context *) ctx, input, ilen );
488}
489
490void sha256_hmac_finish_wrap( void *ctx, unsigned char *output )
491{
492 sha2_hmac_finish( (sha2_context *) ctx, output );
493}
494
495void sha256_hmac_reset_wrap( void *ctx )
496{
497 sha2_hmac_reset( (sha2_context *) ctx );
498}
499
Paul Bakker23986e52011-04-24 08:57:21 +0000500void sha256_hmac_wrap( const unsigned char *key, size_t keylen,
501 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000502 unsigned char *output )
503{
504 sha2_hmac( key, keylen, input, ilen, output, 0 );
505}
506
507void * sha256_ctx_alloc( void )
508{
Paul Bakker6d468122011-01-06 15:35:45 +0000509 return malloc( sizeof( sha2_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000510}
511
512void sha256_ctx_free( void *ctx )
513{
514 free( ctx );
515}
516
517const md_info_t sha256_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000518 POLARSSL_MD_SHA256,
519 "SHA256",
520 32,
521 sha256_starts_wrap,
522 sha256_update_wrap,
523 sha256_finish_wrap,
524 sha256_wrap,
525 sha256_file_wrap,
526 sha256_hmac_starts_wrap,
527 sha256_hmac_update_wrap,
528 sha256_hmac_finish_wrap,
529 sha256_hmac_reset_wrap,
530 sha256_hmac_wrap,
531 sha256_ctx_alloc,
532 sha256_ctx_free,
Paul Bakker17373852011-01-06 14:20:01 +0000533};
534
535#endif
536
537#if defined(POLARSSL_SHA4_C)
538
539void sha384_starts_wrap( void *ctx )
540{
541 sha4_starts( (sha4_context *) ctx, 1 );
542}
543
Paul Bakker23986e52011-04-24 08:57:21 +0000544void sha384_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000545{
546 sha4_update( (sha4_context *) ctx, input, ilen );
547}
548
549void sha384_finish_wrap( void *ctx, unsigned char *output )
550{
551 sha4_finish( (sha4_context *) ctx, output );
552}
553
Paul Bakker23986e52011-04-24 08:57:21 +0000554void sha384_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000555 unsigned char *output )
556{
557 sha4( input, ilen, output, 1 );
558}
559
560int sha384_file_wrap( const char *path, unsigned char *output )
561{
Paul Bakker335db3f2011-04-25 15:28:35 +0000562#if defined(POLARSSL_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000563 return sha4_file( path, output, 1 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000564#else
565 ((void) path);
566 ((void) output);
567 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
568#endif
Paul Bakker17373852011-01-06 14:20:01 +0000569}
570
Paul Bakker23986e52011-04-24 08:57:21 +0000571void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000572{
573 sha4_hmac_starts( (sha4_context *) ctx, key, keylen, 1 );
574}
575
Paul Bakker23986e52011-04-24 08:57:21 +0000576void sha384_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000577{
578 sha4_hmac_update( (sha4_context *) ctx, input, ilen );
579}
580
581void sha384_hmac_finish_wrap( void *ctx, unsigned char *output )
582{
583 sha4_hmac_finish( (sha4_context *) ctx, output );
584}
585
586void sha384_hmac_reset_wrap( void *ctx )
587{
588 sha4_hmac_reset( (sha4_context *) ctx );
589}
590
Paul Bakker23986e52011-04-24 08:57:21 +0000591void sha384_hmac_wrap( const unsigned char *key, size_t keylen,
592 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000593 unsigned char *output )
594{
595 sha4_hmac( key, keylen, input, ilen, output, 1 );
596}
597
598void * sha384_ctx_alloc( void )
599{
600 return malloc( sizeof( sha4_context ) );
601}
602
603void sha384_ctx_free( void *ctx )
604{
605 free( ctx );
606}
607
608const md_info_t sha384_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000609 POLARSSL_MD_SHA384,
610 "SHA384",
611 48,
612 sha384_starts_wrap,
613 sha384_update_wrap,
614 sha384_finish_wrap,
615 sha384_wrap,
616 sha384_file_wrap,
617 sha384_hmac_starts_wrap,
618 sha384_hmac_update_wrap,
619 sha384_hmac_finish_wrap,
620 sha384_hmac_reset_wrap,
621 sha384_hmac_wrap,
622 sha384_ctx_alloc,
623 sha384_ctx_free,
Paul Bakker17373852011-01-06 14:20:01 +0000624};
625
626void sha512_starts_wrap( void *ctx )
627{
628 sha4_starts( (sha4_context *) ctx, 0 );
629}
630
Paul Bakker23986e52011-04-24 08:57:21 +0000631void sha512_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000632{
633 sha4_update( (sha4_context *) ctx, input, ilen );
634}
635
636void sha512_finish_wrap( void *ctx, unsigned char *output )
637{
638 sha4_finish( (sha4_context *) ctx, output );
639}
640
Paul Bakker23986e52011-04-24 08:57:21 +0000641void sha512_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000642 unsigned char *output )
643{
644 sha4( input, ilen, output, 0 );
645}
646
647int sha512_file_wrap( const char *path, unsigned char *output )
648{
Paul Bakker335db3f2011-04-25 15:28:35 +0000649#if defined(POLARSSL_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000650 return sha4_file( path, output, 0 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000651#else
652 ((void) path);
653 ((void) output);
654 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
655#endif
Paul Bakker17373852011-01-06 14:20:01 +0000656}
657
Paul Bakker23986e52011-04-24 08:57:21 +0000658void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000659{
660 sha4_hmac_starts( (sha4_context *) ctx, key, keylen, 0 );
661}
662
Paul Bakker23986e52011-04-24 08:57:21 +0000663void sha512_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000664{
665 sha4_hmac_update( (sha4_context *) ctx, input, ilen );
666}
667
668void sha512_hmac_finish_wrap( void *ctx, unsigned char *output )
669{
670 sha4_hmac_finish( (sha4_context *) ctx, output );
671}
672
673void sha512_hmac_reset_wrap( void *ctx )
674{
675 sha4_hmac_reset( (sha4_context *) ctx );
676}
677
Paul Bakker23986e52011-04-24 08:57:21 +0000678void sha512_hmac_wrap( const unsigned char *key, size_t keylen,
679 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000680 unsigned char *output )
681{
682 sha4_hmac( key, keylen, input, ilen, output, 0 );
683}
684
685void * sha512_ctx_alloc( void )
686{
687 return malloc( sizeof( sha4_context ) );
688}
689
690void sha512_ctx_free( void *ctx )
691{
692 free( ctx );
693}
694
695const md_info_t sha512_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000696 POLARSSL_MD_SHA512,
697 "SHA512",
698 64,
699 sha512_starts_wrap,
700 sha512_update_wrap,
701 sha512_finish_wrap,
702 sha512_wrap,
703 sha512_file_wrap,
704 sha512_hmac_starts_wrap,
705 sha512_hmac_update_wrap,
706 sha512_hmac_finish_wrap,
707 sha512_hmac_reset_wrap,
708 sha512_hmac_wrap,
709 sha512_ctx_alloc,
710 sha512_ctx_free,
Paul Bakker17373852011-01-06 14:20:01 +0000711};
712
713#endif
714
715#endif