diff --git a/ecc/bls12-377/ecdsa/ecdsa.go b/ecc/bls12-377/ecdsa/ecdsa.go index 288a9735f..d0ca34501 100644 --- a/ecc/bls12-377/ecdsa/ecdsa.go +++ b/ecc/bls12-377/ecdsa/ecdsa.go @@ -34,6 +34,7 @@ import ( const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -100,7 +101,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 22ce08e79..74f52145a 100644 --- a/ecc/bls12-378/ecdsa/ecdsa.go +++ b/ecc/bls12-378/ecdsa/ecdsa.go @@ -34,6 +34,7 @@ import ( const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -100,7 +101,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 4aea1575c..9944b8954 100644 --- a/ecc/bls12-381/ecdsa/ecdsa.go +++ b/ecc/bls12-381/ecdsa/ecdsa.go @@ -34,6 +34,7 @@ import ( const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -100,7 +101,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 d9b7362d0..747f3fca4 100644 --- a/ecc/bls24-315/ecdsa/ecdsa.go +++ b/ecc/bls24-315/ecdsa/ecdsa.go @@ -34,6 +34,7 @@ import ( const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -100,7 +101,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 add547cb2..4fb8355e8 100644 --- a/ecc/bls24-317/ecdsa/ecdsa.go +++ b/ecc/bls24-317/ecdsa/ecdsa.go @@ -34,6 +34,7 @@ import ( const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -100,7 +101,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 c860e7b94..dcde60137 100644 --- a/ecc/bn254/ecdsa/ecdsa.go +++ b/ecc/bn254/ecdsa/ecdsa.go @@ -35,6 +35,7 @@ import ( const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -101,7 +102,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 e744f91d4..649a8efe0 100644 --- a/ecc/bw6-633/ecdsa/ecdsa.go +++ b/ecc/bw6-633/ecdsa/ecdsa.go @@ -34,6 +34,7 @@ import ( const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -100,7 +101,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 e3914a732..bf32e9cac 100644 --- a/ecc/bw6-756/ecdsa/ecdsa.go +++ b/ecc/bw6-756/ecdsa/ecdsa.go @@ -34,6 +34,7 @@ import ( const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -100,7 +101,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 4665a1f17..0c77b0b0b 100644 --- a/ecc/bw6-761/ecdsa/ecdsa.go +++ b/ecc/bw6-761/ecdsa/ecdsa.go @@ -34,6 +34,7 @@ import ( const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -100,7 +101,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 f1489bd65..6c633fc99 100644 --- a/ecc/secp256k1/ecdsa/ecdsa.go +++ b/ecc/secp256k1/ecdsa/ecdsa.go @@ -35,6 +35,7 @@ import ( const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = 2 * sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -101,7 +102,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 0523fa1e2..5d94cd791 100644 --- a/ecc/stark-curve/ecdsa/ecdsa.go +++ b/ecc/stark-curve/ecdsa/ecdsa.go @@ -35,6 +35,7 @@ import ( const ( sizeFr = fr.Bytes + sizeFrBits = fr.Bits sizeFp = fp.Bytes sizePublicKey = sizeFp sizePrivateKey = sizeFr + sizePublicKey @@ -101,7 +102,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 ff966d73a..1dda1ed34 100644 --- a/internal/generator/ecdsa/template/ecdsa.go.tmpl +++ b/internal/generator/ecdsa/template/ecdsa.go.tmpl @@ -19,6 +19,7 @@ import ( 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)) }