siphash
Version, currently 1.0.02 versions
- 1.0.1latestFeb 4, 2019
- 1.0.0not indexedFeb 4, 2019
github.com/ysbaddaden/siphash.cr
SipHash is a family of pseudorandom functions (a.k.a. keyed hash functions) optimized for speed on short messages. Target applications include network traffic authentication and defense against hash-flooding DoS attacks. SipHash is secure, fast, and simple (for real): - SipHash is simpler and faster than previous cryptographic algorithms (e.g. MACs based on universal hashing) - SipHash is competitive in performance with insecure non-cryptographic algorithms (e.g. MurmurHash)
Nothing has been indexed for 1.0.0 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
siphash:
github: ysbaddaden/siphash.cr
version: ~> 1.0.0Then run:
shards installshard.yml
No shard.yml has been indexed for 1.0.0. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
# SipHash
Crystal implementation of SipHash and HalfSipHash, a family of pseudorandom
functions optimized for short inputs.
See <https://131002.net/siphash/> for more information on the algorithms.
## SipHash
You may choose how many compression-rounds and finalization-rounds to execute.
Be wary about your use cases; `SipHash(2, 4)` has been verified to be
cryptographically secure for example, whereas `SipHash(1, 3)` is faster but not
verified, and should only be used when the result is never disclosed (e.g. for
table hashing).
```crystal
require "secure_random"
require "siphash"
key = uninitialized SipHash::Key
SecureRandom.random_bytes(key.to_slice)
# generate a 64-bit hash:
hash = SipHash(2, 4).siphash("some data", key)
# => UInt64
# generate a 128-bit hash:
hash = Bytes.new(16)
SipHash(2, 4).siphash("some data", hash, key)
```
You may alternatively hash a streaming input as you read it. This implies a
slight performance hit, and may only generate 64-bit hashes. This is still
useful when you don't know the complete input beforehand, or the input is
scaterred from different places.
```crystal
require "secure_random"
require "siphash/siphash64"
key = uninitialized SipHash64::Key
SecureRandom.random_bytes(key.to_slice)
hasher = SipHash64(2, 4).new(key)
hasher.update("some data")
hash = hasher.final # => UInt64
```
### HalfSipHash
An alternative `SipHash` pseudorandom function that uses a 64-bit key and
generates 32-bit or 64-bit hashes, meant for 32-bit platforms. On 64-bit
platform we advise to use `SipHash` instead.
While `SipHash(2, 4)` has been analyzed and verified to be cryptographically
secure, `HalfSipHash` has not, and isn't expected to be. Results from the
hasher should never be disclosed (e.g. use for table hashing on 32-bit).
```crystal
require "secure_random"
require "siphash/halfsiphash"
key = uninitialized HalfSipHash::Key
SecureRandom.random_bytes(key.to_slice)
# generate a 32-bit hash:
hash = HalfSipHash(2, 4).siphash("some data", key)
# => UInt32
# generate a 64-bit hash:
hash = Bytes.new(8)
HalfSipHash(2, 4).siphash("some data", hash, key)
```
A streaming version is also available, limited to 32-bit hashes:
```crystal
require "secure_random"
require "siphash/halfsiphash32"
key = uninitialized HalfSipHash32::Key
SecureRandom.random_bytes(key.to_slice)
hasher = HalfSipHash32(2, 4).new(key)
hasher.update("some data")
hash = hasher.final # => UInt32
```
## License
Distributed under the Apache 2.0 license.
## Credits
Created by:
- Jean-Philippe Aumasson
- Daniel J. Bernstein
Ported by:
- Julien Portalier
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
1.0.0- Tagged
- Feb 4, 2019
- Commit
ad5c3acb969f- Indexed
- not yet
Dependents
Repository
github.com/ysbaddaden/siphash.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 14, 2026
- Synced
- Aug 13, 2026
- Versions
- 2