forked from initc3/HoneyBadgerBFT-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_trusted_key_gen.py
79 lines (58 loc) · 2.38 KB
/
run_trusted_key_gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from honeybadgerbft.crypto.threshsig import boldyreva
from honeybadgerbft.crypto.threshenc import tpke
from honeybadgerbft.crypto.ecdsa import ecdsa
import pickle
import os
def trusted_key_gen(N=4, f=1, seed=None):
# Generate threshold enc keys
ePK, eSKs = tpke.dealer(N, f+1)
# Generate threshold sig keys for coin (thld f+1)
sPK, sSKs = boldyreva.dealer(N, f+1, seed=seed)
# Generate threshold sig keys for cbc (thld n-f)
sPK1, sSK1s = boldyreva.dealer(N, N-f, seed=seed)
# Generate ECDSA sig keys
sPK2s, sSK2s = ecdsa.pki(N)
# Save all keys to files
if 'keys' not in os.listdir(os.getcwd()):
os.mkdir(os.getcwd() + '/keys')
# public key of (f+1, n) thld sig
with open(os.getcwd() + '/keys/' + 'sPK.key', 'wb') as fp:
pickle.dump(sPK, fp)
# public key of (n-f, n) thld sig
with open(os.getcwd() + '/keys/' + 'sPK1.key', 'wb') as fp:
pickle.dump(sPK1, fp)
# public key of (f+1, n) thld enc
with open(os.getcwd() + '/keys/' + 'ePK.key', 'wb') as fp:
pickle.dump(ePK, fp)
# public keys of ECDSA
for i in range(N):
with open(os.getcwd() + '/keys/' + 'sPK2-' + str(i) + '.key', 'wb') as fp:
pickle.dump(sPK2s[i].format(), fp)
# private key of (f+1, n) thld sig
for i in range(N):
with open(os.getcwd() + '/keys/' + 'sSK-' + str(i) + '.key', 'wb') as fp:
pickle.dump(sSKs[i], fp)
# private key of (n-f, n) thld sig
for i in range(N):
with open(os.getcwd() + '/keys/' + 'sSK1-' + str(i) + '.key', 'wb') as fp:
pickle.dump(sSK1s[i], fp)
# private key of (f+1, n) thld enc
for i in range(N):
with open(os.getcwd() + '/keys/' + 'eSK-' + str(i) + '.key', 'wb') as fp:
pickle.dump(eSKs[i], fp)
# private keys of ECDSA
for i in range(N):
with open(os.getcwd() + '/keys/' + 'sSK2-' + str(i) + '.key', 'wb') as fp:
pickle.dump(sSK2s[i].secret, fp)
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--N', metavar='N', required=True,
help='number of parties', type=int)
parser.add_argument('--f', metavar='f', required=True,
help='number of faulties', type=int)
args = parser.parse_args()
N = args.N
f = args.f
assert N >= 3 * f + 1
trusted_key_gen(N, f)