Skip to main content

Crate starkom_poseidon

Crate starkom_poseidon 

Source
Expand description

§Poseidon

CI crates.io license

§Overview

This is Starkom’s implementation of the Poseidon algebraic hash.

Note that this crate uses version 1 of the permutation. For version 2 see the starkom-poseidon2 crate.

The implementation is generic and works on any prime field.

Configurations for the BLS12-381, Goldilocks, and BlueSky prime fields are provided; the BLS12-381 and BlueSky configurations support T=3 and T=4, while the Goldilocks configurations support T=12 and T=16.

[!NOTE] All predefined configurations are gated behind feature flags to avoid including all constants in all builds. The currently defined feature flags are bls12_381, goldilocks, and bluesky, all disabled by default.

§Usage

The following example functions instantiate Poseidon with T=3 and T=4 respectively, squeezing a single element from the output. Both use a single element for capacity.

use starkom_bluesky::Scalar;
use starkom_poseidon;

fn hash_t3(inputs: impl IntoIterator<Item = Scalar>) -> Scalar {
    starkom_poseidon::hash::<starkom_poseidon::bluesky::BlueSkyConfig3, Scalar, 3, 2, 1>(inputs)[0]
}

fn hash_t4(inputs: impl IntoIterator<Item = Scalar>) -> Scalar {
    starkom_poseidon::hash::<starkom_poseidon::bluesky::BlueSkyConfig4, Scalar, 4, 3, 1>(inputs)[0]
}

Re-exports§

pub use bluesky::*;
pub use bls12_381::*;
pub use goldilocks::*;

Modules§

bls12_381
bluesky
goldilocks

Structs§

Decryptor
Decrypts an arbitrary number of field elements in batches of R using the Poseidon permutation with state size T.
Encryptor
Encrypts an arbitrary number of field elements in batches of R using the Poseidon permutation with state size T.

Traits§

Config
Poseidon instance configuration trait.

Functions§

hash
Generic Poseidon implementation over the prime field F with state size T, absoprtion rate R, and capacity C.
hash0
Convenience function for hashing with Poseidon and squeezing the first element.
permutation
Runs the Poseidon permutation.
sbox5
Standard x^5 S-box.