Cryptographic Functions
SHA-256
#include <ligetron/sha2.h>
// Compute SHA-256 hash
// Returns number of bytes written (32)
uint32_t ligetron_sha2_256(unsigned char* out,
const unsigned char* in,
uint32_t len);
Rust Example:
use ligetron::sha2::*;
let input = b"Hello, world!";
let hash = sha256(input);
Poseidon Hash
#include <ligetron/poseidon.h>
using namespace ligetron;
// Poseidon with t=5 (4 inputs -> 1 output)
poseidon_context<poseidon_permx5_254bit_5> ctx;
// Initialize constants
poseidon_context<poseidon_permx5_254bit_5>::global_init();
// Reset state
ctx.reset();
// Absorb inputs
bn254fr_class input1, input2;
ctx.digest_update(input1);
ctx.digest_update(input2);
// Finalize and get hash
ctx.digest_final();
bn254fr_class hash_output = ctx.state[0];
Poseidon Variants:
poseidon_permx5_254bit_3: t=3 (2 inputs)poseidon_permx5_254bit_5: t=5 (4 inputs)
Rust Example:
use ligetron::poseidon::*;
// Poseidon hash (2 inputs -> 1 output)
let hash = poseidon2to1(&input1, &input2);
// Poseidon hash (4 inputs -> 1 output)
let hash = poseidon4to1(&input1, &input2, &input3, &input4);
Poseidon2 Hash
#include <ligetron/poseidon2.h>
// Similar to Poseidon, but optimized for t=2
Rust Example:
use ligetron::poseidon2::*;
// Poseidon2 for byte arrays
let input = b"Hello, world!";
let hash = poseidon2_bytes(input);
// Batch hashing
let hashes = poseidon2_bytes_batch(&inputs);
EdDSA Signatures
#include <ligetron/eddsa.h>
#include <ligetron/babyjubjub.h>
// Verify EdDSA signature
bool verify_eddsa(const uint8_t* message, size_t msg_len,
const uint8_t* signature,
const uint8_t* public_key);
Rust Example:
use ligetron::eddsa::*;
use ligetron::babyjubjub::*;
// Verify signature
let is_valid = eddsa_verify(&message, &signature, &public_key);
assert_one(is_valid);
Baby Jubjub Curve
The Baby Jubjub curve is a twisted Edwards curve optimized for zero-knowledge circuits:
#include <ligetron/babyjubjub.h>
// Point operations, scalar multiplication, etc.