Skip to content

Commit 54e75e8

Browse files
mundaymFiloSottile
authored andcommitted
crypto/ed25519: remove s390x KDSA implementation
This reverts CL 202578 and CL 230677 which added an optimization to use KDSA when available on s390x. Inconsistencies have been found between the two implementations in their handling of certain edge cases. Since the Go 1.15 release is extremely soon it seems prudent to remove this optimization for now and revisit it in a future release. Fixes #40475. Change-Id: Ifb2ed9b9e573784df57383671f1c29d8abae90d4 Reviewed-on: https://go-review.googlesource.com/c/go/+/245497 Run-TryBot: Michael Munday <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ruixin(Peter) Bao <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]>
1 parent 6b4dcf1 commit 54e75e8

File tree

5 files changed

+8
-269
lines changed

5 files changed

+8
-269
lines changed

src/crypto/ed25519/ed25519.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func Sign(privateKey PrivateKey, message []byte) []byte {
154154
return signature
155155
}
156156

157-
func signGeneric(signature, privateKey, message []byte) {
157+
func sign(signature, privateKey, message []byte) {
158158
if l := len(privateKey); l != PrivateKeySize {
159159
panic("ed25519: bad private key length: " + strconv.Itoa(l))
160160
}
@@ -201,10 +201,6 @@ func signGeneric(signature, privateKey, message []byte) {
201201
// Verify reports whether sig is a valid signature of message by publicKey. It
202202
// will panic if len(publicKey) is not PublicKeySize.
203203
func Verify(publicKey PublicKey, message, sig []byte) bool {
204-
return verify(publicKey, message, sig)
205-
}
206-
207-
func verifyGeneric(publicKey PublicKey, message, sig []byte) bool {
208204
if l := len(publicKey); l != PublicKeySize {
209205
panic("ed25519: bad public key length: " + strconv.Itoa(l))
210206
}

src/crypto/ed25519/ed25519_noasm.go

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

src/crypto/ed25519/ed25519_s390x.go

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

src/crypto/ed25519/ed25519_s390x.s

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

src/crypto/ed25519/ed25519_test.go

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ func (zeroReader) Read(buf []byte) (int, error) {
2626
return len(buf), nil
2727
}
2828

29-
// signGenericWrapper is identical to Sign except that it unconditionally calls signGeneric directly
30-
// rather than going through the sign function that might call assembly code.
31-
func signGenericWrapper(privateKey PrivateKey, msg []byte) []byte {
32-
sig := make([]byte, SignatureSize)
33-
signGeneric(sig, privateKey, msg)
34-
return sig
35-
}
36-
3729
func TestUnmarshalMarshal(t *testing.T) {
3830
pub, _, _ := GenerateKey(rand.Reader)
3931

@@ -53,33 +45,22 @@ func TestUnmarshalMarshal(t *testing.T) {
5345
}
5446

5547
func TestSignVerify(t *testing.T) {
56-
t.Run("Generic", func(t *testing.T) { testSignVerify(t, signGenericWrapper, verifyGeneric) })
57-
t.Run("Native", func(t *testing.T) { testSignVerify(t, Sign, Verify) })
58-
}
59-
60-
func testSignVerify(t *testing.T, signImpl func(privateKey PrivateKey, message []byte) []byte,
61-
verifyImpl func(publicKey PublicKey, message, sig []byte) bool) {
6248
var zero zeroReader
6349
public, private, _ := GenerateKey(zero)
6450

6551
message := []byte("test message")
66-
sig := signImpl(private, message)
67-
if !verifyImpl(public, message, sig) {
52+
sig := Sign(private, message)
53+
if !Verify(public, message, sig) {
6854
t.Errorf("valid signature rejected")
6955
}
7056

7157
wrongMessage := []byte("wrong message")
72-
if verifyImpl(public, wrongMessage, sig) {
58+
if Verify(public, wrongMessage, sig) {
7359
t.Errorf("signature of different message accepted")
7460
}
7561
}
7662

7763
func TestCryptoSigner(t *testing.T) {
78-
t.Run("Generic", func(t *testing.T) { testCryptoSigner(t, verifyGeneric) })
79-
t.Run("Native", func(t *testing.T) { testCryptoSigner(t, Verify) })
80-
}
81-
82-
func testCryptoSigner(t *testing.T, verifyImpl func(publicKey PublicKey, message, sig []byte) bool) {
8364
var zero zeroReader
8465
public, private, _ := GenerateKey(zero)
8566

@@ -102,7 +83,7 @@ func testCryptoSigner(t *testing.T, verifyImpl func(publicKey PublicKey, message
10283
t.Fatalf("error from Sign(): %s", err)
10384
}
10485

105-
if !verifyImpl(public, message, signature) {
86+
if !Verify(public, message, signature) {
10687
t.Errorf("Verify failed on signature from Sign()")
10788
}
10889
}
@@ -130,12 +111,6 @@ func TestEqual(t *testing.T) {
130111
}
131112

132113
func TestGolden(t *testing.T) {
133-
t.Run("Generic", func(t *testing.T) { testGolden(t, signGenericWrapper, verifyGeneric) })
134-
t.Run("Native", func(t *testing.T) { testGolden(t, Sign, Verify) })
135-
}
136-
137-
func testGolden(t *testing.T, signImpl func(privateKey PrivateKey, message []byte) []byte,
138-
verifyImpl func(publicKey PublicKey, message, sig []byte) bool) {
139114
// sign.input.gz is a selection of test cases from
140115
// https://ed25519.cr.yp.to/python/sign.input
141116
testDataZ, err := os.Open("testdata/sign.input.gz")
@@ -177,12 +152,12 @@ func testGolden(t *testing.T, signImpl func(privateKey PrivateKey, message []byt
177152
copy(priv[:], privBytes)
178153
copy(priv[32:], pubKey)
179154

180-
sig2 := signImpl(priv[:], msg)
155+
sig2 := Sign(priv[:], msg)
181156
if !bytes.Equal(sig, sig2[:]) {
182157
t.Errorf("different signature result on line %d: %x vs %x", lineNo, sig, sig2)
183158
}
184159

185-
if !verifyImpl(pubKey, msg, sig2) {
160+
if !Verify(pubKey, msg, sig2) {
186161
t.Errorf("signature failed to verify on line %d", lineNo)
187162
}
188163

@@ -206,11 +181,6 @@ func testGolden(t *testing.T, signImpl func(privateKey PrivateKey, message []byt
206181
}
207182

208183
func TestMalleability(t *testing.T) {
209-
t.Run("Generic", func(t *testing.T) { testMalleability(t, verifyGeneric) })
210-
t.Run("Native", func(t *testing.T) { testMalleability(t, Verify) })
211-
}
212-
213-
func testMalleability(t *testing.T, verifyImpl func(publicKey PublicKey, message, sig []byte) bool) {
214184
// https://tools.ietf.org/html/rfc8032#section-5.1.7 adds an additional test
215185
// that s be in [0, order). This prevents someone from adding a multiple of
216186
// order to s and obtaining a second valid signature for the same message.
@@ -229,7 +199,7 @@ func testMalleability(t *testing.T, verifyImpl func(publicKey PublicKey, message
229199
0xb1, 0x08, 0xc3, 0xbd, 0xae, 0x36, 0x9e, 0xf5, 0x49, 0xfa,
230200
}
231201

232-
if verifyImpl(publicKey, msg, sig) {
202+
if Verify(publicKey, msg, sig) {
233203
t.Fatal("non-canonical signature accepted")
234204
}
235205
}

0 commit comments

Comments
 (0)