Skip to content

Commit 91f1d44

Browse files
Updated crypto natives
1 parent dea4768 commit 91f1d44

File tree

4 files changed

+63
-8
lines changed

4 files changed

+63
-8
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//go:build js
2+
// +build js
3+
4+
package bcache
5+
6+
import "unsafe"
7+
8+
// Cache relies on GC to periodically clear the cache.
9+
// Since GopherJS doesn't have the same GC hooks, it currently can not
10+
// register this cache with the GC.
11+
// Without this cache Boring crypto, in particular public and private
12+
// RSA and ECDSA keys, will be slower because the cache will always miss.
13+
type Cache struct{}
14+
15+
func (c *Cache) Register() {}
16+
func (c *Cache) Clear() {}
17+
func (c *Cache) Get(k unsafe.Pointer) unsafe.Pointer { return nil }
18+
func (c *Cache) Put(k, v unsafe.Pointer) {}
19+
20+
//gopherjs:purge
21+
func (c *Cache) table() *[cacheSize]unsafe.Pointer
22+
23+
//gopherjs:purge
24+
type cacheEntry struct{}
25+
26+
//gopherjs:purge
27+
func registerCache(unsafe.Pointer)
28+
29+
//gopherjs:purge
30+
const cacheSize = 1021
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//go:build js
2+
// +build js
3+
4+
package bcache
5+
6+
import "testing"
7+
8+
func TestCache(t *testing.T) {
9+
t.Skip(`This test uses runtime.GC(), which GopherJS doesn't support`)
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//go:build js
2+
// +build js
3+
4+
package sig
5+
6+
// Setting to no-op
7+
func BoringCrypto() {}
8+
9+
// Setting to no-op
10+
func FIPSOnly() {}
11+
12+
// Setting to no-op
13+
func StandardCrypto() {}

compiler/natives/src/crypto/internal/nistec/nistec_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
package nistec_test
55

66
import (
7-
"crypto/elliptic"
87
"testing"
8+
9+
"crypto/elliptic"
10+
"crypto/internal/nistec"
911
)
1012

1113
func TestAllocations(t *testing.T) {
@@ -31,7 +33,7 @@ func TestEquivalents(t *testing.T) {
3133
}
3234

3335
//gopherjs:override-signature
34-
func testEquivalents(t *testing.T, newPoint, newGenerator func() WrappedPoint, c elliptic.Curve) {}
36+
func testEquivalents(t *testing.T, newPoint, newGenerator func() nistec.WrappedPoint, c elliptic.Curve)
3537

3638
func TestScalarMult(t *testing.T) {
3739
t.Run("P224", func(t *testing.T) {
@@ -49,14 +51,14 @@ func TestScalarMult(t *testing.T) {
4951
}
5052

5153
//gopherjs:override-signature
52-
func testScalarMult(t *testing.T, newPoint, newGenerator func() WrappedPoint, c elliptic.Curve)
54+
func testScalarMult(t *testing.T, newPoint, newGenerator func() nistec.WrappedPoint, c elliptic.Curve)
5355

5456
func BenchmarkScalarMult(b *testing.B) {
5557
b.Run("P224", func(b *testing.B) {
5658
benchmarkScalarMult(b, nistec.NewP224WrappedGenerator(), 28)
5759
})
5860
b.Run("P256", func(b *testing.B) {
59-
benchmarkScalarMult(b, nistec.NewP256GWrappedenerator(), 32)
61+
benchmarkScalarMult(b, nistec.NewP256WrappedGenerator(), 32)
6062
})
6163
b.Run("P384", func(b *testing.B) {
6264
benchmarkScalarMult(b, nistec.NewP384WrappedGenerator(), 48)
@@ -67,11 +69,11 @@ func BenchmarkScalarMult(b *testing.B) {
6769
}
6870

6971
//gopherjs:override-signature
70-
func benchmarkScalarMult(b *testing.B, p WrappedPoint, scalarSize int)
72+
func benchmarkScalarMult(b *testing.B, p nistec.WrappedPoint, scalarSize int)
7173

7274
func BenchmarkScalarBaseMult(b *testing.B) {
7375
b.Run("P224", func(b *testing.B) {
74-
benchmarkScalarBaseMult(b, nistec.NewP22Wrapped4Generator(), 28)
76+
benchmarkScalarBaseMult(b, nistec.NewP224WrappedGenerator(), 28)
7577
})
7678
b.Run("P256", func(b *testing.B) {
7779
benchmarkScalarBaseMult(b, nistec.NewP256WrappedGenerator(), 32)
@@ -80,9 +82,9 @@ func BenchmarkScalarBaseMult(b *testing.B) {
8082
benchmarkScalarBaseMult(b, nistec.NewP384WrappedGenerator(), 48)
8183
})
8284
b.Run("P521", func(b *testing.B) {
83-
benchmarkScalarBaseMult(b, nistec.NewP521GWrappedenerator(), 66)
85+
benchmarkScalarBaseMult(b, nistec.NewP521WrappedGenerator(), 66)
8486
})
8587
}
8688

8789
//gopherjs:override-signature
88-
func benchmarkScalarBaseMult(b *testing.B, p WrappedPoint, scalarSize int)
90+
func benchmarkScalarBaseMult(b *testing.B, p nistec.WrappedPoint, scalarSize int)

0 commit comments

Comments
 (0)