aboutsummaryrefslogtreecommitdiffstats
path: root/src/get_enc.cpp
blob: 17e28e9d9d945f6053e873ed53ca41d677e1f68e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*************************************************
* EMSA/EME/KDF/MGF Retrieval Source File         *
* (C) 1999-2007 Jack Lloyd                       *
*************************************************/

#include <botan/lookup.h>
#include <botan/libstate.h>
#include <botan/parsing.h>
#include <botan/emsa.h>
#include <botan/eme.h>
#include <botan/kdf.h>
#include <botan/mgf1.h>
#include <botan/util.h>

namespace Botan {

/*************************************************
* Get an EMSA by name                            *
*************************************************/
EMSA* get_emsa(const std::string& algo_spec)
   {
   std::vector<std::string> name = parse_algorithm_name(algo_spec);
   const std::string emsa_name = global_state().deref_alias(name[0]);

   if(emsa_name == "Raw")
      {
      if(name.size() == 1)
         return new EMSA_Raw;
      }
   else if(emsa_name == "EMSA1")
      {
      if(name.size() == 2)
         return new EMSA1(name[1]);
      }
   else if(emsa_name == "EMSA2")
      {
      if(name.size() == 2)
         return new EMSA2(name[1]);
      }
   else if(emsa_name == "EMSA3")
      {
      if(name.size() == 2)
         return new EMSA3(name[1]);
      }
   else if(emsa_name == "EMSA4")
      {
      if(name.size() == 2)
         return new EMSA4(name[1], "MGF1");
      if(name.size() == 3)
         return new EMSA4(name[1], name[2]);
      if(name.size() == 4)
         return new EMSA4(name[1], name[2], to_u32bit(name[3]));
      }
   else
      throw Algorithm_Not_Found(algo_spec);

   throw Invalid_Algorithm_Name(algo_spec);
   }

/*************************************************
* Get an EME by name                             *
*************************************************/
EME* get_eme(const std::string& algo_spec)
   {
   std::vector<std::string> name = parse_algorithm_name(algo_spec);
   const std::string eme_name = global_state().deref_alias(name[0]);

   if(eme_name == "PKCS1v15")
      {
      if(name.size() == 1)
         return new EME_PKCS1v15;
      }
   else if(eme_name == "EME1")
      {
      if(name.size() == 2)
         return new EME1(name[1], "MGF1");
      if(name.size() == 3)
         return new EME1(name[1], name[2]);
      }
   else
      throw Algorithm_Not_Found(algo_spec);

   throw Invalid_Algorithm_Name(algo_spec);
   }

/*************************************************
* Get an KDF by name                             *
*************************************************/
KDF* get_kdf(const std::string& algo_spec)
   {
   std::vector<std::string> name = parse_algorithm_name(algo_spec);
   const std::string kdf_name = global_state().deref_alias(name[0]);

   if(kdf_name == "KDF1")
      {
      if(name.size() == 2)
         return new KDF1(name[1]);
      }
   else if(kdf_name == "KDF2")
      {
      if(name.size() == 2)
         return new KDF2(name[1]);
      }
   else if(kdf_name == "X9.42-PRF")
      {
      if(name.size() == 2)
         return new X942_PRF(name[1]);
      }
   else
      throw Algorithm_Not_Found(algo_spec);

   throw Invalid_Algorithm_Name(algo_spec);
   }

/*************************************************
* Get a MGF by name                              *
*************************************************/
MGF* get_mgf(const std::string& algo_spec)
   {
   std::vector<std::string> name = parse_algorithm_name(algo_spec);
   const std::string mgf_name = global_state().deref_alias(name[0]);

   if(mgf_name == "MGF1")
      {
      if(name.size() == 2)
         return new MGF1(name[1]);
      }
   else
      throw Algorithm_Not_Found(algo_spec);

   throw Invalid_Algorithm_Name(algo_spec);
   }

}