/*----- Header files ------------------------------------------------------*/
#include "catacomb-python.h"
+PUBLIC_SYMBOLS;
#include "algorithms.h"
+PRIVATE_SYMBOLS;
/*----- Main code ---------------------------------------------------------*/
-PyTypeObject *grand_pytype, *truerand_pytype;
-PyTypeObject *lcrand_pytype, *fibrand_pytype;
-PyTypeObject *dsarand_pytype, *bbs_pytype, *bbspriv_pytype;
-PyTypeObject *sslprf_pytype, *tlsdx_pytype, *tlsprf_pytype;
+PyTypeObject *grand_pytype;
+static PyTypeObject *truerand_pytype;
+static PyTypeObject *lcrand_pytype, *fibrand_pytype;
+static PyTypeObject *dsarand_pytype, *bbs_pytype, *bbspriv_pytype;
+static PyTypeObject *sslprf_pytype, *tlsdx_pytype, *tlsprf_pytype;
PyObject *rand_pyobj;
static PyObject *gccrands_dict;
PyTypeObject *ty = grand_pytype;
PyObject *ob;
- if (strcmp(r->ops->name, "rand") == 0) ty = truerand_pytype;
- else if (strcmp(r->ops->name, "lcrand") == 0) ty = lcrand_pytype;
- else if (strcmp(r->ops->name, "fibrand") == 0) ty = fibrand_pytype;
- else if (strcmp(r->ops->name, "dsarand") == 0) ty = dsarand_pytype;
- else if (strcmp(r->ops->name, "bbs") == 0) ty = bbs_pytype;
- else if (strcmp(r->ops->name, "sslprf") == 0) ty = sslprf_pytype;
- else if (strcmp(r->ops->name, "tlsdx") == 0) ty = tlsdx_pytype;
- else if (strcmp(r->ops->name, "tlsprf") == 0) ty = tlsprf_pytype;
+ if (STRCMP(r->ops->name, ==, "rand")) ty = truerand_pytype;
+ else if (STRCMP(r->ops->name, ==, "lcrand")) ty = lcrand_pytype;
+ else if (STRCMP(r->ops->name, ==, "fibrand")) ty = fibrand_pytype;
+ else if (STRCMP(r->ops->name, ==, "dsarand")) ty = dsarand_pytype;
+ else if (STRCMP(r->ops->name, ==, "bbs")) ty = bbs_pytype;
+ else if (STRCMP(r->ops->name, ==, "sslprf")) ty = sslprf_pytype;
+ else if (STRCMP(r->ops->name, ==, "tlsdx")) ty = tlsdx_pytype;
+ else if (STRCMP(r->ops->name, ==, "tlsprf")) ty = tlsprf_pytype;
else if ((ob = PyDict_GetItemString(gccrands_dict, r->ops->name)) != 0)
ty = (PyTypeObject *)ob;
return (grand_dopywrap(ty, r, f));
static const char *const kwlist[] = { 0 };
grand *r;
PyObject *rc = 0;
- if (PyArg_ParseTupleAndKeywords(arg, kw, ":new", KWLIST)) goto end;
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, ":new", KWLIST)) goto end;
r = rand_create();
r->ops->misc(r, RAND_NOISESRC, &noise_source);
r->ops->misc(r, RAND_SEED, 160);
static PyObject *sslprf_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
{
char *k, *s;
- int ksz, ssz;
+ Py_ssize_t ksz, ssz;
const gchash *hco = &md5, *hci = &sha;
PyObject *rc = 0;
static const char *const kwlist[] = { "key", "seed", "ohash", "ihash", 0 };
static PyObject *tlsdx_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
{
char *k, *s;
- int ksz, ssz;
+ Py_ssize_t ksz, ssz;
const gcmac *mc = &sha_hmac;
PyObject *rc = 0;
static const char *const kwlist[] = { "key", "seed", "mac", 0 };
static PyObject *tlsprf_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
{
char *k, *s;
- int ksz, ssz;
+ Py_ssize_t ksz, ssz;
const gcmac *mcl = &md5_hmac, *mcr = &sha_hmac;
PyObject *rc = 0;
static const char *const kwlist[] = { "key", "seed", "lmac", "rmac", 0 };
static PyObject *dsarand_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
{
char *p;
- int sz;
+ Py_ssize_t sz;
PyObject *rc = 0;
static const char *const kwlist[] = { "seed", 0 };
static int bbsset_x(PyObject *me, PyObject *val, void *hunoz)
{
- mp *x = 0; grand *r = GRAND_R(me); int rc = -1; if (!x) NIERR("__del__");
+ mp *x = 0; grand *r = GRAND_R(me); int rc = -1; if (!val) NIERR("__del__");
if ((x = getmp(val)) == 0) goto end;
r->ops->misc(r, BBS_SET, x); rc = 0;
end: mp_drop(x); return (rc);
{
bbs_priv bp = { 0 };
mp *x = MP_TWO;
- pgev evt = { 0 };
+ struct excinfo exc = EXCINFO_INIT;
+ pypgev evt = { { 0 } };
unsigned nbits, n = 0;
grand *r = &rand_global;
static const char *const kwlist[] =
{ "class", "nbits", "event", "rng", "nsteps", "seed", 0 };
bbspriv_pyobj *rc = 0;
+ evt.exc = &exc;
if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&|O&O&O&O&:generate", KWLIST,
&me, convuint, &nbits, convpgev, &evt,
convgrand, &r, convuint, &n, convmp, &x))
goto end;
- if (bbs_gen(&bp, nbits, r, n, evt.proc, evt.ctx))
- VALERR("prime genration failed");
+ if (bbs_gen(&bp, nbits, r, n, evt.ev.proc, evt.ev.ctx))
+ PGENERR(&exc);
rc = PyObject_New(bbspriv_pyobj, bbspriv_pytype);
rc->gr.r = bbs_rand(bp.n, x);
rc->gr.f = f_freeme;
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-"BBSPriv(..., seed = 2]): Blum-Blum-Shub, with private key.\n\
+"BBSPriv(..., [seed = 2]): Blum-Blum-Shub, with private key.\n\
Keywords: n, p, q; must provide at least two",
0, /* @tp_traverse@ */
static PyMethodDef methods[] = {
#define METHNAME(name) meth_##name
KWMETH(_BBSPriv_generate, "\
-generate(NBITS, [event = pgen_nullev, rng = rand, nsteps = 0, seed = 2])")
+generate(NBITS, [event = pgen_nullev], [rng = rand],\n\
+ [nsteps = 0], [seed = 2]) -> R")
#undef METHNAME
{ 0 }
};