PoC SWIFFT
- Clean-room Rust port of the n=64, m=16, p=257 parameters.
- Requires
stdfor now (nono_stdsupport). - Optional feature flags:
parallel: enable Rayon-backed parallel column transforms and reductions.simd: reserved for future work.bench: reserved (benchmarks run without extra feature flags).
Use cargo, the standard Rust build tool, to build the library:
git clone https://github.com/cyberbono3/swifft.git
cd swifft
cargo build --releaseAdd the crate to your Cargo.toml (enable the parallel feature only if you want Rayon-backed parallelism):
[dependencies]
swifft = { git = "https://github.com/cyberbono3/swifft" }Then import the types:
use swifft::{Block, Key, State, BLOCK_LEN, KEY_LEN};
// Keys are 1024 bytes interpreted modulo 257 (0..=256).
let key_bytes = [0u8; KEY_LEN];
let key = Key::from(key_bytes);
// State is a 72-byte chaining value; initialize however you like.
let mut state = State::default();
// Blocks are exactly 56 bytes; you can build them from a byte array or slice.
let block_bytes = [0u8; BLOCK_LEN];
let block = Block::from(block_bytes);
// Compress in-place, writing the new state back into `state`.
state.compress(&key, &block);There is a runnable version of this snippet in examples/naive.rs:
cargo run --example naiveIt prints the resulting 72-byte SWIFFT digest in hex.
SWIFFT digest (hex): b4064d836d08c690362a48021db5960912bbf24d1e5f2239b19aebb459bbc974e0355afa89bc40ae93ed0064886c33bd3c40d36f3d6bb3eb9dfddb37c39f4d2b0000000000040000
There is a runnable version of this snippet in examples/naive.rs:
cargo run --example naiveIt prints the resulting 72-byte SWIFFT digest in hex.
- Run with
--features parallelto enable multi-core compression (for example,cargo run --example naive --features parallel).
Criterion benchmarks live in benches/compress.rs.
- Build without running:
CARGO_HUSKY_SKIP=1 cargo bench --no-run - Run (scalar backend):
CARGO_HUSKY_SKIP=1 cargo bench - Run with parallel backend:
CARGO_HUSKY_SKIP=1 cargo bench --features parallel - To avoid husky hook errors, set
CARGO_HUSKY_SKIP=1as above. - Recent results (Apple Silicon laptop, local run for reference):
- Scalar:
compress_single_block≈ 34.8 µs;compress_batch/16≈ 702 µs. - Parallel feature:
compress_single_block≈ 64.1 µs;compress_batch/16≈ 1.06 ms (threading overhead dominates at this size).
- Scalar:
src/lib.rs: crate entry, constants, and public re-exports (Block,Key,State).src/state.rs: byte newtypes and the SWIFFT compression implementation.src/math.rs: power tables, twiddle factors, and the transform used by compression.src/field_element.rs: modular arithmetic overF_257used throughout the math layer.src/test_support.rs: naive reference helpers shared by tests to keep them DRY.
Keyentries are interpreted modulo 257 (range 0..=256).Blockis exactly 56 bytes;Stateis exactly 72 bytes (low bytes then packed high bits).- The implementation is
#![forbid(unsafe_code)]and keeps arithmetic inu16/u32to avoid panics. - Output compatibility is tested against a shared naive reference model in-unit tests; add official vectors once available.