/* -*-c-*-
- *
- * $Id$
*
* Symmetric cryptography
*
* (c) 2004 Straylight/Edgeware
*/
-/*----- Licensing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
*
* This file is part of the Python interface to Catacomb.
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* Catacomb/Python is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with Catacomb/Python; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
} break;
case KSZ_RANGE: {
keyszrange_pyobj *o =
- PyObject_New(keyszrange_pyobj, keyszrange_pytype);
+ PyObject_New(keyszrange_pyobj, keyszrange_pytype);
o->dfl = k[1];
o->min = k[2];
o->max = k[3];
} break;
case KSZ_SET: {
keyszset_pyobj *o =
- PyObject_New(keyszset_pyobj, keyszset_pytype);
+ PyObject_New(keyszset_pyobj, keyszset_pytype);
int i, n;
o->dfl = k[1];
for (i = 0; k[i + 1]; i++) ;
if (xx < 0) VALERR("key size cannot be negative");
PyList_Append(l, x);
Py_DECREF(x);
- x = 0;
+ x = 0;
}
Py_DECREF(set);
if ((set = PySequence_Tuple(l)) == 0) goto end;
static PyTypeObject keysz_pytype_skel = {
PyObject_HEAD_INIT(0) 0, /* Header */
- "catacomb.KeySZ", /* @tp_name@ */
+ "KeySZ", /* @tp_name@ */
sizeof(keysz_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
static PyTypeObject keyszany_pytype_skel = {
PyObject_HEAD_INIT(0) 0, /* Header */
- "catacomb.KeySZAny", /* @tp_name@ */
+ "KeySZAny", /* @tp_name@ */
sizeof(keysz_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
static PyTypeObject keyszrange_pytype_skel = {
PyObject_HEAD_INIT(0) 0, /* Header */
- "catacomb.KeySZRange", /* @tp_name@ */
+ "KeySZRange", /* @tp_name@ */
sizeof(keyszrange_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
static PyTypeObject keyszset_pytype_skel = {
PyObject_HEAD_INIT(0) 0, /* Header */
- "catacomb.KeySZSet", /* @tp_name@ */
+ "KeySZSet", /* @tp_name@ */
sizeof(keyszset_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
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;
g = PyObject_NEW(gcipher_pyobj, (PyTypeObject *)cobj);
g->c = c;
g->f = f;
- return ((PyObject *)g);
+ return ((PyObject *)g);
}
static PyObject *gcipher_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
GC_INIT(GCCIPHER_CC(ty), k, sz),
f_freeme));
end:
- return (0);
+ return (0);
}
PyObject *gccipher_pywrap(gccipher *cc)
g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
g->ty.ht_type.tp_free = 0;
g->ty.ht_type.tp_new = gcipher_pynew;
- PyType_Ready(&g->ty.ht_type);
+ typeready(&g->ty.ht_type);
return ((PyObject *)g);
}
static PyTypeObject gccipher_pytype_skel = {
PyObject_HEAD_INIT(0) 0, /* Header */
- "catacomb.GCCipher", /* @tp_name@ */
+ "GCCipher", /* @tp_name@ */
sizeof(gccipher_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
static PyTypeObject gcipher_pytype_skel = {
PyObject_HEAD_INIT(0) 0, /* Header */
- "catacomb.GCipher", /* @tp_name@ */
+ "GCipher", /* @tp_name@ */
sizeof(gcipher_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
goto end;
return (ghash_pywrap((PyObject *)ty, GH_INIT(GCHASH_CH(ty)), f_freeme));
end:
- return (0);
+ return (0);
}
PyObject *gchash_pywrap(gchash *ch)
g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
g->ty.ht_type.tp_free = 0;
g->ty.ht_type.tp_new = ghash_pynew;
- PyType_Ready(&g->ty.ht_type);
+ typeready(&g->ty.ht_type);
return ((PyObject *)g);
}
g = PyObject_NEW(ghash_pyobj, (PyTypeObject *)cobj);
g->h = h;
g->f = f;
- return ((PyObject *)g);
+ return ((PyObject *)g);
}
static void ghash_pydealloc(PyObject *me)
static PyTypeObject gchash_pytype_skel = {
PyObject_HEAD_INIT(0) 0, /* Header */
- "catacomb.GCHash", /* @tp_name@ */
+ "GCHash", /* @tp_name@ */
sizeof(gchash_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
static PyTypeObject ghash_pytype_skel = {
PyObject_HEAD_INIT(0) 0, /* Header */
- "catacomb.GHash", /* @tp_name@ */
+ "GHash", /* @tp_name@ */
sizeof(ghash_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
GM_KEY(GCMAC_CM(ty), k, sz),
f_freeme));
end:
- return (0);
+ return (0);
}
static PyObject *gmhash_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
g->ty.ht_type.tp_free = 0;
g->ty.ht_type.tp_new = gmac_pynew;
- PyType_Ready(&g->ty.ht_type);
+ typeready(&g->ty.ht_type);
return ((PyObject *)g);
}
g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
g->ty.ht_type.tp_free = 0;
g->ty.ht_type.tp_new = gmhash_pynew;
- PyType_Ready(&g->ty.ht_type);
+ typeready(&g->ty.ht_type);
g->m = m;
g->f = f;
- return ((PyObject *)g);
+ return ((PyObject *)g);
}
static void gmac_pydealloc(PyObject *me)
static PyTypeObject gcmac_pytype_skel = {
PyObject_HEAD_INIT(0) 0, /* Header */
- "catacomb.GCMAC", /* @tp_name@ */
+ "GCMAC", /* @tp_name@ */
sizeof(gchash_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
static PyTypeObject gmac_pytype_skel = {
PyObject_HEAD_INIT(0) 0, /* Header */
- "catacomb.GMAC", /* @tp_name@ */
+ "GMAC", /* @tp_name@ */
sizeof(gmac_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
static PyTypeObject gmhash_pytype_skel = {
PyObject_HEAD_INIT(0) 0, /* Header */
- "catacomb.GMACHash", /* @tp_name@ */
+ "GMACHash", /* @tp_name@ */
sizeof(ghash_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
#define PRP_ENTRY(PRE, pre) &pre##_prpinfo,
PRPS(PRP_ENTRY)
0
-};
+};
typedef struct gcprp_pyobj {
PyHeapTypeObject ty;
Py_INCREF(me);
return (me);
end:
- return (0);
+ return (0);
}
static void gprp_pydealloc(PyObject *me)
g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
g->ty.ht_type.tp_free = 0;
g->ty.ht_type.tp_new = gprp_pynew;
- PyType_Ready(&g->ty.ht_type);
+ typeready(&g->ty.ht_type);
return ((PyObject *)g);
}
static PyTypeObject gcprp_pytype_skel = {
PyObject_HEAD_INIT(0) 0, /* Header */
- "catacomb.GCPRP", /* @tp_name@ */
+ "GCPRP", /* @tp_name@ */
sizeof(gcprp_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
static PyTypeObject gprp_pytype_skel = {
PyObject_HEAD_INIT(0) 0, /* Header */
- "catacomb.GPRP", /* @tp_name@ */
+ "GPRP", /* @tp_name@ */
sizeof(gprp_pyobj), /* @tp_basicsize@ */
0, /* @tp_itemsize@ */
/*----- 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);
INITTYPE(gmhash, ghash);
INITTYPE(gcprp, type);
INITTYPE(gprp, root);
+ addmethods(methods);
}
GEN(gcciphers, cipher)