Lines Matching refs:ctx
48 const mbedtls_ecdh_context *ctx ) in mbedtls_ecdh_grp_id() argument
51 return( ctx->grp.id ); in mbedtls_ecdh_grp_id()
53 return( ctx->grp_id ); in mbedtls_ecdh_grp_id()
158 static void ecdh_init_internal( mbedtls_ecdh_context_mbed *ctx ) in ecdh_init_internal() argument
160 mbedtls_ecp_group_init( &ctx->grp ); in ecdh_init_internal()
161 mbedtls_mpi_init( &ctx->d ); in ecdh_init_internal()
162 mbedtls_ecp_point_init( &ctx->Q ); in ecdh_init_internal()
163 mbedtls_ecp_point_init( &ctx->Qp ); in ecdh_init_internal()
164 mbedtls_mpi_init( &ctx->z ); in ecdh_init_internal()
167 mbedtls_ecp_restart_init( &ctx->rs ); in ecdh_init_internal()
174 void mbedtls_ecdh_init( mbedtls_ecdh_context *ctx ) in mbedtls_ecdh_init() argument
176 ECDH_VALIDATE( ctx != NULL ); in mbedtls_ecdh_init()
179 ecdh_init_internal( ctx ); in mbedtls_ecdh_init()
180 mbedtls_ecp_point_init( &ctx->Vi ); in mbedtls_ecdh_init()
181 mbedtls_ecp_point_init( &ctx->Vf ); in mbedtls_ecdh_init()
182 mbedtls_mpi_init( &ctx->_d ); in mbedtls_ecdh_init()
184 memset( ctx, 0, sizeof( mbedtls_ecdh_context ) ); in mbedtls_ecdh_init()
186 ctx->var = MBEDTLS_ECDH_VARIANT_NONE; in mbedtls_ecdh_init()
188 ctx->point_format = MBEDTLS_ECP_PF_UNCOMPRESSED; in mbedtls_ecdh_init()
190 ctx->restart_enabled = 0; in mbedtls_ecdh_init()
194 static int ecdh_setup_internal( mbedtls_ecdh_context_mbed *ctx, in ecdh_setup_internal() argument
199 ret = mbedtls_ecp_group_load( &ctx->grp, grp_id ); in ecdh_setup_internal()
211 int mbedtls_ecdh_setup( mbedtls_ecdh_context *ctx, mbedtls_ecp_group_id grp_id ) in mbedtls_ecdh_setup() argument
213 ECDH_VALIDATE_RET( ctx != NULL ); in mbedtls_ecdh_setup()
216 return( ecdh_setup_internal( ctx, grp_id ) ); in mbedtls_ecdh_setup()
222 ctx->point_format = MBEDTLS_ECP_PF_COMPRESSED; in mbedtls_ecdh_setup()
223 ctx->var = MBEDTLS_ECDH_VARIANT_EVEREST; in mbedtls_ecdh_setup()
224 ctx->grp_id = grp_id; in mbedtls_ecdh_setup()
225 return( mbedtls_everest_setup( &ctx->ctx.everest_ecdh, grp_id ) ); in mbedtls_ecdh_setup()
228 ctx->point_format = MBEDTLS_ECP_PF_UNCOMPRESSED; in mbedtls_ecdh_setup()
229 ctx->var = MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0; in mbedtls_ecdh_setup()
230 ctx->grp_id = grp_id; in mbedtls_ecdh_setup()
231 ecdh_init_internal( &ctx->ctx.mbed_ecdh ); in mbedtls_ecdh_setup()
232 return( ecdh_setup_internal( &ctx->ctx.mbed_ecdh, grp_id ) ); in mbedtls_ecdh_setup()
237 static void ecdh_free_internal( mbedtls_ecdh_context_mbed *ctx ) in ecdh_free_internal() argument
239 mbedtls_ecp_group_free( &ctx->grp ); in ecdh_free_internal()
240 mbedtls_mpi_free( &ctx->d ); in ecdh_free_internal()
241 mbedtls_ecp_point_free( &ctx->Q ); in ecdh_free_internal()
242 mbedtls_ecp_point_free( &ctx->Qp ); in ecdh_free_internal()
243 mbedtls_mpi_free( &ctx->z ); in ecdh_free_internal()
246 mbedtls_ecp_restart_free( &ctx->rs ); in ecdh_free_internal()
254 void mbedtls_ecdh_enable_restart( mbedtls_ecdh_context *ctx ) in mbedtls_ecdh_enable_restart() argument
256 ECDH_VALIDATE( ctx != NULL ); in mbedtls_ecdh_enable_restart()
258 ctx->restart_enabled = 1; in mbedtls_ecdh_enable_restart()
265 void mbedtls_ecdh_free( mbedtls_ecdh_context *ctx ) in mbedtls_ecdh_free() argument
267 if( ctx == NULL ) in mbedtls_ecdh_free()
271 mbedtls_ecp_point_free( &ctx->Vi ); in mbedtls_ecdh_free()
272 mbedtls_ecp_point_free( &ctx->Vf ); in mbedtls_ecdh_free()
273 mbedtls_mpi_free( &ctx->_d ); in mbedtls_ecdh_free()
274 ecdh_free_internal( ctx ); in mbedtls_ecdh_free()
276 switch( ctx->var ) in mbedtls_ecdh_free()
280 mbedtls_everest_free( &ctx->ctx.everest_ecdh ); in mbedtls_ecdh_free()
284 ecdh_free_internal( &ctx->ctx.mbed_ecdh ); in mbedtls_ecdh_free()
290 ctx->point_format = MBEDTLS_ECP_PF_UNCOMPRESSED; in mbedtls_ecdh_free()
291 ctx->var = MBEDTLS_ECDH_VARIANT_NONE; in mbedtls_ecdh_free()
292 ctx->grp_id = MBEDTLS_ECP_DP_NONE; in mbedtls_ecdh_free()
296 static int ecdh_make_params_internal( mbedtls_ecdh_context_mbed *ctx, in ecdh_make_params_internal() argument
311 if( ctx->grp.pbits == 0 ) in ecdh_make_params_internal()
316 rs_ctx = &ctx->rs; in ecdh_make_params_internal()
323 if( ( ret = ecdh_gen_public_restartable( &ctx->grp, &ctx->d, &ctx->Q, in ecdh_make_params_internal()
327 if( ( ret = mbedtls_ecdh_gen_public( &ctx->grp, &ctx->d, &ctx->Q, in ecdh_make_params_internal()
332 if( ( ret = mbedtls_ecp_tls_write_group( &ctx->grp, &grp_len, buf, in ecdh_make_params_internal()
339 if( ( ret = mbedtls_ecp_tls_write_point( &ctx->grp, &ctx->Q, point_format, in ecdh_make_params_internal()
354 int mbedtls_ecdh_make_params( mbedtls_ecdh_context *ctx, size_t *olen, in mbedtls_ecdh_make_params() argument
360 ECDH_VALIDATE_RET( ctx != NULL ); in mbedtls_ecdh_make_params()
366 restart_enabled = ctx->restart_enabled; in mbedtls_ecdh_make_params()
372 return( ecdh_make_params_internal( ctx, olen, ctx->point_format, buf, blen, in mbedtls_ecdh_make_params()
375 switch( ctx->var ) in mbedtls_ecdh_make_params()
379 return( mbedtls_everest_make_params( &ctx->ctx.everest_ecdh, olen, in mbedtls_ecdh_make_params()
383 return( ecdh_make_params_internal( &ctx->ctx.mbed_ecdh, olen, in mbedtls_ecdh_make_params()
384 ctx->point_format, buf, blen, in mbedtls_ecdh_make_params()
393 static int ecdh_read_params_internal( mbedtls_ecdh_context_mbed *ctx, in ecdh_read_params_internal() argument
397 return( mbedtls_ecp_tls_read_point( &ctx->grp, &ctx->Qp, buf, in ecdh_read_params_internal()
408 int mbedtls_ecdh_read_params( mbedtls_ecdh_context *ctx, in mbedtls_ecdh_read_params() argument
414 ECDH_VALIDATE_RET( ctx != NULL ); in mbedtls_ecdh_read_params()
423 if( ( ret = mbedtls_ecdh_setup( ctx, grp_id ) ) != 0 ) in mbedtls_ecdh_read_params()
427 return( ecdh_read_params_internal( ctx, buf, end ) ); in mbedtls_ecdh_read_params()
429 switch( ctx->var ) in mbedtls_ecdh_read_params()
433 return( mbedtls_everest_read_params( &ctx->ctx.everest_ecdh, in mbedtls_ecdh_read_params()
437 return( ecdh_read_params_internal( &ctx->ctx.mbed_ecdh, in mbedtls_ecdh_read_params()
445 static int ecdh_get_params_internal( mbedtls_ecdh_context_mbed *ctx, in ecdh_get_params_internal() argument
453 return( mbedtls_ecp_copy( &ctx->Qp, &key->Q ) ); in ecdh_get_params_internal()
459 if( ( ret = mbedtls_ecp_copy( &ctx->Q, &key->Q ) ) != 0 || in ecdh_get_params_internal()
460 ( ret = mbedtls_mpi_copy( &ctx->d, &key->d ) ) != 0 ) in ecdh_get_params_internal()
469 int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx, in mbedtls_ecdh_get_params() argument
474 ECDH_VALIDATE_RET( ctx != NULL ); in mbedtls_ecdh_get_params()
479 if( mbedtls_ecdh_grp_id( ctx ) == MBEDTLS_ECP_DP_NONE ) in mbedtls_ecdh_get_params()
483 if( ( ret = mbedtls_ecdh_setup( ctx, key->grp.id ) ) != 0 ) in mbedtls_ecdh_get_params()
491 if( mbedtls_ecdh_grp_id( ctx ) != key->grp.id ) in mbedtls_ecdh_get_params()
496 return( ecdh_get_params_internal( ctx, key, side ) ); in mbedtls_ecdh_get_params()
498 switch( ctx->var ) in mbedtls_ecdh_get_params()
506 return( mbedtls_everest_get_params( &ctx->ctx.everest_ecdh, in mbedtls_ecdh_get_params()
511 return( ecdh_get_params_internal( &ctx->ctx.mbed_ecdh, in mbedtls_ecdh_get_params()
519 static int ecdh_make_public_internal( mbedtls_ecdh_context_mbed *ctx, in ecdh_make_public_internal() argument
533 if( ctx->grp.pbits == 0 ) in ecdh_make_public_internal()
538 rs_ctx = &ctx->rs; in ecdh_make_public_internal()
544 if( ( ret = ecdh_gen_public_restartable( &ctx->grp, &ctx->d, &ctx->Q, in ecdh_make_public_internal()
548 if( ( ret = mbedtls_ecdh_gen_public( &ctx->grp, &ctx->d, &ctx->Q, in ecdh_make_public_internal()
553 return mbedtls_ecp_tls_write_point( &ctx->grp, &ctx->Q, point_format, olen, in ecdh_make_public_internal()
560 int mbedtls_ecdh_make_public( mbedtls_ecdh_context *ctx, size_t *olen, in mbedtls_ecdh_make_public() argument
566 ECDH_VALIDATE_RET( ctx != NULL ); in mbedtls_ecdh_make_public()
572 restart_enabled = ctx->restart_enabled; in mbedtls_ecdh_make_public()
576 return( ecdh_make_public_internal( ctx, olen, ctx->point_format, buf, blen, in mbedtls_ecdh_make_public()
579 switch( ctx->var ) in mbedtls_ecdh_make_public()
583 return( mbedtls_everest_make_public( &ctx->ctx.everest_ecdh, olen, in mbedtls_ecdh_make_public()
587 return( ecdh_make_public_internal( &ctx->ctx.mbed_ecdh, olen, in mbedtls_ecdh_make_public()
588 ctx->point_format, buf, blen, in mbedtls_ecdh_make_public()
597 static int ecdh_read_public_internal( mbedtls_ecdh_context_mbed *ctx, in ecdh_read_public_internal() argument
603 if( ( ret = mbedtls_ecp_tls_read_point( &ctx->grp, &ctx->Qp, &p, in ecdh_read_public_internal()
616 int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx, in mbedtls_ecdh_read_public() argument
619 ECDH_VALIDATE_RET( ctx != NULL ); in mbedtls_ecdh_read_public()
623 return( ecdh_read_public_internal( ctx, buf, blen ) ); in mbedtls_ecdh_read_public()
625 switch( ctx->var ) in mbedtls_ecdh_read_public()
629 return( mbedtls_everest_read_public( &ctx->ctx.everest_ecdh, in mbedtls_ecdh_read_public()
633 return( ecdh_read_public_internal( &ctx->ctx.mbed_ecdh, in mbedtls_ecdh_read_public()
641 static int ecdh_calc_secret_internal( mbedtls_ecdh_context_mbed *ctx, in ecdh_calc_secret_internal() argument
655 if( ctx == NULL || ctx->grp.pbits == 0 ) in ecdh_calc_secret_internal()
660 rs_ctx = &ctx->rs; in ecdh_calc_secret_internal()
666 if( ( ret = ecdh_compute_shared_restartable( &ctx->grp, &ctx->z, &ctx->Qp, in ecdh_calc_secret_internal()
667 &ctx->d, f_rng, p_rng, in ecdh_calc_secret_internal()
673 if( ( ret = mbedtls_ecdh_compute_shared( &ctx->grp, &ctx->z, &ctx->Qp, in ecdh_calc_secret_internal()
674 &ctx->d, f_rng, p_rng ) ) != 0 ) in ecdh_calc_secret_internal()
680 if( mbedtls_mpi_size( &ctx->z ) > blen ) in ecdh_calc_secret_internal()
683 *olen = ctx->grp.pbits / 8 + ( ( ctx->grp.pbits % 8 ) != 0 ); in ecdh_calc_secret_internal()
685 if( mbedtls_ecp_get_type( &ctx->grp ) == MBEDTLS_ECP_TYPE_MONTGOMERY ) in ecdh_calc_secret_internal()
686 return mbedtls_mpi_write_binary_le( &ctx->z, buf, *olen ); in ecdh_calc_secret_internal()
688 return mbedtls_mpi_write_binary( &ctx->z, buf, *olen ); in ecdh_calc_secret_internal()
694 int mbedtls_ecdh_calc_secret( mbedtls_ecdh_context *ctx, size_t *olen, in mbedtls_ecdh_calc_secret() argument
700 ECDH_VALIDATE_RET( ctx != NULL ); in mbedtls_ecdh_calc_secret()
705 restart_enabled = ctx->restart_enabled; in mbedtls_ecdh_calc_secret()
709 return( ecdh_calc_secret_internal( ctx, olen, buf, blen, f_rng, p_rng, in mbedtls_ecdh_calc_secret()
712 switch( ctx->var ) in mbedtls_ecdh_calc_secret()
716 return( mbedtls_everest_calc_secret( &ctx->ctx.everest_ecdh, olen, in mbedtls_ecdh_calc_secret()
720 return( ecdh_calc_secret_internal( &ctx->ctx.mbed_ecdh, olen, buf, in mbedtls_ecdh_calc_secret()