@@ -21,6 +21,7 @@ import (
21
21
"github.com/getamis/alice/crypto/birkhoffinterpolation"
22
22
"github.com/getamis/alice/crypto/ecpointgrouplaw"
23
23
"github.com/getamis/alice/crypto/elliptic"
24
+ "github.com/getamis/alice/crypto/polynomial"
24
25
"github.com/getamis/alice/crypto/tss"
25
26
"github.com/getamis/alice/crypto/utils"
26
27
"github.com/getamis/alice/internal/message/types"
@@ -38,83 +39,120 @@ func TestSigner(t *testing.T) {
38
39
39
40
var _ = Describe ("Signer" , func () {
40
41
var (
41
- curve = elliptic .Ed25519 ()
42
- )
42
+ RumTime = 20
43
+ curve = elliptic .Ed25519 ()
44
+ poly , _ = polynomial .RandomPolynomial (curve .Params ().N , 2 )
45
+ x1 , _ = utils .RandomPositiveInt (curve .Params ().N )
46
+ x2 , _ = utils .RandomPositiveInt (curve .Params ().N )
47
+ x3 , _ = utils .RandomPositiveInt (curve .Params ().N )
48
+ share1 = poly .Evaluate (x1 )
49
+ share2 = poly .Evaluate (x2 )
50
+ share3 = poly .Evaluate (x3 )
51
+ secrertRandomKey = poly .Evaluate (big0 )
43
52
44
- DescribeTable ("It should be OK" , func (ss [][]* big.Int , privateKey * big.Int ) {
45
- expPublic := ecpointgrouplaw .ScalarBaseMult (curve , privateKey )
46
- threshold := len (ss )
47
- message := []byte ("8077818" )
48
- signers , listeners := newSigners (curve , expPublic , ss , message )
49
- doneChs := make ([]chan struct {}, threshold )
50
- i := 0
51
- for _ , l := range listeners {
52
- doneChs [i ] = make (chan struct {})
53
- doneCh := doneChs [i ]
54
- l .On ("OnStateChanged" , types .StateInit , types .StateDone ).Run (func (args mock.Arguments ) {
55
- close (doneCh )
56
- }).Once ()
57
- i ++
58
- }
53
+ setx1 , _ = new (big.Int ).SetString ("2254765913981550676205803762478430869696580688700958727495894224115312987764" , 10 )
54
+ setx2 , _ = new (big.Int ).SetString ("2117636074604900758115075527580492494720639688970891834155177238392086845382" , 10 )
55
+ setx3 , _ = new (big.Int ).SetString ("6414582964050248729324272790247195316284712038021768098875147472012178712076" , 10 )
56
+ setShare1 , _ = new (big.Int ).SetString ("3675788498585450082991846428007326057826754636663877385528274415846839676857" , 10 )
57
+ setShare2 , _ = new (big.Int ).SetString ("1522795425006476177538987458185716386773973361216994141828318603466392185301" , 10 )
58
+ setShare3 , _ = new (big.Int ).SetString ("4575846830523611786637644129807785488887694553004765055615792711279484061401" , 10 )
59
+ xcoord1 , _ = new (big.Int ).SetString ("13303072567237052328013834338380099174471808636153533034015575804719580433195" , 10 )
60
+ ycoord1 , _ = new (big.Int ).SetString ("16964052623936448625187294284159857344364737590067812676140890490183700057118" , 10 )
61
+ pubKey , _ = ecpointgrouplaw .NewECPoint (curve , xcoord1 , ycoord1 )
62
+ )
59
63
60
- for _ , s := range signers {
61
- s .Start ()
62
- }
64
+ DescribeTable ("It should be OK" , func (ss [][]* big.Int , privateKey * big.Int , pubKey * ecpointgrouplaw.ECPoint ) {
65
+ for i := 0 ; i < RumTime ; i ++ {
66
+ expPublic := pubKey
67
+ if privateKey != nil {
68
+ expPublic = ecpointgrouplaw .ScalarBaseMult (curve , privateKey )
69
+ }
70
+ threshold := len (ss )
71
+ message := []byte ("8077818" )
72
+ signers , listeners := newSigners (curve , expPublic , ss , message )
73
+ doneChs := make ([]chan struct {}, threshold )
74
+ i := 0
75
+ for _ , l := range listeners {
76
+ doneChs [i ] = make (chan struct {})
77
+ doneCh := doneChs [i ]
78
+ l .On ("OnStateChanged" , types .StateInit , types .StateDone ).Run (func (args mock.Arguments ) {
79
+ close (doneCh )
80
+ }).Once ()
81
+ i ++
82
+ }
63
83
64
- for i := 0 ; i < threshold ; i ++ {
65
- <- doneChs [ i ]
66
- }
84
+ for _ , s := range signers {
85
+ s . Start ()
86
+ }
67
87
68
- // Build public key
69
- var R * ecpointgrouplaw.ECPoint
70
- var s * big.Int
71
- for _ , signer := range signers {
72
- signer .Stop ()
73
- result , err := signer .GetResult ()
74
- Expect (err ).Should (BeNil ())
75
- // All R and S should be the same
76
- if R != nil {
77
- Expect (R .Equal (result .R )).Should (BeTrue ())
78
- Expect (s ).Should (Equal (result .S ))
79
- } else {
80
- R = result .R
81
- s = result .S
88
+ for i := 0 ; i < threshold ; i ++ {
89
+ <- doneChs [i ]
82
90
}
83
- }
84
- edwardPubKey := edwards .NewPublicKey (edwards .Edwards (), expPublic .GetX (), expPublic .GetY ())
85
- test1 := ecpointEncoding (R )
86
- test2 := * test1
87
- r := new (big.Int ).SetBytes (utils .ReverseByte (test2 [:]))
88
91
89
- Expect (edwards .Verify (edwardPubKey , message , r , s )).Should (BeTrue ())
90
- for _ , l := range listeners {
91
- l .AssertExpectations (GinkgoT ())
92
+ // Build public key
93
+ var R * ecpointgrouplaw.ECPoint
94
+ var s * big.Int
95
+ for _ , signer := range signers {
96
+ signer .Stop ()
97
+ result , err := signer .GetResult ()
98
+ Expect (err ).Should (BeNil ())
99
+ // All R and S should be the same
100
+ if R != nil {
101
+ Expect (R .Equal (result .R )).Should (BeTrue ())
102
+ Expect (s ).Should (Equal (result .S ))
103
+ } else {
104
+ R = result .R
105
+ s = result .S
106
+ }
107
+ }
108
+ edwardPubKey := edwards .NewPublicKey (edwards .Edwards (), expPublic .GetX (), expPublic .GetY ())
109
+ test1 := ecpointEncoding (R )
110
+ test2 := * test1
111
+ r := new (big.Int ).SetBytes (utils .ReverseByte (test2 [:]))
112
+ verifyResult := edwards .Verify (edwardPubKey , message , r , s )
113
+ Expect (verifyResult ).Should (BeTrue ())
114
+ if ! verifyResult {
115
+ break
116
+ }
117
+ for _ , l := range listeners {
118
+ l .AssertExpectations (GinkgoT ())
119
+ }
92
120
}
93
121
},
94
122
Entry ("(x-cooord, share, rank):f(x) = 2x+100" , [][]* big.Int {
95
123
{big .NewInt (1 ), big .NewInt (102 ), big .NewInt (0 )},
96
124
{big .NewInt (2 ), big .NewInt (104 ), big .NewInt (0 )},
97
125
{big .NewInt (8 ), big .NewInt (116 ), big .NewInt (0 )},
98
- }, big .NewInt (100 )),
126
+ }, big .NewInt (100 ), nil ),
99
127
Entry ("(x-cooord, share, rank):f(x) = 2x+100" , [][]* big.Int {
100
128
{big .NewInt (1 ), big .NewInt (102 ), big .NewInt (0 )},
101
129
{big .NewInt (2 ), big .NewInt (104 ), big .NewInt (0 )},
102
- }, big .NewInt (100 )),
130
+ }, big .NewInt (100 ), nil ),
103
131
Entry ("(x-cooord, share, rank):f(x) = x^2+5*x+1109" , [][]* big.Int {
104
132
{big .NewInt (1 ), big .NewInt (1115 ), big .NewInt (0 )},
105
133
{big .NewInt (2 ), big .NewInt (1123 ), big .NewInt (0 )},
106
134
{big .NewInt (50 ), big .NewInt (3859 ), big .NewInt (0 )},
107
- }, big .NewInt (1109 )),
135
+ }, big .NewInt (1109 ), nil ),
108
136
Entry ("(x-cooord, share, rank):f(x) = x^2+3*x+5555" , [][]* big.Int {
109
137
{big .NewInt (1 ), big .NewInt (5559 ), big .NewInt (0 )},
110
138
{big .NewInt (2 ), big .NewInt (5565 ), big .NewInt (0 )},
111
139
{big .NewInt (50 ), big .NewInt (103 ), big .NewInt (1 )},
112
- }, big .NewInt (5555 )),
140
+ }, big .NewInt (5555 ), nil ),
113
141
Entry ("(x-cooord, share, rank):f(x) = 2*x^2+3*x+1111" , [][]* big.Int {
114
142
{big .NewInt (1 ), big .NewInt (1116 ), big .NewInt (0 )},
115
143
{big .NewInt (2 ), big .NewInt (4 ), big .NewInt (2 )},
116
144
{big .NewInt (50 ), big .NewInt (203 ), big .NewInt (1 )},
117
- }, big .NewInt (1111 )),
145
+ }, big .NewInt (1111 ), nil ),
146
+ Entry ("(x-cooord, share, rank):f(x) = random" , [][]* big.Int {
147
+ {x1 , share1 , big .NewInt (0 )},
148
+ {x2 , share2 , big .NewInt (0 )},
149
+ {x3 , share3 , big .NewInt (0 )},
150
+ }, secrertRandomKey , nil ),
151
+ Entry ("(x-cooord, share, rank):" , [][]* big.Int {
152
+ {setx1 , setShare1 , big .NewInt (0 )},
153
+ {setx2 , setShare2 , big .NewInt (0 )},
154
+ {setx3 , setShare3 , big .NewInt (0 )},
155
+ }, nil , pubKey ),
118
156
)
119
157
})
120
158
0 commit comments