secured-cipher 0.1.0

Pure Rust implementation of the ChaCha cipher family
Documentation

Secured-Cipher Library

This library, secured-cipher, provides an implementation of the ChaCha20 encryption algorithm, along with a common cryptographic interface defined by the Cipher trait. The library is structured to offer both low-level and high-level cryptographic functionalities.

Overview

  • ChaCha20: A struct that provides a high-level interface for the ChaCha20 stream cipher algorithm. It offers methods for encryption and decryption operations, simplifying the use of the underlying ChaChaStream.
  • ChaChaStream: A struct that handles the core state and operations of the ChaCha20 cipher. It is used internally by ChaCha20 but can also be used directly for lower-level control.
  • Cipher: A trait that defines a standard interface for cryptographic operations, specifically focusing on encryption and decryption methods.
  • Type aliases (Slice, Key, Nonce, Bytes): These simplify the usage of common cryptographic data types such as keys, nonces, and byte slices.

Usage

Encrypting Data with ChaCha20

use secured_cipher::{chacha20::ChaCha20, Cipher, Slice};

let key: [u8; 32] = [0; 32]; // Replace with your key
let nonce: [u8; 8] = [0; 8]; // Replace with your nonce
let data: &[u8] = b"Your data here"; // Data to be encrypted

let mut cipher = ChaCha20::new(key, nonce);
let encrypted_data = cipher.encrypt(data);
println!("Encrypted data: {:?}", encrypted_data);

Decrypting Data with ChaCha20

use secured_cipher::{chacha20::ChaCha20, Cipher, Slice};

let key: [u8; 32] = [0; 32]; // Replace with your key
let nonce: [u8; 8] = [0; 8]; // Replace with your nonce
let encrypted_data: &[u8] = &[0x1, 0x2, 0x3, 0x4]; // Replace with your encrypted data

let mut cipher = ChaCha20::new(key, nonce);
let decrypted_data = cipher.decrypt(encrypted_data);
println!("Decrypted data: {:?}", decrypted_data);

Modules

  • core: Contains core functionalities and algorithmic implementations.
  • stream: Provides the ChaChaStream struct and related functions for internal stream cipher operations.

This library aims to provide an easy-to-use and efficient implementation of the ChaCha20 cipher, suitable for various cryptographic needs. Whether you need high-level interfaces with ChaCha20 or low-level control with ChaChaStream, secured-cipher is equipped to meet your cryptographic requirements.