3 * Random-number generators
5 * (c) 2004 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the Python interface to Catacomb.
12 * Catacomb/Python is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * Catacomb/Python is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with Catacomb/Python; if not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 /*----- Header files ------------------------------------------------------*/
29 #include "catacomb-python.h"
30 #include "algorithms.h"
32 /*----- Main code ---------------------------------------------------------*/
34 PyTypeObject *grand_pytype, *truerand_pytype;
35 PyTypeObject *lcrand_pytype, *fibrand_pytype;
36 PyTypeObject *dsarand_pytype, *bbs_pytype, *bbspriv_pytype;
37 PyTypeObject *sslprf_pytype, *tlsdx_pytype, *tlsprf_pytype;
40 static PyObject *gccrands_dict;
42 static PyObject *grand_dopywrap(PyTypeObject *ty, grand *r, unsigned f)
46 g = (grand_pyobj *)ty->tp_alloc(ty, 0);
49 return ((PyObject *)g);
52 PyObject *grand_pywrap(grand *r, unsigned f)
54 PyTypeObject *ty = grand_pytype;
57 if (strcmp(r->ops->name, "rand") == 0) ty = truerand_pytype;
58 else if (strcmp(r->ops->name, "lcrand") == 0) ty = lcrand_pytype;
59 else if (strcmp(r->ops->name, "fibrand") == 0) ty = fibrand_pytype;
60 else if (strcmp(r->ops->name, "dsarand") == 0) ty = dsarand_pytype;
61 else if (strcmp(r->ops->name, "bbs") == 0) ty = bbs_pytype;
62 else if (strcmp(r->ops->name, "sslprf") == 0) ty = sslprf_pytype;
63 else if (strcmp(r->ops->name, "tlsdx") == 0) ty = tlsdx_pytype;
64 else if (strcmp(r->ops->name, "tlsprf") == 0) ty = tlsprf_pytype;
65 else if ((ob = PyDict_GetItemString(gccrands_dict, r->ops->name)) != 0)
66 ty = (PyTypeObject *)ob;
67 return (grand_dopywrap(ty, r, f));
70 CONVFUNC(grand, grand *, GRAND_R)
72 static PyObject *grmeth_byte(PyObject *me, PyObject *arg)
74 if (!PyArg_ParseTuple(arg, ":byte")) return (0);
75 return (PyInt_FromLong(grand_byte(GRAND_R(me))));
78 static PyObject *grmeth_word(PyObject *me, PyObject *arg)
80 if (!PyArg_ParseTuple(arg, ":word")) return (0);
81 return (getulong(grand_word(GRAND_R(me))));
84 static PyObject *grmeth_range(PyObject *me, PyObject *arg)
90 if (!PyArg_ParseTuple(arg, "O:range", &m)) return (0);
92 long mm = PyInt_AS_LONG(m);
96 return (PyInt_FromLong(grand_range(GRAND_R(me), mm)));
98 if ((x = getmp(m)) == 0)
102 y = mprand_range(MP_NEW, x, GRAND_R(me), 0);
104 return (mp_pywrap(y));
106 VALERR("range must be strictly positive");
112 static PyObject *grmeth_mp(PyObject *me, PyObject *arg, PyObject *kw)
116 char *kwlist[] = { "bits", "or", 0 };
118 if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&|O&:mp", kwlist,
119 convszt, &l, convmpw, &o))
121 if (l < MPW_BITS && (o >> l)) VALERR("or mask too large");
122 return (mp_pywrap(mprand(MP_NEW, l, GRAND_R(me), o)));
127 static PyObject *grmeth_block(PyObject *me, PyObject *arg)
132 if (!PyArg_ParseTuple(arg, "O&:block", convulong, &n)) goto end;
133 rc = bytestring_pywrap(0, n);
134 grand_fill(GRAND_R(me), PyString_AS_STRING(rc), n);
139 static int checkop(grand *r, unsigned op, const char *what)
141 if (r->ops->misc(r, GRAND_CHECK, op))
143 PyErr_Format(PyExc_TypeError, "operation %s not supported", what);
147 static PyObject *grmeth_seedint(PyObject *me, PyObject *arg)
150 grand *r = GRAND_R(me);
151 if (!PyArg_ParseTuple(arg, "i:seedint", &i) ||
152 checkop(r, GRAND_SEEDINT, "seedint"))
154 r->ops->misc(r, GRAND_SEEDINT, i);
160 static PyObject *grmeth_seedword(PyObject *me, PyObject *arg)
163 grand *r = GRAND_R(me);
164 if (!PyArg_ParseTuple(arg, "O&:seedword", convu32, &u) ||
165 checkop(r, GRAND_SEEDUINT32, "seedword"))
167 r->ops->misc(r, GRAND_SEEDUINT32, u);
173 static PyObject *grmeth_seedblock(PyObject *me, PyObject *arg)
177 grand *r = GRAND_R(me);
178 if (!PyArg_ParseTuple(arg, "s#:seedblock", &p, &n) ||
179 checkop(r, GRAND_SEEDBLOCK, "seedblock"))
181 r->ops->misc(r, GRAND_SEEDBLOCK, p, (size_t)n);
187 static PyObject *grmeth_seedmp(PyObject *me, PyObject *arg)
191 grand *r = GRAND_R(me);
192 if (!PyArg_ParseTuple(arg, "O:seedmp", &x) ||
193 checkop(r, GRAND_SEEDMP, "seedmp") ||
194 (xx = getmp(x)) == 0)
196 r->ops->misc(r, GRAND_SEEDMP, xx);
203 static PyObject *grmeth_seedrand(PyObject *me, PyObject *arg, PyObject *kw)
205 char *kwlist[] = { "rng", 0 };
206 grand *r = GRAND_R(me);
207 grand *rr = &rand_global;
208 if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:seedrand", kwlist,
210 checkop(r, GRAND_SEEDRAND, "seedrand"))
212 r->ops->misc(r, GRAND_SEEDRAND, rr);
218 static PyObject *grmeth_mask(PyObject *me, PyObject *arg)
220 grand *r = GRAND_R(me);
225 if (!PyArg_ParseTuple(arg, "s#:mask", &p, &sz)) return (0);
226 rc = bytestring_pywrap(0, sz);
227 q = PyString_AS_STRING(rc);
229 while (sz--) *q++ ^= *p++;
233 static void grand_pydealloc(PyObject *me)
235 grand_pyobj *g = (grand_pyobj *)me;
241 static PyObject *grget_name(PyObject *me, void *hunoz)
242 { return (PyString_FromString(GRAND_R(me)->ops->name)); }
244 static PyObject *grget_cryptop(PyObject *me, void *hunoz)
245 { return (getbool(GRAND_R(me)->ops->f & GRAND_CRYPTO)); }
247 static PyGetSetDef grand_pygetset[] = {
248 #define GETSETNAME(op, name) gr##op##_##name
249 GET (name, "R.name -> name of this kind of generator")
250 GET (cryptop, "R.cryptop -> flag: cryptographically strong?")
255 static PyMethodDef grand_pymethods[] = {
256 #define METHNAME(name) grmeth_##name
257 METH (byte, "R.byte() -> BYTE")
258 METH (word, "R.word() -> WORD")
259 METH (block, "R.block(N) -> STRING")
260 KWMETH(mp, "R.mp(bits, [or = 0]) -> MP")
261 METH (range, "R.range(MAX) -> INT")
262 METH (mask, "R.mask(STR) -> STR")
263 METH (seedint, "R.seedint(I)")
264 METH (seedword, "R.seedword(I)")
265 METH (seedblock, "R.seedblock(BYTES)")
266 METH (seedmp, "R.seedmp(X)")
267 KWMETH(seedrand, "R.seedrand(RR)")
272 static PyTypeObject grand_pytype_skel = {
273 PyObject_HEAD_INIT(0) 0, /* Header */
274 "GRand", /* @tp_name@ */
275 sizeof(grand_pyobj), /* @tp_basicsize@ */
276 0, /* @tp_itemsize@ */
278 grand_pydealloc, /* @tp_dealloc@ */
280 0, /* @tp_getattr@ */
281 0, /* @tp_setattr@ */
282 0, /* @tp_compare@ */
284 0, /* @tp_as_number@ */
285 0, /* @tp_as_sequence@ */
286 0, /* @tp_as_mapping@ */
290 0, /* @tp_getattro@ */
291 0, /* @tp_setattro@ */
292 0, /* @tp_as_buffer@ */
293 Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
297 "Generic random number source.",
299 0, /* @tp_traverse@ */
301 0, /* @tp_richcompare@ */
302 0, /* @tp_weaklistoffset@ */
304 0, /* @tp_iternext@ */
305 grand_pymethods, /* @tp_methods@ */
306 0, /* @tp_members@ */
307 grand_pygetset, /* @tp_getset@ */
310 0, /* @tp_descr_get@ */
311 0, /* @tp_descr_set@ */
312 0, /* @tp_dictoffset@ */
314 PyType_GenericAlloc, /* @tp_alloc@ */
315 abstract_pynew, /* @tp_new@ */
320 static PyObject *lcrand_pynew(PyTypeObject *me, PyObject *arg, PyObject *kw)
323 char *kwlist[] = { "seed", 0 };
324 if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:new", kwlist, convu32, &n))
326 return (grand_dopywrap(lcrand_pytype, lcrand_create(n), f_freeme));
329 static PyTypeObject lcrand_pytype_skel = {
330 PyObject_HEAD_INIT(0) 0, /* Header */
331 "LCRand", /* @tp_name@ */
332 sizeof(grand_pyobj), /* @tp_basicsize@ */
333 0, /* @tp_itemsize@ */
335 grand_pydealloc, /* @tp_dealloc@ */
337 0, /* @tp_getattr@ */
338 0, /* @tp_setattr@ */
339 0, /* @tp_compare@ */
341 0, /* @tp_as_number@ */
342 0, /* @tp_as_sequence@ */
343 0, /* @tp_as_mapping@ */
347 0, /* @tp_getattro@ */
348 0, /* @tp_setattro@ */
349 0, /* @tp_as_buffer@ */
350 Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
354 "Linear congruential generator.",
356 0, /* @tp_traverse@ */
358 0, /* @tp_richcompare@ */
359 0, /* @tp_weaklistoffset@ */
361 0, /* @tp_iternext@ */
362 0, /* @tp_methods@ */
363 0, /* @tp_members@ */
367 0, /* @tp_descr_get@ */
368 0, /* @tp_descr_set@ */
369 0, /* @tp_dictoffset@ */
371 PyType_GenericAlloc, /* @tp_alloc@ */
372 lcrand_pynew, /* @tp_new@ */
377 static PyObject *fibrand_pynew(PyTypeObject *me, PyObject *arg, PyObject *kw)
380 char *kwlist[] = { "seed", 0 };
381 if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:new", kwlist, convu32, &n))
383 return (grand_dopywrap(fibrand_pytype, fibrand_create(n), f_freeme));
386 static PyTypeObject fibrand_pytype_skel = {
387 PyObject_HEAD_INIT(0) 0, /* Header */
388 "FibRand", /* @tp_name@ */
389 sizeof(grand_pyobj), /* @tp_basicsize@ */
390 0, /* @tp_itemsize@ */
392 grand_pydealloc, /* @tp_dealloc@ */
394 0, /* @tp_getattr@ */
395 0, /* @tp_setattr@ */
396 0, /* @tp_compare@ */
398 0, /* @tp_as_number@ */
399 0, /* @tp_as_sequence@ */
400 0, /* @tp_as_mapping@ */
404 0, /* @tp_getattro@ */
405 0, /* @tp_setattro@ */
406 0, /* @tp_as_buffer@ */
407 Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
411 "Fibonacci generator.",
413 0, /* @tp_traverse@ */
415 0, /* @tp_richcompare@ */
416 0, /* @tp_weaklistoffset@ */
418 0, /* @tp_iternext@ */
419 0, /* @tp_methods@ */
420 0, /* @tp_members@ */
424 0, /* @tp_descr_get@ */
425 0, /* @tp_descr_set@ */
426 0, /* @tp_dictoffset@ */
428 PyType_GenericAlloc, /* @tp_alloc@ */
429 fibrand_pynew, /* @tp_new@ */
434 /*----- True random generator ---------------------------------------------*/
436 static PyObject *trmeth_gate(PyObject *me, PyObject *arg)
438 grand *r = GRAND_R(me);
439 if (!PyArg_ParseTuple(arg, ":gate")) return (0);
440 r->ops->misc(r, RAND_GATE);
444 static PyObject *trmeth_stretch(PyObject *me, PyObject *arg)
446 grand *r = GRAND_R(me);
447 if (!PyArg_ParseTuple(arg, ":stretch")) return (0);
448 r->ops->misc(r, RAND_STRETCH);
452 static PyObject *trmeth_add(PyObject *me, PyObject *arg)
454 grand *r = GRAND_R(me);
455 char *p; Py_ssize_t n; unsigned goodbits;
456 if (!PyArg_ParseTuple(arg, "s#O&:add", &p, &n, convuint, &goodbits))
458 r->ops->misc(r, RAND_ADD, p, (size_t)n, goodbits);
462 static PyObject *trmeth_key(PyObject *me, PyObject *arg)
464 grand *r = GRAND_R(me);
465 char *p; Py_ssize_t n;
466 if (!PyArg_ParseTuple(arg, "s#:key", &p, &n)) return (0);
467 r->ops->misc(r, RAND_KEY, p, (size_t)n);
471 static PyObject *trmeth_seed(PyObject *me, PyObject *arg)
473 grand *r = GRAND_R(me);
475 if (!PyArg_ParseTuple(arg, "O&:seed", convuint, &u)) return (0);
476 if (u > RAND_IBITS) VALERR("pointlessly large");
477 r->ops->misc(r, RAND_SEED, u);
483 static PyObject *trmeth_timer(PyObject *me, PyObject *arg)
485 grand *r = GRAND_R(me);
486 if (!PyArg_ParseTuple(arg, ":timer")) return (0);
487 r->ops->misc(r, RAND_TIMER);
491 static PyObject *truerand_pynew(PyTypeObject *ty,
492 PyObject *arg, PyObject *kw)
494 char *kwlist[] = { 0 };
497 if (PyArg_ParseTupleAndKeywords(arg, kw, ":new", kwlist)) goto end;
499 r->ops->misc(r, RAND_NOISESRC, &noise_source);
500 r->ops->misc(r, RAND_SEED, 160);
501 rc = grand_dopywrap(ty, r, f_freeme);
506 static PyMethodDef truerand_pymethods[] = {
507 #define METHNAME(name) trmeth_##name
508 METH (gate, "R.gate()")
509 METH (stretch, "R.stretch()")
510 METH (key, "R.key(BYTES)")
511 METH (seed, "R.seed(NBITS)")
512 METH (add, "R.add(BYTES, GOODBITS")
513 METH (timer, "R.timer()")
518 static PyObject *trget_goodbits(PyObject *me, void *hunoz)
520 grand *r = GRAND_R(me);
521 return (PyInt_FromLong(r->ops->misc(r, RAND_GOODBITS)));
524 static PyGetSetDef truerand_pygetset[] = {
525 #define GETSETNAME(op, name) tr##op##_##name
526 GET (goodbits, "R.goodbits -> good bits of entropy remaining")
531 static PyTypeObject truerand_pytype_skel = {
532 PyObject_HEAD_INIT(0) 0, /* Header */
533 "TrueRand", /* @tp_name@ */
534 sizeof(grand_pyobj), /* @tp_basicsize@ */
535 0, /* @tp_itemsize@ */
537 grand_pydealloc, /* @tp_dealloc@ */
539 0, /* @tp_getattr@ */
540 0, /* @tp_setattr@ */
541 0, /* @tp_compare@ */
543 0, /* @tp_as_number@ */
544 0, /* @tp_as_sequence@ */
545 0, /* @tp_as_mapping@ */
549 0, /* @tp_getattro@ */
550 0, /* @tp_setattro@ */
551 0, /* @tp_as_buffer@ */
552 Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
556 "True random number source.",
558 0, /* @tp_traverse@ */
560 0, /* @tp_richcompare@ */
561 0, /* @tp_weaklistoffset@ */
563 0, /* @tp_iternext@ */
564 truerand_pymethods, /* @tp_methods@ */
565 0, /* @tp_members@ */
566 truerand_pygetset, /* @tp_getset@ */
569 0, /* @tp_descr_get@ */
570 0, /* @tp_descr_set@ */
571 0, /* @tp_dictoffset@ */
573 PyType_GenericAlloc, /* @tp_alloc@ */
574 truerand_pynew, /* @tp_new@ */
579 /*----- Generators from symmetric encryption algorithms -------------------*/
581 static PyTypeObject *gccrand_pytype, *gcrand_pytype, *gclatinrand_pytype;
583 typedef grand *gcrand_func(const void *, size_t sz);
584 typedef grand *gcirand_func(const void *, size_t sz, uint32);
585 typedef grand *gcnrand_func(const void *, size_t sz, const void *);
586 typedef grand *gcshakerand_func(const void *, size_t,
587 const void *, size_t,
588 const void *, size_t);
589 typedef grand *gcshafuncrand_func(const void *, size_t,
590 const void *, size_t);
591 typedef grand *gckmacrand_func(const void *, size_t, const void *, size_t);
592 typedef struct gccrand_info {
600 #define RNGF_MASK 255u
610 typedef struct gccrand_pyobj {
612 const gccrand_info *info;
614 #define GCCRAND_INFO(o) (((gccrand_pyobj *)(o))->info)
616 #define GCCRAND_DEF(name, ksz, func, f, nsz) \
617 static const gccrand_info func##_info = \
618 { name, ksz, f, nsz, (gcrand_func *)func };
621 static const gccrand_info *const gcrandtab[] = {
622 #define GCCRAND_ENTRY(name, ksz, func, f, nsz) &func##_info,
627 static PyObject *gcrand_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
629 const gccrand_info *info = GCCRAND_INFO(ty);
630 static char *kwlist[] = { "key", 0 };
634 if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#:new", kwlist, &k, &n))
636 if (keysz(n, info->keysz) != n) VALERR("bad key length");
637 return (grand_dopywrap(ty, info->func(k, n), f_freeme));
642 static PyObject *gcirand_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
644 const gccrand_info *info = GCCRAND_INFO(ty);
646 static char *kwlist[] = { "key", "i", 0 };
650 if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#O&:new", kwlist,
651 &k, &n, convu32, &i))
653 if (keysz(n, info->keysz) != n) VALERR("bad key length");
654 return (grand_dopywrap(ty,
655 ((gcirand_func *)info->func)(k, n, i),
661 static PyObject *gcnrand_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
663 const gccrand_info *info = GCCRAND_INFO(ty);
664 static char *kwlist[] = { "key", "nonce", 0 };
668 if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#s#:new", kwlist,
671 if (keysz(ksz, info->keysz) != ksz) VALERR("bad key length");
672 if (nsz != info->noncesz) VALERR("bad nonce length");
673 return (grand_dopywrap(ty,
674 ((gcnrand_func *)info->func)(k, ksz, n),
680 static PyObject *gcshakyrand_pynew(PyTypeObject *ty,
681 PyObject *arg, PyObject *kw)
683 const gccrand_info *info = GCCRAND_INFO(ty);
684 static char *kwlist_shake[] = { "key", "func", "perso", 0 };
685 static char *kwlist_func[] = { "key", "perso", 0 };
686 char *k, *f = 0, *p = 0;
687 Py_ssize_t ksz, fsz = 0, psz = 0;
689 if ((info->f&RNGF_MASK) == RNG_SHAKE
690 ? !PyArg_ParseTupleAndKeywords(arg, kw, "s#|s#s#:new", kwlist_shake,
691 &k, &ksz, &f, &fsz, &p, &psz)
692 : !PyArg_ParseTupleAndKeywords(arg, kw, "s#|s#:new", kwlist_func,
695 if (keysz(ksz, info->keysz) != ksz) VALERR("bad key length");
696 return (grand_dopywrap(ty,
697 (info->f&RNGF_MASK) == RNG_SHAKE
698 ? ((gcshakerand_func *)info->func)(f, fsz,
701 : ((gcshafuncrand_func *)info->func)(p, psz,
708 static PyObject *gccrand_pywrap(const gccrand_info *info)
710 gccrand_pyobj *g = newtype(gccrand_pytype, 0, info->name);
712 g->ty.ht_type.tp_basicsize = sizeof(grand_pyobj);
713 switch (info->f&RNGF_MASK) {
714 case RNG_LATIN: g->ty.ht_type.tp_base = gclatinrand_pytype; break;
715 default: g->ty.ht_type.tp_base = gcrand_pytype; break;
717 Py_INCREF(g->ty.ht_type.tp_base);
718 g->ty.ht_type.tp_flags = (Py_TPFLAGS_DEFAULT |
719 Py_TPFLAGS_BASETYPE |
720 Py_TPFLAGS_HEAPTYPE);
721 g->ty.ht_type.tp_alloc = PyType_GenericAlloc;
722 g->ty.ht_type.tp_free = 0;
723 switch (info->f&RNGF_MASK) {
724 case RNG_LATIN: g->ty.ht_type.tp_new = gcnrand_pynew; break;
725 case RNG_SEAL: g->ty.ht_type.tp_new = gcirand_pynew; break;
726 case RNG_SHAKE: case RNG_KMAC:
727 g->ty.ht_type.tp_new = gcshakyrand_pynew; break;
728 default: g->ty.ht_type.tp_new = gcrand_pynew; break;
730 typeready(&g->ty.ht_type);
731 return ((PyObject *)g);
734 static PyObject *gccrget_name(PyObject *me, void *hunoz)
735 { return (PyString_FromString(GCCRAND_INFO(me)->name)); }
736 static PyObject *gccrget_keysz(PyObject *me, void *hunoz)
737 { return (keysz_pywrap(GCCRAND_INFO(me)->keysz)); }
739 static PyObject *gclrmeth_tell(PyObject *me, PyObject *arg)
741 grand *r = GRAND_R(me);
745 if (!PyArg_ParseTuple(arg, ":tell")) return (0);
746 r->ops->misc(r, SALSA20_TELLU64, &off);
751 static PyObject *gclrmeth_seek(PyObject *me, PyObject *arg)
753 grand *r = GRAND_R(me);
756 if (!PyArg_ParseTuple(arg, "O&:seek", convk64, &off)) return (0);
757 r->ops->misc(r, SALSA20_SEEKU64, off);
761 static PyGetSetDef gccrand_pygetset[] = {
762 #define GETSETNAME(op, name) gccr##op##_##name
763 GET (keysz, "CR.keysz -> acceptable key sizes")
764 GET (name, "CR.name -> name of this kind of generator")
769 static PyMethodDef gclatinrand_pymethods[] = {
770 #define METHNAME(name) gclrmeth_##name
771 METH (tell, "R.tell() -> OFF")
772 METH (seek, "R.seek(OFF)")
777 static PyTypeObject gccrand_pytype_skel = {
778 PyObject_HEAD_INIT(0) 0, /* Header */
779 "GCCRand", /* @tp_name@ */
780 sizeof(gccrand_pyobj), /* @tp_basicsize@ */
781 0, /* @tp_itemsize@ */
783 0, /* @tp_dealloc@ */
785 0, /* @tp_getattr@ */
786 0, /* @tp_setattr@ */
787 0, /* @tp_compare@ */
789 0, /* @tp_as_number@ */
790 0, /* @tp_as_sequence@ */
791 0, /* @tp_as_mapping@ */
795 0, /* @tp_getattro@ */
796 0, /* @tp_setattro@ */
797 0, /* @tp_as_buffer@ */
798 Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
802 "Metaclass for symmetric crypto-based generators.",
804 0, /* @tp_traverse@ */
806 0, /* @tp_richcompare@ */
807 0, /* @tp_weaklistoffset@ */
809 0, /* @tp_iternext@ */
810 0, /* @tp_methods@ */
811 0, /* @tp_members@ */
812 gccrand_pygetset, /* @tp_getset@ */
815 0, /* @tp_descr_get@ */
816 0, /* @tp_descr_set@ */
817 0, /* @tp_dictoffset@ */
819 PyType_GenericAlloc, /* @tp_alloc@ */
820 abstract_pynew, /* @tp_new@ */
825 static PyTypeObject gcrand_pytype_skel = {
826 PyObject_HEAD_INIT(0) 0, /* Header */
827 "GCRand", /* @tp_name@ */
828 sizeof(grand_pyobj), /* @tp_basicsize@ */
829 0, /* @tp_itemsize@ */
831 grand_pydealloc, /* @tp_dealloc@ */
833 0, /* @tp_getattr@ */
834 0, /* @tp_setattr@ */
835 0, /* @tp_compare@ */
837 0, /* @tp_as_number@ */
838 0, /* @tp_as_sequence@ */
839 0, /* @tp_as_mapping@ */
843 0, /* @tp_getattro@ */
844 0, /* @tp_setattro@ */
845 0, /* @tp_as_buffer@ */
846 Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
850 "Abstract base class for symmetric crypto-based generators.",
852 0, /* @tp_traverse@ */
854 0, /* @tp_richcompare@ */
855 0, /* @tp_weaklistoffset@ */
857 0, /* @tp_iternext@ */
858 0, /* @tp_methods@ */
859 0, /* @tp_members@ */
863 0, /* @tp_descr_get@ */
864 0, /* @tp_descr_set@ */
865 0, /* @tp_dictoffset@ */
867 PyType_GenericAlloc, /* @tp_alloc@ */
868 abstract_pynew, /* @tp_new@ */
873 static PyTypeObject gclatinrand_pytype_skel = {
874 PyObject_HEAD_INIT(0) 0, /* Header */
875 "GCLatinRand", /* @tp_name@ */
876 sizeof(grand_pyobj), /* @tp_basicsize@ */
877 0, /* @tp_itemsize@ */
879 grand_pydealloc, /* @tp_dealloc@ */
881 0, /* @tp_getattr@ */
882 0, /* @tp_setattr@ */
883 0, /* @tp_compare@ */
885 0, /* @tp_as_number@ */
886 0, /* @tp_as_sequence@ */
887 0, /* @tp_as_mapping@ */
891 0, /* @tp_getattro@ */
892 0, /* @tp_setattro@ */
893 0, /* @tp_as_buffer@ */
894 Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
898 "Abstract base class for symmetric crypto-based generators.",
900 0, /* @tp_traverse@ */
902 0, /* @tp_richcompare@ */
903 0, /* @tp_weaklistoffset@ */
905 0, /* @tp_iternext@ */
906 gclatinrand_pymethods, /* @tp_methods@ */
907 0, /* @tp_members@ */
911 0, /* @tp_descr_get@ */
912 0, /* @tp_descr_set@ */
913 0, /* @tp_dictoffset@ */
915 PyType_GenericAlloc, /* @tp_alloc@ */
916 abstract_pynew, /* @tp_new@ */
921 /*----- SSL and TLS generators --------------------------------------------*/
923 static PyObject *sslprf_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
927 const gchash *hco = &md5, *hci = &sha;
929 char *kwlist[] = { "key", "seed", "ohash", "ihash", 0 };
931 if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#s#|O&O&:new", kwlist,
933 convgchash, &hco, convgchash, &hci))
935 rc = grand_dopywrap(ty, sslprf_rand(hco, hci, k, ksz, s, ssz), f_freeme);
940 static PyObject *tlsdx_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
944 const gcmac *mc = &sha_hmac;
946 char *kwlist[] = { "key", "seed", "mac", 0 };
948 if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#s#|O&:new", kwlist,
952 rc = grand_dopywrap(ty, tlsdx_rand(mc, k, ksz, s, ssz), f_freeme);
957 static PyObject *tlsprf_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
961 const gcmac *mcl = &md5_hmac, *mcr = &sha_hmac;
963 char *kwlist[] = { "key", "seed", "lmac", "rmac", 0 };
965 if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#s#|O&O&:new", kwlist,
967 convgcmac, &mcl, convgcmac, &mcr))
969 rc = grand_dopywrap(ty, tlsprf_rand(mcl, mcr, k, ksz, s, ssz), f_freeme);
974 static PyTypeObject sslprf_pytype_skel = {
975 PyObject_HEAD_INIT(0) 0, /* Header */
976 "SSLRand", /* @tp_name@ */
977 sizeof(grand_pyobj), /* @tp_basicsize@ */
978 0, /* @tp_itemsize@ */
980 grand_pydealloc, /* @tp_dealloc@ */
982 0, /* @tp_getattr@ */
983 0, /* @tp_setattr@ */
984 0, /* @tp_compare@ */
986 0, /* @tp_as_number@ */
987 0, /* @tp_as_sequence@ */
988 0, /* @tp_as_mapping@ */
992 0, /* @tp_getattro@ */
993 0, /* @tp_setattro@ */
994 0, /* @tp_as_buffer@ */
995 Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
999 "Random number generator for SSL master secret.",
1001 0, /* @tp_traverse@ */
1003 0, /* @tp_richcompare@ */
1004 0, /* @tp_weaklistoffset@ */
1006 0, /* @tp_iternext@ */
1007 0, /* @tp_methods@ */
1008 0, /* @tp_members@ */
1009 0, /* @tp_getset@ */
1012 0, /* @tp_descr_get@ */
1013 0, /* @tp_descr_set@ */
1014 0, /* @tp_dictoffset@ */
1016 PyType_GenericAlloc, /* @tp_alloc@ */
1017 sslprf_pynew, /* @tp_new@ */
1022 static PyTypeObject tlsdx_pytype_skel = {
1023 PyObject_HEAD_INIT(0) 0, /* Header */
1024 "TLSDataExpansion", /* @tp_name@ */
1025 sizeof(grand_pyobj), /* @tp_basicsize@ */
1026 0, /* @tp_itemsize@ */
1028 grand_pydealloc, /* @tp_dealloc@ */
1030 0, /* @tp_getattr@ */
1031 0, /* @tp_setattr@ */
1032 0, /* @tp_compare@ */
1034 0, /* @tp_as_number@ */
1035 0, /* @tp_as_sequence@ */
1036 0, /* @tp_as_mapping@ */
1040 0, /* @tp_getattro@ */
1041 0, /* @tp_setattro@ */
1042 0, /* @tp_as_buffer@ */
1043 Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
1044 Py_TPFLAGS_BASETYPE,
1047 "TLS data expansion function.",
1049 0, /* @tp_traverse@ */
1051 0, /* @tp_richcompare@ */
1052 0, /* @tp_weaklistoffset@ */
1054 0, /* @tp_iternext@ */
1055 0, /* @tp_methods@ */
1056 0, /* @tp_members@ */
1057 0, /* @tp_getset@ */
1060 0, /* @tp_descr_get@ */
1061 0, /* @tp_descr_set@ */
1062 0, /* @tp_dictoffset@ */
1064 PyType_GenericAlloc, /* @tp_alloc@ */
1065 tlsdx_pynew, /* @tp_new@ */
1070 static PyTypeObject tlsprf_pytype_skel = {
1071 PyObject_HEAD_INIT(0) 0, /* Header */
1072 "TLSPRF", /* @tp_name@ */
1073 sizeof(grand_pyobj), /* @tp_basicsize@ */
1074 0, /* @tp_itemsize@ */
1076 grand_pydealloc, /* @tp_dealloc@ */
1078 0, /* @tp_getattr@ */
1079 0, /* @tp_setattr@ */
1080 0, /* @tp_compare@ */
1082 0, /* @tp_as_number@ */
1083 0, /* @tp_as_sequence@ */
1084 0, /* @tp_as_mapping@ */
1088 0, /* @tp_getattro@ */
1089 0, /* @tp_setattro@ */
1090 0, /* @tp_as_buffer@ */
1091 Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
1092 Py_TPFLAGS_BASETYPE,
1095 "TLS pseudorandom function.",
1097 0, /* @tp_traverse@ */
1099 0, /* @tp_richcompare@ */
1100 0, /* @tp_weaklistoffset@ */
1102 0, /* @tp_iternext@ */
1103 0, /* @tp_methods@ */
1104 0, /* @tp_members@ */
1105 0, /* @tp_getset@ */
1108 0, /* @tp_descr_get@ */
1109 0, /* @tp_descr_set@ */
1110 0, /* @tp_dictoffset@ */
1112 PyType_GenericAlloc, /* @tp_alloc@ */
1113 tlsprf_pynew, /* @tp_new@ */
1118 /*----- DSA generator -----------------------------------------------------*/
1120 static PyObject *dsarand_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
1125 char *kwlist[] = { "seed", 0 };
1127 if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#:new", kwlist, &p, &sz))
1129 rc = grand_dopywrap(ty, dsarand_create(p, sz), f_freeme);
1134 static PyObject *drget_seed(PyObject *me, void *hunoz)
1136 grand *r = GRAND_R(me);
1137 int n = r->ops->misc(r, DSARAND_SEEDSZ);
1138 PyObject *rc = bytestring_pywrap(0, n);
1139 r->ops->misc(r, DSARAND_GETSEED, PyString_AS_STRING(rc));
1143 static PyGetSetDef dsarand_pygetset[] = {
1144 #define GETSETNAME(op, name) dr##op##_##name
1145 GET (seed, "R.seed -> current generator seed")
1150 static PyTypeObject dsarand_pytype_skel = {
1151 PyObject_HEAD_INIT(0) 0, /* Header */
1152 "DSARand", /* @tp_name@ */
1153 sizeof(grand_pyobj), /* @tp_basicsize@ */
1154 0, /* @tp_itemsize@ */
1156 grand_pydealloc, /* @tp_dealloc@ */
1158 0, /* @tp_getattr@ */
1159 0, /* @tp_setattr@ */
1160 0, /* @tp_compare@ */
1162 0, /* @tp_as_number@ */
1163 0, /* @tp_as_sequence@ */
1164 0, /* @tp_as_mapping@ */
1168 0, /* @tp_getattro@ */
1169 0, /* @tp_setattro@ */
1170 0, /* @tp_as_buffer@ */
1171 Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
1172 Py_TPFLAGS_BASETYPE,
1175 "Pseudorandom number generator for constructing DSA parameters.",
1177 0, /* @tp_traverse@ */
1179 0, /* @tp_richcompare@ */
1180 0, /* @tp_weaklistoffset@ */
1182 0, /* @tp_iternext@ */
1183 0, /* @tp_methods@ */
1184 0, /* @tp_members@ */
1185 dsarand_pygetset, /* @tp_getset@ */
1188 0, /* @tp_descr_get@ */
1189 0, /* @tp_descr_set@ */
1190 0, /* @tp_dictoffset@ */
1192 PyType_GenericAlloc, /* @tp_alloc@ */
1193 dsarand_pynew, /* @tp_new@ */
1198 /*----- Blum-Blum-Shub generator ------------------------------------------*/
1200 static PyObject *bbs_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
1202 mp *n = 0, *x = MP_TWO;
1204 char *kwlist[] = { "n", "x", 0 };
1206 if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&|O&:new", kwlist,
1207 convmp, &n, convmp, &x))
1209 rc = grand_dopywrap(ty, bbs_rand(n, x), f_freeme);
1216 static PyObject *bbsmeth_step(PyObject *me, PyObject *arg)
1218 grand *r = GRAND_R(me); if (!PyArg_ParseTuple(arg, ":step")) return (0);
1219 r->ops->misc(r, BBS_STEP); RETURN_ME;
1222 static PyObject *bbsmeth_bits(PyObject *me, PyObject *arg)
1224 grand *r = GRAND_R(me); unsigned n; uint32 w;
1225 if (!PyArg_ParseTuple(arg, "O&:bits", convuint, &n)) goto end;
1226 if (n > 32) VALERR("can't get more than 32 bits");
1227 r->ops->misc(r, BBS_BITS, n, &w); return (getulong(w));
1232 static PyObject *bbsmeth_wrap(PyObject *me, PyObject *arg)
1234 grand *r = GRAND_R(me); if (!PyArg_ParseTuple(arg, ":wrap")) return (0);
1235 r->ops->misc(r, BBS_WRAP); RETURN_ME;
1238 static PyObject *bbsget_n(PyObject *me, void *hunoz)
1240 mp *x = MP_NEW; grand *r = GRAND_R(me);
1241 r->ops->misc(r, BBS_MOD, &x); return (mp_pywrap(x));
1244 static PyObject *bbsget_x(PyObject *me, void *hunoz)
1246 mp *x = MP_NEW; grand *r = GRAND_R(me);
1247 r->ops->misc(r, BBS_STATE, &x); return (mp_pywrap(x));
1250 static int bbsset_x(PyObject *me, PyObject *val, void *hunoz)
1252 mp *x = 0; grand *r = GRAND_R(me); int rc = -1; if (!x) NIERR("__del__");
1253 if ((x = getmp(val)) == 0) goto end; r->ops->misc(r, BBS_SET, x); rc = 0;
1254 end: mp_drop(x); return (rc);
1257 static PyObject *bbsget_stepsz(PyObject *me, void *hunoz)
1259 grand *r = GRAND_R(me);
1260 return (PyInt_FromLong(r->ops->misc(r, BBS_STEPSZ)));
1263 static PyMethodDef bbs_pymethods[] = {
1264 #define METHNAME(name) bbsmeth_##name
1265 METH (step, "R.step(): steps the generator (not useful)")
1266 METH (bits, "R.bits(N) -> W: returns N bits (<= 32) from the generator")
1267 METH (wrap, "R.wrap(): flushes unused bits in internal buffer")
1272 static PyGetSetDef bbs_pygetset[] = {
1273 #define GETSETNAME(op, name) bbs##op##_##name
1274 GET (n, "R.n -> Blum modulus")
1275 GETSET(x, "R.x -> current seed value")
1276 GET (stepsz, "R.stepsz -> number of bits generated per step")
1281 static PyTypeObject bbs_pytype_skel = {
1282 PyObject_HEAD_INIT(0) 0, /* Header */
1283 "BlumBlumShub", /* @tp_name@ */
1284 sizeof(grand_pyobj), /* @tp_basicsize@ */
1285 0, /* @tp_itemsize@ */
1287 grand_pydealloc, /* @tp_dealloc@ */
1289 0, /* @tp_getattr@ */
1290 0, /* @tp_setattr@ */
1291 0, /* @tp_compare@ */
1293 0, /* @tp_as_number@ */
1294 0, /* @tp_as_sequence@ */
1295 0, /* @tp_as_mapping@ */
1299 0, /* @tp_getattro@ */
1300 0, /* @tp_setattro@ */
1301 0, /* @tp_as_buffer@ */
1302 Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
1303 Py_TPFLAGS_BASETYPE,
1306 "Blum-Blum-Shub strong pseudorandom number generator.",
1308 0, /* @tp_traverse@ */
1310 0, /* @tp_richcompare@ */
1311 0, /* @tp_weaklistoffset@ */
1313 0, /* @tp_iternext@ */
1314 bbs_pymethods, /* @tp_methods@ */
1315 0, /* @tp_members@ */
1316 bbs_pygetset, /* @tp_getset@ */
1319 0, /* @tp_descr_get@ */
1320 0, /* @tp_descr_set@ */
1321 0, /* @tp_dictoffset@ */
1323 PyType_GenericAlloc, /* @tp_alloc@ */
1324 bbs_pynew, /* @tp_new@ */
1329 typedef struct bbspriv_pyobj {
1334 #define BBSPRIV_BP(o) (&((bbspriv_pyobj *)(o))->bp)
1336 static PyObject *bbspriv_pynew(PyTypeObject *ty,
1337 PyObject *arg, PyObject *kw)
1339 mp *p = 0, *q = 0, *n = 0, *x = MP_TWO;
1340 bbspriv_pyobj *rc = 0;
1341 char *kwlist[] = { "n", "p", "q", "seed", 0 };
1343 if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&O&O&O&:new", kwlist,
1344 convmp, &n, convmp, &p, convmp, &q,
1347 if (!n + !p + !q > 1) VALERR("must specify at least two of n, p, q");
1348 if (!n) n = mp_mul(MP_NEW, p, q);
1349 else if (!p) mp_div(&p, 0, n, q);
1350 else if (!q) mp_div(&q, 0, n, p);
1351 rc = (bbspriv_pyobj *)ty->tp_alloc(ty, 0);
1352 rc->gr.r = bbs_rand(n, x);
1353 rc->gr.f = f_freeme;
1354 rc->bp.p = MP_COPY(p);
1355 rc->bp.q = MP_COPY(q);
1356 rc->bp.n = MP_COPY(n);
1358 mp_drop(p); mp_drop(q); mp_drop(n); mp_drop(x);
1359 return ((PyObject *)rc);
1362 static PyObject *meth__BBSPriv_generate(PyObject *me,
1363 PyObject *arg, PyObject *kw)
1365 bbs_priv bp = { 0 };
1368 unsigned nbits, n = 0;
1369 grand *r = &rand_global;
1370 char *kwlist[] = { "class", "nbits", "event", "rng", "nsteps", "seed", 0 };
1371 bbspriv_pyobj *rc = 0;
1373 if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&|O&O&O&O&:generate", kwlist,
1374 &me, convuint, &nbits, convpgev, &evt,
1375 convgrand, &r, convuint, &n, convmp, &x))
1377 if (bbs_gen(&bp, nbits, r, n, evt.proc, evt.ctx))
1378 VALERR("prime genration failed");
1379 rc = PyObject_New(bbspriv_pyobj, bbspriv_pytype);
1380 rc->gr.r = bbs_rand(bp.n, x);
1381 rc->gr.f = f_freeme;
1382 rc->bp.p = MP_COPY(bp.p);
1383 rc->bp.q = MP_COPY(bp.q);
1384 rc->bp.n = MP_COPY(bp.n);
1386 mp_drop(bp.p); mp_drop(bp.q); mp_drop(bp.n); mp_drop(x);
1387 return ((PyObject *)rc);
1390 static void bbspriv_pydealloc(PyObject *me)
1392 bbs_priv *bp = BBSPRIV_BP(me);
1396 grand_pydealloc(me);
1399 static PyObject *bpmeth_ff(PyObject *me, PyObject *arg)
1401 mp *n = 0; grand *r = GRAND_R(me); bbs_priv *bp = BBSPRIV_BP(me);
1402 if (!PyArg_ParseTuple(arg, "O&:ff", convmp, &n)) return (0);
1403 r->ops->misc(r, BBS_FF, bp, n); RETURN_ME;
1406 static PyObject *bpmeth_rew(PyObject *me, PyObject *arg)
1408 mp *n = 0; grand *r = GRAND_R(me); bbs_priv *bp = BBSPRIV_BP(me);
1409 if (!PyArg_ParseTuple(arg, "O&:rew", convmp, &n)) return (0);
1410 r->ops->misc(r, BBS_REW, bp, n); RETURN_ME;
1413 static PyObject *bpget_n(PyObject *me, void *hunoz)
1414 { return (mp_pywrap(MP_COPY(BBSPRIV_BP(me)->n))); }
1416 static PyObject *bpget_p(PyObject *me, void *hunoz)
1417 { return (mp_pywrap(MP_COPY(BBSPRIV_BP(me)->p))); }
1419 static PyObject *bpget_q(PyObject *me, void *hunoz)
1420 { return (mp_pywrap(MP_COPY(BBSPRIV_BP(me)->q))); }
1422 static PyMethodDef bbspriv_pymethods[] = {
1423 #define METHNAME(name) bpmeth_##name
1424 METH (ff, "R.ff(N): fast-forward N places")
1425 METH (rew, "R.rew(N): rewind N places")
1430 static PyGetSetDef bbspriv_pygetset[] = {
1431 #define GETSETNAME(op, name) bp##op##_##name
1432 GET (n, "R.n -> Blum modulus")
1433 GET (p, "R.p -> one of the factors of the modulus")
1434 GET (q, "R.q -> one of the factors of the modulus")
1439 static PyTypeObject bbspriv_pytype_skel = {
1440 PyObject_HEAD_INIT(0) 0, /* Header */
1441 "BBSPriv", /* @tp_name@ */
1442 sizeof(bbspriv_pyobj), /* @tp_basicsize@ */
1443 0, /* @tp_itemsize@ */
1445 bbspriv_pydealloc, /* @tp_dealloc@ */
1447 0, /* @tp_getattr@ */
1448 0, /* @tp_setattr@ */
1449 0, /* @tp_compare@ */
1451 0, /* @tp_as_number@ */
1452 0, /* @tp_as_sequence@ */
1453 0, /* @tp_as_mapping@ */
1457 0, /* @tp_getattro@ */
1458 0, /* @tp_setattro@ */
1459 0, /* @tp_as_buffer@ */
1460 Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
1461 Py_TPFLAGS_BASETYPE,
1464 "Blum-Blum-Shub strong pseudorandom generator, with private key.",
1466 0, /* @tp_traverse@ */
1468 0, /* @tp_richcompare@ */
1469 0, /* @tp_weaklistoffset@ */
1471 0, /* @tp_iternext@ */
1472 bbspriv_pymethods, /* @tp_methods@ */
1473 0, /* @tp_members@ */
1474 bbspriv_pygetset, /* @tp_getset@ */
1477 0, /* @tp_descr_get@ */
1478 0, /* @tp_descr_set@ */
1479 0, /* @tp_dictoffset@ */
1481 PyType_GenericAlloc, /* @tp_alloc@ */
1482 bbspriv_pynew, /* @tp_new@ */
1487 /*----- Global stuff ------------------------------------------------------*/
1489 static PyMethodDef methods[] = {
1490 #define METHNAME(name) meth_##name
1491 KWMETH(_BBSPriv_generate, "\
1492 generate(NBITS, [event = pgen_nullev], [rng = rand],\n\
1493 [nsteps = 0], [seed = 2])")
1498 void rand_pyinit(void)
1500 INITTYPE(grand, root);
1501 INITTYPE(truerand, grand);
1502 INITTYPE(fibrand, grand);
1503 INITTYPE(lcrand, grand);
1504 INITTYPE(dsarand, grand);
1505 INITTYPE(bbs, grand);
1506 INITTYPE(bbspriv, bbs);
1507 INITTYPE(sslprf, grand);
1508 INITTYPE(tlsdx, grand);
1509 INITTYPE(tlsprf, grand);
1510 INITTYPE(gccrand, type);
1511 INITTYPE(gcrand, grand);
1512 INITTYPE(gclatinrand, gcrand);
1513 rand_noisesrc(RAND_GLOBAL, &noise_source);
1514 rand_seed(RAND_GLOBAL, 160);
1515 addmethods(methods);
1518 #define gccrand gccrand_info
1519 GEN(gccrands, crand)
1521 void rand_pyinsert(PyObject *mod)
1523 INSERT("GRand", grand_pytype);
1524 INSERT("TrueRand", truerand_pytype);
1525 INSERT("LCRand", lcrand_pytype);
1526 INSERT("FibRand", fibrand_pytype);
1527 INSERT("SSLRand", sslprf_pytype);
1528 INSERT("TLSDataExpansion", tlsdx_pytype);
1529 INSERT("TLSPRF", tlsprf_pytype);
1530 INSERT("DSARand", dsarand_pytype);
1531 INSERT("BlumBlumShub", bbs_pytype);
1532 INSERT("BBSPriv", bbspriv_pytype);
1533 INSERT("GCCRand", gccrand_pytype);
1534 INSERT("GCRand", gcrand_pytype);
1535 INSERT("GCLatinRand", gclatinrand_pytype);
1536 rand_pyobj = grand_pywrap(&rand_global, 0); Py_INCREF(rand_pyobj);
1537 gccrands_dict = gccrands(); Py_INCREF(gccrands_dict);
1538 INSERT("gccrands", gccrands_dict);
1539 INSERT("rand", rand_pyobj);
1542 /*----- That's all, folks -------------------------------------------------*/