chiark / gitweb /
math/mpgen: Fix bugs in slot handling.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 14 May 2014 20:29:29 +0000 (21:29 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 14 May 2014 20:36:18 +0000 (21:36 +0100)
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.

math/mpgen

index 683970f243a94be75d3e7310506bb4ada9c60a1c..9a66af1799e532ae28772d3d46d43944c68d7ed8 100644 (file)
@@ -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')]