Skip to content

Commit 97fc981

Browse files
committed
internal/wycheproof: update TestEcdsa to use ecdsa.VerifyASN1
Change-Id: Ibd6ce156550615cb85c06e734641c34fca0cfcd0 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/220697 Run-TryBot: Katie Hockman <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]>
1 parent 1b76d66 commit 97fc981

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

internal/wycheproof/internal/ecdsa/ecdsa.go renamed to internal/wycheproof/ecdsa_compat_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
// Copyright 2019 The Go Authors. All rights reserved.
1+
// Copyright 2020 The Go Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// Package ecdsa provides an internal version of ecdsa.Verify
6-
// that is used for the Wycheproof tests.
7-
package ecdsa
5+
// +build !go1.15
6+
7+
// ecdsa.VerifyASN1 was added in Go 1.15.
8+
9+
package wycheproof
810

911
import (
1012
"crypto/ecdsa"
@@ -14,9 +16,7 @@ import (
1416
"golang.org/x/crypto/cryptobyte/asn1"
1517
)
1618

17-
// VerifyASN1 verifies the ASN1 encoded signature, sig, of hash using the
18-
// public key, pub. Its return value records whether the signature is valid.
19-
func VerifyASN1(pub *ecdsa.PublicKey, hash, sig []byte) bool {
19+
func verifyASN1(pub *ecdsa.PublicKey, hash, sig []byte) bool {
2020
var (
2121
r, s = &big.Int{}, &big.Int{}
2222
inner cryptobyte.String
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build go1.15
6+
7+
package wycheproof
8+
9+
import (
10+
"crypto/ecdsa"
11+
)
12+
13+
func verifyASN1(pub *ecdsa.PublicKey, hash, sig []byte) bool {
14+
return ecdsa.VerifyASN1(pub, hash, sig)
15+
}

internal/wycheproof/ecdsa_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ package wycheproof
77
import (
88
"crypto/ecdsa"
99
"testing"
10-
11-
wecdsa "golang.org/x/crypto/internal/wycheproof/internal/ecdsa"
1210
)
1311

1412
func TestEcdsa(t *testing.T) {
@@ -157,7 +155,7 @@ func TestEcdsa(t *testing.T) {
157155
h.Reset()
158156
h.Write(decodeHex(sig.Msg))
159157
hashed := h.Sum(nil)
160-
got := wecdsa.VerifyASN1(pub, hashed, decodeHex(sig.Sig))
158+
got := verifyASN1(pub, hashed, decodeHex(sig.Sig))
161159
if want := shouldPass(sig.Result, sig.Flags, flagsShouldPass); got != want {
162160
t.Errorf("tcid: %d, type: %s, comment: %q, wanted success: %t", sig.TcId, sig.Result, sig.Comment, want)
163161
}

0 commit comments

Comments
 (0)