Skip to main content

Crate arcana

Crate arcana 

Source
Expand description

§arcana — classical cryptography for the krypteia workspace

Pure-Rust implementations of widely-used classical primitives — hash functions, symmetric ciphers, AEAD modes, RSA, ECDSA / ECDH, EdDSA, X25519, and X448 — sharing the same side-channel countermeasure toolkit (silentops) used by the post-quantum side of the workspace (quantica).

Zero external runtime dependencies (only std / alloc and the workspace-local silentops); constant-time on the data path.

§Algorithms

§Hash functions (hash)

AlgorithmOutputModule
SHA-1160 bhash::sha1::Sha1 (legacy)
SHA-224224 bhash::sha224::Sha224
SHA-256256 bhash::sha256::Sha256
SHA-384384 bhash::sha384::Sha384
SHA-512512 bhash::sha512::Sha512
SHA-512/224224 bhash::sha512_trunc::Sha512_224
SHA-512/256256 bhash::sha512_trunc::Sha512_256
SHA3-224224 bhash::sha3::Sha3_224
SHA3-256256 bhash::sha3::Sha3_256
SHA3-384384 bhash::sha3::Sha3_384
SHA3-512512 bhash::sha3::Sha3_512
SHAKE128XOFhash::sha3::Shake128
SHAKE256XOFhash::sha3::Shake256
cSHAKE128XOFhash::sha3::CShake128
cSHAKE256XOFhash::sha3::CShake256
BLAKE2b1-512 bhash::blake2::Blake2b
BLAKE2s1-256 bhash::blake2::Blake2s
RIPEMD-160160 bhash::ripemd160::Ripemd160 (legacy)

§Symmetric ciphers and modes (cipher)

AlgorithmModule
AES-128 / 192 / 256cipher::aes
DES, Triple-DES (EDE)cipher::des
ECB, CBC, CTR, GCM modescipher::modes
AES-CCM (RFC 3610) AEADcipher::ccm
AES-XTS (IEEE 1619) disk cryptocipher::xts
ChaCha20 (RFC 8439)cipher::chacha20
Poly1305 one-time MACcipher::poly1305
ChaCha20-Poly1305 AEADcipher::chacha20poly1305
XChaCha20-Poly1305 AEADcipher::xchacha20poly1305 (24-byte nonce)

In addition to these one-shot, function-oriented APIs, a stateful streaming Cipher object lives in cipher::ctx. It wraps the AES / DES / 3DES block ciphers with the ECB / CBC / CTR modes behind a uniform init / update / finalize cycle, with caller-provided output buffers (no allocation required) and configurable padding (None, Pkcs7, Iso9797M1, Iso9797M2, AnsiX923). AEAD modes intentionally stay function-oriented to avoid releasing unverified plaintext during streaming decryption.

§Message authentication codes (mac)

A streaming MAC object lives in mac::ctx, exposing a uniform init / update / sign | verify cycle across four families:

FamilyAlgorithmsStandard
HMACSHA-1, SHA-256, SHA-384, SHA-512, SHA3-256/384/512, RIPEMD-160RFC 2104, FIPS 198-1
CMACAES-128 / 192 / 256, Triple-DESNIST SP 800-38B, RFC 4493
KMACKMAC128, KMAC256FIPS SP 800-185
GMACAES-128 / 192 / 256NIST SP 800-38D

Three init variants distinguish families that need different inputs: init(key) (HMAC, CMAC, KMAC default), init_kmac(key, custom) (KMAC with explicit customization string), and init_with_nonce(key, nonce) (GMAC, 12-byte unique nonce). verify accepts truncated tags and runs in constant time. Poly1305 is intentionally not routed through Mac because it is a one-time MAC and would be unsafe behind an “init then reuse” object.

§RSA (rsa)

