PolarSSL v1.3.8
md_wrap.c
Go to the documentation of this file.
1 
30 #if !defined(POLARSSL_CONFIG_FILE)
31 #include "polarssl/config.h"
32 #else
33 #include POLARSSL_CONFIG_FILE
34 #endif
35 
36 #if defined(POLARSSL_MD_C)
37 
38 #include "polarssl/md_wrap.h"
39 
40 #if defined(POLARSSL_MD2_C)
41 #include "polarssl/md2.h"
42 #endif
43 
44 #if defined(POLARSSL_MD4_C)
45 #include "polarssl/md4.h"
46 #endif
47 
48 #if defined(POLARSSL_MD5_C)
49 #include "polarssl/md5.h"
50 #endif
51 
52 #if defined(POLARSSL_RIPEMD160_C)
53 #include "polarssl/ripemd160.h"
54 #endif
55 
56 #if defined(POLARSSL_SHA1_C)
57 #include "polarssl/sha1.h"
58 #endif
59 
60 #if defined(POLARSSL_SHA256_C)
61 #include "polarssl/sha256.h"
62 #endif
63 
64 #if defined(POLARSSL_SHA512_C)
65 #include "polarssl/sha512.h"
66 #endif
67 
68 #if defined(POLARSSL_PLATFORM_C)
69 #include "polarssl/platform.h"
70 #else
71 #define polarssl_malloc malloc
72 #define polarssl_free free
73 #endif
74 
75 #include <stdlib.h>
76 
77 /* Implementation that should never be optimized out by the compiler */
78 static void polarssl_zeroize( void *v, size_t n ) {
79  volatile unsigned char *p = v; while( n-- ) *p++ = 0;
80 }
81 
82 #if defined(POLARSSL_MD2_C)
83 
84 static void md2_starts_wrap( void *ctx )
85 {
86  md2_starts( (md2_context *) ctx );
87 }
88 
89 static void md2_update_wrap( void *ctx, const unsigned char *input,
90  size_t ilen )
91 {
92  md2_update( (md2_context *) ctx, input, ilen );
93 }
94 
95 static void md2_finish_wrap( void *ctx, unsigned char *output )
96 {
97  md2_finish( (md2_context *) ctx, output );
98 }
99 
100 static int md2_file_wrap( const char *path, unsigned char *output )
101 {
102 #if defined(POLARSSL_FS_IO)
103  return md2_file( path, output );
104 #else
105  ((void) path);
106  ((void) output);
108 #endif
109 }
110 
111 static void md2_hmac_starts_wrap( void *ctx, const unsigned char *key,
112  size_t keylen )
113 {
114  md2_hmac_starts( (md2_context *) ctx, key, keylen );
115 }
116 
117 static void md2_hmac_update_wrap( void *ctx, const unsigned char *input,
118  size_t ilen )
119 {
120  md2_hmac_update( (md2_context *) ctx, input, ilen );
121 }
122 
123 static void md2_hmac_finish_wrap( void *ctx, unsigned char *output )
124 {
125  md2_hmac_finish( (md2_context *) ctx, output );
126 }
127 
128 static void md2_hmac_reset_wrap( void *ctx )
129 {
130  md2_hmac_reset( (md2_context *) ctx );
131 }
132 
133 static void * md2_ctx_alloc( void )
134 {
135  return polarssl_malloc( sizeof( md2_context ) );
136 }
137 
138 static void md2_ctx_free( void *ctx )
139 {
140  polarssl_zeroize( ctx, sizeof( md2_context ) );
141  polarssl_free( ctx );
142 }
143 
144 static void md2_process_wrap( void *ctx, const unsigned char *data )
145 {
146  ((void) data);
147 
148  md2_process( (md2_context *) ctx );
149 }
150 
151 const md_info_t md2_info = {
153  "MD2",
154  16,
155  md2_starts_wrap,
156  md2_update_wrap,
157  md2_finish_wrap,
158  md2,
159  md2_file_wrap,
160  md2_hmac_starts_wrap,
161  md2_hmac_update_wrap,
162  md2_hmac_finish_wrap,
163  md2_hmac_reset_wrap,
164  md2_hmac,
165  md2_ctx_alloc,
166  md2_ctx_free,
167  md2_process_wrap,
168 };
169 
170 #endif /* POLARSSL_MD2_C */
171 
172 #if defined(POLARSSL_MD4_C)
173 
174 static void md4_starts_wrap( void *ctx )
175 {
176  md4_starts( (md4_context *) ctx );
177 }
178 
179 static void md4_update_wrap( void *ctx, const unsigned char *input,
180  size_t ilen )
181 {
182  md4_update( (md4_context *) ctx, input, ilen );
183 }
184 
185 static void md4_finish_wrap( void *ctx, unsigned char *output )
186 {
187  md4_finish( (md4_context *) ctx, output );
188 }
189 
190 static int md4_file_wrap( const char *path, unsigned char *output )
191 {
192 #if defined(POLARSSL_FS_IO)
193  return md4_file( path, output );
194 #else
195  ((void) path);
196  ((void) output);
198 #endif
199 }
200 
201 static void md4_hmac_starts_wrap( void *ctx, const unsigned char *key,
202  size_t keylen )
203 {
204  md4_hmac_starts( (md4_context *) ctx, key, keylen );
205 }
206 
207 static void md4_hmac_update_wrap( void *ctx, const unsigned char *input,
208  size_t ilen )
209 {
210  md4_hmac_update( (md4_context *) ctx, input, ilen );
211 }
212 
213 static void md4_hmac_finish_wrap( void *ctx, unsigned char *output )
214 {
215  md4_hmac_finish( (md4_context *) ctx, output );
216 }
217 
218 static void md4_hmac_reset_wrap( void *ctx )
219 {
220  md4_hmac_reset( (md4_context *) ctx );
221 }
222 
223 static void *md4_ctx_alloc( void )
224 {
225  return polarssl_malloc( sizeof( md4_context ) );
226 }
227 
228 static void md4_ctx_free( void *ctx )
229 {
230  polarssl_zeroize( ctx, sizeof( md4_context ) );
231  polarssl_free( ctx );
232 }
233 
234 static void md4_process_wrap( void *ctx, const unsigned char *data )
235 {
236  md4_process( (md4_context *) ctx, data );
237 }
238 
239 const md_info_t md4_info = {
241  "MD4",
242  16,
243  md4_starts_wrap,
244  md4_update_wrap,
245  md4_finish_wrap,
246  md4,
247  md4_file_wrap,
248  md4_hmac_starts_wrap,
249  md4_hmac_update_wrap,
250  md4_hmac_finish_wrap,
251  md4_hmac_reset_wrap,
252  md4_hmac,
253  md4_ctx_alloc,
254  md4_ctx_free,
255  md4_process_wrap,
256 };
257 
258 #endif /* POLARSSL_MD4_C */
259 
260 #if defined(POLARSSL_MD5_C)
261 
262 static void md5_starts_wrap( void *ctx )
263 {
264  md5_starts( (md5_context *) ctx );
265 }
266 
267 static void md5_update_wrap( void *ctx, const unsigned char *input,
268  size_t ilen )
269 {
270  md5_update( (md5_context *) ctx, input, ilen );
271 }
272 
273 static void md5_finish_wrap( void *ctx, unsigned char *output )
274 {
275  md5_finish( (md5_context *) ctx, output );
276 }
277 
278 static int md5_file_wrap( const char *path, unsigned char *output )
279 {
280 #if defined(POLARSSL_FS_IO)
281  return md5_file( path, output );
282 #else
283  ((void) path);
284  ((void) output);
286 #endif
287 }
288 
289 static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key,
290  size_t keylen )
291 {
292  md5_hmac_starts( (md5_context *) ctx, key, keylen );
293 }
294 
295 static void md5_hmac_update_wrap( void *ctx, const unsigned char *input,
296  size_t ilen )
297 {
298  md5_hmac_update( (md5_context *) ctx, input, ilen );
299 }
300 
301 static void md5_hmac_finish_wrap( void *ctx, unsigned char *output )
302 {
303  md5_hmac_finish( (md5_context *) ctx, output );
304 }
305 
306 static void md5_hmac_reset_wrap( void *ctx )
307 {
308  md5_hmac_reset( (md5_context *) ctx );
309 }
310 
311 static void * md5_ctx_alloc( void )
312 {
313  return polarssl_malloc( sizeof( md5_context ) );
314 }
315 
316 static void md5_ctx_free( void *ctx )
317 {
318  polarssl_zeroize( ctx, sizeof( md5_context ) );
319  polarssl_free( ctx );
320 }
321 
322 static void md5_process_wrap( void *ctx, const unsigned char *data )
323 {
324  md5_process( (md5_context *) ctx, data );
325 }
326 
327 const md_info_t md5_info = {
329  "MD5",
330  16,
331  md5_starts_wrap,
332  md5_update_wrap,
333  md5_finish_wrap,
334  md5,
335  md5_file_wrap,
336  md5_hmac_starts_wrap,
337  md5_hmac_update_wrap,
338  md5_hmac_finish_wrap,
339  md5_hmac_reset_wrap,
340  md5_hmac,
341  md5_ctx_alloc,
342  md5_ctx_free,
343  md5_process_wrap,
344 };
345 
346 #endif /* POLARSSL_MD5_C */
347 
348 #if defined(POLARSSL_RIPEMD160_C)
349 
350 static void ripemd160_starts_wrap( void *ctx )
351 {
353 }
354 
355 static void ripemd160_update_wrap( void *ctx, const unsigned char *input,
356  size_t ilen )
357 {
358  ripemd160_update( (ripemd160_context *) ctx, input, ilen );
359 }
360 
361 static void ripemd160_finish_wrap( void *ctx, unsigned char *output )
362 {
363  ripemd160_finish( (ripemd160_context *) ctx, output );
364 }
365 
366 static int ripemd160_file_wrap( const char *path, unsigned char *output )
367 {
368 #if defined(POLARSSL_FS_IO)
369  return ripemd160_file( path, output );
370 #else
371  ((void) path);
372  ((void) output);
374 #endif
375 }
376 
377 static void ripemd160_hmac_starts_wrap( void *ctx, const unsigned char *key,
378  size_t keylen )
379 {
380  ripemd160_hmac_starts( (ripemd160_context *) ctx, key, keylen );
381 }
382 
383 static void ripemd160_hmac_update_wrap( void *ctx, const unsigned char *input,
384  size_t ilen )
385 {
386  ripemd160_hmac_update( (ripemd160_context *) ctx, input, ilen );
387 }
388 
389 static void ripemd160_hmac_finish_wrap( void *ctx, unsigned char *output )
390 {
391  ripemd160_hmac_finish( (ripemd160_context *) ctx, output );
392 }
393 
394 static void ripemd160_hmac_reset_wrap( void *ctx )
395 {
397 }
398 
399 static void * ripemd160_ctx_alloc( void )
400 {
401  ripemd160_context *ctx;
402  ctx = (ripemd160_context *) polarssl_malloc( sizeof( ripemd160_context ) );
403 
404  if( ctx == NULL )
405  return( NULL );
406 
407  ripemd160_init( ctx );
408 
409  return( ctx );
410 }
411 
412 static void ripemd160_ctx_free( void *ctx )
413 {
415  polarssl_free( ctx );
416 }
417 
418 static void ripemd160_process_wrap( void *ctx, const unsigned char *data )
419 {
420  ripemd160_process( (ripemd160_context *) ctx, data );
421 }
422 
423 const md_info_t ripemd160_info = {
425  "RIPEMD160",
426  20,
427  ripemd160_starts_wrap,
428  ripemd160_update_wrap,
429  ripemd160_finish_wrap,
430  ripemd160,
431  ripemd160_file_wrap,
432  ripemd160_hmac_starts_wrap,
433  ripemd160_hmac_update_wrap,
434  ripemd160_hmac_finish_wrap,
435  ripemd160_hmac_reset_wrap,
437  ripemd160_ctx_alloc,
438  ripemd160_ctx_free,
439  ripemd160_process_wrap,
440 };
441 
442 #endif /* POLARSSL_RIPEMD160_C */
443 
444 #if defined(POLARSSL_SHA1_C)
445 
446 static void sha1_starts_wrap( void *ctx )
447 {
448  sha1_starts( (sha1_context *) ctx );
449 }
450 
451 static void sha1_update_wrap( void *ctx, const unsigned char *input,
452  size_t ilen )
453 {
454  sha1_update( (sha1_context *) ctx, input, ilen );
455 }
456 
457 static void sha1_finish_wrap( void *ctx, unsigned char *output )
458 {
459  sha1_finish( (sha1_context *) ctx, output );
460 }
461 
462 static int sha1_file_wrap( const char *path, unsigned char *output )
463 {
464 #if defined(POLARSSL_FS_IO)
465  return sha1_file( path, output );
466 #else
467  ((void) path);
468  ((void) output);
470 #endif
471 }
472 
473 static void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key,
474  size_t keylen )
475 {
476  sha1_hmac_starts( (sha1_context *) ctx, key, keylen );
477 }
478 
479 static void sha1_hmac_update_wrap( void *ctx, const unsigned char *input,
480  size_t ilen )
481 {
482  sha1_hmac_update( (sha1_context *) ctx, input, ilen );
483 }
484 
485 static void sha1_hmac_finish_wrap( void *ctx, unsigned char *output )
486 {
487  sha1_hmac_finish( (sha1_context *) ctx, output );
488 }
489 
490 static void sha1_hmac_reset_wrap( void *ctx )
491 {
492  sha1_hmac_reset( (sha1_context *) ctx );
493 }
494 
495 static void * sha1_ctx_alloc( void )
496 {
497  sha1_context *ctx;
498  ctx = (sha1_context *) polarssl_malloc( sizeof( sha1_context ) );
499 
500  if( ctx == NULL )
501  return( NULL );
502 
503  sha1_init( ctx );
504 
505  return( ctx );
506 }
507 
508 static void sha1_ctx_free( void *ctx )
509 {
510  sha1_free( (sha1_context *) ctx );
511  polarssl_free( ctx );
512 }
513 
514 static void sha1_process_wrap( void *ctx, const unsigned char *data )
515 {
516  sha1_process( (sha1_context *) ctx, data );
517 }
518 
519 const md_info_t sha1_info = {
521  "SHA1",
522  20,
523  sha1_starts_wrap,
524  sha1_update_wrap,
525  sha1_finish_wrap,
526  sha1,
527  sha1_file_wrap,
528  sha1_hmac_starts_wrap,
529  sha1_hmac_update_wrap,
530  sha1_hmac_finish_wrap,
531  sha1_hmac_reset_wrap,
532  sha1_hmac,
533  sha1_ctx_alloc,
534  sha1_ctx_free,
535  sha1_process_wrap,
536 };
537 
538 #endif /* POLARSSL_SHA1_C */
539 
540 /*
541  * Wrappers for generic message digests
542  */
543 #if defined(POLARSSL_SHA256_C)
544 
545 static void sha224_starts_wrap( void *ctx )
546 {
547  sha256_starts( (sha256_context *) ctx, 1 );
548 }
549 
550 static void sha224_update_wrap( void *ctx, const unsigned char *input,
551  size_t ilen )
552 {
553  sha256_update( (sha256_context *) ctx, input, ilen );
554 }
555 
556 static void sha224_finish_wrap( void *ctx, unsigned char *output )
557 {
558  sha256_finish( (sha256_context *) ctx, output );
559 }
560 
561 static void sha224_wrap( const unsigned char *input, size_t ilen,
562  unsigned char *output )
563 {
564  sha256( input, ilen, output, 1 );
565 }
566 
567 static int sha224_file_wrap( const char *path, unsigned char *output )
568 {
569 #if defined(POLARSSL_FS_IO)
570  return sha256_file( path, output, 1 );
571 #else
572  ((void) path);
573  ((void) output);
575 #endif
576 }
577 
578 static void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key,
579  size_t keylen )
580 {
581  sha256_hmac_starts( (sha256_context *) ctx, key, keylen, 1 );
582 }
583 
584 static void sha224_hmac_update_wrap( void *ctx, const unsigned char *input,
585  size_t ilen )
586 {
587  sha256_hmac_update( (sha256_context *) ctx, input, ilen );
588 }
589 
590 static void sha224_hmac_finish_wrap( void *ctx, unsigned char *output )
591 {
592  sha256_hmac_finish( (sha256_context *) ctx, output );
593 }
594 
595 static void sha224_hmac_reset_wrap( void *ctx )
596 {
598 }
599 
600 static void sha224_hmac_wrap( const unsigned char *key, size_t keylen,
601  const unsigned char *input, size_t ilen,
602  unsigned char *output )
603 {
604  sha256_hmac( key, keylen, input, ilen, output, 1 );
605 }
606 
607 static void * sha224_ctx_alloc( void )
608 {
609  return polarssl_malloc( sizeof( sha256_context ) );
610 }
611 
612 static void sha224_ctx_free( void *ctx )
613 {
614  polarssl_zeroize( ctx, sizeof( sha256_context ) );
615  polarssl_free( ctx );
616 }
617 
618 static void sha224_process_wrap( void *ctx, const unsigned char *data )
619 {
620  sha256_process( (sha256_context *) ctx, data );
621 }
622 
623 const md_info_t sha224_info = {
625  "SHA224",
626  28,
627  sha224_starts_wrap,
628  sha224_update_wrap,
629  sha224_finish_wrap,
630  sha224_wrap,
631  sha224_file_wrap,
632  sha224_hmac_starts_wrap,
633  sha224_hmac_update_wrap,
634  sha224_hmac_finish_wrap,
635  sha224_hmac_reset_wrap,
636  sha224_hmac_wrap,
637  sha224_ctx_alloc,
638  sha224_ctx_free,
639  sha224_process_wrap,
640 };
641 
642 static void sha256_starts_wrap( void *ctx )
643 {
644  sha256_starts( (sha256_context *) ctx, 0 );
645 }
646 
647 static void sha256_update_wrap( void *ctx, const unsigned char *input,
648  size_t ilen )
649 {
650  sha256_update( (sha256_context *) ctx, input, ilen );
651 }
652 
653 static void sha256_finish_wrap( void *ctx, unsigned char *output )
654 {
655  sha256_finish( (sha256_context *) ctx, output );
656 }
657 
658 static void sha256_wrap( const unsigned char *input, size_t ilen,
659  unsigned char *output )
660 {
661  sha256( input, ilen, output, 0 );
662 }
663 
664 static int sha256_file_wrap( const char *path, unsigned char *output )
665 {
666 #if defined(POLARSSL_FS_IO)
667  return sha256_file( path, output, 0 );
668 #else
669  ((void) path);
670  ((void) output);
672 #endif
673 }
674 
675 static void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key,
676  size_t keylen )
677 {
678  sha256_hmac_starts( (sha256_context *) ctx, key, keylen, 0 );
679 }
680 
681 static void sha256_hmac_update_wrap( void *ctx, const unsigned char *input,
682  size_t ilen )
683 {
684  sha256_hmac_update( (sha256_context *) ctx, input, ilen );
685 }
686 
687 static void sha256_hmac_finish_wrap( void *ctx, unsigned char *output )
688 {
689  sha256_hmac_finish( (sha256_context *) ctx, output );
690 }
691 
692 static void sha256_hmac_reset_wrap( void *ctx )
693 {
695 }
696 
697 static void sha256_hmac_wrap( const unsigned char *key, size_t keylen,
698  const unsigned char *input, size_t ilen,
699  unsigned char *output )
700 {
701  sha256_hmac( key, keylen, input, ilen, output, 0 );
702 }
703 
704 static void * sha256_ctx_alloc( void )
705 {
706  sha256_context *ctx;
707  ctx = (sha256_context *) polarssl_malloc( sizeof( sha256_context ) );
708 
709  if( ctx == NULL )
710  return( NULL );
711 
712  sha256_init( ctx );
713 
714  return( ctx );
715 }
716 
717 static void sha256_ctx_free( void *ctx )
718 {
719  sha256_free( (sha256_context *) ctx );
720  polarssl_free( ctx );
721 }
722 
723 static void sha256_process_wrap( void *ctx, const unsigned char *data )
724 {
725  sha256_process( (sha256_context *) ctx, data );
726 }
727 
728 const md_info_t sha256_info = {
730  "SHA256",
731  32,
732  sha256_starts_wrap,
733  sha256_update_wrap,
734  sha256_finish_wrap,
735  sha256_wrap,
736  sha256_file_wrap,
737  sha256_hmac_starts_wrap,
738  sha256_hmac_update_wrap,
739  sha256_hmac_finish_wrap,
740  sha256_hmac_reset_wrap,
741  sha256_hmac_wrap,
742  sha256_ctx_alloc,
743  sha256_ctx_free,
744  sha256_process_wrap,
745 };
746 
747 #endif /* POLARSSL_SHA256_C */
748 
749 #if defined(POLARSSL_SHA512_C)
750 
751 static void sha384_starts_wrap( void *ctx )
752 {
753  sha512_starts( (sha512_context *) ctx, 1 );
754 }
755 
756 static void sha384_update_wrap( void *ctx, const unsigned char *input,
757  size_t ilen )
758 {
759  sha512_update( (sha512_context *) ctx, input, ilen );
760 }
761 
762 static void sha384_finish_wrap( void *ctx, unsigned char *output )
763 {
764  sha512_finish( (sha512_context *) ctx, output );
765 }
766 
767 static void sha384_wrap( const unsigned char *input, size_t ilen,
768  unsigned char *output )
769 {
770  sha512( input, ilen, output, 1 );
771 }
772 
773 static int sha384_file_wrap( const char *path, unsigned char *output )
774 {
775 #if defined(POLARSSL_FS_IO)
776  return sha512_file( path, output, 1 );
777 #else
778  ((void) path);
779  ((void) output);
781 #endif
782 }
783 
784 static void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key,
785  size_t keylen )
786 {
787  sha512_hmac_starts( (sha512_context *) ctx, key, keylen, 1 );
788 }
789 
790 static void sha384_hmac_update_wrap( void *ctx, const unsigned char *input,
791  size_t ilen )
792 {
793  sha512_hmac_update( (sha512_context *) ctx, input, ilen );
794 }
795 
796 static void sha384_hmac_finish_wrap( void *ctx, unsigned char *output )
797 {
798  sha512_hmac_finish( (sha512_context *) ctx, output );
799 }
800 
801 static void sha384_hmac_reset_wrap( void *ctx )
802 {
804 }
805 
806 static void sha384_hmac_wrap( const unsigned char *key, size_t keylen,
807  const unsigned char *input, size_t ilen,
808  unsigned char *output )
809 {
810  sha512_hmac( key, keylen, input, ilen, output, 1 );
811 }
812 
813 static void * sha384_ctx_alloc( void )
814 {
815  return polarssl_malloc( sizeof( sha512_context ) );
816 }
817 
818 static void sha384_ctx_free( void *ctx )
819 {
820  polarssl_zeroize( ctx, sizeof( sha512_context ) );
821  polarssl_free( ctx );
822 }
823 
824 static void sha384_process_wrap( void *ctx, const unsigned char *data )
825 {
826  sha512_process( (sha512_context *) ctx, data );
827 }
828 
829 const md_info_t sha384_info = {
831  "SHA384",
832  48,
833  sha384_starts_wrap,
834  sha384_update_wrap,
835  sha384_finish_wrap,
836  sha384_wrap,
837  sha384_file_wrap,
838  sha384_hmac_starts_wrap,
839  sha384_hmac_update_wrap,
840  sha384_hmac_finish_wrap,
841  sha384_hmac_reset_wrap,
842  sha384_hmac_wrap,
843  sha384_ctx_alloc,
844  sha384_ctx_free,
845  sha384_process_wrap,
846 };
847 
848 static void sha512_starts_wrap( void *ctx )
849 {
850  sha512_starts( (sha512_context *) ctx, 0 );
851 }
852 
853 static void sha512_update_wrap( void *ctx, const unsigned char *input,
854  size_t ilen )
855 {
856  sha512_update( (sha512_context *) ctx, input, ilen );
857 }
858 
859 static void sha512_finish_wrap( void *ctx, unsigned char *output )
860 {
861  sha512_finish( (sha512_context *) ctx, output );
862 }
863 
864 static void sha512_wrap( const unsigned char *input, size_t ilen,
865  unsigned char *output )
866 {
867  sha512( input, ilen, output, 0 );
868 }
869 
870 static int sha512_file_wrap( const char *path, unsigned char *output )
871 {
872 #if defined(POLARSSL_FS_IO)
873  return sha512_file( path, output, 0 );
874 #else
875  ((void) path);
876  ((void) output);
878 #endif
879 }
880 
881 static void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key,
882  size_t keylen )
883 {
884  sha512_hmac_starts( (sha512_context *) ctx, key, keylen, 0 );
885 }
886 
887 static void sha512_hmac_update_wrap( void *ctx, const unsigned char *input,
888  size_t ilen )
889 {
890  sha512_hmac_update( (sha512_context *) ctx, input, ilen );
891 }
892 
893 static void sha512_hmac_finish_wrap( void *ctx, unsigned char *output )
894 {
895  sha512_hmac_finish( (sha512_context *) ctx, output );
896 }
897 
898 static void sha512_hmac_reset_wrap( void *ctx )
899 {
901 }
902 
903 static void sha512_hmac_wrap( const unsigned char *key, size_t keylen,
904  const unsigned char *input, size_t ilen,
905  unsigned char *output )
906 {
907  sha512_hmac( key, keylen, input, ilen, output, 0 );
908 }
909 
910 static void * sha512_ctx_alloc( void )
911 {
912  sha512_context *ctx;
913  ctx = (sha512_context *) polarssl_malloc( sizeof( sha512_context ) );
914 
915  if( ctx == NULL )
916  return( NULL );
917 
918  sha512_init( ctx );
919 
920  return( ctx );
921 }
922 
923 static void sha512_ctx_free( void *ctx )
924 {
925  sha512_free( (sha512_context *) ctx );
926  polarssl_free( ctx );
927 }
928 
929 static void sha512_process_wrap( void *ctx, const unsigned char *data )
930 {
931  sha512_process( (sha512_context *) ctx, data );
932 }
933 
934 const md_info_t sha512_info = {
936  "SHA512",
937  64,
938  sha512_starts_wrap,
939  sha512_update_wrap,
940  sha512_finish_wrap,
941  sha512_wrap,
942  sha512_file_wrap,
943  sha512_hmac_starts_wrap,
944  sha512_hmac_update_wrap,
945  sha512_hmac_finish_wrap,
946  sha512_hmac_reset_wrap,
947  sha512_hmac_wrap,
948  sha512_ctx_alloc,
949  sha512_ctx_free,
950  sha512_process_wrap,
951 };
952 
953 #endif /* POLARSSL_SHA512_C */
954 
955 #endif /* POLARSSL_MD_C */