Commit | Line | Data |
---|---|---|
d7ab1bab | 1 | ## -*-python-*- |
2 | ||
3 | def 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 | ||
15 | prps = ''' | |
16 | des desx des3 mars | |
17 | idea safer safersk | |
18 | blowfish twofish | |
19 | tea xtea | |
20 | rc2 rc5 | |
21 | skipjack | |
22 | cast128 cast256 | |
23 | square rijndael rijndael192 rijndael256 | |
24 | serpent noekeon | |
25 | '''.split() | |
26 | pmodes = ''' | |
27 | ecb cbc cfb ofb counter | |
28 | '''.split() | |
29 | streamciphers = ''' | |
30 | rc4 seal | |
31 | '''.split() | |
3f4f64b8 | 32 | latindances = ''' |
f9041075 MW |
33 | salsa20 salsa20/12 salsa20/8 |
34 | salsa20-ietf salsa20/12-ietf salsa20/8-ietf | |
35 | xsalsa20 xsalsa20/12 xsalsa20/8 | |
36 | chacha20 chacha12 chacha8 | |
37 | chacha20-ietf chacha12-ietf chacha8-ietf | |
38 | xchacha20 xchacha12 xchacha8 | |
3f4f64b8 MW |
39 | '''.split() |
40 | streamciphers += map(lambda s: s.translate(None, '/'), latindances) | |
d7ab1bab | 41 | hashes = ''' |
42 | md2 md4 md5 tiger has160 | |
43 | sha sha224 sha256 sha384 sha512 | |
44 | rmd128 rmd160 rmd256 rmd320 | |
45 | whirlpool whirlpool256 | |
46 | '''.split() | |
47 | hmodes = ''' | |
48 | mgf hmac | |
49 | '''.split() | |
50 | ||
51 | print '/* algorithms.h [generated] */' | |
52 | ||
53 | ||
54 | for i in prps: | |
55 | print '#include <catacomb/%s.h>' % i | |
56 | for j in pmodes: | |
57 | print '#include <catacomb/%s-%s.h>' % (i, j) | |
58 | for i in streamciphers: | |
b2687a0a | 59 | print '#include <catacomb/%s.h>' % i |
d7ab1bab | 60 | |
61 | for i in hashes: | |
62 | print '#include <catacomb/%s.h>' % i | |
63 | for j in hmodes: | |
64 | print '#include <catacomb/%s-%s.h>' % (i, j) | |
65 | ||
66 | ||
03ed9abb | 67 | print '#define PRPS(_) \\' |
d7ab1bab | 68 | for i in prps: |
eb0f76ed MW |
69 | print '\t_(%s, %s) \\' % (i.upper(), i) |
70 | print '\t/* end */' | |
03ed9abb MW |
71 | |
72 | ||
73 | print '#define RNGS(_) \\' | |
74 | for i in (cross(prps, ['ofb', 'counter'])): | |
eb0f76ed | 75 | print ('\t_("%(prim)s-%(mode)s", %(prim)s_keysz, ' + |
3f4f64b8 | 76 | '%(prim)s_%(mode)srand, 0, 0) \\') % \ |
eb0f76ed | 77 | {'prim': i[0], 'mode': i[1]} |
03ed9abb | 78 | for i in (cross(hashes, 'mgf')): |
eb0f76ed | 79 | print ('\t_("%(prim)s-%(mode)s", %(prim)s_%(mode)skeysz, ' + |
3f4f64b8 | 80 | '%(prim)s_%(mode)srand, 0, 0) \\') % \ |
eb0f76ed | 81 | {'prim': i[0], 'mode': i[1]} |
3f4f64b8 MW |
82 | print '\t_("rc4", rc4_keysz, rc4_rand, 0, 0) \\' |
83 | print '\t_("seal", seal_keysz, seal_rand, RNGF_INT, 0) \\' | |
84 | for i in latindances: | |
85 | for r in ['salsa20', 'xsalsa20', 'chacha', 'xchacha']: | |
86 | if i.startswith(r): | |
87 | root = r | |
88 | break | |
89 | else: | |
90 | raise ValueError, 'failed to find root name for %s' % i | |
f9041075 | 91 | if i.endswith('-ietf'): root += '_ietf' |
3f4f64b8 | 92 | print ('\t_("%(name)s", %(root)s_keysz, %(id)s_rand, ' + |
35e5469a | 93 | 'RNGF_NONCE | RNGF_LATIN, %(ROOT)s_NONCESZ) \\') % \ |
f9041075 | 94 | {'name': i, 'id': i.translate(None, '/').replace('-', '_'), |
3f4f64b8 | 95 | 'root': root, 'ROOT': root.upper()} |
eb0f76ed | 96 | print '\t/* end */' |
d7ab1bab | 97 |