This package is a Swift package manager wrapper for HighwayHash — a fast, stable, and dos-attack resistent hashing algorithm.
HighwayHash
is faster thanSipHash
(which backs Swift's Hashable implementation.)HighwayHash
is stable for a given seed value. Unlike Swift'sHashable
you can serializeHighwayHash
output to match values across sessions.- This package bundles the c++ implementation of
HighwayHash
and provides a simplified API to swift.- (No incremental hashing API is currently exposed. Open to code contributions.)
- This package is usable on
arm64
andx86_64
variants of macOS, iOS, and linux. - The bundled code, and this package, are Apache 2 licensed.
- The underlying library contains an implementation of SipHash. It is also re-exposed here.
HighwayHash
(and SipHash
) accept Data
or String
input and return a UInt64
hash.
import HighwayHash
// Choose a seed
let seed = Seed(a: 1, b: 0, c: 6, d: 6)
// Instantiate your hasher
let hasher = HighwayHash(seed: seed)
// Hash your data
let output = hasher.hash(data: input)
// Given a stable seed, observe a stable output value
XCTAssertEqual(output, UInt64(10_502_827_635_072_092_050))
// Note: the hasher instance is consumed and can't be reused.
// Reinstantiate with the same seed if desired.