chiark / gitweb /
Merge branch '1.1.x'
[catacomb-python] / algorithms.py
index ad41f69b6d42470c6511640d39db85e1d2aa494d..a2a468f46bf613fa8207079e0b6f63e19967e523 100644 (file)
@@ -29,6 +29,15 @@ ecb cbc cfb ofb counter
 streamciphers = '''
 rc4 seal
 '''.split()
+latindances = '''
+salsa20 salsa20/12 salsa20/8
+salsa20-ietf salsa20/12-ietf salsa20/8-ietf
+xsalsa20 xsalsa20/12 xsalsa20/8
+chacha20 chacha12 chacha8
+chacha20-ietf chacha12-ietf chacha8-ietf
+xchacha20 xchacha12 xchacha8
+'''.split()
+streamciphers += map(lambda s: s.translate(None, '/'), latindances)
 hashes = '''
 md2 md4 md5 tiger has160
 sha sha224 sha256 sha384 sha512
@@ -59,20 +68,30 @@ print '#define PRPS(_) \\'
 for i in prps:
   print '\t_(%s, %s) \\' % (i.upper(), i)
 print '\t/* end */'
-
-print '#define RNGF_INT 1u'
 print
 
 print '#define RNGS(_) \\'
 for i in (cross(prps, ['ofb', 'counter'])):
   print ('\t_("%(prim)s-%(mode)s", %(prim)s_keysz, ' +
-         '%(prim)s_%(mode)srand, 0) \\') % \
+         '%(prim)s_%(mode)srand, 0, 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) \\') % \
+         '%(prim)s_%(mode)srand, 0, 0) \\') % \
          {'prim': i[0], 'mode': i[1]}
-print '\t_("rc4", rc4_keysz, rc4_rand, 0) \\'
-print '\t_("seal", seal_keysz, seal_rand, RNGF_INT) \\'
+print '\t_("rc4", rc4_keysz, rc4_rand, 0, 0) \\'
+print '\t_("seal", seal_keysz, seal_rand, RNGF_INT, 0) \\'
+for i in latindances:
+  for r in ['salsa20', 'xsalsa20', 'chacha', 'xchacha']:
+    if i.startswith(r):
+      root = r
+      break
+  else:
+    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) \\') % \
+      {'name': i, 'id': i.translate(None, '/').replace('-', '_'),
+       'root': root, 'ROOT': root.upper()}
 print '\t/* end */'
 print