X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/d7ab1bab81155baa763449d5afa81e16df98dbe7..994b671e8ee14c5690c179bb19d3f1cfc4286186:/algorithms.py diff --git a/algorithms.py b/algorithms.py index cc209c6..46abccb 100644 --- a/algorithms.py +++ b/algorithms.py @@ -29,11 +29,21 @@ 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.replace('/', ''), latindances) hashes = ''' md2 md4 md5 tiger has160 -sha sha224 sha256 sha384 sha512 +sha sha224 sha256 sha512/224 sha512/256 sha384 sha512 rmd128 rmd160 rmd256 rmd320 whirlpool whirlpool256 +sha3-224 sha3-256 sha3-384 sha3-512 '''.split() hmodes = ''' mgf hmac @@ -43,30 +53,55 @@ print '/* algorithms.h [generated] */' print for i in prps: - print '#include ' % i + print '#include ' % i.replace('/', '-') for j in pmodes: - print '#include ' % (i, j) + print '#include ' % (i.replace('/', '-'), j) for i in streamciphers: - print '#include ' % i + print '#include ' % i.replace('/', '-') print for i in hashes: - print '#include ' % i + print '#include ' % i.replace('/', '-') for j in hmodes: - print '#include ' % (i, j) + print '#include ' % (i.replace('/', '-'), j) print -print '#define PRPS(DO) \\' +print '#define PRPS(_) \\' for i in prps: - print ' DO(%s, %s) \\' % (i.upper(), i) -print ' /* end */' + print '\t_(%s, %s) \\' % (i.upper(), i) +print '\t/* end */' print -print '#define RNGS(DO) \\' -for i in (cross(prps, ['ofb', 'counter']) + - cross(hashes, 'mgf')): - print ' DO("%(prim)s-%(mode)s", %(prim)s_%(mode)srand) \\' % \ - {'prim': i[0], 'mode': i[1]} -print ' DO("rc4", rc4_rand) \\' -print ' DO("seal", seal_randkludge) \\' -print ' /* end */' +print '#define RNGS(_) \\' +for i in (cross(prps, ['ofb', 'counter'])): + print ('\t_("%(prim)s-%(mode)s", %(primid)s_keysz, ' + + '%(primid)s_%(mode)srand, RNG_PLAIN, 0) \\') % \ + {'prim': i[0], 'mode': i[1], + 'primid': i[0].replace('-', '_').replace('/', '_')} +for i in (cross(hashes, 'mgf')): + print ('\t_("%(prim)s-%(mode)s", %(primid)s_%(mode)skeysz, ' + + '%(primid)s_%(mode)srand, RNG_PLAIN, 0) \\') % \ + {'prim': i[0], 'mode': i[1], + 'primid': i[0].replace('-', '_').replace('/', '_')} +print '\t_("rc4", rc4_keysz, rc4_rand, 0, 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): + 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, ' + + 'RNG_LATIN, %(ROOT)s_NONCESZ) \\') % \ + {'name': i, 'id': i.replace('/', '').replace('-', '_'), + 'root': root, 'ROOT': root.upper()} +for i in [128, 256]: + print ('\t_("shake%(w)d", shake%(w)d_keysz, cshake%(w)d_rand, ' + + 'RNG_SHAKE, 0) \\') % \ + {'w': i} + print ('\t_("kmac%(w)d", kmac%(w)d_keysz, kmac%(w)d_rand, ' + + 'RNG_KMAC, 0) \\') % \ + {'w': i} +print '\t/* end */' print