brioche/hash

Hash in the hash module are not cryptographically secure. You can use them for non-important data, such a identity hash for files or data, but you should never use them to store sensible informations. To store sensible informations, Brioche exposes two additional modules: brioche/hash/password and brioche/hash/crypto_hasher. Both modules are cryptographically secure, and are made to work with passwords, or with any data.

As a matter of convenience, hash exposes an entrypoint for hashing, and is using Wyhash, to provide fast and robust hashing. However, multiple algorithms can be used, according to your needs. Every function exposes two way to hash data: hashing strings or hashing binaries. Hashing strings is a commodity, while hashing binaries should be your privileged way to perform hashing.

Every functions working on 32 bits will return an Int, while every functions working with 64 bits will return a BigInt. This is due to a limitation of JavaScript, that can not handle 64 bits as max integer. bigi is used to manipulate easily BigInt in JavaScript and Brioche.

import brioche/hash

hash.hash("my-data")
hash.hash_bytes(<<"my-bit-array":utf8>>)
hash.wyhash("my-data")
hash.crc32("my-data")
hash.city_hash64("my-data")

Bun Documentation

Functions

pub fn adler32(data: String) -> Int
pub fn adler32_bytes(data: BitArray) -> Int
pub fn city_hash32(data: String) -> Int
pub fn city_hash32_bytes(data: BitArray) -> Int
pub fn city_hash64(data: String) -> BigInt
pub fn city_hash64_bytes(data: BitArray) -> BigInt
pub fn crc32(data: String) -> Int
pub fn crc32_bytes(data: BitArray) -> Int
pub fn hash(data: String) -> BigInt

Hash a string using Wyhash.

This is not a cryptographic hash function.

pub fn hash_bytes(data: BitArray) -> BigInt

Hash a binary using Wyhash.

This is not a cryptographic hash function.

pub fn murmur32v2(data: String) -> Int
pub fn murmur32v2_bytes(data: BitArray) -> Int
pub fn murmur32v3(data: String) -> Int
pub fn murmur32v3_bytes(data: BitArray) -> Int
pub fn murmur64v2(data: String) -> BigInt
pub fn murmur64v2_bytes(data: BitArray) -> BigInt
pub fn wyhash(data: String) -> BigInt
pub fn wyhash_bytes(data: BitArray) -> BigInt
pub fn xx_hash3(data: String) -> BigInt
pub fn xx_hash32(data: String) -> Int
pub fn xx_hash32_bytes(data: BitArray) -> Int
pub fn xx_hash3_bytes(data: BitArray) -> BigInt
pub fn xx_hash64(data: String) -> BigInt
pub fn xx_hash64_bytes(data: BitArray) -> BigInt
Search Document