Cryptography Reference
In-Depth Information
parse_huge( &target->dsa_signature_value.s, dsa_signature.children->next );
asn1free( &dsa_signature );
return 0;
}
Most of the complexity in dealing with DSA certifi cates is in parsing the pub-
lic key information. An RSA public key is simply two numbers. A DSA public
key is a single number, but the algorithm also requires parameters. For no clear
reason, the X.509 designers split the parameters and the public key into two
separate ASN.1 sequences, with different parent elements, so the parsing code
gets a bit involved in Listing 5-33.
Listing 5-33: “x509.c” public key info parsing with DSA support
static const unsigned char OID_RSA[] =
{ 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01 };
static const unsigned char OID_DSA[] =
{ 0x2A, 0x86, 0x48, 0xCE, 0x38, 0x04, 0x01 };
static int parse_public_key_info( public_key_info *target,
struct asn1struct *source )
{
if ( !memcmp( oid->data, &OID_RSA, sizeof( OID_RSA ) ) )
{
}
else if ( !memcmp( oid->data, &OID_DSA, sizeof( OID_DSA ) ) )
{
struct asn1struct *params;
target->algorithm = dsa;
parse_huge( &target->dsa_public_key, &public_key_value );
params = oid->next;
parse_dsa_params( target, params );
}
Finally, parsing the DSA params themselves in Listing 5-34 is simple after
you've identifi ed the node.
Listing 5-34: “tls.c” parse_dsa_params
static int parse_dsa_params( public_key_info *target, struct asn1struct *source )
{
struct asn1struct *p;
struct asn1struct *q;
struct asn1struct *g;
(Continued)
Search WWH ::




Custom Search