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.

30 lines
654 B

  1. package merkle
  2. import (
  3. "github.com/tendermint/tendermint/crypto/tmhash"
  4. )
  5. // TODO: make these have a large predefined capacity
  6. var (
  7. leafPrefix = []byte{0}
  8. innerPrefix = []byte{1}
  9. )
  10. // returns tmhash(<empty>)
  11. func emptyHash() []byte {
  12. return tmhash.Sum([]byte{})
  13. }
  14. // returns tmhash(0x00 || leaf)
  15. func leafHash(leaf []byte) []byte {
  16. return tmhash.Sum(append(leafPrefix, leaf...))
  17. }
  18. // returns tmhash(0x01 || left || right)
  19. func innerHash(left []byte, right []byte) []byte {
  20. data := make([]byte, len(innerPrefix)+len(left)+len(right))
  21. n := copy(data, innerPrefix)
  22. n += copy(data[n:], left)
  23. copy(data[n:], right)
  24. return tmhash.Sum(data)
  25. }