chiark / gitweb /
algorithms.c: Add bindings for the key-strength conversion functions.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 26 Feb 2015 19:32:54 +0000 (19:32 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 26 Feb 2015 19:35:59 +0000 (19:35 +0000)
algorithms.c
catacomb/__init__.py

index 16d426d0f8a5b0f3e7a6bf33edc35def295e2dde..b672498ae9db4f31402660b1bc50641f1ab719a0 100644 (file)
@@ -422,6 +422,24 @@ few listed sizes.",
   0                                    /* @tp_is_gc@ */
 };
 
   0                                    /* @tp_is_gc@ */
 };
 
+#define KSZCONVOP(op)                                                  \
+  static PyObject *meth__KeySZ_##op(PyObject *me, PyObject *arg)       \
+  {                                                                    \
+    double x, y;                                                       \
+    if (!PyArg_ParseTuple(arg, "Od:" #op, &me, &x)) return (0);                \
+    y = keysz_##op(x);                                                 \
+    return (PyFloat_FromDouble(y));                                    \
+  }
+KSZCONVOP(fromdl)
+KSZCONVOP(fromschnorr)
+KSZCONVOP(fromif)
+KSZCONVOP(fromec)
+KSZCONVOP(todl)
+KSZCONVOP(toschnorr)
+KSZCONVOP(toif)
+KSZCONVOP(toec)
+#undef KSZCONVOP
+
 /*----- Symmetric encryption ----------------------------------------------*/
 
 PyTypeObject *gccipher_pytype, *gcipher_pytype;
 /*----- Symmetric encryption ----------------------------------------------*/
 
 PyTypeObject *gccipher_pytype, *gcipher_pytype;
@@ -1411,6 +1429,28 @@ static PyTypeObject gprp_pytype_skel = {
 
 /*----- Main code ---------------------------------------------------------*/
 
 
 /*----- Main code ---------------------------------------------------------*/
 
+static PyMethodDef methods[] = {
+#define METHNAME(func) meth_##func
+  METH (_KeySZ_fromdl,         "\
+fromdl(N) -> M: convert integer discrete log field size to work factor")
+  METH (_KeySZ_fromschnorr,    "\
+fromschnorr(N) -> M: convert Schnorr group order to work factor")
+  METH (_KeySZ_fromif,         "\
+fromif(N) -> M: convert integer factorization problem size to work factor")
+  METH (_KeySZ_fromec,         "\
+fromec(N) -> M: convert elliptic curve group order to work factor")
+  METH (_KeySZ_todl,           "\
+todl(N) -> M: convert work factor to integer discrete log field size")
+  METH (_KeySZ_toschnorr,      "\
+toschnorr(N) -> M: convert work factor to Schnorr group order")
+  METH (_KeySZ_toif,           "\
+toif(N) -> M: convert work factor to integer factorization problem size")
+  METH (_KeySZ_toec,           "\
+toec(N) -> M: convert work factor to elliptic curve group order")
+#undef METHNAME
+  { 0 }
+};
+
 void algorithms_pyinit(void)
 {
   INITTYPE(keysz, root);
 void algorithms_pyinit(void)
 {
   INITTYPE(keysz, root);
@@ -1426,6 +1466,7 @@ void algorithms_pyinit(void)
   INITTYPE(gmhash, ghash);
   INITTYPE(gcprp, type);
   INITTYPE(gprp, root);
   INITTYPE(gmhash, ghash);
   INITTYPE(gcprp, type);
   INITTYPE(gprp, root);
+  addmethods(methods);
 }
 
 GEN(gcciphers, cipher)
 }
 
 GEN(gcciphers, cipher)
index 8dac0b4279a2e3209082be52c24b28084ce5b95c..0f0aa9973028bc86809705b3f0cb421cd49a4927 100644 (file)
@@ -47,7 +47,7 @@ def _init():
             'DHInfo', 'BinDHInfo', 'RSAPriv', 'BBSPriv',
             'PrimeFilter', 'RabinMiller',
             'Group', 'GE',
             'DHInfo', 'BinDHInfo', 'RSAPriv', 'BBSPriv',
             'PrimeFilter', 'RabinMiller',
             'Group', 'GE',
-            'KeyData']:
+            'KeySZ', 'KeyData']:
     c = d[i]
     pre = '_' + i + '_'
     plen = len(pre)
     c = d[i]
     pre = '_' + i + '_'
     plen = len(pre)