Botan: Botan::ElGamal_Encryption_Operation Class Reference

Botan 1.10.16

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

`#include <elgamal.h>`

Inheritance diagram for Botan::ElGamal_Encryption_Operation:

## Public Member Functions
| ElGamal_Encryption_Operation (const ElGamal_PublicKey &key)
SecureVector< byte > | encrypt (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 | ) |

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

## ◆ 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 }
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::BigInt::binary_encode
void binary_encode(byte buf[]) const
Definition: bigint.cpp:340
Botan::Modular_Reducer::get_modulus
const BigInt & get_modulus() const
Definition: reducer.h:21
Botan::dl_work_factor
size_t dl_work_factor(size_t bits)
Definition: workfactor.cpp:14
Botan::Modular_Reducer::multiply
BigInt multiply(const BigInt &x, const BigInt &y) const
Definition: reducer.h:31

## ◆ 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; }
Botan::BigInt::bits
size_t bits() const
Definition: bigint.cpp:253
Botan::Modular_Reducer::get_modulus
const BigInt & get_modulus() const
Definition: reducer.h:21

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

- src/pubkey/elgamal/elgamal.h
- src/pubkey/elgamal/elgamal.cpp