mirror of
https://github.com/logos-storage/nim-goldilocks-hash.git
synced 2026-01-03 06:03:05 +00:00
Nim/C implementation of Poseidon2 over the Goldilocks field
Experimental implementation of the Poseidon2 cryptographic hash function,
specialized to the Goldilocks field p=2^64-2^32+1 and t=12.
Uses a C implementation internally.
Installation
Use the Nimble package manager to add poseidon2-goldilocks to an existing
project. Add the following to its .nimble file:
requires "poseidon2-goldilocks >= 0.0.1 & < 0.0.1"
Usage
Hashing bytes into a field element with the sponge construction:
import poseidon2_goldilocks
let input = [1'u8, 2'u8, 3'u8] # some bytes that you want to hash
let digest: F = Sponge.digest(input) # a field element
Converting a hash digest (4 field elements) into bytes:
let output: array[32, byte] = digest.toBytes
Combining field elements, useful for constructing a binary Merkle tree:
let left = Sponge.digest([1'u8, 2'u8, 3'u8])
let right = Sponge.digest([4'u8, 5'u8, 6'u8])
let combination = compress(left, right)
Description
Languages
Nim
92.2%
Haskell
4.4%
C
2.2%
C++
0.7%
POV-Ray SDL
0.5%