argon2 password hashing algorithm.
Project description
Argon2 won the Password Hashing Competition in 2015. argon2_cffi is the simplest way to use it in Python and PyPy:
>>> import argon2
>>> encoded_hash = argon2.hash_password(b"secret", b"somesalt")
>>> encoded_hash
b'$argon2i$m=4096,t=3,p=2$c29tZXNhbHQ$FNqxwHC2l1liWu3JTgGn6w'
>>> argon2.verify_password(encoded_hash, b"secret")
True
>>> argon2.verify_password(encoded_hash, b"wrong")
Traceback (most recent call last):
...
argon2.exceptions.VerificationError: Decoding failed
You can omit the salt argument for a secure random salt of length argon2.DEFAULT_RANDOM_SALT_LENGTH:
>>> argon2.hash_password(b"secret") # doctest: +SKIP
b'$argon2i$m=4096,t=3,p=2$GIESi4asMZaP051OPlH/zw$s5bQHIupLB1Fep/U5NXIVQ'
Installation
A working C compiler is required because the official Argon2 C implementation is shipped along with the Python CFFI bindings. Otherwise a plain pip install argon2_cffi should just work. Binary wheels are offered for OS X and Windows.
Hands-on
argon2_cffi comes with hopefully reasonable defaults for Argon2 parameters. But of course, you can set them yourself if you wish:
>>> argon2.hash_password(
... b"secret", b"somesalt",
... time_cost=1, # number of iterations
... memory_cost=8, # used memory in KiB
... parallelism=1, # number of threads used; changes hash!
... hash_len=64, # length of resulting raw hash
... type=argon2.Type.D, # choose Argon2i or Argon2d
... )
b'$argon2d$m=8,t=1,p=1$c29tZXNhbHQ$H0oN1/L3H8t8hcg47pAyJZ8toBh2UbgcMt0zRFrqt4mEJCeKSEWGxt+KpZrMwxvr7M5qktNcc/bk/hvbinueJA'
The raw hash can also be computed. The function takes the same parameters as hash_password():
>>> argon2.hash_password_raw(b"secret", b"somesalt")
b'\x14\xda\xb1\xc0p\xb6\x97YbZ\xed\xc9N\x01\xa7\xeb'
Choosing Parameters
Finding the right parameters for a password hashing algorithm is a daunting task. The authors of Argon2 specified a method in their paper but it should be noted that they also mention that no value for time_cost or memory_cost is actually insecure (cf. section 6.4).
Choose whether you want Argon2i or Argon2d (type). If you don’t know what that means, choose Argon2i (Type.I).
Figure out how many threads can be used on each call to Argon2 (parallelism). They recommend twice as many as the number of cores dedicated to hashing passwords.
Figure out how much memory each call can afford (memory_cost).
Choose a salt length. 16 Bytes are fine.
Choose a hash length (hash_len). 16 Bytes are fine.
Figure out how long each call can take. One recommendation for concurent user logins is to keep it under 0.5ms.
Measure the time for hashing using your chosen parameters. Find a time_cost that is within your accounted time. If time_cost=1 takes too long, lower memory_cost.
CLI
To aid you with finding the parameters, argon2_cffi offers a CLI interface that can be accessed using python -m argon2. It will benchmark Argon2’s password verification in the current environment. You can use command line arguments to set hashing parameters:
$ python -m argon2 -t 1 -m 512 -p 2
Running Argon2i 100 times with:
hash_len: 16
memory_cost: 512
parallelism: 2
time_cost: 1
Measuring...
0.418ms per password verification
This should make it much easier to determine the right parameters for your use case and your environment.
Credits
argon2_cffi is written and maintained by Hynek Schlawack.
The development is kindly supported by Variomedia AG.
A full list of contributors can be found on GitHub.
Vendored Code
Argon2
The original Argon2 repo can be found at https://github.com/P-H-C/phc-winner-argon2/.
Except for the components listed below, the Argon2 code in this repository is copyright (c) 2015 Daniel Dinu, Dmitry Khovratovich (main authors), Jean-Philippe Aumasson and Samuel Neves, and under CC0 license.
The string encoding routines in src/encoding.c are copyright (c) 2015 Thomas Pornin, and under CC0 license.
The BLAKE2 code in src/blake2/ is copyright (c) Samuel Neves, 2013-2015, and under CC0 license.
msinttypes
In order to be able to compile on Visual Studio 2008 which is required for Python 2.7, we also ship two headers with integer types. They are from the msinttypes project (auto-import on GitHub) and licensed under New BSD:
Copyright (c) 2006-2013 Alexander Chemeris
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the product nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ‘’AS IS’’ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Changelog
Versions are year-based with a strict backward compatibility policy. The third digit is only for regressions.
15.0.0 (UNRELEASED)
Vendoring argon2 @ 4fe0d8cda37691228dd5a96a310be57369403a4b.
Changes:
15.0.0b5 (2015-12-10)
Vendoring argon2 @ 4fe0d8cda37691228dd5a96a310be57369403a4b.
Changes:
Vendor msinttypes to build on Visual Studio 2008 for Python 2.7. See AUTHORS.rst for licensing details.
Update argon2. The authors were kind enough to help me to get it building under that ancient compiler we’re forced to use.
15.0.0b4 (2015-12-10)
Vendoring argon2 @ 567c22d97bf137cf4aeca99decb12d946d1799c7.
Changes:
Update argon2.
15.0.0b3 (2015-12-09)
Vendoring argon2 @ 7f0dbc3efa0d07b338c3a40260aef92f3b619a00.
Changes:
More Windows fixes.
15.0.0b2 (2015-12-09)
Vendoring argon2 @ 7f0dbc3efa0d07b338c3a40260aef92f3b619a00.
Changes:
Use proper #include in CFFI aka fix Windows packaging some more.
15.0.0b1 (2015-12-09)
Vendoring argon2 @ 7f0dbc3efa0d07b338c3a40260aef92f3b619a00.
Changes:
Fix packaging on Windows.
15.0.0b0 (2015-12-09)
Vendoring argon2 @ 7f0dbc3efa0d07b338c3a40260aef92f3b619a00.
Initial work.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file argon2_cffi-15.0.0b5.tar.gz
.
File metadata
- Download URL: argon2_cffi-15.0.0b5.tar.gz
- Upload date:
- Size: 805.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42dac34f893990755f8278b68da1e94c22cc0dc77f653673bcaac36cb8c3346f |
|
MD5 | 842c3e79b1a5778c1001c27054fc568c |
|
BLAKE2b-256 | 593bc736cb9883f7f1c11d98d4c0deef10af0922caec9380a8a16e751adc6244 |
File details
Details for the file argon2_cffi-15.0.0b5-cp35-none-win_amd64.whl
.
File metadata
- Download URL: argon2_cffi-15.0.0b5-cp35-none-win_amd64.whl
- Upload date:
- Size: 35.3 kB
- Tags: CPython 3.5, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 573c7313e1d1112b57be8abf38c25a646f5b771e7b8a926e7c3d74c3a1e81a1e |
|
MD5 | 4e601d864ab6bbb227a28116e8a166d6 |
|
BLAKE2b-256 | d5646ba304598c57836e0d799d1a2a266c5d444c91206c81c6e95657311505be |
File details
Details for the file argon2_cffi-15.0.0b5-cp35-none-win32.whl
.
File metadata
- Download URL: argon2_cffi-15.0.0b5-cp35-none-win32.whl
- Upload date:
- Size: 33.7 kB
- Tags: CPython 3.5, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20be27e719c52fa3ceaf3deb055f124cb645558f2a1e641666fad2b28d5890ad |
|
MD5 | 33d220eb785b1d0bbfe482c1e8c9720c |
|
BLAKE2b-256 | c7652ad5d62c3cb3e10ae4a4a8bac3eb8feab0d25f284763b832e0ebed58722b |
File details
Details for the file argon2_cffi-15.0.0b5-cp35-cp35m-macosx_10_6_intel.whl
.
File metadata
- Download URL: argon2_cffi-15.0.0b5-cp35-cp35m-macosx_10_6_intel.whl
- Upload date:
- Size: 50.5 kB
- Tags: CPython 3.5m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cd9d1d7b7f7ce59064fe25e34956269d04af460ca3ae4f2a42c67f92f24dcd9 |
|
MD5 | 6cc802f56c03d4cacac768b2c514ef3f |
|
BLAKE2b-256 | b1646b62705d2d79873e52296b332bbc968cfaee2a62f36f00777a553cf239ae |
File details
Details for the file argon2_cffi-15.0.0b5-cp34-cp34m-macosx_10_6_intel.whl
.
File metadata
- Download URL: argon2_cffi-15.0.0b5-cp34-cp34m-macosx_10_6_intel.whl
- Upload date:
- Size: 50.4 kB
- Tags: CPython 3.4m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08604317c1d2c687e414ee307e1056b8d3817bc9ecf0a759b6faee4251d5e7c1 |
|
MD5 | 95105db154e723d4da8fd7da0fb7c943 |
|
BLAKE2b-256 | 4d7242147dbc90eba7e5f1695028f9cede7f8d3e6f33fc1fee0ce2771b27194b |
File details
Details for the file argon2_cffi-15.0.0b5-cp33-cp33m-macosx_10_6_intel.whl
.
File metadata
- Download URL: argon2_cffi-15.0.0b5-cp33-cp33m-macosx_10_6_intel.whl
- Upload date:
- Size: 50.4 kB
- Tags: CPython 3.3m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eb78653872c0a6309c66141ca6e03e59e086636b811fd312d6ecb8e732c7808 |
|
MD5 | d6a36fc1e54ac799db8385f353391a0d |
|
BLAKE2b-256 | 1a9cef3a3854ff97be75411dcdea64db320bb0902cda258551018617f484a66a |
File details
Details for the file argon2_cffi-15.0.0b5-cp27-none-win_amd64.whl
.
File metadata
- Download URL: argon2_cffi-15.0.0b5-cp27-none-win_amd64.whl
- Upload date:
- Size: 31.6 kB
- Tags: CPython 2.7, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a96ea78e4a3eb0182dc00cd19e4ccc5cedabe0a7fbd1fd320ffc42e662aee99 |
|
MD5 | a48e2ce61ce365b94550578e1d099fc6 |
|
BLAKE2b-256 | 4d70abc63f3acda4e487807b24395d7870a121a9ecac3a70f9fd5d2bd6ee2c9a |
File details
Details for the file argon2_cffi-15.0.0b5-cp27-none-win32.whl
.
File metadata
- Download URL: argon2_cffi-15.0.0b5-cp27-none-win32.whl
- Upload date:
- Size: 32.9 kB
- Tags: CPython 2.7, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef50827206a2f9c484073324c6027d5fc1ebb4773352f3a014ee587c939c13a1 |
|
MD5 | fba5688ff6f4a1dc4d04d79792a5c5ee |
|
BLAKE2b-256 | 09dca6fab0beabe9c402d97a1d8e115e4cc1ff69258f88e38fe8b080ebae60b3 |
File details
Details for the file argon2_cffi-15.0.0b5-cp27-none-macosx_10_6_intel.whl
.
File metadata
- Download URL: argon2_cffi-15.0.0b5-cp27-none-macosx_10_6_intel.whl
- Upload date:
- Size: 50.4 kB
- Tags: CPython 2.7, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdb78ef7aedd1bf627b8cbcecd5e127a07ae32cf9adfdb6fd983485957bef35e |
|
MD5 | ec6f71fc9805f95bd63af2a465cd5efd |
|
BLAKE2b-256 | f9c6328b44e6d787e4dd0a6d6e5440b9b987d420a222aefe8fdaa6538055dd84 |
File details
Details for the file argon2_cffi-15.0.0b5-cp26-none-win_amd64.whl
.
File metadata
- Download URL: argon2_cffi-15.0.0b5-cp26-none-win_amd64.whl
- Upload date:
- Size: 31.9 kB
- Tags: CPython 2.6, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c42d9ccf797faac9d3ce7cb59f071932c9c1e092168ed688524188cc400e4ada |
|
MD5 | 0d8cbcf89dbf00cb89b2eb0e28f3c3ac |
|
BLAKE2b-256 | befa9d092a71921b304796d88b62c45dcece88817afae32ed73a3ac9b8bc6445 |
File details
Details for the file argon2_cffi-15.0.0b5-cp26-none-win32.whl
.
File metadata
- Download URL: argon2_cffi-15.0.0b5-cp26-none-win32.whl
- Upload date:
- Size: 33.2 kB
- Tags: CPython 2.6, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | acbad900835d681f2d5e75d05282ebd98a7f458d62a714fdcf97bd4d9e8aeb08 |
|
MD5 | 0e3080262842d70c58ba4cf5f15bfdd8 |
|
BLAKE2b-256 | df9a7b861a4d12b9d5fbc04000ff921593bbb956e17348999ebbad9c69e87062 |
File details
Details for the file argon2_cffi-15.0.0b5-cp26-none-macosx_10_7_intel.whl
.
File metadata
- Download URL: argon2_cffi-15.0.0b5-cp26-none-macosx_10_7_intel.whl
- Upload date:
- Size: 47.5 kB
- Tags: CPython 2.6, macOS 10.7+ intel
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ccb1b0533f82ec9a2f1e59e28debcc972c74aaf46d3665e339a76acf7f19a8f |
|
MD5 | 566eb27bd9bbef311044c754b7139003 |
|
BLAKE2b-256 | 5e5cab5f762839eab420e972694d0e65e38edc65e97371b1cea8cc48b0ba319a |