diff --git a/ecc/bls12-377/ecdsa/ecdsa.go b/ecc/bls12-377/ecdsa/ecdsa.go index cc13e8ac60..452e7df2a3 100644 --- a/ecc/bls12-377/ecdsa/ecdsa.go +++ b/ecc/bls12-377/ecdsa/ecdsa.go @@ -37,6 +37,7 @@ var errInvalidSig = errors.New("invalid signature") const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -103,7 +104,7 @@ func HashToInt(hash []byte) *big.Int { hash = hash[:sizeFr] } ret := new(big.Int).SetBytes(hash) - excess := len(hash)*8 - sizeFr + excess := ret.BitLen() - sizeFrBits if excess > 0 { ret.Rsh(ret, uint(excess)) } diff --git a/ecc/bls12-378/ecdsa/ecdsa.go b/ecc/bls12-378/ecdsa/ecdsa.go index 44c297cc82..f6a5d04f91 100644 --- a/ecc/bls12-378/ecdsa/ecdsa.go +++ b/ecc/bls12-378/ecdsa/ecdsa.go @@ -37,6 +37,7 @@ var errInvalidSig = errors.New("invalid signature") const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -103,7 +104,7 @@ func HashToInt(hash []byte) *big.Int { hash = hash[:sizeFr] } ret := new(big.Int).SetBytes(hash) - excess := len(hash)*8 - sizeFr + excess := ret.BitLen() - sizeFrBits if excess > 0 { ret.Rsh(ret, uint(excess)) } diff --git a/ecc/bls12-381/ecdsa/ecdsa.go b/ecc/bls12-381/ecdsa/ecdsa.go index 9039ee3885..3374cabdda 100644 --- a/ecc/bls12-381/ecdsa/ecdsa.go +++ b/ecc/bls12-381/ecdsa/ecdsa.go @@ -37,6 +37,7 @@ var errInvalidSig = errors.New("invalid signature") const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -103,7 +104,7 @@ func HashToInt(hash []byte) *big.Int { hash = hash[:sizeFr] } ret := new(big.Int).SetBytes(hash) - excess := len(hash)*8 - sizeFr + excess := ret.BitLen() - sizeFrBits if excess > 0 { ret.Rsh(ret, uint(excess)) } diff --git a/ecc/bls24-315/ecdsa/ecdsa.go b/ecc/bls24-315/ecdsa/ecdsa.go index e1309b2f36..deb4712a52 100644 --- a/ecc/bls24-315/ecdsa/ecdsa.go +++ b/ecc/bls24-315/ecdsa/ecdsa.go @@ -37,6 +37,7 @@ var errInvalidSig = errors.New("invalid signature") const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -103,7 +104,7 @@ func HashToInt(hash []byte) *big.Int { hash = hash[:sizeFr] } ret := new(big.Int).SetBytes(hash) - excess := len(hash)*8 - sizeFr + excess := ret.BitLen() - sizeFrBits if excess > 0 { ret.Rsh(ret, uint(excess)) } diff --git a/ecc/bls24-317/ecdsa/ecdsa.go b/ecc/bls24-317/ecdsa/ecdsa.go index dfcbab66cb..eda1c88065 100644 --- a/ecc/bls24-317/ecdsa/ecdsa.go +++ b/ecc/bls24-317/ecdsa/ecdsa.go @@ -37,6 +37,7 @@ var errInvalidSig = errors.New("invalid signature") const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -103,7 +104,7 @@ func HashToInt(hash []byte) *big.Int { hash = hash[:sizeFr] } ret := new(big.Int).SetBytes(hash) - excess := len(hash)*8 - sizeFr + excess := ret.BitLen() - sizeFrBits if excess > 0 { ret.Rsh(ret, uint(excess)) } diff --git a/ecc/bn254/ecdsa/ecdsa.go b/ecc/bn254/ecdsa/ecdsa.go index 8593d6a721..b25cb4d9ea 100644 --- a/ecc/bn254/ecdsa/ecdsa.go +++ b/ecc/bn254/ecdsa/ecdsa.go @@ -37,6 +37,7 @@ var errInvalidSig = errors.New("invalid signature") const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -103,7 +104,7 @@ func HashToInt(hash []byte) *big.Int { hash = hash[:sizeFr] } ret := new(big.Int).SetBytes(hash) - excess := len(hash)*8 - sizeFr + excess := ret.BitLen() - sizeFrBits if excess > 0 { ret.Rsh(ret, uint(excess)) } diff --git a/ecc/bw6-633/ecdsa/ecdsa.go b/ecc/bw6-633/ecdsa/ecdsa.go index f264a1e479..7bfa57467b 100644 --- a/ecc/bw6-633/ecdsa/ecdsa.go +++ b/ecc/bw6-633/ecdsa/ecdsa.go @@ -37,6 +37,7 @@ var errInvalidSig = errors.New("invalid signature") const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -103,7 +104,7 @@ func HashToInt(hash []byte) *big.Int { hash = hash[:sizeFr] } ret := new(big.Int).SetBytes(hash) - excess := len(hash)*8 - sizeFr + excess := ret.BitLen() - sizeFrBits if excess > 0 { ret.Rsh(ret, uint(excess)) } diff --git a/ecc/bw6-756/ecdsa/ecdsa.go b/ecc/bw6-756/ecdsa/ecdsa.go index 11c7725b5c..092e08e799 100644 --- a/ecc/bw6-756/ecdsa/ecdsa.go +++ b/ecc/bw6-756/ecdsa/ecdsa.go @@ -37,6 +37,7 @@ var errInvalidSig = errors.New("invalid signature") const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -103,7 +104,7 @@ func HashToInt(hash []byte) *big.Int { hash = hash[:sizeFr] } ret := new(big.Int).SetBytes(hash) - excess := len(hash)*8 - sizeFr + excess := ret.BitLen() - sizeFrBits if excess > 0 { ret.Rsh(ret, uint(excess)) } diff --git a/ecc/bw6-761/ecdsa/ecdsa.go b/ecc/bw6-761/ecdsa/ecdsa.go index 7a6669fcab..b556cca823 100644 --- a/ecc/bw6-761/ecdsa/ecdsa.go +++ b/ecc/bw6-761/ecdsa/ecdsa.go @@ -37,6 +37,7 @@ var errInvalidSig = errors.New("invalid signature") const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -103,7 +104,7 @@ func HashToInt(hash []byte) *big.Int { hash = hash[:sizeFr] } ret := new(big.Int).SetBytes(hash) - excess := len(hash)*8 - sizeFr + excess := ret.BitLen() - sizeFrBits if excess > 0 { ret.Rsh(ret, uint(excess)) } diff --git a/ecc/secp256k1/ecdsa/ecdsa.go b/ecc/secp256k1/ecdsa/ecdsa.go index de7c735da8..929592a46e 100644 --- a/ecc/secp256k1/ecdsa/ecdsa.go +++ b/ecc/secp256k1/ecdsa/ecdsa.go @@ -37,6 +37,7 @@ var errInvalidSig = errors.New("invalid signature") const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = 2 * sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -103,7 +104,7 @@ func HashToInt(hash []byte) *big.Int { hash = hash[:sizeFr] } ret := new(big.Int).SetBytes(hash) - excess := len(hash)*8 - sizeFr + excess := ret.BitLen() - sizeFrBits if excess > 0 { ret.Rsh(ret, uint(excess)) } diff --git a/ecc/stark-curve/ecdsa/ecdsa.go b/ecc/stark-curve/ecdsa/ecdsa.go index 4707f32195..55b0e09050 100644 --- a/ecc/stark-curve/ecdsa/ecdsa.go +++ b/ecc/stark-curve/ecdsa/ecdsa.go @@ -37,6 +37,7 @@ var errInvalidSig = errors.New("invalid signature") const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -103,7 +104,7 @@ func HashToInt(hash []byte) *big.Int { hash = hash[:sizeFr] } ret := new(big.Int).SetBytes(hash) - excess := len(hash)*8 - sizeFr + excess := ret.BitLen() - sizeFrBits if excess > 0 { ret.Rsh(ret, uint(excess)) } diff --git a/internal/generator/ecdsa/template/ecdsa.go.tmpl b/internal/generator/ecdsa/template/ecdsa.go.tmpl index fd953cdf42..17234c557c 100644 --- a/internal/generator/ecdsa/template/ecdsa.go.tmpl +++ b/internal/generator/ecdsa/template/ecdsa.go.tmpl @@ -19,6 +19,7 @@ var errInvalidSig = errors.New("invalid signature") const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes {{- if eq .Name "secp256k1"}} sizePublicKey = 2 * sizeFp @@ -94,7 +95,7 @@ func HashToInt(hash []byte) *big.Int { hash = hash[:sizeFr] } ret := new(big.Int).SetBytes(hash) - excess := len(hash)*8 - sizeFr + excess := ret.BitLen() - sizeFrBits if excess > 0 { ret.Rsh(ret, uint(excess)) }