X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/c00df2de0692981b25f2194e5ad58539407d6ac1..3200c805f073fc4a480fbbd1345c09d03f4efae4:/algorithms.py diff --git a/algorithms.py b/algorithms.py index 7f31e60..2444382 100644 --- a/algorithms.py +++ b/algorithms.py @@ -26,6 +26,7 @@ serpent noekeon pmodes = ''' ecb cbc cfb ofb counter cmac pmac1 +ccm eax gcm ocb1 ocb3 '''.split() streamciphers = ''' rc4 seal @@ -38,7 +39,7 @@ chacha20 chacha12 chacha8 chacha20-ietf chacha12-ietf chacha8-ietf xchacha20 xchacha12 xchacha8 '''.split() -streamciphers += map(lambda s: s.translate(None, '/'), latindances) +streamciphers += map(lambda s: s.replace('/', ''), latindances) hashes = ''' md2 md4 md5 tiger has160 sha sha224 sha256 sha512/224 sha512/256 sha384 sha512 @@ -50,59 +51,59 @@ hmodes = ''' mgf hmac '''.split() -print '/* algorithms.h [generated] */' -print +print('/* algorithms.h [generated] */') +print('') for i in prps: - print '#include ' % i.replace('/', '-') + print('#include ' % i.replace('/', '-')) for j in pmodes: - print '#include ' % (i.replace('/', '-'), j) + print('#include ' % (i.replace('/', '-'), j)) for i in streamciphers: - print '#include ' % i.replace('/', '-') -print + print('#include ' % i.replace('/', '-')) +print('') for i in hashes: - print '#include ' % i.replace('/', '-') + print('#include ' % i.replace('/', '-')) for j in hmodes: - print '#include ' % (i.replace('/', '-'), j) -print + print('#include ' % (i.replace('/', '-'), j)) +print('') -print '#define PRPS(_) \\' +print('#define PRPS(_) \\') for i in prps: - print '\t_(%s, %s) \\' % (i.upper(), i) -print '\t/* end */' -print + print('\t_(%s, %s) \\' % (i.upper(), i)) +print('\t/* end */') +print('') -print '#define RNGS(_) \\' +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('/', '_')} + 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) \\' + 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 + 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, ' + + print(('\t_("%(name)s", %(root)s_keysz, %(id)s_rand, ' + 'RNG_LATIN, %(ROOT)s_NONCESZ) \\') % \ - {'name': i, 'id': i.translate(None, '/').replace('-', '_'), - 'root': root, 'ROOT': root.upper()} + {'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, ' + + 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, ' + + {'w': i}) + print(('\t_("kmac%(w)d", kmac%(w)d_keysz, kmac%(w)d_rand, ' + 'RNG_KMAC, 0) \\') % \ - {'w': i} -print '\t/* end */' -print + {'w': i}) +print('\t/* end */') +print('')