Skip to content

Commit 67c21f2

Browse files
committed
primitives/x25519: Remove the x/crypto/curve25519 fallback
Upstream got rid of the assembly. This is marginally slower, but it will use fiat, and it's only a few percent.
1 parent 5fa5c78 commit 67c21f2

File tree

4 files changed

+1
-115
lines changed

4 files changed

+1
-115
lines changed

primitives/x25519/x25519.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ import (
3737
"crypto/subtle"
3838
"fmt"
3939

40-
xcurve "golang.org/x/crypto/curve25519"
41-
4240
"github.com/oasisprotocol/curve25519-voi/curve"
4341
"github.com/oasisprotocol/curve25519-voi/curve/scalar"
4442
"github.com/oasisprotocol/curve25519-voi/primitives/ed25519"
@@ -54,11 +52,7 @@ const (
5452
// Basepoint is the canonical Curve25519 generator.
5553
var Basepoint []byte
5654

57-
var (
58-
basePoint = [32]byte{9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
59-
60-
debugNoXcurve bool
61-
)
55+
var basePoint = [32]byte{9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
6256

6357
// ScalarMult sets dst to the product in*base where dst and base are the x
6458
// coordinates of group points and all values are in little-endian form.
@@ -67,14 +61,6 @@ var (
6761
// zeroes, irrespective of the scalar. Instead, use the X25519 function, which
6862
// will return an error.
6963
func ScalarMult(dst, in, base *[32]byte) {
70-
// If the `x/crypto/curve25519` package would be faster, and we
71-
// are not exercising the implementation provided by this package
72-
// (eg: testing or benchmarking), use that instead.
73-
if xcurveFaster && !debugNoXcurve {
74-
xcurve.ScalarMult(dst, in, base)
75-
return
76-
}
77-
7864
var ec [ScalarSize]byte
7965
copy(ec[:], in[:])
8066
clampScalar(ec[:])

primitives/x25519/x25519_amd64.go

Lines changed: 0 additions & 38 deletions
This file was deleted.

primitives/x25519/x25519_generic.go

Lines changed: 0 additions & 35 deletions
This file was deleted.

primitives/x25519/x25519_test.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,6 @@ func TestScalarBaseMult(t *testing.T) {
6666

6767
func TestX25519(t *testing.T) {
6868
t.Run("voi", testX25519)
69-
if xcurveFaster {
70-
t.Run("voi/debugNoXcurve", func(t *testing.T) {
71-
debugNoXcurve = true
72-
defer func() {
73-
debugNoXcurve = false
74-
}()
75-
testX25519(t)
76-
})
77-
}
7869
}
7970

8071
func testX25519(t *testing.T) {
@@ -166,15 +157,6 @@ func testTestVectors(t *testing.T, scalarMult func(dst, scalar, point *[32]byte)
166157

167158
func TestScalarMult(t *testing.T) {
168159
t.Run("voi", testScalarMult)
169-
if xcurveFaster {
170-
t.Run("voi/debugNoXcurve", func(t *testing.T) {
171-
debugNoXcurve = true
172-
defer func() {
173-
debugNoXcurve = false
174-
}()
175-
testScalarMult(t)
176-
})
177-
}
178160
}
179161

180162
func testScalarMult(t *testing.T) {
@@ -245,15 +227,6 @@ func benchScalarBaseMult(b *testing.B, scalarBaseMult func(dst, scalar *[32]byte
245227

246228
func BenchmarkScalarMult(b *testing.B) {
247229
b.Run("voi", func(b *testing.B) { benchScalarMult(b, ScalarMult) })
248-
if xcurveFaster {
249-
b.Run("voi/debugNoXcurve", func(b *testing.B) {
250-
debugNoXcurve = true
251-
defer func() {
252-
debugNoXcurve = false
253-
}()
254-
benchScalarMult(b, ScalarMult)
255-
})
256-
}
257230
b.Run("xcrypto", func(b *testing.B) {
258231
benchScalarMult(b, xcurve.ScalarMult) //nolint:staticcheck
259232
})

0 commit comments

Comments
 (0)