ext/lib/crypto/tinycrypt/source/ecc.c
/*
 * Computes modular exponentiation.
 *
 * Side-channel countermeasure: algorithm strengthened against timing attack.
 */
Computes modular exponentiation.
Side-channel countermeasure: algorithm strengthened against timing attack.
Computes modular exponentiation . Side - channel countermeasure : algorithm strengthened against timing attack .
static void vli_modExp(uint32_t *p_result, uint32_t *p_base,
		       uint32_t *p_exp, uint32_t *p_mod, uint32_t *p_barrett)
{
	uint32_t acc[NUM_ECC_DIGITS], tmp[NUM_ECC_DIGITS], product[2 * NUM_ECC_DIGITS];
	uint32_t j;
	int32_t i;
	vli_clear(acc);
	acc[0] = 1;
	for (i = NUM_ECC_DIGITS - 1; i >= 0; i--) {
		for (j = 1 << 31; j > 0; j = j >> 1) {
			vli_square(product, acc);
			vli_mmod_barrett(acc, product, p_mod, p_barrett);
			vli_mult(product, acc, p_base, NUM_ECC_DIGITS);
			vli_mmod_barrett(tmp, product, p_mod, p_barrett);
			vli_cond_set(acc, tmp, acc, j & p_exp[i]);
		}
	}
	vli_set(p_result, acc);
}
static void vli_modExp ( uint32_t * p_result , uint32_t * p_base , uint32_t * p_exp , uint32_t * p_mod , uint32_t * p_barrett ) { uint32_t acc [ NUM_ECC_DIGITS ] , tmp [ NUM_ECC_DIGITS ] , product [ 2 * NUM_ECC_DIGITS ] ; uint32_t j ; int32_t i ; vli_clear ( acc ) ; acc [ 0 ] = 1 ; for ( i = NUM_ECC_DIGITS - 1 ; i >= 0 ; i -- ) { for ( j = 1 << 31 ; j > 0 ; j = j >> 1 ) { vli_square ( product , acc ) ; vli_mmod_barrett ( acc , product , p_mod , p_barrett ) ; vli_mult ( product , acc , p_base , NUM_ECC_DIGITS ) ; vli_mmod_barrett ( tmp , product , p_mod , p_barrett ) ; vli_cond_set ( acc , tmp , acc , j & p_exp [ i ] ) ; } } vli_set ( p_result , acc ) ; }
Computes modular exponentiation.
Computes modular exponentiation .