gotenthash is a Go implementation of TentHash, a 160-bit non-cryptographic hash function.
- Fast and simple non-cryptographic hash function
- Support for incremental hashing and streaming input
- Compatible with the original C implementation of TentHash
Using Go modules, you can install gotenthash with the following command:
go get github.com/lib-x/gotenthash
import "github.com/lib-x/gotenthash"
h := gotenthash.New()
h.Write([]byte("Hello, world!"))
fmt.Printf("%x\n", h.Sum(nil))
h := gotenthash.New()
h.Write([]byte("Hello, "))
h.Write([]byte("world!"))
fmt.Printf("%x\n", h.Sum(nil))
file, := os.Open("example.txt")
defer file.Close()
hash, err := gotenthash.HashReader(file)
if err != nil {
// Handle error
}
func New() *TentHasher
: Create a new TentHasher instancefunc (t *TentHasher) Write(data []byte) (int, error)
: Write data to the hasherfunc (t *TentHasher) Sum(b []byte) []byte
: Compute the current hash valuefunc (t *TentHasher) Reset()
: Reset the hasher statefunc (t *TentHasher) WriteReader(r io.Reader) (int64, error)
: Write data from an io.Readerfunc (t *TentHasher) SumReader(r io.Reader) ([]byte, error)
: Compute hash value from an io.Readerfunc Hash(data []byte) [DigestSize]byte
: Compute hash value of a byte slicefunc HashReader(reader io.Reader) ([DigestSize]byte, error)
: Compute hash value from an io.Reader
Contributions are welcome! Please submit a pull request or create an issue to discuss the changes you want to make.
This project is licensed under the MIT License. See the LICENSE file for details.
This project is based on TentHash by Casey Rodarmor.