X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/963a61481edc7a83698b18b518bf20cd93d268a6..8fc76cc0e1dea41218fca11b3405183252e7f57f:/share.c diff --git a/share.c b/share.c index c5222e0..77da423 100644 --- a/share.c +++ b/share.c @@ -1,13 +1,11 @@ /* -*-c-*- * - * $Id$ - * * Secret sharing * * (c) 2005 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of the Python interface to Catacomb. * @@ -15,12 +13,12 @@ * 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. @@ -65,7 +63,7 @@ static PyGetSetDef gfshare_pygetset[]= { static PyTypeObject gfshare_pytype_skel = { PyObject_HEAD_INIT(&PyType_Type) 0, /* Header */ - "catacomb.GFShare", /* @tp_name@ */ + "GFShare", /* @tp_name@ */ sizeof(gfshare_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -115,12 +113,12 @@ static PyObject *gfsharesplit_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) { char *p; - int n; + Py_ssize_t n; unsigned t; grand *r = &rand_global; gfshare_pyobj *s; - char *kwlist[] = { "threshold", "secret", "rng", 0 }; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&s#|O&:new", kwlist, + static const char *const kwlist[] = { "threshold", "secret", "rng", 0 }; + if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&s#|O&:new", KWLIST, convuint, &t, &p, &n, convgrand, &r)) goto end; if (!t || t > 255) VALERR("threshold must be nonzero and < 256"); @@ -153,7 +151,7 @@ static PyMethodDef gfsharesplit_pymethods[] = { static PyTypeObject gfsharesplit_pytype_skel = { PyObject_HEAD_INIT(&PyType_Type) 0, /* Header */ - "catacomb.GFShareSplit", /* @tp_name@ */ + "GFShareSplit", /* @tp_name@ */ sizeof(gfshare_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -176,7 +174,8 @@ static PyTypeObject gfsharesplit_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"Binary field secret sharing: split secret into shares.", +"GFShareSplit(THRESHOLD, SECRET, [rng = rand]): binary-field sharing:\n\ + split secret into shares.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -204,8 +203,8 @@ static PyObject *gfsharejoin_pynew(PyTypeObject *ty, { unsigned t, sz; gfshare_pyobj *s; - char *kwlist[] = { "threshold", "size", 0 }; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&:new", kwlist, + static const char *const kwlist[] = { "threshold", "size", 0 }; + if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&:new", KWLIST, convuint, &t, convuint, &sz)) goto end; if (!t || t > 255) VALERR("threshold must be nonzero and < 256"); @@ -230,7 +229,7 @@ static PyObject *gfsmeth_add(PyObject *me, PyObject *arg) { unsigned i; char *p; - int n; + Py_ssize_t n; if (!PyArg_ParseTuple(arg, "O&s#:add", convuint, &i, &p, &n)) goto end; if (i > 254) VALERR("index must be < 255"); if (n != GFSHARE_S(me)->sz) VALERR("bad share size"); @@ -274,7 +273,7 @@ static PyGetSetDef gfsharejoin_pygetset[]= { static PyTypeObject gfsharejoin_pytype_skel = { PyObject_HEAD_INIT(&PyType_Type) 0, /* Header */ - "catacomb.GFShareJoin", /* @tp_name@ */ + "GFShareJoin", /* @tp_name@ */ sizeof(gfshare_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -297,7 +296,8 @@ static PyTypeObject gfsharejoin_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"Binary field secret sharing: join shares to recover secret.", +"GFShareJoin(THRESHOLD, SIZE): binary field sharing:\n\ + join shares to recover secret.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -355,7 +355,7 @@ static PyGetSetDef share_pygetset[]= { static PyTypeObject share_pytype_skel = { PyObject_HEAD_INIT(&PyType_Type) 0, /* Header */ - "catacomb.Share", /* @tp_name@ */ + "Share", /* @tp_name@ */ sizeof(share_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -409,8 +409,10 @@ static PyObject *sharesplit_pynew(PyTypeObject *ty, grand *r = &rand_global; mp *m = 0; share_pyobj *s; - char *kwlist[] = { "threshold", "secret", "modulus", "rng", 0 }; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&)&|O&O&:new", kwlist, + static const char *const kwlist[] = + { "threshold", "secret", "modulus", "rng", 0 }; + + if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&|O&O&:new", KWLIST, convuint, &t, convmp, &sec, convmp, &m, convgrand, &r)) goto end; @@ -446,7 +448,7 @@ static PyMethodDef sharesplit_pymethods[] = { static PyTypeObject sharesplit_pytype_skel = { PyObject_HEAD_INIT(&PyType_Type) 0, /* Header */ - "catacomb.ShareSplit", /* @tp_name@ */ + "ShareSplit", /* @tp_name@ */ sizeof(share_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -469,7 +471,8 @@ static PyTypeObject sharesplit_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"Prime field secret sharing: split secret into shares.", +"ShareSplit(THRESHOLD, SECRET, [modulus = ?], [rng = rand]):\n\ + prime field secret sharing: split secret into shares.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -498,8 +501,8 @@ static PyObject *sharejoin_pynew(PyTypeObject *ty, unsigned t; mp *m = 0; share_pyobj *s; - char *kwlist[] = { "threshold", "modulus", 0 }; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&:new", kwlist, + static const char *const kwlist[] = { "threshold", "modulus", 0 }; + if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&:new", KWLIST, convuint, &t, convmp, &m)) goto end; if (!t) VALERR("threshold must be nonzero"); @@ -569,7 +572,7 @@ static PyGetSetDef sharejoin_pygetset[]= { static PyTypeObject sharejoin_pytype_skel = { PyObject_HEAD_INIT(&PyType_Type) 0, /* Header */ - "catacomb.ShareJoin", /* @tp_name@ */ + "ShareJoin", /* @tp_name@ */ sizeof(share_pyobj), /* @tp_basicsize@ */ 0, /* @tp_itemsize@ */ @@ -592,7 +595,8 @@ static PyTypeObject sharejoin_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"Prime field secret sharing: join shares to recover secret.", +"ShareJoin(THRESHOLD, MODULUS): prime field secret sharing:\n\ + join shares to recover secret.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */