Rust

hashes

Module

The built-in password hashing algorithms, each a Hash with its own options.

Contents

9 submodules.

hashes::argon2

Own page

The Argon2id password hash.

use utopia_auth::hashes::argon2::Argon2;
Rust
pub struct Argon2

The Argon2id password hash, in the standard $argon2id$ format.

Options: type, memory_cost (KiB), time_cost and threads.

Rust
use utopia_auth::Hash;
use utopia_auth::hashes::Argon2;

let mut argon2 = Argon2::new();
argon2.set_memory_cost(7168).set_time_cost(5).set_threads(1);
let hash = argon2.hash(b"secret")?;
assert!(hash.starts_with(b"$argon2id$v=19$m=7168,t=5,p=1$"));
assert!(argon2.verify(b"secret", &hash)?);
Also implements Default.

hashes::bcrypt

Own page

The bcrypt password hash.

use utopia_auth::hashes::bcrypt::Bcrypt;
Rust
pub struct Bcrypt

The bcrypt password hash, in the $2y$ format.

Options: type and cost.

Also implements Default.

hashes::md5

Own page

The unsalted MD5 digest, for imported legacy passwords.

use utopia_auth::hashes::md5::Md5;
Rust
pub struct Md5

The unsalted MD5 digest of a password, as lowercase hex.

Weak: use it only to verify passwords imported from another system.

Also implements Default.

hashes::password

Own page

The shared bcrypt, Argon2id and crypt calls behind the hashes: the options they read and the random salt they draw.

hashes::phpass

Own page

The phpass password hash used by WordPress and phpBB.

use utopia_auth::hashes::phpass::PHPass;
Rust
pub struct PHPass

The phpass password hash, as WordPress and phpBB use it: $2a$ bcrypt hashes, or $P$ portable MD5 hashes when portable_hashes is set (or bcrypt fails).

Options: type, iteration_count_log2, portable_hashes and random_state.

Also implements Default.

hashes::plaintext

Own page

A hash that stores the password as is.

use utopia_auth::hashes::plaintext::Plaintext;
Rust
pub struct Plaintext

A hash that stores the password unchanged.

Also implements Default.

hashes::scrypt

Own page

The scrypt password hash.

use utopia_auth::hashes::scrypt::Scrypt;
Rust
pub struct Scrypt

The scrypt key derivation as a password hash, in lowercase hex.

Options: type, costCpu (N), costMemory (r), costParallel (p), length (bytes) and salt (used as given, a random hex string by default).

Also implements Default.

hashes::scrypt_modified

Own page

Firebase's modified scrypt password hash.

use utopia_auth::hashes::scrypt_modified::ScryptModified;
Rust
pub struct ScryptModified

Firebase's modified scrypt: the signer key encrypted with AES-256-CTR under a key scrypt derives from the password, as base64.

Use it to verify passwords exported from Firebase Authentication.

Options: type, salt, saltSeparator, signerKey (all base64).

Also implements Default.

hashes::sha

Own page

Unsalted SHA-1, SHA-2 and SHA-3 digests, for imported legacy passwords.

use utopia_auth::hashes::sha::Sha;
Rust
pub struct Sha

The unsalted SHA digest of a password, as lowercase hex.

Its options hold only version (no type): the name of the algorithm. Weak: use it only to verify passwords imported from another system.

Rust
use utopia_auth::Hash;
use utopia_auth::hashes::{Sha, ShaVersion};

let mut sha = Sha::new();
sha.set_version(ShaVersion::Sha256);
let hash = sha.hash(b"password")?;
assert_eq!(hash, b"5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8");
Also implements Default.
use utopia_auth::hashes::sha::ShaVersion;
Rust
pub enum ShaVersion

A SHA algorithm a Sha hash can use.