Skip to main content

Simultaneously the simplest and most powerful Argon2 implemenation in Python

Project description

pyargon2

Simultaneously the simplest and most powerful implementation of Argon2 in Python.

Installation

pip install pyargon2

Basic Usage

The hash function supports basic password hashing using the Argon2id variant and mandates password and salt strings. The resulting hash returned is hex encoded.

from pyargon2 import hash

password = 'a strong password'
salt = 'a unique salt'
hex_encoded_hash = hash(password, salt)

The default parameters aim to generate hashes in around 0.5 seconds and are targeted at a machine housing a CPU with 4 cores and at least 4GB of RAM. If timing differs significantly on your machine, adjust the parameters using the advanced options below. Remember password hashing should be slow for security so don't optimise for speed!

Advanced Usage

Function Choices

pyargon2 contains two functions for hashing. Namely, hash and hash_bytes. These two functions differ in their input types only. This is explained in detail in the subsequent sections. To minimise input dependent hashing performance, dynamic type checking is not used in pyargon2. Instead, dedicated functions are exposed to deal with hashing strings or byte arrays separately. As such, one should ensure that they hash passwords, salts and peppers of the same type and then pick the corresponding function in pyargon2 as appropriate.

Function Parameters

The hash and hash_bytes functions take in the following parameters:

Positional
  • password : A string (or byte array when using hash_bytes) representing a password.
  • salt : A string (or byte array when using hash_bytes) representing a unique salt.
Keyword (Optional)
  • pepper : A secret string (or byte array when using hash_bytes) to fold into the hash of the password.
  • hash_len : The length in bytes of the resulting hash.
  • time_cost : The number of iterations to perform.
  • memory_cost : The number of kibibytes in memory to utilise.
  • parallelism : The number of independent computations chains (lanes) to run.
  • flags : Flags to determine which fields are securely wiped.
  • variant : Argon2 algorithm variant ('i', 'd', or 'id').
  • version : Argon2 algorithm version number.
  • encoding : Encoding for the returned hash type ('raw', 'hex' or 'b64').

For assistance with parameter selection refer to RFC 9106, in particular "Chapter 4: Parameter Choice".

Function Exceptions

Exceptions generated by the underlying Argon2 hashing function are raised under the Argon2Error class which can be imported as follows:

from pyargon2 import Argon2Error

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

pyargon2-1.1.0.tar.gz (58.8 kB view details)

Uploaded Source

File details

Details for the file pyargon2-1.1.0.tar.gz.

File metadata

  • Download URL: pyargon2-1.1.0.tar.gz
  • Upload date:
  • Size: 58.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.18

File hashes

Hashes for pyargon2-1.1.0.tar.gz
Algorithm Hash digest
SHA256 f5a759429c08ee220d95eafe99a2d14d60f0381885283c10ad9a45335ed868a7
MD5 615848a1d900b7f3f25e9c9ab3be58ae
BLAKE2b-256 faf6a283a5fd81ef66da0069cb31bfab6ada3318926ff9b6b2bf06c66c9f391b

See more details on using hashes here.

Supported by

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