From 9cabb72eb9e1b8db7f21b1b1fbc5e66471457adb Mon Sep 17 00:00:00 2001 From: lauener Date: Mon, 26 Aug 2024 16:34:15 +0200 Subject: [PATCH] Add p256 test --- group/p256/group_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/group/p256/group_test.go b/group/p256/group_test.go index d379e18fd..4f7075c64 100644 --- a/group/p256/group_test.go +++ b/group/p256/group_test.go @@ -1,8 +1,12 @@ package p256 import ( + "encoding/hex" + "math/big" + "strings" "testing" + "github.com/stretchr/testify/require" "go.dedis.ch/kyber/v4/util/test" ) @@ -24,6 +28,26 @@ func TestSetBytesBE(t *testing.T) { } } +func TestVectors(t *testing.T) { + k := big.NewInt(0) + s := testP256.Scalar() + + BasePoint := testP256.Point().Base().(*curvePoint) + BasePoint.x.SetString(basePointScalarMult[0].X, 16) + BasePoint.y.SetString(basePointScalarMult[0].Y, 16) + + for _, vec := range basePointScalarMult { + // Read from strings + k, ok := k.SetString(vec.K, 10) + require.Equal(t, true, ok) + s.SetBytes(k.Bytes()) + + Q := testP256.Point().Mul(s, BasePoint).(*curvePoint) + require.Equal(t, strings.ToLower(vec.X), hex.EncodeToString(Q.x.Bytes())) + require.Equal(t, strings.ToLower(vec.Y), hex.EncodeToString(Q.y.Bytes())) + } +} + var benchP256 = test.NewGroupBench(testP256) func BenchmarkScalarAdd(b *testing.B) { benchP256.ScalarAdd(b.N) }