You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
693 B

  1. package arbo
  2. import "math/big"
  3. // SwapEndianness swaps the order of the bytes in the byte slice.
  4. func SwapEndianness(b []byte) []byte {
  5. o := make([]byte, len(b))
  6. for i := range b {
  7. o[len(b)-1-i] = b[i]
  8. }
  9. return o
  10. }
  11. // BigIntToBytes converts a *big.Int into a byte array in Little-Endian
  12. func BigIntToBytes(blen int, bi *big.Int) []byte {
  13. // var b [blen]byte // TODO make the length depending on the tree.hashFunction.Len()
  14. b := make([]byte, blen)
  15. copy(b[:], SwapEndianness(bi.Bytes()))
  16. return b[:]
  17. }
  18. // BytesToBigInt converts a byte array in Little-Endian representation into
  19. // *big.Int
  20. func BytesToBigInt(b []byte) *big.Int {
  21. return new(big.Int).SetBytes(SwapEndianness(b))
  22. }