monotone

monotone Mtn Source Tree

Root/botan/hash_id.cpp

1/*************************************************
2* Hash Function Identification Source File *
3* (C) 1999-2006 The Botan Project *
4*************************************************/
5
6#include <botan/hash_id.h>
7#include <botan/lookup.h>
8
9namespace Botan {
10
11namespace PKCS_IDS {
12
13const byte MD2_ID[] = {
140x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86,
150xF7, 0x0D, 0x02, 0x02, 0x05, 0x00, 0x04, 0x10 };
16
17const byte MD5_ID[] = {
180x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86,
190xF7, 0x0D, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10 };
20
21const byte RIPEMD_128_ID[] = {
220x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24, 0x03, 0x02,
230x02, 0x05, 0x00, 0x04, 0x14 };
24
25const byte RIPEMD_160_ID[] = {
260x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24, 0x03, 0x02,
270x01, 0x05, 0x00, 0x04, 0x14 };
28
29const byte SHA_160_ID[] = {
300x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02,
310x1A, 0x05, 0x00, 0x04, 0x14 };
32
33const byte SHA_256_ID[] = {
340x30, 0x31, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
350x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20 };
36
37const byte SHA_384_ID[] = {
380x30, 0x41, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
390x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30 };
40
41const byte SHA_512_ID[] = {
420x30, 0x31, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01,
430x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40 };
44
45const byte TIGER_ID[] = {
460x30, 0x29, 0x30, 0x0D, 0x06, 0x09, 0x2B, 0x06, 0x01, 0x04,
470x01, 0xDA, 0x47, 0x0C, 0x02, 0x05, 0x00, 0x04, 0x18 };
48
49}
50
51/*************************************************
52* Return the HashID, as specified by PKCS *
53*************************************************/
54MemoryVector<byte> pkcs_hash_id(const std::string& name_or_alias)
55 {
56 const std::string name = deref_alias(name_or_alias);
57
58 MemoryVector<byte> out;
59
60 if(name == "Parallel(MD5,SHA-160)")
61 return out;
62
63 if(name == "MD2")
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));
81
82 if(out.size())
83 return out;
84
85 throw Invalid_Argument("No PKCS #1 identifier for " + name_or_alias);
86 }
87
88/*************************************************
89* Return the HashID, as specified by IEEE 1363 *
90*************************************************/
91byte ieee1363_hash_id(const std::string& name_or_alias)
92 {
93 const std::string name = deref_alias(name_or_alias);
94
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;
102 return 0;
103 }
104
105}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status