Lines Matching refs:i
76 #define BITS_TO_LIMBS(i) ( (i) / biL + ( (i) % biL != 0 ) ) argument
77 #define CHARS_TO_LIMBS(i) ( (i) / ciL + ( (i) % ciL != 0 ) ) argument
147 size_t i; in mbedtls_mpi_shrink() local
153 for( i = X->n - 1; i > 0; i-- ) in mbedtls_mpi_shrink()
154 if( X->p[i] != 0 ) in mbedtls_mpi_shrink()
156 i++; in mbedtls_mpi_shrink()
158 if( i < nblimbs ) in mbedtls_mpi_shrink()
159 i = nblimbs; in mbedtls_mpi_shrink()
161 if( ( p = (mbedtls_mpi_uint*)mbedtls_calloc( i, ciL ) ) == NULL ) in mbedtls_mpi_shrink()
166 memcpy( p, X->p, i * ciL ); in mbedtls_mpi_shrink()
171 X->n = i; in mbedtls_mpi_shrink()
183 size_t i; in mbedtls_mpi_copy() local
194 for( i = Y->n - 1; i > 0; i-- ) in mbedtls_mpi_copy()
195 if( Y->p[i] != 0 ) in mbedtls_mpi_copy()
197 i++; in mbedtls_mpi_copy()
201 MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, i ) ); in mbedtls_mpi_copy()
204 memcpy( X->p, Y->p, i * ciL ); in mbedtls_mpi_copy()
231 size_t i; in mbedtls_mpi_safe_cond_assign() local
240 for( i = 0; i < Y->n; i++ ) in mbedtls_mpi_safe_cond_assign()
241 X->p[i] = X->p[i] * ( 1 - assign ) + Y->p[i] * assign; in mbedtls_mpi_safe_cond_assign()
243 for( ; i < X->n; i++ ) in mbedtls_mpi_safe_cond_assign()
244 X->p[i] *= ( 1 - assign ); in mbedtls_mpi_safe_cond_assign()
259 size_t i; in mbedtls_mpi_safe_cond_swap() local
276 for( i = 0; i < X->n; i++ ) in mbedtls_mpi_safe_cond_swap()
278 tmp = X->p[i]; in mbedtls_mpi_safe_cond_swap()
279 X->p[i] = X->p[i] * ( 1 - swap ) + Y->p[i] * swap; in mbedtls_mpi_safe_cond_swap()
280 Y->p[i] = Y->p[i] * ( 1 - swap ) + tmp * swap; in mbedtls_mpi_safe_cond_swap()
349 size_t i, j, count = 0; in mbedtls_mpi_lsb() local
351 for( i = 0; i < X->n; i++ ) in mbedtls_mpi_lsb()
353 if( ( ( X->p[i] >> j ) & 1 ) != 0 ) in mbedtls_mpi_lsb()
382 size_t i, j; in mbedtls_mpi_bitlen() local
387 for( i = X->n - 1; i > 0; i-- ) in mbedtls_mpi_bitlen()
388 if( X->p[i] != 0 ) in mbedtls_mpi_bitlen()
391 j = biL - mbedtls_clz( X->p[i] ); in mbedtls_mpi_bitlen()
393 return( ( i * biL ) + j ); in mbedtls_mpi_bitlen()
427 size_t i, j, slen, n; in mbedtls_mpi_read_string() local
448 for( i = slen, j = 0; i > 0; i--, j++ ) in mbedtls_mpi_read_string()
450 if( i == 1 && s[i - 1] == '-' ) in mbedtls_mpi_read_string()
456 MBEDTLS_MPI_CHK( mpi_get_digit( &d, radix, s[i - 1] ) ); in mbedtls_mpi_read_string()
464 for( i = 0; i < slen; i++ ) in mbedtls_mpi_read_string()
466 if( i == 0 && s[i] == '-' ) in mbedtls_mpi_read_string()
472 MBEDTLS_MPI_CHK( mpi_get_digit( &d, radix, s[i] ) ); in mbedtls_mpi_read_string()
554 size_t i, j, k; in mbedtls_mpi_write_string() local
556 for( i = X->n, k = 0; i > 0; i-- ) in mbedtls_mpi_write_string()
560 c = ( X->p[i - 1] >> ( ( j - 1 ) << 3) ) & 0xFF; in mbedtls_mpi_write_string()
562 if( c == 0 && k == 0 && ( i + j ) != 2 ) in mbedtls_mpi_write_string()
670 size_t i, j, n; in mbedtls_mpi_read_binary() local
679 for( i = buflen, j = 0; i > n; i--, j++ ) in mbedtls_mpi_read_binary()
680 X->p[j / ciL] |= ((mbedtls_mpi_uint) buf[i - 1]) << ((j % ciL) << 3); in mbedtls_mpi_read_binary()
692 size_t i, j, n; in mbedtls_mpi_write_binary() local
701 for( i = buflen - 1, j = 0; n > 0; i--, j++, n-- ) in mbedtls_mpi_write_binary()
702 buf[i] = (unsigned char)( X->p[j / ciL] >> ((j % ciL) << 3) ); in mbedtls_mpi_write_binary()
713 size_t i, v0, t1; in mbedtls_mpi_shift_l() local
719 i = mbedtls_mpi_bitlen( X ) + count; in mbedtls_mpi_shift_l()
721 if( X->n * biL < i ) in mbedtls_mpi_shift_l()
722 MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, BITS_TO_LIMBS( i ) ) ); in mbedtls_mpi_shift_l()
731 for( i = X->n; i > v0; i-- ) in mbedtls_mpi_shift_l()
732 X->p[i - 1] = X->p[i - v0 - 1]; in mbedtls_mpi_shift_l()
734 for( ; i > 0; i-- ) in mbedtls_mpi_shift_l()
735 X->p[i - 1] = 0; in mbedtls_mpi_shift_l()
743 for( i = v0; i < X->n; i++ ) in mbedtls_mpi_shift_l()
745 r1 = X->p[i] >> (biL - t1); in mbedtls_mpi_shift_l()
746 X->p[i] <<= t1; in mbedtls_mpi_shift_l()
747 X->p[i] |= r0; in mbedtls_mpi_shift_l()
762 size_t i, v0, v1; in mbedtls_mpi_shift_r() local
776 for( i = 0; i < X->n - v0; i++ ) in mbedtls_mpi_shift_r()
777 X->p[i] = X->p[i + v0]; in mbedtls_mpi_shift_r()
779 for( ; i < X->n; i++ ) in mbedtls_mpi_shift_r()
780 X->p[i] = 0; in mbedtls_mpi_shift_r()
788 for( i = X->n; i > 0; i-- ) in mbedtls_mpi_shift_r()
790 r1 = X->p[i - 1] << (biL - v1); in mbedtls_mpi_shift_r()
791 X->p[i - 1] >>= v1; in mbedtls_mpi_shift_r()
792 X->p[i - 1] |= r0; in mbedtls_mpi_shift_r()
805 size_t i, j; in mbedtls_mpi_cmp_abs() local
807 for( i = X->n; i > 0; i-- ) in mbedtls_mpi_cmp_abs()
808 if( X->p[i - 1] != 0 ) in mbedtls_mpi_cmp_abs()
815 if( i == 0 && j == 0 ) in mbedtls_mpi_cmp_abs()
818 if( i > j ) return( 1 ); in mbedtls_mpi_cmp_abs()
819 if( j > i ) return( -1 ); in mbedtls_mpi_cmp_abs()
821 for( ; i > 0; i-- ) in mbedtls_mpi_cmp_abs()
823 if( X->p[i - 1] > Y->p[i - 1] ) return( 1 ); in mbedtls_mpi_cmp_abs()
824 if( X->p[i - 1] < Y->p[i - 1] ) return( -1 ); in mbedtls_mpi_cmp_abs()
835 size_t i, j; in mbedtls_mpi_cmp_mpi() local
837 for( i = X->n; i > 0; i-- ) in mbedtls_mpi_cmp_mpi()
838 if( X->p[i - 1] != 0 ) in mbedtls_mpi_cmp_mpi()
845 if( i == 0 && j == 0 ) in mbedtls_mpi_cmp_mpi()
848 if( i > j ) return( X->s ); in mbedtls_mpi_cmp_mpi()
849 if( j > i ) return( -Y->s ); in mbedtls_mpi_cmp_mpi()
854 for( ; i > 0; i-- ) in mbedtls_mpi_cmp_mpi()
856 if( X->p[i - 1] > Y->p[i - 1] ) return( X->s ); in mbedtls_mpi_cmp_mpi()
857 if( X->p[i - 1] < Y->p[i - 1] ) return( -X->s ); in mbedtls_mpi_cmp_mpi()
885 size_t i, j; in mbedtls_mpi_add_abs() local
912 for( i = 0; i < j; i++, o++, p++ ) in mbedtls_mpi_add_abs()
921 if( i >= X->n ) in mbedtls_mpi_add_abs()
923 MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, i + 1 ) ); in mbedtls_mpi_add_abs()
924 p = X->p + i; in mbedtls_mpi_add_abs()
927 *p += c; c = ( *p < c ); i++; p++; in mbedtls_mpi_add_abs()
940 size_t i; in mpi_sub_hlp() local
943 for( i = c = 0; i < n; i++, s++, d++ ) in mpi_sub_hlp()
952 c = z; i++; d++; in mpi_sub_hlp()
1104 void mpi_mul_hlp( size_t i, mbedtls_mpi_uint *s, mbedtls_mpi_uint *d, mbedtls_mpi_uint b ) in mpi_mul_hlp() argument
1109 for( ; i >= 8; i -= 8 ) in mpi_mul_hlp()
1116 for( ; i > 0; i-- ) in mpi_mul_hlp()
1123 for( ; i >= 16; i -= 16 ) in mpi_mul_hlp()
1138 for( ; i >= 8; i -= 8 ) in mpi_mul_hlp()
1149 for( ; i > 0; i-- ) in mpi_mul_hlp()
1171 size_t i, j; in mbedtls_mpi_mul_mpi() local
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()
1187 MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, i + j ) ); in mbedtls_mpi_mul_mpi()
1190 for( i++; j > 0; j-- ) 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()
1320 size_t i, n, t, k; in mbedtls_mpi_div_mpi() local
1365 for( i = n; i > t ; i-- ) in mbedtls_mpi_div_mpi()
1367 if( X.p[i] >= Y.p[t] ) in mbedtls_mpi_div_mpi()
1368 Z.p[i - t - 1] = ~0; in mbedtls_mpi_div_mpi()
1371 Z.p[i - t - 1] = mbedtls_int_div_int( X.p[i], X.p[i - 1], in mbedtls_mpi_div_mpi()
1375 Z.p[i - t - 1]++; in mbedtls_mpi_div_mpi()
1378 Z.p[i - t - 1]--; in mbedtls_mpi_div_mpi()
1383 MBEDTLS_MPI_CHK( mbedtls_mpi_mul_int( &T1, &T1, Z.p[i - t - 1] ) ); in mbedtls_mpi_div_mpi()
1386 T2.p[0] = ( i < 2 ) ? 0 : X.p[i - 2]; in mbedtls_mpi_div_mpi()
1387 T2.p[1] = ( i < 1 ) ? 0 : X.p[i - 1]; in mbedtls_mpi_div_mpi()
1388 T2.p[2] = X.p[i]; in mbedtls_mpi_div_mpi()
1392 MBEDTLS_MPI_CHK( mbedtls_mpi_mul_int( &T1, &Y, Z.p[i - t - 1] ) ); in mbedtls_mpi_div_mpi()
1393 MBEDTLS_MPI_CHK( mbedtls_mpi_shift_l( &T1, biL * ( i - t - 1 ) ) ); in mbedtls_mpi_div_mpi()
1399 MBEDTLS_MPI_CHK( mbedtls_mpi_shift_l( &T1, biL * ( i - t - 1 ) ) ); in mbedtls_mpi_div_mpi()
1401 Z.p[i - t - 1]--; in mbedtls_mpi_div_mpi()
1473 size_t i; in mbedtls_mpi_mod_int() local
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()
1531 unsigned int i; in mpi_montg_init() local
1536 for( i = biL; i >= 8; i /= 2 ) in mpi_montg_init()
1548 size_t i, n, m; in mpi_montmul() local
1560 for( i = 0; i < n; i++ ) in mpi_montmul()
1565 u0 = A->p[i]; in mpi_montmul()
1606 size_t i, j, nblimbs; in mbedtls_mpi_exp_mod() local
1626 i = mbedtls_mpi_bitlen( E ); in mbedtls_mpi_exp_mod()
1628 wsize = ( i > 671 ) ? 6 : ( i > 239 ) ? 5 : in mbedtls_mpi_exp_mod()
1629 ( i > 79 ) ? 4 : ( i > 23 ) ? 3 : 1; in mbedtls_mpi_exp_mod()
1691 for( i = 0; i < wsize - 1; i++ ) in mbedtls_mpi_exp_mod()
1697 for( i = j + 1; i < ( one << wsize ); i++ ) in mbedtls_mpi_exp_mod()
1699 MBEDTLS_MPI_CHK( mbedtls_mpi_grow( &W[i], N->n + 1 ) ); in mbedtls_mpi_exp_mod()
1700 MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &W[i], &W[i - 1] ) ); in mbedtls_mpi_exp_mod()
1702 MBEDTLS_MPI_CHK( mpi_montmul( &W[i], &W[1], N, mm, &T ) ); in mbedtls_mpi_exp_mod()
1756 for( i = 0; i < wsize; i++ ) in mbedtls_mpi_exp_mod()
1773 for( i = 0; i < nbits; i++ ) in mbedtls_mpi_exp_mod()
1796 for( i = ( one << ( wsize - 1 ) ); i < ( one << wsize ); i++ ) in mbedtls_mpi_exp_mod()
1797 mbedtls_mpi_free( &W[i] ); in mbedtls_mpi_exp_mod()
2017 size_t i; in mpi_check_small_factors() local
2023 for( i = 0; small_prime[i] > 0; i++ ) in mpi_check_small_factors()
2025 if( mbedtls_mpi_cmp_int( X, small_prime[i] ) <= 0 ) in mpi_check_small_factors()
2028 MBEDTLS_MPI_CHK( mbedtls_mpi_mod_int( &r, X, small_prime[i] ) ); in mpi_check_small_factors()
2046 size_t i, j, k, n, s; in mpi_miller_rabin() local
2061 i = mbedtls_mpi_bitlen( X ); in mpi_miller_rabin()
2065 n = ( ( i >= 1300 ) ? 2 : ( i >= 850 ) ? 3 : in mpi_miller_rabin()
2066 ( i >= 650 ) ? 4 : ( i >= 350 ) ? 8 : in mpi_miller_rabin()
2067 ( i >= 250 ) ? 12 : ( i >= 150 ) ? 18 : 27 ); in mpi_miller_rabin()
2069 for( i = 0; i < n; i++ ) in mpi_miller_rabin()
2284 int ret, i; in mbedtls_mpi_self_test() local
2406 for( i = 0; i < GCD_PAIR_COUNT; i++ ) in mbedtls_mpi_self_test()
2408 MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &X, gcd_pairs[i][0] ) ); in mbedtls_mpi_self_test()
2409 MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &Y, gcd_pairs[i][1] ) ); in mbedtls_mpi_self_test()
2413 if( mbedtls_mpi_cmp_int( &A, gcd_pairs[i][2] ) != 0 ) in mbedtls_mpi_self_test()
2416 mbedtls_printf( "failed at %d\n", i ); in mbedtls_mpi_self_test()