Botan  1.10.9
Public Member Functions | List of all members
Botan::ElGamal_Encryption_Operation Class Reference

#include <elgamal.h>

Inheritance diagram for Botan::ElGamal_Encryption_Operation:
Botan::PK_Ops::Encryption

Public Member Functions

 ElGamal_Encryption_Operation (const ElGamal_PublicKey &key)
 
SecureVector< byteencrypt (const byte msg[], size_t msg_len, RandomNumberGenerator &rng)
 
size_t max_input_bits () const
 

Detailed Description

ElGamal encryption operation

Definition at line 61 of file elgamal.h.

Constructor & Destructor Documentation

Botan::ElGamal_Encryption_Operation::ElGamal_Encryption_Operation ( const ElGamal_PublicKey key)

Definition at line 70 of file elgamal.cpp.

References Botan::DL_Scheme_PublicKey::get_y(), Botan::DL_Scheme_PublicKey::group_g(), and Botan::DL_Scheme_PublicKey::group_p().

71  {
72  const BigInt& p = key.group_p();
73 
74  powermod_g_p = Fixed_Base_Power_Mod(key.group_g(), p);
75  powermod_y_p = Fixed_Base_Power_Mod(key.get_y(), p);
76  mod_p = Modular_Reducer(p);
77  }

Member Function Documentation

SecureVector< byte > Botan::ElGamal_Encryption_Operation::encrypt ( const byte  msg[],
size_t  msg_len,
RandomNumberGenerator rng 
)
virtual

Implements Botan::PK_Ops::Encryption.

Definition at line 80 of file elgamal.cpp.

References Botan::BigInt::binary_encode(), Botan::BigInt::bits(), Botan::BigInt::bytes(), Botan::dl_work_factor(), Botan::Modular_Reducer::get_modulus(), and Botan::Modular_Reducer::multiply().

82  {
83  const BigInt& p = mod_p.get_modulus();
84 
85  BigInt m(msg, msg_len);
86 
87  if(m >= p)
88  throw Invalid_Argument("ElGamal encryption: Input is too large");
89 
90  BigInt k(rng, 2 * dl_work_factor(p.bits()));
91 
92  BigInt a = powermod_g_p(k);
93  BigInt b = mod_p.multiply(m, powermod_y_p(k));
94 
95  SecureVector<byte> output(2*p.bytes());
96  a.binary_encode(&output[p.bytes() - a.bytes()]);
97  b.binary_encode(&output[output.size() / 2 + (p.bytes() - b.bytes())]);
98  return output;
99  }
void binary_encode(byte buf[]) const
Definition: bigint.cpp:340
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
RandomNumberGenerator * rng
Definition: global_rng.cpp:165
BigInt multiply(const BigInt &x, const BigInt &y) const
Definition: reducer.h:31
size_t dl_work_factor(size_t bits)
Definition: workfactor.cpp:14
const BigInt & get_modulus() const
Definition: reducer.h:21
size_t Botan::ElGamal_Encryption_Operation::max_input_bits ( ) const
inlinevirtual

Implements Botan::PK_Ops::Encryption.

Definition at line 64 of file elgamal.h.

64 { return mod_p.get_modulus().bits() - 1; }
size_t bits() const
Definition: bigint.cpp:253
const BigInt & get_modulus() const
Definition: reducer.h:21

The documentation for this class was generated from the following files: