#password-hashing #scrypt #firebase #pure #algorithm #script

firebase-scrypt

Pure Rust implementation of Firebase's script password hashing algorithm

4 releases

0.2.1 Sep 8, 2023
0.2.0 Oct 4, 2022
0.1.1 Oct 3, 2022
0.1.0 Oct 2, 2022

#2625 in Cryptography

Download history 30/week @ 2024-11-10 61/week @ 2024-11-17 15/week @ 2024-11-24 1/week @ 2024-12-01 7/week @ 2024-12-08 76/week @ 2024-12-15 79/week @ 2024-12-22 118/week @ 2024-12-29 48/week @ 2025-01-05 12/week @ 2025-01-12 20/week @ 2025-01-19 38/week @ 2025-01-26 68/week @ 2025-02-02 33/week @ 2025-02-09 23/week @ 2025-02-16 4/week @ 2025-02-23

132 downloads per month

MIT license

19KB
260 lines

Firebase Scrypt (for Rust)

Pure Rust implementation of Firebase's scrypt password hashing algorithm.

Crates.io Documentation

Installation

Add this to your Cargo.toml

[dependencies]
firebase-scrypt = "0.2"

Usage

With the simple feature:

use firebase_scrypt::FirebaseScrypt;

const SALT_SEPARATOR: &str = "Bw==";
const SIGNER_KEY: &str = "jxspr8Ki0RYycVU8zykbdLGjFQ3McFUH0uiiTvC8pVMXAn210wjLNmdZJzxUECKbm0QsEmYUSDzZvpjeJ9WmXA==";
const ROUNDS: u32 = 8;
const MEM_COST: u32 = 14;

let firebase_scrypt = FirebaseScrypt::new(SALT_SEPARATOR, SIGNER_KEY, ROUNDS, MEM_COST);

let password = "user1password";
let salt = "42xEC+ixf3L2lw==";
let password_hash ="lSrfV15cpx95/sZS2W9c9Kp6i/LVgQNDNC/qzrCnh1SAyZvqmZqAjTdn3aoItz+VHjoZilo78198JAdRuid5lQ==";

assert!(firebase_scrypt.verify_password(password, salt, password_hash).unwrap())

Use the verify_password function without FirebaseScrypt

use firebase_scrypt::verify_password;

const SALT_SEPARATOR: &str = "Bw==";
const SIGNER_KEY: &str = "jxspr8Ki0RYycVU8zykbdLGjFQ3McFUH0uiiTvC8pVMXAn210wjLNmdZJzxUECKbm0QsEmYUSDzZvpjeJ9WmXA==";
const ROUNDS: u32 = 8;
const MEM_COST: u32 = 14;

let password = "user1password";
let salt = "42xEC+ixf3L2lw==";
let password_hash ="lSrfV15cpx95/sZS2W9c9Kp6i/LVgQNDNC/qzrCnh1SAyZvqmZqAjTdn3aoItz+VHjoZilo78198JAdRuid5lQ==";

let is_valid = verify_password(
     password,
     password_hash,
     salt,
     SALT_SEPARATOR,
     SIGNER_KEY,
     ROUNDS,
     MEM_COST,
).unwrap();

MSRV

The minimum supported Rust version is: 1.59

Dependencies

~1.5MB
~33K SLoC