Skip to Content
oxcrypto

Argon2

Create and verify Argon2 password hashes.

from oxcrypto.password.argon2 import ARGON2

algorithm = ARGON2.ARGON2ID
encoded = algorithm.hash(b"example password")
assert algorithm.verify(b"example password", encoded)

hash generates a random salt and returns a PHC string. verify reads the salt and cost parameters from that string and returns a boolean.

The module exposes ARGON2D, ARGON2I, and ARGON2ID on ARGON2. For raw key derivation, call derive(password, salt=..., params=..., length=...). The Parameters() defaults are 65,536 KiB of memory, 3 passes, and 4 lanes.

hash accepts keyword-only options. The defaults give the same record as before:

from oxcrypto.password.argon2 import ARGON2, Parameters

encoded = ARGON2.ARGON2ID.hash(
    b"example password",
    params=Parameters(memory_cost=19_456, time_cost=2, parallelism=1),
    version=19,
    secret=b"server-side pepper",
    associated_data=b"user-42",
)
assert ARGON2.ARGON2ID.verify(b"example password", encoded, secret=b"server-side pepper")
  • version is 19 (0x13, the RFC 9106 version) or 16 (0x10, legacy).
  • secret is the RFC 9106 secret value K (a pepper). It is not stored in the record, so verify needs the same secret.
  • associated_data (at most 32 bytes) is stored in the record as data= and read back by verify.

Argon2 is specified in RFC 9106 (Informational, IRTF CFRG). The implementation is the RustCrypto argon2 crate 0.6.0, a stable release with no published audit. Tests use the RFC 9106 section 5 vectors, which include a secret and associated data, and the reference implementation's PHC strings.