Initial check-in of catacomb-python.
[catacomb-python] / algorithms.py
CommitLineData
d7ab1bab 1## -*-python-*-
2
3def cross(*seq):
4 if not len(seq):
5 return [(),]
6 x = seq[0]
7 if type(x) is not tuple and type(x) is not list:
8 x = x,
9 r = []
10 for i in x:
11 for j in cross(*seq[1:]):
12 r.append((i,) + j)
13 return r
14
15prps = '''
16des desx des3 mars
17idea safer safersk
18blowfish twofish
19tea xtea
20rc2 rc5
21skipjack
22cast128 cast256
23square rijndael rijndael192 rijndael256
24serpent noekeon
25'''.split()
26pmodes = '''
27ecb cbc cfb ofb counter
28'''.split()
29streamciphers = '''
30rc4 seal
31'''.split()
32hashes = '''
33md2 md4 md5 tiger has160
34sha sha224 sha256 sha384 sha512
35rmd128 rmd160 rmd256 rmd320
36whirlpool whirlpool256
37'''.split()
38hmodes = '''
39mgf hmac
40'''.split()
41
42print '/* algorithms.h [generated] */'
43print
44
45for i in prps:
46 print '#include <catacomb/%s.h>' % i
47 for j in pmodes:
48 print '#include <catacomb/%s-%s.h>' % (i, j)
49for i in streamciphers:
50 print '#include <catacomb/%s.h>' % i
51print
52for i in hashes:
53 print '#include <catacomb/%s.h>' % i
54 for j in hmodes:
55 print '#include <catacomb/%s-%s.h>' % (i, j)
56print
57
58print '#define PRPS(DO) \\'
59for i in prps:
60 print ' DO(%s, %s) \\' % (i.upper(), i)
61print ' /* end */'
62print
63
64print '#define RNGS(DO) \\'
65for i in (cross(prps, ['ofb', 'counter']) +
66 cross(hashes, 'mgf')):
67 print ' DO("%(prim)s-%(mode)s", %(prim)s_%(mode)srand) \\' % \
68 {'prim': i[0], 'mode': i[1]}
69print ' DO("rc4", rc4_rand) \\'
70print ' DO("seal", seal_randkludge) \\'
71print ' /* end */'
72print