Crate ysc1

Source
Expand description

§YSC1 (Yeun’s Stream Cipher 1)

This crate provides a Rust implementation of the YSC1 stream cipher.

The design is based on the “Amaryllis-1024” specification, which utilizes a (2x2) generalized Lai-Massey structure. This structure offers robust security properties and efficient performance across various platforms.

§Features

  • Two Security Levels:
    • Ysc1_512: 512-bit key and 512-bit nonce.
    • Ysc1_1024: 1024-bit key and 512-bit nonce.
  • Multiple Backends:
    • A platform-agnostic scalar (soft) backend.
    • A portable SIMD backend using std::simd for accelerated performance on modern CPUs (requires Nightly Rust).
  • cipher Crate Integration: Implements the traits from the cipher crate for a familiar and consistent API.

§Usage

Basic encryption and decryption using the cipher crate traits:

use ysc1::cipher::{KeyIvInit, StreamCipher};
use ysc1::{Ysc1_512Cipher, Ysc1Variant}; // Use Ysc1_1024_Cipher for the 1024-bit version

// Create a new cipher instance with a key and nonce.
let key = [0x42; 64];
let nonce = [0x24; 64];
let mut cipher = Ysc1_512Cipher::new(&key.into(), &nonce.into());

let mut buffer = [1, 2, 3, 4, 5];

// Apply the keystream to the buffer to encrypt it.
cipher.apply_keystream(&mut buffer);
assert_ne!(buffer, [1, 2, 3, 4, 5]);

// Applying the same keystream again decrypts the data.
let mut cipher = Ysc1_512Cipher::new(&key.into(), &nonce.into());
cipher.apply_keystream(&mut buffer);
assert_eq!(buffer, [1, 2, 3, 4, 5]);

Re-exports§

pub use cipher;

Structs§

Ysc1_512
YSC1 variant with a 512-bit key and 512-bit nonce.
Ysc1_1024
YSC1 variant with a 1024-bit key and 512-bit nonce.

Traits§

Ysc1Variant
A trait to define the security parameters for a YSC1 variant.

Type Aliases§

Ysc1_512Cipher
Ysc1_1024Cipher