Lines Matching refs:ctx
61 void mbedtls_hmac_drbg_init( mbedtls_hmac_drbg_context *ctx ) in mbedtls_hmac_drbg_init() argument
63 memset( ctx, 0, sizeof( mbedtls_hmac_drbg_context ) ); in mbedtls_hmac_drbg_init()
66 mbedtls_mutex_init( &ctx->mutex ); in mbedtls_hmac_drbg_init()
73 void mbedtls_hmac_drbg_update( mbedtls_hmac_drbg_context *ctx, in mbedtls_hmac_drbg_update() argument
76 size_t md_len = mbedtls_md_get_size( ctx->md_ctx.md_info ); in mbedtls_hmac_drbg_update()
84 mbedtls_md_hmac_reset( &ctx->md_ctx ); in mbedtls_hmac_drbg_update()
85 mbedtls_md_hmac_update( &ctx->md_ctx, ctx->V, md_len ); in mbedtls_hmac_drbg_update()
86 mbedtls_md_hmac_update( &ctx->md_ctx, sep, 1 ); in mbedtls_hmac_drbg_update()
88 mbedtls_md_hmac_update( &ctx->md_ctx, additional, add_len ); in mbedtls_hmac_drbg_update()
89 mbedtls_md_hmac_finish( &ctx->md_ctx, K ); in mbedtls_hmac_drbg_update()
92 mbedtls_md_hmac_starts( &ctx->md_ctx, K, md_len ); in mbedtls_hmac_drbg_update()
93 mbedtls_md_hmac_update( &ctx->md_ctx, ctx->V, md_len ); in mbedtls_hmac_drbg_update()
94 mbedtls_md_hmac_finish( &ctx->md_ctx, ctx->V ); in mbedtls_hmac_drbg_update()
101 int mbedtls_hmac_drbg_seed_buf( mbedtls_hmac_drbg_context *ctx, in mbedtls_hmac_drbg_seed_buf() argument
107 if( ( ret = mbedtls_md_setup( &ctx->md_ctx, md_info, 1 ) ) != 0 ) in mbedtls_hmac_drbg_seed_buf()
115 mbedtls_md_hmac_starts( &ctx->md_ctx, ctx->V, mbedtls_md_get_size( md_info ) ); in mbedtls_hmac_drbg_seed_buf()
116 memset( ctx->V, 0x01, mbedtls_md_get_size( md_info ) ); in mbedtls_hmac_drbg_seed_buf()
118 mbedtls_hmac_drbg_update( ctx, data, data_len ); in mbedtls_hmac_drbg_seed_buf()
126 int mbedtls_hmac_drbg_reseed( mbedtls_hmac_drbg_context *ctx, in mbedtls_hmac_drbg_reseed() argument
134 ctx->entropy_len + len > MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT ) in mbedtls_hmac_drbg_reseed()
142 if( ctx->f_entropy( ctx->p_entropy, seed, ctx->entropy_len ) != 0 ) in mbedtls_hmac_drbg_reseed()
145 seedlen = ctx->entropy_len; in mbedtls_hmac_drbg_reseed()
155 mbedtls_hmac_drbg_update( ctx, seed, seedlen ); in mbedtls_hmac_drbg_reseed()
158 ctx->reseed_counter = 1; in mbedtls_hmac_drbg_reseed()
167 int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx, in mbedtls_hmac_drbg_seed() argument
177 if( ( ret = mbedtls_md_setup( &ctx->md_ctx, md_info, 1 ) ) != 0 ) in mbedtls_hmac_drbg_seed()
187 mbedtls_md_hmac_starts( &ctx->md_ctx, ctx->V, md_size ); in mbedtls_hmac_drbg_seed()
188 memset( ctx->V, 0x01, md_size ); in mbedtls_hmac_drbg_seed()
190 ctx->f_entropy = f_entropy; in mbedtls_hmac_drbg_seed()
191 ctx->p_entropy = p_entropy; in mbedtls_hmac_drbg_seed()
193 ctx->reseed_interval = MBEDTLS_HMAC_DRBG_RESEED_INTERVAL; in mbedtls_hmac_drbg_seed()
210 ctx->entropy_len = entropy_len * 3 / 2; in mbedtls_hmac_drbg_seed()
212 if( ( ret = mbedtls_hmac_drbg_reseed( ctx, custom, len ) ) != 0 ) in mbedtls_hmac_drbg_seed()
215 ctx->entropy_len = entropy_len; in mbedtls_hmac_drbg_seed()
223 void mbedtls_hmac_drbg_set_prediction_resistance( mbedtls_hmac_drbg_context *ctx, in mbedtls_hmac_drbg_set_prediction_resistance() argument
226 ctx->prediction_resistance = resistance; in mbedtls_hmac_drbg_set_prediction_resistance()
232 void mbedtls_hmac_drbg_set_entropy_len( mbedtls_hmac_drbg_context *ctx, size_t len ) in mbedtls_hmac_drbg_set_entropy_len() argument
234 ctx->entropy_len = len; in mbedtls_hmac_drbg_set_entropy_len()
240 void mbedtls_hmac_drbg_set_reseed_interval( mbedtls_hmac_drbg_context *ctx, int interval ) in mbedtls_hmac_drbg_set_reseed_interval() argument
242 ctx->reseed_interval = interval; in mbedtls_hmac_drbg_set_reseed_interval()
254 mbedtls_hmac_drbg_context *ctx = (mbedtls_hmac_drbg_context *) p_rng; in mbedtls_hmac_drbg_random_with_add() local
255 size_t md_len = mbedtls_md_get_size( ctx->md_ctx.md_info ); in mbedtls_hmac_drbg_random_with_add()
268 if( ctx->f_entropy != NULL && /* For no-reseeding instances */ in mbedtls_hmac_drbg_random_with_add()
269 ( ctx->prediction_resistance == MBEDTLS_HMAC_DRBG_PR_ON || in mbedtls_hmac_drbg_random_with_add()
270 ctx->reseed_counter > ctx->reseed_interval ) ) in mbedtls_hmac_drbg_random_with_add()
272 if( ( ret = mbedtls_hmac_drbg_reseed( ctx, additional, add_len ) ) != 0 ) in mbedtls_hmac_drbg_random_with_add()
280 mbedtls_hmac_drbg_update( ctx, additional, add_len ); in mbedtls_hmac_drbg_random_with_add()
287 mbedtls_md_hmac_reset( &ctx->md_ctx ); in mbedtls_hmac_drbg_random_with_add()
288 mbedtls_md_hmac_update( &ctx->md_ctx, ctx->V, md_len ); in mbedtls_hmac_drbg_random_with_add()
289 mbedtls_md_hmac_finish( &ctx->md_ctx, ctx->V ); in mbedtls_hmac_drbg_random_with_add()
291 memcpy( out, ctx->V, use_len ); in mbedtls_hmac_drbg_random_with_add()
297 mbedtls_hmac_drbg_update( ctx, additional, add_len ); in mbedtls_hmac_drbg_random_with_add()
300 ctx->reseed_counter++; in mbedtls_hmac_drbg_random_with_add()
312 mbedtls_hmac_drbg_context *ctx = (mbedtls_hmac_drbg_context *) p_rng; in mbedtls_hmac_drbg_random() local
315 if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) in mbedtls_hmac_drbg_random()
319 ret = mbedtls_hmac_drbg_random_with_add( ctx, output, out_len, NULL, 0 ); in mbedtls_hmac_drbg_random()
322 if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) in mbedtls_hmac_drbg_random()
332 void mbedtls_hmac_drbg_free( mbedtls_hmac_drbg_context *ctx ) in mbedtls_hmac_drbg_free() argument
334 if( ctx == NULL ) in mbedtls_hmac_drbg_free()
338 mbedtls_mutex_free( &ctx->mutex ); in mbedtls_hmac_drbg_free()
340 mbedtls_md_free( &ctx->md_ctx ); in mbedtls_hmac_drbg_free()
341 mbedtls_zeroize( ctx, sizeof( mbedtls_hmac_drbg_context ) ); in mbedtls_hmac_drbg_free()
345 int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path ) in mbedtls_hmac_drbg_write_seed_file() argument
354 if( ( ret = mbedtls_hmac_drbg_random( ctx, buf, sizeof( buf ) ) ) != 0 ) in mbedtls_hmac_drbg_write_seed_file()
370 int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path ) in mbedtls_hmac_drbg_update_seed_file() argument
397 mbedtls_hmac_drbg_update( ctx, buf, n ); in mbedtls_hmac_drbg_update_seed_file()
399 return( mbedtls_hmac_drbg_write_seed_file( ctx, path ) ); in mbedtls_hmac_drbg_update_seed_file()
471 mbedtls_hmac_drbg_context ctx; in mbedtls_hmac_drbg_self_test() local
475 mbedtls_hmac_drbg_init( &ctx ); in mbedtls_hmac_drbg_self_test()
484 CHK( mbedtls_hmac_drbg_seed( &ctx, md_info, in mbedtls_hmac_drbg_self_test()
487 mbedtls_hmac_drbg_set_prediction_resistance( &ctx, MBEDTLS_HMAC_DRBG_PR_ON ); in mbedtls_hmac_drbg_self_test()
488 CHK( mbedtls_hmac_drbg_random( &ctx, buf, OUTPUT_LEN ) ); in mbedtls_hmac_drbg_self_test()
489 CHK( mbedtls_hmac_drbg_random( &ctx, buf, OUTPUT_LEN ) ); in mbedtls_hmac_drbg_self_test()
491 mbedtls_hmac_drbg_free( &ctx ); in mbedtls_hmac_drbg_self_test()
493 mbedtls_hmac_drbg_free( &ctx ); in mbedtls_hmac_drbg_self_test()
504 mbedtls_hmac_drbg_init( &ctx ); in mbedtls_hmac_drbg_self_test()
507 CHK( mbedtls_hmac_drbg_seed( &ctx, md_info, in mbedtls_hmac_drbg_self_test()
510 CHK( mbedtls_hmac_drbg_reseed( &ctx, NULL, 0 ) ); in mbedtls_hmac_drbg_self_test()
511 CHK( mbedtls_hmac_drbg_random( &ctx, buf, OUTPUT_LEN ) ); in mbedtls_hmac_drbg_self_test()
512 CHK( mbedtls_hmac_drbg_random( &ctx, buf, OUTPUT_LEN ) ); in mbedtls_hmac_drbg_self_test()
514 mbedtls_hmac_drbg_free( &ctx ); in mbedtls_hmac_drbg_self_test()
516 mbedtls_hmac_drbg_free( &ctx ); in mbedtls_hmac_drbg_self_test()