chiark / gitweb /
Merge branch 'fixes'
[catacomb] / mkpgroups
1 #! /usr/bin/python
2
3 import catacomb as C
4 import mLib as M
5 from sys import stdin
6
7 kf = C.KeyFile('pgroups.kr', C.KOPEN_WRITE)
8
9 for line in stdin:
10   line = line.strip()
11   if line == '' or (line.startswith('#') and not line.startswith('#:')):
12     continue
13   F = line.split()
14   if F[0] == 'group':
15     name = F[1]
16     if not name.startswith('catacomb'):
17       continue
18     def snarf(what):
19       F = stdin.next().split()
20       assert F[0] == what
21       return F[1]
22     p = C.MP(snarf('p'))
23     q = C.MP(snarf('q'))
24     g = C.MP(snarf('g'))
25     ff = []
26     while True:
27       F = stdin.next().split()
28       if not F or F[0] != '#:factor':
29         break
30       ff.append(C.MP(F[1]))
31     seed = C.rmd160().hash(name).done()
32     k = kf.newkey(C.ReadBuffer(seed).getu32(), 'dh-param')
33     k.tag = name
34     k.data = C.KeyDataStructured({
35       'p': C.KeyDataMP(p, 'shared'),
36       'q': C.KeyDataMP(q, 'shared'),
37       'g': C.KeyDataMP(g, 'shared')
38     })
39     k.attr['factor'] = ', '.join([f.tostring() for f in ff])
40     k.attr['genseed'] = M.base64_encode(seed)
41     k.attr['seedalg'] = 'rmd160-mgf'
42 kf.save()