Port of TI's CC3100 Websock camera demo. Using FreeRTOS, mbedTLS, also parts of Arducam for cams ov5642 and 0v2640. Can also use MT9D111. Work in progress. Be warned some parts maybe a bit flacky. This is for Seeed Arch max only, for an M3, see the demo for CM3 using the 0v5642 aducam mini.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers md_wrap.c Source File

md_wrap.c

Go to the documentation of this file.
00001 /**
00002  * \file md_wrap.c
00003 
00004  * \brief Generic message digest wrapper for mbed TLS
00005  *
00006  * \author Adriaan de Jong <dejong@fox-it.com>
00007  *
00008  *  Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
00009  *
00010  *  This file is part of mbed TLS (https://tls.mbed.org)
00011  *
00012  *  This program is free software; you can redistribute it and/or modify
00013  *  it under the terms of the GNU General Public License as published by
00014  *  the Free Software Foundation; either version 2 of the License, or
00015  *  (at your option) any later version.
00016  *
00017  *  This program is distributed in the hope that it will be useful,
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *  GNU General Public License for more details.
00021  *
00022  *  You should have received a copy of the GNU General Public License along
00023  *  with this program; if not, write to the Free Software Foundation, Inc.,
00024  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00025  */
00026 
00027 #if !defined(POLARSSL_CONFIG_FILE)
00028 #include "polarssl/config.h"
00029 #else
00030 #include POLARSSL_CONFIG_FILE
00031 #endif
00032 
00033 #if defined(POLARSSL_MD_C)
00034 
00035 #include "polarssl/md_wrap.h"
00036 
00037 #if defined(POLARSSL_MD2_C)
00038 #include "polarssl/md2.h"
00039 #endif
00040 
00041 #if defined(POLARSSL_MD4_C)
00042 #include "polarssl/md4.h"
00043 #endif
00044 
00045 #if defined(POLARSSL_MD5_C)
00046 #include "polarssl/md5.h"
00047 #endif
00048 
00049 #if defined(POLARSSL_RIPEMD160_C)
00050 #include "polarssl/ripemd160.h"
00051 #endif
00052 
00053 #if defined(POLARSSL_SHA1_C)
00054 #include "polarssl/sha1.h"
00055 #endif
00056 
00057 #if defined(POLARSSL_SHA256_C)
00058 #include "polarssl/sha256.h"
00059 #endif
00060 
00061 #if defined(POLARSSL_SHA512_C)
00062 #include "polarssl/sha512.h"
00063 #endif
00064 
00065 #if defined(POLARSSL_PLATFORM_C)
00066 #include "polarssl/platform.h"
00067 #else
00068 #include <stdlib.h>
00069 #define polarssl_malloc     malloc
00070 #define polarssl_free       free
00071 #endif
00072 
00073 /* Implementation that should never be optimized out by the compiler */
00074 static void polarssl_zeroize( void *v, size_t n ) {
00075     volatile unsigned char *p = v; while( n-- ) *p++ = 0;
00076 }
00077 
00078 #if defined(POLARSSL_MD2_C)
00079 
00080 static void md2_starts_wrap( void *ctx )
00081 {
00082     md2_starts( (md2_context *) ctx );
00083 }
00084 
00085 static void md2_update_wrap( void *ctx, const unsigned char *input,
00086                              size_t ilen )
00087 {
00088     md2_update( (md2_context *) ctx, input, ilen );
00089 }
00090 
00091 static void md2_finish_wrap( void *ctx, unsigned char *output )
00092 {
00093     md2_finish( (md2_context *) ctx, output );
00094 }
00095 
00096 static int md2_file_wrap( const char *path, unsigned char *output )
00097 {
00098 #if defined(POLARSSL_FS_IO)
00099     return md2_file( path, output );
00100 #else
00101     ((void) path);
00102     ((void) output);
00103     return( POLARSSL_ERR_MD_FEATURE_UNAVAILABLE );
00104 #endif
00105 }
00106 
00107 static void md2_hmac_starts_wrap( void *ctx, const unsigned char *key,
00108                                   size_t keylen )
00109 {
00110     md2_hmac_starts( (md2_context *) ctx, key, keylen );
00111 }
00112 
00113 static void md2_hmac_update_wrap( void *ctx, const unsigned char *input,
00114                                   size_t ilen )
00115 {
00116     md2_hmac_update( (md2_context *) ctx, input, ilen );
00117 }
00118 
00119 static void md2_hmac_finish_wrap( void *ctx, unsigned char *output )
00120 {
00121     md2_hmac_finish( (md2_context *) ctx, output );
00122 }
00123 
00124 static void md2_hmac_reset_wrap( void *ctx )
00125 {
00126     md2_hmac_reset( (md2_context *) ctx );
00127 }
00128 
00129 static void * md2_ctx_alloc( void )
00130 {
00131     return polarssl_malloc( sizeof( md2_context ) );
00132 }
00133 
00134 static void md2_ctx_free( void *ctx )
00135 {
00136     polarssl_zeroize( ctx, sizeof( md2_context ) );
00137     polarssl_free( ctx );
00138 }
00139 
00140 static void md2_process_wrap( void *ctx, const unsigned char *data )
00141 {
00142     ((void) data);
00143 
00144     md2_process( (md2_context *) ctx );
00145 }
00146 
00147 const md_info_t md2_info = {
00148     POLARSSL_MD_MD2,
00149     "MD2",
00150     16,
00151     md2_starts_wrap,
00152     md2_update_wrap,
00153     md2_finish_wrap,
00154     md2,
00155     md2_file_wrap,
00156     md2_hmac_starts_wrap,
00157     md2_hmac_update_wrap,
00158     md2_hmac_finish_wrap,
00159     md2_hmac_reset_wrap,
00160     md2_hmac,
00161     md2_ctx_alloc,
00162     md2_ctx_free,
00163     md2_process_wrap,
00164 };
00165 
00166 #endif /* POLARSSL_MD2_C */
00167 
00168 #if defined(POLARSSL_MD4_C)
00169 
00170 static void md4_starts_wrap( void *ctx )
00171 {
00172     md4_starts( (md4_context *) ctx );
00173 }
00174 
00175 static void md4_update_wrap( void *ctx, const unsigned char *input,
00176                              size_t ilen )
00177 {
00178     md4_update( (md4_context *) ctx, input, ilen );
00179 }
00180 
00181 static void md4_finish_wrap( void *ctx, unsigned char *output )
00182 {
00183     md4_finish( (md4_context *) ctx, output );
00184 }
00185 
00186 static int md4_file_wrap( const char *path, unsigned char *output )
00187 {
00188 #if defined(POLARSSL_FS_IO)
00189     return md4_file( path, output );
00190 #else
00191     ((void) path);
00192     ((void) output);
00193     return( POLARSSL_ERR_MD_FEATURE_UNAVAILABLE );
00194 #endif
00195 }
00196 
00197 static void md4_hmac_starts_wrap( void *ctx, const unsigned char *key,
00198                                   size_t keylen )
00199 {
00200     md4_hmac_starts( (md4_context *) ctx, key, keylen );
00201 }
00202 
00203 static void md4_hmac_update_wrap( void *ctx, const unsigned char *input,
00204                                   size_t ilen )
00205 {
00206     md4_hmac_update( (md4_context *) ctx, input, ilen );
00207 }
00208 
00209 static void md4_hmac_finish_wrap( void *ctx, unsigned char *output )
00210 {
00211     md4_hmac_finish( (md4_context *) ctx, output );
00212 }
00213 
00214 static void md4_hmac_reset_wrap( void *ctx )
00215 {
00216     md4_hmac_reset( (md4_context *) ctx );
00217 }
00218 
00219 static void *md4_ctx_alloc( void )
00220 {
00221     return polarssl_malloc( sizeof( md4_context ) );
00222 }
00223 
00224 static void md4_ctx_free( void *ctx )
00225 {
00226     polarssl_zeroize( ctx, sizeof( md4_context ) );
00227     polarssl_free( ctx );
00228 }
00229 
00230 static void md4_process_wrap( void *ctx, const unsigned char *data )
00231 {
00232     md4_process( (md4_context *) ctx, data );
00233 }
00234 
00235 const md_info_t md4_info = {
00236     POLARSSL_MD_MD4,
00237     "MD4",
00238     16,
00239     md4_starts_wrap,
00240     md4_update_wrap,
00241     md4_finish_wrap,
00242     md4,
00243     md4_file_wrap,
00244     md4_hmac_starts_wrap,
00245     md4_hmac_update_wrap,
00246     md4_hmac_finish_wrap,
00247     md4_hmac_reset_wrap,
00248     md4_hmac,
00249     md4_ctx_alloc,
00250     md4_ctx_free,
00251     md4_process_wrap,
00252 };
00253 
00254 #endif /* POLARSSL_MD4_C */
00255 
00256 #if defined(POLARSSL_MD5_C)
00257 
00258 static void md5_starts_wrap( void *ctx )
00259 {
00260     md5_starts( (md5_context *) ctx );
00261 }
00262 
00263 static void md5_update_wrap( void *ctx, const unsigned char *input,
00264                              size_t ilen )
00265 {
00266     md5_update( (md5_context *) ctx, input, ilen );
00267 }
00268 
00269 static void md5_finish_wrap( void *ctx, unsigned char *output )
00270 {
00271     md5_finish( (md5_context *) ctx, output );
00272 }
00273 
00274 static int md5_file_wrap( const char *path, unsigned char *output )
00275 {
00276 #if defined(POLARSSL_FS_IO)
00277     return md5_file( path, output );
00278 #else
00279     ((void) path);
00280     ((void) output);
00281     return( POLARSSL_ERR_MD_FEATURE_UNAVAILABLE );
00282 #endif
00283 }
00284 
00285 static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key,
00286                                   size_t keylen )
00287 {
00288     md5_hmac_starts( (md5_context *) ctx, key, keylen );
00289 }
00290 
00291 static void md5_hmac_update_wrap( void *ctx, const unsigned char *input,
00292                                   size_t ilen )
00293 {
00294     md5_hmac_update( (md5_context *) ctx, input, ilen );
00295 }
00296 
00297 static void md5_hmac_finish_wrap( void *ctx, unsigned char *output )
00298 {
00299     md5_hmac_finish( (md5_context *) ctx, output );
00300 }
00301 
00302 static void md5_hmac_reset_wrap( void *ctx )
00303 {
00304     md5_hmac_reset( (md5_context *) ctx );
00305 }
00306 
00307 static void * md5_ctx_alloc( void )
00308 {
00309     return polarssl_malloc( sizeof( md5_context ) );
00310 }
00311 
00312 static void md5_ctx_free( void *ctx )
00313 {
00314     polarssl_zeroize( ctx, sizeof( md5_context ) );
00315     polarssl_free( ctx );
00316 }
00317 
00318 static void md5_process_wrap( void *ctx, const unsigned char *data )
00319 {
00320     md5_process( (md5_context *) ctx, data );
00321 }
00322 
00323 const md_info_t md5_info = {
00324     POLARSSL_MD_MD5,
00325     "MD5",
00326     16,
00327     md5_starts_wrap,
00328     md5_update_wrap,
00329     md5_finish_wrap,
00330     md5,
00331     md5_file_wrap,
00332     md5_hmac_starts_wrap,
00333     md5_hmac_update_wrap,
00334     md5_hmac_finish_wrap,
00335     md5_hmac_reset_wrap,
00336     md5_hmac,
00337     md5_ctx_alloc,
00338     md5_ctx_free,
00339     md5_process_wrap,
00340 };
00341 
00342 #endif /* POLARSSL_MD5_C */
00343 
00344 #if defined(POLARSSL_RIPEMD160_C)
00345 
00346 static void ripemd160_starts_wrap( void *ctx )
00347 {
00348     ripemd160_starts( (ripemd160_context *) ctx );
00349 }
00350 
00351 static void ripemd160_update_wrap( void *ctx, const unsigned char *input,
00352                                    size_t ilen )
00353 {
00354     ripemd160_update( (ripemd160_context *) ctx, input, ilen );
00355 }
00356 
00357 static void ripemd160_finish_wrap( void *ctx, unsigned char *output )
00358 {
00359     ripemd160_finish( (ripemd160_context *) ctx, output );
00360 }
00361 
00362 static int ripemd160_file_wrap( const char *path, unsigned char *output )
00363 {
00364 #if defined(POLARSSL_FS_IO)
00365     return ripemd160_file( path, output );
00366 #else
00367     ((void) path);
00368     ((void) output);
00369     return( POLARSSL_ERR_MD_FEATURE_UNAVAILABLE );
00370 #endif
00371 }
00372 
00373 static void ripemd160_hmac_starts_wrap( void *ctx, const unsigned char *key,
00374                                         size_t keylen )
00375 {
00376     ripemd160_hmac_starts( (ripemd160_context *) ctx, key, keylen );
00377 }
00378 
00379 static void ripemd160_hmac_update_wrap( void *ctx, const unsigned char *input,
00380                                         size_t ilen )
00381 {
00382     ripemd160_hmac_update( (ripemd160_context *) ctx, input, ilen );
00383 }
00384 
00385 static void ripemd160_hmac_finish_wrap( void *ctx, unsigned char *output )
00386 {
00387     ripemd160_hmac_finish( (ripemd160_context *) ctx, output );
00388 }
00389 
00390 static void ripemd160_hmac_reset_wrap( void *ctx )
00391 {
00392     ripemd160_hmac_reset( (ripemd160_context *) ctx );
00393 }
00394 
00395 static void * ripemd160_ctx_alloc( void )
00396 {
00397     ripemd160_context *ctx;
00398     ctx = polarssl_malloc( sizeof( ripemd160_context ) );
00399 
00400     if( ctx == NULL )
00401         return( NULL );
00402 
00403     ripemd160_init( ctx );
00404 
00405     return( ctx );
00406 }
00407 
00408 static void ripemd160_ctx_free( void *ctx )
00409 {
00410     ripemd160_free( (ripemd160_context *) ctx );
00411     polarssl_free( ctx );
00412 }
00413 
00414 static void ripemd160_process_wrap( void *ctx, const unsigned char *data )
00415 {
00416     ripemd160_process( (ripemd160_context *) ctx, data );
00417 }
00418 
00419 const md_info_t ripemd160_info = {
00420     POLARSSL_MD_RIPEMD160,
00421     "RIPEMD160",
00422     20,
00423     ripemd160_starts_wrap,
00424     ripemd160_update_wrap,
00425     ripemd160_finish_wrap,
00426     ripemd160,
00427     ripemd160_file_wrap,
00428     ripemd160_hmac_starts_wrap,
00429     ripemd160_hmac_update_wrap,
00430     ripemd160_hmac_finish_wrap,
00431     ripemd160_hmac_reset_wrap,
00432     ripemd160_hmac,
00433     ripemd160_ctx_alloc,
00434     ripemd160_ctx_free,
00435     ripemd160_process_wrap,
00436 };
00437 
00438 #endif /* POLARSSL_RIPEMD160_C */
00439 
00440 #if defined(POLARSSL_SHA1_C)
00441 
00442 static void sha1_starts_wrap( void *ctx )
00443 {
00444     sha1_starts( (sha1_context *) ctx );
00445 }
00446 
00447 static void sha1_update_wrap( void *ctx, const unsigned char *input,
00448                               size_t ilen )
00449 {
00450     sha1_update( (sha1_context *) ctx, input, ilen );
00451 }
00452 
00453 static void sha1_finish_wrap( void *ctx, unsigned char *output )
00454 {
00455     sha1_finish( (sha1_context *) ctx, output );
00456 }
00457 
00458 static int sha1_file_wrap( const char *path, unsigned char *output )
00459 {
00460 #if defined(POLARSSL_FS_IO)
00461     return sha1_file( path, output );
00462 #else
00463     ((void) path);
00464     ((void) output);
00465     return( POLARSSL_ERR_MD_FEATURE_UNAVAILABLE );
00466 #endif
00467 }
00468 
00469 static void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key,
00470                                    size_t keylen )
00471 {
00472     sha1_hmac_starts( (sha1_context *) ctx, key, keylen );
00473 }
00474 
00475 static void sha1_hmac_update_wrap( void *ctx, const unsigned char *input,
00476                                    size_t ilen )
00477 {
00478     sha1_hmac_update( (sha1_context *) ctx, input, ilen );
00479 }
00480 
00481 static void sha1_hmac_finish_wrap( void *ctx, unsigned char *output )
00482 {
00483     sha1_hmac_finish( (sha1_context *) ctx, output );
00484 }
00485 
00486 static void sha1_hmac_reset_wrap( void *ctx )
00487 {
00488     sha1_hmac_reset( (sha1_context *) ctx );
00489 }
00490 
00491 static void * sha1_ctx_alloc( void )
00492 {
00493     sha1_context *ctx;
00494     ctx = polarssl_malloc( sizeof( sha1_context ) );
00495 
00496     if( ctx == NULL )
00497         return( NULL );
00498 
00499     sha1_init( ctx );
00500 
00501     return( ctx );
00502 }
00503 
00504 static void sha1_ctx_free( void *ctx )
00505 {
00506     sha1_free( (sha1_context *) ctx );
00507     polarssl_free( ctx );
00508 }
00509 
00510 static void sha1_process_wrap( void *ctx, const unsigned char *data )
00511 {
00512     sha1_process( (sha1_context *) ctx, data );
00513 }
00514 
00515 const md_info_t sha1_info = {
00516     POLARSSL_MD_SHA1,
00517     "SHA1",
00518     20,
00519     sha1_starts_wrap,
00520     sha1_update_wrap,
00521     sha1_finish_wrap,
00522     sha1,
00523     sha1_file_wrap,
00524     sha1_hmac_starts_wrap,
00525     sha1_hmac_update_wrap,
00526     sha1_hmac_finish_wrap,
00527     sha1_hmac_reset_wrap,
00528     sha1_hmac,
00529     sha1_ctx_alloc,
00530     sha1_ctx_free,
00531     sha1_process_wrap,
00532 };
00533 
00534 #endif /* POLARSSL_SHA1_C */
00535 
00536 /*
00537  * Wrappers for generic message digests
00538  */
00539 #if defined(POLARSSL_SHA256_C)
00540 
00541 static void sha224_starts_wrap( void *ctx )
00542 {
00543     sha256_starts( (sha256_context *) ctx, 1 );
00544 }
00545 
00546 static void sha224_update_wrap( void *ctx, const unsigned char *input,
00547                                 size_t ilen )
00548 {
00549     sha256_update( (sha256_context *) ctx, input, ilen );
00550 }
00551 
00552 static void sha224_finish_wrap( void *ctx, unsigned char *output )
00553 {
00554     sha256_finish( (sha256_context *) ctx, output );
00555 }
00556 
00557 static void sha224_wrap( const unsigned char *input, size_t ilen,
00558                     unsigned char *output )
00559 {
00560     sha256( input, ilen, output, 1 );
00561 }
00562 
00563 static int sha224_file_wrap( const char *path, unsigned char *output )
00564 {
00565 #if defined(POLARSSL_FS_IO)
00566     return sha256_file( path, output, 1 );
00567 #else
00568     ((void) path);
00569     ((void) output);
00570     return( POLARSSL_ERR_MD_FEATURE_UNAVAILABLE );
00571 #endif
00572 }
00573 
00574 static void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key,
00575                                      size_t keylen )
00576 {
00577     sha256_hmac_starts( (sha256_context *) ctx, key, keylen, 1 );
00578 }
00579 
00580 static void sha224_hmac_update_wrap( void *ctx, const unsigned char *input,
00581                                      size_t ilen )
00582 {
00583     sha256_hmac_update( (sha256_context *) ctx, input, ilen );
00584 }
00585 
00586 static void sha224_hmac_finish_wrap( void *ctx, unsigned char *output )
00587 {
00588     sha256_hmac_finish( (sha256_context *) ctx, output );
00589 }
00590 
00591 static void sha224_hmac_reset_wrap( void *ctx )
00592 {
00593     sha256_hmac_reset( (sha256_context *) ctx );
00594 }
00595 
00596 static void sha224_hmac_wrap( const unsigned char *key, size_t keylen,
00597         const unsigned char *input, size_t ilen,
00598         unsigned char *output )
00599 {
00600     sha256_hmac( key, keylen, input, ilen, output, 1 );
00601 }
00602 
00603 static void * sha224_ctx_alloc( void )
00604 {
00605     return polarssl_malloc( sizeof( sha256_context ) );
00606 }
00607 
00608 static void sha224_ctx_free( void *ctx )
00609 {
00610     polarssl_zeroize( ctx, sizeof( sha256_context ) );
00611     polarssl_free( ctx );
00612 }
00613 
00614 static void sha224_process_wrap( void *ctx, const unsigned char *data )
00615 {
00616     sha256_process( (sha256_context *) ctx, data );
00617 }
00618 
00619 const md_info_t sha224_info = {
00620     POLARSSL_MD_SHA224,
00621     "SHA224",
00622     28,
00623     sha224_starts_wrap,
00624     sha224_update_wrap,
00625     sha224_finish_wrap,
00626     sha224_wrap,
00627     sha224_file_wrap,
00628     sha224_hmac_starts_wrap,
00629     sha224_hmac_update_wrap,
00630     sha224_hmac_finish_wrap,
00631     sha224_hmac_reset_wrap,
00632     sha224_hmac_wrap,
00633     sha224_ctx_alloc,
00634     sha224_ctx_free,
00635     sha224_process_wrap,
00636 };
00637 
00638 static void sha256_starts_wrap( void *ctx )
00639 {
00640     sha256_starts( (sha256_context *) ctx, 0 );
00641 }
00642 
00643 static void sha256_update_wrap( void *ctx, const unsigned char *input,
00644                                 size_t ilen )
00645 {
00646     sha256_update( (sha256_context *) ctx, input, ilen );
00647 }
00648 
00649 static void sha256_finish_wrap( void *ctx, unsigned char *output )
00650 {
00651     sha256_finish( (sha256_context *) ctx, output );
00652 }
00653 
00654 static void sha256_wrap( const unsigned char *input, size_t ilen,
00655                     unsigned char *output )
00656 {
00657     sha256( input, ilen, output, 0 );
00658 }
00659 
00660 static int sha256_file_wrap( const char *path, unsigned char *output )
00661 {
00662 #if defined(POLARSSL_FS_IO)
00663     return sha256_file( path, output, 0 );
00664 #else
00665     ((void) path);
00666     ((void) output);
00667     return( POLARSSL_ERR_MD_FEATURE_UNAVAILABLE );
00668 #endif
00669 }
00670 
00671 static void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key,
00672                                      size_t keylen )
00673 {
00674     sha256_hmac_starts( (sha256_context *) ctx, key, keylen, 0 );
00675 }
00676 
00677 static void sha256_hmac_update_wrap( void *ctx, const unsigned char *input,
00678                                      size_t ilen )
00679 {
00680     sha256_hmac_update( (sha256_context *) ctx, input, ilen );
00681 }
00682 
00683 static void sha256_hmac_finish_wrap( void *ctx, unsigned char *output )
00684 {
00685     sha256_hmac_finish( (sha256_context *) ctx, output );
00686 }
00687 
00688 static void sha256_hmac_reset_wrap( void *ctx )
00689 {
00690     sha256_hmac_reset( (sha256_context *) ctx );
00691 }
00692 
00693 static void sha256_hmac_wrap( const unsigned char *key, size_t keylen,
00694         const unsigned char *input, size_t ilen,
00695         unsigned char *output )
00696 {
00697     sha256_hmac( key, keylen, input, ilen, output, 0 );
00698 }
00699 
00700 static void * sha256_ctx_alloc( void )
00701 {
00702     sha256_context *ctx;
00703     ctx = polarssl_malloc( sizeof( sha256_context ) );
00704 
00705     if( ctx == NULL )
00706         return( NULL );
00707 
00708     sha256_init( ctx );
00709 
00710     return( ctx );
00711 }
00712 
00713 static void sha256_ctx_free( void *ctx )
00714 {
00715     sha256_free( (sha256_context *) ctx );
00716     polarssl_free( ctx );
00717 }
00718 
00719 static void sha256_process_wrap( void *ctx, const unsigned char *data )
00720 {
00721     sha256_process( (sha256_context *) ctx, data );
00722 }
00723 
00724 const md_info_t sha256_info = {
00725     POLARSSL_MD_SHA256,
00726     "SHA256",
00727     32,
00728     sha256_starts_wrap,
00729     sha256_update_wrap,
00730     sha256_finish_wrap,
00731     sha256_wrap,
00732     sha256_file_wrap,
00733     sha256_hmac_starts_wrap,
00734     sha256_hmac_update_wrap,
00735     sha256_hmac_finish_wrap,
00736     sha256_hmac_reset_wrap,
00737     sha256_hmac_wrap,
00738     sha256_ctx_alloc,
00739     sha256_ctx_free,
00740     sha256_process_wrap,
00741 };
00742 
00743 #endif /* POLARSSL_SHA256_C */
00744 
00745 #if defined(POLARSSL_SHA512_C)
00746 
00747 static void sha384_starts_wrap( void *ctx )
00748 {
00749     sha512_starts( (sha512_context *) ctx, 1 );
00750 }
00751 
00752 static void sha384_update_wrap( void *ctx, const unsigned char *input,
00753                                 size_t ilen )
00754 {
00755     sha512_update( (sha512_context *) ctx, input, ilen );
00756 }
00757 
00758 static void sha384_finish_wrap( void *ctx, unsigned char *output )
00759 {
00760     sha512_finish( (sha512_context *) ctx, output );
00761 }
00762 
00763 static void sha384_wrap( const unsigned char *input, size_t ilen,
00764                     unsigned char *output )
00765 {
00766     sha512( input, ilen, output, 1 );
00767 }
00768 
00769 static int sha384_file_wrap( const char *path, unsigned char *output )
00770 {
00771 #if defined(POLARSSL_FS_IO)
00772     return sha512_file( path, output, 1 );
00773 #else
00774     ((void) path);
00775     ((void) output);
00776     return( POLARSSL_ERR_MD_FEATURE_UNAVAILABLE );
00777 #endif
00778 }
00779 
00780 static void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key,
00781                                      size_t keylen )
00782 {
00783     sha512_hmac_starts( (sha512_context *) ctx, key, keylen, 1 );
00784 }
00785 
00786 static void sha384_hmac_update_wrap( void *ctx, const unsigned char *input,
00787                                      size_t ilen )
00788 {
00789     sha512_hmac_update( (sha512_context *) ctx, input, ilen );
00790 }
00791 
00792 static void sha384_hmac_finish_wrap( void *ctx, unsigned char *output )
00793 {
00794     sha512_hmac_finish( (sha512_context *) ctx, output );
00795 }
00796 
00797 static void sha384_hmac_reset_wrap( void *ctx )
00798 {
00799     sha512_hmac_reset( (sha512_context *) ctx );
00800 }
00801 
00802 static void sha384_hmac_wrap( const unsigned char *key, size_t keylen,
00803         const unsigned char *input, size_t ilen,
00804         unsigned char *output )
00805 {
00806     sha512_hmac( key, keylen, input, ilen, output, 1 );
00807 }
00808 
00809 static void * sha384_ctx_alloc( void )
00810 {
00811     return polarssl_malloc( sizeof( sha512_context ) );
00812 }
00813 
00814 static void sha384_ctx_free( void *ctx )
00815 {
00816     polarssl_zeroize( ctx, sizeof( sha512_context ) );
00817     polarssl_free( ctx );
00818 }
00819 
00820 static void sha384_process_wrap( void *ctx, const unsigned char *data )
00821 {
00822     sha512_process( (sha512_context *) ctx, data );
00823 }
00824 
00825 const md_info_t sha384_info = {
00826     POLARSSL_MD_SHA384,
00827     "SHA384",
00828     48,
00829     sha384_starts_wrap,
00830     sha384_update_wrap,
00831     sha384_finish_wrap,
00832     sha384_wrap,
00833     sha384_file_wrap,
00834     sha384_hmac_starts_wrap,
00835     sha384_hmac_update_wrap,
00836     sha384_hmac_finish_wrap,
00837     sha384_hmac_reset_wrap,
00838     sha384_hmac_wrap,
00839     sha384_ctx_alloc,
00840     sha384_ctx_free,
00841     sha384_process_wrap,
00842 };
00843 
00844 static void sha512_starts_wrap( void *ctx )
00845 {
00846     sha512_starts( (sha512_context *) ctx, 0 );
00847 }
00848 
00849 static void sha512_update_wrap( void *ctx, const unsigned char *input,
00850                                 size_t ilen )
00851 {
00852     sha512_update( (sha512_context *) ctx, input, ilen );
00853 }
00854 
00855 static void sha512_finish_wrap( void *ctx, unsigned char *output )
00856 {
00857     sha512_finish( (sha512_context *) ctx, output );
00858 }
00859 
00860 static void sha512_wrap( const unsigned char *input, size_t ilen,
00861                     unsigned char *output )
00862 {
00863     sha512( input, ilen, output, 0 );
00864 }
00865 
00866 static int sha512_file_wrap( const char *path, unsigned char *output )
00867 {
00868 #if defined(POLARSSL_FS_IO)
00869     return sha512_file( path, output, 0 );
00870 #else
00871     ((void) path);
00872     ((void) output);
00873     return( POLARSSL_ERR_MD_FEATURE_UNAVAILABLE );
00874 #endif
00875 }
00876 
00877 static void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key,
00878                                      size_t keylen )
00879 {
00880     sha512_hmac_starts( (sha512_context *) ctx, key, keylen, 0 );
00881 }
00882 
00883 static void sha512_hmac_update_wrap( void *ctx, const unsigned char *input,
00884                                      size_t ilen )
00885 {
00886     sha512_hmac_update( (sha512_context *) ctx, input, ilen );
00887 }
00888 
00889 static void sha512_hmac_finish_wrap( void *ctx, unsigned char *output )
00890 {
00891     sha512_hmac_finish( (sha512_context *) ctx, output );
00892 }
00893 
00894 static void sha512_hmac_reset_wrap( void *ctx )
00895 {
00896     sha512_hmac_reset( (sha512_context *) ctx );
00897 }
00898 
00899 static void sha512_hmac_wrap( const unsigned char *key, size_t keylen,
00900         const unsigned char *input, size_t ilen,
00901         unsigned char *output )
00902 {
00903     sha512_hmac( key, keylen, input, ilen, output, 0 );
00904 }
00905 
00906 static void * sha512_ctx_alloc( void )
00907 {
00908     sha512_context *ctx;
00909     ctx = polarssl_malloc( sizeof( sha512_context ) );
00910 
00911     if( ctx == NULL )
00912         return( NULL );
00913 
00914     sha512_init( ctx );
00915 
00916     return( ctx );
00917 }
00918 
00919 static void sha512_ctx_free( void *ctx )
00920 {
00921     sha512_free( (sha512_context *) ctx );
00922     polarssl_free( ctx );
00923 }
00924 
00925 static void sha512_process_wrap( void *ctx, const unsigned char *data )
00926 {
00927     sha512_process( (sha512_context *) ctx, data );
00928 }
00929 
00930 const md_info_t sha512_info = {
00931     POLARSSL_MD_SHA512,
00932     "SHA512",
00933     64,
00934     sha512_starts_wrap,
00935     sha512_update_wrap,
00936     sha512_finish_wrap,
00937     sha512_wrap,
00938     sha512_file_wrap,
00939     sha512_hmac_starts_wrap,
00940     sha512_hmac_update_wrap,
00941     sha512_hmac_finish_wrap,
00942     sha512_hmac_reset_wrap,
00943     sha512_hmac_wrap,
00944     sha512_ctx_alloc,
00945     sha512_ctx_free,
00946     sha512_process_wrap,
00947 };
00948 
00949 #endif /* POLARSSL_SHA512_C */
00950 
00951 #endif /* POLARSSL_MD_C */
00952