Botan  1.10.9
def_pk_ops.cpp
Go to the documentation of this file.
1 /*
2 * PK Operations
3 * (C) 1999-2010 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7 
8 #include <botan/internal/core_engine.h>
9 
10 #if defined(BOTAN_HAS_RSA)
11  #include <botan/rsa.h>
12 #endif
13 
14 #if defined(BOTAN_HAS_RW)
15  #include <botan/rw.h>
16 #endif
17 
18 #if defined(BOTAN_HAS_DSA)
19  #include <botan/dsa.h>
20 #endif
21 
22 #if defined(BOTAN_HAS_ECDSA)
23  #include <botan/ecdsa.h>
24 #endif
25 
26 #if defined(BOTAN_HAS_ELGAMAL)
27  #include <botan/elgamal.h>
28 #endif
29 
30 #if defined(BOTAN_HAS_GOST_34_10_2001)
31  #include <botan/gost_3410.h>
32 #endif
33 
34 #if defined(BOTAN_HAS_NYBERG_RUEPPEL)
35  #include <botan/nr.h>
36 #endif
37 
38 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
39  #include <botan/dh.h>
40 #endif
41 
42 #if defined(BOTAN_HAS_ECDH)
43  #include <botan/ecdh.h>
44 #endif
45 
46 namespace Botan {
47 
48 PK_Ops::Encryption*
50  {
51 #if defined(BOTAN_HAS_RSA)
52  if(const RSA_PublicKey* s = dynamic_cast<const RSA_PublicKey*>(&key))
53  return new RSA_Public_Operation(*s);
54 #endif
55 
56 #if defined(BOTAN_HAS_ELGAMAL)
57  if(const ElGamal_PublicKey* s = dynamic_cast<const ElGamal_PublicKey*>(&key))
58  return new ElGamal_Encryption_Operation(*s);
59 #endif
60 
61  return 0;
62  }
63 
66  {
67 #if defined(BOTAN_HAS_RSA)
68  if(const RSA_PrivateKey* s = dynamic_cast<const RSA_PrivateKey*>(&key))
69  return new RSA_Private_Operation(*s);
70 #endif
71 
72 #if defined(BOTAN_HAS_ELGAMAL)
73  if(const ElGamal_PrivateKey* s = dynamic_cast<const ElGamal_PrivateKey*>(&key))
74  return new ElGamal_Decryption_Operation(*s);
75 #endif
76 
77  return 0;
78  }
79 
82  {
83 #if defined(BOTAN_HAS_DIFFIE_HELLMAN)
84  if(const DH_PrivateKey* dh = dynamic_cast<const DH_PrivateKey*>(&key))
85  return new DH_KA_Operation(*dh);
86 #endif
87 
88 #if defined(BOTAN_HAS_ECDH)
89  if(const ECDH_PrivateKey* ecdh = dynamic_cast<const ECDH_PrivateKey*>(&key))
90  return new ECDH_KA_Operation(*ecdh);
91 #endif
92 
93  return 0;
94  }
95 
98  {
99 #if defined(BOTAN_HAS_RSA)
100  if(const RSA_PrivateKey* s = dynamic_cast<const RSA_PrivateKey*>(&key))
101  return new RSA_Private_Operation(*s);
102 #endif
103 
104 #if defined(BOTAN_HAS_RW)
105  if(const RW_PrivateKey* s = dynamic_cast<const RW_PrivateKey*>(&key))
106  return new RW_Signature_Operation(*s);
107 #endif
108 
109 #if defined(BOTAN_HAS_DSA)
110  if(const DSA_PrivateKey* s = dynamic_cast<const DSA_PrivateKey*>(&key))
111  return new DSA_Signature_Operation(*s);
112 #endif
113 
114 #if defined(BOTAN_HAS_ECDSA)
115  if(const ECDSA_PrivateKey* s = dynamic_cast<const ECDSA_PrivateKey*>(&key))
116  return new ECDSA_Signature_Operation(*s);
117 #endif
118 
119 #if defined(BOTAN_HAS_GOST_34_10_2001)
120  if(const GOST_3410_PrivateKey* s =
121  dynamic_cast<const GOST_3410_PrivateKey*>(&key))
122  return new GOST_3410_Signature_Operation(*s);
123 #endif
124 
125 #if defined(BOTAN_HAS_NYBERG_RUEPPEL)
126  if(const NR_PrivateKey* s = dynamic_cast<const NR_PrivateKey*>(&key))
127  return new NR_Signature_Operation(*s);
128 #endif
129 
130  return 0;
131  }
132 
135  {
136 #if defined(BOTAN_HAS_RSA)
137  if(const RSA_PublicKey* s = dynamic_cast<const RSA_PublicKey*>(&key))
138  return new RSA_Public_Operation(*s);
139 #endif
140 
141 #if defined(BOTAN_HAS_RW)
142  if(const RW_PublicKey* s = dynamic_cast<const RW_PublicKey*>(&key))
143  return new RW_Verification_Operation(*s);
144 #endif
145 
146 #if defined(BOTAN_HAS_DSA)
147  if(const DSA_PublicKey* s = dynamic_cast<const DSA_PublicKey*>(&key))
148  return new DSA_Verification_Operation(*s);
149 #endif
150 
151 #if defined(BOTAN_HAS_ECDSA)
152  if(const ECDSA_PublicKey* s = dynamic_cast<const ECDSA_PublicKey*>(&key))
153  return new ECDSA_Verification_Operation(*s);
154 #endif
155 
156 #if defined(BOTAN_HAS_GOST_34_10_2001)
157  if(const GOST_3410_PublicKey* s =
158  dynamic_cast<const GOST_3410_PublicKey*>(&key))
159  return new GOST_3410_Verification_Operation(*s);
160 #endif
161 
162 #if defined(BOTAN_HAS_NYBERG_RUEPPEL)
163  if(const NR_PublicKey* s = dynamic_cast<const NR_PublicKey*>(&key))
164  return new NR_Verification_Operation(*s);
165 #endif
166 
167  return 0;
168  }
169 
170 }
PK_Ops::Decryption * get_decryption_op(const Private_Key &key) const
Definition: def_pk_ops.cpp:65
PK_Ops::Encryption * get_encryption_op(const Public_Key &key) const
Definition: def_pk_ops.cpp:49
PK_Ops::Verification * get_verify_op(const Public_Key &key) const
Definition: def_pk_ops.cpp:134
PK_Ops::Signature * get_signature_op(const Private_Key &key) const
Definition: def_pk_ops.cpp:97
PK_Ops::Key_Agreement * get_key_agreement_op(const Private_Key &key) const
Definition: def_pk_ops.cpp:81
size_t s
Definition: numthry.cpp:27