Skip to content

Commit

Permalink
primitives/x25519: Remove the x/crypto/curve25519 fallback
Browse files Browse the repository at this point in the history
Upstream got rid of the assembly.  This is marginally slower, but it
will use fiat, and it's only a few percent.
  • Loading branch information
Yawning committed Aug 11, 2021
1 parent 1fcb446 commit f07c83a
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 115 deletions.
16 changes: 1 addition & 15 deletions primitives/x25519/x25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ import (
"crypto/subtle"
"fmt"

xcurve "golang.org/x/crypto/curve25519"

"github.com/oasisprotocol/curve25519-voi/curve"
"github.com/oasisprotocol/curve25519-voi/curve/scalar"
_ "github.com/oasisprotocol/curve25519-voi/internal/toolchain"
Expand All @@ -55,11 +53,7 @@ const (
// Basepoint is the canonical Curve25519 generator.
var Basepoint []byte

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}

debugNoXcurve bool
)
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}

// ScalarMult sets dst to the product in*base where dst and base are the x
// coordinates of group points and all values are in little-endian form.
Expand All @@ -68,14 +62,6 @@ var (
// zeroes, irrespective of the scalar. Instead, use the X25519 function, which
// will return an error.
func ScalarMult(dst, in, base *[32]byte) {
// If the `x/crypto/curve25519` package would be faster, and we
// are not exercising the implementation provided by this package
// (eg: testing or benchmarking), use that instead.
if xcurveFaster && !debugNoXcurve {
xcurve.ScalarMult(dst, in, base)
return
}

var ec [ScalarSize]byte
copy(ec[:], in[:])
clampScalar(ec[:])
Expand Down
38 changes: 0 additions & 38 deletions primitives/x25519/x25519_amd64.go

This file was deleted.

35 changes: 0 additions & 35 deletions primitives/x25519/x25519_generic.go

This file was deleted.

27 changes: 0 additions & 27 deletions primitives/x25519/x25519_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,6 @@ func TestScalarBaseMult(t *testing.T) {

func TestX25519(t *testing.T) {
t.Run("voi", testX25519)
if xcurveFaster {
t.Run("voi/debugNoXcurve", func(t *testing.T) {
debugNoXcurve = true
defer func() {
debugNoXcurve = false
}()
testX25519(t)
})
}
}

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

func TestScalarMult(t *testing.T) {
t.Run("voi", testScalarMult)
if xcurveFaster {
t.Run("voi/debugNoXcurve", func(t *testing.T) {
debugNoXcurve = true
defer func() {
debugNoXcurve = false
}()
testScalarMult(t)
})
}
}

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

func BenchmarkScalarMult(b *testing.B) {
b.Run("voi", func(b *testing.B) { benchScalarMult(b, ScalarMult) })
if xcurveFaster {
b.Run("voi/debugNoXcurve", func(b *testing.B) {
debugNoXcurve = true
defer func() {
debugNoXcurve = false
}()
benchScalarMult(b, ScalarMult)
})
}
b.Run("xcrypto", func(b *testing.B) {
benchScalarMult(b, xcurve.ScalarMult) //nolint:staticcheck
})
Expand Down

0 comments on commit f07c83a

Please sign in to comment.