Crate secured_cipher

source ·
Expand description

Secured-Cipher Library

secured-cipher is a Rust library offering an implementation of the ChaCha20 and XChaCha20 encryption algorithms. It provides both high-level and low-level cryptographic functionalities through a common interface.

Overview

The library includes the following key components:

  • core: A module containing essential ChaCha20 cryptographic functionalities.
  • ChaCha20: A struct for the ChaCha20 stream cipher algorithm.
  • Cipher: A struct that provides a common interface for cryptographic operations, focusing on encryption and decryption.
  • CipherMode: An enum to specify the mode of the cipher (only ChaCha20 for now).

Features

  • High-level interfaces for ChaCha20 and XChaCha20 ciphers.
  • Common Cipher interface for encryption and decryption operations.
  • Flexible usage with support for both raw and high-level cryptographic operations.

Usage

Basic Encryption and Decryption

This example demonstrates encrypting and decrypting data using the ChaCha20 cipher.

use secured_cipher::Cipher;

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

let mut cipher = Cipher::default();
cipher.init(&key, &nonce);

let encrypted_data = cipher.encrypt(data);
println!("Encrypted data: {:?}", encrypted_data);

let decrypted_data = cipher.decrypt(&encrypted_data);
println!("Decrypted data: {:?}", decrypted_data);

Modules

  • core: Core functionalities and algorithmic implementations.
  • stream: Internal stream cipher operations, including ChaChaStream.

Re-exports

Modules

Structs

  • The Cipher struct provides a common interface for cryptographic operations, specifically focusing on encryption and decryption.
  • Key holds a public key and a salt value. This struct is specifically designed for use in symmetric encryption, and is compatible with multiple encryption algorithms.

Enums

Functions

  • Generates a random byte array of a specified size.