static PyObject *grmeth_seedblock(PyObject *me, PyObject *arg)
{
char *p;
- int n;
+ Py_ssize_t n;
grand *r = GRAND_R(me);
if (!PyArg_ParseTuple(arg, "s#:seedblock", &p, &n) ||
checkop(r, GRAND_SEEDBLOCK, "seedblock"))
{
grand *r = GRAND_R(me);
char *p, *q;
- int sz;
+ Py_ssize_t sz;
PyObject *rc;
if (!PyArg_ParseTuple(arg, "s#:mask", &p, &sz)) return (0);
static PyObject *trmeth_add(PyObject *me, PyObject *arg)
{
grand *r = GRAND_R(me);
- char *p; int n; unsigned goodbits;
+ char *p; Py_ssize_t n; unsigned goodbits;
if (!PyArg_ParseTuple(arg, "s#O&:add", &p, &n, convuint, &goodbits))
return (0);
r->ops->misc(r, RAND_ADD, p, (size_t)n, goodbits);
static PyObject *trmeth_key(PyObject *me, PyObject *arg)
{
grand *r = GRAND_R(me);
- char *p; int n;
+ char *p; Py_ssize_t n;
if (!PyArg_ParseTuple(arg, "s#:key", &p, &n)) return (0);
r->ops->misc(r, RAND_KEY, p, (size_t)n);
RETURN_ME;
gcrand_func *func;
} gccrand_info;
-#define RNGF_INT 1u
-#define RNGF_NONCE 2u
-#define RNGF_LATIN 4u
+#define RNGF_MASK 255u
+
+enum {
+ RNG_PLAIN = 0,
+ RNG_SEAL,
+ RNG_LATIN,
+ RNG_SHAKE,
+ RNG_KMAC
+};
typedef struct gccrand_pyobj {
PyHeapTypeObject ty;
const gccrand_info *info = GCCRAND_INFO(ty);
static char *kwlist[] = { "key", 0 };
char *k;
- int n;
+ Py_ssize_t n;
if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#:new", kwlist, &k, &n))
goto end;
uint32 i = 0;
static char *kwlist[] = { "key", "i", 0 };
char *k;
- int n;
+ Py_ssize_t n;
if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#O&:new", kwlist,
&k, &n, convu32, &i))
const gccrand_info *info = GCCRAND_INFO(ty);
static char *kwlist[] = { "key", "nonce", 0 };
char *k, *n;
- int ksz, nsz;
+ Py_ssize_t ksz, nsz;
if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#s#:new", kwlist,
&k, &ksz, &n, &nsz))
gccrand_pyobj *g = newtype(gccrand_pytype, 0, info->name);
g->info = info;
g->ty.ht_type.tp_basicsize = sizeof(grand_pyobj);
- g->ty.ht_type.tp_base =
- (info->f & RNGF_LATIN) ? gclatinrand_pytype : gcrand_pytype;
+ switch (info->f&RNGF_MASK) {
+ case RNG_LATIN: g->ty.ht_type.tp_base = gclatinrand_pytype; break;
+ default: g->ty.ht_type.tp_base = gcrand_pytype; break;
+ }
Py_INCREF(g->ty.ht_type.tp_base);
g->ty.ht_type.tp_flags = (Py_TPFLAGS_DEFAULT |
Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_HEAPTYPE);
g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
g->ty.ht_type.tp_free = 0;
- if (info->f & RNGF_INT) g->ty.ht_type.tp_new = gcirand_pynew;
- else if (info->f & RNGF_NONCE) g->ty.ht_type.tp_new = gcnrand_pynew;
- else g->ty.ht_type.tp_new = gcrand_pynew;
+ switch (info->f&RNGF_MASK) {
+ case RNG_LATIN: g->ty.ht_type.tp_new = gcnrand_pynew; break;
+ case RNG_SEAL: g->ty.ht_type.tp_new = gcirand_pynew; break;
+ default: g->ty.ht_type.tp_new = gcrand_pynew; break;
+ }
typeready(&g->ty.ht_type);
return ((PyObject *)g);
}