7 #if CRYPTOPP_MSC_VERSION
8 # pragma warning(disable: 4189 4589)
11 #ifndef CRYPTOPP_IMPORTS
23 #if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
24 void TestInstantiations_gfpcrypt()
28 DSA::Signer test5(
NullRNG(), 100);
29 DSA::Signer test2(test5);
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);
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);
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);
131 const Integer &p = GetModulus(), &q = GetSubgroupOrder();
147 const Integer &p = GetModulus(), &q = GetSubgroupOrder();
150 pass = pass && GetFieldType() == 1 ? g.IsPositive() : g.NotNegative();
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;
242 g.BERDecode(parameters);
243 parameters.MessageEnd();
245 SetModulusAndSubgroupGenerator(p, g);
255 parameters.MessageEnd();
260 return GetValueHelper<DL_GroupParameters<Element> >(
this, name, valueType, pValue)
261 CRYPTOPP_GET_FUNCTION_ENTRY(Modulus);
266 AssignFromHelper(
this, source)
267 CRYPTOPP_SET_FUNCTION_ENTRY2(Modulus, SubgroupGenerator)
268 CRYPTOPP_SET_FUNCTION_ENTRY(SubgroupOrder)
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
280 ma.SimultaneousExponentiate(results, base, exponents, exponentsCount);
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
291 return ma.CascadeExponentiate(element1, exponent1, element2, exponent2);
294 Integer DL_GroupParameters_IntegerBased::GetMaxExponent()
const
296 return STDMIN(GetSubgroupOrder()-1,
Integer::Power2(2*DiscreteLogWorkFactor(GetFieldType()*GetModulus().BitCount())));
299 unsigned int DL_GroupParameters_IntegerBased::GetDefaultSubgroupOrderSize(
unsigned int modulusSize)
const
301 return 2*DiscreteLogWorkFactor(GetFieldType()*modulusSize);