X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/204416123385794c92b7767e7702c0d4fd387468..740847afe208bb8f33e7d6cf642acaf4aa739f6a:/algorithms.c diff --git a/algorithms.c b/algorithms.c index 2a3bece..888ceb0 100644 --- a/algorithms.c +++ b/algorithms.c @@ -137,9 +137,8 @@ static PyObject *keyszset_pynew(PyTypeObject *ty, if (!set) set = PyTuple_New(0); else Py_INCREF(set); if (!PySequence_Check(set)) TYERR("want a sequence"); - n = PySequence_Size(set); - l = PyList_New(0); - if (PyErr_Occurred()) goto end; + n = PySequence_Size(set); if (n < 0) goto end; + l = PyList_New(0); if (!l) goto end; if (dfl < 0) VALERR("key size cannot be negative"); x = PyInt_FromLong(dfl); PyList_Append(l, x); @@ -208,7 +207,7 @@ static PyMemberDef keysz_pymembers[] = { static PyGetSetDef keyszany_pygetset[] = { #define GETSETNAME(op, name) ka##op##_##name GET (min, "KSZ.min -> smallest allowed key size") - GET (max, "KSZ.min -> largest allowed key size") + GET (max, "KSZ.max -> largest allowed key size") #undef GETSETNAME { 0 } }; @@ -216,7 +215,7 @@ static PyGetSetDef keyszany_pygetset[] = { static PyMemberDef keyszrange_pymembers[] = { #define MEMBERSTRUCT keyszrange_pyobj MEMBER(min, T_INT, READONLY, "KSZ.min -> smallest allowed key size") - MEMBER(max, T_INT, READONLY, "KSZ.min -> largest allowed key size") + MEMBER(max, T_INT, READONLY, "KSZ.max -> largest allowed key size") MEMBER(mod, T_INT, READONLY, "KSZ.mod -> key size must be a multiple of this") #undef MEMBERSTRUCT @@ -226,7 +225,7 @@ static PyMemberDef keyszrange_pymembers[] = { static PyGetSetDef keyszset_pygetset[] = { #define GETSETNAME(op, name) ks##op##_##name GET (min, "KSZ.min -> smallest allowed key size") - GET (max, "KSZ.min -> largest allowed key size") + GET (max, "KSZ.max -> largest allowed key size") #undef GETSETNAME { 0 } }; @@ -990,6 +989,7 @@ static PyObject *gaeameth_copy(PyObject *me, PyObject *arg) VALERR("can't duplicate nonce-dependent aad"); rc = gaeadaad_pywrap((PyObject *)me->ob_type, GAEAD_DUP(GAEADAAD_A(me)), 0, 0); + GAEADAAD_HLEN(rc) = GAEADAAD_HLEN(me); end: return (rc); } @@ -1133,7 +1133,8 @@ static PyObject *gaeemeth_aad(PyObject *me, PyObject *arg) if (!ge->aad) ge->aad = (gaeadaad_pyobj *) gaeadaad_pywrap((PyObject *)GCAEADENC_KEY(ge->ob_type)->aad, - GAEAD_AAD(ge->e), ge->f&AEADF_PCHSZ, ge->hsz); + GAEAD_AAD(ge->e), ge->f&(AEADF_PCHSZ | AEADF_NOAAD), + ge->hsz); Py_INCREF(ge->aad); rc = (PyObject *)ge->aad; } @@ -1304,7 +1305,8 @@ static PyObject *gaedmeth_aad(PyObject *me, PyObject *arg) if (!gd->aad) gd->aad = (gaeadaad_pyobj *) gaeadaad_pywrap((PyObject *)GCAEADENC_KEY(gd->ob_type)->aad, - GAEAD_AAD(gd->d), gd->f&AEADF_PCHSZ, gd->hsz); + GAEAD_AAD(gd->d), gd->f&(AEADF_PCHSZ | AEADF_NOAAD), + gd->hsz); Py_INCREF(gd->aad); return ((PyObject *)gd->aad); } @@ -2639,7 +2641,7 @@ static PyTypeObject poly1305hash_pytype_skel = { if (!PyArg_ParseTuple(arg, "s#s#:" #hdance "_prf", \ &k, &ksz, &n, &nsz)) \ goto end; \ - if (ksz != DANCE##_KEYSZ) VALERR("bad key length"); \ + if (ksz != keysz(ksz, dance##_keysz)) VALERR("bad key length"); \ if (nsz != HDANCE##_INSZ) VALERR("bad input length"); \ rc = bytestring_pywrap(0, HSALSA20_OUTSZ); \ dance##_init(&dance, k, ksz, 0); \ @@ -2725,7 +2727,7 @@ static PyObject *kxvikmeth_extract(PyObject *me, PyObject *arg) unsigned i; unsigned n; - if (!PyArg_ParseTuple(arg, "O&:mix", convuint, &n)) goto end; + if (!PyArg_ParseTuple(arg, "O&:extract", convuint, &n)) goto end; if (n > 200) VALERR("out of range"); rc = bytestring_pywrap(0, n); q = (octet *)PyString_AS_STRING(rc); @@ -2755,10 +2757,14 @@ static int kxvikset_nround(PyObject *me, PyObject *val, void *hunoz) { kxvik_pyobj *k = (kxvik_pyobj *)me; unsigned n; + int rc = -1; - if (!convuint(val, &n)) return (-1); + if (!val) NIERR("__del__"); + if (!convuint(val, &n)) goto end; k->n = n; - return (0); + rc = 0; +end: + return (rc); } static PyGetSetDef kxvik_pygetset[] = { @@ -2955,7 +2961,7 @@ static PyObject *shakemeth_copy(PyObject *me, PyObject *arg) rc->h = *SHAKE_H(me); rc->st = SHAKE_ST(me); end: - return ((PyObject *)me); + return ((PyObject *)rc); } static PyObject *shakemeth_get(PyObject *me, PyObject *arg)