Botan: src/pubkey/pk_algs.cpp Source File

Botan 1.10.12

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

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
47 namespace Botan {
48
49 Public_Key* make_public_key(const AlgorithmIdentifier& alg_id,
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
104 Private_Key* make_private_key(const AlgorithmIdentifier& alg_id,
105 const MemoryRegion<byte>& key_bits,
106 RandomNumberGenerator& rng)
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 }
Botan::RandomNumberGenerator
Definition: rng.h:20
Botan::Private_Key
Definition: pk_keys.h:86
Botan::ECDH_PublicKey
Definition: ecdh.h:21
Botan::ElGamal_PublicKey
Definition: elgamal.h:22
Botan::ElGamal_PrivateKey
Definition: elgamal.h:43
Botan::make_private_key
Private_Key * make_private_key(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, RandomNumberGenerator &rng)
Definition: pk_algs.cpp:104
Botan::NR_PrivateKey
Definition: nr.h:43
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:31
Botan::ECDSA_PublicKey
Definition: ecdsa.h:22
Botan::DSA_PrivateKey
Definition: dsa.h:45
Botan::AlgorithmIdentifier::oid
OID oid
Definition: alg_id.h:35
Botan::RW_PublicKey
Definition: rw.h:21
Botan::Decoding_Error
Definition: exceptn.h:138
Botan::RSA_PrivateKey
Definition: rsa.h:47
Botan::MemoryRegion< byte >
Botan
Definition: algo_base.h:14
Botan::NR_PublicKey
Definition: nr.h:21
Botan::Public_Key
Definition: pk_keys.h:21
Botan::DSA_PublicKey
Definition: dsa.h:21
Botan::DH_PublicKey
Definition: dh.h:21
Botan::OID::as_string
std::string as_string() const
Definition: asn1_oid.cpp:50
Botan::RW_PrivateKey
Definition: rw.h:42
Botan::AlgorithmIdentifier
Definition: alg_id.h:20
Botan::ECDSA_PrivateKey
Definition: ecdsa.h:64
Botan::ECDH_PrivateKey
Definition: ecdh.h:65
Botan::DH_PrivateKey
Definition: dh.h:48
Botan::make_public_key
Public_Key * make_public_key(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition: pk_algs.cpp:49
Botan::RSA_PublicKey
Definition: rsa.h:21