Cryptography Reference
In-Depth Information
// p1->x = p3.x
// p1->y = p3.y
copy_huge( &p1->x, &p3.x );
copy_huge( &p1->y, &p3.y );
free_huge( &p3.x );
free_huge( &p3.y );
free_huge( &denominator );
free_huge( &numerator );
free_huge( &invdenom );
free_huge( &lambda );
}
I've left comments indicating the int operations that the huge operation
blocks correspond to so you can cross-reference this implementation back
to the easier-to-understand integer-based operation in Listing 3-39.
3. Recall that multiplication is defi ned in terms of “double-and-add” — in
this case, not as a performance optimization, but because adding a point
to itself is actually not defi ned, so you need a double_point operation in
Listing 4-37.
Listing 4-37: “ecc.c” point-doubling algorithm
static void double_point( point *p1, huge *a, huge *p )
{
huge lambda;
huge l1;
huge x1;
huge y1;
set_huge( &lambda, 0 );
set_huge( &x1, 0 );
set_huge( &y1, 0 );
set_huge( &lambda, 2 ); // lambda = 2;
multiply( &lambda, &p1->y ); // lambda = 2 * y1
inv( &lambda, p ); // lambda = ( 2 * y1 ) ^ -1 (% p)
set_huge( &l1, 3 ); // l1 = 3
multiply( &l1, &p1->x ); // l1 = 3 * x
multiply( &l1, &p1->x ); // l1 = 3 * x ^ 2
add( &l1, a ); // l1 = ( 3 * x ^ 2 ) + a
multiply( &lambda, &l1 ); // lambda = [ ( 3 * x ^ 2 ) + a ] / [ 2 * y1 ] ) % p
copy_huge( &y1, &p1->y );
// Note - make two copies of x2; this one is for y1 below
copy_huge( &p1->y, &p1->x );
set_huge( &x1, 2 );
multiply( &x1, &p1->x ); // x1 = 2 * x1
copy_huge( &p1->x, &lambda ); // x1 = lambda
(Continued)
 
Search WWH ::




Custom Search