From 91b2ed32a51aef0c23d12ac037f6614f6144f9b7 Mon Sep 17 00:00:00 2001 From: Jimmy Song Date: Thu, 25 May 2017 17:04:59 -0400 Subject: [PATCH] more efficient pubkey generation --- internal_test.go | 15 +++++++++++++++ ringct.go | 2 +- ringsignature_test.go | 3 +-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/internal_test.go b/internal_test.go index d33debc..f25c741 100644 --- a/internal_test.go +++ b/internal_test.go @@ -15,3 +15,18 @@ func HexToHash(h string) (result Hash) { copy(result[:], byteSlice) return } + +// RandomPubKey takes a random scalar, interprets it as a point on the curve +// and then multiplies by 8 to make it a point in the Group +func RandomPubKey() (result *Key) { + result = new(Key) + p3 := new(ExtendedGroupElement) + var p1 ProjectiveGroupElement + var p2 CompletedGroupElement + h := RandomScalar() + p1.FromBytes(h) + GeMul8(&p2, &p1) + p2.ToExtended(p3) + p3.ToBytes(result) + return +} diff --git a/ringct.go b/ringct.go index 2f53232..158ebbd 100644 --- a/ringct.go +++ b/ringct.go @@ -133,7 +133,7 @@ func AddKeys2(result, a, b, B *Key) { return } -// subtract two points together +// subtract two points A - B func SubKeys(diff, k1, k2 *Key) { a := k1.ToExtended() b := new(CachedGroupElement) diff --git a/ringsignature_test.go b/ringsignature_test.go index ead55f0..431b20d 100644 --- a/ringsignature_test.go +++ b/ringsignature_test.go @@ -1819,8 +1819,7 @@ func TestCreateSignature(t *testing.T) { privKey, _ := NewKeyPair() mixins := make([]Key, numMixins) for j := 0; j < numMixins; j++ { - _, pk := NewKeyPair() - mixins[j] = *pk + mixins[j] = *RandomPubKey() } keyImage, pubKeys, sig := CreateSignature(&hash, mixins, privKey) if !VerifySignature(&hash, &keyImage, pubKeys, sig) {