Lines Matching refs:ctx

181 void mbedtls_md_init( mbedtls_md_context_t *ctx )  in mbedtls_md_init()  argument
183 memset( ctx, 0, sizeof( mbedtls_md_context_t ) ); in mbedtls_md_init()
186 void mbedtls_md_free( mbedtls_md_context_t *ctx ) in mbedtls_md_free() argument
188 if( ctx == NULL || ctx->md_info == NULL ) in mbedtls_md_free()
191 if( ctx->md_ctx != NULL ) in mbedtls_md_free()
192 ctx->md_info->ctx_free_func( ctx->md_ctx ); in mbedtls_md_free()
194 if( ctx->hmac_ctx != NULL ) in mbedtls_md_free()
196 mbedtls_zeroize( ctx->hmac_ctx, 2 * ctx->md_info->block_size ); in mbedtls_md_free()
197 mbedtls_free( ctx->hmac_ctx ); in mbedtls_md_free()
200 mbedtls_zeroize( ctx, sizeof( mbedtls_md_context_t ) ); in mbedtls_md_free()
219 int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) in mbedtls_md_init_ctx() argument
221 return mbedtls_md_setup( ctx, md_info, 1 ); in mbedtls_md_init_ctx()
225 int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac ) in mbedtls_md_setup() argument
227 if( md_info == NULL || ctx == NULL ) in mbedtls_md_setup()
230 if( ( ctx->md_ctx = md_info->ctx_alloc_func() ) == NULL ) in mbedtls_md_setup()
235 ctx->hmac_ctx = mbedtls_calloc( 2, md_info->block_size ); in mbedtls_md_setup()
236 if( ctx->hmac_ctx == NULL ) in mbedtls_md_setup()
238 md_info->ctx_free_func( ctx->md_ctx ); in mbedtls_md_setup()
243 ctx->md_info = md_info; in mbedtls_md_setup()
248 int mbedtls_md_starts( mbedtls_md_context_t *ctx ) in mbedtls_md_starts() argument
250 if( ctx == NULL || ctx->md_info == NULL ) in mbedtls_md_starts()
253 ctx->md_info->starts_func( ctx->md_ctx ); in mbedtls_md_starts()
258 int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen ) in mbedtls_md_update() argument
260 if( ctx == NULL || ctx->md_info == NULL ) in mbedtls_md_update()
263 ctx->md_info->update_func( ctx->md_ctx, input, ilen ); in mbedtls_md_update()
268 int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output ) in mbedtls_md_finish() argument
270 if( ctx == NULL || ctx->md_info == NULL ) in mbedtls_md_finish()
273 ctx->md_info->finish_func( ctx->md_ctx, output ); in mbedtls_md_finish()
295 mbedtls_md_context_t ctx; in mbedtls_md_file() local
304 mbedtls_md_init( &ctx ); in mbedtls_md_file()
306 if( ( ret = mbedtls_md_setup( &ctx, md_info, 0 ) ) != 0 ) in mbedtls_md_file()
309 md_info->starts_func( ctx.md_ctx ); in mbedtls_md_file()
312 md_info->update_func( ctx.md_ctx, buf, n ); in mbedtls_md_file()
320 md_info->finish_func( ctx.md_ctx, output ); in mbedtls_md_file()
324 mbedtls_md_free( &ctx ); in mbedtls_md_file()
330 int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key, size_t keylen ) in mbedtls_md_hmac_starts() argument
336 if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL ) in mbedtls_md_hmac_starts()
339 if( keylen > (size_t) ctx->md_info->block_size ) in mbedtls_md_hmac_starts()
341 ctx->md_info->starts_func( ctx->md_ctx ); in mbedtls_md_hmac_starts()
342 ctx->md_info->update_func( ctx->md_ctx, key, keylen ); in mbedtls_md_hmac_starts()
343 ctx->md_info->finish_func( ctx->md_ctx, sum ); in mbedtls_md_hmac_starts()
345 keylen = ctx->md_info->size; in mbedtls_md_hmac_starts()
349 ipad = (unsigned char *) ctx->hmac_ctx; in mbedtls_md_hmac_starts()
350 opad = (unsigned char *) ctx->hmac_ctx + ctx->md_info->block_size; in mbedtls_md_hmac_starts()
352 memset( ipad, 0x36, ctx->md_info->block_size ); in mbedtls_md_hmac_starts()
353 memset( opad, 0x5C, ctx->md_info->block_size ); in mbedtls_md_hmac_starts()
363 ctx->md_info->starts_func( ctx->md_ctx ); in mbedtls_md_hmac_starts()
364 ctx->md_info->update_func( ctx->md_ctx, ipad, ctx->md_info->block_size ); in mbedtls_md_hmac_starts()
369 int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen ) in mbedtls_md_hmac_update() argument
371 if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL ) in mbedtls_md_hmac_update()
374 ctx->md_info->update_func( ctx->md_ctx, input, ilen ); in mbedtls_md_hmac_update()
379 int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output ) in mbedtls_md_hmac_finish() argument
384 if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL ) in mbedtls_md_hmac_finish()
387 opad = (unsigned char *) ctx->hmac_ctx + ctx->md_info->block_size; in mbedtls_md_hmac_finish()
389 ctx->md_info->finish_func( ctx->md_ctx, tmp ); in mbedtls_md_hmac_finish()
390 ctx->md_info->starts_func( ctx->md_ctx ); in mbedtls_md_hmac_finish()
391 ctx->md_info->update_func( ctx->md_ctx, opad, ctx->md_info->block_size ); in mbedtls_md_hmac_finish()
392 ctx->md_info->update_func( ctx->md_ctx, tmp, ctx->md_info->size ); in mbedtls_md_hmac_finish()
393 ctx->md_info->finish_func( ctx->md_ctx, output ); in mbedtls_md_hmac_finish()
398 int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx ) in mbedtls_md_hmac_reset() argument
402 if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL ) in mbedtls_md_hmac_reset()
405 ipad = (unsigned char *) ctx->hmac_ctx; in mbedtls_md_hmac_reset()
407 ctx->md_info->starts_func( ctx->md_ctx ); in mbedtls_md_hmac_reset()
408 ctx->md_info->update_func( ctx->md_ctx, ipad, ctx->md_info->block_size ); in mbedtls_md_hmac_reset()
417 mbedtls_md_context_t ctx; in mbedtls_md_hmac() local
423 mbedtls_md_init( &ctx ); in mbedtls_md_hmac()
425 if( ( ret = mbedtls_md_setup( &ctx, md_info, 1 ) ) != 0 ) in mbedtls_md_hmac()
428 mbedtls_md_hmac_starts( &ctx, key, keylen ); in mbedtls_md_hmac()
429 mbedtls_md_hmac_update( &ctx, input, ilen ); in mbedtls_md_hmac()
430 mbedtls_md_hmac_finish( &ctx, output ); in mbedtls_md_hmac()
432 mbedtls_md_free( &ctx ); in mbedtls_md_hmac()
437 int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data ) in mbedtls_md_process() argument
439 if( ctx == NULL || ctx->md_info == NULL ) in mbedtls_md_process()
442 ctx->md_info->process_func( ctx->md_ctx, data ); in mbedtls_md_process()