X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/catacomb-python/blobdiff_plain/838ab173c38713fbf8aebde9417ff6b78275b579..4d09d07e731d0454bf9f103ba486f06edcc6c2df:/algorithms.c diff --git a/algorithms.c b/algorithms.c index e55456e..3e1866f 100644 --- a/algorithms.c +++ b/algorithms.c @@ -83,11 +83,11 @@ PyObject *keysz_pywrap(const octet *k) static PyObject *keyszany_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) { - char *kwlist[] = { "default", 0 }; + static const char *const kwlist[] = { "default", 0 }; int dfl; keysz_pyobj *o; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "i:new", kwlist, &dfl)) + if (!PyArg_ParseTupleAndKeywords(arg, kw, "i:new", KWLIST, &dfl)) goto end; if (dfl < 0) VALERR("key size cannot be negative"); o = (keysz_pyobj *)ty->tp_alloc(ty, 0); @@ -100,11 +100,11 @@ end: static PyObject *keyszrange_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) { - char *kwlist[] = { "default", "min", "max", "mod", 0 }; + static const char *const kwlist[] = { "default", "min", "max", "mod", 0 }; int dfl, min = 0, max = 0, mod = 1; keyszrange_pyobj *o; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "i|iii:new", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "i|iii:new", KWLIST, &dfl, &min, &max, &mod)) goto end; if (dfl < 0 || min < 0) VALERR("key size cannot be negative"); @@ -124,13 +124,13 @@ end: static PyObject *keyszset_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) { - char *kwlist[] = { "default", "set", 0 }; + static const char *const kwlist[] = { "default", "set", 0 }; int dfl, i, n, xx; PyObject *set = 0; PyObject *x = 0, *l = 0; keyszset_pyobj *o = 0; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "i|O:new", kwlist, &dfl, &set)) + if (!PyArg_ParseTupleAndKeywords(arg, kw, "i|O:new", KWLIST, &dfl, &set)) goto end; if (!set) set = PyTuple_New(0); else Py_INCREF(set); @@ -261,7 +261,7 @@ static PyTypeObject keysz_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"Key size constraints.", +"Key size constraints. Abstract.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -309,7 +309,8 @@ static PyTypeObject keyszany_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"Key size constraints. This object imposes no constraints on size.", +"KeySZAny(DEFAULT)\n\ + Key size constraints. This object imposes no constraints on size.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -357,8 +358,9 @@ static PyTypeObject keyszrange_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"Key size constraints. This object asserts minimum and maximum (if\n\ -sizes, and requires the key length to be a multiple of some value.", +"KeySZRange(DEFAULT, [min = 0], [max = 0], [mod = 1])\n\ + Key size constraints. Key size must be between MIN and MAX inclusive,\n\ + and be a multiple of MOD.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -406,8 +408,8 @@ static PyTypeObject keyszset_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"Key size constraints. This object requires the key to be one of a\n\ -few listed sizes.", +"KeySZSet(DEFAULT, SEQ)\n\ + Key size constraints. Key size must be DEFAULT or one in SEQ.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -468,11 +470,11 @@ PyObject *gcipher_pywrap(PyObject *cobj, gcipher *c, unsigned f) static PyObject *gcipher_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) { - char *kwlist[] = { "k", 0 }; + static const char *const kwlist[] = { "k", 0 }; char *k; Py_ssize_t sz; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#:new", kwlist, &k, &sz)) + if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#:new", KWLIST, &k, &sz)) goto end; if (keysz(sz, GCCIPHER_CC(ty)->keysz) != sz) VALERR("bad key length"); return (gcipher_pywrap((PyObject *)ty, @@ -720,8 +722,8 @@ CONVFUNC(ghash, ghash *, GHASH_H) static PyObject *ghash_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) { - char *kwlist[] = { 0 }; - if (!PyArg_ParseTupleAndKeywords(arg, kw, ":new", kwlist)) + static const char *const kwlist[] = { 0 }; + if (!PyArg_ParseTupleAndKeywords(arg, kw, ":new", KWLIST)) goto end; return (ghash_pywrap((PyObject *)ty, GH_INIT(GCHASH_CH(ty)), f_freeme)); end: @@ -958,11 +960,11 @@ CONVFUNC(gmhash, ghash *, GHASH_H) static PyObject *gmac_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) { - char *kwlist[] = { "k", 0 }; + static const char *const kwlist[] = { "k", 0 }; char *k; Py_ssize_t sz; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#:new", kwlist, &k, &sz)) + if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#:new", KWLIST, &k, &sz)) goto end; if (keysz(sz, GCMAC_CM(ty)->keysz) != sz) VALERR("bad key length"); return (gmac_pywrap((PyObject *)ty, @@ -974,10 +976,10 @@ end: static PyObject *gmhash_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) { - char *kwlist[] = { 0 }; + static const char *const kwlist[] = { 0 }; ghash_pyobj *g; - if (!PyArg_ParseTupleAndKeywords(arg, kw, ":new", kwlist)) return (0); + if (!PyArg_ParseTupleAndKeywords(arg, kw, ":new", KWLIST)) return (0); g = PyObject_NEW(ghash_pyobj, ty); g->h = GM_INIT(GMAC_M(ty)); g->f = f_freeme; @@ -1218,13 +1220,13 @@ CONVFUNC(poly1305hash, poly1305_ctx *, P1305_CTX) static PyObject *poly1305hash_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) { - char *kwlist[] = { "mask", 0 }; + static const char *const kwlist[] = { "mask", 0 }; poly1305key_pyobj *pk = (poly1305key_pyobj *)ty; poly1305hash_pyobj *ph; char *m = 0; Py_ssize_t sz; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "|s#:new", kwlist, &m, &sz)) + if (!PyArg_ParseTupleAndKeywords(arg, kw, "|s#:new", KWLIST, &m, &sz)) return (0); if (m && sz != POLY1305_MASKSZ) VALERR("bad mask length"); ph = PyObject_NEW(poly1305hash_pyobj, ty); @@ -1240,12 +1242,12 @@ end: static PyObject *poly1305key_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) { - char *kwlist[] = { "k", 0 }; + static const char *const kwlist[] = { "k", 0 }; poly1305key_pyobj *pk; char *k; Py_ssize_t sz; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#:new", kwlist, &k, &sz)) + if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#:new", KWLIST, &k, &sz)) goto end; if (keysz(sz, poly1305_keysz) != sz) VALERR("bad key length"); @@ -1482,7 +1484,7 @@ static PyTypeObject poly1305key_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"Poly1305 key.", +"poly1305(K): Poly1305 key.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -1598,8 +1600,8 @@ static PyObject *kxvik_pynew(PyTypeObject *ty, { unsigned n = 24; kxvik_pyobj *rc = 0; - char *kwlist[] = { "nround", 0 }; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:new", kwlist, + static const char *const kwlist[] = { "nround", 0 }; + if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:new", KWLIST, convuint, &n)) goto end; rc = (kxvik_pyobj *)ty->tp_alloc(ty, 0); @@ -1719,7 +1721,7 @@ static PyTypeObject kxvik_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"Keccak-p[1600, n] state.", +"Keccak1600([nround = 24]): Keccak-p[1600, n] state.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -1762,9 +1764,9 @@ static PyObject *shake_dopynew(void (*initfn)(shake_ctx *, shake_pyobj *rc = 0; char *p = 0, *f = 0; Py_ssize_t psz = 0, fsz = 0; - char *kwlist[] = { "perso", "func", 0 }; + static const char *const kwlist[] = { "perso", "func", 0 }; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "|s#s#:new", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "|s#s#:new", KWLIST, &p, &psz, &f, &fsz)) goto end; rc = (shake_pyobj *)ty->tp_alloc(ty, 0); @@ -2016,7 +2018,7 @@ static PyTypeObject shake128_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"SHAKE128/cSHAKE128 XOF.", +"Shake128([perso = STR], [func = STR]): SHAKE128/cSHAKE128 XOF.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -2064,7 +2066,7 @@ static PyTypeObject shake256_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"SHAKE256/cSHAKE256 XOF.", +"Shake256([perso = STR], [func = STR]): SHAKE256/cSHAKE256 XOF.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -2146,13 +2148,13 @@ typedef struct prp { static PyObject *gprp_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) { - char *kwlist[] = { "key", 0 }; + static const char *const kwlist[] = { "key", 0 }; char *k; Py_ssize_t sz; const prpinfo *prp = GCPRP_PRP(ty); PyObject *me; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#:new", kwlist, &k, &sz)) + if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#:new", KWLIST, &k, &sz)) goto end; if (keysz(sz, prp->keysz) != sz) VALERR("bad key length"); me = (PyObject *)ty->tp_alloc(ty, 0);