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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
/*
* PK Key
* (C) 1999-2010 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#include <botan/internal/pk_algs.h>
#include <botan/oids.h>
#if defined(BOTAN_HAS_RSA)
#include <botan/rsa.h>
#endif
#if defined(BOTAN_HAS_DSA)
#include <botan/dsa.h>
#endif
#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
#include <botan/dh.h>
#endif
#if defined(BOTAN_HAS_ECDSA)
#include <botan/ecdsa.h>
#endif
#if defined(BOTAN_HAS_ECGDSA)
#include <botan/ecgdsa.h>
#endif
#if defined(BOTAN_HAS_ECKCDSA)
#include <botan/eckcdsa.h>
#endif
#if defined(BOTAN_HAS_GOST_34_10_2001)
#include <botan/gost_3410.h>
#endif
#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
#include <botan/nr.h>
#endif
#if defined(BOTAN_HAS_RW)
#include <botan/rw.h>
#endif
#if defined(BOTAN_HAS_ELGAMAL)
#include <botan/elgamal.h>
#endif
#if defined(BOTAN_HAS_ECDH)
#include <botan/ecdh.h>
#endif
#if defined(BOTAN_HAS_CURVE_25519)
#include <botan/curve25519.h>
#endif
#if defined(BOTAN_HAS_MCELIECE)
#include <botan/mceliece.h>
#endif
namespace Botan {
Public_Key* make_public_key(const AlgorithmIdentifier& alg_id,
const secure_vector<byte>& key_bits)
{
const std::string alg_name = OIDS::lookup(alg_id.oid);
if(alg_name == "")
throw Decoding_Error("Unknown algorithm OID: " + alg_id.oid.as_string());
#if defined(BOTAN_HAS_RSA)
if(alg_name == "RSA")
return new RSA_PublicKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_RW)
if(alg_name == "RW")
return new RW_PublicKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_DSA)
if(alg_name == "DSA")
return new DSA_PublicKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
if(alg_name == "DH")
return new DH_PublicKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
if(alg_name == "NR")
return new NR_PublicKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_ELGAMAL)
if(alg_name == "ElGamal")
return new ElGamal_PublicKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_ECDSA)
if(alg_name == "ECDSA")
return new ECDSA_PublicKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_ECGDSA)
if(alg_name == "ECGDSA")
return new ECGDSA_PublicKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_ECKCDSA)
if(alg_name == "ECKCDSA")
return new ECKCDSA_PublicKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_GOST_34_10_2001)
if(alg_name == "GOST-34.10")
return new GOST_3410_PublicKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_ECDH)
if(alg_name == "ECDH")
return new ECDH_PublicKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_CURVE_25519)
if(alg_name == "Curve25519")
return new Curve25519_PublicKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_MCELIECE)
if(alg_name == "McEliece")
return new McEliece_PublicKey(unlock(key_bits));
#endif
throw Decoding_Error("Unhandled PK algorithm " + alg_name);
}
Private_Key* make_private_key(const AlgorithmIdentifier& alg_id,
const secure_vector<byte>& key_bits,
RandomNumberGenerator& rng)
{
const std::string alg_name = OIDS::lookup(alg_id.oid);
if(alg_name == "")
throw Decoding_Error("Unknown algorithm OID: " + alg_id.oid.as_string());
#if defined(BOTAN_HAS_RSA)
if(alg_name == "RSA")
return new RSA_PrivateKey(alg_id, key_bits, rng);
#endif
#if defined(BOTAN_HAS_RW)
if(alg_name == "RW")
return new RW_PrivateKey(alg_id, key_bits, rng);
#endif
#if defined(BOTAN_HAS_DSA)
if(alg_name == "DSA")
return new DSA_PrivateKey(alg_id, key_bits, rng);
#endif
#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
if(alg_name == "DH")
return new DH_PrivateKey(alg_id, key_bits, rng);
#endif
#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
if(alg_name == "NR")
return new NR_PrivateKey(alg_id, key_bits, rng);
#endif
#if defined(BOTAN_HAS_ELGAMAL)
if(alg_name == "ElGamal")
return new ElGamal_PrivateKey(alg_id, key_bits, rng);
#endif
#if defined(BOTAN_HAS_ECDSA)
if(alg_name == "ECDSA")
return new ECDSA_PrivateKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_ECGDSA)
if(alg_name == "ECGDSA")
return new ECGDSA_PrivateKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_ECKCDSA)
if(alg_name == "ECKCDSA")
return new ECKCDSA_PrivateKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_GOST_34_10_2001)
if(alg_name == "GOST-34.10")
return new GOST_3410_PrivateKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_ECDH)
if(alg_name == "ECDH")
return new ECDH_PrivateKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_CURVE_25519)
if(alg_name == "Curve25519")
return new Curve25519_PrivateKey(alg_id, key_bits, rng);
#endif
#if defined(BOTAN_HAS_MCELIECE)
if(alg_name == "McEliece")
return new McEliece_PrivateKey(key_bits);
#endif
throw Decoding_Error("Unhandled PK algorithm " + alg_name);
}
}
|