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
17namespace Botan {
18
19/**
20* ElGamal Public Key
21*/
22class BOTAN_DLL ElGamal_PublicKey : public virtual DL_Scheme_PublicKey
23 {
24 public:
25 std::string algo_name() const { return "ElGamal"; }
27
28 size_t max_input_bits() const { return (group_p().bits() - 1); }
29
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:
38 };
39
40/**
41* ElGamal Private Key
42*/
43class 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
50 const MemoryRegion<byte>& key_bits,
52
54 const DL_Group& group,
55 const BigInt& priv_key = 0);
56 };
57
58/**
59* ElGamal encryption operation
60*/
62 {
63 public:
64 size_t max_input_bits() const { return mod_p.get_modulus().bits() - 1; }
65
67
68 SecureVector<byte> encrypt(const byte msg[], size_t msg_len,
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*/
80 {
81 public:
82 size_t max_input_bits() const { return mod_p.get_modulus().bits() - 1; }
83
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
DL_Scheme_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, DL_Group::Format group_format)
Definition dl_algo.cpp:41
const BigInt & group_p() const
Definition dl_algo.h:44
DL_Scheme_PublicKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, DL_Group::Format group_format)
Definition dl_algo.cpp:26
ElGamal_Decryption_Operation(const ElGamal_PrivateKey &key)
Definition elgamal.cpp:101
ElGamal_Encryption_Operation(const ElGamal_PublicKey &key)
Definition elgamal.cpp:70
ElGamal_PrivateKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, RandomNumberGenerator &rng)
Definition elgamal.cpp:46
bool check_key(RandomNumberGenerator &rng, bool) const
Definition elgamal.cpp:58
std::string algo_name() const
Definition elgamal.h:25
size_t max_input_bits() const
Definition elgamal.h:28
DL_Group::Format group_format() const
Definition elgamal.h:26
ElGamal_PublicKey(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits)
Definition elgamal.h:30