Cryptography Reference
In-Depth Information
p3.x = ( ( lambda * lambda ) - ( 2 * p1->x ) ) % p;
p3.y = ( ( lambda * ( p1->x - p3.x ) ) - p1->y ) % p;
p1->x = p3.x;
p1->y = p3.y;
}
5. Finally, you can implement multiplication in terms of double and add,
shown in Listing 3-41.
Listing 3-41: “ecc_int.c” multiply_point routine
static void multiply_point( point *p1, int k, int a, int p )
{
point dp;
int mask;
int paf = 1;
dp.x = p1->x;
dp.y = p1->y;
for ( mask = 0x00000001; mask; mask <<= 1 )
{
if ( mask & k )
{
if ( paf )
{
paf = 0;
p1->x = dp.x;
p1->y = dp.y;
}
else
{
add_points( p1, &dp, p );
}
}
double_point( &dp, p, a );
}
}
NOTE Notice the paf fl ag that indicates that p1 is the point at infi nity (that
is, the ECC equivalent of “zero”). It's not particularly pretty, but it works.
Otherwise, this should look fairly familiar. The same routine has effectively
been implemented twice now — once for large integer multiplication and once
for large integer exponentiation.
6. To implement Diffi e-Hellman, you need a set of domain parameters T and
a private key each for A and B. You can't just make up random domain
parameters; in this case, just hardcode them:
 
Search WWH ::




Custom Search