Botan  1.11.17
pk_algs.cpp
Go to the documentation of this file.
1 /*
2 * PK Key
3 * (C) 1999-2010 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #include <botan/internal/pk_algs.h>
9 #include <botan/oids.h>
10 
11 #if defined(BOTAN_HAS_RSA)
12  #include <botan/rsa.h>
13 #endif
14 
15 #if defined(BOTAN_HAS_DSA)
16  #include <botan/dsa.h>
17 #endif
18 
19 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
20  #include <botan/dh.h>
21 #endif
22 
23 #if defined(BOTAN_HAS_ECDSA)
24  #include <botan/ecdsa.h>
25 #endif
26 
27 #if defined(BOTAN_HAS_GOST_34_10_2001)
28  #include <botan/gost_3410.h>
29 #endif
30 
31 #if defined(BOTAN_HAS_NYBERG_RUEPPEL)
32  #include <botan/nr.h>
33 #endif
34 
35 #if defined(BOTAN_HAS_RW)
36  #include <botan/rw.h>
37 #endif
38 
39 #if defined(BOTAN_HAS_ELGAMAL)
40  #include <botan/elgamal.h>
41 #endif
42 
43 #if defined(BOTAN_HAS_ECDH)
44  #include <botan/ecdh.h>
45 #endif
46 
47 #if defined(BOTAN_HAS_CURVE_25519)
48  #include <botan/curve25519.h>
49 #endif
50 
51 namespace Botan {
52 
54  const secure_vector<byte>& key_bits)
55  {
56  const std::string alg_name = OIDS::lookup(alg_id.oid);
57  if(alg_name == "")
58  throw Decoding_Error("Unknown algorithm OID: " + alg_id.oid.as_string());
59 
60 #if defined(BOTAN_HAS_RSA)
61  if(alg_name == "RSA")
62  return new RSA_PublicKey(alg_id, key_bits);
63 #endif
64 
65 #if defined(BOTAN_HAS_RW)
66  if(alg_name == "RW")
67  return new RW_PublicKey(alg_id, key_bits);
68 #endif
69 
70 #if defined(BOTAN_HAS_DSA)
71  if(alg_name == "DSA")
72  return new DSA_PublicKey(alg_id, key_bits);
73 #endif
74 
75 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
76  if(alg_name == "DH")
77  return new DH_PublicKey(alg_id, key_bits);
78 #endif
79 
80 #if defined(BOTAN_HAS_NYBERG_RUEPPEL)
81  if(alg_name == "NR")
82  return new NR_PublicKey(alg_id, key_bits);
83 #endif
84 
85 #if defined(BOTAN_HAS_ELGAMAL)
86  if(alg_name == "ElGamal")
87  return new ElGamal_PublicKey(alg_id, key_bits);
88 #endif
89 
90 #if defined(BOTAN_HAS_ECDSA)
91  if(alg_name == "ECDSA")
92  return new ECDSA_PublicKey(alg_id, key_bits);
93 #endif
94 
95 #if defined(BOTAN_HAS_GOST_34_10_2001)
96  if(alg_name == "GOST-34.10")
97  return new GOST_3410_PublicKey(alg_id, key_bits);
98 #endif
99 
100 #if defined(BOTAN_HAS_ECDH)
101  if(alg_name == "ECDH")
102  return new ECDH_PublicKey(alg_id, key_bits);
103 #endif
104 
105 #if defined(BOTAN_HAS_CURVE_25519)
106  if(alg_name == "Curve25519")
107  return new Curve25519_PublicKey(alg_id, key_bits);
108 #endif
109 
110  throw Decoding_Error("Unhandled PK algorithm " + alg_name);
111  }
112 
114  const secure_vector<byte>& key_bits,
116  {
117  const std::string alg_name = OIDS::lookup(alg_id.oid);
118  if(alg_name == "")
119  throw Decoding_Error("Unknown algorithm OID: " + alg_id.oid.as_string());
120 
121 #if defined(BOTAN_HAS_RSA)
122  if(alg_name == "RSA")
123  return new RSA_PrivateKey(alg_id, key_bits, rng);
124 #endif
125 
126 #if defined(BOTAN_HAS_RW)
127  if(alg_name == "RW")
128  return new RW_PrivateKey(alg_id, key_bits, rng);
129 #endif
130 
131 #if defined(BOTAN_HAS_DSA)
132  if(alg_name == "DSA")
133  return new DSA_PrivateKey(alg_id, key_bits, rng);
134 #endif
135 
136 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
137  if(alg_name == "DH")
138  return new DH_PrivateKey(alg_id, key_bits, rng);
139 #endif
140 
141 #if defined(BOTAN_HAS_NYBERG_RUEPPEL)
142  if(alg_name == "NR")
143  return new NR_PrivateKey(alg_id, key_bits, rng);
144 #endif
145 
146 #if defined(BOTAN_HAS_ELGAMAL)
147  if(alg_name == "ElGamal")
148  return new ElGamal_PrivateKey(alg_id, key_bits, rng);
149 #endif
150 
151 #if defined(BOTAN_HAS_ECDSA)
152  if(alg_name == "ECDSA")
153  return new ECDSA_PrivateKey(alg_id, key_bits);
154 #endif
155 
156 #if defined(BOTAN_HAS_GOST_34_10_2001)
157  if(alg_name == "GOST-34.10")
158  return new GOST_3410_PrivateKey(alg_id, key_bits);
159 #endif
160 
161 #if defined(BOTAN_HAS_ECDH)
162  if(alg_name == "ECDH")
163  return new ECDH_PrivateKey(alg_id, key_bits);
164 #endif
165 
166 #if defined(BOTAN_HAS_CURVE_25519)
167  if(alg_name == "Curve25519")
168  return new Curve25519_PrivateKey(alg_id, key_bits, rng);
169 #endif
170 
171  throw Decoding_Error("Unhandled PK algorithm " + alg_name);
172  }
173 
174 }
Private_Key * make_private_key(const AlgorithmIdentifier &alg_id, const secure_vector< byte > &key_bits, RandomNumberGenerator &rng)
Definition: pk_algs.cpp:113
Public_Key * make_public_key(const AlgorithmIdentifier &alg_id, const secure_vector< byte > &key_bits)
Definition: pk_algs.cpp:53
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:93
std::string lookup(const OID &oid)
Definition: oids.cpp:155
std::string as_string() const
Definition: asn1_oid.cpp:50