github.com/smalaichami/go-bowhead@v0.0.0-20180311002552-16302db95eaa/crypto/bn256/bn256_amd64.go (about) 1 // Copyright 2018 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 // +build amd64,!appengine,!gccgo 18 19 // Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve. 20 package bn256 21 22 import ( 23 "math/big" 24 25 "github.com/smalaichami/go-bowhead/crypto/bn256/cloudflare" 26 ) 27 28 // G1 is an abstract cyclic group. The zero value is suitable for use as the 29 // output of an operation, but cannot be used as an input. 30 type G1 struct { 31 bn256.G1 32 } 33 34 // Add sets e to a+b and then returns e. 35 func (e *G1) Add(a, b *G1) *G1 { 36 e.G1.Add(&a.G1, &b.G1) 37 return e 38 } 39 40 // ScalarMult sets e to a*k and then returns e. 41 func (e *G1) ScalarMult(a *G1, k *big.Int) *G1 { 42 e.G1.ScalarMult(&a.G1, k) 43 return e 44 } 45 46 // G2 is an abstract cyclic group. The zero value is suitable for use as the 47 // output of an operation, but cannot be used as an input. 48 type G2 struct { 49 bn256.G2 50 } 51 52 // PairingCheck calculates the Optimal Ate pairing for a set of points. 53 func PairingCheck(a []*G1, b []*G2) bool { 54 as := make([]*bn256.G1, len(a)) 55 for i, p := range a { 56 as[i] = &p.G1 57 } 58 bs := make([]*bn256.G2, len(b)) 59 for i, p := range b { 60 bs[i] = &p.G2 61 } 62 return bn256.PairingCheck(as, bs) 63 }