github.com/gopherjs/gopherjs@v1.19.0-beta1.0.20240506212314-27071a8796e4/compiler/natives/src/crypto/internal/nistec/nistec_test.go (about) 1 //go:build js 2 // +build js 3 4 package nistec_test 5 6 import ( 7 "crypto/elliptic" 8 "crypto/internal/nistec" 9 "testing" 10 ) 11 12 func TestAllocations(t *testing.T) { 13 t.Skip("testing.AllocsPerRun not supported in GopherJS") 14 } 15 16 //gopherjs:purge 17 type nistPoint[T any] interface{} 18 19 func TestEquivalents(t *testing.T) { 20 t.Run("P224", func(t *testing.T) { 21 testEquivalents(t, nistec.NewP224WrappedPoint, nistec.NewP224WrappedGenerator, elliptic.P224()) 22 }) 23 t.Run("P256", func(t *testing.T) { 24 testEquivalents(t, nistec.NewP256WrappedPoint, nistec.NewP256WrappedGenerator, elliptic.P256()) 25 }) 26 t.Run("P384", func(t *testing.T) { 27 testEquivalents(t, nistec.NewP384WrappedPoint, nistec.NewP384WrappedGenerator, elliptic.P384()) 28 }) 29 t.Run("P521", func(t *testing.T) { 30 testEquivalents(t, nistec.NewP521WrappedPoint, nistec.NewP521WrappedGenerator, elliptic.P521()) 31 }) 32 } 33 34 //gopherjs:override-signature 35 func testEquivalents(t *testing.T, newPoint, newGenerator func() nistec.WrappedPoint, c elliptic.Curve) 36 37 func TestScalarMult(t *testing.T) { 38 t.Run("P224", func(t *testing.T) { 39 testScalarMult(t, nistec.NewP224WrappedPoint, nistec.NewP224WrappedGenerator, elliptic.P224()) 40 }) 41 t.Run("P256", func(t *testing.T) { 42 testScalarMult(t, nistec.NewP256WrappedPoint, nistec.NewP256WrappedGenerator, elliptic.P256()) 43 }) 44 t.Run("P384", func(t *testing.T) { 45 testScalarMult(t, nistec.NewP384WrappedPoint, nistec.NewP384WrappedGenerator, elliptic.P384()) 46 }) 47 t.Run("P521", func(t *testing.T) { 48 testScalarMult(t, nistec.NewP521WrappedPoint, nistec.NewP521WrappedGenerator, elliptic.P521()) 49 }) 50 } 51 52 //gopherjs:override-signature 53 func testScalarMult(t *testing.T, newPoint, newGenerator func() nistec.WrappedPoint, c elliptic.Curve) 54 55 func BenchmarkScalarMult(b *testing.B) { 56 b.Run("P224", func(b *testing.B) { 57 benchmarkScalarMult(b, nistec.NewP224WrappedGenerator(), 28) 58 }) 59 b.Run("P256", func(b *testing.B) { 60 benchmarkScalarMult(b, nistec.NewP256WrappedGenerator(), 32) 61 }) 62 b.Run("P384", func(b *testing.B) { 63 benchmarkScalarMult(b, nistec.NewP384WrappedGenerator(), 48) 64 }) 65 b.Run("P521", func(b *testing.B) { 66 benchmarkScalarMult(b, nistec.NewP521WrappedGenerator(), 66) 67 }) 68 } 69 70 //gopherjs:override-signature 71 func benchmarkScalarMult(b *testing.B, p nistec.WrappedPoint, scalarSize int) 72 73 func BenchmarkScalarBaseMult(b *testing.B) { 74 b.Run("P224", func(b *testing.B) { 75 benchmarkScalarBaseMult(b, nistec.NewP224WrappedGenerator(), 28) 76 }) 77 b.Run("P256", func(b *testing.B) { 78 benchmarkScalarBaseMult(b, nistec.NewP256WrappedGenerator(), 32) 79 }) 80 b.Run("P384", func(b *testing.B) { 81 benchmarkScalarBaseMult(b, nistec.NewP384WrappedGenerator(), 48) 82 }) 83 b.Run("P521", func(b *testing.B) { 84 benchmarkScalarBaseMult(b, nistec.NewP521WrappedGenerator(), 66) 85 }) 86 } 87 88 //gopherjs:override-signature 89 func benchmarkScalarBaseMult(b *testing.B, p nistec.WrappedPoint, scalarSize int)