This repository has been archived on 2024-04-07. You can view files and clone it, but cannot push or open issues or pull requests.
moneroutil/keccak.go

40 lines
641 B
Go
Raw Normal View History

2017-04-25 00:19:04 +00:00
package moneroutil
import (
"golang.org/x/crypto/sha3"
2017-04-25 00:19:04 +00:00
)
2017-05-05 03:11:50 +00:00
const (
ChecksumLength = 4
HashLength = 32
)
type Hash [HashLength]byte
type Checksum [ChecksumLength]byte
func Keccak256(data ...[]byte) (result Hash) {
h := sha3.NewLegacyKeccak256()
2017-04-25 00:19:04 +00:00
for _, b := range data {
h.Write(b)
}
2017-05-05 03:11:50 +00:00
r := h.Sum(nil)
copy(result[:], r)
2017-04-25 00:19:04 +00:00
return
}
2017-05-05 03:11:50 +00:00
func GetChecksum(data ...[]byte) (result Checksum) {
2017-04-25 00:19:04 +00:00
keccak256 := Keccak256(data...)
2017-05-05 03:11:50 +00:00
copy(result[:], keccak256[:4])
return
}
func Keccak512(data ...[]byte) (result Hash) {
h := sha3.NewLegacyKeccak512()
2017-05-05 03:11:50 +00:00
for _, b := range data {
h.Write(b)
}
r := h.Sum(nil)
copy(result[:], r)
2017-04-25 00:19:04 +00:00
return
}