argus

Types

pub type Argon2Algorithm {
  Argon2d
  Argon2i
  Argon2id
}

Constructors

  • Argon2d
  • Argon2i
  • Argon2id

All possible Argon2 hashing errors. Most are unlikely to occur, but it’s good to be aware of them.

pub type HashError {
  OutputPointerIsNull
  OutputTooShort
  OutputTooLong
  PasswordTooShort
  PasswordTooLong
  SaltTooShort
  SaltTooLong
  AssociatedDataTooShort
  AssociatedDataTooLong
  SecretTooShort
  SecretTooLong
  TimeCostTooSmall
  TimeCostTooLarge
  MemoryCostTooSmall
  MemoryCostTooLarge
  TooFewLanes
  TooManyLanes
  PasswordPointerMismatch
  SaltPointerMismatch
  SecretPointerMismatch
  AssociatedDataPointerMismatch
  MemoryAllocationError
  FreeMemoryCallbackNull
  AllocateMemoryCallbackNull
  IncorrectParameter
  IncorrectType
  InvalidAlgorithm
  OutputPointerMismatch
  TooFewThreads
  TooManyThreads
  NotEnoughMemory
  EncodingFailed
  DecodingFailed
  ThreadFailure
  DecodingLengthFailure
  VerificationFailure
  UnknownErrorCode
}

Constructors

  • OutputPointerIsNull
  • OutputTooShort
  • OutputTooLong
  • PasswordTooShort
  • PasswordTooLong
  • SaltTooShort
  • SaltTooLong
  • AssociatedDataTooShort
  • AssociatedDataTooLong
  • SecretTooShort
  • SecretTooLong
  • TimeCostTooSmall
  • TimeCostTooLarge
  • MemoryCostTooSmall
  • MemoryCostTooLarge
  • TooFewLanes
  • TooManyLanes
  • PasswordPointerMismatch
  • SaltPointerMismatch
  • SecretPointerMismatch
  • AssociatedDataPointerMismatch
  • MemoryAllocationError
  • FreeMemoryCallbackNull
  • AllocateMemoryCallbackNull
  • IncorrectParameter
  • IncorrectType
  • InvalidAlgorithm
  • OutputPointerMismatch
  • TooFewThreads
  • TooManyThreads
  • NotEnoughMemory
  • EncodingFailed
  • DecodingFailed
  • ThreadFailure
  • DecodingLengthFailure
  • VerificationFailure
  • UnknownErrorCode
pub opaque type Hasher
pub type Hashes {
  Hashes(raw_hash: BitArray, encoded_hash: String)
}

Constructors

  • Hashes(raw_hash: BitArray, encoded_hash: String)

Functions

pub fn algorithm(
  hasher: Hasher,
  algorithm: Argon2Algorithm,
) -> Hasher

Set the algorithm to use for the hasher.

pub fn gen_salt() -> String

Generate a random salt of at least 64 bytes.

pub fn hash(
  hasher: Hasher,
  password: String,
  salt: String,
) -> Result(Hashes, HashError)

Hash a password using the provided hasher.

Examples

import argus

let assert Ok(hashes) =
  argus.hasher()
  |> argus.algorithm(argus.Argon2id)
  |> argus.time_cost(3)
  |> argus.memory_cost(12228)
  |> argus.parallelism(1)
  |> argus.hash_length(32)
  |> argus.hash("password", gen_salt())

let assert Ok(True) = argus.verify(hashes.encoded_hash, "password")
pub fn hash_length(hasher: Hasher, hash_length: Int) -> Hasher

Set the hash length to use for the hasher.

pub fn hasher() -> Hasher

Create a new hasher with default settings based on the OWASP recommendations.

Note: if you change the algorithm to Argon2i, you will need to change the memory_cost to 12_228 (12 mebibytes) or less for performance reasons.

The hasher_argon2i function is provided with the recommended settings for Argon2i.

pub fn hasher_argon2i() -> Hasher

Create a new hasher with default settings based on the OWASP recommendations for Argon2i.

pub fn memory_cost(hasher: Hasher, memory_cost: Int) -> Hasher

Set the memory cost to use for the hasher.

pub fn parallelism(hasher: Hasher, parallelism: Int) -> Hasher

Set the parallelism to use for the hasher.

pub fn time_cost(hasher: Hasher, time_cost: Int) -> Hasher

Set the time cost to use for the hasher.

pub fn verify(
  encoded_hash: String,
  password: String,
) -> Result(Bool, HashError)

Verify a password using the provided encoded hash.

Search Document