-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecc.py
More file actions
43 lines (29 loc) · 939 Bytes
/
ecc.py
File metadata and controls
43 lines (29 loc) · 939 Bytes
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
import time
from Crypto.PublicKey import ECC
from Crypto.Random import random
def hash_to_curve(num, key):
return key._curve.G * num
def blind(_in, pubkey, random_number):
return _in + pubkey._curve.G * random_number # _in + r * G
def unblind(_in, pubkey, random_number):
return _in + (-pubkey.pointQ * random_number) # _in - r * Q
def sign(_in, prikey):
return _in * prikey.d # d * _in
private_key = ECC.generate(curve='p256')
public_key = private_key.public_key()
# 点击监测
# begin = time.time()
# for i in range(1000):
pa = hash_to_curve(38654201, public_key)
epa = sign(pa, private_key)
# end = time.time()
# nanos = (end - begin) * 1e9 / 1000
# print('time: ' + str(nanos) + 'ns')
# 2. 客户加盲
rand = random.randint(0, 0xffffffff)
bpa = blind(pa, public_key, rand)
# 3. 字节加密
ebpa = sign(bpa, private_key)
# 4. 客户解盲
bebpa = unblind(ebpa, public_key, rand)
assert bebpa == epa