add Poseidon multihash ([]*big.Int), add HashBytes for MiMC7 & Poseidon

This commit is contained in:
arnaucube
2019-08-30 18:36:41 +02:00
parent 2b1935299c
commit c95c95b7b1
4 changed files with 115 additions and 13 deletions

View File

@@ -127,3 +127,21 @@ func Hash(arr []*big.Int, key *big.Int) (*big.Int, error) {
}
return r, nil
}
// HashBytes hashes a msg byte slice by blocks of 31 bytes encoded as
// little-endian
func HashBytes(b []byte) (*big.Int, error) {
n := 31
bElems := make([]*big.Int, 0, len(b)/n+1)
for i := 0; i < len(b)/n; i++ {
v := new(big.Int)
utils.SetBigIntFromLEBytes(v, b[n*i:n*(i+1)])
bElems = append(bElems, v)
}
if len(b)%n != 0 {
v := new(big.Int)
utils.SetBigIntFromLEBytes(v, b[(len(b)/n)*n:])
bElems = append(bElems, v)
}
return Hash(bElems, nil)
}