X-Git-Url: https://www.bearssl.org/gitweb//home/git/?p=BearSSL;a=blobdiff_plain;f=tools%2Fkeys.c;h=6e54676380a64f0a517f501196000d9cda67f5fb;hp=278a3b2452d7513c31b61b5396898f914385fcb6;hb=12db697bccf2ff732665b9c7668c0826513489e0;hpb=3210f38e0491b39aec1ef419cb4114e9483089fb diff --git a/tools/keys.c b/tools/keys.c index 278a3b2..6e54676 100644 --- a/tools/keys.c +++ b/tools/keys.c @@ -168,3 +168,67 @@ free_private_key(private_key *sk) } xfree(sk); } + +/* + * OID for hash functions in RSA signatures. + */ +static const unsigned char HASH_OID_SHA1[] = { + 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A +}; + +static const unsigned char HASH_OID_SHA224[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04 +}; + +static const unsigned char HASH_OID_SHA256[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01 +}; + +static const unsigned char HASH_OID_SHA384[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02 +}; + +static const unsigned char HASH_OID_SHA512[] = { + 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03 +}; + +static const unsigned char *HASH_OID[] = { + HASH_OID_SHA1, + HASH_OID_SHA224, + HASH_OID_SHA256, + HASH_OID_SHA384, + HASH_OID_SHA512 +}; + +/* see brssl.h */ +const unsigned char * +get_hash_oid(int id) +{ + if (id >= 2 && id <= 6) { + return HASH_OID[id - 2]; + } else { + return NULL; + } +} + +/* see brssl.h */ +const br_hash_class * +get_hash_impl(int hash_id) +{ + size_t u; + + if (hash_id == 0) { + return &br_md5sha1_vtable; + } + for (u = 0; hash_functions[u].name; u ++) { + const br_hash_class *hc; + int id; + + hc = hash_functions[u].hclass; + id = (hc->desc >> BR_HASHDESC_ID_OFF) & BR_HASHDESC_ID_MASK; + if (id == hash_id) { + return hc; + } + } + return NULL; +}