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.

41 lines
583 B

7 years ago
  1. package tmhash
  2. import (
  3. "crypto/sha256"
  4. "hash"
  5. )
  6. var (
  7. Size = 20
  8. BlockSize = sha256.BlockSize
  9. )
  10. type sha256trunc struct {
  11. sha256 hash.Hash
  12. }
  13. func (h sha256trunc) Write(p []byte) (n int, err error) {
  14. return h.sha256.Write(p)
  15. }
  16. func (h sha256trunc) Sum(b []byte) []byte {
  17. shasum := h.sha256.Sum(b)
  18. return shasum[:Size]
  19. }
  20. func (h sha256trunc) Reset() {
  21. h.sha256.Reset()
  22. }
  23. func (h sha256trunc) Size() int {
  24. return Size
  25. }
  26. func (h sha256trunc) BlockSize() int {
  27. return h.sha256.BlockSize()
  28. }
  29. func New() hash.Hash {
  30. return sha256trunc{
  31. sha256: sha256.New(),
  32. }
  33. }