X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/b2687a0a4b3c5e45cad7c5815a6d3805bfc8d4f1..dc0757504af5097a4bb323d64e429a99f86d1076:/algorithms.c diff --git a/algorithms.c b/algorithms.c index ea52434..4753cf0 100644 --- a/algorithms.c +++ b/algorithms.c @@ -1,7 +1,5 @@ /* -*-c-*- * - * $Id$ - * * Symmetric cryptography * * (c) 2004 Straylight/Edgeware @@ -232,7 +230,7 @@ static PyMemberDef keyszset_pymembers[] = { 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@ */ @@ -280,7 +278,7 @@ static PyTypeObject keysz_pytype_skel = { 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@ */ @@ -328,7 +326,7 @@ static PyTypeObject keyszany_pytype_skel = { 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@ */ @@ -377,7 +375,7 @@ sizes, and requires the key length to be a multiple of some value.", 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@ */ @@ -424,6 +422,24 @@ few listed sizes.", 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; @@ -471,7 +487,7 @@ 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); } @@ -591,7 +607,7 @@ static PyMethodDef gcipher_pymethods[] = { 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@ */ @@ -639,7 +655,7 @@ static PyTypeObject gccipher_pytype_skel = { 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@ */ @@ -715,7 +731,7 @@ 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); } @@ -826,7 +842,7 @@ static PyMethodDef ghash_pymethods[] = { 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@ */ @@ -874,7 +890,7 @@ static PyTypeObject gchash_pytype_skel = { 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@ */ @@ -970,7 +986,7 @@ PyObject *gcmac_pywrap(gcmac *cm) 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); } @@ -990,7 +1006,7 @@ PyObject *gmac_pywrap(PyObject *cobj, gmac *m, unsigned f) 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); @@ -1024,7 +1040,7 @@ static PyGetSetDef gcmac_pygetset[] = { 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@ */ @@ -1072,7 +1088,7 @@ static PyTypeObject gcmac_pytype_skel = { 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@ */ @@ -1120,7 +1136,7 @@ static PyTypeObject gmac_pytype_skel = { 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@ */ @@ -1259,7 +1275,7 @@ static PyObject *gcprp_pywrap(const prpinfo *prp) 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); } @@ -1317,7 +1333,7 @@ static PyMethodDef gprp_pymethods[] = { 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@ */ @@ -1365,7 +1381,7 @@ static PyTypeObject gcprp_pytype_skel = { 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@ */ @@ -1413,6 +1429,28 @@ static PyTypeObject gprp_pytype_skel = { /*----- 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); @@ -1428,6 +1466,7 @@ void algorithms_pyinit(void) INITTYPE(gmhash, ghash); INITTYPE(gcprp, type); INITTYPE(gprp, root); + addmethods(methods); } GEN(gcciphers, cipher)