7 #if CRYPTOPP_MSC_VERSION 8 # pragma warning(disable: 4189 4589) 11 #ifndef CRYPTOPP_IMPORTS 23 #if !defined(NDEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING) 24 void TestInstantiations_gfpcrypt()
48 int modulusSize = 1024, defaultSubgroupOrderSize;
54 defaultSubgroupOrderSize = 160;
57 defaultSubgroupOrderSize = 224;
60 defaultSubgroupOrderSize = 256;
74 pass = pass && ((pSize==1024 && qSize==160) || (pSize==2048 && qSize==224) || (pSize==2048 && qSize==256) || (pSize==3072 && qSize==256));
79 const byte *recoverableMessage,
size_t recoverableMessageLength,
81 byte *representative,
size_t representativeBitLength)
const 83 CRYPTOPP_UNUSED(rng), CRYPTOPP_UNUSED(recoverableMessage), CRYPTOPP_UNUSED(recoverableMessageLength);
84 CRYPTOPP_UNUSED(messageEmpty), CRYPTOPP_UNUSED(hashIdentifier);
85 assert(recoverableMessageLength == 0);
86 assert(hashIdentifier.second == 0);
88 const size_t representativeByteLength =
BitsToBytes(representativeBitLength);
92 memset(representative, 0, paddingLength);
95 if (digestSize*8 > representativeBitLength)
97 Integer h(representative, representativeByteLength);
98 h >>= representativeByteLength*8 - representativeBitLength;
99 h.
Encode(representative, representativeByteLength);
104 const byte *recoverableMessage,
size_t recoverableMessageLength,
106 byte *representative,
size_t representativeBitLength)
const 108 CRYPTOPP_UNUSED(rng);CRYPTOPP_UNUSED(recoverableMessage); CRYPTOPP_UNUSED(recoverableMessageLength);
109 CRYPTOPP_UNUSED(hash); CRYPTOPP_UNUSED(hashIdentifier); CRYPTOPP_UNUSED(messageEmpty);
110 CRYPTOPP_UNUSED(representative); CRYPTOPP_UNUSED(representativeBitLength);
112 assert(recoverableMessageLength == 0);
113 assert(hashIdentifier.second == 0);
114 const size_t representativeByteLength =
BitsToBytes(representativeBitLength);
116 const size_t paddingLength =
SaturatingSubtract(representativeByteLength, digestSize);
118 memset(representative, 0, paddingLength);
119 hash.
TruncatedFinal(representative+paddingLength,
STDMIN(representativeByteLength, digestSize));
121 if (digestSize*8 >= representativeBitLength)
123 Integer h(representative, representativeByteLength);
124 h >>= representativeByteLength*8 - representativeBitLength + 1;
125 h.
Encode(representative, representativeByteLength);
160 if (GetFieldType() == 2)
161 pass = pass && Jacobi(g*g-4, p)==-1;
165 bool fullValidate = (GetFieldType() == 2 && level >= 3) || !FastSubgroupCheckAvailable();
167 if (fullValidate && pass)
172 else if (GetFieldType() == 1)
173 pass = pass && Jacobi(g, p) == 1;
189 int modulusSize, subgroupOrderSize;
194 if (!alg.
GetIntValue(
"SubgroupOrderSize", subgroupOrderSize))
195 subgroupOrderSize = GetDefaultSubgroupOrderSize(modulusSize);
198 pg.Generate(GetFieldType() == 1 ? 1 : -1, rng, modulusSize, subgroupOrderSize);
207 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 210 CRYPTOPP_UNUSED(reversible);
211 element.
Encode(encoded, GetModulus().ByteCount());
216 CRYPTOPP_UNUSED(reversible);
223 CRYPTOPP_UNUSED(checkForGroupMembership);
224 Integer g(encoded, GetModulus().ByteCount());
236 if (parameters.EndReached())
239 q = ComputeGroupOrder(p) / 2;
243 parameters.MessageEnd();
245 SetModulusAndSubgroupGenerator(p, g);
253 m_q.DEREncode(parameters);
255 parameters.MessageEnd();
260 return GetValueHelper<DL_GroupParameters<Element> >(
this, name, valueType, pValue)
261 CRYPTOPP_GET_FUNCTION_ENTRY(
Modulus);
266 AssignFromHelper(
this, source)
272 OID DL_GroupParameters_IntegerBased::GetAlgorithmID()
const 274 return ASN1::id_dsa();
277 void DL_GroupParameters_GFP::SimultaneousExponentiate(
Element *results,
const Element &base,
const Integer *exponents,
unsigned int exponentsCount)
const 285 return a_times_b_mod_c(a, b, GetModulus());
299 unsigned int DL_GroupParameters_IntegerBased::GetDefaultSubgroupOrderSize(
unsigned int modulusSize)
const 301 return 2*DiscreteLogWorkFactor(GetFieldType()*modulusSize);
void DEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
bool IsIdentity(const Integer &element) const
Determines if an element is an identity.
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
An invalid argument was detected.
bool ValidateElement(unsigned int level, const Integer &element, const DL_FixedBasePrecomputation< Integer > *precomp) const
Check the element for errors.
Integer CascadeExponentiate(const Integer &x, const Integer &e1, const Integer &y, const Integer &e2) const
TODO.
void BERDecode(BufferedTransformation &bt)
Decode this object from a BufferedTransformation.
Utility functions for the Crypto++ library.
void Encode(byte *output, size_t outputLen, Signedness sign=UNSIGNED) const
Encode in big-endian format.
bool IsOdd() const
Determines if the Integer is odd parity.
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
Integer GetGroupOrder() const
Retrieves the order of the group.
size_t BitsToBytes(size_t bitCount)
Returns the number of 8-bit bytes or octets required for the specified number of bits.
ASN.1 object identifiers for algorthms and schemes.
void EncodeElement(bool reversible, const Element &element, byte *encoded) const
Encodes the element.
Library configuration file.
Ring of congruence classes modulo n.
Interface for random number generators.
Combines two sets of NameValuePairs.
generator of prime numbers of special forms
static const Integer & One()
Integer representing 1.
bool GetIntValue(const char *name, int &value) const
Get a named value with type int.
virtual const Element & GetSubgroupGenerator() const
Retrieves the subgroup generator.
Integer GetMaxExponent() const
Retrieves the maximum exponent for the group.
unsigned int BitCount() const
Determines the number of bits required to represent the Integer.
const char * SubgroupOrderSize()
int, in bits
bool IsPositive() const
Determines if the Integer is positive.
bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const
bool GetValue(const char *name, T &value) const
Get a named value.
int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed=true)
Create an object that implements NameValuePairs.
bool VerifyPrime(RandomNumberGenerator &rng, const Integer &p, unsigned int level=1)
Verifies a prime number.
static Integer Power2(size_t e)
Exponentiates to a power of 2.
const Integer & GetSubgroupOrder() const
Retrieves the subgroup order.
Multiple precision integer with arithmetic operations.
T1 SaturatingSubtract(const T1 &a, const T2 &b)
Performs a saturating subtract clamped at 0.
const char * SubgroupGenerator()
Integer, ECP::Point, or EC2N::Point.
Implementation of schemes based on DL over GF(p)
const DL_GroupPrecomputation< Element > & GetGroupPrecomputation() const
Retrieves the group precomputation.
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
Exception thrown when an invalid group element is encountered.
virtual Integer GetCofactor() const
Retrieves the cofactor.
RandomNumberGenerator & NullRNG()
Random Number Generator that does not produce random numbers.
const T & STDMIN(const T &a, const T &b)
Replacement function for std::min.
unsigned int GetEncodedElementSize(bool reversible) const
Retrieves the encoded element's size.
Classes and functions for working with ANS.1 objects.
Classes and functions for number theoretic operations.
void DEREncode(BufferedTransformation &bt) const
Encode in DER format.
Integer DecodeElement(const byte *encoded, bool checkForGroupMembership) const
Decodes the element.
bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const
Check the group for errors.
const char * Modulus()
Integer.
Multiple precision integer with arithmetic operations.
static const Integer & Zero()
Integer representing 0.
void BERDecode(const byte *input, size_t inputLen)
Decode from BER format.
Class file for performing modular arithmetic.
Crypto++ library namespace.
void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const
Exponentiates a base to multiple exponents in the ring.
const char * SubgroupOrder()
Integer.
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
virtual Element ExponentiateElement(const Element &base, const Integer &exponent) const
Exponentiates an element.
unsigned int ByteCount() const
Determines the number of bytes required to represent the Integer.
bool NotNegative() const
Determines if the Integer is non-negative.
Interface for retrieving values given their names.
Template implementing constructors for public key algorithm classes.