Crate cryptographic_primitives

Source
Expand description

§cryptographic_primitives

cryptographic_primitives is a Rust crate that provides implementations of various cryptographic algorithms and ciphers. It is designed to offer flexible and easy-to-use building blocks for cryptography, suitable for both educational purposes and practical cryptographic operations.

§Supported Algorithms

This crate includes implementations for several classic and modern cryptographic algorithms, including:

  • Rail Fence Cipher: A transposition cipher where the plaintext is written in a zigzag pattern along multiple rails.
  • Route Cipher: Another transposition cipher that writes the plaintext into a grid and then reads it in a specific route pattern.
  • Feistel Cipher: A symmetric structure used in many block ciphers like DES. This crate allows for a flexible number of rounds and key choices.
  • Substitution-Permutation Network (SPN): A structure used in modern block ciphers like AES, combining substitution and permutation steps for encryption.
  • AES-128: A widely used symmetric encryption standard based on a specific substitution-permutation network.

§Modules

  • constants: Contains predefined constants like S-boxes and permutation tables used in the encryption algorithms.
  • helpers: Provides utility functions and primitives to support the cryptographic algorithms, such as byte manipulation, XOR operations, and S-box initialization.
  • block_ciphers: Implements block cipher modes of operation (e.g., ECB, CBC, OFB, CTR) and integrates with specific encryption/decryption functions.

§Example Usage

To use the crate, import the desired function and apply it to your data. For example, to encrypt a byte array using the AES-128 cipher in ECB mode:

use cryptographic_primitives::aes_128_encrypt;
use cryptographic_primitives::block_ciphers::ecb_encrypt;
 
let plaintext = b"Hello, world!";
let key = 0x2b7e151628aed2a6abf7158809cf4f3c;
let encrypted = ecb_encrypt(plaintext, key, aes_128_encrypt).unwrap();

§Errors

Functions in this crate generally return a Result<T, &'static str> to handle potential errors, such as invalid inputs, key lengths, or padding issues.

§License

This crate is provided under the MIT License, allowing for both personal and commercial use.

Modules§

block_ciphers
Block Ciphers Module
constants
Constants Module
helpers
Helpers Module

Functions§

aes_128_decrypt
Decrypts an array of bytes using the AES-128 cipher
aes_128_encrypt
Encrypts an array of bytes using the AES-128 cipher
feistel_network_decrypt
Decrypts an array of bytes using the feistel cipher
feistel_network_encrypt
Encrypts an array of bytes using the feistel cipher
rail_fence_cipher_decrypt
Decrypts an array of bytes using the rail fence cipher.
rail_fence_cipher_encrypt
Encrypts an array of bytes using the rail fence cipher.
route_cipher_decrypt
Decrypts an array of bytes using the route cipher.
route_cipher_encrypt
Encrypts an array of bytes using the route cipher.
sub_per_box_decrypt
Decrypts an array of bytes using the substitution-permutation network
sub_per_box_encrypt
Encrypts an array of bytes using the substitution-permutation network