print '#define RNGS(_) \\'
for i in (cross(prps, ['ofb', 'counter'])):
print ('\t_("%(prim)s-%(mode)s", %(prim)s_keysz, ' +
- '%(prim)s_%(mode)srand, 0, 0) \\') % \
+ '%(prim)s_%(mode)srand, RNG_PLAIN, 0) \\') % \
{'prim': i[0], 'mode': i[1]}
for i in (cross(hashes, 'mgf')):
print ('\t_("%(prim)s-%(mode)s", %(prim)s_%(mode)skeysz, ' +
- '%(prim)s_%(mode)srand, 0, 0) \\') % \
+ '%(prim)s_%(mode)srand, RNG_PLAIN, 0) \\') % \
{'prim': i[0], 'mode': i[1]}
print '\t_("rc4", rc4_keysz, rc4_rand, 0, 0) \\'
-print '\t_("seal", seal_keysz, seal_rand, RNGF_INT, 0) \\'
+print '\t_("seal", seal_keysz, seal_rand, RNG_SEAL, 0) \\'
for i in latindances:
for r in ['salsa20', 'xsalsa20', 'chacha', 'xchacha']:
if i.startswith(r):
raise ValueError, 'failed to find root name for %s' % i
if i.endswith('-ietf'): root += '_ietf'
print ('\t_("%(name)s", %(root)s_keysz, %(id)s_rand, ' +
- 'RNGF_NONCE | RNGF_LATIN, %(ROOT)s_NONCESZ) \\') % \
+ 'RNG_LATIN, %(ROOT)s_NONCESZ) \\') % \
{'name': i, 'id': i.translate(None, '/').replace('-', '_'),
'root': root, 'ROOT': root.upper()}
print '\t/* end */'
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;
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);
}