#openssl #password #key #salt #derive #evp-bytes-to-key

evpkdf

Rust implementation of OpenSSL EVP_bytesToKey function

3 unstable releases

0.2.0 Mar 19, 2023
0.1.1 Oct 7, 2021
0.1.0 Mar 1, 2020

#1416 in Cryptography

Download history 194/week @ 2023-12-12 209/week @ 2023-12-19 433/week @ 2023-12-26 415/week @ 2024-01-02 162/week @ 2024-01-09 246/week @ 2024-01-16 307/week @ 2024-01-23 95/week @ 2024-01-30 85/week @ 2024-02-06 170/week @ 2024-02-13 170/week @ 2024-02-20 117/week @ 2024-02-27 87/week @ 2024-03-05 133/week @ 2024-03-12 100/week @ 2024-03-19 236/week @ 2024-03-26

563 downloads per month
Used in 9 crates (2 directly)

MIT license

7KB

evpkdf

Rust implementation of OpenSSL EVP_bytesToKey function.

evpkdf derives key from the given password and salt.

Notice that this approach is too weak for modern standard now. Newer applications should choice a more modern algorithm like bcrypt, pbkdf2 or scrypt.

Basic Usage

use evpkdf::evpkdf;
use hex_literal::hex;
use md5::Md5;   // from md-5 crate
use sha1::Sha1; // from sha-1 crate

let mut output = [];

evpkdf::<Md5>(b"password", b"saltsalt", 1000, &mut output);

assert_eq!(output, []);

let mut output = [0; 128 / 8];

evpkdf::<Md5>(b"password", b"saltsalt", 1000, &mut output);

assert_eq!(output, hex!("8006de5d2a5d15f9bbdb8f40196d5af1"));

let mut output = [0; 128 / 8];

evpkdf::<Sha1>(b"password", b"saltsalt", 1000, &mut output);

assert_eq!(output, hex!("f8833429b112582447bc66f433497f75"));

Compatible with crypto-js

Below sinppet generates the same result as CryptoJS.kdf.OpenSSL.execute('password', 256 / 32, 128 / 32, 'saltsalt').

use evpkdf::evpkdf;
use hex_literal::hex;
use md5::Md5;   // from md-5 crate

const KEY_SIZE: usize = 256;
const IV_SIZE: usize = 128;

let mut output = [0; (KEY_SIZE + IV_SIZE) / 8];

evpkdf::<Md5>(b"password", b"saltsalt", 1, &mut output);

let (key, iv) = output.split_at(KEY_SIZE / 8);

assert_eq!(
    key,
    hex!("fdbdf3419fff98bdb0241390f62a9db35f4aba29d77566377997314ebfc709f2")
);

assert_eq!(
    iv,
    hex!("0b5ca7b1081f94b1ac12e3c8ba87d05a")
);

License

MIT

Dependencies

~325KB