Botan  1.10.9
Public Member Functions | List of all members
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

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

Definition at line 101 of file elgamal.cpp.

References Botan::BigInt::bits(), Botan::DL_Scheme_PrivateKey::get_x(), Botan::Global_State_Management::global_state(), and Botan::DL_Scheme_PublicKey::group_p().

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()

Member Function Documentation

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.

References Botan::Blinder::blind(), Botan::BigInt::bytes(), Botan::BigInt::encode(), Botan::Modular_Reducer::get_modulus(), Botan::inverse_mod(), Botan::Modular_Reducer::multiply(), r, and Botan::Blinder::unblind().

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  }
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
static SecureVector< byte > encode(const BigInt &n, Base base=Binary)
Definition: big_code.cpp:64
BigInt multiply(const BigInt &x, const BigInt &y) const
Definition: reducer.h:31
BigInt unblind(const BigInt &x) const
Definition: blinding.cpp:42
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition: numthry.cpp:202
BigInt blind(const BigInt &x) const
Definition: blinding.cpp:29
BigInt r
Definition: numthry.cpp:26
const BigInt & get_modulus() const
Definition: reducer.h:21
size_t bytes() const
Definition: bigint.cpp:245
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; }
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: