Expand description
§Hash (HSH), a Quantum-Resistant Cryptographic Hash Library
A Highly Secure Quantum-Resistant Cryptographic Hash Library for Password Encryption and Verification in Rust. Designed with quantum-resistant cryptography, this library provides a robust line of defence against current and emerging computational threats.
Part of the Mini Functions family of libraries.
§Overview
The Hash (HSH) Rust library provides an interface for implementing secure hash and digest algorithms, specifically designed for password encryption and verification.
The library provides a simple API that makes it easy to store and verify hashed passwords. It enables robust security for passwords, using the latest advancements in Quantum-resistant cryptography. Quantum- resistant cryptography refers to cryptographic algorithms, usually public-key algorithms, that are thought to be secure against an attack by a quantum computer. As quantum computing continues to advance, this feature of the library assures that the passwords managed through this system remain secure even against cutting-edge computational capabilities.
The library supports the following Password Hashing Schemes (Password Based Key Derivation Functions):
- Argon2i: A cutting-edge and highly secure key derivation function designed to protect against both traditional brute-force attacks and rainbow table attacks. (Recommended)
- Bcrypt: A password hashing function designed to be secure against brute-force attacks. It is a work-factor function, which means that it takes a certain amount of time to compute. This makes it difficult to attack with a brute-force algorithm.
- Scrypt: A password hashing function designed to be secure against both brute-force attacks and rainbow table attacks. It is a memory-hard and work- factor function, which means that it requires a lot of memory and time to compute. This makes it very difficult to attack with a GPU or other parallel computing device.
§Features
- Ease of Use: Simple API for storing and verifying hashed passwords.
- Future-Proof: Quantum-resistant cryptography to secure against future technological advancements.
- Integrable: Written in Rust, the library is fast, efficient, and easily integrable into other Rust projects.
- Versatility: Supports multiple Password Hashing Schemes like Argon2i, Bcrypt, and Scrypt.
§Core Components
§Hash
Struct
Contains:
- algorithm: Enum representing the hashing algorithm (Argon2i, Bcrypt, Scrypt).
- hash: Byte vector containing the hashed password.
- salt: Byte vector containing the salt used in hashing.
§HashAlgorithm
Enum
Provides variants for supported hashing algorithms: Argon2i, Bcrypt, and Scrypt.
§Methods
The Hash
struct offers methods for password hashing and management, including but not limited to:
- Creating new Hash objects.
- Generating and setting salts and hashes.
- Verifying passwords against stored hashes.
§Getting Started
Add Hash (HSH)
as a dependency in your Cargo.toml
and import it in your main Rust file.
§Example
Here’s a simple example demonstrating basic usage:
use hsh::models::hash::Hash; // Import the Hash struct
let password = "password123";
let salt = "somesalt";
let algo = "argon2i";
let original_hash = Hash::new(password, salt, algo).expect("Failed to create hash");
let hashed_password = original_hash.hash.clone();
assert_eq!(original_hash.hash(), &hashed_password);
§License
Licensed under the MIT and Apache License (Version 2.0).
Modules§
- algorithms
- The
algorithms
module contains the password hashing algorithms. - macros
- The
macros
module contains functions for generating macros. - models
- The
models
module contains the data models for the library.
Macros§
- generate_
hash - This macro generates a new hash for a given password, salt, and algorithm.
- hash_
length - This macro returns the length of the password for a given
Hash
struct instance. - hsh
- This macro takes any number of arguments and parses them into a Rust
value. The parsed value is returned wrapped in
hsh::Hash::parse()
function call. - hsh_
assert - This macro asserts that the given condition is true. If the condition is false, the macro panics with the message “Assertion failed!”.
- hsh_
contains - This macro checks if the given string contains the given substring.
- hsh_
in_ range - This macro checks if the given value is within the given range. The range is inclusive of both endpoints.
- hsh_
join - This macro joins the given strings together with the given separator.
- hsh_max
- This macro finds the maximum value of the given values.
- hsh_min
- This macro finds the minimum value of the given values.
- hsh_
parse - This macro attempts to parse the given input into a u64 value. If parsing fails, an error is returned with a message indicating the failure.
- hsh_
print - This macro prints the given arguments to the console.
- hsh_
print_ vec - This macro prints the given vector of values to the console. Each value is printed on a new line.
- hsh_
split - This macro splits the given string into a vector of strings. The string is split on whitespace characters.
- hsh_vec
- This macro creates a new vector with the given elements.
- macro_
execute_ and_ log - Macros related to executing shell commands.
- match_
algo - This macro matches the hash algorithm strings to their corresponding enum variants.
- new_
hash - This macro creates a new instance of the
Hash
struct with the given password, salt, and algorithm. - random_
string - This macro generates a random string of the given length. The string consists of alphanumeric characters (both upper and lower case).
- to_
str_ error - This macro abstracts away the error handling for the
to_string
method. If the method fails, an error is returned with the failure message.
Functions§
- run
- This is the main entry point for the
Hash (HSH)
library.