LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Package bn256 implements a particular bilinear group at the 128-bit security
level. | 5 // Package bn256 implements a particular bilinear group at the 128-bit security
level. |
6 // | 6 // |
7 // Bilinear groups are the basis of many of the new cryptographic protocols | 7 // Bilinear groups are the basis of many of the new cryptographic protocols |
8 // that have been proposed over the past decade. They consist of a triplet of | 8 // that have been proposed over the past decade. They consist of a triplet of |
9 // groups (G₁, G₂ and GT) such that there exists a function e(g₁ˣ,g₂ʸ)=gTˣʸ | 9 // groups (G₁, G₂ and GT) such that there exists a function e(g₁ˣ,g₂ʸ)=gTˣʸ |
10 // (where gₓ is a generator of the respective group). That function is called | 10 // (where gₓ is a generator of the respective group). That function is called |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 e.p = newCurvePoint(nil) | 122 e.p = newCurvePoint(nil) |
123 } | 123 } |
124 | 124 |
125 e.p.x.SetBytes(m[0*numBytes : 1*numBytes]) | 125 e.p.x.SetBytes(m[0*numBytes : 1*numBytes]) |
126 e.p.y.SetBytes(m[1*numBytes : 2*numBytes]) | 126 e.p.y.SetBytes(m[1*numBytes : 2*numBytes]) |
127 | 127 |
128 if e.p.x.Sign() == 0 && e.p.y.Sign() == 0 { | 128 if e.p.x.Sign() == 0 && e.p.y.Sign() == 0 { |
129 // This is the point at infinity. | 129 // This is the point at infinity. |
130 e.p.y.SetInt64(1) | 130 e.p.y.SetInt64(1) |
131 e.p.z.SetInt64(0) | 131 e.p.z.SetInt64(0) |
| 132 e.p.t.SetInt64(0) |
132 } else { | 133 } else { |
133 e.p.z.SetInt64(1) | 134 e.p.z.SetInt64(1) |
| 135 e.p.t.SetInt64(1) |
| 136 |
134 if !e.p.IsOnCurve() { | 137 if !e.p.IsOnCurve() { |
135 return nil, false | 138 return nil, false |
136 } | 139 } |
137 } | 140 } |
138 | 141 |
139 return e, true | 142 return e, true |
140 } | 143 } |
141 | 144 |
142 // G2 is an abstract cyclic group. The zero value is suitable for use as the | 145 // G2 is an abstract cyclic group. The zero value is suitable for use as the |
143 // output of an operation, but cannot be used as an input. | 146 // output of an operation, but cannot be used as an input. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 e.p.y.x.SetBytes(m[2*numBytes : 3*numBytes]) | 239 e.p.y.x.SetBytes(m[2*numBytes : 3*numBytes]) |
237 e.p.y.y.SetBytes(m[3*numBytes : 4*numBytes]) | 240 e.p.y.y.SetBytes(m[3*numBytes : 4*numBytes]) |
238 | 241 |
239 if e.p.x.x.Sign() == 0 && | 242 if e.p.x.x.Sign() == 0 && |
240 e.p.x.y.Sign() == 0 && | 243 e.p.x.y.Sign() == 0 && |
241 e.p.y.x.Sign() == 0 && | 244 e.p.y.x.Sign() == 0 && |
242 e.p.y.y.Sign() == 0 { | 245 e.p.y.y.Sign() == 0 { |
243 // This is the point at infinity. | 246 // This is the point at infinity. |
244 e.p.y.SetOne() | 247 e.p.y.SetOne() |
245 e.p.z.SetZero() | 248 e.p.z.SetZero() |
| 249 e.p.t.SetZero() |
246 } else { | 250 } else { |
247 e.p.z.SetOne() | 251 e.p.z.SetOne() |
| 252 e.p.t.SetOne() |
248 | 253 |
249 if !e.p.IsOnCurve() { | 254 if !e.p.IsOnCurve() { |
250 println("X") | |
251 return nil, false | 255 return nil, false |
252 } | 256 } |
253 } | 257 } |
254 | 258 |
255 return e, true | 259 return e, true |
256 } | 260 } |
257 | 261 |
258 // GT is an abstract cyclic group. The zero value is suitable for use as the | 262 // GT is an abstract cyclic group. The zero value is suitable for use as the |
259 // output of an operation, but cannot be used as an input. | 263 // output of an operation, but cannot be used as an input. |
260 type GT struct { | 264 type GT struct { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 if pool == nil { | 395 if pool == nil { |
392 return | 396 return |
393 } | 397 } |
394 pool.bns = append(pool.bns, bn) | 398 pool.bns = append(pool.bns, bn) |
395 pool.count-- | 399 pool.count-- |
396 } | 400 } |
397 | 401 |
398 func (pool *bnPool) Count() int { | 402 func (pool *bnPool) Count() int { |
399 return pool.count | 403 return pool.count |
400 } | 404 } |
LEFT | RIGHT |