aboutsummaryrefslogtreecommitdiff
path: root/pkg/types/util.go
blob: 3cd7dfa7d18f197fd87282d59bd59d7b0f7ddb9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package types

import (
	"crypto/sha256"
)

const (
	LeafHashPrefix = 0x00
)

func Hash(buf []byte) *[HashSize]byte {
	var ret [HashSize]byte
	hash := sha256.New()
	hash.Write(buf)
	copy(ret[:], hash.Sum(nil))
	return &ret
}

func HashLeaf(buf []byte) *[HashSize]byte {
	return Hash(append([]byte{LeafHashPrefix}, buf...))
}