pub fn hash(
    parameters: Parameters,
    endianness: Endianness,
    val: &[u8]
) -> Result<PoseidonHash, PoseidonSyscallError>
Expand description

Return a Poseidon hash for the given data with the given elliptic curve and endianness.

§Examples

use solana_program::poseidon::{hash, Endianness, Parameters};

let input = [1u8; 32];

let result = hash(Parameters::Bn254X5, Endianness::BigEndian, &input).unwrap();
assert_eq!(
    result.to_bytes(),
    [
        5, 191, 172, 229, 129, 238, 97, 119, 204, 25, 198, 197, 99, 99, 166, 136, 130, 241,
        30, 132, 7, 172, 99, 157, 185, 145, 224, 210, 127, 27, 117, 230
    ],
);

let hash = hash(Parameters::Bn254X5, Endianness::LittleEndian, &input).unwrap();
assert_eq!(
    hash.to_bytes(),
    [
        230, 117, 27, 127, 210, 224, 145, 185, 157, 99, 172, 7, 132, 30, 241, 130, 136,
        166, 99, 99, 197, 198, 25, 204, 119, 97, 238, 129, 229, 172, 191, 5
    ],
);