summaryrefslogtreecommitdiffstats
path: root/CryptoPP/gfpcrypt.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2013-08-16 12:25:53 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2013-08-16 12:25:53 +0200
commitcbde4f546a3135d9889b37aa227468106958a94a (patch)
tree0444a5f3d1797a01fb6a4c01def9933084652e8c /CryptoPP/gfpcrypt.cpp
parentFeature and bugfixes [SEE DESC] (diff)
parentReplaced E_ENTITY_TYPE_XXX with cMonster::mtXXX. (diff)
downloadcuberite-cbde4f546a3135d9889b37aa227468106958a94a.tar
cuberite-cbde4f546a3135d9889b37aa227468106958a94a.tar.gz
cuberite-cbde4f546a3135d9889b37aa227468106958a94a.tar.bz2
cuberite-cbde4f546a3135d9889b37aa227468106958a94a.tar.lz
cuberite-cbde4f546a3135d9889b37aa227468106958a94a.tar.xz
cuberite-cbde4f546a3135d9889b37aa227468106958a94a.tar.zst
cuberite-cbde4f546a3135d9889b37aa227468106958a94a.zip
Diffstat (limited to 'CryptoPP/gfpcrypt.cpp')
-rw-r--r--CryptoPP/gfpcrypt.cpp38
1 files changed, 18 insertions, 20 deletions
diff --git a/CryptoPP/gfpcrypt.cpp b/CryptoPP/gfpcrypt.cpp
index 6d9ffcebd..e293fc598 100644
--- a/CryptoPP/gfpcrypt.cpp
+++ b/CryptoPP/gfpcrypt.cpp
@@ -30,39 +30,37 @@ void DL_GroupParameters_DSA::GenerateRandom(RandomNumberGenerator &rng, const Na
if (alg.GetValue("Modulus", p) && alg.GetValue("SubgroupGenerator", g))
{
q = alg.GetValueWithDefault("SubgroupOrder", ComputeGroupOrder(p)/2);
+ Initialize(p, q, g);
}
else
{
- int modulusSize = 1024;
+ int modulusSize = 1024, defaultSubgroupOrderSize;
alg.GetIntValue("ModulusSize", modulusSize) || alg.GetIntValue("KeySize", modulusSize);
- if (!DSA::IsValidPrimeLength(modulusSize))
- throw InvalidArgument("DSA: not a valid prime length");
-
- SecByteBlock seed(SHA::DIGESTSIZE);
- Integer h;
- int c;
-
- do
+ switch (modulusSize)
{
- rng.GenerateBlock(seed, SHA::DIGESTSIZE);
- } while (!DSA::GeneratePrimes(seed, SHA::DIGESTSIZE*8, c, p, modulusSize, q));
+ case 1024:
+ defaultSubgroupOrderSize = 160;
+ break;
+ case 2048:
+ defaultSubgroupOrderSize = 224;
+ break;
+ case 3072:
+ defaultSubgroupOrderSize = 256;
+ break;
+ default:
+ throw InvalidArgument("DSA: not a valid prime length");
+ }
- do
- {
- h.Randomize(rng, 2, p-2);
- g = a_exp_b_mod_c(h, (p-1)/q, p);
- } while (g <= 1);
+ DL_GroupParameters_GFP::GenerateRandom(rng, CombinedNameValuePairs(alg, MakeParameters(Name::SubgroupOrderSize(), defaultSubgroupOrderSize, false)));
}
-
- Initialize(p, q, g);
}
bool DL_GroupParameters_DSA::ValidateGroup(RandomNumberGenerator &rng, unsigned int level) const
{
bool pass = DL_GroupParameters_GFP::ValidateGroup(rng, level);
- pass = pass && DSA::IsValidPrimeLength(GetModulus().BitCount());
- pass = pass && GetSubgroupOrder().BitCount() == 160;
+ int pSize = GetModulus().BitCount(), qSize = GetSubgroupOrder().BitCount();
+ pass = pass && ((pSize==1024 && qSize==160) || (pSize==2048 && qSize==224) || (pSize==2048 && qSize==256) || (pSize==3072 && qSize==256));
return pass;
}