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 | 39 | '''.split() |
3e80d327 | 40 | streamciphers += map(lambda s: s.replace('/', ''), latindances) |
d7ab1bab | 41 | hashes = ''' |
42 | md2 md4 md5 tiger has160 | |
cae28129 | 43 | sha sha224 sha256 sha512/224 sha512/256 sha384 sha512 |
d7ab1bab | 44 | rmd128 rmd160 rmd256 rmd320 |
45 | whirlpool whirlpool256 | |
6bd22b53 | 46 | sha3-224 sha3-256 sha3-384 sha3-512 |
d7ab1bab | 47 | '''.split() |
48 | hmodes = ''' | |
49 | mgf hmac | |
50 | '''.split() | |
51 | ||
52 | print '/* algorithms.h [generated] */' | |
53 | ||
54 | ||
55 | for i in prps: | |
a7f2e389 | 56 | print '#include <catacomb/%s.h>' % i.replace('/', '-') |
d7ab1bab | 57 | for j in pmodes: |
a7f2e389 | 58 | print '#include <catacomb/%s-%s.h>' % (i.replace('/', '-'), j) |
d7ab1bab | 59 | for i in streamciphers: |
a7f2e389 | 60 | print '#include <catacomb/%s.h>' % i.replace('/', '-') |
d7ab1bab | 61 | |
62 | for i in hashes: | |
a7f2e389 | 63 | print '#include <catacomb/%s.h>' % i.replace('/', '-') |
d7ab1bab | 64 | for j in hmodes: |
a7f2e389 | 65 | print '#include <catacomb/%s-%s.h>' % (i.replace('/', '-'), j) |
d7ab1bab | 66 | |
67 | ||
03ed9abb | 68 | print '#define PRPS(_) \\' |
d7ab1bab | 69 | for i in prps: |
eb0f76ed MW |
70 | print '\t_(%s, %s) \\' % (i.upper(), i) |
71 | print '\t/* end */' | |
03ed9abb MW |
72 | |
73 | ||
74 | print '#define RNGS(_) \\' | |
75 | for i in (cross(prps, ['ofb', 'counter'])): | |
a7f2e389 MW |
76 | print ('\t_("%(prim)s-%(mode)s", %(primid)s_keysz, ' + |
77 | '%(primid)s_%(mode)srand, RNG_PLAIN, 0) \\') % \ | |
78 | {'prim': i[0], 'mode': i[1], | |
79 | 'primid': i[0].replace('-', '_').replace('/', '_')} | |
03ed9abb | 80 | for i in (cross(hashes, 'mgf')): |
a7f2e389 MW |
81 | print ('\t_("%(prim)s-%(mode)s", %(primid)s_%(mode)skeysz, ' + |
82 | '%(primid)s_%(mode)srand, RNG_PLAIN, 0) \\') % \ | |
83 | {'prim': i[0], 'mode': i[1], | |
84 | 'primid': i[0].replace('-', '_').replace('/', '_')} | |
3f4f64b8 | 85 | print '\t_("rc4", rc4_keysz, rc4_rand, 0, 0) \\' |
34825452 | 86 | print '\t_("seal", seal_keysz, seal_rand, RNG_SEAL, 0) \\' |
3f4f64b8 MW |
87 | for i in latindances: |
88 | for r in ['salsa20', 'xsalsa20', 'chacha', 'xchacha']: | |
89 | if i.startswith(r): | |
90 | root = r | |
91 | break | |
92 | else: | |
93 | raise ValueError, 'failed to find root name for %s' % i | |
f9041075 | 94 | if i.endswith('-ietf'): root += '_ietf' |
3f4f64b8 | 95 | print ('\t_("%(name)s", %(root)s_keysz, %(id)s_rand, ' + |
34825452 | 96 | 'RNG_LATIN, %(ROOT)s_NONCESZ) \\') % \ |
3e80d327 | 97 | {'name': i, 'id': i.replace('/', '').replace('-', '_'), |
3f4f64b8 | 98 | 'root': root, 'ROOT': root.upper()} |
6bd22b53 MW |
99 | for i in [128, 256]: |
100 | print ('\t_("shake%(w)d", shake%(w)d_keysz, cshake%(w)d_rand, ' + | |
101 | 'RNG_SHAKE, 0) \\') % \ | |
102 | {'w': i} | |
103 | print ('\t_("kmac%(w)d", kmac%(w)d_keysz, kmac%(w)d_rand, ' + | |
104 | 'RNG_KMAC, 0) \\') % \ | |
105 | {'w': i} | |
eb0f76ed | 106 | print '\t/* end */' |
d7ab1bab | 107 |