ec-field-test.c: Make the field-element type use internal format.
[secnet] / mdw-test / mk-sshv1-rsapriv
CommitLineData
2ad8dd37
MW
1#! /usr/bin/python
2
3from sys import argv
4import os as OS
5import catacomb as C
6
7MAGIC = 'SSH PRIVATE KEY FILE FORMAT 1.1\n\0'
8keyring, tag, outfile = argv[1:]
9kf = C.KeyFile(keyring)
10k = kf[tag]
11kd = k.data
12
13n, e = [kd[label].mp for label in ['n', 'e']]
14priv = kd['private']
15d, p, q, dp, dq, q_inv = \
16 [priv[label].mp for label in ['d', 'p', 'q', 'd-mod-p', 'd-mod-q', 'q-inv']]
17
18buf = C.WriteBuffer()
19buf.put(MAGIC)
20buf.putu8(0) # symmetric cipher type
21buf.putu32(0) # `reserved data'
22buf.putu32(n.nbits) # `not sure what this is'
23buf.putu16(n.nbits).put(n.storeb())
24buf.putu16(e.nbits).put(e.storeb())
25buf.putblk32(k.fulltag) # comment
26buf.putu16(1234).putu16(1234)# `next two pairs of characters are identical'
27buf.putu16(d.nbits).put(d.storeb())
28buf.putu16(q_inv.nbits).put(q_inv.storeb())
29buf.putu16(q.nbits).put(q.storeb())
30buf.putu16(p.nbits).put(p.storeb())
31outtmp = outfile + '.new'
32with open(outtmp, 'wb') as f: f.write(buf)
33OS.rename(outtmp, outfile)