Botan 1.10.17
pk_algs.cpp
Go to the documentation of this file.
1/*
2* PK Key
3* (C) 1999-2010 Jack Lloyd
4*
5* Distributed under the terms of the Botan license
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
47namespace Botan {
48
50 const MemoryRegion<byte>& key_bits)
51 {
52 const std::string alg_name = OIDS::lookup(alg_id.oid);
53 if(alg_name == "")
54 throw Decoding_Error("Unknown algorithm OID: " + alg_id.oid.as_string());
55
56#if defined(BOTAN_HAS_RSA)
57 if(alg_name == "RSA")
58 return new RSA_PublicKey(alg_id, key_bits);
59#endif
60
61#if defined(BOTAN_HAS_RW)
62 if(alg_name == "RW")
63 return new RW_PublicKey(alg_id, key_bits);
64#endif
65
66#if defined(BOTAN_HAS_DSA)
67 if(alg_name == "DSA")
68 return new DSA_PublicKey(alg_id, key_bits);
69#endif
70
71#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
72 if(alg_name == "DH")
73 return new DH_PublicKey(alg_id, key_bits);
74#endif
75
76#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
77 if(alg_name == "NR")
78 return new NR_PublicKey(alg_id, key_bits);
79#endif
80
81#if defined(BOTAN_HAS_ELGAMAL)
82 if(alg_name == "ElGamal")
83 return new ElGamal_PublicKey(alg_id, key_bits);
84#endif
85
86#if defined(BOTAN_HAS_ECDSA)
87 if(alg_name == "ECDSA")
88 return new ECDSA_PublicKey(alg_id, key_bits);
89#endif
90
91#if defined(BOTAN_HAS_GOST_34_10_2001)
92 if(alg_name == "GOST-34.10")
93 return new GOST_3410_PublicKey(alg_id, key_bits);
94#endif
95
96#if defined(BOTAN_HAS_ECDH)
97 if(alg_name == "ECDH")
98 return new ECDH_PublicKey(alg_id, key_bits);
99#endif
100
101 return 0;
102 }
103
105 const MemoryRegion<byte>& key_bits,
107 {
108 const std::string alg_name = OIDS::lookup(alg_id.oid);
109 if(alg_name == "")
110 throw Decoding_Error("Unknown algorithm OID: " + alg_id.oid.as_string());
111
112#if defined(BOTAN_HAS_RSA)
113 if(alg_name == "RSA")
114 return new RSA_PrivateKey(alg_id, key_bits, rng);
115#endif
116
117#if defined(BOTAN_HAS_RW)
118 if(alg_name == "RW")
119 return new RW_PrivateKey(alg_id, key_bits, rng);
120#endif
121
122#if defined(BOTAN_HAS_DSA)
123 if(alg_name == "DSA")
124 return new DSA_PrivateKey(alg_id, key_bits, rng);
125#endif
126
127#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
128 if(alg_name == "DH")
129 return new DH_PrivateKey(alg_id, key_bits, rng);
130#endif
131
132#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
133 if(alg_name == "NR")
134 return new NR_PrivateKey(alg_id, key_bits, rng);
135#endif
136
137#if defined(BOTAN_HAS_ELGAMAL)
138 if(alg_name == "ElGamal")
139 return new ElGamal_PrivateKey(alg_id, key_bits, rng);
140#endif
141
142#if defined(BOTAN_HAS_ECDSA)
143 if(alg_name == "ECDSA")
144 return new ECDSA_PrivateKey(alg_id, key_bits);
145#endif
146
147#if defined(BOTAN_HAS_GOST_34_10_2001)
148 if(alg_name == "GOST-34.10")
149 return new GOST_3410_PrivateKey(alg_id, key_bits);
150#endif
151
152#if defined(BOTAN_HAS_ECDH)
153 if(alg_name == "ECDH")
154 return new ECDH_PrivateKey(alg_id, key_bits);
155#endif
156
157 return 0;
158 }
159
160}
DH_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, RandomNumberGenerator &rng)
Definition dh.cpp:60
DSA_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, RandomNumberGenerator &rng)
Definition dsa.cpp:44
ECDH_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition ecdh.h:71
ECDSA_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition ecdsa.h:74
ElGamal_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, RandomNumberGenerator &rng)
Definition elgamal.cpp:46
NR_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, RandomNumberGenerator &rng)
Definition nr.cpp:50
std::string as_string() const
Definition asn1_oid.cpp:50
RSA_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, RandomNumberGenerator &rng)
Definition rsa.h:53
RW_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, RandomNumberGenerator &rng)
Definition rw.h:46
std::string lookup(const OID &oid)
Definition oids.cpp:31
Private_Key * make_private_key(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, RandomNumberGenerator &rng)
Definition pk_algs.cpp:104
Public_Key * make_public_key(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition pk_algs.cpp:49
Decoding_Error(const std::string &name)
Definition exceptn.h:140