Skip to content

Commit

Permalink
Add p256 test
Browse files Browse the repository at this point in the history
  • Loading branch information
K1li4nL committed Sep 9, 2024
1 parent 7a0e165 commit 9cabb72
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions group/p256/group_test.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand All @@ -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) }
Expand Down

0 comments on commit 9cabb72

Please sign in to comment.