1
/*************************************************
2
* Hash Function Identification Source File *
3
* (C) 1999-2007 The Botan Project *
4
*************************************************/
6
#include <botan/hash_id.h>
7
#include <botan/lookup.h>
13
const byte MD2_ID[] = {
14
0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86,
15
0xF7, 0x0D, 0x02, 0x02, 0x05, 0x00, 0x04, 0x10 };
17
const byte MD5_ID[] = {
18
0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86,
19
0xF7, 0x0D, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10 };
21
const byte RIPEMD_128_ID[] = {
22
0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24, 0x03, 0x02,
23
0x02, 0x05, 0x00, 0x04, 0x14 };
25
const byte RIPEMD_160_ID[] = {
26
0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24, 0x03, 0x02,
27
0x01, 0x05, 0x00, 0x04, 0x14 };
29
const byte SHA_160_ID[] = {
30
0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02,
31
0x1A, 0x05, 0x00, 0x04, 0x14 };
33
const byte SHA_256_ID[] = {
34
0x30, 0x31, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
35
0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20 };
37
const byte SHA_384_ID[] = {
38
0x30, 0x41, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
39
0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30 };
41
const byte SHA_512_ID[] = {
42
0x30, 0x31, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
43
0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40 };
45
const byte TIGER_ID[] = {
46
0x30, 0x29, 0x30, 0x0D, 0x06, 0x09, 0x2B, 0x06, 0x01, 0x04,
47
0x01, 0xDA, 0x47, 0x0C, 0x02, 0x05, 0x00, 0x04, 0x18 };
51
/*************************************************
52
* Return the HashID, as specified by PKCS *
53
*************************************************/
54
MemoryVector<byte> pkcs_hash_id(const std::string& name_or_alias)
56
const std::string name = deref_alias(name_or_alias);
58
MemoryVector<byte> out;
60
if(name == "Parallel(MD5,SHA-160)")
64
out.set(PKCS_IDS::MD2_ID, sizeof(PKCS_IDS::MD2_ID));
65
else if(name == "MD5")
66
out.set(PKCS_IDS::MD5_ID, sizeof(PKCS_IDS::MD5_ID));
67
else if(name == "RIPEMD-128")
68
out.set(PKCS_IDS::RIPEMD_128_ID, sizeof(PKCS_IDS::RIPEMD_128_ID));
69
else if(name == "RIPEMD-160")
70
out.set(PKCS_IDS::RIPEMD_160_ID, sizeof(PKCS_IDS::RIPEMD_160_ID));
71
else if(name == "SHA-160")
72
out.set(PKCS_IDS::SHA_160_ID, sizeof(PKCS_IDS::SHA_160_ID));
73
else if(name == "SHA-256")
74
out.set(PKCS_IDS::SHA_256_ID, sizeof(PKCS_IDS::SHA_256_ID));
75
else if(name == "SHA-384")
76
out.set(PKCS_IDS::SHA_384_ID, sizeof(PKCS_IDS::SHA_384_ID));
77
else if(name == "SHA-512")
78
out.set(PKCS_IDS::SHA_512_ID, sizeof(PKCS_IDS::SHA_512_ID));
79
else if(name == "Tiger(24,3)")
80
out.set(PKCS_IDS::TIGER_ID, sizeof(PKCS_IDS::TIGER_ID));
85
throw Invalid_Argument("No PKCS #1 identifier for " + name_or_alias);
88
/*************************************************
89
* Return the HashID, as specified by IEEE 1363 *
90
*************************************************/
91
byte ieee1363_hash_id(const std::string& name_or_alias)
93
const std::string name = deref_alias(name_or_alias);
95
if(name == "RIPEMD-160") return 0x31;
96
if(name == "RIPEMD-128") return 0x32;
97
if(name == "SHA-160") return 0x33;
98
if(name == "SHA-256") return 0x34;
99
if(name == "SHA-512") return 0x35;
100
if(name == "SHA-384") return 0x36;
101
if(name == "Whirlpool") return 0x37;