Categorygithub.com/spectre-project/go-muhash
modulepackage
0.0.1
Repository: https://github.com/spectre-project/go-muhash.git
Documentation: pkg.go.dev

# README

go-muhash

Warning: This is pre-alpha software. The code has not been audited and/or reviewed by anyone other than the author.

ISC License

go-muhash implements a rolling hash function using a multiplicative hash. It is based on a multiplicative group over Z=2^3072-1103717 using multiplication and division for adding/removing elements from the hash function. The current code is heavily based on: Bitcoin MuHash (written by Pieter Wuille, MIT licensed) but uses BLAKE2B as the hash function and Go's standard library big.Int for fast modular inversions (GCD).

MuHash is the public interface implementing Add/Remove elements functions, and a Finalize function to return a final hash.

  • uint3072.go is a go implementation of the multiplicative group.
  • num3072.c/h is a C implementation of the multiplicative group.
  • num3072.go is go bindings for the C imlementation.

Ideally we will add Go Assembly implementations using SSE2/SSE4.1/AVX and will choose the correct one in runtime, this should also remove the cgo overhead.

Tests

  • ./build_and_test.sh will run all the tests and checks in this library.

  • ./fuzz.sh will run the fuzzer and put new corpus in the corpus directory. By default, it will use go-fuzz. But if you run with LIBFUZZER=1 ./fuzz.sh it will run it with libfuzzer. All the current corpus are checked in the unit test in fuzz_corpuses_test.go (requires -tags=gofuzz).

# Functions

DeserializeMuHash will deserialize the MuHash that `Serialize()` serialized.
NewMuHash return an empty initialized set.

# Constants

HashSize of array used to store hashes.
SerializedMuHashSize defines the length in bytes of SerializedMuHash.

# Variables

EmptyMuHashHash is the hash of `NewMuHash().Finalize()`.

# Structs

MuHash is a type used to create a Multiplicative Hash which is a rolling(homomorphic) hash that you can add and remove elements from and receive the same resulting hash as-if you never hashed them.

# Type aliases

Hash is a type encapsulating the result of hashing some unknown sized data.
SerializedMuHash is a is a byte array representing the storage representation of a MuHash.