79 const std::vector<uint8_t>& key_bits)
82 const std::vector<std::string> alg_info =
split_on(oid_str,
'/');
83 const std::string alg_name = alg_info[0];
85#if defined(BOTAN_HAS_RSA)
87 return std::unique_ptr<Public_Key>(
new RSA_PublicKey(alg_id, key_bits));
90#if defined(BOTAN_HAS_CURVE_25519)
91 if(alg_name ==
"Curve25519")
95#if defined(BOTAN_HAS_MCELIECE)
96 if(alg_name ==
"McEliece")
100#if defined(BOTAN_HAS_ECDSA)
101 if(alg_name ==
"ECDSA")
102 return std::unique_ptr<Public_Key>(
new ECDSA_PublicKey(alg_id, key_bits));
105#if defined(BOTAN_HAS_ECDH)
106 if(alg_name ==
"ECDH")
107 return std::unique_ptr<Public_Key>(
new ECDH_PublicKey(alg_id, key_bits));
110#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
112 return std::unique_ptr<Public_Key>(
new DH_PublicKey(alg_id, key_bits));
115#if defined(BOTAN_HAS_DSA)
116 if(alg_name ==
"DSA")
117 return std::unique_ptr<Public_Key>(
new DSA_PublicKey(alg_id, key_bits));
120#if defined(BOTAN_HAS_ELGAMAL)
121 if(alg_name ==
"ElGamal")
125#if defined(BOTAN_HAS_ECGDSA)
126 if(alg_name ==
"ECGDSA")
130#if defined(BOTAN_HAS_ECKCDSA)
131 if(alg_name ==
"ECKCDSA")
135#if defined(BOTAN_HAS_ED25519)
136 if(alg_name ==
"Ed25519")
140#if defined(BOTAN_HAS_GOST_34_10_2001)
141 if(alg_name ==
"GOST-34.10" || alg_name ==
"GOST-34.10-2012-256" || alg_name ==
"GOST-34.10-2012-512")
145#if defined(BOTAN_HAS_SM2)
146 if(alg_name ==
"SM2" || alg_name ==
"SM2_Sig" || alg_name ==
"SM2_Enc")
147 return std::unique_ptr<Public_Key>(
new SM2_PublicKey(alg_id, key_bits));
150#if defined(BOTAN_HAS_XMSS_RFC8391)
151 if(alg_name ==
"XMSS")
155 throw Decoding_Error(
"Unknown or unavailable public key algorithm " + alg_name);
164#if defined(BOTAN_HAS_RSA)
165 if(alg_name ==
"RSA")
166 return std::unique_ptr<Private_Key>(
new RSA_PrivateKey(alg_id, key_bits));
169#if defined(BOTAN_HAS_CURVE_25519)
170 if(alg_name ==
"Curve25519")
174#if defined(BOTAN_HAS_ECDSA)
175 if(alg_name ==
"ECDSA")
176 return std::unique_ptr<Private_Key>(
new ECDSA_PrivateKey(alg_id, key_bits));
179#if defined(BOTAN_HAS_ECDH)
180 if(alg_name ==
"ECDH")
181 return std::unique_ptr<Private_Key>(
new ECDH_PrivateKey(alg_id, key_bits));
184#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
186 return std::unique_ptr<Private_Key>(
new DH_PrivateKey(alg_id, key_bits));
189#if defined(BOTAN_HAS_DSA)
190 if(alg_name ==
"DSA")
191 return std::unique_ptr<Private_Key>(
new DSA_PrivateKey(alg_id, key_bits));
194#if defined(BOTAN_HAS_MCELIECE)
195 if(alg_name ==
"McEliece")
199#if defined(BOTAN_HAS_ECGDSA)
200 if(alg_name ==
"ECGDSA")
204#if defined(BOTAN_HAS_ECKCDSA)
205 if(alg_name ==
"ECKCDSA")
209#if defined(BOTAN_HAS_ED25519)
210 if(alg_name ==
"Ed25519")
214#if defined(BOTAN_HAS_GOST_34_10_2001)
215 if(alg_name ==
"GOST-34.10" || alg_name ==
"GOST-34.10-2012-256" || alg_name ==
"GOST-34.10-2012-512")
219#if defined(BOTAN_HAS_SM2)
220 if(alg_name ==
"SM2" || alg_name ==
"SM2_Sig" || alg_name ==
"SM2_Enc")
221 return std::unique_ptr<Private_Key>(
new SM2_PrivateKey(alg_id, key_bits));
224#if defined(BOTAN_HAS_ELGAMAL)
225 if(alg_name ==
"ElGamal")
229#if defined(BOTAN_HAS_XMSS_RFC8391)
230 if(alg_name ==
"XMSS")
234 throw Decoding_Error(
"Unknown or unavailable public key algorithm " + alg_name);
262 const std::string& params,
263 const std::string& provider)
269#if defined(BOTAN_HAS_CURVE_25519)
270 if(alg_name ==
"Curve25519")
274#if defined(BOTAN_HAS_RSA)
275 if(alg_name ==
"RSA")
277 const size_t rsa_bits = (params.empty() ? 3072 :
to_u32bit(params));
278 return std::unique_ptr<Private_Key>(
new RSA_PrivateKey(rng, rsa_bits));
282#if defined(BOTAN_HAS_MCELIECE)
283 if(alg_name ==
"McEliece")
285 std::vector<std::string> mce_param =
288 if(mce_param.size() != 2)
289 throw Invalid_Argument(
"create_private_key bad McEliece parameters " + params);
298#if defined(BOTAN_HAS_XMSS_RFC8391)
299 if(alg_name ==
"XMSS")
301 return std::unique_ptr<Private_Key>(
306#if defined(BOTAN_HAS_ED25519)
307 if(alg_name ==
"Ed25519")
314#if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO)
316 if(alg_name ==
"ECDSA" ||
317 alg_name ==
"ECDH" ||
318 alg_name ==
"ECKCDSA" ||
319 alg_name ==
"ECGDSA" ||
321 alg_name ==
"SM2_Sig" ||
322 alg_name ==
"SM2_Enc" ||
323 alg_name ==
"GOST-34.10" ||
324 alg_name ==
"GOST-34.10-2012-256" ||
325 alg_name ==
"GOST-34.10-2012-512")
327 const EC_Group ec_group(params.empty() ? default_ec_group_for(alg_name) : params);
329#if defined(BOTAN_HAS_ECDSA)
330 if(alg_name ==
"ECDSA")
334#if defined(BOTAN_HAS_ECDH)
335 if(alg_name ==
"ECDH")
336 return std::unique_ptr<Private_Key>(
new ECDH_PrivateKey(rng, ec_group));
339#if defined(BOTAN_HAS_ECKCDSA)
340 if(alg_name ==
"ECKCDSA")
344#if defined(BOTAN_HAS_GOST_34_10_2001)
345 if(alg_name ==
"GOST-34.10" || alg_name ==
"GOST-34.10-2012-256" || alg_name ==
"GOST-34.10-2012-512")
349#if defined(BOTAN_HAS_SM2)
350 if(alg_name ==
"SM2" || alg_name ==
"SM2_Sig" || alg_name ==
"SM2_Enc")
351 return std::unique_ptr<Private_Key>(
new SM2_PrivateKey(rng, ec_group));
354#if defined(BOTAN_HAS_ECGDSA)
355 if(alg_name ==
"ECGDSA")
362#if defined(BOTAN_HAS_DL_GROUP)
363 if(alg_name ==
"DH" || alg_name ==
"DSA" || alg_name ==
"ElGamal")
365 std::string default_group = (alg_name ==
"DSA") ?
"dsa/botan/2048" :
"modp/ietf/2048";
366 DL_Group modp_group(params.empty() ? default_group : params);
368#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
370 return std::unique_ptr<Private_Key>(
new DH_PrivateKey(rng, modp_group));
373#if defined(BOTAN_HAS_DSA)
374 if(alg_name ==
"DSA")
375 return std::unique_ptr<Private_Key>(
new DSA_PrivateKey(rng, modp_group));
378#if defined(BOTAN_HAS_ELGAMAL)
379 if(alg_name ==
"ElGamal")
387 return std::unique_ptr<Private_Key>();