6#ifndef CRYPTOPP_ELGAMAL_H
7#define CRYPTOPP_ELGAMAL_H
30 CRYPTOPP_UNUSED(groupParams), CRYPTOPP_UNUSED(ephemeralPublicKey), CRYPTOPP_UNUSED(derivationParams);
31 agreedElement.
Encode(derivedKey, derivedLength);
34 size_t GetSymmetricKeyLength(
size_t plainTextLength)
const
36 CRYPTOPP_UNUSED(plainTextLength);
37 return GetGroupParameters().GetModulus().ByteCount();
40 size_t GetSymmetricCiphertextLength(
size_t plainTextLength)
const
42 unsigned int len = GetGroupParameters().GetModulus().ByteCount();
43 if (plainTextLength <= GetMaxSymmetricPlaintextLength(len))
49 size_t GetMaxSymmetricPlaintextLength(
size_t cipherTextLength)
const
51 unsigned int len = GetGroupParameters().GetModulus().ByteCount();
52 if (cipherTextLength == len)
53 return STDMIN(255U, len-3);
60 CRYPTOPP_UNUSED(parameters);
61 const Integer &p = GetGroupParameters().GetModulus();
66 memcpy(block+modulusLen-2-plainTextLength, plainText, plainTextLength);
67 block[modulusLen-2] = (byte)plainTextLength;
69 a_times_b_mod_c(
Integer(key, modulusLen),
Integer(block, modulusLen-1), p).
Encode(cipherText, modulusLen);
72 DecodingResult SymmetricDecrypt(
const byte *key,
const byte *cipherText,
size_t cipherTextLength,
byte *plainText,
const NameValuePairs ¶meters)
const
74 CRYPTOPP_UNUSED(parameters);
75 const Integer &p = GetGroupParameters().GetModulus();
78 if (cipherTextLength != modulusLen)
81 Integer m = a_times_b_mod_c(
Integer(cipherText, modulusLen),
Integer(key, modulusLen).InverseMod(p), p);
84 unsigned int plainTextLength = plainText[0];
85 if (plainTextLength > GetMaxSymmetricPlaintextLength(modulusLen))
88 m.
Encode(plainText, plainTextLength);
97template <
class BASE,
class SCHEME_OPTIONS,
class KEY>
103 size_t FixedMaxPlaintextLength()
const {
return this->MaxPlaintextLength(FixedCiphertextLength());}
104 size_t FixedCiphertextLength()
const {
return this->CiphertextLength(0);}
109 {
return Decrypt(rng, cipherText, FixedCiphertextLength(), plainText);}
135 CRYPTOPP_STATIC_CONSTEXPR
const char* StaticAlgorithmName() {
return "ElgamalEnc/Crypto++Padding";}
137 typedef SchemeOptions::GroupParameters GroupParameters;
GF(p) group parameters that default to safe primes.
Interface for Discrete Log (DL) group parameters.
Diffie-Hellman key agreement algorithm.
Interface for DL key agreement algorithms.
Interface for key derivation algorithms used in DL cryptosystems.
Discrete Log (DL) base object implementation.
Discrete Log (DL) private key in GF(p) groups.
Discrete Log (DL) public key in GF(p) groups.
Interface for symmetric encryption algorithms used in DL cryptosystems.
ElGamal key agreement and encryption schemes base class.
ElGamal key agreement and encryption schemes default implementation.
Multiple precision integer with arithmetic operations.
unsigned int ByteCount() const
Determines the number of bytes required to represent the Integer.
void Encode(byte *output, size_t outputLen, Signedness sign=UNSIGNED) const
Encode in big-endian format.
Interface for retrieving values given their names.
Template implementing constructors for public key algorithm classes.
Interface for random number generators.
virtual void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
Abstract base classes that provide a uniform interface to this library.
Classes for the DSA signature algorithm.
Classes and functions for schemes based on Discrete Logs (DL) over GF(p)
Multiple precision integer with arithmetic operations.
Utility functions for the Crypto++ library.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
Crypto++ library namespace.
This file contains helper classes/functions for implementing public key algorithms.
Discrete Log (DL) crypto scheme options.
Returns a decoding results.
ElGamal encryption scheme with non-standard padding.
PK_FinalTemplate< ElGamalObjectImpl< DL_EncryptorBase< Integer >, SchemeOptions, SchemeOptions::PublicKey > > Encryptor
implements PK_Encryptor interface
PK_FinalTemplate< ElGamalObjectImpl< DL_DecryptorBase< Integer >, SchemeOptions, SchemeOptions::PrivateKey > > Decryptor
implements PK_Decryptor interface
ElGamal key agreement and encryption schemes keys.
Converts an enumeration to a type suitable for use as a template parameter.