2 #include "mbedtls/ecdh.h"
4 static int load_public_key( int grp_id, data_t *point,
5 mbedtls_ecp_keypair *ecp )
8 TEST_ASSERT( mbedtls_ecp_group_load( &ecp->grp, grp_id ) == 0 );
9 TEST_ASSERT( mbedtls_ecp_point_read_binary( &ecp->grp,
13 TEST_ASSERT( mbedtls_ecp_check_pubkey( &ecp->grp,
20 static int load_private_key( int grp_id, data_t *private_key,
21 mbedtls_ecp_keypair *ecp,
22 rnd_pseudo_info *rnd_info )
25 TEST_ASSERT( mbedtls_ecp_group_load( &ecp->grp, grp_id ) == 0 );
26 TEST_ASSERT( mbedtls_mpi_read_binary( &ecp->d,
28 private_key->len ) == 0 );
29 TEST_ASSERT( mbedtls_ecp_check_privkey( &ecp->grp, &ecp->d ) == 0 );
30 /* Calculate the public key from the private key. */
31 TEST_ASSERT( mbedtls_ecp_mul( &ecp->grp, &ecp->Q, &ecp->d,
33 &rnd_pseudo_rand, rnd_info ) == 0 );
42 * depends_on:MBEDTLS_ECDH_C
47 void ecdh_valid_param( )
49 TEST_VALID_PARAM( mbedtls_ecdh_free( NULL ) );
53 /* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
54 void ecdh_invalid_param( )
56 mbedtls_ecp_group grp;
57 mbedtls_ecdh_context ctx;
60 mbedtls_ecp_keypair kp;
62 unsigned char buf[42] = { 0 };
63 const unsigned char *buf_null = NULL;
64 size_t const buflen = sizeof( buf );
65 int invalid_side = 42;
66 mbedtls_ecp_group_id valid_grp = MBEDTLS_ECP_DP_SECP192R1;
68 TEST_INVALID_PARAM( mbedtls_ecdh_init( NULL ) );
70 #if defined(MBEDTLS_ECP_RESTARTABLE)
71 TEST_INVALID_PARAM( mbedtls_ecdh_enable_restart( NULL ) );
72 #endif /* MBEDTLS_ECP_RESTARTABLE */
74 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
75 mbedtls_ecdh_gen_public( NULL, &m, &P,
76 rnd_std_rand, NULL ) );
77 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
78 mbedtls_ecdh_gen_public( &grp, NULL, &P,
79 rnd_std_rand, NULL ) );
80 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
81 mbedtls_ecdh_gen_public( &grp, &m, NULL,
82 rnd_std_rand, NULL ) );
83 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
84 mbedtls_ecdh_gen_public( &grp, &m, &P,
87 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
88 mbedtls_ecdh_compute_shared( NULL, &m, &P, &m,
89 rnd_std_rand, NULL ) );
90 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
91 mbedtls_ecdh_compute_shared( &grp, NULL, &P, &m,
92 rnd_std_rand, NULL ) );
93 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
94 mbedtls_ecdh_compute_shared( &grp, &m, NULL, &m,
95 rnd_std_rand, NULL ) );
96 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
97 mbedtls_ecdh_compute_shared( &grp, &m, &P, NULL,
98 rnd_std_rand, NULL ) );
100 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
101 mbedtls_ecdh_setup( NULL, valid_grp ) );
103 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
104 mbedtls_ecdh_make_params( NULL, &olen,
106 rnd_std_rand, NULL ) );
107 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
108 mbedtls_ecdh_make_params( &ctx, NULL,
110 rnd_std_rand, NULL ) );
111 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
112 mbedtls_ecdh_make_params( &ctx, &olen,
114 rnd_std_rand, NULL ) );
115 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
116 mbedtls_ecdh_make_params( &ctx, &olen,
120 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
121 mbedtls_ecdh_read_params( NULL,
122 (const unsigned char**) &buf,
124 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
125 mbedtls_ecdh_read_params( &ctx, &buf_null,
127 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
128 mbedtls_ecdh_read_params( &ctx, NULL, buf ) );
129 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
130 mbedtls_ecdh_read_params( &ctx,
131 (const unsigned char**) &buf,
134 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
135 mbedtls_ecdh_get_params( NULL, &kp,
136 MBEDTLS_ECDH_OURS ) );
137 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
138 mbedtls_ecdh_get_params( &ctx, NULL,
139 MBEDTLS_ECDH_OURS ) );
140 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
141 mbedtls_ecdh_get_params( &ctx, &kp,
144 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
145 mbedtls_ecdh_make_public( NULL, &olen,
149 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
150 mbedtls_ecdh_make_public( &ctx, NULL,
154 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
155 mbedtls_ecdh_make_public( &ctx, &olen,
159 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
160 mbedtls_ecdh_make_public( &ctx, &olen,
165 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
166 mbedtls_ecdh_read_public( NULL, buf, buflen ) );
167 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
168 mbedtls_ecdh_read_public( &ctx, NULL, buflen ) );
170 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
171 mbedtls_ecdh_calc_secret( NULL, &olen, buf, buflen,
174 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
175 mbedtls_ecdh_calc_secret( &ctx, NULL, buf, buflen,
178 TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
179 mbedtls_ecdh_calc_secret( &ctx, &olen, NULL, buflen,
189 void ecdh_primitive_random( int id )
191 mbedtls_ecp_group grp;
192 mbedtls_ecp_point qA, qB;
193 mbedtls_mpi dA, dB, zA, zB;
194 rnd_pseudo_info rnd_info;
196 mbedtls_ecp_group_init( &grp );
197 mbedtls_ecp_point_init( &qA ); mbedtls_ecp_point_init( &qB );
198 mbedtls_mpi_init( &dA ); mbedtls_mpi_init( &dB );
199 mbedtls_mpi_init( &zA ); mbedtls_mpi_init( &zB );
200 memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
202 TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
204 TEST_ASSERT( mbedtls_ecdh_gen_public( &grp, &dA, &qA, &rnd_pseudo_rand, &rnd_info )
206 TEST_ASSERT( mbedtls_ecdh_gen_public( &grp, &dB, &qB, &rnd_pseudo_rand, &rnd_info )
208 TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zA, &qB, &dA,
209 &rnd_pseudo_rand, &rnd_info ) == 0 );
210 TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zB, &qA, &dB,
213 TEST_ASSERT( mbedtls_mpi_cmp_mpi( &zA, &zB ) == 0 );
216 mbedtls_ecp_group_free( &grp );
217 mbedtls_ecp_point_free( &qA ); mbedtls_ecp_point_free( &qB );
218 mbedtls_mpi_free( &dA ); mbedtls_mpi_free( &dB );
219 mbedtls_mpi_free( &zA ); mbedtls_mpi_free( &zB );
224 void ecdh_primitive_testvec( int id, data_t * rnd_buf_A, char * xA_str,
225 char * yA_str, data_t * rnd_buf_B,
226 char * xB_str, char * yB_str, char * z_str )
228 mbedtls_ecp_group grp;
229 mbedtls_ecp_point qA, qB;
230 mbedtls_mpi dA, dB, zA, zB, check;
231 rnd_buf_info rnd_info_A, rnd_info_B;
233 mbedtls_ecp_group_init( &grp );
234 mbedtls_ecp_point_init( &qA ); mbedtls_ecp_point_init( &qB );
235 mbedtls_mpi_init( &dA ); mbedtls_mpi_init( &dB );
236 mbedtls_mpi_init( &zA ); mbedtls_mpi_init( &zB ); mbedtls_mpi_init( &check );
238 TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
240 rnd_info_A.buf = rnd_buf_A->x;
241 rnd_info_A.length = rnd_buf_A->len;
243 /* Fix rnd_buf_A->x by shifting it left if necessary */
244 if( grp.nbits % 8 != 0 )
246 unsigned char shift = 8 - ( grp.nbits % 8 );
249 for( i = 0; i < rnd_info_A.length - 1; i++ )
250 rnd_buf_A->x[i] = rnd_buf_A->x[i] << shift
251 | rnd_buf_A->x[i+1] >> ( 8 - shift );
253 rnd_buf_A->x[rnd_info_A.length-1] <<= shift;
256 rnd_info_B.buf = rnd_buf_B->x;
257 rnd_info_B.length = rnd_buf_B->len;
259 /* Fix rnd_buf_B->x by shifting it left if necessary */
260 if( grp.nbits % 8 != 0 )
262 unsigned char shift = 8 - ( grp.nbits % 8 );
265 for( i = 0; i < rnd_info_B.length - 1; i++ )
266 rnd_buf_B->x[i] = rnd_buf_B->x[i] << shift
267 | rnd_buf_B->x[i+1] >> ( 8 - shift );
269 rnd_buf_B->x[rnd_info_B.length-1] <<= shift;
272 TEST_ASSERT( mbedtls_ecdh_gen_public( &grp, &dA, &qA,
273 rnd_buffer_rand, &rnd_info_A ) == 0 );
274 TEST_ASSERT( ! mbedtls_ecp_is_zero( &qA ) );
275 TEST_ASSERT( mbedtls_mpi_read_string( &check, 16, xA_str ) == 0 );
276 TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qA.X, &check ) == 0 );
277 TEST_ASSERT( mbedtls_mpi_read_string( &check, 16, yA_str ) == 0 );
278 TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qA.Y, &check ) == 0 );
280 TEST_ASSERT( mbedtls_ecdh_gen_public( &grp, &dB, &qB,
281 rnd_buffer_rand, &rnd_info_B ) == 0 );
282 TEST_ASSERT( ! mbedtls_ecp_is_zero( &qB ) );
283 TEST_ASSERT( mbedtls_mpi_read_string( &check, 16, xB_str ) == 0 );
284 TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qB.X, &check ) == 0 );
285 TEST_ASSERT( mbedtls_mpi_read_string( &check, 16, yB_str ) == 0 );
286 TEST_ASSERT( mbedtls_mpi_cmp_mpi( &qB.Y, &check ) == 0 );
288 TEST_ASSERT( mbedtls_mpi_read_string( &check, 16, z_str ) == 0 );
289 TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zA, &qB, &dA, NULL, NULL ) == 0 );
290 TEST_ASSERT( mbedtls_mpi_cmp_mpi( &zA, &check ) == 0 );
291 TEST_ASSERT( mbedtls_ecdh_compute_shared( &grp, &zB, &qA, &dB, NULL, NULL ) == 0 );
292 TEST_ASSERT( mbedtls_mpi_cmp_mpi( &zB, &check ) == 0 );
295 mbedtls_ecp_group_free( &grp );
296 mbedtls_ecp_point_free( &qA ); mbedtls_ecp_point_free( &qB );
297 mbedtls_mpi_free( &dA ); mbedtls_mpi_free( &dB );
298 mbedtls_mpi_free( &zA ); mbedtls_mpi_free( &zB ); mbedtls_mpi_free( &check );
303 void ecdh_exchange( int id )
305 mbedtls_ecdh_context srv, cli;
306 unsigned char buf[1000];
307 const unsigned char *vbuf;
309 rnd_pseudo_info rnd_info;
310 unsigned char res_buf[1000];
313 mbedtls_ecdh_init( &srv );
314 mbedtls_ecdh_init( &cli );
315 memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
317 TEST_ASSERT( mbedtls_ecdh_setup( &srv, id ) == 0 );
319 memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
320 TEST_ASSERT( mbedtls_ecdh_make_params( &srv, &len, buf, 1000,
321 &rnd_pseudo_rand, &rnd_info ) == 0 );
322 TEST_ASSERT( mbedtls_ecdh_read_params( &cli, &vbuf, buf + len ) == 0 );
324 memset( buf, 0x00, sizeof( buf ) );
325 TEST_ASSERT( mbedtls_ecdh_make_public( &cli, &len, buf, 1000,
326 &rnd_pseudo_rand, &rnd_info ) == 0 );
327 TEST_ASSERT( mbedtls_ecdh_read_public( &srv, buf, len ) == 0 );
329 TEST_ASSERT( mbedtls_ecdh_calc_secret( &srv, &len, buf, 1000,
330 &rnd_pseudo_rand, &rnd_info ) == 0 );
331 TEST_ASSERT( mbedtls_ecdh_calc_secret( &cli, &res_len, res_buf, 1000,
333 TEST_ASSERT( len == res_len );
334 TEST_ASSERT( memcmp( buf, res_buf, len ) == 0 );
337 mbedtls_ecdh_free( &srv );
338 mbedtls_ecdh_free( &cli );
342 /* BEGIN_CASE depends_on:MBEDTLS_ECP_RESTARTABLE */
343 void ecdh_restart( int id, char *dA_str, char *dB_str, char *z_str,
344 int enable, int max_ops, int min_restart, int max_restart )
347 mbedtls_ecdh_context srv, cli;
348 unsigned char buf[1000];
349 const unsigned char *vbuf;
351 unsigned char z[MBEDTLS_ECP_MAX_BYTES];
353 unsigned char rnd_buf_A[MBEDTLS_ECP_MAX_BYTES];
354 unsigned char rnd_buf_B[MBEDTLS_ECP_MAX_BYTES];
355 rnd_buf_info rnd_info_A, rnd_info_B;
357 mbedtls_ecp_group grp;
359 mbedtls_ecp_group_init( &grp );
360 mbedtls_ecdh_init( &srv );
361 mbedtls_ecdh_init( &cli );
363 z_len = unhexify( z, z_str );
365 rnd_info_A.buf = rnd_buf_A;
366 rnd_info_A.length = unhexify( rnd_buf_A, dA_str );
368 rnd_info_B.buf = rnd_buf_B;
369 rnd_info_B.length = unhexify( rnd_buf_B, dB_str );
371 /* The ECDH context is not guaranteed ot have an mbedtls_ecp_group structure
372 * in every configuration, therefore we load it separately. */
373 TEST_ASSERT( mbedtls_ecp_group_load( &grp, id ) == 0 );
375 /* Otherwise we would have to fix the random buffer,
376 * as in ecdh_primitive_testvec. */
377 TEST_ASSERT( grp.nbits % 8 == 0 );
379 TEST_ASSERT( mbedtls_ecdh_setup( &srv, id ) == 0 );
381 /* set up restart parameters */
382 mbedtls_ecp_set_max_ops( max_ops );
386 mbedtls_ecdh_enable_restart( &srv );
387 mbedtls_ecdh_enable_restart( &cli );
390 /* server writes its paramaters */
391 memset( buf, 0x00, sizeof( buf ) );
396 ret = mbedtls_ecdh_make_params( &srv, &len, buf, sizeof( buf ),
397 rnd_buffer_rand, &rnd_info_A );
398 } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
400 TEST_ASSERT( ret == 0 );
401 TEST_ASSERT( cnt_restart >= min_restart );
402 TEST_ASSERT( cnt_restart <= max_restart );
404 /* client read server params */
406 TEST_ASSERT( mbedtls_ecdh_read_params( &cli, &vbuf, buf + len ) == 0 );
408 /* client writes its key share */
409 memset( buf, 0x00, sizeof( buf ) );
414 ret = mbedtls_ecdh_make_public( &cli, &len, buf, sizeof( buf ),
415 rnd_buffer_rand, &rnd_info_B );
416 } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
418 TEST_ASSERT( ret == 0 );
419 TEST_ASSERT( cnt_restart >= min_restart );
420 TEST_ASSERT( cnt_restart <= max_restart );
422 /* server reads client key share */
423 TEST_ASSERT( mbedtls_ecdh_read_public( &srv, buf, len ) == 0 );
425 /* server computes shared secret */
426 memset( buf, 0, sizeof( buf ) );
431 ret = mbedtls_ecdh_calc_secret( &srv, &len, buf, sizeof( buf ),
433 } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
435 TEST_ASSERT( ret == 0 );
436 TEST_ASSERT( cnt_restart >= min_restart );
437 TEST_ASSERT( cnt_restart <= max_restart );
439 TEST_ASSERT( len == z_len );
440 TEST_ASSERT( memcmp( buf, z, len ) == 0 );
442 /* client computes shared secret */
443 memset( buf, 0, sizeof( buf ) );
448 ret = mbedtls_ecdh_calc_secret( &cli, &len, buf, sizeof( buf ),
450 } while( ret == MBEDTLS_ERR_ECP_IN_PROGRESS && ++cnt_restart );
452 TEST_ASSERT( ret == 0 );
453 TEST_ASSERT( cnt_restart >= min_restart );
454 TEST_ASSERT( cnt_restart <= max_restart );
456 TEST_ASSERT( len == z_len );
457 TEST_ASSERT( memcmp( buf, z, len ) == 0 );
460 mbedtls_ecp_group_free( &grp );
461 mbedtls_ecdh_free( &srv );
462 mbedtls_ecdh_free( &cli );
466 /* BEGIN_CASE depends_on:MBEDTLS_ECDH_LEGACY_CONTEXT */
467 void ecdh_exchange_legacy( int id )
469 mbedtls_ecdh_context srv, cli;
470 unsigned char buf[1000];
471 const unsigned char *vbuf;
474 rnd_pseudo_info rnd_info;
476 mbedtls_ecdh_init( &srv );
477 mbedtls_ecdh_init( &cli );
478 memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
480 TEST_ASSERT( mbedtls_ecp_group_load( &srv.grp, id ) == 0 );
482 memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
483 TEST_ASSERT( mbedtls_ecdh_make_params( &srv, &len, buf, 1000,
484 &rnd_pseudo_rand, &rnd_info ) == 0 );
485 TEST_ASSERT( mbedtls_ecdh_read_params( &cli, &vbuf, buf + len ) == 0 );
487 memset( buf, 0x00, sizeof( buf ) );
488 TEST_ASSERT( mbedtls_ecdh_make_public( &cli, &len, buf, 1000,
489 &rnd_pseudo_rand, &rnd_info ) == 0 );
490 TEST_ASSERT( mbedtls_ecdh_read_public( &srv, buf, len ) == 0 );
492 TEST_ASSERT( mbedtls_ecdh_calc_secret( &srv, &len, buf, 1000,
493 &rnd_pseudo_rand, &rnd_info ) == 0 );
494 TEST_ASSERT( mbedtls_ecdh_calc_secret( &cli, &len, buf, 1000, NULL,
496 TEST_ASSERT( mbedtls_mpi_cmp_mpi( &srv.z, &cli.z ) == 0 );
499 mbedtls_ecdh_free( &srv );
500 mbedtls_ecdh_free( &cli );
505 void ecdh_exchange_calc_secret( int grp_id,
506 data_t *our_private_key,
511 rnd_pseudo_info rnd_info;
512 mbedtls_ecp_keypair our_key;
513 mbedtls_ecp_keypair their_key;
514 mbedtls_ecdh_context ecdh;
515 unsigned char shared_secret[MBEDTLS_ECP_MAX_BYTES];
516 size_t shared_secret_length = 0;
518 memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
519 mbedtls_ecdh_init( &ecdh );
520 mbedtls_ecp_keypair_init( &our_key );
521 mbedtls_ecp_keypair_init( &their_key );
523 if( ! load_private_key( grp_id, our_private_key, &our_key, &rnd_info ) )
525 if( ! load_public_key( grp_id, their_point, &their_key ) )
528 /* Import the keys to the ECDH calculation. */
531 TEST_ASSERT( mbedtls_ecdh_get_params(
532 &ecdh, &our_key, MBEDTLS_ECDH_OURS ) == 0 );
533 TEST_ASSERT( mbedtls_ecdh_get_params(
534 &ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) == 0 );
538 TEST_ASSERT( mbedtls_ecdh_get_params(
539 &ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) == 0 );
540 TEST_ASSERT( mbedtls_ecdh_get_params(
541 &ecdh, &our_key, MBEDTLS_ECDH_OURS ) == 0 );
544 /* Perform the ECDH calculation. */
545 TEST_ASSERT( mbedtls_ecdh_calc_secret(
547 &shared_secret_length,
548 shared_secret, sizeof( shared_secret ),
549 &rnd_pseudo_rand, &rnd_info ) == 0 );
550 TEST_ASSERT( shared_secret_length == expected->len );
551 TEST_ASSERT( memcmp( expected->x, shared_secret,
552 shared_secret_length ) == 0 );
555 mbedtls_ecdh_free( &ecdh );
556 mbedtls_ecp_keypair_free( &our_key );
557 mbedtls_ecp_keypair_free( &their_key );
562 void ecdh_exchange_get_params_fail( int our_grp_id,
563 data_t *our_private_key,
569 rnd_pseudo_info rnd_info;
570 mbedtls_ecp_keypair our_key;
571 mbedtls_ecp_keypair their_key;
572 mbedtls_ecdh_context ecdh;
574 memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
575 mbedtls_ecdh_init( &ecdh );
576 mbedtls_ecp_keypair_init( &our_key );
577 mbedtls_ecp_keypair_init( &their_key );
579 if( ! load_private_key( our_grp_id, our_private_key, &our_key, &rnd_info ) )
581 if( ! load_public_key( their_grp_id, their_point, &their_key ) )
586 TEST_ASSERT( mbedtls_ecdh_get_params(
587 &ecdh, &our_key, MBEDTLS_ECDH_OURS ) == 0 );
588 TEST_ASSERT( mbedtls_ecdh_get_params(
589 &ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) ==
594 TEST_ASSERT( mbedtls_ecdh_get_params(
595 &ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) == 0 );
596 TEST_ASSERT( mbedtls_ecdh_get_params(
597 &ecdh, &our_key, MBEDTLS_ECDH_OURS ) ==
602 mbedtls_ecdh_free( &ecdh );
603 mbedtls_ecp_keypair_free( &our_key );
604 mbedtls_ecp_keypair_free( &their_key );