Skip to content

Commit

Permalink
calc: add xxh64 hash
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlindhe committed Jan 11, 2024
1 parent 1943edc commit 13f9955
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ with `hasher --list-hashes`
| streebog-512 | GOST R 34.11-2012-512 | 512 bit | 64 byte | 2012 |
| tiger192 | Tiger | 192 bit | 24 byte | 1996 |
| whirlpool | Whirlpool | 512 bit | 64 byte | 2000 |
| xxh64 | xxHash 64 | 64 bit | 4 byte | 2012 |

## Binary-to-text encodings

Expand Down
11 changes: 11 additions & 0 deletions calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"io"
"sort"

"github.com/cespare/xxhash"
"github.com/cxmcc/tiger"
"github.com/dchest/blake256"
"github.com/dchest/blake2b"
Expand Down Expand Up @@ -76,6 +77,7 @@ var (
"fnv1a-32": 32,
"fnv1-64": 64,
"fnv1a-64": 64,
"xxh64": 64,
"gost94": 256,
"gost94-cryptopro": 256,
"md2": 128,
Expand Down Expand Up @@ -129,6 +131,7 @@ var (
"fnv1a-32": fnv1a32Sum,
"fnv1-64": fnv1_64Sum,
"fnv1a-64": fnv1a64Sum,
"xxh64": xxh64Sum,
"gost94": gost94Sum,
"gost94-cryptopro": gost94CryptoproSum,
"md2": md2Sum,
Expand Down Expand Up @@ -630,3 +633,11 @@ func whirlpoolSum(r io.Reader) ([]byte, error) {
}
return h.Sum(nil), nil
}

func xxh64Sum(r io.Reader) ([]byte, error) {
h := xxhash.New()
if _, err := io.Copy(h, r); err != nil {
return nil, err
}
return h.Sum(nil), nil
}
2 changes: 2 additions & 0 deletions calc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ var (
"whirlpool": {
fox: "b97de512e91e3828b40d2b0fdce9ceb3c4a71f9bea8d88e75c4fa854df36725fd2b52eb6544edcacd6f8beddfea403cb55ae31f03ad62a5ef54e42ee82c3fb35",
blank: "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3"},
"xxh64": {fox: "0b242d361fda71bc",
blank: "ef46db3751d8e999"},
}
)

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/aybabtme/color v0.0.0-20140713052517-28ad4cc941d6
github.com/bproctor/base91 v0.0.0-20160902125316-7de6f1dd34e8
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cxmcc/tiger v0.0.0-20170524142333-bde35e2713d7
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dchest/blake256 v1.1.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/alecthomas/kingpin v2.2.6+incompatible h1:5svnBTFgJjZvGKyYBtMB0+m5wvrbUHiqye8wRJMlnYI=
github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
Expand All @@ -8,6 +9,8 @@ github.com/aybabtme/color v0.0.0-20140713052517-28ad4cc941d6 h1:k5FebMq+CuzGrf3L
github.com/aybabtme/color v0.0.0-20140713052517-28ad4cc941d6/go.mod h1:k6bCbg1gudUfWem/VvfWXsk5Qqag/NDXzEHu0mNcsPM=
github.com/bproctor/base91 v0.0.0-20160902125316-7de6f1dd34e8 h1:AOcLIabtn5jh31VACsbAI1R6y/FjyFRDyuNxkvHmSTI=
github.com/bproctor/base91 v0.0.0-20160902125316-7de6f1dd34e8/go.mod h1:Qf+Cy/9Oy2JSEKDrf5nBXdsBqEFBNbU8Rzrart5f7h0=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cxmcc/tiger v0.0.0-20170524142333-bde35e2713d7 h1:jBEtq1t2gpn2kEzvRlCUxvvrxl5aSWkXNPwe/hwvSNQ=
github.com/cxmcc/tiger v0.0.0-20170524142333-bde35e2713d7/go.mod h1:ruCYvt9rtYymAr4rNmfYJrl1dz8HSXUFP7cufqKOsDI=
Expand Down Expand Up @@ -63,6 +66,7 @@ github.com/mewpkg/hashutil v1.0.1 h1:me5DWIMS8wLeMmtZnMxwNTMIA9nT9HvQZLYVMbmBIyw
github.com/mewpkg/hashutil v1.0.1/go.mod h1:DSL30IKicBzaNFwGvhg9BG8YkZj0Nb+d6TDPb9P7hQY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
Expand Down

0 comments on commit 13f9955

Please sign in to comment.