Botan  2.7.0
Crypto and TLS for C++11
elgamal.h
Go to the documentation of this file.
1 /*
2 * ElGamal
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_ELGAMAL_H_
9 #define BOTAN_ELGAMAL_H_
10 
11 #include <botan/dl_algo.h>
12 
13 namespace Botan {
14 
15 /**
16 * ElGamal Public Key
17 */
19  {
20  public:
21  std::string algo_name() const override { return "ElGamal"; }
22  DL_Group::Format group_format() const override { return DL_Group::ANSI_X9_42; }
23 
24  /**
25  * Load a public key.
26  * @param alg_id the X.509 algorithm identifier
27  * @param key_bits DER encoded public key bits
28  */
30  const std::vector<uint8_t>& key_bits) :
31  DL_Scheme_PublicKey(alg_id, key_bits, DL_Group::ANSI_X9_42)
32  {}
33 
34  /**
35  * Create a public key.
36  * @param group the underlying DL group
37  * @param y the public value y = g^x mod p
38  */
39  ElGamal_PublicKey(const DL_Group& group, const BigInt& y);
40 
41  std::unique_ptr<PK_Ops::Encryption>
42  create_encryption_op(RandomNumberGenerator& rng,
43  const std::string& params,
44  const std::string& provider) const override;
45 
46  protected:
47  ElGamal_PublicKey() = default;
48  };
49 
50 /**
51 * ElGamal Private Key
52 */
54  public virtual DL_Scheme_PrivateKey
55  {
56  public:
57  bool check_key(RandomNumberGenerator& rng, bool) const override;
58 
59  /**
60  * Load a private key.
61  * @param alg_id the X.509 algorithm identifier
62  * @param key_bits DER encoded key bits in ANSI X9.42 format
63  */
65  const secure_vector<uint8_t>& key_bits);
66 
67  /**
68  * Create a private key.
69  * @param rng random number generator to use
70  * @param group the group to be used in the key
71  * @param priv_key the key's secret value (or if zero, generate a new key)
72  */
74  const DL_Group& group,
75  const BigInt& priv_key = 0);
76 
77  std::unique_ptr<PK_Ops::Decryption>
78  create_decryption_op(RandomNumberGenerator& rng,
79  const std::string& params,
80  const std::string& provider) const override;
81  };
82 
83 }
84 
85 #endif
DL_Group::Format group_format() const override
Definition: elgamal.h:22
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
ElGamal_PublicKey(const AlgorithmIdentifier &alg_id, const std::vector< uint8_t > &key_bits)
Definition: elgamal.h:29
Definition: alg_id.cpp:13
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
std::string algo_name() const override
Definition: elgamal.h:21