-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkgc.py
63 lines (46 loc) · 1.89 KB
/
kgc.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
from util.ecc import *
from random import randint
from util.hash import gen_hash
class Kgc:
H_0: callable
H_1: callable
q: int
def setup(self):
######### Below is based on the course tutorial 7 implementation #########
# Using the secp256k1 elliptic curve equation: yˆ2 = xˆ3 + 7
# Prime of the finite field
# Necessary parameters for the cryptographic operations
P: int = (
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
)
field = PrimeGaloisField(prime=P)
A: int = 0
B: int = 7
curve256k1 = EllipticCurve(
a=A,
b=B,
field=field
)
I = ECCPoint(x = None, y = None, curve = curve256k1)
# Generator point of the chosen group
G = ECCPoint(
x = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798,
y = 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8,
curve = curve256k1
)
# Order of the group generated by G, such that nG = I
self.q = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
###########################################################################
x_master = randint(0, self.q) # random KGC master key
P_pub = x_master * G # scalar multiplication, public key
# Pick two hash functions
self.H_0 = gen_hash
self.H_1 = gen_hash
# Return common parameters (omega)
return {"G": G, "P_pub": P_pub, "P": P, "H_0": self.H_0, "H_1": self.H_1, "x": x_master}
def gen_partial_key(self, d_i, P_i, x_master):
# Decide a random value and generate partial keys based on drone values
r_i = randint(0, self.q)
R_i = r_i * G
s_i = r_i + x_master * self.H_0(d_i, R_i, P_i) % self.q
return (R_i, s_i)