6 #ifndef CRYPTOPP_ELGAMAL_H 7 #define CRYPTOPP_ELGAMAL_H 31 void Derive(
const DL_GroupParameters<Integer> &groupParams, byte *derivedKey,
size_t derivedLength,
const Integer &agreedElement,
const Integer &ephemeralPublicKey,
const NameValuePairs &derivationParams)
const 33 CRYPTOPP_UNUSED(groupParams); CRYPTOPP_UNUSED(ephemeralPublicKey);
34 CRYPTOPP_UNUSED(derivationParams);
35 agreedElement.
Encode(derivedKey, derivedLength);
38 size_t GetSymmetricKeyLength(
size_t plainTextLength)
const 40 CRYPTOPP_UNUSED(plainTextLength);
41 return GetGroupParameters().GetModulus().ByteCount();
44 size_t GetSymmetricCiphertextLength(
size_t plainTextLength)
const 46 unsigned int len = GetGroupParameters().GetModulus().ByteCount();
47 if (plainTextLength <= GetMaxSymmetricPlaintextLength(len))
53 size_t GetMaxSymmetricPlaintextLength(
size_t cipherTextLength)
const 55 unsigned int len = GetGroupParameters().GetModulus().ByteCount();
58 if (cipherTextLength == len)
59 return STDMIN(255U, len-3);
66 CRYPTOPP_UNUSED(parameters);
67 const Integer &p = GetGroupParameters().GetModulus();
72 memcpy(block+modulusLen-2-plainTextLength, plainText, plainTextLength);
73 block[modulusLen-2] = (byte)plainTextLength;
75 a_times_b_mod_c(Integer(key, modulusLen), Integer(block, modulusLen-1), p).
Encode(cipherText, modulusLen);
78 DecodingResult SymmetricDecrypt(
const byte *key,
const byte *cipherText,
size_t cipherTextLength, byte *plainText,
const NameValuePairs ¶meters)
const 80 CRYPTOPP_UNUSED(parameters);
81 const Integer &p = GetGroupParameters().GetModulus();
84 if (cipherTextLength != modulusLen)
87 Integer m = a_times_b_mod_c(Integer(cipherText, modulusLen), Integer(key, modulusLen).InverseMod(p), p);
90 unsigned int plainTextLength = plainText[0];
91 if (plainTextLength > GetMaxSymmetricPlaintextLength(modulusLen))
94 m.
Encode(plainText, plainTextLength);
106 template <
class BASE,
class SCHEME_OPTIONS,
class KEY>
114 size_t FixedMaxPlaintextLength()
const {
return this->MaxPlaintextLength(FixedCiphertextLength());}
115 size_t FixedCiphertextLength()
const {
return this->CiphertextLength(0);}
120 {
return Decrypt(rng, cipherText, FixedCiphertextLength(), plainText);}
139 template <
class BASE>
155 return ASN1::elGamal();
170 template <
class BASE>
186 return ASN1::elGamal();
218 CRYPTOPP_ASSERT(this->GetAbstractGroupParameters().Validate(rng, level));
219 bool pass = this->GetAbstractGroupParameters().Validate(rng, level);
221 const Integer &p = this->GetGroupParameters().GetModulus();
222 const Integer &q = this->GetAbstractGroupParameters().GetSubgroupOrder();
223 const Integer &x = this->GetPrivateExponent();
283 typedef SchemeOptions::PublicKey
PublicKey;
289 CRYPTOPP_STATIC_CONSTEXPR
const char* StaticAlgorithmName() {
return "ElgamalEnc/Crypto++Padding";}
PK_FinalTemplate< ElGamalObjectImpl< DL_EncryptorBase< Integer >, SchemeOptions, SchemeOptions::PublicKey > > Encryptor
Implements PK_Encryptor interface.
ElGamal Public Key adapter.
Diffie-Hellman key agreement algorithm.
Utility functions for the Crypto++ library.
ElGamal key agreement and encryption schemes default implementation.
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
This file contains helper classes/functions for implementing public key algorithms.
DL_CryptoKeys_GFP::GroupParameters GroupParameters
Implements DL_GroupParameters interface.
static Integer CRYPTOPP_API Gcd(const Integer &a, const Integer &n)
Calculate greatest common divisor.
SchemeOptions::GroupParameters GroupParameters
Implements DL_GroupParameters interface.
Converts an enumeration to a type suitable for use as a template parameter.
Abstract base classes that provide a uniform interface to this library.
GF(p) group parameters that default to safe primes.
ASN.1 object identifiers for algorthms and schemes.
Interface for key derivation algorithms used in DL cryptosystems.
Interface for random number generators.
ElGamal key agreement and encryption schemes keys.
Discrete Log (DL) crypto scheme options.
DL_PublicKey_ElGamal< DL_CryptoKeys_GFP::PublicKey > PublicKey
Implements DL_PublicKey interface.
Interface for private keys.
bool IsPositive() const
Determines if the Integer is positive.
static const Integer &CRYPTOPP_API One()
Integer representing 1.
ElGamal encryption scheme with non-standard padding.
unsigned int ByteCount() const
Determines the number of bytes required to represent the Integer.
ElGamal Private Key adapter.
Returns a decoding results.
Multiple precision integer with arithmetic operations.
Discrete Log (DL) base object implementation.
virtual OID GetAlgorithmID() const
Retrieves the OID of the algorithm.
Classes and functions for schemes based on Discrete Logs (DL) over GF(p)
Classes for the DSA signature algorithm.
virtual OID GetAlgorithmID() const
Retrieves the OID of the algorithm.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Classes and functions for working with ANS.1 objects.
void Encode(byte *output, size_t outputLen, Signedness sign=UNSIGNED) const
Encode in big-endian format.
DL_PrivateKey_ElGamal< DL_CryptoKeys_GFP::PrivateKey > PrivateKey
Implements DL_PrivateKey interface.
Multiple precision integer with arithmetic operations.
ElGamal key agreement and encryption schemes base class.
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
Check the key for errors.
Interface for public keys.
Crypto++ library namespace.
Interface for symmetric encryption algorithms used in DL cryptosystems.
PK_FinalTemplate< ElGamalObjectImpl< DL_DecryptorBase< Integer >, SchemeOptions, SchemeOptions::PrivateKey > > Decryptor
Implements PK_Encryptor interface.
Interface for retrieving values given their names.
Template implementing constructors for public key algorithm classes.