Botan 1.10.17
Botan::ElGamal_Decryption_Operation Class Reference

#include <elgamal.h>

Inheritance diagram for Botan::ElGamal_Decryption_Operation:
Botan::PK_Ops::Decryption

Public Member Functions

SecureVector< bytedecrypt (const byte msg[], size_t msg_len)
 ElGamal_Decryption_Operation (const ElGamal_PrivateKey &key)
size_t max_input_bits () const

Detailed Description

ElGamal decryption operation

Definition at line 79 of file elgamal.h.

Constructor & Destructor Documentation

◆ ElGamal_Decryption_Operation()

Botan::ElGamal_Decryption_Operation::ElGamal_Decryption_Operation ( const ElGamal_PrivateKey & key)

Definition at line 101 of file elgamal.cpp.

102 {
103 const BigInt& p = key.group_p();
104
105 powermod_x_p = Fixed_Exponent_Power_Mod(key.get_x(), p);
106 mod_p = Modular_Reducer(p);
107
108 BigInt k(global_state().global_rng(), p.bits() - 1);
109 blinder = Blinder(k, powermod_x_p(k), p);
110 }
Library_State & global_state()

References Botan::BigInt::bits(), Botan::Blinder::Blinder(), Botan::Fixed_Exponent_Power_Mod::Fixed_Exponent_Power_Mod(), Botan::DL_Scheme_PrivateKey::get_x(), Botan::global_state(), Botan::DL_Scheme_PublicKey::group_p(), and Botan::Modular_Reducer::Modular_Reducer().

Referenced by Botan::Core_Engine::get_decryption_op().

Member Function Documentation

◆ decrypt()

SecureVector< byte > Botan::ElGamal_Decryption_Operation::decrypt ( const byte msg[],
size_t msg_len )
virtual

Implements Botan::PK_Ops::Decryption.

Definition at line 113 of file elgamal.cpp.

114 {
115 const BigInt& p = mod_p.get_modulus();
116
117 const size_t p_bytes = p.bytes();
118
119 if(msg_len != 2 * p_bytes)
120 throw Invalid_Argument("ElGamal decryption: Invalid message");
121
122 BigInt a(msg, p_bytes);
123 BigInt b(msg + p_bytes, p_bytes);
124
125 if(a >= p || b >= p)
126 throw Invalid_Argument("ElGamal decryption: Invalid message");
127
128 a = blinder.blind(a);
129
130 BigInt r = mod_p.multiply(b, inverse_mod(powermod_x_p(a), p));
131
132 return BigInt::encode(blinder.unblind(r));
133 }
static SecureVector< byte > encode(const BigInt &n, Base base=Binary)
Definition big_code.cpp:64
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition numthry.cpp:314
std::invalid_argument Invalid_Argument
Definition exceptn.h:20

References Botan::BigInt::bytes(), Botan::BigInt::encode(), and Botan::inverse_mod().

◆ max_input_bits()

size_t Botan::ElGamal_Decryption_Operation::max_input_bits ( ) const
inlinevirtual

Implements Botan::PK_Ops::Decryption.

Definition at line 82 of file elgamal.h.

82{ return mod_p.get_modulus().bits() - 1; }

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