compact_argon2
The ergonomics of the argon2 crate sucks.
This crate provides a thin wrapper around argon2's methods and an alternate,
much smaller binary serialization format. It uses whatever the default
parameters of argon2 current are, but uses deserialized parameters during
verification, just like the argon2 crate. It's hardcoded to use the
argon2id algorithm with the default salt and output lengths because get real.
Usage
let password = b"hunter2";
let hash = hash.unwrap;
assert!;
// save to a file
let bytes: = hash.as_bytes;
serde compatibility
Enable the serde feature for Serialize and Deserialize impls on Hash.
hex representation
Enable the hex feature to convert Hash to/from a hex string.
let hash = hash.unwrap;
let hex_string = hash.to_string;
let parsed_hash = hex_string.parse.unwrap;
assert_eq!;
// Can also be used with serde
sqlx::Postgres compatibility
Enable the postgres feature to use Hash with sqlx's PostgeSQL driver.
let mut user: User = query_as
.bind
.fetch_one
.await?;
let new_password = hash.unwrap;
query
.bind
.bind
.execute
.await?;
Serialized format
The Hash struct is fully stack allocated and serializes to
a nice and even 64 bytes (128 in hex).
- litte endian u32 (4 bytes) -
t_cost - litte endian u32 (4 bytes) -
p_cost - litte endian u32 (4 bytes) -
m_cost - litte endian u32 (4 bytes) - Version
- 16 bytes - Salt
- 32 bytes - Hash output
Zero-copy deserialization
On little-endian targets, enable the zerocopy feature to deserialize
&'a [u8] into &'a Hash directly, copying only 16 bytes to verify params.
let original_hash = hash.unwrap;
let bytes = original_hash.as_bytes;
let reconstructed = checked_cast.unwrap;
assert_eq!;