Coder Social home page Coder Social logo

evpkdf's Introduction

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 argon2, 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

evpkdf's People

Contributors

enoughtea avatar poiscript avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

evpkdf's Issues

In the Readme, recommend Argon2 instead of PBKDF2

PBKDF2 has been identified as a not-great function for deriving keys from passwords a long time ago. 7 years ago, Argon2 won the password hashing competition, so by now it should be the first candidate on the table.

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.