Cryptography Reference
In-Depth Information
memcpy( target->rep, source->data, target->size );
return 0;
}
Parsing Object Identifi ers (OIDs)
Following the serial number is the algorithm identifi er of the signature. This
is an OID and can take on several possible values; each value is unique and
identifi es a digest algorithm/digital signature algorithm pair. For now, only
support two: MD5 with RSA and SHA-1 with RSA, as shown in Listing 5-16.
Listing 5-16: “x509.c” parse_algorithm_identifi er
static const unsigned char OID_md5WithRSA[] =
{ 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x04 };
static const unsigned char OID_sha1WithRSA[] =
{ 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05 };
static int parse_algorithm_identifier( signatureAlgorithmIdentifier *target,
struct asn1struct *source )
{
struct asn1struct *oid = ( struct asn1struct * ) source->children;
if ( !memcmp( oid->data, OID_md5WithRSA, oid->length ) )
{
*target = md5WithRSAEncryption;
}
else if ( !memcmp( oid->data, OID_sha1WithRSA, oid->length ) )
{
*target = shaWithRSAEncryption;
}
else
{
int i;
fprintf( stderr, “Unsupported or unrecognized algorithm identifier OID “ );
for ( i = 0; i < oid->length; i++ )
{
fprintf( stderr, “%.02x “, oid->data[ i ] );
}
fprintf( stderr, “\n” );
return 2;
}
return 0;
}
Remember that OIDs are being hardcoded in expanded form so that you can
just do a memcmp to identify them.
 
Search WWH ::




Custom Search