PaddingModule
PKCS#1 v1.5 encryption + signaturersa::pkcs1 (8 hash functions supported)
OAEP encryption (PKCS#1 v2.2)rsa::oaep
RSASSA-PSS signature (PKCS#1 v2.2)rsa::pss

§Elliptic curve cryptography (ecc)

ECDSA / ECDH / SEC1-compressed / signature DER are all unified behind a single ecc::curves::Curve trait, implemented by:

WrapperCurve
ecc::curves::P256NIST P-256
ecc::curves::P384NIST P-384
ecc::curves::P521NIST P-521
ecc::curves::Secp256k1secp256k1 (SECG)
ecc::curves::BrainpoolP256r1BSI / RFC 5639
ecc::curves::BrainpoolP384r1BSI / RFC 5639
ecc::curves::BrainpoolP512r1BSI / RFC 5639

Edwards / Montgomery curves live in standalone modules because their algebraic shape doesn’t fit the short-Weierstrass Curve trait:

AlgorithmModule
Ed25519, Ed25519ctx, Ed25519phecc::eddsa
X25519 ECDH (Curve25519)ecc::x25519
X448 ECDH (Curve448)ecc::x448

Ed448 is planned but not yet implemented.

§Cargo features

FeatureDefaultEffect
stdnoReserved for future no_std work (currently a no-op).
rust-crypto-traitsnoPulls in digest 0.10 / cipher 0.4 / signature 2.0 and activates the bridge module, which wraps every hash in a digest::Digest impl for ecosystem interop (HMAC, HKDF, PBKDF2, Argon2, …).

Default builds are zero-dependency (only the workspace-local silentops crate). The rust-crypto-traits feature is opt-in and pulls in definitions only (no crypto code).

§Quick start

// SHA-256 one-shot hash
use arcana::hash::sha256::Sha256;
use arcana::Hasher;
let digest = Sha256::hash(b"hello, arcana");
assert_eq!(digest.len(), 32);
// AES-128-GCM AEAD
use arcana::cipher::aes::Aes128;
use arcana::cipher::modes::Gcm;
use arcana::BlockCipher;

let key = [0x42u8; 16];
let nonce = [0u8; 12];
let cipher = Aes128::new(&key);
let (ct, tag) = Gcm::encrypt(&cipher, &nonce, b"aad", b"plaintext");
let pt = Gcm::decrypt(&cipher, &nonce, b"aad", &ct, &tag).unwrap();
assert_eq!(pt, b"plaintext");
// X25519 ECDH key exchange
use arcana::ecc::x25519::{x25519_derive_public, x25519_ecdh};
let alice_sk = [0x77u8; 32];
let bob_sk   = [0x88u8; 32];
let alice_pk = x25519_derive_public(&alice_sk);
let bob_pk   = x25519_derive_public(&bob_sk);
let shared_a = x25519_ecdh(&alice_sk, &bob_pk);
let shared_b = x25519_ecdh(&bob_sk,   &alice_pk);
assert_eq!(shared_a, shared_b);

§Examples

cargo run -p arcana --release --example hash_demo
cargo run -p arcana --release --example aes_demo
cargo run -p arcana --release --example rsa_demo
cargo run -p arcana --release --example ecdsa_demo
cargo run -p arcana --release --example eddsa_demo
cargo run -p arcana --release --example x25519_demo

§Side-channel guarantees

The full threat model and per-algorithm countermeasure roadmap lives in arcana/doc/sca/ (HTML rendered by ./gendoc.sh arcana). The roadmap items referenced here (T1-A, T1-C, T2-D …) are defined there. This section is a quick-reference summary; for evaluation evidence, refer to the annex.

§Always-on

DefenceScope
Constant-time tag comparisonAll AEAD decrypt, MAC verify, ECDSA verify (via silentops::ct_eq)
Constant-time field arithmeticECC (P-256, P-384, P-521, secp256k1, Brainpool), Ed25519, X25519, X448
CT Montgomery ladderecc::curve::scalar_mul_point — branch-free across all 7 short-Weierstrass curves
core::hint::black_box shieldingecc::field mask selects, to keep LLVM from recovering branches at opt-level >= 2
No secret-dependent branchesHash, symmetric, HMAC, CMAC, KMAC, GMAC
RFC 6979 deterministic nonceECDSA — eliminates nonce-reuse attacks (but see fault-attack note below)
silentops::ct_zeroize availableCaller can zeroize sensitive buffers explicitly

§Open vulnerabilities (evaluation gaps — track in roadmap)

PrimitiveIssueRoadmap item
AES S-boxTable-based lookup — cache-line leaks on CPUs with shared L1T1-A (fixsliced AES port from Adomnicai-Peyrin TCHES 2021/1)
RSA-CRT decryptBellcore single-fault → factorisation of NT1-C (Aumüller 2002, formally verified)
RSA bigintMontgomery_mul, cmp, pow_mod not formally CT-auditedT1-E
ECDSA / ECDHMinerva-class bit-length leak audit not yet completedT1-B
Ed25519 / ECDSA-RFC 6979Single-fault on deterministic signing → key recoveryT1-D (hedged signatures, CFRG draft)
HMAC-SHA-2Carry-based DPA breaks unmasked HMAC-SHA-2 in 30 K – 275 K tracesT2-D (first-order Boolean masking)
DES / 3DES S-boxesTable-based; legacy onlyunscoped — avoid on SCA-sensitive targets

§Not yet implemented

§Native API vs RustCrypto bridge

By default, this crate exposes its own trait hierarchy (Hasher, Xof, BlockCipher, …). Enable rust-crypto-traits to additionally activate the bridge module which implements digest::Digest for the hash functions. The two universes are intentionally separate so the native modules never depend on a specific external crate version.

Modules§

cipher
Symmetric ciphers: AES, DES, 3DES.
ecc
Elliptic curve cryptography: ECDSA, EdDSA.
encoding
Key serialization: DER, PEM, PKCS#1, PKCS#8, SEC1, SPKI. Key serialization: DER (ASN.1), PEM, PKCS#1, PKCS#8, SPKI, SEC1.
hash
Hash functions: SHA-1, SHA-2, SHA-3, RIPEMD-160.
mac
Message authentication codes (HMAC, CMAC, KMAC, GMAC). Message Authentication Codes (MACs).
rsa
RSA encryption and signatures. RSA encryption and signatures.

Traits§

BlockCipher
Trait for symmetric block ciphers operating on a fixed block size.
Hasher
Trait for hash functions (fixed-output).
PublicKeyEncryption
Trait for public-key encryption schemes.
SignatureScheme
Trait for digital signature schemes that produce fixed-shape keys and signatures (no per-call hash parameter).
Xof
Trait for extendable-output functions (XOF) such as SHAKE128 / SHAKE256.