Botan: Botan::ElGamal_Decryption_Operation Class Reference

Botan 1.10.16

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

`#include <elgamal.h>`

Inheritance diagram for Botan::ElGamal_Decryption_Operation:

## Public Member Functions
SecureVector< byte > | decrypt (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.

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 }
Botan::Global_State_Management::global_state
Library_State & global_state()
Definition: global_state.cpp:32

## 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.

References Botan::BigInt::bytes().

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

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