From: Mark Wooding Date: Fri, 7 Apr 2017 18:20:53 +0000 (+0100) Subject: algorithms.c: Add bindings for HSalsa20/r and HChaCha/r. X-Git-Tag: 1.2.0~46 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/catacomb-python/commitdiff_plain/a75e68c977a90a6aebfa8e9509c46b739ea1e791 algorithms.c: Add bindings for HSalsa20/r and HChaCha/r. --- diff --git a/algorithms.c b/algorithms.c index 4561b9a..2f9889d 100644 --- a/algorithms.c +++ b/algorithms.c @@ -1535,6 +1535,35 @@ static PyTypeObject poly1305hash_pytype_skel = { 0 /* @tp_is_gc@ */ }; +/*----- Special snowflake for HSalsa and HChaCha --------------------------*/ + +#define DEF_HDANCE(DANCE, HDANCE, dance, hdance) \ + static PyObject *meth_##hdance##_prf(PyObject *me, PyObject *arg) \ + { \ + dance##_ctx dance; \ + char *k, *n; \ + int ksz, nsz; \ + PyObject *rc; \ + if (!PyArg_ParseTuple(arg, "s#s#:" #hdance "_prf", \ + &k, &ksz, &n, &nsz)) \ + goto end; \ + if (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); \ + hdance##_prf(&dance, n, PyString_AS_STRING(rc)); \ + return (rc); \ + end: \ + return (0); \ + } + +DEF_HDANCE(SALSA20, HSALSA20, salsa20, hsalsa20) +DEF_HDANCE(SALSA20, HSALSA20, salsa20, hsalsa2012) +DEF_HDANCE(SALSA20, HSALSA20, salsa20, hsalsa208) + +DEF_HDANCE(CHACHA, HCHACHA, chacha, hchacha20) +DEF_HDANCE(CHACHA, HCHACHA, chacha, hchacha12) +DEF_HDANCE(CHACHA, HCHACHA, chacha, hchacha8) /*----- Pseudorandom permutations -----------------------------------------*/ @@ -1801,6 +1830,17 @@ toschnorr(N) -> M: convert work factor to Schnorr group order") 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") + METH (_KeySZ_toec, "\ +toec(N) -> M: convert work factor to elliptic curve group order") +#define METH_HDANCE(hdance, HDance) METH(hdance##_prf, "\ +" #hdance "_prf(K, N) -> H: calculate " HDance " hash of N with K") + METH_HDANCE(hsalsa20, "HSalsa20") + METH_HDANCE(hsalsa2012, "HSalsa20/12") + METH_HDANCE(hsalsa208, "HSalsa20/8") + METH_HDANCE(hchacha20, "HChaCha20") + METH_HDANCE(hchacha12, "HChaCha12") + METH_HDANCE(hchacha8, "HChaCha8") +#undef METH_DANCE #undef METHNAME { 0 } };