Botan 1.10.17
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

◆ ElGamal_Encryption_Operation()

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

Member Function Documentation

◆ encrypt()

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.

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 }
size_t dl_work_factor(size_t bits)
std::invalid_argument Invalid_Argument
Definition exceptn.h:20

References Botan::BigInt::binary_encode(), Botan::BigInt::bits(), Botan::BigInt::bytes(), Botan::dl_work_factor(), and Botan::MemoryRegion< T >::size().

◆ max_input_bits()

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; }

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