X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/1e8aaf8b7069139bdbd802e1d419cd10141bebd5..d91d53e0e3b769955cc2adfb8aed493ce84367d3:/catacomb/__init__.py diff --git a/catacomb/__init__.py b/catacomb/__init__.py index 725f6d2..2b433cf 100644 --- a/catacomb/__init__.py +++ b/catacomb/__init__.py @@ -444,6 +444,8 @@ class _tmp: pp.pretty(me.a); pp.text(','); pp.breakable() pp.pretty(me.b) pp.end_group(ind, ')') + def fromstring(str): return _checkend(ECCurve.parse(str)) + fromstring = staticmethod(fromstring) def frombuf(me, s): return ecpt.frombuf(me, s) def fromraw(me, s): @@ -508,6 +510,8 @@ class _tmp: h ^= hash(me.curve) h ^= 2*hash(me.G) & 0xffffffff return h + def fromstring(str): return _checkend(ECInfo.parse(str)) + fromstring = staticmethod(fromstring) def group(me): return ECGroup(me) _augment(ECInfo, _tmp) @@ -1182,13 +1186,19 @@ def findprimitive(mod, hh = [], exp = None, name = 'g', event = pgen_nullev): def kcdsaprime(pbits, qbits, rng = rand, event = pgen_nullev, name = 'p', nsteps = 0): - hbits = pbits - qbits - h = pgen(rng.mp(hbits, 1), name + ' [h]', - PrimeGenStepper(2), PrimeGenTester(), - event, nsteps, RabinMiller.iters(hbits)) - q = pgen(rng.mp(qbits, 1), name, SimulStepper(2 * h, 1, 2), - SimulTester(2 * h, 1), event, nsteps, RabinMiller.iters(qbits)) - p = 2 * q * h + 1 - return p, q, h + hbits = pbits - qbits - 1 + while True: + h = pgen(rng.mp(hbits, 1), name + ' [h]', + PrimeGenStepper(2), PrimeGenTester(), + event, nsteps, RabinMiller.iters(hbits)) + while True: + q0 = rng.mp(qbits, 1) + p0 = 2*q0*h + 1 + if p0.nbits == pbits: break + q = pgen(q0, name, SimulStepper(2*h, 1, 2), + SimulTester(2 * h, 1), event, nsteps, RabinMiller.iters(qbits)) + p = 2*q*h + 1 + if q.nbits == qbits and p.nbits == pbits: return p, q, h + elif nsteps: raise ValueError("prime generation failed") #----- That's all, folks ----------------------------------------------------