From: Mark Wooding Date: Wed, 14 May 2014 20:29:29 +0000 (+0100) Subject: math/mpgen: Fix bugs in slot handling. X-Git-Tag: 2.1.7~8 X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/commitdiff_plain/18533217a1622569aa813252fceef43bae9276e7 math/mpgen: Fix bugs in slot handling. Several bugs, which conspired to cover their tracks. * BaseSlot never actually stored the `omitp' and `allowp' functions. * The MPSlot handler didn't chain up to the BaseSlot implementation of `setup'. * The EllipticCurveGroup's `beta' slot definition's `omitp' and `allowp' functions used the slot name `type' instead of the object. The incorrect lookups were hidden because the functions were never called. The omission of `beta' values for most curve groups should then have caused an error, only MPSlot.setup didn't chain up to the method which would have noticed. --- diff --git a/math/mpgen b/math/mpgen index 683970f2..9a66af17 100644 --- a/math/mpgen +++ b/math/mpgen @@ -383,8 +383,8 @@ class BaseSlot (object): def __init__(me, name, headline = False, omitp = None, allowp = None): me.name = name me.headline = headline - me._omitp = None - me._allowp = None + me._omitp = omitp + me._allowp = allowp def set(me, st, value): if me._allowp and not me._allowp(st, value): raise Exception, "slot `%s' not allowed here" % me.name @@ -408,6 +408,7 @@ class EnumSlot (BaseSlot): class MPSlot (BaseSlot): def setup(me, st): + super(MPSlot, me).setup(st) v = st.d.get(me) if v not in st.mpmap: write_limbs('v%d' % st.nextmp, v) @@ -435,13 +436,16 @@ class EllipticCurveTable (GroupTable): data_t = 'ecdata' entry_t = 'ecentry' tabname = 'ectab' - slots = [EnumSlot('type', 'FTAG', - ['prime', 'niceprime', 'binpoly', 'binnorm'], - headline = True), + _typeslot = EnumSlot('type', 'FTAG', + ['prime', 'niceprime', 'binpoly', 'binnorm'], + headline = True) + slots = [_typeslot, MPSlot('p'), MPSlot('beta', - allowp = lambda st, _: st.d['type'] == 'binnorm', - omitp = lambda st: st.d['type'] != 'binnorm'), + allowp = lambda st, _: + st.d[EllipticCurveTable._typeslot] == 'binnorm', + omitp = lambda st: + st.d[EllipticCurveTable._typeslot] != 'binnorm'), MPSlot('a'), MPSlot('b'), MPSlot('r'), MPSlot('h'), MPSlot('gx'), MPSlot('gy')]