mirror of
https://github.com/arnaucube/arbo.git
synced 2026-01-09 07:21:28 +01:00
Add HashFunction interface (w/ Poseidon & Sha256)
This commit is contained in:
25
utils.go
Normal file
25
utils.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package arbo
|
||||
|
||||
import "math/big"
|
||||
|
||||
// SwapEndianness swaps the order of the bytes in the byte slice.
|
||||
func SwapEndianness(b []byte) []byte {
|
||||
o := make([]byte, len(b))
|
||||
for i := range b {
|
||||
o[len(b)-1-i] = b[i]
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
// BigIntToBytes converts a *big.Int into a byte array in Little-Endian
|
||||
func BigIntToBytes(bi *big.Int) []byte {
|
||||
var b [32]byte
|
||||
copy(b[:], SwapEndianness(bi.Bytes()))
|
||||
return b[:]
|
||||
}
|
||||
|
||||
// BytesToBigInt converts a byte array in Little-Endian representation into
|
||||
// *big.Int
|
||||
func BytesToBigInt(b []byte) *big.Int {
|
||||
return new(big.Int).SetBytes(SwapEndianness(b))
|
||||
}
|
||||
Reference in New Issue
Block a user