7#if CRYPTOPP_MSC_VERSION
8# pragma warning(disable: 4189 4589)
11#ifndef CRYPTOPP_IMPORTS
21NAMESPACE_BEGIN(CryptoPP)
23#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
24void TestInstantiations_gfpcrypt()
48 int modulusSize = 2048, defaultSubgroupOrderSize;
54 defaultSubgroupOrderSize = 160;
57 defaultSubgroupOrderSize = 224;
60 defaultSubgroupOrderSize = 256;
73 CRYPTOPP_ASSERT(pass);
76 pass = pass && ((pSize==1024 && qSize==160) || (pSize==2048 && qSize==224) || (pSize==2048 && qSize==256) || (pSize==3072 && qSize==256));
77 CRYPTOPP_ASSERT(pass);
83 const byte *recoverableMessage,
size_t recoverableMessageLength,
85 byte *representative,
size_t representativeBitLength)
const
87 CRYPTOPP_UNUSED(rng), CRYPTOPP_UNUSED(recoverableMessage), CRYPTOPP_UNUSED(recoverableMessageLength);
88 CRYPTOPP_UNUSED(messageEmpty), CRYPTOPP_UNUSED(hashIdentifier);
89 CRYPTOPP_ASSERT(recoverableMessageLength == 0);
90 CRYPTOPP_ASSERT(hashIdentifier.second == 0);
92 const size_t representativeByteLength =
BitsToBytes(representativeBitLength);
96 memset(representative, 0, paddingLength);
99 if (digestSize*8 > representativeBitLength)
101 Integer h(representative, representativeByteLength);
102 h >>= representativeByteLength*8 - representativeBitLength;
103 h.Encode(representative, representativeByteLength);
108 const byte *recoverableMessage,
size_t recoverableMessageLength,
110 byte *representative,
size_t representativeBitLength)
const
112 CRYPTOPP_UNUSED(rng);CRYPTOPP_UNUSED(recoverableMessage); CRYPTOPP_UNUSED(recoverableMessageLength);
113 CRYPTOPP_UNUSED(hash); CRYPTOPP_UNUSED(hashIdentifier); CRYPTOPP_UNUSED(messageEmpty);
114 CRYPTOPP_UNUSED(representative); CRYPTOPP_UNUSED(representativeBitLength);
116 CRYPTOPP_ASSERT(recoverableMessageLength == 0);
117 CRYPTOPP_ASSERT(hashIdentifier.second == 0);
118 const size_t representativeByteLength =
BitsToBytes(representativeBitLength);
120 const size_t paddingLength =
SaturatingSubtract(representativeByteLength, digestSize);
122 memset(representative, 0, paddingLength);
123 hash.
TruncatedFinal(representative+paddingLength,
STDMIN(representativeByteLength, digestSize));
125 if (digestSize*8 >= representativeBitLength)
127 Integer h(representative, representativeByteLength);
128 h >>= representativeByteLength*8 - representativeBitLength + 1;
129 h.Encode(representative, representativeByteLength);
153 CRYPTOPP_ASSERT(VerifyPrime(rng, q, level-2));
154 CRYPTOPP_ASSERT(VerifyPrime(rng, p, level-2));
156 pass = pass && VerifyPrime(rng, q, level-2) && VerifyPrime(rng, p, level-2);
167 CRYPTOPP_ASSERT(GetFieldType() == 1 ? g.IsPositive() : g.NotNegative());
168 pass = pass && GetFieldType() == 1 ? g.IsPositive() : g.NotNegative();
183 if (GetFieldType() == 2)
185 CRYPTOPP_ASSERT(Jacobi(g*g-4, p)==-1);
186 pass = pass && Jacobi(g*g-4, p)==-1;
193 if (fullValidate && pass)
199 else if (GetFieldType() == 1)
201 CRYPTOPP_ASSERT(Jacobi(g, p) == 1);
202 pass = pass && Jacobi(g, p) == 1;
219 int modulusSize, subgroupOrderSize;
224 if (!alg.
GetIntValue(
"SubgroupOrderSize", subgroupOrderSize))
225 subgroupOrderSize = GetDefaultSubgroupOrderSize(modulusSize);
228 pg.
Generate(GetFieldType() == 1 ? 1 : -1, rng, modulusSize, subgroupOrderSize);
239 CRYPTOPP_UNUSED(reversible);
240 element.Encode(encoded,
GetModulus().ByteCount());
245 CRYPTOPP_UNUSED(reversible);
251 CRYPTOPP_UNUSED(checkForGroupMembership);
267 q = ComputeGroupOrder(p) / 2;
270 g.BERDecode(parameters);
288 return GetValueHelper<DL_GroupParameters<Element> >(
this, name, valueType, pValue)
289 CRYPTOPP_GET_FUNCTION_ENTRY(Modulus);
294 AssignFromHelper(
this, source)
295 CRYPTOPP_SET_FUNCTION_ENTRY2(Modulus, SubgroupGenerator)
296 CRYPTOPP_SET_FUNCTION_ENTRY(SubgroupOrder)
302 return ASN1::id_dsa();
311DL_GroupParameters_GFP::Element DL_GroupParameters_GFP::MultiplyElements(
const Element &a,
const Element &b)
const
316DL_GroupParameters_GFP::Element DL_GroupParameters_GFP::CascadeExponentiate(
const Element &element1,
const Integer &exponent1,
const Element &element2,
const Integer &exponent2)
const
319 return ma.CascadeExponentiate(element1, exponent1, element2, exponent2);
327unsigned int DL_GroupParameters_IntegerBased::GetDefaultSubgroupOrderSize(
unsigned int modulusSize)
const
329 return 2*DiscreteLogWorkFactor(GetFieldType()*modulusSize);
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
Classes and functions for working with ANS.1 objects.
bool EndReached() const
Determine end of stream.
void MessageEnd()
Signals the end of messages to the object.
Combines two sets of NameValuePairs.
void MessageEnd()
Signals the end of messages to the object.
Exception thrown when an invalid group element is encountered.
DL_FixedBasePrecomputation interface.
virtual Element Exponentiate(const DL_GroupPrecomputation< Element > &group, const Integer &exponent) const =0
Exponentiates an element.
bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const
Check the group for errors.
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
Generate a random key or crypto parameters.
void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const
Exponentiates a base to multiple exponents.
void AssignFrom(const NameValuePairs &source)
Initialize or reinitialize this key.
Integer GetGroupOrder() const
Retrieves the order of the group.
virtual void SetModulusAndSubgroupGenerator(const Integer &p, const Integer &g)=0
Set group parameters.
OID GetAlgorithmID() const
Retrieve the OID of the algorithm.
void DEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
Integer GetMaxExponent() const
Retrieve the maximum exponent for the group.
void SetSubgroupOrder(const Integer &q)
Set subgroup order.
Integer DecodeElement(const byte *encoded, bool checkForGroupMembership) const
Decodes the element.
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
Generate a random key.
void BERDecode(BufferedTransformation &bt)
Decode this object from a BufferedTransformation.
virtual const Integer & GetModulus() const =0
Retrieve the modulus for the group.
bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const
Check the group for errors.
void Initialize(const DL_GroupParameters_IntegerBased ¶ms)
Initialize a group parameters over integers.
bool FastSubgroupCheckAvailable() const
Determine if subgroup membership check is fast.
unsigned int GetEncodedElementSize(bool reversible) const
Retrieve the encoded element's size.
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
bool ValidateElement(unsigned int level, const Integer &element, const DL_FixedBasePrecomputation< Integer > *precomp) const
Check the element for errors.
const Integer & GetSubgroupOrder() const
Retrieves the subgroup order.
void EncodeElement(bool reversible, const Element &element, byte *encoded) const
Encodes the element.
const Integer & GetModulus() const
Retrieve the modulus for the group.
virtual Element ExponentiateElement(const Element &base, const Integer &exponent) const
Exponentiates an element.
virtual Integer GetCofactor() const
Retrieves the cofactor.
virtual bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const =0
Check the group for errors.
virtual const Element & GetSubgroupGenerator() const
Retrieves the subgroup generator.
virtual const DL_GroupPrecomputation< Element > & GetGroupPrecomputation() const=0
Retrieves the group precomputation.
virtual const Integer & GetSubgroupOrder() const =0
Retrieves the subgroup order.
virtual bool IsIdentity(const Element &element) const=0
Determines if an element is an identity.
virtual void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs ¶ms=g_nullNameValuePairs)
Generate a random key or crypto parameters.
Multiple precision integer with arithmetic operations.
void DEREncode(BufferedTransformation &bt) const
Encode in DER format.
static const Integer &CRYPTOPP_API Zero()
Integer representing 0.
unsigned int BitCount() const
Determines the number of bits required to represent the Integer.
static const Integer &CRYPTOPP_API One()
Integer representing 1.
static Integer CRYPTOPP_API Power2(size_t e)
Exponentiates to a power of 2.
unsigned int ByteCount() const
Determines the number of bytes required to represent the Integer.
bool IsOdd() const
Determines if the Integer is odd parity.
An invalid argument was detected.
Ring of congruence classes modulo n.
void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const
Exponentiates a base to multiple exponents in the ring.
Interface for retrieving values given their names.
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
bool GetValue(const char *name, T &value) const
Get a named value.
CRYPTOPP_DLL int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
CRYPTOPP_DLL bool GetIntValue(const char *name, int &value) const
Get a named value with type int.
Template implementing constructors for public key algorithm classes.
Generator of prime numbers of special forms.
const Integer & SubPrime() const
Retrieve second prime.
const Integer & Generator() const
Retrieve the generator.
void Generate(signed int delta, RandomNumberGenerator &rng, unsigned int pbits, unsigned qbits)
Generate a Prime and Generator.
const Integer & Prime() const
Retrieve first prime.
Interface for random number generators.
Library configuration file.
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.
T1 SaturatingSubtract(const T1 &a, const T2 &b)
Performs a saturating subtract clamped at 0.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
size_t BitsToBytes(size_t bitCount)
Returns the number of 8-bit bytes or octets required for the specified number of bits.
Class file for performing modular arithmetic.
Classes and functions for number theoretic operations.
ASN.1 object identifiers for algorithms and schemes.