Skip to content

Commit 7e3ac20

Browse files
internal/wycheproof: also use Verify in TestECDSA
Check both Verify and VerifyASN1 in the ECDSA tests. Change-Id: Id767354484a7da18ae4e00cd6f2a01a2909e6732 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/453755 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
1 parent 23edec0 commit 7e3ac20

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

internal/wycheproof/ecdsa_test.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ package wycheproof
66

77
import (
88
"crypto/ecdsa"
9+
"math/big"
910
"testing"
11+
12+
"golang.org/x/crypto/cryptobyte"
13+
"golang.org/x/crypto/cryptobyte/asn1"
1014
)
1115

1216
func TestECDSA(t *testing.T) {
@@ -76,9 +80,25 @@ func TestECDSA(t *testing.T) {
7680
h.Reset()
7781
h.Write(decodeHex(sig.Msg))
7882
hashed := h.Sum(nil)
79-
got := ecdsa.VerifyASN1(pub, hashed, decodeHex(sig.Sig))
83+
sigBytes := decodeHex(sig.Sig)
84+
got := ecdsa.VerifyASN1(pub, hashed, sigBytes)
85+
if want := shouldPass(sig.Result, sig.Flags, flagsShouldPass); got != want {
86+
t.Errorf("tcid: %d, type: %s, comment: %q, VerifyASN1 wanted success: %t", sig.TcID, sig.Result, sig.Comment, want)
87+
}
88+
89+
var r, s big.Int
90+
var inner cryptobyte.String
91+
input := cryptobyte.String(sigBytes)
92+
if !input.ReadASN1(&inner, asn1.SEQUENCE) ||
93+
!input.Empty() ||
94+
!inner.ReadASN1Integer(&r) ||
95+
!inner.ReadASN1Integer(&s) ||
96+
!inner.Empty() {
97+
continue
98+
}
99+
got = ecdsa.Verify(pub, hashed, &r, &s)
80100
if want := shouldPass(sig.Result, sig.Flags, flagsShouldPass); got != want {
81-
t.Errorf("tcid: %d, type: %s, comment: %q, wanted success: %t", sig.TcID, sig.Result, sig.Comment, want)
101+
t.Errorf("tcid: %d, type: %s, comment: %q, Verify wanted success: %t", sig.TcID, sig.Result, sig.Comment, want)
82102
}
83103
}
84104
}

0 commit comments

Comments
 (0)