Cryptography Reference
In-Depth Information
multiply( &p1->x, &lambda ); // x1 = ( lambda ^ 2 );
subtract( &p1->x, &x1 ); // x1 = ( lambda ^ 2 ) - ( 2 * x1 )
divide( &p1->x, p, NULL ); // [ x1 = ( lambda ^ 2 ) - ( 2 * x1 ) ] % p
if ( p1->x.sign )
{
subtract( &p1->x, p );
p1->x.sign = 0;
subtract( &p1->x, p );
}
subtract( &p1->y, &p1->x ); // y3 = x3 - x1
multiply( &p1->y, &lambda ); // y3 = lambda * ( x3 - x1 );
subtract( &p1->y, &y1 ); // y3 = ( lambda * ( x3 - x1 ) ) - y1
divide( &p1->y, p, NULL ); // y3 = [ ( lambda * ( x3 - x1 ) ) - y1 ] % p
if ( p1->y.sign )
{
p1->y.sign = 0;
subtract( &p1->y, p );
p1->y.sign = 0;
}
free_huge( &lambda );
free_huge( &x1 );
free_huge( &y1 );
free_huge( &l1 );
}
4. Finally, you can implement multiply_point in Listing 4-38, the really
important function, in terms of double_point and add_points .
Listing 4-38: “ecc.c” point-multiplication algorithm
void multiply_point( point *p1, huge *k, huge *a, huge *p )
{
int i;
unsigned char mask;
point dp;
int paf = 1;
set_huge( &dp.x, 0 );
set_huge( &dp.y, 0 );
copy_huge( &dp.x, &p1->x );
copy_huge( &dp.y, &p1->y );
for ( i = k->size; i; i-- )
{
for ( mask = 0x01; mask; mask <<= 1 )
{
if ( k->rep[ i - 1 ] & mask )
{
if ( paf )
{
 
Search WWH ::




Custom Search