From 5be8306ecec35bf8cca31d4a2f1980563dd8b0e6 Mon Sep 17 00:00:00 2001 From: vishal <1117327+vishalchangrani@users.noreply.github.com> Date: Mon, 10 Aug 2026 18:25:55 -0400 Subject: [PATCH] use readTwoBigInts helper in signatureNormalizeS and signatureFlipS Replace direct big.Int.SetBytes calls with the readTwoBigInts helper for consistency with the rest of the ECDSA code that reads (R, S) components from a serialized signature. Co-Authored-By: Claude Opus 4.7 (1M context) --- ecdsa.go | 4 ++-- ecdsa_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ecdsa.go b/ecdsa.go index ffbcfffd..894de053 100644 --- a/ecdsa.go +++ b/ecdsa.go @@ -397,8 +397,8 @@ func (a *ecdsaContext) isLowS(s *big.Int) bool { func (a *ecdsaContext) signatureNormalizeS(sig []byte) ([]byte, bool) { // read S nLen := bitsToBytes(a.curveN.BitLen()) - s := new(big.Int).SetBytes(sig[nLen:]) // S >= 0 - if a.isLowS(s) { // S <= (n-1)/2 + _, s := readTwoBigInts(sig, nLen) // S >= 0 + if a.isLowS(s) { // S <= (n-1)/2 return sig, true // S is in the valid range and no need to flip it } diff --git a/ecdsa_test.go b/ecdsa_test.go index 8c9e3c35..6f0819a5 100644 --- a/ecdsa_test.go +++ b/ecdsa_test.go @@ -549,7 +549,7 @@ func TestECDSAHighAndLowS(t *testing.T) { func (a *ecdsaContext) signatureFlipS(sig []byte) []byte { // read S nLen := bitsToBytes(a.curveN.BitLen()) - s := new(big.Int).SetBytes(sig[nLen:]) + _, s := readTwoBigInts(sig, nLen) // compute N-S sComplement := new(big.Int).Sub(a.curveN, s) // write it into a new signature