go__cache/docs/hash.md

61 lines
2.5 KiB
Markdown

# Hash logic
Keys are hashed.
## Memcached hashes
Memcached itself uses either:
* [Jenkins hash](https://en.wikipedia.org/wiki/Jenkins_hash_function)
* http://burtleburtle.net/bob/hash/doobs.html
* http://burtleburtle.net/bob/c/lookup3.c Public domain.
* [Murmur 3 hash](https://en.wikipedia.org/wiki/MurmurHash)
* [Murmur 3 in Go](https://github.com/spaolacci/murmur3)
## Golang
Beyond the Go ports of these hashes, Go includes native alternatives:
* Jenkins hash
* https://github.com/mtchavez/jenkins MIT license.
* https://github.com/tsaost/bjh port of lookup3.c. BSD license.
* https://github.com/Apsalar/lookup3 hashlittle() from lookup3.c. Optimized for compatibility/portability,
not for performance. Implements `hash.Hash32`. Public domain.
* https://github.com/MstrVLT/lookup3/ port of lookup3.c. License undefined.
* Murmur 3:
* https://github.com/reusee/mmh3 MIT license.
* https://github.com/huichen/murmur APL 2.0 license.
* https://github.com/go-ego/murmur APL 2.0 license. Based on huichen's version.
* https://github.com/beevik/murmur License undefined.
* https://github.com/ericx10ng/murmurhash2-go License undefined: was MIT but got removed.
* xxhash:
* https://github.com/vova616/xxhash/blob/master/xxhash.go (not ARM-compatible). MIT license.
* Golang standard library hashes:
* hash/adler32
* https://golang.org/pkg/hash/adler32/
* hash/crc32
* https://golang.org/pkg/hash/crc32/
* The Castagnoli polynomial may be hardware-accelerated on post-Nehalem CPUs compiled with 6g
(https://stackoverflow.com/questions/23436358/bob-jenkins-hash-getting-bad-performance)
* hash/crc64:
* https://golang.org/pkg/hash/crc64/
* hash/fnv:
* https://golang.org/pkg/hash/fnv/
* Golang [crypto](https://golang.org/pkg/crypto/#pkg-subdirectories) package includes many
cryptographic hashed with optimized implementations too. Most interesting are probably MD5 and SHA1
* AES (Rijndael),
* Cipher package provides bloc cipher modes around low-level ciphers, no specific hashes.
* DES (DIPS 46-3)
* DSA (FIPS 186-3)
* ECDSA (FIPS 186-3)
* Elliptic package doesn't directly apply
* HMAC
* MD5 (RFC 1321)
* rand package doesn't directly apply
* RC4, RSA provide encryption, don't directly apply
* SHA1 (RFC 3174). Reported to be as fast as a Jenkins hash, but may not has optimal distribution
properties
* SHA-256, SHA-384, SHA512, SHA512-224, SHA-512/256 (FIPC 180-4)
* subtle package doesn't directly apply
* TLS 1.2, doesn't directly apply
* X.509, doesn't directly apply