diff options
| author | Roland Shoemaker <roland@golang.org> | 2022-11-28 10:56:10 -0800 |
|---|---|---|
| committer | Roland Shoemaker <roland@golang.org> | 2022-12-21 16:58:14 +0000 |
| commit | 7e3ac2043e18f9cbc0c089cb28e73caac2c9d9d1 (patch) | |
| tree | 79478f3b7fbebf1249a073c189b4ebee4dd8ba3b | |
| parent | 23edec0b383afbf83bd3e94309cfe09a01a68a99 (diff) | |
| download | go-x-crypto-7e3ac2043e18f9cbc0c089cb28e73caac2c9d9d1.tar.xz | |
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>
| -rw-r--r-- | internal/wycheproof/ecdsa_test.go | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/internal/wycheproof/ecdsa_test.go b/internal/wycheproof/ecdsa_test.go index 42f3285..80125ad 100644 --- a/internal/wycheproof/ecdsa_test.go +++ b/internal/wycheproof/ecdsa_test.go @@ -6,7 +6,11 @@ package wycheproof import ( "crypto/ecdsa" + "math/big" "testing" + + "golang.org/x/crypto/cryptobyte" + "golang.org/x/crypto/cryptobyte/asn1" ) func TestECDSA(t *testing.T) { @@ -76,9 +80,25 @@ func TestECDSA(t *testing.T) { h.Reset() h.Write(decodeHex(sig.Msg)) hashed := h.Sum(nil) - got := ecdsa.VerifyASN1(pub, hashed, decodeHex(sig.Sig)) + sigBytes := decodeHex(sig.Sig) + got := ecdsa.VerifyASN1(pub, hashed, sigBytes) + if want := shouldPass(sig.Result, sig.Flags, flagsShouldPass); got != want { + t.Errorf("tcid: %d, type: %s, comment: %q, VerifyASN1 wanted success: %t", sig.TcID, sig.Result, sig.Comment, want) + } + + var r, s big.Int + var inner cryptobyte.String + input := cryptobyte.String(sigBytes) + if !input.ReadASN1(&inner, asn1.SEQUENCE) || + !input.Empty() || + !inner.ReadASN1Integer(&r) || + !inner.ReadASN1Integer(&s) || + !inner.Empty() { + continue + } + got = ecdsa.Verify(pub, hashed, &r, &s) if want := shouldPass(sig.Result, sig.Flags, flagsShouldPass); got != want { - t.Errorf("tcid: %d, type: %s, comment: %q, wanted success: %t", sig.TcID, sig.Result, sig.Comment, want) + t.Errorf("tcid: %d, type: %s, comment: %q, Verify wanted success: %t", sig.TcID, sig.Result, sig.Comment, want) } } } |
