Cryptography Reference
In-Depth Information
0x09, 0x75, 0x59, 0xC2, 0x7F, 0x16, 0x14, 0xC8, 0x8A, 0x7F };
elliptic_curve curve;
ecc_key A;
dsa_signature signature;
digest_ctx ctx;
load_huge( &curve.p, ( unsigned char * ) P, sizeof( P ) );
set_huge( &curve.a, 3 );
curve.a.sign = 1;
load_huge( &curve.b, b, sizeof( b ) );
load_huge( &curve.G.x, gx, sizeof( gx ) );
load_huge( &curve.G.y, gy, sizeof( gy ) );
load_huge( &curve.n, q, sizeof( q ) );
// Generate new public key from private key “w” and point “G”
load_huge( &A.d, w, sizeof( w ) );
set_huge( &A.Q.x, 0 );
set_huge( &A.Q.y, 0 );
copy_huge( &A.Q.x, &curve.G.x );
copy_huge( &A.Q.y, &curve.G.y );
multiply_point( &A.Q, &A.d, &curve.a, &curve.p );
new_sha256_digest( &ctx );
update_digest( &ctx, “abc”, 3 );
finalize_digest( &ctx );
ecdsa_sign( &curve, &A.d, ctx.hash, ctx.hash_len, &signature );
printf( “R:” );
show_hex( signature.r.rep, signature.r.size );
printf( “S:” );
show_hex( signature.s.rep, signature.r.size );
if ( !ecdsa_verify( &curve, &A.Q, ctx.hash, ctx.hash_len, &signature ) )
{
printf( “Signatures don't match.\n” );
}
else
{
printf( “Signature verified.\n” );
}
return 0;
}
#endif
Like the DSA test routine output, this one isn't particularly interesting, but
it demonstrates the concept:
jdavies@localhost$ ./ecdsa
Search WWH ::




Custom Search