8 #include <botan/pk_algs.h>
9 #include <botan/oids.h>
11 #if defined(BOTAN_HAS_RSA)
12 #include <botan/rsa.h>
15 #if defined(BOTAN_HAS_DSA)
16 #include <botan/dsa.h>
19 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
23 #if defined(BOTAN_HAS_ECDSA)
24 #include <botan/ecdsa.h>
27 #if defined(BOTAN_HAS_ECGDSA)
28 #include <botan/ecgdsa.h>
31 #if defined(BOTAN_HAS_ECKCDSA)
32 #include <botan/eckcdsa.h>
35 #if defined(BOTAN_HAS_GOST_34_10_2001)
36 #include <botan/gost_3410.h>
39 #if defined(BOTAN_HAS_ELGAMAL)
40 #include <botan/elgamal.h>
43 #if defined(BOTAN_HAS_ECDH)
44 #include <botan/ecdh.h>
47 #if defined(BOTAN_HAS_CURVE_25519)
48 #include <botan/curve25519.h>
51 #if defined(BOTAN_HAS_MCELIECE)
52 #include <botan/mceliece.h>
55 #if defined(BOTAN_HAS_XMSS)
56 #include <botan/xmss.h>
61 std::unique_ptr<Public_Key>
63 const std::vector<uint8_t>& key_bits)
69 #if defined(BOTAN_HAS_RSA)
71 return std::unique_ptr<Public_Key>(
new RSA_PublicKey(alg_id, key_bits));
74 #if defined(BOTAN_HAS_CURVE_25519)
75 if(alg_name ==
"Curve25519")
79 #if defined(BOTAN_HAS_MCELIECE)
80 if(alg_name ==
"McEliece")
84 #if defined(BOTAN_HAS_ECDSA)
85 if(alg_name ==
"ECDSA")
86 return std::unique_ptr<Public_Key>(
new ECDSA_PublicKey(alg_id, key_bits));
89 #if defined(BOTAN_HAS_ECDH)
90 if(alg_name ==
"ECDH")
91 return std::unique_ptr<Public_Key>(
new ECDH_PublicKey(alg_id, key_bits));
94 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
96 return std::unique_ptr<Public_Key>(
new DH_PublicKey(alg_id, key_bits));
99 #if defined(BOTAN_HAS_DSA)
100 if(alg_name ==
"DSA")
101 return std::unique_ptr<Public_Key>(
new DSA_PublicKey(alg_id, key_bits));
104 #if defined(BOTAN_HAS_ELGAMAL)
105 if(alg_name ==
"ElGamal")
109 #if defined(BOTAN_HAS_ECGDSA)
110 if(alg_name ==
"ECGDSA")
114 #if defined(BOTAN_HAS_ECKCDSA)
115 if(alg_name ==
"ECKCDSA")
119 #if defined(BOTAN_HAS_GOST_34_10_2001)
120 if(alg_name ==
"GOST-34.10")
124 #if defined(BOTAN_HAS_XMSS)
125 if(alg_name ==
"XMSS")
132 std::unique_ptr<Private_Key>
140 #if defined(BOTAN_HAS_RSA)
141 if(alg_name ==
"RSA")
142 return std::unique_ptr<Private_Key>(
new RSA_PrivateKey(alg_id, key_bits));
145 #if defined(BOTAN_HAS_CURVE_25519)
146 if(alg_name ==
"Curve25519")
150 #if defined(BOTAN_HAS_ECDSA)
151 if(alg_name ==
"ECDSA")
152 return std::unique_ptr<Private_Key>(
new ECDSA_PrivateKey(alg_id, key_bits));
155 #if defined(BOTAN_HAS_ECDH)
156 if(alg_name ==
"ECDH")
157 return std::unique_ptr<Private_Key>(
new ECDH_PrivateKey(alg_id, key_bits));
160 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
162 return std::unique_ptr<Private_Key>(
new DH_PrivateKey(alg_id, key_bits));
165 #if defined(BOTAN_HAS_DSA)
166 if(alg_name ==
"DSA")
167 return std::unique_ptr<Private_Key>(
new DSA_PrivateKey(alg_id, key_bits));
170 #if defined(BOTAN_HAS_MCELIECE)
171 if(alg_name ==
"McEliece")
175 #if defined(BOTAN_HAS_ECGDSA)
176 if(alg_name ==
"ECGDSA")
180 #if defined(BOTAN_HAS_ECKCDSA)
181 if(alg_name ==
"ECKCDSA")
185 #if defined(BOTAN_HAS_GOST_34_10_2001)
186 if(alg_name ==
"GOST-34.10")
190 #if defined(BOTAN_HAS_ELGAMAL)
191 if(alg_name ==
"ElGamal")
195 #if defined(BOTAN_HAS_XMSS)
196 if(alg_name ==
"XMSS")
203 std::unique_ptr<Private_Key>
206 const std::string& params)
212 #if defined(BOTAN_HAS_CURVE_25519)
213 if(alg_name ==
"Curve25519")
217 #if defined(BOTAN_HAS_RSA)
218 if(alg_name ==
"RSA")
220 const size_t rsa_bits = (params.empty() ? 3072 :
to_u32bit(params));
221 return std::unique_ptr<Private_Key>(
new RSA_PrivateKey(rng, rsa_bits));
225 #if defined(BOTAN_HAS_MCELIECE)
226 if(alg_name ==
"McEliece")
228 std::vector<std::string> mce_param =
231 if(mce_param.size() != 2)
232 throw Invalid_Argument(
"create_private_key bad McEliece parameters " + params);
241 #if defined(BOTAN_HAS_XMSS)
242 if(alg_name ==
"XMSS")
244 return std::unique_ptr<Private_Key>(
250 #if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
252 if(alg_name ==
"ECDSA" ||
253 alg_name ==
"ECDH" ||
254 alg_name ==
"ECKCDSA" ||
255 alg_name ==
"ECGDSA" ||
256 alg_name ==
"GOST-34.10")
258 const EC_Group ec_group(params.empty() ?
"secp256r1" : params);
260 #if defined(BOTAN_HAS_ECDSA)
261 if(alg_name ==
"ECDSA")
265 #if defined(BOTAN_HAS_ECDH)
266 if(alg_name ==
"ECDH")
267 return std::unique_ptr<Private_Key>(
new ECDH_PrivateKey(rng, ec_group));
270 #if defined(BOTAN_HAS_ECKCDSA)
271 if(alg_name ==
"ECKCDSA")
275 #if defined(BOTAN_HAS_GOST_34_10_2001)
276 if(alg_name ==
"GOST-34.10")
280 #if defined(BOTAN_HAS_ECGDSA)
281 if(alg_name ==
"ECGDSA")
288 #if defined(BOTAN_HAS_DL_GROUP)
289 if(alg_name ==
"DH" || alg_name ==
"DSA" || alg_name ==
"ElGamal")
291 std::string default_group = (alg_name ==
"DSA") ?
"dsa/botan/2048" :
"modp/ietf/2048";
292 DL_Group modp_group(params.empty() ? default_group : params);
294 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
296 return std::unique_ptr<Private_Key>(
new DH_PrivateKey(rng, modp_group));
299 #if defined(BOTAN_HAS_DSA)
300 if(alg_name ==
"DSA")
301 return std::unique_ptr<Private_Key>(
new DSA_PrivateKey(rng, modp_group));
304 #if defined(BOTAN_HAS_ELGAMAL)
305 if(alg_name ==
"ElGamal")
311 return std::unique_ptr<Private_Key>();
uint32_t to_u32bit(const std::string &str)
std::vector< std::string > split_on(const std::string &str, char delim)
std::vector< T, secure_allocator< T >> secure_vector
std::unique_ptr< Public_Key > load_public_key(const AlgorithmIdentifier &alg_id, const std::vector< uint8_t > &key_bits)
std::string lookup(const OID &oid)
std::string as_string() const
std::unique_ptr< Private_Key > load_private_key(const AlgorithmIdentifier &alg_id, const secure_vector< uint8_t > &key_bits)
std::unique_ptr< Private_Key > create_private_key(const std::string &alg_name, RandomNumberGenerator &rng, const std::string ¶ms)