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 283 DL_GroupParameters_GFP::Element DL_GroupParameters_GFP::MultiplyElements(
const Element &a,
const Element &b)
const 285 return a_times_b_mod_c(a, b, GetModulus());
288 DL_GroupParameters_GFP::Element DL_GroupParameters_GFP::CascadeExponentiate(
const Element &element1,
const Integer &exponent1,
const Element &element2,
const Integer &exponent2)
const 299 unsigned int DL_GroupParameters_IntegerBased::GetDefaultSubgroupOrderSize(
unsigned int modulusSize)
const 301 return 2*DiscreteLogWorkFactor(GetFieldType()*modulusSize);
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
An invalid argument was detected.
void BERDecode(BufferedTransformation &bt)
Decode this object from a BufferedTransformation.
virtual Integer GetCofactor() const
Retrieves the cofactor.
Utility functions for the Crypto++ library.
const DL_GroupPrecomputation< Element > & GetGroupPrecomputation() const
Retrieves the group precomputation.
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
Integer GetGroupOrder() const
Retrieves the order of the group.
void DEREncode(BufferedTransformation &bt) const
Encode in DER format.
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.
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
bool IsPositive() const
Determines if the Integer is positive.
bool NotNegative() const
Determines if the Integer is non-negative.
static const Integer & One()
Integer representing 1.
bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const
Check the group for errors.
unsigned int ByteCount() const
Determines the number of bytes required to represent the Integer.
const char * SubgroupOrderSize()
int, in bits
Integer CascadeExponentiate(const Integer &x, const Integer &e1, const Integer &y, const Integer &e2) const
TODO.
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.
virtual const Element & GetSubgroupGenerator() const
Retrieves the subgroup generator.
static Integer Power2(size_t e)
Exponentiates to a power of 2.
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)
bool IsIdentity(const Integer &element) const
Determines if an element is an identity.
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
bool ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const
Exception thrown when an invalid group element is encountered.
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.
Classes and functions for working with ANS.1 objects.
unsigned int BitCount() const
Determines the number of bits required to represent the Integer.
Classes and functions for number theoretic operations.
void Encode(byte *output, size_t outputLen, Signedness sign=UNSIGNED) const
Encode in big-endian format.
bool ValidateElement(unsigned int level, const Integer &element, const DL_FixedBasePrecomputation< Integer > *precomp) const
Check the element for errors.
void EncodeElement(bool reversible, const Element &element, byte *encoded) const
Encodes the element.
void DEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
Integer GetMaxExponent() const
Retrieves the maximum exponent for the group.
const char * Modulus()
Integer.
void SimultaneousExponentiate(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const
Exponentiates a base to multiple exponents in the ring.
Multiple precision integer with arithmetic operations.
const Integer & GetSubgroupOrder() const
Retrieves the subgroup order.
static const Integer & Zero()
Integer representing 0.
unsigned int GetEncodedElementSize(bool reversible) const
Retrieves the encoded element's size.
void BERDecode(const byte *input, size_t inputLen)
Decode from BER format.
Class file for performing modular arithmetic.
Crypto++ library namespace.
bool GetValue(const char *name, T &value) const
Get a named value.
bool GetIntValue(const char *name, int &value) const
Get a named value with type int.
Integer DecodeElement(const byte *encoded, bool checkForGroupMembership) const
Decodes the element.
virtual Element ExponentiateElement(const Element &base, const Integer &exponent) const
Exponentiates an element.
const char * SubgroupOrder()
Integer.
void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg)
bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const
Get a named value.
bool IsOdd() const
Determines if the Integer is odd parity.
Interface for retrieving values given their names.
Template implementing constructors for public key algorithm classes.