Rust Cryptographic Primitives
This repository contains a collection of cryptographic primitives implemented in Rust. The goal is to provide a comprehensive set of cryptographic primitives that are easy to use and hard to misuse.
This crate was done as a personal project to learn Rust and cryptography, implementing some of the algorithms I learned in the "Secure and Dependable Systems" course at my university. The code is open source and I am happy to receive contributions and feedback. Feel free to open an issue or a pull request on this repository.
If this crate is useful to you, please consider giving it a star on GitHub :)
Features
The crate currently provides the following cryptographic primitives, with an encryption and decryption function for each:
- Rail Fence Cipher
- Route Cipher
- Feistel Network
- Substitution-Permutation Network (SPN)
- Advanced Encryption Standard (AES)
The following cryptographic primitives are planned to be implemented in the future:
- Electronic Codebook (ECB) mode
- Cipher Block Chaining (CBC) mode
- Counter (CTR) mode
- Output Feedback (OFB) mode
- Rivest-Shamir-Adleman (RSA) algorithm
The helpers module provides the following helper functions for cryptographic algorithms:
rotl8initialize_aes_sboxpermutefeistel_round_functionkdfgmix_columngmix_column_inv
The constants module provides some useful constants for cryptographic algorithms, such as:
- and example
S-Box - an example
P-Box MIX_COLUMNS_LOOKUP_2,MIX_COLUMNS_LOOKUP_3,MIX_COLUMNS_LOOKUP_9,MIX_COLUMNS_LOOKUP_11,MIX_COLUMNS_LOOKUP_13,MIX_COLUMNS_LOOKUP_14lookup tables for the AES MixColumns operation
For any suggestions or requests, feel free to open an issue on this repository.
Usage
Add this to your Cargo.toml:
[]
= "0.1.0"
You can also use cargo to add the dependency to your Cargo.toml:
Then, simply import the crate and use the cryptographic primitives:
use *;
Example
Here is an example of using the sub_per_box_encrypt and sub_per_box_decrypt functions to encrypt and decrypt a message using the substitution-permutation network (SPN) algorithm.
use ;
let plaintext = b"Hello, world!";
// key = 15, rounds = 3
let ciphertext = sub_per_box_encrypt.unwrap;
let decrypted = sub_per_box_decrypt.unwrap;
assert_eq!;
License
This project is licensed under the MIT license.