Skip to main content

A Python-wrapped Rust Argon2 Hasher

Project description

argon2_hasher

A minimal-surface Python extension that exposes an optimised, memory-hard Argon2id password hasher implemented in Rust


Installation

Quick-start (debug)
pip install maturin            # one-time
maturin develop                # builds & installs in debug mode
Production wheel (recommended)
# 1. Build an optimised, CPU-tuned wheel…
RUSTFLAGS="-C target-cpu=native" \
  maturin build --release --strip

# 2. Install it
pip install target/wheels/argon2_hasher-*.whl

Why two commands? maturin develop is great for dev loops but compiles without optimisations. For benchmarks or production you’ll want the --release wheel (20-50 × faster).


Usage

from argon2_hasher import Argon2Hasher

plain_pw = "correct horse battery staple"

# ① Hash ----------------------------------------------------------------
phc = Argon2Hasher.hash(plain_pw)     # '$argon2id$v=19$m=8192,t=2,p=4$…'

# ② Verify --------------------------------------------------------------
assert Argon2Hasher.verify(phc, plain_pw)          # ✅ True
assert not Argon2Hasher.verify(phc, "wrong pass")  # ❌ False

That’s it – no knobs exposed to Python; all tuning happens inside the Rust crate.


API

Function Signature Description
Argon2Hasher.hash (plain: str, salt: str | None = None) -> str Returns a PHC-encoded Argon2id hash. If salt is None, a cryptographically-secure 16-byte salt is generated.
Argon2Hasher.verify (hash: str, plain: str) -> bool Constant-time verification. Returns True if plain matches hash.

All errors are raised as ValueError (malformed hash / salt) or RuntimeError (internal hashing error).


Tests

# tests/test_argon2_hasher.py
from argon2_hasher import Argon2Hasher

def test_match():
    pw  = "my_secure_password"
    phc = Argon2Hasher.hash(pw)
    assert Argon2Hasher.verify(phc, pw)

def test_mismatch():
    phc = Argon2Hasher.hash("secret")
    assert not Argon2Hasher.verify(phc, "bad")

def test_speed():
    import time, bcrypt
    pw = "pw"
    t0 = time.perf_counter()
    Argon2Hasher.verify(Argon2Hasher.hash(pw), pw)
    argon_time = time.perf_counter() - t0

    t0 = time.perf_counter()
    bcrypt.checkpw(pw.encode(),
                   bcrypt.hashpw(pw.encode(),
                                 bcrypt.gensalt(rounds=12)))
    bcrypt_time = time.perf_counter() - t0

    print(f"argon2 {argon_time:.3f}s  / bcrypt {bcrypt_time:.3f}s")

License

argon2_hasher is released under the MIT License. See LICENSE for the full text.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fast_argon2_hasher-0.1.3.tar.gz (15.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fast_argon2_hasher-0.1.3-cp311-cp311-manylinux_2_28_x86_64.whl (306.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

fast_argon2_hasher-0.1.3-cp311-cp311-manylinux_2_28_aarch64.whl (298.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

File details

Details for the file fast_argon2_hasher-0.1.3.tar.gz.

File metadata

  • Download URL: fast_argon2_hasher-0.1.3.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for fast_argon2_hasher-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f280f05807a183d4455d219e847c04a4ba619cdffff53ddf665b3584088e27f3
MD5 cdfc58335dab42ee36959c6dd61b07a4
BLAKE2b-256 28c19f8af8ab8673079d36569e28c3d583f9a69bd75b91fc67e4708601b023f4

See more details on using hashes here.

File details

Details for the file fast_argon2_hasher-0.1.3-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fast_argon2_hasher-0.1.3-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 04d2d3f72adf06c087c8ff71cc0ff9068176e44d0cf44246f47fffb6ebeef731
MD5 59436bfca4cf5df34c6e13fb91e5aab3
BLAKE2b-256 29dbaba3ac83c3dbe645f17ae0e480affec95ee2f45ed16a81391c263f68c13a

See more details on using hashes here.

File details

Details for the file fast_argon2_hasher-0.1.3-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for fast_argon2_hasher-0.1.3-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 305ef533300945b4d5e2892b09595684cabc7267705646477eb6b156770c3824
MD5 dff667a9c10dbd478d4a078aefec570b
BLAKE2b-256 f1da32e417254e53ac4770ff5f6920fe792519ad8fa0b9e55c67152f3e42b5a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page