Botan: src/pubkey/elgamal/elgamal.h Source File

Botan 1.10.17

elgamal.h
Go to the documentation of this file.
1 /*
2 * ElGamal
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_ELGAMAL_H__
9 #define BOTAN_ELGAMAL_H__
10
11 #include <botan/dl_algo.h>
12 #include <botan/numthry.h>
13 #include <botan/reducer.h>
14 #include <botan/blinding.h>
15 #include <botan/pk_ops.h>
16
17 namespace Botan {
18
19 /**
20 * ElGamal Public Key
21 */
22 class BOTAN_DLL ElGamal_PublicKey : public virtual DL_Scheme_PublicKey
23 {
24 public:
25 std::string algo_name() const { return "ElGamal"; }
26 DL_Group::Format group_format() const { return DL_Group::ANSI_X9_42; }
27
28 size_t max_input_bits() const { return (group_p().bits() - 1); }
29
30 ElGamal_PublicKey(const AlgorithmIdentifier& alg_id,
31 const MemoryRegion<byte>& key_bits) :
32 DL_Scheme_PublicKey(alg_id, key_bits, DL_Group::ANSI_X9_42)
33 {}
34
35 ElGamal_PublicKey(const DL_Group& group, const BigInt& y);
36 protected:
37 ElGamal_PublicKey() {}
38 };
39
40 /**
41 * ElGamal Private Key
42 */
43 class BOTAN_DLL ElGamal_PrivateKey : public ElGamal_PublicKey,
44 public virtual DL_Scheme_PrivateKey
45 {
46 public:
47 bool check_key(RandomNumberGenerator& rng, bool) const;
48
49 ElGamal_PrivateKey(const AlgorithmIdentifier& alg_id,
50 const MemoryRegion<byte>& key_bits,
51 RandomNumberGenerator& rng);
52
53 ElGamal_PrivateKey(RandomNumberGenerator& rng,
54 const DL_Group& group,
55 const BigInt& priv_key = 0);
56 };
57
58 /**
59 * ElGamal encryption operation
60 */
61 class BOTAN_DLL ElGamal_Encryption_Operation : public PK_Ops::Encryption
62 {
63 public:
64 size_t max_input_bits() const { return mod_p.get_modulus().bits() - 1; }
65
66 ElGamal_Encryption_Operation(const ElGamal_PublicKey& key);
67
68 SecureVector<byte> encrypt(const byte msg[], size_t msg_len,
69 RandomNumberGenerator& rng);
70
71 private:
72 Fixed_Base_Power_Mod powermod_g_p, powermod_y_p;
73 Modular_Reducer mod_p;
74 };
75
76 /**
77 * ElGamal decryption operation
78 */
79 class BOTAN_DLL ElGamal_Decryption_Operation : public PK_Ops::Decryption
80 {
81 public:
82 size_t max_input_bits() const { return mod_p.get_modulus().bits() - 1; }
83
84 ElGamal_Decryption_Operation(const ElGamal_PrivateKey& key);
85
86 SecureVector<byte> decrypt(const byte msg[], size_t msg_len);
87 private:
88 Fixed_Exponent_Power_Mod powermod_x_p;
89 Modular_Reducer mod_p;
90 Blinder blinder;
91 };
92
93 }
94
95 #endif
Botan::DL_Scheme_PrivateKey
Definition: dl_algo.h:85
Botan::Fixed_Base_Power_Mod
Definition: pow_mod.h:87
Botan::BigInt
Definition: bigint.h:22
Botan::ElGamal_PublicKey::ElGamal_PublicKey
ElGamal_PublicKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition: elgamal.h:30
Botan::RandomNumberGenerator
Definition: rng.h:20
Botan::ElGamal_PublicKey
Definition: elgamal.h:22
Botan::ElGamal_Decryption_Operation::max_input_bits
size_t max_input_bits() const
Definition: elgamal.h:82
Botan::DL_Scheme_PublicKey
Definition: dl_algo.h:20
Botan::ElGamal_PrivateKey
Definition: elgamal.h:43
Botan::ElGamal_PublicKey::ElGamal_PublicKey
ElGamal_PublicKey()
Definition: elgamal.h:37
Botan::ElGamal_PublicKey::group_format
DL_Group::Format group_format() const
Definition: elgamal.h:26
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::DL_Group
Definition: dl_group.h:20
Botan::DL_Group::Format
Format
Definition: dl_group.h:44
Botan::ElGamal_PublicKey::max_input_bits
size_t max_input_bits() const
Definition: elgamal.h:28
Botan::ElGamal_Decryption_Operation
Definition: elgamal.h:79
Botan::MemoryRegion< byte >
Botan
Definition: algo_base.h:14
Botan::DL_Group::ANSI_X9_42
Definition: dl_group.h:45
Botan::Blinder
Definition: blinding.h:19
Botan::AlgorithmIdentifier
Definition: alg_id.h:20
Botan::Fixed_Exponent_Power_Mod
Definition: pow_mod.h:73
Botan::ElGamal_Encryption_Operation
Definition: elgamal.h:61
Botan::SecureVector< byte >
Botan::PK_Ops::Decryption
Definition: pk_ops.h:35
Botan::PK_Ops::Encryption
Definition: pk_ops.h:21
Botan::Modular_Reducer
Definition: reducer.h:18
Botan::ElGamal_Encryption_Operation::max_input_bits
size_t max_input_bits() const
Definition: elgamal.h:64
Botan::ElGamal_PublicKey::algo_name
std::string algo_name() const
Definition: elgamal.h:25