Cryptography Reference
In-Depth Information
Listing 4-29: “dsa.h” dsa_params structure
typedef struct
{
huge g;
huge p;
huge q;
}
dsa_params;
Defi ne the structure in Listing 4-30 to hold the actual signature.
Listing 4-30: “dsa.h” dsa_signature structure
typedef struct
{
huge r;
huge s;
}
dsa_signature;
So now, in code, the signature algorithm can be implemented as shown in
Listing 4-31.
Listing 4-31: “dsa.c” DSA signature generation algorithm
void dsa_sign( dsa_params *params,
huge *private_key,
unsigned int *hash,
int hash_len,
dsa_signature *signature )
{
huge k;
huge z;
huge q;
set_huge( &q, 1 );
generate_message_secret( params, &k );
// r = ( g ^ k % p ) % q
mod_pow( &params->g, &k, &params->p, &signature->r );
copy_huge( &q, &params->q );
divide( &signature->r, &q, NULL );
// z = hash(message), only approved with SHA
load_huge( &z, ( unsigned char * ) hash,
( (hash_len * 4 ) < params->q.size ) ?
(hash_len * 4 ) : params->q.size );
(Continued)
Search WWH ::




Custom Search