-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.py
57 lines (45 loc) · 1.93 KB
/
test.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
from darkpoly import *
import os
from gmpy2 import *
import unittest
class MyTestCase(unittest.TestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.logd = 10
rand = os.urandom(120)
self.state = random_state(int.from_bytes(rand, 'big'))
self.p = next_prime(mpz_rrandomb(self.state, 120))
self.q = mpz(2) ** (self.logd * 2 * 120)
def test_verify(self):
coefficients = [mpz_random(self.state, self.p) for i in range(2 ** self.logd)]
poly = Polynomial(self.q, coefficients)
com = poly_commit(self.q, poly=poly)
x = mpz_random(self.state, self.p)
y, proof = eval_proof(self.q, poly, self.p, x, com)
valid = verify_eval(self.q, com, proof, len(poly), self.p, x, y)
self.assertEqual(valid, True)
self.assertEqual(y, poly.eval_at(x, self.p))
def test_param_commit(self):
coefficients = [mpz_random(self.state, self.p) for i in range(2 ** self.logd)]
poly = Polynomial(self.q, coefficients)
com = poly_commit(self.q, poly=poly)
params = create_params(self.q, 2 ** self.logd)
commit2 = poly_commit(self.q, poly=poly, params=params)
self.assertEqual(com, commit2)
def test_small_params(self):
coefficients = [mpz_random(self.state, self.p) for i in range(2 ** self.logd)]
poly = Polynomial(self.q, coefficients)
com = poly_commit(self.q, poly=poly)
params = create_params(self.q, 2 ** (self.logd + 1))
commit2 = poly_commit(self.q, poly=poly, params=params)
self.assertEqual(com, commit2)
def test_poe(self):
C = RSAGroup.generator() ** 3245
Cprime = C ** (self.q ** 23)
pi = poe_proof(0, C, self.q, 23)
C_result = compute_poe(0, C, pi, self.q, 23)
print(Cprime)
print(C_result)
self.assertEqual(Cprime, C_result)
if __name__ == '__main__':
unittest.main()