6 #ifndef CRYPTOPP_ELGAMAL_H 7 #define CRYPTOPP_ELGAMAL_H 24 void Derive(
const DL_GroupParameters<Integer> &groupParams, byte *derivedKey,
size_t derivedLength,
const Integer &agreedElement,
const Integer &ephemeralPublicKey,
const NameValuePairs &derivationParams)
const 26 CRYPTOPP_UNUSED(groupParams), CRYPTOPP_UNUSED(ephemeralPublicKey), CRYPTOPP_UNUSED(derivationParams);
27 agreedElement.
Encode(derivedKey, derivedLength);
30 size_t GetSymmetricKeyLength(
size_t plainTextLength)
const 32 CRYPTOPP_UNUSED(plainTextLength);
33 return GetGroupParameters().GetModulus().ByteCount();
36 size_t GetSymmetricCiphertextLength(
size_t plainTextLength)
const 38 unsigned int len = GetGroupParameters().GetModulus().ByteCount();
39 if (plainTextLength <= GetMaxSymmetricPlaintextLength(len))
45 size_t GetMaxSymmetricPlaintextLength(
size_t cipherTextLength)
const 47 unsigned int len = GetGroupParameters().GetModulus().ByteCount();
48 if (cipherTextLength == len)
49 return STDMIN(255U, len-3);
56 CRYPTOPP_UNUSED(parameters);
57 const Integer &p = GetGroupParameters().GetModulus();
62 memcpy(block+modulusLen-2-plainTextLength, plainText, plainTextLength);
63 block[modulusLen-2] = (byte)plainTextLength;
65 a_times_b_mod_c(Integer(key, modulusLen), Integer(block, modulusLen-1), p).
Encode(cipherText, modulusLen);
68 DecodingResult SymmetricDecrypt(
const byte *key,
const byte *cipherText,
size_t cipherTextLength, byte *plainText,
const NameValuePairs ¶meters)
const 70 CRYPTOPP_UNUSED(parameters);
71 const Integer &p = GetGroupParameters().GetModulus();
74 if (cipherTextLength != modulusLen)
77 Integer m = a_times_b_mod_c(Integer(cipherText, modulusLen), Integer(key, modulusLen).InverseMod(p), p);
80 unsigned int plainTextLength = plainText[0];
81 if (plainTextLength > GetMaxSymmetricPlaintextLength(modulusLen))
84 m.
Encode(plainText, plainTextLength);
90 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 95 template <
class BASE,
class SCHEME_OPTIONS,
class KEY>
99 size_t FixedMaxPlaintextLength()
const {
return this->MaxPlaintextLength(FixedCiphertextLength());}
100 size_t FixedCiphertextLength()
const {
return this->CiphertextLength(0);}
105 {
return Decrypt(rng, cipherText, FixedCiphertextLength(), plainText);}
107 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 130 CRYPTOPP_CONSTEXPR
static const char *StaticAlgorithmName() {
return "ElgamalEnc/Crypto++Padding";}
132 typedef SchemeOptions::GroupParameters GroupParameters;
PK_FinalTemplate< ElGamalObjectImpl< DL_EncryptorBase< Integer >, SchemeOptions, SchemeOptions::PublicKey > > Encryptor
implements PK_Encryptor interface
Utility functions for the Crypto++ library.
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
This file contains helper classes/functions for implementing public key algorithms.
Converts a typename to an enumerated value.
Abstract base classes that provide a uniform interface to this library.
GF(p) group parameters that default to same primes.
Interface for key derivation algorithms used in DL cryptosystems.
Interface for random number generators.
Discrete Log (DL) crypto scheme options.
ElGamal encryption scheme with non-standard padding.
unsigned int ByteCount() const
Determines the number of bytes required to represent the Integer.
Returns a decoding results.
Multiple precision integer with arithmetic operations.
Discrete Log (DL) base object implementation.
Implementation of schemes based on DL over GF(p)
Classes for the DSA signature algorithm.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
void Encode(byte *output, size_t outputLen, Signedness sign=UNSIGNED) const
Encode in big-endian format.
Multiple precision integer with arithmetic operations.
Crypto++ library namespace.
Interface for symmetric encryption algorithms used in DL cryptosystems.
PK_FinalTemplate< ElGamalObjectImpl< DL_DecryptorBase< Integer >, SchemeOptions, SchemeOptions::PrivateKey > > Decryptor
implements PK_Decryptor interface
Interface for retrieving values given their names.
Template implementing constructors for public key algorithm classes.