5 #ifndef CRYPTOPP_IMPORTS
12 NAMESPACE_BEGIN(CryptoPP)
14 void TestInstantiations_gfpcrypt()
37 int modulusSize = 1024, defaultSubgroupOrderSize;
43 defaultSubgroupOrderSize = 160;
46 defaultSubgroupOrderSize = 224;
49 defaultSubgroupOrderSize = 256;
61 bool pass = DL_GroupParameters_GFP::ValidateGroup(rng, level);
63 pass = pass && ((pSize==1024 && qSize==160) || (pSize==2048 && qSize==224) || (pSize==2048 && qSize==256) || (pSize==3072 && qSize==256));
68 const byte *recoverableMessage,
size_t recoverableMessageLength,
70 byte *representative,
size_t representativeBitLength)
const
72 assert(recoverableMessageLength == 0);
73 assert(hashIdentifier.second == 0);
74 const size_t representativeByteLength = BitsToBytes(representativeBitLength);
76 const size_t paddingLength = SaturatingSubtract(representativeByteLength, digestSize);
78 memset(representative, 0, paddingLength);
79 hash.
TruncatedFinal(representative+paddingLength, STDMIN(representativeByteLength, digestSize));
81 if (digestSize*8 > representativeBitLength)
83 Integer h(representative, representativeByteLength);
84 h >>= representativeByteLength*8 - representativeBitLength;
85 h.Encode(representative, representativeByteLength);
90 const byte *recoverableMessage,
size_t recoverableMessageLength,
92 byte *representative,
size_t representativeBitLength)
const
94 assert(recoverableMessageLength == 0);
95 assert(hashIdentifier.second == 0);
96 const size_t representativeByteLength = BitsToBytes(representativeBitLength);
98 const size_t paddingLength = SaturatingSubtract(representativeByteLength, digestSize);
100 memset(representative, 0, paddingLength);
101 hash.
TruncatedFinal(representative+paddingLength, STDMIN(representativeByteLength, digestSize));
103 if (digestSize*8 >= representativeBitLength)
105 Integer h(representative, representativeByteLength);
106 h >>= representativeByteLength*8 - representativeBitLength + 1;
107 h.Encode(representative, representativeByteLength);
111 bool DL_GroupParameters_IntegerBased::ValidateGroup(
RandomNumberGenerator &rng,
unsigned int level)
const
113 const Integer &p = GetModulus(), &q = GetSubgroupOrder();
122 pass = pass && VerifyPrime(rng, q, level-2) && VerifyPrime(rng, p, level-2);
129 const Integer &p = GetModulus(), &q = GetSubgroupOrder();
132 pass = pass && GetFieldType() == 1 ? g.IsPositive() : g.NotNegative();
133 pass = pass && g < p && !IsIdentity(g);
138 pass = pass && gpc->Exponentiate(GetGroupPrecomputation(),
Integer::One()) == g;
142 if (GetFieldType() == 2)
143 pass = pass && Jacobi(g*g-4, p)==-1;
147 bool fullValidate = (GetFieldType() == 2 && level >= 3) || !FastSubgroupCheckAvailable();
149 if (fullValidate && pass)
151 Integer gp = gpc ? gpc->Exponentiate(GetGroupPrecomputation(), q) : ExponentiateElement(g, q);
152 pass = pass && IsIdentity(gp);
154 else if (GetFieldType() == 1)
155 pass = pass && Jacobi(g, p) == 1;
171 int modulusSize, subgroupOrderSize;
176 if (!alg.
GetIntValue(
"SubgroupOrderSize", subgroupOrderSize))
177 subgroupOrderSize = GetDefaultSubgroupOrderSize(modulusSize);
180 pg.Generate(GetFieldType() == 1 ? 1 : -1, rng, modulusSize, subgroupOrderSize);
189 Integer DL_GroupParameters_IntegerBased::DecodeElement(
const byte *encoded,
bool checkForGroupMembership)
const
191 Integer g(encoded, GetModulus().ByteCount());
192 if (!ValidateElement(1, g, NULL))
203 if (parameters.EndReached())
206 q = ComputeGroupOrder(p) / 2;
209 g.BERDecode(parameters);
210 parameters.MessageEnd();
212 SetModulusAndSubgroupGenerator(p, g);
221 GetSubgroupGenerator().
DEREncode(parameters);
222 parameters.MessageEnd();
227 return GetValueHelper<DL_GroupParameters<Element> >(
this, name, valueType, pValue)
228 CRYPTOPP_GET_FUNCTION_ENTRY(Modulus);
233 AssignFromHelper(
this, source)
234 CRYPTOPP_SET_FUNCTION_ENTRY2(Modulus, SubgroupGenerator)
235 CRYPTOPP_SET_FUNCTION_ENTRY(SubgroupOrder)
239 OID DL_GroupParameters_IntegerBased::GetAlgorithmID()
const
241 return ASN1::id_dsa();
244 void DL_GroupParameters_GFP::SimultaneousExponentiate(Element *results,
const Element &base,
const Integer *exponents,
unsigned int exponentsCount)
const
247 ma.SimultaneousExponentiate(results, base, exponents, exponentsCount);
252 return a_times_b_mod_c(a, b, GetModulus());
258 return ma.CascadeExponentiate(element1, exponent1, element2, exponent2);
261 Integer DL_GroupParameters_IntegerBased::GetMaxExponent()
const
263 return STDMIN(GetSubgroupOrder()-1,
Integer::Power2(2*DiscreteLogWorkFactor(GetFieldType()*GetModulus().BitCount())));
266 unsigned int DL_GroupParameters_IntegerBased::GetDefaultSubgroupOrderSize(
unsigned int modulusSize)
const
268 return 2*DiscreteLogWorkFactor(GetFieldType()*modulusSize);