Lines Matching refs:ctx

265 void mbedtls_md_init( mbedtls_md_context_t *ctx )  in mbedtls_md_init()  argument
267 memset( ctx, 0, sizeof( mbedtls_md_context_t ) ); in mbedtls_md_init()
270 void mbedtls_md_free( mbedtls_md_context_t *ctx ) in mbedtls_md_free() argument
272 if( ctx == NULL || ctx->md_info == NULL ) in mbedtls_md_free()
275 if( ctx->md_ctx != NULL ) in mbedtls_md_free()
277 switch( ctx->md_info->type ) in mbedtls_md_free()
281 mbedtls_md2_free( ctx->md_ctx ); in mbedtls_md_free()
286 mbedtls_md4_free( ctx->md_ctx ); in mbedtls_md_free()
291 mbedtls_md5_free( ctx->md_ctx ); in mbedtls_md_free()
296 mbedtls_ripemd160_free( ctx->md_ctx ); in mbedtls_md_free()
301 mbedtls_sha1_free( ctx->md_ctx ); in mbedtls_md_free()
307 mbedtls_sha256_free( ctx->md_ctx ); in mbedtls_md_free()
315 mbedtls_sha512_free( ctx->md_ctx ); in mbedtls_md_free()
322 mbedtls_free( ctx->md_ctx ); in mbedtls_md_free()
325 if( ctx->hmac_ctx != NULL ) in mbedtls_md_free()
327 mbedtls_platform_zeroize( ctx->hmac_ctx, in mbedtls_md_free()
328 2 * ctx->md_info->block_size ); in mbedtls_md_free()
329 mbedtls_free( ctx->hmac_ctx ); in mbedtls_md_free()
332 mbedtls_platform_zeroize( ctx, sizeof( mbedtls_md_context_t ) ); in mbedtls_md_free()
397 int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) in mbedtls_md_init_ctx() argument
399 return mbedtls_md_setup( ctx, md_info, 1 ); in mbedtls_md_init_ctx()
405 ctx->md_ctx = mbedtls_calloc( 1, sizeof( mbedtls_##type##_context ) ); \
406 if( ctx->md_ctx == NULL ) \
408 mbedtls_##type##_init( ctx->md_ctx ); \
412 int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac ) in mbedtls_md_setup() argument
414 if( md_info == NULL || ctx == NULL ) in mbedtls_md_setup()
417 ctx->md_info = md_info; in mbedtls_md_setup()
418 ctx->md_ctx = NULL; in mbedtls_md_setup()
419 ctx->hmac_ctx = NULL; in mbedtls_md_setup()
468 ctx->hmac_ctx = mbedtls_calloc( 2, md_info->block_size ); in mbedtls_md_setup()
469 if( ctx->hmac_ctx == NULL ) in mbedtls_md_setup()
471 mbedtls_md_free( ctx ); in mbedtls_md_setup()
480 int mbedtls_md_starts( mbedtls_md_context_t *ctx ) in mbedtls_md_starts() argument
482 if( ctx == NULL || ctx->md_info == NULL ) in mbedtls_md_starts()
485 switch( ctx->md_info->type ) in mbedtls_md_starts()
489 return( mbedtls_md2_starts_ret( ctx->md_ctx ) ); in mbedtls_md_starts()
493 return( mbedtls_md4_starts_ret( ctx->md_ctx ) ); in mbedtls_md_starts()
497 return( mbedtls_md5_starts_ret( ctx->md_ctx ) ); in mbedtls_md_starts()
501 return( mbedtls_ripemd160_starts_ret( ctx->md_ctx ) ); in mbedtls_md_starts()
505 return( mbedtls_sha1_starts_ret( ctx->md_ctx ) ); in mbedtls_md_starts()
509 return( mbedtls_sha256_starts_ret( ctx->md_ctx, 1 ) ); in mbedtls_md_starts()
511 return( mbedtls_sha256_starts_ret( ctx->md_ctx, 0 ) ); in mbedtls_md_starts()
516 return( mbedtls_sha512_starts_ret( ctx->md_ctx, 1 ) ); in mbedtls_md_starts()
519 return( mbedtls_sha512_starts_ret( ctx->md_ctx, 0 ) ); in mbedtls_md_starts()
526 int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen ) in mbedtls_md_update() argument
528 if( ctx == NULL || ctx->md_info == NULL ) in mbedtls_md_update()
531 switch( ctx->md_info->type ) in mbedtls_md_update()
535 return( mbedtls_md2_update_ret( ctx->md_ctx, input, ilen ) ); in mbedtls_md_update()
539 return( mbedtls_md4_update_ret( ctx->md_ctx, input, ilen ) ); in mbedtls_md_update()
543 return( mbedtls_md5_update_ret( ctx->md_ctx, input, ilen ) ); in mbedtls_md_update()
547 return( mbedtls_ripemd160_update_ret( ctx->md_ctx, input, ilen ) ); in mbedtls_md_update()
551 return( mbedtls_sha1_update_ret( ctx->md_ctx, input, ilen ) ); in mbedtls_md_update()
556 return( mbedtls_sha256_update_ret( ctx->md_ctx, input, ilen ) ); in mbedtls_md_update()
563 return( mbedtls_sha512_update_ret( ctx->md_ctx, input, ilen ) ); in mbedtls_md_update()
570 int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output ) in mbedtls_md_finish() argument
572 if( ctx == NULL || ctx->md_info == NULL ) in mbedtls_md_finish()
575 switch( ctx->md_info->type ) in mbedtls_md_finish()
579 return( mbedtls_md2_finish_ret( ctx->md_ctx, output ) ); in mbedtls_md_finish()
583 return( mbedtls_md4_finish_ret( ctx->md_ctx, output ) ); in mbedtls_md_finish()
587 return( mbedtls_md5_finish_ret( ctx->md_ctx, output ) ); in mbedtls_md_finish()
591 return( mbedtls_ripemd160_finish_ret( ctx->md_ctx, output ) ); in mbedtls_md_finish()
595 return( mbedtls_sha1_finish_ret( ctx->md_ctx, output ) ); in mbedtls_md_finish()
600 return( mbedtls_sha256_finish_ret( ctx->md_ctx, output ) ); in mbedtls_md_finish()
607 return( mbedtls_sha512_finish_ret( ctx->md_ctx, output ) ); in mbedtls_md_finish()
667 mbedtls_md_context_t ctx; in mbedtls_md_file() local
676 mbedtls_md_init( &ctx ); in mbedtls_md_file()
678 if( ( ret = mbedtls_md_setup( &ctx, md_info, 0 ) ) != 0 ) in mbedtls_md_file()
681 if( ( ret = mbedtls_md_starts( &ctx ) ) != 0 ) in mbedtls_md_file()
685 if( ( ret = mbedtls_md_update( &ctx, buf, n ) ) != 0 ) in mbedtls_md_file()
691 ret = mbedtls_md_finish( &ctx, output ); in mbedtls_md_file()
696 mbedtls_md_free( &ctx ); in mbedtls_md_file()
702 int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key, size_t keylen ) in mbedtls_md_hmac_starts() argument
709 if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL ) in mbedtls_md_hmac_starts()
712 if( keylen > (size_t) ctx->md_info->block_size ) in mbedtls_md_hmac_starts()
714 if( ( ret = mbedtls_md_starts( ctx ) ) != 0 ) in mbedtls_md_hmac_starts()
716 if( ( ret = mbedtls_md_update( ctx, key, keylen ) ) != 0 ) in mbedtls_md_hmac_starts()
718 if( ( ret = mbedtls_md_finish( ctx, sum ) ) != 0 ) in mbedtls_md_hmac_starts()
721 keylen = ctx->md_info->size; in mbedtls_md_hmac_starts()
725 ipad = (unsigned char *) ctx->hmac_ctx; in mbedtls_md_hmac_starts()
726 opad = (unsigned char *) ctx->hmac_ctx + ctx->md_info->block_size; in mbedtls_md_hmac_starts()
728 memset( ipad, 0x36, ctx->md_info->block_size ); in mbedtls_md_hmac_starts()
729 memset( opad, 0x5C, ctx->md_info->block_size ); in mbedtls_md_hmac_starts()
737 if( ( ret = mbedtls_md_starts( ctx ) ) != 0 ) in mbedtls_md_hmac_starts()
739 if( ( ret = mbedtls_md_update( ctx, ipad, in mbedtls_md_hmac_starts()
740 ctx->md_info->block_size ) ) != 0 ) in mbedtls_md_hmac_starts()
749 int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen ) in mbedtls_md_hmac_update() argument
751 if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL ) in mbedtls_md_hmac_update()
754 return( mbedtls_md_update( ctx, input, ilen ) ); in mbedtls_md_hmac_update()
757 int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output ) in mbedtls_md_hmac_finish() argument
763 if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL ) in mbedtls_md_hmac_finish()
766 opad = (unsigned char *) ctx->hmac_ctx + ctx->md_info->block_size; in mbedtls_md_hmac_finish()
768 if( ( ret = mbedtls_md_finish( ctx, tmp ) ) != 0 ) in mbedtls_md_hmac_finish()
770 if( ( ret = mbedtls_md_starts( ctx ) ) != 0 ) in mbedtls_md_hmac_finish()
772 if( ( ret = mbedtls_md_update( ctx, opad, in mbedtls_md_hmac_finish()
773 ctx->md_info->block_size ) ) != 0 ) in mbedtls_md_hmac_finish()
775 if( ( ret = mbedtls_md_update( ctx, tmp, in mbedtls_md_hmac_finish()
776 ctx->md_info->size ) ) != 0 ) in mbedtls_md_hmac_finish()
778 return( mbedtls_md_finish( ctx, output ) ); in mbedtls_md_hmac_finish()
781 int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx ) in mbedtls_md_hmac_reset() argument
786 if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL ) in mbedtls_md_hmac_reset()
789 ipad = (unsigned char *) ctx->hmac_ctx; in mbedtls_md_hmac_reset()
791 if( ( ret = mbedtls_md_starts( ctx ) ) != 0 ) in mbedtls_md_hmac_reset()
793 return( mbedtls_md_update( ctx, ipad, ctx->md_info->block_size ) ); in mbedtls_md_hmac_reset()
801 mbedtls_md_context_t ctx; in mbedtls_md_hmac() local
807 mbedtls_md_init( &ctx ); in mbedtls_md_hmac()
809 if( ( ret = mbedtls_md_setup( &ctx, md_info, 1 ) ) != 0 ) in mbedtls_md_hmac()
812 if( ( ret = mbedtls_md_hmac_starts( &ctx, key, keylen ) ) != 0 ) in mbedtls_md_hmac()
814 if( ( ret = mbedtls_md_hmac_update( &ctx, input, ilen ) ) != 0 ) in mbedtls_md_hmac()
816 if( ( ret = mbedtls_md_hmac_finish( &ctx, output ) ) != 0 ) in mbedtls_md_hmac()
820 mbedtls_md_free( &ctx ); in mbedtls_md_hmac()
825 int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data ) in mbedtls_md_process() argument
827 if( ctx == NULL || ctx->md_info == NULL ) in mbedtls_md_process()
830 switch( ctx->md_info->type ) in mbedtls_md_process()
834 return( mbedtls_internal_md2_process( ctx->md_ctx ) ); in mbedtls_md_process()
838 return( mbedtls_internal_md4_process( ctx->md_ctx, data ) ); in mbedtls_md_process()
842 return( mbedtls_internal_md5_process( ctx->md_ctx, data ) ); in mbedtls_md_process()
846 return( mbedtls_internal_ripemd160_process( ctx->md_ctx, data ) ); in mbedtls_md_process()
850 return( mbedtls_internal_sha1_process( ctx->md_ctx, data ) ); in mbedtls_md_process()
855 return( mbedtls_internal_sha256_process( ctx->md_ctx, data ) ); in mbedtls_md_process()
862 return( mbedtls_internal_sha512_process( ctx->md_ctx, data ) ); in mbedtls_md_process()