SPARX block ciphers implementations for Rust
SPARX is a family of lightweight block ciphers allowing small processors to securely encrypt information for a fraction of the cost a standard algorithm would require.
Due to the use of ARX operations, these block ciphers are inherently more secure against side-channel attacks than an S-Box-based cipher such as AES.
Furthermore, unlike all other ARX-based, which share those advantages, SPARX ciphers are the only ARX-based block ciphers for which bounds on the probability of differential and linear trails can be proved.
To sum up, SPARX has:
- the lightweightness and side-channel resilience of an ARX-based cipher,
- the security argument of an S-Box-based cipher, and
- a flexible structure easing implementation trade-offs.
Usage
This crate implements SPARX-64/128 (64 bit block size, 128 bit key) in the sparx64
module and SPARX-128/128 (128 bit block size, 128 bit key) in the sparx128
module.
It doesn't require the Rust standard library.
Encryption of a single block
let key: = ;
let mut block: = ;
let ks = key_schedule_encrypt; // key schedule - can be reused with multiple blocks
encrypt_block;
// ...
decrypt_block;
Encryption of an arbitrary-sized buffer
This uses SPARX in counter mode as well as a 160-bit nonce in order to encrypt multiple blocks.
The internal counter size for this construction with SPARX-64/128 is 32 bits (no more than 32 GB should be encrypted with the same (key, nonce)
tuple) and 48 bits with SPARX-128/128 (allowing up to 4 PB to be encrypted with the same (key, nonce)
tuple).
The nonce is large enough to be randomly chosen; the probably of a collision to occur will be negligible.
Note that this construction does not add any authentication tags to the message.
let nonce: = ;
let key: = ;
let input = b"The quick brown fox jumps over the lazy dog";
let mut buf = input.to_vec;
encrypt_ctr;
// ...
decrypt_ctr;
References
- Design Strategies for ARX with Provable Bounds: SPARX and LAX (Daniel Dinu, Léo Perrin, Aleksei Udovenko, Vesselin Velichkov, Johann Großschädl, Alex Biryukov).