Lines Matching refs:ctx
28 mbedtls_rsa_context ctx;
34 mbedtls_rsa_init( &ctx, padding_mode, 0 );
42 ctx.len = mod / 8;
43 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
44 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
45 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
46 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
48 TEST_ASSERT( mbedtls_mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
49 TEST_ASSERT( mbedtls_mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
51 TEST_ASSERT( mbedtls_mpi_gcd( &G, &ctx.E, &H ) == 0 );
52 TEST_ASSERT( mbedtls_mpi_inv_mod( &ctx.D , &ctx.E, &H ) == 0 );
53 TEST_ASSERT( mbedtls_mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
54 TEST_ASSERT( mbedtls_mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
55 TEST_ASSERT( mbedtls_mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
57 TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
64 …TEST_ASSERT( mbedtls_rsa_pkcs1_sign( &ctx, &rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, diges…
67 hexify( output_str, output, ctx.len );
74 mbedtls_rsa_free( &ctx );
86 mbedtls_rsa_context ctx;
89 mbedtls_rsa_init( &ctx, padding_mode, 0 );
94 ctx.len = mod / 8;
95 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
96 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
98 TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
106 …TEST_ASSERT( mbedtls_rsa_pkcs1_verify( &ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, digest, 0, hash_resul…
109 mbedtls_rsa_free( &ctx );
125 mbedtls_rsa_context ctx;
131 mbedtls_rsa_init( &ctx, padding_mode, 0 );
139 ctx.len = mod / 8;
140 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
141 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
142 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
143 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
145 TEST_ASSERT( mbedtls_mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
146 TEST_ASSERT( mbedtls_mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
148 TEST_ASSERT( mbedtls_mpi_gcd( &G, &ctx.E, &H ) == 0 );
149 TEST_ASSERT( mbedtls_mpi_inv_mod( &ctx.D , &ctx.E, &H ) == 0 );
150 TEST_ASSERT( mbedtls_mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
151 TEST_ASSERT( mbedtls_mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
152 TEST_ASSERT( mbedtls_mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
154 TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
159 …TEST_ASSERT( mbedtls_rsa_pkcs1_sign( &ctx, &rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, MBEDT…
161 hexify( output_str, output, ctx.len );
171 TEST_ASSERT( mbedtls_rsa_rsaes_pkcs1_v15_encrypt( &ctx,
175 hexify( output_str, output, ctx.len );
182 mbedtls_rsa_free( &ctx );
196 mbedtls_rsa_context ctx;
199 mbedtls_rsa_init( &ctx, padding_mode, 0 );
205 ctx.len = mod / 8;
206 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
207 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
209 TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
215 …TEST_ASSERT( mbedtls_rsa_pkcs1_verify( &ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_NONE, hash…
222 TEST_ASSERT( mbedtls_rsa_rsaes_pkcs1_v15_decrypt( &ctx,
234 mbedtls_rsa_free( &ctx );
246 mbedtls_rsa_context ctx;
252 mbedtls_rsa_init( &ctx, padding_mode, 0 );
257 ctx.len = mod / 8;
258 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
259 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
261 TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
265 …TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PUBLIC, msg…
268 hexify( output_str, output, ctx.len );
274 mbedtls_rsa_free( &ctx );
287 mbedtls_rsa_context ctx;
290 mbedtls_rsa_init( &ctx, padding_mode, 0 );
295 ctx.len = mod / 8;
296 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
297 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
299 TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
303 …TEST_ASSERT( mbedtls_rsa_pkcs1_encrypt( &ctx, &rnd_zero_rand, NULL, MBEDTLS_RSA_PUBLIC, msg_len, m…
306 hexify( output_str, output, ctx.len );
312 mbedtls_rsa_free( &ctx );
325 mbedtls_rsa_context ctx;
331 mbedtls_rsa_init( &ctx, padding_mode, 0 );
338 ctx.len = mod / 8;
339 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
340 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
341 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
342 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
344 TEST_ASSERT( mbedtls_mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
345 TEST_ASSERT( mbedtls_mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
347 TEST_ASSERT( mbedtls_mpi_gcd( &G, &ctx.E, &H ) == 0 );
348 TEST_ASSERT( mbedtls_mpi_inv_mod( &ctx.D , &ctx.E, &H ) == 0 );
349 TEST_ASSERT( mbedtls_mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
350 TEST_ASSERT( mbedtls_mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
351 TEST_ASSERT( mbedtls_mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
353 TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
358 …TEST_ASSERT( mbedtls_rsa_pkcs1_decrypt( &ctx, rnd_pseudo_rand, &rnd_info, MBEDTLS_RSA_PRIVATE, &ou…
361 hexify( output_str, output, ctx.len );
368 mbedtls_rsa_free( &ctx );
379 mbedtls_rsa_context ctx, ctx2; /* Also test mbedtls_rsa_copy() while at it */
381 mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, 0 );
387 ctx.len = mod / 8;
388 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
389 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
391 TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == 0 );
395 TEST_ASSERT( mbedtls_rsa_public( &ctx, message_str, output ) == result );
398 hexify( output_str, output, ctx.len );
404 TEST_ASSERT( mbedtls_rsa_copy( &ctx2, &ctx ) == 0 );
406 mbedtls_rsa_free( &ctx );
421 mbedtls_rsa_free( &ctx );
434 mbedtls_rsa_context ctx, ctx2; /* Also test mbedtls_rsa_copy() while at it */
440 mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, 0 );
446 ctx.len = mod / 8;
447 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
448 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
449 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
450 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
452 TEST_ASSERT( mbedtls_mpi_sub_int( &P1, &ctx.P, 1 ) == 0 );
453 TEST_ASSERT( mbedtls_mpi_sub_int( &Q1, &ctx.Q, 1 ) == 0 );
455 TEST_ASSERT( mbedtls_mpi_gcd( &G, &ctx.E, &H ) == 0 );
456 TEST_ASSERT( mbedtls_mpi_inv_mod( &ctx.D , &ctx.E, &H ) == 0 );
457 TEST_ASSERT( mbedtls_mpi_mod_mpi( &ctx.DP, &ctx.D, &P1 ) == 0 );
458 TEST_ASSERT( mbedtls_mpi_mod_mpi( &ctx.DQ, &ctx.D, &Q1 ) == 0 );
459 TEST_ASSERT( mbedtls_mpi_inv_mod( &ctx.QP, &ctx.Q, &ctx.P ) == 0 );
461 TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
470 TEST_ASSERT( mbedtls_rsa_private( &ctx, rnd_pseudo_rand, &rnd_info,
474 hexify( output_str, output, ctx.len );
482 TEST_ASSERT( mbedtls_rsa_copy( &ctx2, &ctx ) == 0 );
484 mbedtls_rsa_free( &ctx );
502 mbedtls_rsa_free( &ctx ); mbedtls_rsa_free( &ctx2 );
509 mbedtls_rsa_context ctx;
510 memset( &ctx, 0x00, sizeof( mbedtls_rsa_context ) );
512 TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == MBEDTLS_ERR_RSA_KEY_CHECK_FAILED );
520 mbedtls_rsa_context ctx;
522 mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, 0 );
526 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
530 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
533 TEST_ASSERT( mbedtls_rsa_check_pubkey( &ctx ) == result );
536 mbedtls_rsa_free( &ctx );
548 mbedtls_rsa_context ctx;
550 mbedtls_rsa_init( &ctx, MBEDTLS_RSA_PKCS_V15, 0 );
552 ctx.len = mod / 8;
555 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.P, radix_P, input_P ) == 0 );
559 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.Q, radix_Q, input_Q ) == 0 );
563 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.N, radix_N, input_N ) == 0 );
567 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.E, radix_E, input_E ) == 0 );
571 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.D, radix_D, input_D ) == 0 );
575 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.DP, radix_DP, input_DP ) == 0 );
579 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.DQ, radix_DQ, input_DQ ) == 0 );
583 TEST_ASSERT( mbedtls_mpi_read_string( &ctx.QP, radix_QP, input_QP ) == 0 );
586 TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == result );
589 mbedtls_rsa_free( &ctx );
664 mbedtls_rsa_context ctx;
675 mbedtls_rsa_init( &ctx, 0, 0 );
677 …TEST_ASSERT( mbedtls_rsa_gen_key( &ctx, mbedtls_ctr_drbg_random, &ctr_drbg, nrbits, exponent ) == …
680 TEST_ASSERT( mbedtls_rsa_check_privkey( &ctx ) == 0 );
681 TEST_ASSERT( mbedtls_mpi_cmp_mpi( &ctx.P, &ctx.Q ) > 0 );
685 mbedtls_rsa_free( &ctx );