Skip to content

Commit

Permalink
internal/wycheproof: also use Verify in TestECDSA
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rolandshoemaker committed Dec 21, 2022
1 parent 23edec0 commit 7e3ac20
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions internal/wycheproof/ecdsa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit 7e3ac20

Please sign in to comment.