PolarSSL v1.1.4
|
00001 00030 #include "polarssl/config.h" 00031 00032 #if defined(POLARSSL_MD_C) 00033 00034 #include "polarssl/md_wrap.h" 00035 #include "polarssl/md2.h" 00036 #include "polarssl/md4.h" 00037 #include "polarssl/md5.h" 00038 #include "polarssl/sha1.h" 00039 #include "polarssl/sha2.h" 00040 #include "polarssl/sha4.h" 00041 00042 #include <stdlib.h> 00043 00044 #if defined(POLARSSL_MD2_C) 00045 00046 static void md2_starts_wrap( void *ctx ) 00047 { 00048 md2_starts( (md2_context *) ctx ); 00049 } 00050 00051 static void md2_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 00052 { 00053 md2_update( (md2_context *) ctx, input, ilen ); 00054 } 00055 00056 static void md2_finish_wrap( void *ctx, unsigned char *output ) 00057 { 00058 md2_finish( (md2_context *) ctx, output ); 00059 } 00060 00061 int md2_file_wrap( const char *path, unsigned char *output ) 00062 { 00063 #if defined(POLARSSL_FS_IO) 00064 return md2_file( path, output ); 00065 #else 00066 ((void) path); 00067 ((void) output); 00068 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; 00069 #endif 00070 } 00071 00072 static void md2_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 00073 { 00074 md2_hmac_starts( (md2_context *) ctx, key, keylen ); 00075 } 00076 00077 static void md2_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 00078 { 00079 md2_hmac_update( (md2_context *) ctx, input, ilen ); 00080 } 00081 00082 static void md2_hmac_finish_wrap( void *ctx, unsigned char *output ) 00083 { 00084 md2_hmac_finish( (md2_context *) ctx, output ); 00085 } 00086 00087 static void md2_hmac_reset_wrap( void *ctx ) 00088 { 00089 md2_hmac_reset( (md2_context *) ctx ); 00090 } 00091 00092 static void * md2_ctx_alloc( void ) 00093 { 00094 return malloc( sizeof( md2_context ) ); 00095 } 00096 00097 static void md2_ctx_free( void *ctx ) 00098 { 00099 free( ctx ); 00100 } 00101 00102 const md_info_t md2_info = { 00103 POLARSSL_MD_MD2, 00104 "MD2", 00105 16, 00106 md2_starts_wrap, 00107 md2_update_wrap, 00108 md2_finish_wrap, 00109 md2, 00110 md2_file_wrap, 00111 md2_hmac_starts_wrap, 00112 md2_hmac_update_wrap, 00113 md2_hmac_finish_wrap, 00114 md2_hmac_reset_wrap, 00115 md2_hmac, 00116 md2_ctx_alloc, 00117 md2_ctx_free, 00118 }; 00119 00120 #endif 00121 00122 #if defined(POLARSSL_MD4_C) 00123 00124 void md4_starts_wrap( void *ctx ) 00125 { 00126 md4_starts( (md4_context *) ctx ); 00127 } 00128 00129 void md4_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 00130 { 00131 md4_update( (md4_context *) ctx, input, ilen ); 00132 } 00133 00134 void md4_finish_wrap( void *ctx, unsigned char *output ) 00135 { 00136 md4_finish( (md4_context *) ctx, output ); 00137 } 00138 00139 int md4_file_wrap( const char *path, unsigned char *output ) 00140 { 00141 #if defined(POLARSSL_FS_IO) 00142 return md4_file( path, output ); 00143 #else 00144 ((void) path); 00145 ((void) output); 00146 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; 00147 #endif 00148 } 00149 00150 void md4_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 00151 { 00152 md4_hmac_starts( (md4_context *) ctx, key, keylen ); 00153 } 00154 00155 void md4_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 00156 { 00157 md4_hmac_update( (md4_context *) ctx, input, ilen ); 00158 } 00159 00160 void md4_hmac_finish_wrap( void *ctx, unsigned char *output ) 00161 { 00162 md4_hmac_finish( (md4_context *) ctx, output ); 00163 } 00164 00165 void md4_hmac_reset_wrap( void *ctx ) 00166 { 00167 md4_hmac_reset( (md4_context *) ctx ); 00168 } 00169 00170 void *md4_ctx_alloc( void ) 00171 { 00172 return malloc( sizeof( md4_context ) ); 00173 } 00174 00175 void md4_ctx_free( void *ctx ) 00176 { 00177 free( ctx ); 00178 } 00179 00180 const md_info_t md4_info = { 00181 POLARSSL_MD_MD4, 00182 "MD4", 00183 16, 00184 md4_starts_wrap, 00185 md4_update_wrap, 00186 md4_finish_wrap, 00187 md4, 00188 md4_file_wrap, 00189 md4_hmac_starts_wrap, 00190 md4_hmac_update_wrap, 00191 md4_hmac_finish_wrap, 00192 md4_hmac_reset_wrap, 00193 md4_hmac, 00194 md4_ctx_alloc, 00195 md4_ctx_free, 00196 }; 00197 00198 #endif 00199 00200 #if defined(POLARSSL_MD5_C) 00201 00202 static void md5_starts_wrap( void *ctx ) 00203 { 00204 md5_starts( (md5_context *) ctx ); 00205 } 00206 00207 static void md5_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 00208 { 00209 md5_update( (md5_context *) ctx, input, ilen ); 00210 } 00211 00212 static void md5_finish_wrap( void *ctx, unsigned char *output ) 00213 { 00214 md5_finish( (md5_context *) ctx, output ); 00215 } 00216 00217 int md5_file_wrap( const char *path, unsigned char *output ) 00218 { 00219 #if defined(POLARSSL_FS_IO) 00220 return md5_file( path, output ); 00221 #else 00222 ((void) path); 00223 ((void) output); 00224 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; 00225 #endif 00226 } 00227 00228 static void md5_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 00229 { 00230 md5_hmac_starts( (md5_context *) ctx, key, keylen ); 00231 } 00232 00233 static void md5_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 00234 { 00235 md5_hmac_update( (md5_context *) ctx, input, ilen ); 00236 } 00237 00238 static void md5_hmac_finish_wrap( void *ctx, unsigned char *output ) 00239 { 00240 md5_hmac_finish( (md5_context *) ctx, output ); 00241 } 00242 00243 static void md5_hmac_reset_wrap( void *ctx ) 00244 { 00245 md5_hmac_reset( (md5_context *) ctx ); 00246 } 00247 00248 static void * md5_ctx_alloc( void ) 00249 { 00250 return malloc( sizeof( md5_context ) ); 00251 } 00252 00253 static void md5_ctx_free( void *ctx ) 00254 { 00255 free( ctx ); 00256 } 00257 00258 const md_info_t md5_info = { 00259 POLARSSL_MD_MD5, 00260 "MD5", 00261 16, 00262 md5_starts_wrap, 00263 md5_update_wrap, 00264 md5_finish_wrap, 00265 md5, 00266 md5_file_wrap, 00267 md5_hmac_starts_wrap, 00268 md5_hmac_update_wrap, 00269 md5_hmac_finish_wrap, 00270 md5_hmac_reset_wrap, 00271 md5_hmac, 00272 md5_ctx_alloc, 00273 md5_ctx_free, 00274 }; 00275 00276 #endif 00277 00278 #if defined(POLARSSL_SHA1_C) 00279 00280 void sha1_starts_wrap( void *ctx ) 00281 { 00282 sha1_starts( (sha1_context *) ctx ); 00283 } 00284 00285 void sha1_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 00286 { 00287 sha1_update( (sha1_context *) ctx, input, ilen ); 00288 } 00289 00290 void sha1_finish_wrap( void *ctx, unsigned char *output ) 00291 { 00292 sha1_finish( (sha1_context *) ctx, output ); 00293 } 00294 00295 int sha1_file_wrap( const char *path, unsigned char *output ) 00296 { 00297 #if defined(POLARSSL_FS_IO) 00298 return sha1_file( path, output ); 00299 #else 00300 ((void) path); 00301 ((void) output); 00302 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; 00303 #endif 00304 } 00305 00306 void sha1_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 00307 { 00308 sha1_hmac_starts( (sha1_context *) ctx, key, keylen ); 00309 } 00310 00311 void sha1_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 00312 { 00313 sha1_hmac_update( (sha1_context *) ctx, input, ilen ); 00314 } 00315 00316 void sha1_hmac_finish_wrap( void *ctx, unsigned char *output ) 00317 { 00318 sha1_hmac_finish( (sha1_context *) ctx, output ); 00319 } 00320 00321 void sha1_hmac_reset_wrap( void *ctx ) 00322 { 00323 sha1_hmac_reset( (sha1_context *) ctx ); 00324 } 00325 00326 void * sha1_ctx_alloc( void ) 00327 { 00328 return malloc( sizeof( sha1_context ) ); 00329 } 00330 00331 void sha1_ctx_free( void *ctx ) 00332 { 00333 free( ctx ); 00334 } 00335 00336 const md_info_t sha1_info = { 00337 POLARSSL_MD_SHA1, 00338 "SHA1", 00339 20, 00340 sha1_starts_wrap, 00341 sha1_update_wrap, 00342 sha1_finish_wrap, 00343 sha1, 00344 sha1_file_wrap, 00345 sha1_hmac_starts_wrap, 00346 sha1_hmac_update_wrap, 00347 sha1_hmac_finish_wrap, 00348 sha1_hmac_reset_wrap, 00349 sha1_hmac, 00350 sha1_ctx_alloc, 00351 sha1_ctx_free, 00352 }; 00353 00354 #endif 00355 00356 /* 00357 * Wrappers for generic message digests 00358 */ 00359 #if defined(POLARSSL_SHA2_C) 00360 00361 void sha224_starts_wrap( void *ctx ) 00362 { 00363 sha2_starts( (sha2_context *) ctx, 1 ); 00364 } 00365 00366 void sha224_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 00367 { 00368 sha2_update( (sha2_context *) ctx, input, ilen ); 00369 } 00370 00371 void sha224_finish_wrap( void *ctx, unsigned char *output ) 00372 { 00373 sha2_finish( (sha2_context *) ctx, output ); 00374 } 00375 00376 void sha224_wrap( const unsigned char *input, size_t ilen, 00377 unsigned char *output ) 00378 { 00379 sha2( input, ilen, output, 1 ); 00380 } 00381 00382 int sha224_file_wrap( const char *path, unsigned char *output ) 00383 { 00384 #if defined(POLARSSL_FS_IO) 00385 return sha2_file( path, output, 1 ); 00386 #else 00387 ((void) path); 00388 ((void) output); 00389 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; 00390 #endif 00391 } 00392 00393 void sha224_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 00394 { 00395 sha2_hmac_starts( (sha2_context *) ctx, key, keylen, 1 ); 00396 } 00397 00398 void sha224_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 00399 { 00400 sha2_hmac_update( (sha2_context *) ctx, input, ilen ); 00401 } 00402 00403 void sha224_hmac_finish_wrap( void *ctx, unsigned char *output ) 00404 { 00405 sha2_hmac_finish( (sha2_context *) ctx, output ); 00406 } 00407 00408 void sha224_hmac_reset_wrap( void *ctx ) 00409 { 00410 sha2_hmac_reset( (sha2_context *) ctx ); 00411 } 00412 00413 void sha224_hmac_wrap( const unsigned char *key, size_t keylen, 00414 const unsigned char *input, size_t ilen, 00415 unsigned char *output ) 00416 { 00417 sha2_hmac( key, keylen, input, ilen, output, 1 ); 00418 } 00419 00420 void * sha224_ctx_alloc( void ) 00421 { 00422 return malloc( sizeof( sha2_context ) ); 00423 } 00424 00425 void sha224_ctx_free( void *ctx ) 00426 { 00427 free( ctx ); 00428 } 00429 00430 const md_info_t sha224_info = { 00431 POLARSSL_MD_SHA224, 00432 "SHA224", 00433 28, 00434 sha224_starts_wrap, 00435 sha224_update_wrap, 00436 sha224_finish_wrap, 00437 sha224_wrap, 00438 sha224_file_wrap, 00439 sha224_hmac_starts_wrap, 00440 sha224_hmac_update_wrap, 00441 sha224_hmac_finish_wrap, 00442 sha224_hmac_reset_wrap, 00443 sha224_hmac_wrap, 00444 sha224_ctx_alloc, 00445 sha224_ctx_free, 00446 }; 00447 00448 void sha256_starts_wrap( void *ctx ) 00449 { 00450 sha2_starts( (sha2_context *) ctx, 0 ); 00451 } 00452 00453 void sha256_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 00454 { 00455 sha2_update( (sha2_context *) ctx, input, ilen ); 00456 } 00457 00458 void sha256_finish_wrap( void *ctx, unsigned char *output ) 00459 { 00460 sha2_finish( (sha2_context *) ctx, output ); 00461 } 00462 00463 void sha256_wrap( const unsigned char *input, size_t ilen, 00464 unsigned char *output ) 00465 { 00466 sha2( input, ilen, output, 0 ); 00467 } 00468 00469 int sha256_file_wrap( const char *path, unsigned char *output ) 00470 { 00471 #if defined(POLARSSL_FS_IO) 00472 return sha2_file( path, output, 0 ); 00473 #else 00474 ((void) path); 00475 ((void) output); 00476 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; 00477 #endif 00478 } 00479 00480 void sha256_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 00481 { 00482 sha2_hmac_starts( (sha2_context *) ctx, key, keylen, 0 ); 00483 } 00484 00485 void sha256_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 00486 { 00487 sha2_hmac_update( (sha2_context *) ctx, input, ilen ); 00488 } 00489 00490 void sha256_hmac_finish_wrap( void *ctx, unsigned char *output ) 00491 { 00492 sha2_hmac_finish( (sha2_context *) ctx, output ); 00493 } 00494 00495 void sha256_hmac_reset_wrap( void *ctx ) 00496 { 00497 sha2_hmac_reset( (sha2_context *) ctx ); 00498 } 00499 00500 void sha256_hmac_wrap( const unsigned char *key, size_t keylen, 00501 const unsigned char *input, size_t ilen, 00502 unsigned char *output ) 00503 { 00504 sha2_hmac( key, keylen, input, ilen, output, 0 ); 00505 } 00506 00507 void * sha256_ctx_alloc( void ) 00508 { 00509 return malloc( sizeof( sha2_context ) ); 00510 } 00511 00512 void sha256_ctx_free( void *ctx ) 00513 { 00514 free( ctx ); 00515 } 00516 00517 const md_info_t sha256_info = { 00518 POLARSSL_MD_SHA256, 00519 "SHA256", 00520 32, 00521 sha256_starts_wrap, 00522 sha256_update_wrap, 00523 sha256_finish_wrap, 00524 sha256_wrap, 00525 sha256_file_wrap, 00526 sha256_hmac_starts_wrap, 00527 sha256_hmac_update_wrap, 00528 sha256_hmac_finish_wrap, 00529 sha256_hmac_reset_wrap, 00530 sha256_hmac_wrap, 00531 sha256_ctx_alloc, 00532 sha256_ctx_free, 00533 }; 00534 00535 #endif 00536 00537 #if defined(POLARSSL_SHA4_C) 00538 00539 void sha384_starts_wrap( void *ctx ) 00540 { 00541 sha4_starts( (sha4_context *) ctx, 1 ); 00542 } 00543 00544 void sha384_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 00545 { 00546 sha4_update( (sha4_context *) ctx, input, ilen ); 00547 } 00548 00549 void sha384_finish_wrap( void *ctx, unsigned char *output ) 00550 { 00551 sha4_finish( (sha4_context *) ctx, output ); 00552 } 00553 00554 void sha384_wrap( const unsigned char *input, size_t ilen, 00555 unsigned char *output ) 00556 { 00557 sha4( input, ilen, output, 1 ); 00558 } 00559 00560 int sha384_file_wrap( const char *path, unsigned char *output ) 00561 { 00562 #if defined(POLARSSL_FS_IO) 00563 return sha4_file( path, output, 1 ); 00564 #else 00565 ((void) path); 00566 ((void) output); 00567 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; 00568 #endif 00569 } 00570 00571 void sha384_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 00572 { 00573 sha4_hmac_starts( (sha4_context *) ctx, key, keylen, 1 ); 00574 } 00575 00576 void sha384_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 00577 { 00578 sha4_hmac_update( (sha4_context *) ctx, input, ilen ); 00579 } 00580 00581 void sha384_hmac_finish_wrap( void *ctx, unsigned char *output ) 00582 { 00583 sha4_hmac_finish( (sha4_context *) ctx, output ); 00584 } 00585 00586 void sha384_hmac_reset_wrap( void *ctx ) 00587 { 00588 sha4_hmac_reset( (sha4_context *) ctx ); 00589 } 00590 00591 void sha384_hmac_wrap( const unsigned char *key, size_t keylen, 00592 const unsigned char *input, size_t ilen, 00593 unsigned char *output ) 00594 { 00595 sha4_hmac( key, keylen, input, ilen, output, 1 ); 00596 } 00597 00598 void * sha384_ctx_alloc( void ) 00599 { 00600 return malloc( sizeof( sha4_context ) ); 00601 } 00602 00603 void sha384_ctx_free( void *ctx ) 00604 { 00605 free( ctx ); 00606 } 00607 00608 const md_info_t sha384_info = { 00609 POLARSSL_MD_SHA384, 00610 "SHA384", 00611 48, 00612 sha384_starts_wrap, 00613 sha384_update_wrap, 00614 sha384_finish_wrap, 00615 sha384_wrap, 00616 sha384_file_wrap, 00617 sha384_hmac_starts_wrap, 00618 sha384_hmac_update_wrap, 00619 sha384_hmac_finish_wrap, 00620 sha384_hmac_reset_wrap, 00621 sha384_hmac_wrap, 00622 sha384_ctx_alloc, 00623 sha384_ctx_free, 00624 }; 00625 00626 void sha512_starts_wrap( void *ctx ) 00627 { 00628 sha4_starts( (sha4_context *) ctx, 0 ); 00629 } 00630 00631 void sha512_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 00632 { 00633 sha4_update( (sha4_context *) ctx, input, ilen ); 00634 } 00635 00636 void sha512_finish_wrap( void *ctx, unsigned char *output ) 00637 { 00638 sha4_finish( (sha4_context *) ctx, output ); 00639 } 00640 00641 void sha512_wrap( const unsigned char *input, size_t ilen, 00642 unsigned char *output ) 00643 { 00644 sha4( input, ilen, output, 0 ); 00645 } 00646 00647 int sha512_file_wrap( const char *path, unsigned char *output ) 00648 { 00649 #if defined(POLARSSL_FS_IO) 00650 return sha4_file( path, output, 0 ); 00651 #else 00652 ((void) path); 00653 ((void) output); 00654 return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE; 00655 #endif 00656 } 00657 00658 void sha512_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen ) 00659 { 00660 sha4_hmac_starts( (sha4_context *) ctx, key, keylen, 0 ); 00661 } 00662 00663 void sha512_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) 00664 { 00665 sha4_hmac_update( (sha4_context *) ctx, input, ilen ); 00666 } 00667 00668 void sha512_hmac_finish_wrap( void *ctx, unsigned char *output ) 00669 { 00670 sha4_hmac_finish( (sha4_context *) ctx, output ); 00671 } 00672 00673 void sha512_hmac_reset_wrap( void *ctx ) 00674 { 00675 sha4_hmac_reset( (sha4_context *) ctx ); 00676 } 00677 00678 void sha512_hmac_wrap( const unsigned char *key, size_t keylen, 00679 const unsigned char *input, size_t ilen, 00680 unsigned char *output ) 00681 { 00682 sha4_hmac( key, keylen, input, ilen, output, 0 ); 00683 } 00684 00685 void * sha512_ctx_alloc( void ) 00686 { 00687 return malloc( sizeof( sha4_context ) ); 00688 } 00689 00690 void sha512_ctx_free( void *ctx ) 00691 { 00692 free( ctx ); 00693 } 00694 00695 const md_info_t sha512_info = { 00696 POLARSSL_MD_SHA512, 00697 "SHA512", 00698 64, 00699 sha512_starts_wrap, 00700 sha512_update_wrap, 00701 sha512_finish_wrap, 00702 sha512_wrap, 00703 sha512_file_wrap, 00704 sha512_hmac_starts_wrap, 00705 sha512_hmac_update_wrap, 00706 sha512_hmac_finish_wrap, 00707 sha512_hmac_reset_wrap, 00708 sha512_hmac_wrap, 00709 sha512_ctx_alloc, 00710 sha512_ctx_free, 00711 }; 00712 00713 #endif 00714 00715 #endif