Lines Matching refs:A
882 int mbedtls_mpi_add_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ) in mbedtls_mpi_add_abs() argument
890 const mbedtls_mpi *T = A; A = X; B = T; in mbedtls_mpi_add_abs()
893 if( X != A ) in mbedtls_mpi_add_abs()
894 MBEDTLS_MPI_CHK( mbedtls_mpi_copy( X, A ) ); in mbedtls_mpi_add_abs()
959 int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ) in mbedtls_mpi_sub_abs() argument
965 if( mbedtls_mpi_cmp_abs( A, B ) < 0 ) in mbedtls_mpi_sub_abs()
976 if( X != A ) in mbedtls_mpi_sub_abs()
977 MBEDTLS_MPI_CHK( mbedtls_mpi_copy( X, A ) ); in mbedtls_mpi_sub_abs()
1002 int mbedtls_mpi_add_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ) in mbedtls_mpi_add_mpi() argument
1004 int ret, s = A->s; in mbedtls_mpi_add_mpi()
1006 if( A->s * B->s < 0 ) in mbedtls_mpi_add_mpi()
1008 if( mbedtls_mpi_cmp_abs( A, B ) >= 0 ) in mbedtls_mpi_add_mpi()
1010 MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( X, A, B ) ); in mbedtls_mpi_add_mpi()
1015 MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( X, B, A ) ); in mbedtls_mpi_add_mpi()
1021 MBEDTLS_MPI_CHK( mbedtls_mpi_add_abs( X, A, B ) ); in mbedtls_mpi_add_mpi()
1033 int mbedtls_mpi_sub_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ) in mbedtls_mpi_sub_mpi() argument
1035 int ret, s = A->s; in mbedtls_mpi_sub_mpi()
1037 if( A->s * B->s > 0 ) in mbedtls_mpi_sub_mpi()
1039 if( mbedtls_mpi_cmp_abs( A, B ) >= 0 ) in mbedtls_mpi_sub_mpi()
1041 MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( X, A, B ) ); in mbedtls_mpi_sub_mpi()
1046 MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( X, B, A ) ); in mbedtls_mpi_sub_mpi()
1052 MBEDTLS_MPI_CHK( mbedtls_mpi_add_abs( X, A, B ) ); in mbedtls_mpi_sub_mpi()
1064 int mbedtls_mpi_add_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b ) in mbedtls_mpi_add_int() argument
1074 return( mbedtls_mpi_add_mpi( X, A, &_B ) ); in mbedtls_mpi_add_int()
1080 int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b ) in mbedtls_mpi_sub_int() argument
1090 return( mbedtls_mpi_sub_mpi( X, A, &_B ) ); in mbedtls_mpi_sub_int()
1168 int mbedtls_mpi_mul_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ) in mbedtls_mpi_mul_mpi() argument
1176 if( X == A ) { MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &TA, A ) ); A = &TA; } in mbedtls_mpi_mul_mpi()
1179 for( i = A->n; i > 0; i-- ) in mbedtls_mpi_mul_mpi()
1180 if( A->p[i - 1] != 0 ) in mbedtls_mpi_mul_mpi()
1191 mpi_mul_hlp( i - 1, A->p, X->p + j - 1, B->p[j - 1] ); in mbedtls_mpi_mul_mpi()
1193 X->s = A->s * B->s; in mbedtls_mpi_mul_mpi()
1205 int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b ) in mbedtls_mpi_mul_int() argument
1215 return( mbedtls_mpi_mul_mpi( X, A, &_B ) ); in mbedtls_mpi_mul_int()
1317 int mbedtls_mpi_div_mpi( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B… in mbedtls_mpi_div_mpi() argument
1329 if( mbedtls_mpi_cmp_abs( A, B ) < 0 ) in mbedtls_mpi_div_mpi()
1332 if( R != NULL ) MBEDTLS_MPI_CHK( mbedtls_mpi_copy( R, A ) ); in mbedtls_mpi_div_mpi()
1336 MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &X, A ) ); in mbedtls_mpi_div_mpi()
1340 MBEDTLS_MPI_CHK( mbedtls_mpi_grow( &Z, A->n + 2 ) ); in mbedtls_mpi_div_mpi()
1408 Q->s = A->s * B->s; in mbedtls_mpi_div_mpi()
1414 X.s = A->s; in mbedtls_mpi_div_mpi()
1432 int mbedtls_mpi_div_int( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, mbedtls_mpi_sint b ) in mbedtls_mpi_div_int() argument
1442 return( mbedtls_mpi_div_mpi( Q, R, A, &_B ) ); in mbedtls_mpi_div_int()
1448 int mbedtls_mpi_mod_mpi( mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B ) in mbedtls_mpi_mod_mpi() argument
1455 MBEDTLS_MPI_CHK( mbedtls_mpi_div_mpi( NULL, R, A, B ) ); in mbedtls_mpi_mod_mpi()
1471 int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_sint b ) in mbedtls_mpi_mod_int() argument
1493 *r = A->p[0] & 1; in mbedtls_mpi_mod_int()
1500 for( i = A->n, y = 0; i > 0; i-- ) in mbedtls_mpi_mod_int()
1502 x = A->p[i - 1]; in mbedtls_mpi_mod_int()
1517 if( A->s < 0 && y != 0 ) in mbedtls_mpi_mod_int()
1545 static int mpi_montmul( mbedtls_mpi *A, const mbedtls_mpi *B, const mbedtls_mpi *N, mbedtls_mpi_uin… in mpi_montmul() argument
1565 u0 = A->p[i]; in mpi_montmul()
1574 memcpy( A->p, d, ( n + 1 ) * ciL ); in mpi_montmul()
1576 if( mbedtls_mpi_cmp_abs( A, N ) >= 0 ) in mpi_montmul()
1577 mpi_sub_hlp( n, N->p, A->p ); in mpi_montmul()
1580 mpi_sub_hlp( n, A->p, T->p ); in mpi_montmul()
1588 static int mpi_montred( mbedtls_mpi *A, const mbedtls_mpi *N, mbedtls_mpi_uint mm, const mbedtls_mp… in mpi_montred() argument
1596 return( mpi_montmul( A, &U, N, mm, T ) ); in mpi_montred()
1602 int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *E, const mbedtls_… in mbedtls_mpi_exp_mod() argument
1642 neg = ( A->s == -1 ); in mbedtls_mpi_exp_mod()
1645 MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &Apos, A ) ); in mbedtls_mpi_exp_mod()
1647 A = &Apos; in mbedtls_mpi_exp_mod()
1668 if( mbedtls_mpi_cmp_mpi( A, N ) >= 0 ) in mbedtls_mpi_exp_mod()
1669 MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &W[1], A, N ) ); in mbedtls_mpi_exp_mod()
1671 MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &W[1], A ) ); in mbedtls_mpi_exp_mod()
1810 int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B ) in mbedtls_mpi_gcd() argument
1818 MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &TA, A ) ); in mbedtls_mpi_gcd()
1886 int mbedtls_mpi_inv_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *N ) in mbedtls_mpi_inv_mod() argument
1898 MBEDTLS_MPI_CHK( mbedtls_mpi_gcd( &G, A, N ) ); in mbedtls_mpi_inv_mod()
1906 MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &TA, A, N ) ); in mbedtls_mpi_inv_mod()
2047 mbedtls_mpi W, R, T, A, RR; in mpi_miller_rabin() local
2049 mbedtls_mpi_init( &W ); mbedtls_mpi_init( &R ); mbedtls_mpi_init( &T ); mbedtls_mpi_init( &A ); in mpi_miller_rabin()
2074 MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &A, X->n * ciL, f_rng, p_rng ) ); in mpi_miller_rabin()
2076 if( mbedtls_mpi_cmp_mpi( &A, &W ) >= 0 ) in mpi_miller_rabin()
2078 j = mbedtls_mpi_bitlen( &A ) - mbedtls_mpi_bitlen( &W ); in mpi_miller_rabin()
2079 MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &A, j + 1 ) ); in mpi_miller_rabin()
2081 A.p[0] |= 3; in mpi_miller_rabin()
2085 MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &A, X->n * ciL, f_rng, p_rng ) ); in mpi_miller_rabin()
2087 j = mbedtls_mpi_bitlen( &A ); in mpi_miller_rabin()
2090 MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &A, j - k ) ); in mpi_miller_rabin()
2097 } while ( mbedtls_mpi_cmp_mpi( &A, &W ) >= 0 || in mpi_miller_rabin()
2098 mbedtls_mpi_cmp_int( &A, 1 ) <= 0 ); in mpi_miller_rabin()
2103 MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &A, &A, &R, X, &RR ) ); in mpi_miller_rabin()
2105 if( mbedtls_mpi_cmp_mpi( &A, &W ) == 0 || in mpi_miller_rabin()
2106 mbedtls_mpi_cmp_int( &A, 1 ) == 0 ) in mpi_miller_rabin()
2110 while( j < s && mbedtls_mpi_cmp_mpi( &A, &W ) != 0 ) in mpi_miller_rabin()
2115 MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &T, &A, &A ) ); in mpi_miller_rabin()
2116 MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &A, &T, X ) ); in mpi_miller_rabin()
2118 if( mbedtls_mpi_cmp_int( &A, 1 ) == 0 ) in mpi_miller_rabin()
2127 if( mbedtls_mpi_cmp_mpi( &A, &W ) != 0 || in mpi_miller_rabin()
2128 mbedtls_mpi_cmp_int( &A, 1 ) == 0 ) in mpi_miller_rabin()
2136 mbedtls_mpi_free( &W ); mbedtls_mpi_free( &R ); mbedtls_mpi_free( &T ); mbedtls_mpi_free( &A ); in mpi_miller_rabin()
2285 mbedtls_mpi A, E, N, X, Y, U, V; in mbedtls_mpi_self_test() local
2287 mbedtls_mpi_init( &A ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &N ); mbedtls_mpi_init( &X ); in mbedtls_mpi_self_test()
2290 MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &A, 16, in mbedtls_mpi_self_test()
2307 MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &X, &A, &N ) ); in mbedtls_mpi_self_test()
2333 MBEDTLS_MPI_CHK( mbedtls_mpi_div_mpi( &X, &Y, &A, &N ) ); in mbedtls_mpi_self_test()
2359 MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &X, &A, &E, &N, NULL ) ); in mbedtls_mpi_self_test()
2381 MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( &X, &A, &N ) ); in mbedtls_mpi_self_test()
2411 MBEDTLS_MPI_CHK( mbedtls_mpi_gcd( &A, &X, &Y ) ); in mbedtls_mpi_self_test()
2413 if( mbedtls_mpi_cmp_int( &A, gcd_pairs[i][2] ) != 0 ) in mbedtls_mpi_self_test()
2431 mbedtls_mpi_free( &A ); mbedtls_mpi_free( &E ); mbedtls_mpi_free( &N ); mbedtls_mpi_free( &X ); in mbedtls_mpi_self_test()