arnaucube
arnaucube/go-blindsecp256k1Public Self-hosted repository
Add secp256k1 wrappers
arnaucube root@arnaucube.com
Sun, 10 Jan 2021 14:32:45 +0100
commit

560c9030c13c7e10c77dafbbec1f96db178fca6f

parent

bdead8ba84549444e0b5466335f2447bc10ed1fb

1 files changed, 50 insertions(+), 0 deletions(-)

jump to
A blindsecp256k1.go

@@ -0,0 +1,50 @@

+package blindsecp256k1 + +// WARNING: WIP code + +import ( + "crypto/rand" + "math/big" + + "github.com/ethereum/go-ethereum/crypto/secp256k1" +) + +type Point struct { + X *big.Int + Y *big.Int +} + +var ( + G *Point = &Point{ + X: secp256k1.S256().Gx, + Y: secp256k1.S256().Gy, + } + + N *big.Int = secp256k1.S256().N +) + +func (p *Point) Add(q *Point) *Point { + x, y := secp256k1.S256().Add(p.X, p.Y, q.X, q.Y) + return &Point{ + X: x, + Y: y, + } +} + +func (p *Point) Mul(scalar *big.Int) *Point { + x, y := secp256k1.S256().ScalarMult(p.X, p.Y, scalar.Bytes()) + return &Point{ + X: x, + Y: y, + } +} + +func newRand() *big.Int { + var b [32]byte + _, err := rand.Read(b[:]) + if err != nil { + panic(err) + } + bi := new(big.Int).SetBytes(b[:]) + return new(big.Int).Mod(bi, N) +}