Giter VIP home page Giter VIP logo

block-ciphers's Introduction

RustCrypto: block ciphers Build Status

Collection of block ciphers and block modes written in pure Rust.

Warnings

Currently only AES crates provide constant-time implementations. If you do not really know what you are doing it's generally recommended not to use other cipher implementations in this repository.

Additionally crates in this repository have not yet received any formal cryptographic and security reviews.

USE AT YOUR OWN RISK.

Supported algorithms

Name Alt name Crate name crates.io Docs
AES Rijndael aes

aesni

aes-soft
crates.io

crates.io

crates.io
Documentation

Documentation

Documentation
Blowfish blowfish crates.io Documentation
DES + 3DES DEA + 3DEA des crates.io Documentation
Kuznyechik GOST R 34.12-2015 kuznyechik crates.io Documentation
Magma GOST 28147-89 and GOST R 34.12-2015 magma crates.io Documentation
RC2 ARC2 rc2 crates.io Documentation
Twofish twofish crates.io Documentation

Minimum Rust version

All crates in this repository support Rust 1.22 or higher. (except aesni and aes crates, which require Rust 1.27) In future minimum supported Rust version can be changed, but it will be done with the minor version bump.

Usage

Block cipher crates provide only bare block cipher implementations. For most applications you will need to use some block cipher mode of operation which are generically implemented in the block-modes crate.

Lets use AES128-CBC with PKCS7 padding to show an example:

extern crate aes_soft as aes;
extern crate block_modes;

use block_modes::{BlockMode, BlockModeIv, Cbc};
use block_modes::block_padding::Pkcs7;
use aes::Aes128;

// create an alias for convinience
type Aes128Cbc = Cbc<Aes128, Pkcs7>;

let mut cipher = Aes128Cbc::new_varkey(key, iv).unwrap();
// buffer must have enough space for message+padding
let mut buffer = [0u8; 32];
// copy message to the buffer
buffer[..msg_len].copy_from_slice(msg);
let encrypted_msg = cipher.encrypt_pad(&mut buffer, msg_len).unwrap();

let mut cipher = Aes128Cbc::new_varkey(key, iv).unwrap();
let decrypted_msg = cipher.decrypt_pad(encrypted_data).unwrap();

Note that this example does not use any authentification which can lead to serious vulnarabilities! For Message Authentication Code implementations take a look at RustCrypto/MACs repository.

Some block modes (e.g. CTR, CFB) effectively transform block ciphers into stream ciphers. Such modes are published under separate crates in the RustCrypto/stream-ciphers repository.

License

All crates licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

block-ciphers's People

Contributors

alleysira avatar cheme avatar gsingh93 avatar luisbg avatar newpavlov avatar roblabla avatar trojan295 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.