Skip to content

Commit

Permalink
secp256k1/ecdsa: Add tests for new R and S methods.
Browse files Browse the repository at this point in the history
This adds a couple of additional checks to the sign and verify tests to
ensure the new R and S methods return the expected values.
  • Loading branch information
davecgh committed Sep 21, 2023
1 parent 813446b commit 9754217
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion dcrec/secp256k1/ecdsa/signature_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2013-2016 The btcsuite developers
// Copyright (c) 2015-2022 The Decred developers
// Copyright (c) 2015-2023 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -548,6 +548,20 @@ func TestSignAndVerify(t *testing.T) {
continue
}

// Ensure the R method returns the expected value.
gotSigR := gotSig.R()
if !gotSigR.Equals(wantSigR) {
t.Errorf("%s: unexpected R component -- got %064x, want %064x",
test.name, gotSigR.Bytes(), wantSigR.Bytes())
}

// Ensure the S method returns the expected value.
gotSigS := gotSig.S()
if !gotSigS.Equals(wantSigS) {
t.Errorf("%s: unexpected S component -- got %064x, want %064x",
test.name, gotSigS.Bytes(), wantSigS.Bytes())
}

// Ensure the produced signature verifies.
pubKey := privKey.PubKey()
if !gotSig.Verify(hash, pubKey) {
Expand Down

0 comments on commit 9754217

Please sign in to comment.