Giter Site home page Giter Site logo

ohsayan / rcrypt Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 1.0 35 KB

rcrypt is a compact hashing and salting library based on bcrypt that produces smaller hashes

Home Page: https://docs.rs/rcrypt

License: Apache License 2.0

Rust 100.00%
rust cryptography bcrypt rcrypt bmcf mcf hashing salting cryptographic-hash-functions

rcrypt's Introduction

rcrypt: A compact hashing and salting library

GitHub Workflow Status Crates.io docs.rs Crates.io

rcrypt, short for "reduced crypt" is a compact hashing and salting library based on bcrypt generating hashes that are 33.3% smaller than bcrypt (40 bytes over 60 bytes).

It was originally made for a part of Skytable's authentication system storage, but was moved into a separate library for usage in the wider Rust community. rcrypt is almost a drop-in replacement for the bcrypt crate. Here's how it works.

Usage

use rcrypt::DEFAULT_COST;
// your password
let mypass = String::from("pass123");
// hash
let hash = rcrypt::hash(&mypass, DEFAULT_COST).unwrap();
// verify
assert!(rcrypt::verify(&mypass, &hash).unwrap());

The usage remains just the same for users who use the bcrypt crate, except that the hash method returns a Vec<u8> instead of a String, while for the verify method you need to pass a &[u8] for the hash.

Getting back your bcrypt hash

If for some reason you need a String with the bcrypt hash from your rcrypt hash, you can do that too! Here's the procedure:

use rcrypt::DEFAULT_COST;
let rhash = rcrypt::hash("mypassword", DEFAULT_COST).unwrap();
// now let's get the bcrypt hash from the rcrypt hash
let bhash = rcrypt::bmcf::decode_into_mcf(&rhash).unwrap();

How it works

The smaller hash sizes result by rcrypt producing binary hashes and merging hash fields, in accordance with the BMCF spec.

  • The field separators in the MCF hash are not present in hashes generated by rcrypt
  • The cost and scheme fields are merged into one field
  • The hashes generated by rcrypt do not use base64 which results in lesser bytes being used to store the salt+digest

Acknowledgements

License

This crate is distributed under the Apache-2.0 License.

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.