blob: f276db5925c2c16880732b5fc4387fbf83d2cba0 [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
120const md_info_t md2_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000121 POLARSSL_MD_MD2,
122 "MD2",
123 16,
124 md2_starts_wrap,
125 md2_update_wrap,
126 md2_finish_wrap,
127 md2,
Paul Bakker335db3f2011-04-25 15:28:35 +0000128 md2_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000129 md2_hmac_starts_wrap,
130 md2_hmac_update_wrap,
131 md2_hmac_finish_wrap,
132 md2_hmac_reset_wrap,
133 md2_hmac,
134 md2_ctx_alloc,
135 md2_ctx_free,
Paul Bakker17373852011-01-06 14:20:01 +0000136};
137
138#endif
139
140#if defined(POLARSSL_MD4_C)
141
142void md4_starts_wrap( void *ctx )
143{
144 md4_starts( (md4_context *) ctx );
145}
146
Paul Bakker23986e52011-04-24 08:57:21 +0000147void md4_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000148{
149 md4_update( (md4_context *) ctx, input, ilen );
150}
151
152void md4_finish_wrap( void *ctx, unsigned char *output )
153{
154 md4_finish( (md4_context *) ctx, output );
155}
156
Paul Bakker335db3f2011-04-25 15:28:35 +0000157int md4_file_wrap( const char *path, unsigned char *output )
158{
159#if defined(POLARSSL_FS_IO)
160 return md4_file( path, output );
161#else
162 ((void) path);
163 ((void) output);
164 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
165#endif
166}
167
Paul Bakker23986e52011-04-24 08:57:21 +0000168void md4_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000169{
170 md4_hmac_starts( (md4_context *) ctx, key, keylen );
171}
172
Paul Bakker23986e52011-04-24 08:57:21 +0000173void md4_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000174{
175 md4_hmac_update( (md4_context *) ctx, input, ilen );
176}
177
178void md4_hmac_finish_wrap( void *ctx, unsigned char *output )
179{
180 md4_hmac_finish( (md4_context *) ctx, output );
181}
182
183void md4_hmac_reset_wrap( void *ctx )
184{
185 md4_hmac_reset( (md4_context *) ctx );
186}
187
188void *md4_ctx_alloc( void )
189{
190 return malloc( sizeof( md4_context ) );
191}
192
193void md4_ctx_free( void *ctx )
194{
195 free( ctx );
196}
197
198const md_info_t md4_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000199 POLARSSL_MD_MD4,
200 "MD4",
201 16,
202 md4_starts_wrap,
203 md4_update_wrap,
204 md4_finish_wrap,
205 md4,
Paul Bakker335db3f2011-04-25 15:28:35 +0000206 md4_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000207 md4_hmac_starts_wrap,
208 md4_hmac_update_wrap,
209 md4_hmac_finish_wrap,
210 md4_hmac_reset_wrap,
211 md4_hmac,
212 md4_ctx_alloc,
213 md4_ctx_free,
Paul Bakker17373852011-01-06 14:20:01 +0000214};
215
216#endif
217
218#if defined(POLARSSL_MD5_C)
219
220static void md5_starts_wrap( void *ctx )
221{
222 md5_starts( (md5_context *) ctx );
223}
224
Paul Bakker23986e52011-04-24 08:57:21 +0000225static void md5_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000226{
227 md5_update( (md5_context *) ctx, input, ilen );
228}
229
230static void md5_finish_wrap( void *ctx, unsigned char *output )
231{
232 md5_finish( (md5_context *) ctx, output );
233}
234
Paul Bakker335db3f2011-04-25 15:28:35 +0000235int md5_file_wrap( const char *path, unsigned char *output )
236{
237#if defined(POLARSSL_FS_IO)
238 return md5_file( path, output );
239#else
240 ((void) path);
241 ((void) output);
242 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
243#endif
244}
245
Paul Bakker23986e52011-04-24 08:57:21 +0000246static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000247{
248 md5_hmac_starts( (md5_context *) ctx, key, keylen );
249}
250
Paul Bakker23986e52011-04-24 08:57:21 +0000251static void md5_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000252{
253 md5_hmac_update( (md5_context *) ctx, input, ilen );
254}
255
256static void md5_hmac_finish_wrap( void *ctx, unsigned char *output )
257{
258 md5_hmac_finish( (md5_context *) ctx, output );
259}
260
261static void md5_hmac_reset_wrap( void *ctx )
262{
263 md5_hmac_reset( (md5_context *) ctx );
264}
265
266static void * md5_ctx_alloc( void )
267{
268 return malloc( sizeof( md5_context ) );
269}
270
271static void md5_ctx_free( void *ctx )
272{
273 free( ctx );
274}
275
276const md_info_t md5_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000277 POLARSSL_MD_MD5,
278 "MD5",
279 16,
280 md5_starts_wrap,
281 md5_update_wrap,
282 md5_finish_wrap,
283 md5,
Paul Bakker335db3f2011-04-25 15:28:35 +0000284 md5_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000285 md5_hmac_starts_wrap,
286 md5_hmac_update_wrap,
287 md5_hmac_finish_wrap,
288 md5_hmac_reset_wrap,
289 md5_hmac,
290 md5_ctx_alloc,
291 md5_ctx_free,
Paul Bakker17373852011-01-06 14:20:01 +0000292};
293
294#endif
295
296#if defined(POLARSSL_SHA1_C)
297
298void sha1_starts_wrap( void *ctx )
299{
300 sha1_starts( (sha1_context *) ctx );
301}
302
Paul Bakker23986e52011-04-24 08:57:21 +0000303void sha1_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000304{
305 sha1_update( (sha1_context *) ctx, input, ilen );
306}
307
308void sha1_finish_wrap( void *ctx, unsigned char *output )
309{
310 sha1_finish( (sha1_context *) ctx, output );
311}
312
Paul Bakker335db3f2011-04-25 15:28:35 +0000313int sha1_file_wrap( const char *path, unsigned char *output )
314{
315#if defined(POLARSSL_FS_IO)
316 return sha1_file( path, output );
317#else
318 ((void) path);
319 ((void) output);
320 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
321#endif
322}
323
Paul Bakker23986e52011-04-24 08:57:21 +0000324void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000325{
326 sha1_hmac_starts( (sha1_context *) ctx, key, keylen );
327}
328
Paul Bakker23986e52011-04-24 08:57:21 +0000329void sha1_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000330{
331 sha1_hmac_update( (sha1_context *) ctx, input, ilen );
332}
333
334void sha1_hmac_finish_wrap( void *ctx, unsigned char *output )
335{
336 sha1_hmac_finish( (sha1_context *) ctx, output );
337}
338
339void sha1_hmac_reset_wrap( void *ctx )
340{
341 sha1_hmac_reset( (sha1_context *) ctx );
342}
343
344void * sha1_ctx_alloc( void )
345{
346 return malloc( sizeof( sha1_context ) );
347}
348
349void sha1_ctx_free( void *ctx )
350{
351 free( ctx );
352}
353
354const md_info_t sha1_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000355 POLARSSL_MD_SHA1,
356 "SHA1",
357 20,
358 sha1_starts_wrap,
359 sha1_update_wrap,
360 sha1_finish_wrap,
361 sha1,
Paul Bakker335db3f2011-04-25 15:28:35 +0000362 sha1_file_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000363 sha1_hmac_starts_wrap,
364 sha1_hmac_update_wrap,
365 sha1_hmac_finish_wrap,
366 sha1_hmac_reset_wrap,
367 sha1_hmac,
368 sha1_ctx_alloc,
369 sha1_ctx_free,
Paul Bakker17373852011-01-06 14:20:01 +0000370};
371
372#endif
373
374/*
375 * Wrappers for generic message digests
376 */
377#if defined(POLARSSL_SHA2_C)
378
379void sha224_starts_wrap( void *ctx )
380{
381 sha2_starts( (sha2_context *) ctx, 1 );
382}
383
Paul Bakker23986e52011-04-24 08:57:21 +0000384void sha224_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000385{
386 sha2_update( (sha2_context *) ctx, input, ilen );
387}
388
389void sha224_finish_wrap( void *ctx, unsigned char *output )
390{
391 sha2_finish( (sha2_context *) ctx, output );
392}
393
Paul Bakker23986e52011-04-24 08:57:21 +0000394void sha224_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000395 unsigned char *output )
396{
397 sha2( input, ilen, output, 1 );
398}
399
400int sha224_file_wrap( const char *path, unsigned char *output )
401{
Paul Bakker335db3f2011-04-25 15:28:35 +0000402#if defined(POLARSSL_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000403 return sha2_file( path, output, 1 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000404#else
405 ((void) path);
406 ((void) output);
407 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
408#endif
Paul Bakker17373852011-01-06 14:20:01 +0000409}
410
Paul Bakker23986e52011-04-24 08:57:21 +0000411void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000412{
413 sha2_hmac_starts( (sha2_context *) ctx, key, keylen, 1 );
414}
415
Paul Bakker23986e52011-04-24 08:57:21 +0000416void sha224_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000417{
418 sha2_hmac_update( (sha2_context *) ctx, input, ilen );
419}
420
421void sha224_hmac_finish_wrap( void *ctx, unsigned char *output )
422{
423 sha2_hmac_finish( (sha2_context *) ctx, output );
424}
425
426void sha224_hmac_reset_wrap( void *ctx )
427{
428 sha2_hmac_reset( (sha2_context *) ctx );
429}
430
Paul Bakker23986e52011-04-24 08:57:21 +0000431void sha224_hmac_wrap( const unsigned char *key, size_t keylen,
432 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000433 unsigned char *output )
434{
435 sha2_hmac( key, keylen, input, ilen, output, 1 );
436}
437
438void * sha224_ctx_alloc( void )
439{
440 return malloc( sizeof( sha2_context ) );
441}
442
443void sha224_ctx_free( void *ctx )
444{
445 free( ctx );
446}
447
448const md_info_t sha224_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000449 POLARSSL_MD_SHA224,
450 "SHA224",
451 28,
452 sha224_starts_wrap,
453 sha224_update_wrap,
454 sha224_finish_wrap,
455 sha224_wrap,
456 sha224_file_wrap,
457 sha224_hmac_starts_wrap,
458 sha224_hmac_update_wrap,
459 sha224_hmac_finish_wrap,
460 sha224_hmac_reset_wrap,
461 sha224_hmac_wrap,
462 sha224_ctx_alloc,
463 sha224_ctx_free,
Paul Bakker17373852011-01-06 14:20:01 +0000464};
465
466void sha256_starts_wrap( void *ctx )
467{
468 sha2_starts( (sha2_context *) ctx, 0 );
469}
470
Paul Bakker23986e52011-04-24 08:57:21 +0000471void sha256_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000472{
473 sha2_update( (sha2_context *) ctx, input, ilen );
474}
475
476void sha256_finish_wrap( void *ctx, unsigned char *output )
477{
478 sha2_finish( (sha2_context *) ctx, output );
479}
480
Paul Bakker23986e52011-04-24 08:57:21 +0000481void sha256_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000482 unsigned char *output )
483{
484 sha2( input, ilen, output, 0 );
485}
486
487int sha256_file_wrap( const char *path, unsigned char *output )
488{
Paul Bakker335db3f2011-04-25 15:28:35 +0000489#if defined(POLARSSL_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000490 return sha2_file( path, output, 0 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000491#else
492 ((void) path);
493 ((void) output);
494 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
495#endif
Paul Bakker17373852011-01-06 14:20:01 +0000496}
497
Paul Bakker23986e52011-04-24 08:57:21 +0000498void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000499{
500 sha2_hmac_starts( (sha2_context *) ctx, key, keylen, 0 );
501}
502
Paul Bakker23986e52011-04-24 08:57:21 +0000503void sha256_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000504{
505 sha2_hmac_update( (sha2_context *) ctx, input, ilen );
506}
507
508void sha256_hmac_finish_wrap( void *ctx, unsigned char *output )
509{
510 sha2_hmac_finish( (sha2_context *) ctx, output );
511}
512
513void sha256_hmac_reset_wrap( void *ctx )
514{
515 sha2_hmac_reset( (sha2_context *) ctx );
516}
517
Paul Bakker23986e52011-04-24 08:57:21 +0000518void sha256_hmac_wrap( const unsigned char *key, size_t keylen,
519 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000520 unsigned char *output )
521{
522 sha2_hmac( key, keylen, input, ilen, output, 0 );
523}
524
525void * sha256_ctx_alloc( void )
526{
Paul Bakker6d468122011-01-06 15:35:45 +0000527 return malloc( sizeof( sha2_context ) );
Paul Bakker17373852011-01-06 14:20:01 +0000528}
529
530void sha256_ctx_free( void *ctx )
531{
532 free( ctx );
533}
534
535const md_info_t sha256_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000536 POLARSSL_MD_SHA256,
537 "SHA256",
538 32,
539 sha256_starts_wrap,
540 sha256_update_wrap,
541 sha256_finish_wrap,
542 sha256_wrap,
543 sha256_file_wrap,
544 sha256_hmac_starts_wrap,
545 sha256_hmac_update_wrap,
546 sha256_hmac_finish_wrap,
547 sha256_hmac_reset_wrap,
548 sha256_hmac_wrap,
549 sha256_ctx_alloc,
550 sha256_ctx_free,
Paul Bakker17373852011-01-06 14:20:01 +0000551};
552
553#endif
554
555#if defined(POLARSSL_SHA4_C)
556
557void sha384_starts_wrap( void *ctx )
558{
559 sha4_starts( (sha4_context *) ctx, 1 );
560}
561
Paul Bakker23986e52011-04-24 08:57:21 +0000562void sha384_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000563{
564 sha4_update( (sha4_context *) ctx, input, ilen );
565}
566
567void sha384_finish_wrap( void *ctx, unsigned char *output )
568{
569 sha4_finish( (sha4_context *) ctx, output );
570}
571
Paul Bakker23986e52011-04-24 08:57:21 +0000572void sha384_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000573 unsigned char *output )
574{
575 sha4( input, ilen, output, 1 );
576}
577
578int sha384_file_wrap( const char *path, unsigned char *output )
579{
Paul Bakker335db3f2011-04-25 15:28:35 +0000580#if defined(POLARSSL_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000581 return sha4_file( path, output, 1 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000582#else
583 ((void) path);
584 ((void) output);
585 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
586#endif
Paul Bakker17373852011-01-06 14:20:01 +0000587}
588
Paul Bakker23986e52011-04-24 08:57:21 +0000589void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000590{
591 sha4_hmac_starts( (sha4_context *) ctx, key, keylen, 1 );
592}
593
Paul Bakker23986e52011-04-24 08:57:21 +0000594void sha384_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000595{
596 sha4_hmac_update( (sha4_context *) ctx, input, ilen );
597}
598
599void sha384_hmac_finish_wrap( void *ctx, unsigned char *output )
600{
601 sha4_hmac_finish( (sha4_context *) ctx, output );
602}
603
604void sha384_hmac_reset_wrap( void *ctx )
605{
606 sha4_hmac_reset( (sha4_context *) ctx );
607}
608
Paul Bakker23986e52011-04-24 08:57:21 +0000609void sha384_hmac_wrap( const unsigned char *key, size_t keylen,
610 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000611 unsigned char *output )
612{
613 sha4_hmac( key, keylen, input, ilen, output, 1 );
614}
615
616void * sha384_ctx_alloc( void )
617{
618 return malloc( sizeof( sha4_context ) );
619}
620
621void sha384_ctx_free( void *ctx )
622{
623 free( ctx );
624}
625
626const md_info_t sha384_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000627 POLARSSL_MD_SHA384,
628 "SHA384",
629 48,
630 sha384_starts_wrap,
631 sha384_update_wrap,
632 sha384_finish_wrap,
633 sha384_wrap,
634 sha384_file_wrap,
635 sha384_hmac_starts_wrap,
636 sha384_hmac_update_wrap,
637 sha384_hmac_finish_wrap,
638 sha384_hmac_reset_wrap,
639 sha384_hmac_wrap,
640 sha384_ctx_alloc,
641 sha384_ctx_free,
Paul Bakker17373852011-01-06 14:20:01 +0000642};
643
644void sha512_starts_wrap( void *ctx )
645{
646 sha4_starts( (sha4_context *) ctx, 0 );
647}
648
Paul Bakker23986e52011-04-24 08:57:21 +0000649void sha512_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000650{
651 sha4_update( (sha4_context *) ctx, input, ilen );
652}
653
654void sha512_finish_wrap( void *ctx, unsigned char *output )
655{
656 sha4_finish( (sha4_context *) ctx, output );
657}
658
Paul Bakker23986e52011-04-24 08:57:21 +0000659void sha512_wrap( const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000660 unsigned char *output )
661{
662 sha4( input, ilen, output, 0 );
663}
664
665int sha512_file_wrap( const char *path, unsigned char *output )
666{
Paul Bakker335db3f2011-04-25 15:28:35 +0000667#if defined(POLARSSL_FS_IO)
Paul Bakker17373852011-01-06 14:20:01 +0000668 return sha4_file( path, output, 0 );
Paul Bakker335db3f2011-04-25 15:28:35 +0000669#else
670 ((void) path);
671 ((void) output);
672 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
673#endif
Paul Bakker17373852011-01-06 14:20:01 +0000674}
675
Paul Bakker23986e52011-04-24 08:57:21 +0000676void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
Paul Bakker17373852011-01-06 14:20:01 +0000677{
678 sha4_hmac_starts( (sha4_context *) ctx, key, keylen, 0 );
679}
680
Paul Bakker23986e52011-04-24 08:57:21 +0000681void sha512_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
Paul Bakker17373852011-01-06 14:20:01 +0000682{
683 sha4_hmac_update( (sha4_context *) ctx, input, ilen );
684}
685
686void sha512_hmac_finish_wrap( void *ctx, unsigned char *output )
687{
688 sha4_hmac_finish( (sha4_context *) ctx, output );
689}
690
691void sha512_hmac_reset_wrap( void *ctx )
692{
693 sha4_hmac_reset( (sha4_context *) ctx );
694}
695
Paul Bakker23986e52011-04-24 08:57:21 +0000696void sha512_hmac_wrap( const unsigned char *key, size_t keylen,
697 const unsigned char *input, size_t ilen,
Paul Bakker17373852011-01-06 14:20:01 +0000698 unsigned char *output )
699{
700 sha4_hmac( key, keylen, input, ilen, output, 0 );
701}
702
703void * sha512_ctx_alloc( void )
704{
705 return malloc( sizeof( sha4_context ) );
706}
707
708void sha512_ctx_free( void *ctx )
709{
710 free( ctx );
711}
712
713const md_info_t sha512_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000714 POLARSSL_MD_SHA512,
715 "SHA512",
716 64,
717 sha512_starts_wrap,
718 sha512_update_wrap,
719 sha512_finish_wrap,
720 sha512_wrap,
721 sha512_file_wrap,
722 sha512_hmac_starts_wrap,
723 sha512_hmac_update_wrap,
724 sha512_hmac_finish_wrap,
725 sha512_hmac_reset_wrap,
726 sha512_hmac_wrap,
727 sha512_ctx_alloc,
728 sha512_ctx_free,
Paul Bakker17373852011-01-06 14:20:01 +0000729};
730
731#endif
732
733#endif