From 560c9030c13c7e10c77dafbbec1f96db178fca6f Mon Sep 17 00:00:00 2001 From: arnaucube Date: Sun, 10 Jan 2021 14:32:45 +0100 Subject: [PATCH] Add secp256k1 wrappers --- blindsecp256k1.go | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 blindsecp256k1.go diff --git a/blindsecp256k1.go b/blindsecp256k1.go new file mode 100644 index 0000000..66d8229 --- /dev/null +++ b/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) +}