File tree 4 files changed +20
-6
lines changed
4 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,19 @@ func TestTripartiteDiffieHellman(t *testing.T) {
92
92
}
93
93
}
94
94
95
+ func TestG2SelfAddition (t * testing.T ) {
96
+ s , _ := rand .Int (rand .Reader , Order )
97
+ p := new (G2 ).ScalarBaseMult (s )
98
+
99
+ if ! p .p .IsOnCurve () {
100
+ t .Fatal ("p isn't on curve" )
101
+ }
102
+ m := p .Add (p , p ).Marshal ()
103
+ if _ , err := p .Unmarshal (m ); err != nil {
104
+ t .Fatalf ("p.Add(p, p) ∉ G₂: %v" , err )
105
+ }
106
+ }
107
+
95
108
func BenchmarkG1 (b * testing.B ) {
96
109
x , _ := rand .Int (rand .Reader , Order )
97
110
b .ResetTimer ()
Original file line number Diff line number Diff line change @@ -171,15 +171,15 @@ func (c *curvePoint) Double(a *curvePoint) {
171
171
gfpAdd (t , d , d )
172
172
gfpSub (& c .x , f , t )
173
173
174
+ gfpMul (& c .z , & a .y , & a .z )
175
+ gfpAdd (& c .z , & c .z , & c .z )
176
+
174
177
gfpAdd (t , C , C )
175
178
gfpAdd (t2 , t , t )
176
179
gfpAdd (t , t2 , t2 )
177
180
gfpSub (& c .y , d , & c .x )
178
181
gfpMul (t2 , e , & c .y )
179
182
gfpSub (& c .y , t2 , t )
180
-
181
- gfpMul (t , & a .y , & a .z )
182
- gfpAdd (& c .z , t , t )
183
183
}
184
184
185
185
func (c * curvePoint ) Mul (a * curvePoint , scalar * big.Int ) {
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ func (e *gfP) Marshal(out []byte) {
61
61
func (e * gfP ) Unmarshal (in []byte ) error {
62
62
// Unmarshal the bytes into little endian form
63
63
for w := uint (0 ); w < 4 ; w ++ {
64
+ e [3 - w ] = 0
64
65
for b := uint (0 ); b < 8 ; b ++ {
65
66
e [3 - w ] += uint64 (in [8 * w + b ]) << (56 - 8 * b )
66
67
}
Original file line number Diff line number Diff line change @@ -150,15 +150,15 @@ func (c *twistPoint) Double(a *twistPoint) {
150
150
t .Add (d , d )
151
151
c .x .Sub (f , t )
152
152
153
+ c .z .Mul (& a .y , & a .z )
154
+ c .z .Add (& c .z , & c .z )
155
+
153
156
t .Add (C , C )
154
157
t2 .Add (t , t )
155
158
t .Add (t2 , t2 )
156
159
c .y .Sub (d , & c .x )
157
160
t2 .Mul (e , & c .y )
158
161
c .y .Sub (t2 , t )
159
-
160
- t .Mul (& a .y , & a .z )
161
- c .z .Add (t , t )
162
162
}
163
163
164
164
func (c * twistPoint ) Mul (a * twistPoint , scalar * big.Int ) {
You can’t perform that action at this time.
0 commit comments