Botan 3.0.0
Crypto and TLS for C&
elgamal.h
Go to the documentation of this file.
1/*
2* ElGamal
3* (C) 1999-2007,2023 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/pk_keys.h>
12#include <memory>
13
14namespace Botan {
15
16class BigInt;
17class DL_Group;
18class DL_PublicKey;
19class DL_PrivateKey;
20
21/**
22* ElGamal Public Key
23*/
25 {
26 public:
27 bool supports_operation(PublicKeyOperation op) const override
28 {
29 return (op == PublicKeyOperation::Encryption);
30 }
31
32 /**
33 * Load a public key from the ASN.1 encoding
34 * @param alg_id the X.509 algorithm identifier
35 * @param key_bits DER encoded public key bits
36 */
38 std::span<const uint8_t> key_bits);
39
40 /**
41 * Create a public key.
42 * @param group the underlying DL group
43 * @param y the public value y = g^x mod p
44 */
45 ElGamal_PublicKey(const DL_Group& group, const BigInt& y);
46
47 AlgorithmIdentifier algorithm_identifier() const override;
48 std::vector<uint8_t> public_key_bits() const override;
49
50 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
51
52 size_t estimated_strength() const override;
53 size_t key_length() const override;
54
55 std::string algo_name() const override { return "ElGamal"; }
56
57 const BigInt& get_int_field(std::string_view field) const override;
58
59 std::unique_ptr<PK_Ops::Encryption>
60 create_encryption_op(RandomNumberGenerator& rng,
61 std::string_view params,
62 std::string_view provider) const override;
63
64 private:
65 friend class ElGamal_PrivateKey;
66
67 ElGamal_PublicKey() = default;
68
69 ElGamal_PublicKey(std::shared_ptr<const DL_PublicKey> key) :
70 m_public_key(key) {}
71
72 std::shared_ptr<const DL_PublicKey> m_public_key;
73 };
74
75/**
76* ElGamal Private Key
77*/
78
81
83 public ElGamal_PublicKey,
84 public virtual Private_Key
85 {
86 public:
87 /**
88 * Load a private key from the ASN.1 encoding
89 * @param alg_id the X.509 algorithm identifier
90 * @param key_bits DER encoded key bits in ANSI X9.42 format
91 */
93 std::span<const uint8_t> key_bits);
94
95 /**
96 * Create a new random private key.
97 * @param rng random number generator to use
98 * @param group the group to be used in the key
99 */
101 const DL_Group& group);
102
103 /**
104 * Load a private key from the integer encoding
105 * @param group the group to be used in the key
106 * @param private_key the key's secret value
107 */
108 ElGamal_PrivateKey(const DL_Group& group,
109 const BigInt& private_key);
110
111 bool check_key(RandomNumberGenerator& rng, bool) const override;
112
113 std::unique_ptr<Public_Key> public_key() const override;
114
115 secure_vector<uint8_t> private_key_bits() const override;
116
117 secure_vector<uint8_t> raw_private_key_bits() const override;
118
119 const BigInt& get_int_field(std::string_view field) const override;
120
121 std::unique_ptr<PK_Ops::Decryption>
122 create_decryption_op(RandomNumberGenerator& rng,
123 std::string_view params,
124 std::string_view provider) const override;
125 private:
126 std::shared_ptr<const DL_PrivateKey> m_private_key;
127 };
128
130
131}
132
133#endif
static SIMD_4x64 y
std::string algo_name() const override
Definition: elgamal.h:55
bool supports_operation(PublicKeyOperation op) const override
Definition: elgamal.h:27
int(* final)(unsigned char *, CTX *)
#define BOTAN_DIAGNOSTIC_POP
Definition: compiler.h:204
#define BOTAN_DIAGNOSTIC_PUSH
Definition: compiler.h:201
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition: compiler.h:203
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Definition: alg_id.cpp:12
PublicKeyOperation
Definition: pk_keys.h:43
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:64