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