Lines Matching refs:ctx

60 void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx )  in mbedtls_ctr_drbg_init()  argument
62 memset( ctx, 0, sizeof( mbedtls_ctr_drbg_context ) ); in mbedtls_ctr_drbg_init()
65 mbedtls_mutex_init( &ctx->mutex ); in mbedtls_ctr_drbg_init()
74 mbedtls_ctr_drbg_context *ctx, in mbedtls_ctr_drbg_seed_entropy_len() argument
86 mbedtls_aes_init( &ctx->aes_ctx ); in mbedtls_ctr_drbg_seed_entropy_len()
88 ctx->f_entropy = f_entropy; in mbedtls_ctr_drbg_seed_entropy_len()
89 ctx->p_entropy = p_entropy; in mbedtls_ctr_drbg_seed_entropy_len()
91 ctx->entropy_len = entropy_len; in mbedtls_ctr_drbg_seed_entropy_len()
92 ctx->reseed_interval = MBEDTLS_CTR_DRBG_RESEED_INTERVAL; in mbedtls_ctr_drbg_seed_entropy_len()
97 mbedtls_aes_setkey_enc( &ctx->aes_ctx, key, MBEDTLS_CTR_DRBG_KEYBITS ); in mbedtls_ctr_drbg_seed_entropy_len()
99 if( ( ret = mbedtls_ctr_drbg_reseed( ctx, custom, len ) ) != 0 ) in mbedtls_ctr_drbg_seed_entropy_len()
105 int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *ctx, in mbedtls_ctr_drbg_seed() argument
111 return( mbedtls_ctr_drbg_seed_entropy_len( ctx, f_entropy, p_entropy, custom, len, in mbedtls_ctr_drbg_seed()
115 void mbedtls_ctr_drbg_free( mbedtls_ctr_drbg_context *ctx ) in mbedtls_ctr_drbg_free() argument
117 if( ctx == NULL ) in mbedtls_ctr_drbg_free()
121 mbedtls_mutex_free( &ctx->mutex ); in mbedtls_ctr_drbg_free()
123 mbedtls_aes_free( &ctx->aes_ctx ); in mbedtls_ctr_drbg_free()
124 mbedtls_zeroize( ctx, sizeof( mbedtls_ctr_drbg_context ) ); in mbedtls_ctr_drbg_free()
127 void mbedtls_ctr_drbg_set_prediction_resistance( mbedtls_ctr_drbg_context *ctx, int resistance ) in mbedtls_ctr_drbg_set_prediction_resistance() argument
129 ctx->prediction_resistance = resistance; in mbedtls_ctr_drbg_set_prediction_resistance()
132 void mbedtls_ctr_drbg_set_entropy_len( mbedtls_ctr_drbg_context *ctx, size_t len ) in mbedtls_ctr_drbg_set_entropy_len() argument
134 ctx->entropy_len = len; in mbedtls_ctr_drbg_set_entropy_len()
137 void mbedtls_ctr_drbg_set_reseed_interval( mbedtls_ctr_drbg_context *ctx, int interval ) in mbedtls_ctr_drbg_set_reseed_interval() argument
139 ctx->reseed_interval = interval; in mbedtls_ctr_drbg_set_reseed_interval()
232 static int ctr_drbg_update_internal( mbedtls_ctr_drbg_context *ctx, in ctr_drbg_update_internal() argument
247 if( ++ctx->counter[i - 1] != 0 ) in ctr_drbg_update_internal()
253 mbedtls_aes_crypt_ecb( &ctx->aes_ctx, MBEDTLS_AES_ENCRYPT, ctx->counter, p ); in ctr_drbg_update_internal()
264 mbedtls_aes_setkey_enc( &ctx->aes_ctx, tmp, MBEDTLS_CTR_DRBG_KEYBITS ); in ctr_drbg_update_internal()
265 memcpy( ctx->counter, tmp + MBEDTLS_CTR_DRBG_KEYSIZE, MBEDTLS_CTR_DRBG_BLOCKSIZE ); in ctr_drbg_update_internal()
270 void mbedtls_ctr_drbg_update( mbedtls_ctr_drbg_context *ctx, in mbedtls_ctr_drbg_update() argument
283 ctr_drbg_update_internal( ctx, add_input ); in mbedtls_ctr_drbg_update()
287 int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx, in mbedtls_ctr_drbg_reseed() argument
293 if( ctx->entropy_len + len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT ) in mbedtls_ctr_drbg_reseed()
301 if( 0 != ctx->f_entropy( ctx->p_entropy, seed, in mbedtls_ctr_drbg_reseed()
302 ctx->entropy_len ) ) in mbedtls_ctr_drbg_reseed()
307 seedlen += ctx->entropy_len; in mbedtls_ctr_drbg_reseed()
326 ctr_drbg_update_internal( ctx, seed ); in mbedtls_ctr_drbg_reseed()
327 ctx->reseed_counter = 1; in mbedtls_ctr_drbg_reseed()
337 mbedtls_ctr_drbg_context *ctx = (mbedtls_ctr_drbg_context *) p_rng; in mbedtls_ctr_drbg_random_with_add() local
352 if( ctx->reseed_counter > ctx->reseed_interval || in mbedtls_ctr_drbg_random_with_add()
353 ctx->prediction_resistance ) in mbedtls_ctr_drbg_random_with_add()
355 if( ( ret = mbedtls_ctr_drbg_reseed( ctx, additional, add_len ) ) != 0 ) in mbedtls_ctr_drbg_random_with_add()
364 ctr_drbg_update_internal( ctx, add_input ); in mbedtls_ctr_drbg_random_with_add()
373 if( ++ctx->counter[i - 1] != 0 ) in mbedtls_ctr_drbg_random_with_add()
379 mbedtls_aes_crypt_ecb( &ctx->aes_ctx, MBEDTLS_AES_ENCRYPT, ctx->counter, tmp ); in mbedtls_ctr_drbg_random_with_add()
391 ctr_drbg_update_internal( ctx, add_input ); in mbedtls_ctr_drbg_random_with_add()
393 ctx->reseed_counter++; in mbedtls_ctr_drbg_random_with_add()
401 mbedtls_ctr_drbg_context *ctx = (mbedtls_ctr_drbg_context *) p_rng; in mbedtls_ctr_drbg_random() local
404 if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) in mbedtls_ctr_drbg_random()
408 ret = mbedtls_ctr_drbg_random_with_add( ctx, output, output_len, NULL, 0 ); in mbedtls_ctr_drbg_random()
411 if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) in mbedtls_ctr_drbg_random()
419 int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path ) in mbedtls_ctr_drbg_write_seed_file() argument
428 if( ( ret = mbedtls_ctr_drbg_random( ctx, buf, MBEDTLS_CTR_DRBG_MAX_INPUT ) ) != 0 ) in mbedtls_ctr_drbg_write_seed_file()
444 int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path ) in mbedtls_ctr_drbg_update_seed_file() argument
471 mbedtls_ctr_drbg_update( ctx, buf, n ); in mbedtls_ctr_drbg_update_seed_file()
473 return( mbedtls_ctr_drbg_write_seed_file( ctx, path ) ); in mbedtls_ctr_drbg_update_seed_file()
541 mbedtls_ctr_drbg_context ctx; in mbedtls_ctr_drbg_self_test() local
544 mbedtls_ctr_drbg_init( &ctx ); in mbedtls_ctr_drbg_self_test()
553 CHK( mbedtls_ctr_drbg_seed_entropy_len( &ctx, ctr_drbg_self_test_entropy, in mbedtls_ctr_drbg_self_test()
555 mbedtls_ctr_drbg_set_prediction_resistance( &ctx, MBEDTLS_CTR_DRBG_PR_ON ); in mbedtls_ctr_drbg_self_test()
556 CHK( mbedtls_ctr_drbg_random( &ctx, buf, MBEDTLS_CTR_DRBG_BLOCKSIZE ) ); in mbedtls_ctr_drbg_self_test()
557 CHK( mbedtls_ctr_drbg_random( &ctx, buf, MBEDTLS_CTR_DRBG_BLOCKSIZE ) ); in mbedtls_ctr_drbg_self_test()
560 mbedtls_ctr_drbg_free( &ctx ); in mbedtls_ctr_drbg_self_test()
571 mbedtls_ctr_drbg_init( &ctx ); in mbedtls_ctr_drbg_self_test()
574 CHK( mbedtls_ctr_drbg_seed_entropy_len( &ctx, ctr_drbg_self_test_entropy, in mbedtls_ctr_drbg_self_test()
576 CHK( mbedtls_ctr_drbg_random( &ctx, buf, 16 ) ); in mbedtls_ctr_drbg_self_test()
577 CHK( mbedtls_ctr_drbg_reseed( &ctx, NULL, 0 ) ); in mbedtls_ctr_drbg_self_test()
578 CHK( mbedtls_ctr_drbg_random( &ctx, buf, 16 ) ); in mbedtls_ctr_drbg_self_test()
581 mbedtls_ctr_drbg_free( &ctx ); in mbedtls_ctr_drbg_self_test()