blob: 93c35f39cd877de03cdbe832ba49e98b8ac0b25b [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"
Paul Bakkerf6543712012-03-05 14:01:29 +000035
36#if defined(POLARSSL_MD2_C)
Paul Bakker17373852011-01-06 14:20:01 +000037#include "polarssl/md2.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000038#endif
39
40#if defined(POLARSSL_MD4_C)
Paul Bakker17373852011-01-06 14:20:01 +000041#include "polarssl/md4.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000042#endif
43
44#if defined(POLARSSL_MD5_C)
Paul Bakker17373852011-01-06 14:20:01 +000045#include "polarssl/md5.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000046#endif
47
48#if defined(POLARSSL_SHA1_C)
Paul Bakker17373852011-01-06 14:20:01 +000049#include "polarssl/sha1.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000050#endif
51
52#if defined(POLARSSL_SHA2_C)
Paul Bakker17373852011-01-06 14:20:01 +000053#include "polarssl/sha2.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000054#endif
55
56#if defined(POLARSSL_SHA4_C)
Paul Bakker17373852011-01-06 14:20:01 +000057#include "polarssl/sha4.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000058#endif
Paul Bakker17373852011-01-06 14:20:01 +000059
Paul Bakker17373852011-01-06 14:20:01 +000060#include <stdlib.h>
61
62#if defined(POLARSSL_MD2_C)
63
64static void md2_starts_wrap( void *ctx )
65{
66 md2_starts( (md2_context *) ctx );
67}
68
Paul Bakker23986e52011-04-24 08:57:21 +000069static void md2_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +000070{
71 md2_update( (md2_context *) ctx, input, ilen );
72}
73
74static void md2_finish_wrap( void *ctx, unsigned char *output )
75{
76 md2_finish( (md2_context *) ctx, output );
77}
78
Paul Bakker335db3f2011-04-25 15:28:35 +000079int md2_file_wrap( const char *path, unsigned char *output )
80{
81#if defined(POLARSSL_FS_IO)
82 return md2_file( path, output );
83#else
84 ((void) path);
85 ((void) output);
86 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
87#endif
88}
89
Paul Bakker23986e52011-04-24 08:57:21 +000090static void md2_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +000091{
92 md2_hmac_starts( (md2_context *) ctx, key, keylen );
93}
94
Paul Bakker23986e52011-04-24 08:57:21 +000095static void md2_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +000096{
97 md2_hmac_update( (md2_context *) ctx, input, ilen );
98}
99
100static void md2_hmac_finish_wrap( void *ctx, unsigned char *output )
101{
102 md2_hmac_finish( (md2_context *) ctx, output );
103}
104
105static void md2_hmac_reset_wrap( void *ctx )
106{
107 md2_hmac_reset( (md2_context *) ctx );
108}
109
110static void * md2_ctx_alloc( void )
111{
112 return malloc( sizeof( md2_context ) );
113}
114
115static void md2_ctx_free( void *ctx )
116{
117 free( ctx );
118}
119
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100120static void md2_process_wrap( void *ctx, const unsigned char *data )
121{
122 ((void) data);
123
124 md2_process( (md2_context *) ctx );
125}
126
Paul Bakker17373852011-01-06 14:20:01 +0000127const md_info_t md2_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000128 POLARSSL_MD_MD2,
129 "MD2",
130 16,
131 md2_starts_wrap,
132 md2_update_wrap,
133 md2_finish_wrap,
134 md2,
Paul Bakker335db3f2011-04-25 15:28:35 +0000135 md2_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000136 md2_hmac_starts_wrap,
137 md2_hmac_update_wrap,
138 md2_hmac_finish_wrap,
139 md2_hmac_reset_wrap,
140 md2_hmac,
141 md2_ctx_alloc,
142 md2_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100143 md2_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000144};
145
146#endif
147
148#if defined(POLARSSL_MD4_C)
149
150void md4_starts_wrap( void *ctx )
151{
152 md4_starts( (md4_context *) ctx );
153}
154
Paul Bakker23986e52011-04-24 08:57:21 +0000155void md4_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000156{
157 md4_update( (md4_context *) ctx, input, ilen );
158}
159
160void md4_finish_wrap( void *ctx, unsigned char *output )
161{
162 md4_finish( (md4_context *) ctx, output );
163}
164
Paul Bakker335db3f2011-04-25 15:28:35 +0000165int md4_file_wrap( const char *path, unsigned char *output )
166{
167#if defined(POLARSSL_FS_IO)
168 return md4_file( path, output );
169#else
170 ((void) path);
171 ((void) output);
172 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
173#endif
174}
175
Paul Bakker23986e52011-04-24 08:57:21 +0000176void md4_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000177{
178 md4_hmac_starts( (md4_context *) ctx, key, keylen );
179}
180
Paul Bakker23986e52011-04-24 08:57:21 +0000181void md4_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000182{
183 md4_hmac_update( (md4_context *) ctx, input, ilen );
184}
185
186void md4_hmac_finish_wrap( void *ctx, unsigned char *output )
187{
188 md4_hmac_finish( (md4_context *) ctx, output );
189}
190
191void md4_hmac_reset_wrap( void *ctx )
192{
193 md4_hmac_reset( (md4_context *) ctx );
194}
195
196void *md4_ctx_alloc( void )
197{
198 return malloc( sizeof( md4_context ) );
199}
200
201void md4_ctx_free( void *ctx )
202{
203 free( ctx );
204}
205
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100206void md4_process_wrap( void *ctx, const unsigned char *data )
207{
208 md4_process( (md4_context *) ctx, data );
209}
210
Paul Bakker17373852011-01-06 14:20:01 +0000211const md_info_t md4_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000212 POLARSSL_MD_MD4,
213 "MD4",
214 16,
215 md4_starts_wrap,
216 md4_update_wrap,
217 md4_finish_wrap,
218 md4,
Paul Bakker335db3f2011-04-25 15:28:35 +0000219 md4_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000220 md4_hmac_starts_wrap,
221 md4_hmac_update_wrap,
222 md4_hmac_finish_wrap,
223 md4_hmac_reset_wrap,
224 md4_hmac,
225 md4_ctx_alloc,
226 md4_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100227 md4_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000228};
229
230#endif
231
232#if defined(POLARSSL_MD5_C)
233
234static void md5_starts_wrap( void *ctx )
235{
236 md5_starts( (md5_context *) ctx );
237}
238
Paul Bakker23986e52011-04-24 08:57:21 +0000239static void md5_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000240{
241 md5_update( (md5_context *) ctx, input, ilen );
242}
243
244static void md5_finish_wrap( void *ctx, unsigned char *output )
245{
246 md5_finish( (md5_context *) ctx, output );
247}
248
Paul Bakker335db3f2011-04-25 15:28:35 +0000249int md5_file_wrap( const char *path, unsigned char *output )
250{
251#if defined(POLARSSL_FS_IO)
252 return md5_file( path, output );
253#else
254 ((void) path);
255 ((void) output);
256 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
257#endif
258}
259
Paul Bakker23986e52011-04-24 08:57:21 +0000260static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000261{
262 md5_hmac_starts( (md5_context *) ctx, key, keylen );
263}
264
Paul Bakker23986e52011-04-24 08:57:21 +0000265static void md5_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000266{
267 md5_hmac_update( (md5_context *) ctx, input, ilen );
268}
269
270static void md5_hmac_finish_wrap( void *ctx, unsigned char *output )
271{
272 md5_hmac_finish( (md5_context *) ctx, output );
273}
274
275static void md5_hmac_reset_wrap( void *ctx )
276{
277 md5_hmac_reset( (md5_context *) ctx );
278}
279
280static void * md5_ctx_alloc( void )
281{
282 return malloc( sizeof( md5_context ) );
283}
284
285static void md5_ctx_free( void *ctx )
286{
287 free( ctx );
288}
289
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100290static void md5_process_wrap( void *ctx, const unsigned char *data )
291{
292 md5_process( (md5_context *) ctx, data );
293}
294
Paul Bakker17373852011-01-06 14:20:01 +0000295const md_info_t md5_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000296 POLARSSL_MD_MD5,
297 "MD5",
298 16,
299 md5_starts_wrap,
300 md5_update_wrap,
301 md5_finish_wrap,
302 md5,
Paul Bakker335db3f2011-04-25 15:28:35 +0000303 md5_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000304 md5_hmac_starts_wrap,
305 md5_hmac_update_wrap,
306 md5_hmac_finish_wrap,
307 md5_hmac_reset_wrap,
308 md5_hmac,
309 md5_ctx_alloc,
310 md5_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100311 md5_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000312};
313
314#endif
315
316#if defined(POLARSSL_SHA1_C)
317
318void sha1_starts_wrap( void *ctx )
319{
320 sha1_starts( (sha1_context *) ctx );
321}
322
Paul Bakker23986e52011-04-24 08:57:21 +0000323void sha1_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000324{
325 sha1_update( (sha1_context *) ctx, input, ilen );
326}
327
328void sha1_finish_wrap( void *ctx, unsigned char *output )
329{
330 sha1_finish( (sha1_context *) ctx, output );
331}
332
Paul Bakker335db3f2011-04-25 15:28:35 +0000333int sha1_file_wrap( const char *path, unsigned char *output )
334{
335#if defined(POLARSSL_FS_IO)
336 return sha1_file( path, output );
337#else
338 ((void) path);
339 ((void) output);
340 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
341#endif
342}
343
Paul Bakker23986e52011-04-24 08:57:21 +0000344void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000345{
346 sha1_hmac_starts( (sha1_context *) ctx, key, keylen );
347}
348
Paul Bakker23986e52011-04-24 08:57:21 +0000349void sha1_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000350{
351 sha1_hmac_update( (sha1_context *) ctx, input, ilen );
352}
353
354void sha1_hmac_finish_wrap( void *ctx, unsigned char *output )
355{
356 sha1_hmac_finish( (sha1_context *) ctx, output );
357}
358
359void sha1_hmac_reset_wrap( void *ctx )
360{
361 sha1_hmac_reset( (sha1_context *) ctx );
362}
363
364void * sha1_ctx_alloc( void )
365{
366 return malloc( sizeof( sha1_context ) );
367}
368
369void sha1_ctx_free( void *ctx )
370{
371 free( ctx );
372}
373
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100374void sha1_process_wrap( void *ctx, const unsigned char *data )
375{
376 sha1_process( (sha1_context *) ctx, data );
377}
378
Paul Bakker17373852011-01-06 14:20:01 +0000379const md_info_t sha1_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000380 POLARSSL_MD_SHA1,
381 "SHA1",
382 20,
383 sha1_starts_wrap,
384 sha1_update_wrap,
385 sha1_finish_wrap,
386 sha1,
Paul Bakker335db3f2011-04-25 15:28:35 +0000387 sha1_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000388 sha1_hmac_starts_wrap,
389 sha1_hmac_update_wrap,
390 sha1_hmac_finish_wrap,
391 sha1_hmac_reset_wrap,
392 sha1_hmac,
393 sha1_ctx_alloc,
394 sha1_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100395 sha1_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000396};
397
398#endif
399
400/*
401 * Wrappers for generic message digests
402 */
403#if defined(POLARSSL_SHA2_C)
404
405void sha224_starts_wrap( void *ctx )
406{
407 sha2_starts( (sha2_context *) ctx, 1 );
408}
409
Paul Bakker23986e52011-04-24 08:57:21 +0000410void sha224_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000411{
412 sha2_update( (sha2_context *) ctx, input, ilen );
413}
414
415void sha224_finish_wrap( void *ctx, unsigned char *output )
416{
417 sha2_finish( (sha2_context *) ctx, output );
418}
419
Paul Bakker23986e52011-04-24 08:57:21 +0000420void sha224_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000421 unsigned char *output )
422{
423 sha2( input, ilen, output, 1 );
424}
425
426int sha224_file_wrap( const char *path, unsigned char *output )
427{
Paul Bakker335db3f2011-04-25 15:28:35 +0000428#if defined(POLARSSL_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000429 return sha2_file( path, output, 1 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000430#else
431 ((void) path);
432 ((void) output);
433 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
434#endif
Paul Bakker17373852011-01-06 14:20:01 +0000435}
436
Paul Bakker23986e52011-04-24 08:57:21 +0000437void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000438{
439 sha2_hmac_starts( (sha2_context *) ctx, key, keylen, 1 );
440}
441
Paul Bakker23986e52011-04-24 08:57:21 +0000442void sha224_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000443{
444 sha2_hmac_update( (sha2_context *) ctx, input, ilen );
445}
446
447void sha224_hmac_finish_wrap( void *ctx, unsigned char *output )
448{
449 sha2_hmac_finish( (sha2_context *) ctx, output );
450}
451
452void sha224_hmac_reset_wrap( void *ctx )
453{
454 sha2_hmac_reset( (sha2_context *) ctx );
455}
456
Paul Bakker23986e52011-04-24 08:57:21 +0000457void sha224_hmac_wrap( const unsigned char *key, size_t keylen,
458 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000459 unsigned char *output )
460{
461 sha2_hmac( key, keylen, input, ilen, output, 1 );
462}
463
464void * sha224_ctx_alloc( void )
465{
466 return malloc( sizeof( sha2_context ) );
467}
468
469void sha224_ctx_free( void *ctx )
470{
471 free( ctx );
472}
473
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100474void sha224_process_wrap( void *ctx, const unsigned char *data )
475{
476 sha2_process( (sha2_context *) ctx, data );
477}
478
Paul Bakker17373852011-01-06 14:20:01 +0000479const md_info_t sha224_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000480 POLARSSL_MD_SHA224,
481 "SHA224",
482 28,
483 sha224_starts_wrap,
484 sha224_update_wrap,
485 sha224_finish_wrap,
486 sha224_wrap,
487 sha224_file_wrap,
488 sha224_hmac_starts_wrap,
489 sha224_hmac_update_wrap,
490 sha224_hmac_finish_wrap,
491 sha224_hmac_reset_wrap,
492 sha224_hmac_wrap,
493 sha224_ctx_alloc,
494 sha224_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100495 sha224_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000496};
497
498void sha256_starts_wrap( void *ctx )
499{
500 sha2_starts( (sha2_context *) ctx, 0 );
501}
502
Paul Bakker23986e52011-04-24 08:57:21 +0000503void sha256_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000504{
505 sha2_update( (sha2_context *) ctx, input, ilen );
506}
507
508void sha256_finish_wrap( void *ctx, unsigned char *output )
509{
510 sha2_finish( (sha2_context *) ctx, output );
511}
512
Paul Bakker23986e52011-04-24 08:57:21 +0000513void sha256_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000514 unsigned char *output )
515{
516 sha2( input, ilen, output, 0 );
517}
518
519int sha256_file_wrap( const char *path, unsigned char *output )
520{
Paul Bakker335db3f2011-04-25 15:28:35 +0000521#if defined(POLARSSL_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000522 return sha2_file( path, output, 0 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000523#else
524 ((void) path);
525 ((void) output);
526 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
527#endif
Paul Bakker17373852011-01-06 14:20:01 +0000528}
529
Paul Bakker23986e52011-04-24 08:57:21 +0000530void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000531{
532 sha2_hmac_starts( (sha2_context *) ctx, key, keylen, 0 );
533}
534
Paul Bakker23986e52011-04-24 08:57:21 +0000535void sha256_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000536{
537 sha2_hmac_update( (sha2_context *) ctx, input, ilen );
538}
539
540void sha256_hmac_finish_wrap( void *ctx, unsigned char *output )
541{
542 sha2_hmac_finish( (sha2_context *) ctx, output );
543}
544
545void sha256_hmac_reset_wrap( void *ctx )
546{
547 sha2_hmac_reset( (sha2_context *) ctx );
548}
549
Paul Bakker23986e52011-04-24 08:57:21 +0000550void sha256_hmac_wrap( const unsigned char *key, size_t keylen,
551 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000552 unsigned char *output )
553{
554 sha2_hmac( key, keylen, input, ilen, output, 0 );
555}
556
557void * sha256_ctx_alloc( void )
558{
Paul Bakker6d468122011-01-06 15:35:45 +0000559 return malloc( sizeof( sha2_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000560}
561
562void sha256_ctx_free( void *ctx )
563{
564 free( ctx );
565}
566
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100567void sha256_process_wrap( void *ctx, const unsigned char *data )
568{
569 sha2_process( (sha2_context *) ctx, data );
570}
571
Paul Bakker17373852011-01-06 14:20:01 +0000572const md_info_t sha256_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000573 POLARSSL_MD_SHA256,
574 "SHA256",
575 32,
576 sha256_starts_wrap,
577 sha256_update_wrap,
578 sha256_finish_wrap,
579 sha256_wrap,
580 sha256_file_wrap,
581 sha256_hmac_starts_wrap,
582 sha256_hmac_update_wrap,
583 sha256_hmac_finish_wrap,
584 sha256_hmac_reset_wrap,
585 sha256_hmac_wrap,
586 sha256_ctx_alloc,
587 sha256_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100588 sha256_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000589};
590
591#endif
592
593#if defined(POLARSSL_SHA4_C)
594
595void sha384_starts_wrap( void *ctx )
596{
597 sha4_starts( (sha4_context *) ctx, 1 );
598}
599
Paul Bakker23986e52011-04-24 08:57:21 +0000600void sha384_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000601{
602 sha4_update( (sha4_context *) ctx, input, ilen );
603}
604
605void sha384_finish_wrap( void *ctx, unsigned char *output )
606{
607 sha4_finish( (sha4_context *) ctx, output );
608}
609
Paul Bakker23986e52011-04-24 08:57:21 +0000610void sha384_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000611 unsigned char *output )
612{
613 sha4( input, ilen, output, 1 );
614}
615
616int sha384_file_wrap( const char *path, unsigned char *output )
617{
Paul Bakker335db3f2011-04-25 15:28:35 +0000618#if defined(POLARSSL_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000619 return sha4_file( path, output, 1 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000620#else
621 ((void) path);
622 ((void) output);
623 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
624#endif
Paul Bakker17373852011-01-06 14:20:01 +0000625}
626
Paul Bakker23986e52011-04-24 08:57:21 +0000627void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000628{
629 sha4_hmac_starts( (sha4_context *) ctx, key, keylen, 1 );
630}
631
Paul Bakker23986e52011-04-24 08:57:21 +0000632void sha384_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000633{
634 sha4_hmac_update( (sha4_context *) ctx, input, ilen );
635}
636
637void sha384_hmac_finish_wrap( void *ctx, unsigned char *output )
638{
639 sha4_hmac_finish( (sha4_context *) ctx, output );
640}
641
642void sha384_hmac_reset_wrap( void *ctx )
643{
644 sha4_hmac_reset( (sha4_context *) ctx );
645}
646
Paul Bakker23986e52011-04-24 08:57:21 +0000647void sha384_hmac_wrap( const unsigned char *key, size_t keylen,
648 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000649 unsigned char *output )
650{
651 sha4_hmac( key, keylen, input, ilen, output, 1 );
652}
653
654void * sha384_ctx_alloc( void )
655{
656 return malloc( sizeof( sha4_context ) );
657}
658
659void sha384_ctx_free( void *ctx )
660{
661 free( ctx );
662}
663
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100664void sha384_process_wrap( void *ctx, const unsigned char *data )
665{
666 sha4_process( (sha4_context *) ctx, data );
667}
668
Paul Bakker17373852011-01-06 14:20:01 +0000669const md_info_t sha384_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000670 POLARSSL_MD_SHA384,
671 "SHA384",
672 48,
673 sha384_starts_wrap,
674 sha384_update_wrap,
675 sha384_finish_wrap,
676 sha384_wrap,
677 sha384_file_wrap,
678 sha384_hmac_starts_wrap,
679 sha384_hmac_update_wrap,
680 sha384_hmac_finish_wrap,
681 sha384_hmac_reset_wrap,
682 sha384_hmac_wrap,
683 sha384_ctx_alloc,
684 sha384_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100685 sha384_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000686};
687
688void sha512_starts_wrap( void *ctx )
689{
690 sha4_starts( (sha4_context *) ctx, 0 );
691}
692
Paul Bakker23986e52011-04-24 08:57:21 +0000693void sha512_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000694{
695 sha4_update( (sha4_context *) ctx, input, ilen );
696}
697
698void sha512_finish_wrap( void *ctx, unsigned char *output )
699{
700 sha4_finish( (sha4_context *) ctx, output );
701}
702
Paul Bakker23986e52011-04-24 08:57:21 +0000703void sha512_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000704 unsigned char *output )
705{
706 sha4( input, ilen, output, 0 );
707}
708
709int sha512_file_wrap( const char *path, unsigned char *output )
710{
Paul Bakker335db3f2011-04-25 15:28:35 +0000711#if defined(POLARSSL_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000712 return sha4_file( path, output, 0 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000713#else
714 ((void) path);
715 ((void) output);
716 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
717#endif
Paul Bakker17373852011-01-06 14:20:01 +0000718}
719
Paul Bakker23986e52011-04-24 08:57:21 +0000720void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000721{
722 sha4_hmac_starts( (sha4_context *) ctx, key, keylen, 0 );
723}
724
Paul Bakker23986e52011-04-24 08:57:21 +0000725void sha512_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000726{
727 sha4_hmac_update( (sha4_context *) ctx, input, ilen );
728}
729
730void sha512_hmac_finish_wrap( void *ctx, unsigned char *output )
731{
732 sha4_hmac_finish( (sha4_context *) ctx, output );
733}
734
735void sha512_hmac_reset_wrap( void *ctx )
736{
737 sha4_hmac_reset( (sha4_context *) ctx );
738}
739
Paul Bakker23986e52011-04-24 08:57:21 +0000740void sha512_hmac_wrap( const unsigned char *key, size_t keylen,
741 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000742 unsigned char *output )
743{
744 sha4_hmac( key, keylen, input, ilen, output, 0 );
745}
746
747void * sha512_ctx_alloc( void )
748{
749 return malloc( sizeof( sha4_context ) );
750}
751
752void sha512_ctx_free( void *ctx )
753{
754 free( ctx );
755}
756
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100757void sha512_process_wrap( void *ctx, const unsigned char *data )
758{
759 sha4_process( (sha4_context *) ctx, data );
760}
761
Paul Bakker17373852011-01-06 14:20:01 +0000762const md_info_t sha512_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000763 POLARSSL_MD_SHA512,
764 "SHA512",
765 64,
766 sha512_starts_wrap,
767 sha512_update_wrap,
768 sha512_finish_wrap,
769 sha512_wrap,
770 sha512_file_wrap,
771 sha512_hmac_starts_wrap,
772 sha512_hmac_update_wrap,
773 sha512_hmac_finish_wrap,
774 sha512_hmac_reset_wrap,
775 sha512_hmac_wrap,
776 sha512_ctx_alloc,
777 sha512_ctx_free,
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100778 sha512_process_wrap,
Paul Bakker17373852011-01-06 14:20:01 +0000779};
780
781#endif
782
783#endif