~ubuntu-branches/debian/sid/botan/sid

« back to all changes in this revision

Viewing changes to src/hash_id.cpp

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2018-03-01 22:23:25 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20180301222325-7p7vc45gu3hta34d
Tags: 2.4.0-2
* Don't remove .doctrees from the manual if it doesn't exist.
* Don't specify parallel to debhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*************************************************
2
 
* Hash Function Identification Source File       *
3
 
* (C) 1999-2007 The Botan Project                *
4
 
*************************************************/
5
 
 
6
 
#include <botan/hash_id.h>
7
 
#include <botan/lookup.h>
8
 
 
9
 
namespace Botan {
10
 
 
11
 
namespace PKCS_IDS {
12
 
 
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 };
16
 
 
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 };
20
 
 
21
 
const byte RIPEMD_128_ID[] = {
22
 
0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24, 0x03, 0x02,
23
 
0x02, 0x05, 0x00, 0x04, 0x14 };
24
 
 
25
 
const byte RIPEMD_160_ID[] = {
26
 
0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24, 0x03, 0x02,
27
 
0x01, 0x05, 0x00, 0x04, 0x14 };
28
 
 
29
 
const byte SHA_160_ID[] = {
30
 
0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02,
31
 
0x1A, 0x05, 0x00, 0x04, 0x14 };
32
 
 
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 };
36
 
 
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 };
40
 
 
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 };
44
 
 
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 };
48
 
 
49
 
}
50
 
 
51
 
/*************************************************
52
 
* Return the HashID, as specified by PKCS        *
53
 
*************************************************/
54
 
MemoryVector<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
 
*************************************************/
91
 
byte 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
 
}