lib-q-sha3
NIST-aligned SHA-3 (FIPS 202), SHAKE, cSHAKE (SP 800-185), and TurboSHAKE (12-round Keccak as in RFC 9861 KangarooTwelve) for lib-Q. Pre–FIPS raw Keccak fixed digests (Keccak224 … Keccak512, Keccak256Full) are in the separate crate lib-q-keccak-digest (see ADR 001).
- Repository: https://github.com/Enkom-Tech/libQ
- API reference: https://docs.rs/lib-q-sha3
- Related crates:
lib-q-keccak(Keccak-ppermutation),lib-q-k12(KangarooTwelve),lib-q-keccak-digest(raw Keccak / non–FIPS-202 digests)
Algorithms
| Family | Types (crate root) | Normative reference |
|---|---|---|
| SHA-3 (224–512) | Sha3_224 … Sha3_512 |
FIPS 202 |
| SHAKE XOF | Shake128, Shake256 + readers |
FIPS 202 |
| cSHAKE XOF | CShake128, CShake256 + readers |
SP 800-185 |
| TurboSHAKE XOF | TurboShake128<DS>, TurboShake256<DS> (domain byte DS) |
IRTF / RFC 9861 (K12); collision strength in type impls |
| Raw Keccak (not this crate) | Keccak224 … / Keccak256Full |
See lib-q-keccak-digest (pre-FIPS padding; not interoperable with SHA-3) |
Which traits to use
- Fixed-length digest (
SHA3-*): implementDigest—update,finalizeinto a fixedOutput. - XOFs (
SHAKE,cSHAKE,TurboSHAKE): do not useDigest. UseUpdate,ExtendableOutput(orExtendableOutputResetwhere implemented), andXofReader. These traits are re-exported at the crate root (use lib_q_sha3::{Update, ExtendableOutput, XofReader}). If you also importDigestin the same module, qualifyDigest::updateorUpdate::updateto avoid method-name ambiguity. - cSHAKE customization only (NIST “S” string, empty function name):
CustomizedInit::new_customizedor theCShake*constructors.
Digest is not implemented for XOFs by design (the digest crate splits fixed vs extendable output APIs).
Prelude
This crate does not provide a prelude module. Imports are kept explicit so security reviews can see exactly which algorithms and traits are in scope. Use the re-exports documented below or use lib_q_sha3::digest::{...} for additional digest traits.
Feature flags
| Feature | Effect |
|---|---|
alloc (default) |
Enables digest/alloc (e.g. finalize_boxed on XOFs where applicable). |
oid (default) |
OID support for fixed-output types where defined. |
zeroize |
Zeroizes dropped sponge state for supported types (see digest + this crate’s ZeroizeOnDrop impls). |
asm |
ARMv8 Keccak acceleration via lib-q-keccak (not all targets). |
no_std: supported with default-features = false; you may need to disable alloc for the leanest build.
Security
- Output length (XOF): security depends on how many bytes you read; use enough bytes for your collision and preimage profile (see FIPS 202 / SP 800-185 and
CollisionResistanceon each type in rustdoc). - cSHAKE: use distinct function-name and/or customization strings for distinct protocols: both empty degrades to SHAKE (SP 800-185).
- TurboSHAKE: the const generic
DS(domain separator,0x01–0x7F) must differ across independent uses to avoid cross-protocol output collisions (see RFC 9861 / Turbot documentation). - SHA3-256 vs SHA-256:
Sha3_256andsha3_256are FIPS 202 SHA3-256 (Keccak sponge with SHA-3 padding). They are not FIPS 180-4 SHA-256 (Merkle–Damgård); outputs and wire formats differ. - Keccak vs SHA-3: use
lib-q-keccak-digestfor pre-FIPSKeccak256types; they are different fromSha3_256(different padding). - Implementation status: the code targets correct sponge semantics per the referenced standards. Constant-time or side-channel guarantees are not claimed here unless supported by your platform and analysis.
- Architecture: whether to split non–FIPS-202 Keccak surfaces is recorded in docs/adr/001-keccak-nonfips-surface.md.
Examples
SHA3-256 (Digest)
use hex;
use ;
let mut hasher = new;
hasher.update;
let hash = hasher.finalize;
assert_eq!;
One-shot SHA3-256
For a single input slice, sha3_256 hashes in one call. This is SHA3-256 (FIPS 202); it is not SHA-256 (FIPS 180). Prefer Sha3_256 with Digest when you need incremental updates or state serialization.
use hex;
use sha3_256;
let digest = sha3_256;
assert_eq!;
SHAKE128 (XOF)
use hex;
use ;
let mut hasher = default;
hasher.update;
let mut reader = hasher.finalize_xof;
let mut buf = ;
reader.read;
assert_eq!;
cSHAKE256 with customization
use ;
let mut h = new_customized;
h.update;
let mut out = ;
h.finalize_xof.read;
TurboSHAKE128 with domain byte (RFC 9861 style)
use ;
const D: u8 = 0x07; // distinct per protocol; see RFC 9861
let mut h = default;
h.update;
let mut out = ;
h.finalize_xof.read;
License
Licensed under Apache License, Version 2.0; see the workspace LICENSE file.