Compare commits
410 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
554c9d210b | ||
|
|
da495b9bfd | ||
|
|
b2d793e9fe | ||
|
|
f00944b9e5 | ||
|
|
274102dcc8 | ||
|
|
8237f19ee5 | ||
|
|
5d243f8480 | ||
|
|
d7f2d798cd | ||
|
|
f56fb033e6 | ||
|
|
d6af39a00f | ||
|
|
5c24ec8836 | ||
|
|
9121bf7161 | ||
|
|
e29c384da2 | ||
|
|
b5a4c64446 | ||
|
|
b23c61e7a4 | ||
|
|
edaa01db15 | ||
|
|
bf51fee370 | ||
|
|
3cf14095c4 | ||
|
|
dde21d5dcd | ||
|
|
1651eaab84 | ||
|
|
cb38bdd94b | ||
|
|
96e4ac635e | ||
|
|
937f5e9aaa | ||
|
|
0c4c4632ba | ||
|
|
33cf4babc2 | ||
|
|
72b058a1d9 | ||
|
|
c78942f326 | ||
|
|
0ae76a8017 | ||
|
|
5427ba996a | ||
|
|
60695c9394 | ||
|
|
86d5f8475e | ||
|
|
fe4006da2b | ||
|
|
e28bc9431a | ||
|
|
47ef1e4bb7 | ||
|
|
71a5f0f84c | ||
|
|
16476222ca | ||
|
|
1fcae4fc1b | ||
|
|
18939b166b | ||
|
|
8dcceb5709 | ||
|
|
9542242475 | ||
|
|
298af7e4db | ||
|
|
2eedf07ac7 | ||
|
|
bc861f04ff | ||
|
|
f8260dd07d | ||
|
|
b8321fa3b6 | ||
|
|
9143d9092b | ||
|
|
cd9799b14b | ||
|
|
50f87e492e | ||
|
|
bccfe7e7db | ||
|
|
6c2264e203 | ||
|
|
c4633ca2c2 | ||
|
|
8041a043f4 | ||
|
|
04bc442396 | ||
|
|
d8036728bc | ||
|
|
adde7185f2 | ||
|
|
fade17c9ee | ||
|
|
aa98519d64 | ||
|
|
a95a6cbb54 | ||
|
|
bb132e8cf7 | ||
|
|
52db639e39 | ||
|
|
6928cdd5fa | ||
|
|
33a5be6286 | ||
|
|
cf3c1d60dd | ||
|
|
da9e29b6a2 | ||
|
|
517093871c | ||
|
|
4bbe30f859 | ||
|
|
af1f60bf3d | ||
|
|
7749356596 | ||
|
|
e26858b221 | ||
|
|
ced64d8a26 | ||
|
|
48960ab755 | ||
|
|
a021330c8b | ||
|
|
bde5a25811 | ||
|
|
e2e984e615 | ||
|
|
4af54b24ad | ||
|
|
40ffe811dc | ||
|
|
477d7cb784 | ||
|
|
362435579d | ||
|
|
9b91be0c23 | ||
|
|
57ab8d9313 | ||
|
|
3d85dfe30a | ||
|
|
113e1effb2 | ||
|
|
367678c8e2 | ||
|
|
4985c72546 | ||
|
|
836ccd82ca | ||
|
|
0805dbdded | ||
|
|
119357eb31 | ||
|
|
489135aa5d | ||
|
|
b8c7d47734 | ||
|
|
64c82a474b | ||
|
|
79ceaa9822 | ||
|
|
d362c8dded | ||
|
|
abd0cf90d6 | ||
|
|
51600c12ea | ||
|
|
2d1ad772fa | ||
|
|
e5b25832f6 | ||
|
|
8eb9405d96 | ||
|
|
abd18e525b | ||
|
|
87e7399a60 | ||
|
|
5164f70990 | ||
|
|
e5c18125d0 | ||
|
|
e7d12b6e03 | ||
|
|
991a8492f8 | ||
|
|
34ffe83adc | ||
|
|
fc1cadd10b | ||
|
|
9642cd20c0 | ||
|
|
951a94575a | ||
|
|
df548a54c4 | ||
|
|
fa8b7a0fd4 | ||
|
|
2eeadd26ed | ||
|
|
c9683325d5 | ||
|
|
ecd1b32632 | ||
|
|
aaad007957 | ||
|
|
5c13aa6bbb | ||
|
|
d0e4c35291 | ||
|
|
08b4d3c61f | ||
|
|
8fb1ea1451 | ||
|
|
3b9664cd60 | ||
|
|
79b5a39711 | ||
|
|
1380a12b3f | ||
|
|
3d5eb74a38 | ||
|
|
5d25e9c9f6 | ||
|
|
a704754f91 | ||
|
|
c3fb9d8ad9 | ||
|
|
7b3213f30e | ||
|
|
35ef67cf7b | ||
|
|
2708fd94b6 | ||
|
|
e9473c8f0b | ||
|
|
7d3edeffee | ||
|
|
aa1d42404a | ||
|
|
2745a0dcdd | ||
|
|
001ae15a21 | ||
|
|
88e2ef2a2f | ||
|
|
17e2808dde | ||
|
|
ee243d2390 | ||
|
|
456e175076 | ||
|
|
413e03a6d4 | ||
|
|
3316c26b7f | ||
|
|
baead4e9e5 | ||
|
|
811841d1b3 | ||
|
|
1d0b9de7e9 | ||
|
|
d34f50b4f0 | ||
|
|
840fe22789 | ||
|
|
66f9b9bb50 | ||
|
|
42c71f1b86 | ||
|
|
93e64e96c9 | ||
|
|
a1d48ebade | ||
|
|
18339bdbc7 | ||
|
|
3cfdf1e632 | ||
|
|
8c28113caa | ||
|
|
08c5c177fd | ||
|
|
01328c9157 | ||
|
|
7c8a3aef24 | ||
|
|
c3e2d2b2b4 | ||
|
|
4da64d2ed4 | ||
|
|
0088d913e8 | ||
|
|
c1b9e2d649 | ||
|
|
57950c9247 | ||
|
|
2886c462e9 | ||
|
|
4db390ac51 | ||
|
|
505ef6af98 | ||
|
|
9f40aebb29 | ||
|
|
4f9cc1389c | ||
|
|
5acd326940 | ||
|
|
df3b71b1f8 | ||
|
|
9b0e9bb35b | ||
|
|
c6e65e8c76 | ||
|
|
c1dfc9502a | ||
|
|
93850eb021 | ||
|
|
4fb3ca32e3 | ||
|
|
50c946537a | ||
|
|
8d0d508838 | ||
|
|
9bf4953911 | ||
|
|
f019b29cdf | ||
|
|
3189e0e7b3 | ||
|
|
c56ccc21eb | ||
|
|
193d514def | ||
|
|
f28261a0bb | ||
|
|
242a50af62 | ||
|
|
6b98dfcf46 | ||
|
|
fc71583c6c | ||
|
|
4517191532 | ||
|
|
686f2a7784 | ||
|
|
1f015576ed | ||
|
|
e3e3dcc423 | ||
|
|
e60676e8cb | ||
|
|
17dca649e9 | ||
|
|
6498dde3e9 | ||
|
|
2263f0000b | ||
|
|
2fe6813cbe | ||
|
|
f82e6e023c | ||
|
|
99750627c1 | ||
|
|
e16d88d861 | ||
|
|
e6eb7a269d | ||
|
|
73681878c8 | ||
|
|
8c5a01c96e | ||
|
|
05e6992c06 | ||
|
|
d6c3e05ebf | ||
|
|
d544949e95 | ||
|
|
e9fbfdfcf4 | ||
|
|
59c7470af1 | ||
|
|
7b723bd02b | ||
|
|
8dd8536440 | ||
|
|
3368bb1bcd | ||
|
|
1e77c0a6bb | ||
|
|
9b8708fda4 | ||
|
|
85c4874dc9 | ||
|
|
abef8cbab6 | ||
|
|
4cf5799c0b | ||
|
|
1133f3c2ba | ||
|
|
42282cd88c | ||
|
|
f64cb194bf | ||
|
|
89d063ff88 | ||
|
|
aa448dba49 | ||
|
|
e6bf6d247a | ||
|
|
82c8611f1c | ||
|
|
fa31ddb11d | ||
|
|
2c775ff4ec | ||
|
|
94e33605c2 | ||
|
|
f5931f71c6 | ||
|
|
865eb42313 | ||
|
|
00ca21b2bd | ||
|
|
bd4738d02a | ||
|
|
6695f73294 | ||
|
|
06a4a5b631 | ||
|
|
0c7b6ec667 | ||
|
|
5380702aed | ||
|
|
73c1bbf8b3 | ||
|
|
ae3ea17337 | ||
|
|
e0bd240bff | ||
|
|
6bcdd94d2c | ||
|
|
f84ffa0d90 | ||
|
|
a3a4a4d63e | ||
|
|
27332284e4 | ||
|
|
909717c717 | ||
|
|
0b3969f313 | ||
|
|
c52205378a | ||
|
|
02ba01033c | ||
|
|
844ab7e803 | ||
|
|
e9f84e4b6d | ||
|
|
41e0dd4af3 | ||
|
|
b1d8c50901 | ||
|
|
dd3e061cd6 | ||
|
|
54d3d963c4 | ||
|
|
3fe1a9c624 | ||
|
|
ca53e42145 | ||
|
|
8093335ef9 | ||
|
|
6fe3fa2999 | ||
|
|
65685ddd90 | ||
|
|
6e594b7029 | ||
|
|
6cf80df699 | ||
|
|
8a083490ac | ||
|
|
ed6c5a91d6 | ||
|
|
9c2ed6edea | ||
|
|
547c8f35fd | ||
|
|
024e35889f | ||
|
|
5b86092759 | ||
|
|
ce05a9f7fb | ||
|
|
fac5c08bce | ||
|
|
2c41b1f3ff | ||
|
|
cb0248d29a | ||
|
|
3f4173f84d | ||
|
|
d261ad011f | ||
|
|
52f29d1304 | ||
|
|
a44d4d7f22 | ||
|
|
230e1e011a | ||
|
|
385f78a95b | ||
|
|
bce1226de3 | ||
|
|
618a0f659c | ||
|
|
ad1b5b9db4 | ||
|
|
42d35ba8a7 | ||
|
|
2feb08ac70 | ||
|
|
2b413b08b5 | ||
|
|
d07729b758 | ||
|
|
18e06c0c2c | ||
|
|
a11241605e | ||
|
|
5c12dbb41c | ||
|
|
39b89edfa6 | ||
|
|
1699576ce1 | ||
|
|
815155eac1 | ||
|
|
4e3d9aed38 | ||
|
|
15cd1da118 | ||
|
|
567fc08fa6 | ||
|
|
9d44324e78 | ||
|
|
3b572911e5 | ||
|
|
50e4625835 | ||
|
|
c229e475e5 | ||
|
|
340aac3d03 | ||
|
|
df907dbb09 | ||
|
|
66dc95b3b6 | ||
|
|
d5a483e737 | ||
|
|
58529eb865 | ||
|
|
34ce08a0f4 | ||
|
|
ea63406afa | ||
|
|
3291460e42 | ||
|
|
a912cf9b87 | ||
|
|
6e0f2a12d5 | ||
|
|
923415707d | ||
|
|
757eba3d51 | ||
|
|
7d07db75b1 | ||
|
|
2b0c5d1337 | ||
|
|
ec73115cd1 | ||
|
|
99f63d1440 | ||
|
|
2263796fb9 | ||
|
|
133186f4ff | ||
|
|
e9992f0b4c | ||
|
|
3cb58d73b2 | ||
|
|
8b4d5134f9 | ||
|
|
efe4708a0b | ||
|
|
304b997b4c | ||
|
|
53e2246246 | ||
|
|
f4dee3cb7f | ||
|
|
76ea7f412d | ||
|
|
5c14669bd5 | ||
|
|
5a7df8f6cd | ||
|
|
c8220dd4f2 | ||
|
|
905819fc3b | ||
|
|
0dd38dc957 | ||
|
|
cca01edadd | ||
|
|
483ea106a6 | ||
|
|
ef582d88a9 | ||
|
|
6eacf630e8 | ||
|
|
1c4604efac | ||
|
|
ce46d6aee6 | ||
|
|
5d5f5fbad4 | ||
|
|
4b77129d2a | ||
|
|
54db526c32 | ||
|
|
826c33b3b8 | ||
|
|
36819f5939 | ||
|
|
be7be1683e | ||
|
|
fba2e6f2f3 | ||
|
|
76effec5a7 | ||
|
|
f31132b435 | ||
|
|
03efd25d96 | ||
|
|
147af0c298 | ||
|
|
6e76d9f76a | ||
|
|
52c44c577a | ||
|
|
a86115622e | ||
|
|
581a942f02 | ||
|
|
c4842873d5 | ||
|
|
f413008cc6 | ||
|
|
b7463e7449 | ||
|
|
31d77dc7f0 | ||
|
|
b4ff075607 | ||
|
|
7ca52b9ce3 | ||
|
|
fcb646100d | ||
|
|
362913c9cf | ||
|
|
d713915867 | ||
|
|
c43ad81b99 | ||
|
|
b42a51818d | ||
|
|
cfdc8bfcac | ||
|
|
52faa80e5e | ||
|
|
b4a022c86d | ||
|
|
7628ea4f28 | ||
|
|
098890ed36 | ||
|
|
b6ac55b9d3 | ||
|
|
46e54907dd | ||
|
|
9d79828026 | ||
|
|
01ca1a5e3a | ||
|
|
2c942a0a52 | ||
|
|
4cc27e9559 | ||
|
|
513372082f | ||
|
|
af722a9bb9 | ||
|
|
a386f4ec4b | ||
|
|
f6fcea576b | ||
|
|
a3fb3ebca7 | ||
|
|
ced7a769e4 | ||
|
|
4cb8fa3443 | ||
|
|
dd331dc29f | ||
|
|
5bcbf4c611 | ||
|
|
104322bfd8 | ||
|
|
53da783331 | ||
|
|
b8d295f18e | ||
|
|
27141e61ac | ||
|
|
9c53397ab4 | ||
|
|
14ce81716f | ||
|
|
d9bf79f17a | ||
|
|
df96b78d02 | ||
|
|
0ffc3cfe0e | ||
|
|
deed76baa5 | ||
|
|
8d756ed032 | ||
|
|
b3acf94d0f | ||
|
|
77c5655d89 | ||
|
|
f94f8e27e0 | ||
|
|
7fac743d42 | ||
|
|
4aa1fe76af | ||
|
|
6d174b430f | ||
|
|
e4cce5e9a6 | ||
|
|
4f03299ace | ||
|
|
dfcb532250 | ||
|
|
7cf3fdc8ee | ||
|
|
b83ba3bd05 | ||
|
|
3096be4d02 | ||
|
|
8eed81aaee | ||
|
|
d4a2919ce6 | ||
|
|
f77c0563a5 | ||
|
|
0ccdbe2af4 | ||
|
|
cc4ce44d64 | ||
|
|
97b166538a | ||
|
|
c574e8b1f9 | ||
|
|
5f1078f5d0 | ||
|
|
98b52c69e0 | ||
|
|
c1762aa45a | ||
|
|
3fef9cf4fb | ||
|
|
84774570dc | ||
|
|
8fe404c4ec | ||
|
|
ac42631e3d | ||
|
|
39d8a8b7e3 | ||
|
|
1910e210da | ||
|
|
5d134d2d26 |
14
.coveragerc
14
.coveragerc
@ -1,14 +0,0 @@
|
||||
[run]
|
||||
branch = True
|
||||
source = argon2
|
||||
|
||||
[paths]
|
||||
source =
|
||||
src/argon2
|
||||
.tox/*/lib/python*/site-packages/argon2
|
||||
.tox/pypy*/site-packages/argon2
|
||||
|
||||
[report]
|
||||
show_missing = True
|
||||
omit =
|
||||
src/argon2/_ffi_build.py
|
||||
3
.git_archival.txt
Normal file
3
.git_archival.txt
Normal file
@ -0,0 +1,3 @@
|
||||
node: $Format:%H$
|
||||
node-date: $Format:%cI$
|
||||
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
|
||||
16
.github/CODE_OF_CONDUCT.md
vendored
Normal file
16
.github/CODE_OF_CONDUCT.md
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
# Code of Conduct
|
||||
|
||||
While not being a [Python Software Foundation](https://www.python.org/psf-landing/) project, everyone interacting in this project is expected to follow the [PSF Code of Conduct](https://policies.python.org/python.org/code-of-conduct/).
|
||||
|
||||
In general, this means that everyone is expected to be **open**, **considerate**, and **respectful** of others no matter what their position is within the project.
|
||||
|
||||
|
||||
## Enforcement
|
||||
|
||||
We take Code of Conduct violations seriously, and will act to ensure our spaces are welcoming, inclusive, and professional environments to communicate in.
|
||||
|
||||
If you need to raise a Code of Conduct report, you may do so privately by email to [Hynek Schlawack](mailto:hs@ox.cx).
|
||||
|
||||
Reports will be treated confidentially.
|
||||
|
||||
Alternately you can make a [report to the Python Software Foundation](https://policies.python.org/python.org/code-of-conduct/Procedures-for-Reporting-Incidents/).
|
||||
55
.github/CODE_OF_CONDUCT.rst
vendored
55
.github/CODE_OF_CONDUCT.rst
vendored
@ -1,55 +0,0 @@
|
||||
Contributor Covenant Code of Conduct
|
||||
====================================
|
||||
|
||||
Our Pledge
|
||||
----------
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
Our Standards
|
||||
-------------
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
Our Responsibilities
|
||||
--------------------
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
Scope
|
||||
-----
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
|
||||
Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
||||
Representation of a project may be further defined and clarified by project maintainers.
|
||||
|
||||
Enforcement
|
||||
-----------
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at hs@ox.cx.
|
||||
All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances.
|
||||
The project team is obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||
|
||||
Attribution
|
||||
-----------
|
||||
|
||||
This Code of Conduct is adapted from the `Contributor Covenant <https://www.contributor-covenant.org>`_, version 1.4, available at <https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>.
|
||||
206
.github/CONTRIBUTING.md
vendored
Normal file
206
.github/CONTRIBUTING.md
vendored
Normal file
@ -0,0 +1,206 @@
|
||||
# How To Contribute
|
||||
|
||||
First off, thank you for considering contributing!
|
||||
It's people like *you* who make it is such a great tool for everyone.
|
||||
|
||||
This document is mainly to help you to get started by codifying tribal knowledge and expectations and make it more accessible to everyone.
|
||||
But don't be afraid to open half-finished PRs and ask questions if something is unclear!
|
||||
|
||||
|
||||
## Workflow
|
||||
|
||||
- No contribution is too small!
|
||||
Please submit as many fixes for typos and grammar bloopers as you can!
|
||||
- Try to limit each pull request to *one* change only.
|
||||
- Since we squash on merge, it's up to you how you handle updates to the main branch.
|
||||
Whether you prefer to rebase on main or merge main into your branch, do whatever is more comfortable for you.
|
||||
- *Always* add tests and docs for your code.
|
||||
This is a hard rule; patches with missing tests or documentation can't be merged.
|
||||
- Make sure your changes pass our [CI].
|
||||
You won't get any feedback until it's green unless you ask for it.
|
||||
- For the CI to pass, the coverage must be 100%.
|
||||
If you have problems to test something, open anyway and ask for advice.
|
||||
In some situations, we may agree to add an `# pragma: no cover`.
|
||||
- Once you've addressed review feedback, make sure to bump the pull request with a short note, so we know you're done.
|
||||
- Don’t break backwards-compatibility.
|
||||
|
||||
|
||||
## Local development environment
|
||||
|
||||
First, **fork** the repository on GitHub and **clone** it using one of the alternatives that you can copy-paste by pressing the big green button labeled `<> Code`.
|
||||
|
||||
You can (and should) run our test suite using [*tox*](https://tox.wiki/).
|
||||
However, you'll probably want a more traditional environment as well.
|
||||
|
||||
We recommend using the Python version from the `.python-version-default` file in the project's root directory, because that's the one that is used in the CI by default, too.
|
||||
|
||||
If you're using [*direnv*](https://direnv.net), you can automate the creation of the project virtual environment with the correct Python version by adding the following `.envrc` to the project root:
|
||||
|
||||
```bash
|
||||
layout python python$(cat .python-version-default)
|
||||
```
|
||||
|
||||
or, if you like [*uv*](https://github.com/astral-sh/uv):
|
||||
|
||||
```bash
|
||||
test -d .venv || uv venv --python python$(cat .python-version-default)
|
||||
. .venv/bin/activate
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
> - **Before** you start working on a new pull request, use the "*Sync fork*" button in GitHub's web UI to ensure your fork is up to date.
|
||||
> - **Always create a new branch off `main` for each new pull request.**
|
||||
> Yes, you can work on `main` in your fork and submit pull requests.
|
||||
> But this will *inevitably* lead to you not being able to synchronize your fork with upstream and having to start over.
|
||||
|
||||
Change into the newly created directory and after activating a virtual environment, install an editable version of this project along with its tests requirements:
|
||||
|
||||
```console
|
||||
$ pip install -e . --group dev # or `uv pip install -e . --group dev`
|
||||
```
|
||||
|
||||
Now you can run the test suite:
|
||||
|
||||
```console
|
||||
$ python -Im pytest
|
||||
```
|
||||
|
||||
When working on the documentation, use:
|
||||
|
||||
```console
|
||||
$ tox run -e docs-watch
|
||||
```
|
||||
|
||||
This will build the documentation, and then watch for changes and rebuild it whenever you save a file.
|
||||
|
||||
To just build the documentation and run doctests, use:
|
||||
|
||||
```console
|
||||
$ tox run -e docs
|
||||
```
|
||||
|
||||
You will find the built documentation in `docs/_build/html`.
|
||||
|
||||
To avoid committing code that violates our style guide, we strongly advise you to install [*pre-commit*] and its hooks:
|
||||
|
||||
```console
|
||||
$ pre-commit install
|
||||
```
|
||||
|
||||
This is not strictly necessary, because our [*tox*] file contains an environment that runs:
|
||||
|
||||
```console
|
||||
$ pre-commit run --all-files
|
||||
```
|
||||
|
||||
and our CI has integration with [*pre-commit.ci*](https://pre-commit.ci).
|
||||
But it's way more comfortable to run it locally and *git* catching avoidable errors.
|
||||
|
||||
|
||||
## Code
|
||||
|
||||
- Obey [PEP 8](https://www.python.org/dev/peps/pep-0008/) and [PEP 257](https://www.python.org/dev/peps/pep-0257/).
|
||||
We use the `"""`-on-separate-lines style for docstrings and [Napoleon](https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html) for parsing them:
|
||||
|
||||
```python
|
||||
def func(x: str, y: bool) -> int:
|
||||
"""
|
||||
Do something.
|
||||
|
||||
Args:
|
||||
x: A very important parameter.
|
||||
|
||||
y:
|
||||
Another important parameter whose description is too long for one
|
||||
line, therefore it starts on the next line.
|
||||
|
||||
Returns:
|
||||
Something!
|
||||
"""
|
||||
```
|
||||
- If you add or change public APIs, tag the docstring using `.. versionadded:: 16.0.0 WHAT` or `.. versionchanged:: 16.2.0 WHAT`.
|
||||
|
||||
- We use [Ruff](https://ruff.rs/) to sort our imports and format our code with a line length of 79 characters.
|
||||
As long as you run our full [*tox*] suite before committing, or install our [*pre-commit*] hooks (ideally you'll do both – see [*Local Development Environment*](#local-development-environment) above), you won't have to spend any time on formatting your code at all.
|
||||
If you don't, [CI] will catch it for you – but that seems like a waste of your time!
|
||||
|
||||
|
||||
## Tests
|
||||
|
||||
- Write your asserts as `expected == actual` to line them up nicely:
|
||||
|
||||
```python
|
||||
x = f()
|
||||
|
||||
assert 42 == x.some_attribute
|
||||
assert "foo" == x._a_private_attribute
|
||||
```
|
||||
|
||||
- To run the test suite, all you need is a recent [*tox*].
|
||||
It will ensure the test suite runs with all dependencies against all Python versions just as it will in our [CI].
|
||||
|
||||
- Write [good test docstrings](https://jml.io/pages/test-docstrings.html).
|
||||
|
||||
|
||||
## Documentation
|
||||
|
||||
- Use [semantic newlines] in [*reStructuredText*](https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html) and [Markdown](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax) files (files ending in `.rst` and `.md`):
|
||||
|
||||
```rst
|
||||
This is a sentence.
|
||||
This is another sentence.
|
||||
```
|
||||
|
||||
|
||||
### Changelog
|
||||
|
||||
If your change is noteworthy, there needs to be a changelog entry in `CHANGELOG.md`.
|
||||
|
||||
- The changelog follows the [*Keep a Changelog*](https://keepachangelog.com/en/1.0.0/) standard.
|
||||
Please add the best-fitting section if it's missing for the current release.
|
||||
We use the following order: `Security`, `Removed`, `Deprecated`, `Added`, `Changed`, `Fixed`.
|
||||
- As with other docs, please use [semantic newlines] in the changelog.
|
||||
- Make the last line a link to your pull request.
|
||||
You probably have to open it first to know the number.
|
||||
- Wrap symbols like modules, functions, or classes into backticks so they are rendered in a `monospace font`.
|
||||
- Wrap arguments into asterisks like in docstrings:
|
||||
`Added new argument *an_argument*.`
|
||||
- If you mention functions or other callables, add parentheses at the end of their names:
|
||||
`argon2_cffi.func()` or `argon2_cffi.Class.method()`.
|
||||
This makes the changelog a lot more readable.
|
||||
- Prefer simple past tense or constructions with "now".
|
||||
For example:
|
||||
|
||||
* Added `argon2_cffi.func()`.
|
||||
* `argon2_cffi.func()` now doesn't crash the Large Hadron Collider anymore when passed the *foobar* argument.
|
||||
|
||||
|
||||
#### Example entries
|
||||
|
||||
```markdown
|
||||
Added `argon2_cffi.func()`.
|
||||
The feature really *is* awesome.
|
||||
```
|
||||
|
||||
or:
|
||||
|
||||
```markdown
|
||||
`argon2_cffi.func()` now doesn't crash the Large Hadron Collider anymore when passed the *foobar* argument.
|
||||
The bug really *was* nasty.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Again, this list is mainly to help you to get started by codifying tribal knowledge and expectations.
|
||||
If something is unclear, feel free to ask for help!
|
||||
|
||||
Please note that this project is released with a Contributor [Code of Conduct](https://github.com/hynek/argon2-cffi/blob/main/.github/CODE_OF_CONDUCT.md).
|
||||
By participating in this project you agree to abide by its terms.
|
||||
Please report any harm to [Hynek Schlawack] in any way you find appropriate.
|
||||
|
||||
|
||||
[CI]: https://github.com/hynek/argon2-cffi/actions
|
||||
[Hynek Schlawack]: https://hynek.me/about/
|
||||
[*pre-commit*]: https://pre-commit.com/
|
||||
[*tox*]: https://https://tox.wiki/
|
||||
[semantic newlines]: https://rhodesmill.org/brandon/2012/one-sentence-per-line/
|
||||
51
.github/CONTRIBUTING.rst
vendored
51
.github/CONTRIBUTING.rst
vendored
@ -1,51 +0,0 @@
|
||||
How To Contribute
|
||||
=================
|
||||
|
||||
Every open source project lives from the generous help by contributors that sacrifice their time and ``argon2_cffi`` is no different.
|
||||
|
||||
Here are a few guidelines to get you started:
|
||||
|
||||
- If you want to install a *development version* of ``argon2_cffi`` into your current ``virtualenv``, you have to remember to:
|
||||
|
||||
#. ``git submodule init`` (to initialize git submodule mechanics)
|
||||
#. ``git submodule update`` (to update the vendored Argon2 C library to the version ``argon2_cffi`` is currently packaging)
|
||||
#. ``python setup.py build`` (to build the CFFI module)
|
||||
#. ``pip install -e .[dev]`` (to [re-]install it along with the Python code and test dependencies)
|
||||
|
||||
You have to perform steps 2, 3, and 4 whenever something changes in the Argon2 C code (e.g. if the vendored code has been updated).
|
||||
|
||||
- Try to limit each pull request to one change only.
|
||||
- To run the test suite, all you need is a recent tox_.
|
||||
It will ensure the test suite runs with all dependencies against all Python versions just as it will on `Travis CI`_.
|
||||
If you lack some Python versions, you can can make it a non-failure using ``tox --skip-missing-interpreters`` (in that case you may want to look into pyenv_ that makes it very easy to install many different Python versions in parallel).
|
||||
|
||||
One of the environments requires a system-wide installation of Argon2.
|
||||
On macOS, it's available in Homebrew and recent Ubuntus (zesty and later) ship it too.
|
||||
- Make sure your changes pass our CI.
|
||||
You won't get any feedback until it's green unless you ask for it.
|
||||
- Once you've addressed review feedback, make sure to bump the pull request with a short note, so we know you're done.
|
||||
- If your change is noteworthy, add an entry to the changelog_.
|
||||
Use semantic newlines and add a link to your pull request.
|
||||
- No contribution is too small; please submit as many fixes for typos and grammar bloopers as you can!
|
||||
- Don’t break backward compatibility.
|
||||
- *Always* add tests and docs for your code.
|
||||
This is a hard rule; patches with missing tests or documentation won’t be merged.
|
||||
- Write `good test docstrings`_.
|
||||
- Obey `PEP 8`_ and `PEP 257`_.
|
||||
|
||||
Please note that this project is released with a Contributor `Code of Conduct`_.
|
||||
By participating in this project you agree to abide by its terms.
|
||||
Please report any harm to `Hynek Schlawack`_ in any way you find appropriate.
|
||||
|
||||
Thank you for considering to contribute!
|
||||
|
||||
|
||||
.. _Hynek Schlawack: https://hynek.me/about/
|
||||
.. _`PEP 8`: https://www.python.org/dev/peps/pep-0008/
|
||||
.. _`PEP 257`: https://www.python.org/dev/peps/pep-0257/
|
||||
.. _`good test docstrings`: https://jml.io/pages/test-docstrings.html
|
||||
.. _`Code of Conduct`: https://github.com/hynek/argon2_cffi/blob/master/.github/CODE_OF_CONDUCT.rst
|
||||
.. _changelog: https://github.com/hynek/argon2_cffi/blob/master/CHANGELOG.rst
|
||||
.. _`tox`: https://tox.readthedocs.io/
|
||||
.. _`Travis CI`: https://travis-ci.org/
|
||||
.. _pyenv: https://github.com/pyenv/pyenv
|
||||
3
.github/FUNDING.yml
vendored
Normal file
3
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
---
|
||||
github: hynek
|
||||
tidelift: "pypi/argon2_cffi"
|
||||
33
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
33
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
# Summary
|
||||
|
||||
<!-- Please tell us what your pull request is about here. -->
|
||||
|
||||
|
||||
# Pull Request Check List
|
||||
|
||||
<!--
|
||||
This is just a friendly reminder about the most common mistakes.
|
||||
Please make sure that you tick all boxes.
|
||||
But please read our [contribution guide](https://github.com/hynek/argon2-cffi/blob/main/.github/CONTRIBUTING.md) at least once; it will save you unnecessary review cycles!
|
||||
|
||||
If an item doesn't apply to your pull request, **check it anyway** to make it apparent that there's nothing left to do.
|
||||
-->
|
||||
|
||||
- [ ] Do **not** open pull requests from your `main` branch – **use a separate branch**!
|
||||
- There's a ton of footguns waiting if you don't heed this warning. You can still go back to your project, create a branch from your main branch, push it, and open the pull request from the new branch.
|
||||
- This is not a pre-requisite for your pull request to be accepted, but **you have been warned**.
|
||||
- [ ] Added **tests** for changed code.
|
||||
- The CI fails with less than 100% coverage.
|
||||
- [ ] **New APIs** are added to our typing tests in [`api.py`](https://github.com/hynek/argon2-cffi/blob/main/tests/typing/api.py).
|
||||
- [ ] Updated **documentation** for changed code.
|
||||
- [ ] New functions/classes have to be added to `docs/api.rst` by hand.
|
||||
- [ ] Changed/added classes/methods/functions have appropriate `versionadded`, `versionchanged`, or `deprecated` [directives](http://www.sphinx-doc.org/en/stable/markup/para.html#directive-versionadded).
|
||||
- The next version is the second number in the current release + 1. The first number represents the current year. So if the current version on PyPI is 23.1.0, the next version is gonna be 23.2.0. If the next version is the first in the new year, it'll be 24.1.0.
|
||||
- [ ] Documentation in `.rst` and `.md` files is written using [**semantic newlines**](https://rhodesmill.org/brandon/2012/one-sentence-per-line/).
|
||||
- [ ] Changes (and possible deprecations) are documented in the [**changelog**](https://github.com/hynek/argon2-cffi/blob/main/CHANGELOG.md).
|
||||
- [ ] Consider granting [push permissions to the PR branch](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork), so maintainers can fix minor issues themselves without pestering you.
|
||||
|
||||
<!--
|
||||
If you have *any* questions to *any* of the points above, just **submit and ask**!
|
||||
This checklist is here to *help* you, not to deter you from contributing!
|
||||
-->
|
||||
18
.github/SECURITY.md
vendored
Normal file
18
.github/SECURITY.md
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
We follow [Calendar Versioning](https://calver.org) with generous backwards-compatibility guarantees.
|
||||
Therefore, we only support the latest version.
|
||||
|
||||
That said, you shouldn't be afraid to upgrade if you're only using our documented public APIs and pay attention to `DeprecationWarning`s.
|
||||
Whenever there is a need to break compatibility, it is announced in the changelog and raises a `DeprecationWarning` for a year (if possible) before it's finally really broken.
|
||||
|
||||
> [!WARNING]
|
||||
> What explicitly *may* change over time are the default [hashing parameters](https://argon2-cffi.readthedocs.io/en/stable/parameters.html) and the behavior of the [CLI interface](https://argon2-cffi.readthedocs.io/en/stable/cli.html).
|
||||
|
||||
|
||||
## Security contact information
|
||||
|
||||
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security).
|
||||
Tidelift will coordinate the fix and disclosure.
|
||||
14
.github/dependabot.yml
vendored
Normal file
14
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
---
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: github-actions
|
||||
directory: /
|
||||
schedule:
|
||||
interval: monthly
|
||||
cooldown:
|
||||
# https://blog.yossarian.net/2025/11/21/We-should-all-be-using-dependency-cooldowns
|
||||
default-days: 7
|
||||
groups:
|
||||
github-actions:
|
||||
patterns:
|
||||
- "*"
|
||||
265
.github/workflows/ci.yml
vendored
Normal file
265
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,265 @@
|
||||
---
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
tags: ["*"]
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
FORCE_COLOR: "1" # Make tools pretty.
|
||||
PIP_DISABLE_PIP_VERSION_CHECK: "1"
|
||||
PIP_NO_PYTHON_VERSION_WARNING: "1"
|
||||
|
||||
permissions: {}
|
||||
|
||||
|
||||
jobs:
|
||||
build-package:
|
||||
name: Build & verify package
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
|
||||
- uses: hynek/build-and-inspect-python-package@fe0a0fb1925ca263d076ca4f2c13e93a6e92a33e # v2.17.0
|
||||
id: baipp
|
||||
|
||||
outputs:
|
||||
# Used to define the matrix for tests below. The value is based on
|
||||
# packaging metadata (trove classifiers).
|
||||
python-versions: ${{ steps.baipp.outputs.supported_python_classifiers_json_array }}
|
||||
|
||||
|
||||
tests:
|
||||
name: Tests & Mypy API on ${{ matrix.python-version }}
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-package
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
# Created by the build-and-inspect-python-package action above.
|
||||
python-version: ${{ fromJson(needs.build-package.outputs.python-versions) }}
|
||||
|
||||
env:
|
||||
PYTHON: ${{ matrix.python-version }}
|
||||
|
||||
steps:
|
||||
- name: Download pre-built packages
|
||||
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: Packages
|
||||
path: dist
|
||||
- run: |
|
||||
tar xf dist/*.tar.gz --strip-components=1
|
||||
rm -rf src
|
||||
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
allow-prereleases: true
|
||||
- uses: hynek/setup-cached-uv@4300ec2180bc77d705e626a34e381b81a4772c51 # v2.5.0
|
||||
|
||||
- name: Run tests
|
||||
run: >
|
||||
uvx --with tox-uv tox run
|
||||
--installpkg dist/*.whl
|
||||
-f py${PYTHON//./}-tests
|
||||
|
||||
- name: Upload coverage data
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: coverage-data-${{ matrix.python-version }}
|
||||
path: .coverage.*
|
||||
include-hidden-files: true
|
||||
if-no-files-found: ignore
|
||||
|
||||
- name: Check public API with Mypy
|
||||
run: >
|
||||
uvx --with tox-uv tox run
|
||||
--installpkg dist/*.whl
|
||||
-e py${PYTHON//./}-mypy
|
||||
|
||||
free-threading:
|
||||
name: Test free-threaded builds on ${{ matrix.python-version }}
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-package
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version:
|
||||
- 3.14t
|
||||
env:
|
||||
PYTHON: ${{ matrix.python-version }}
|
||||
|
||||
steps:
|
||||
- name: Download pre-built packages
|
||||
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: Packages
|
||||
path: dist
|
||||
- run: |
|
||||
tar xf dist/*.tar.gz --strip-components=1
|
||||
rm -rf src
|
||||
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
allow-prereleases: true
|
||||
- uses: hynek/setup-cached-uv@4300ec2180bc77d705e626a34e381b81a4772c51 # v2.5.0
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
uv venv --python $PYTHON
|
||||
# cffi 2 is required and currently beta.
|
||||
uv pip install --prerelease=allow dist/*.whl --group dev
|
||||
|
||||
.venv/bin/python -Im pytest tests
|
||||
|
||||
|
||||
coverage:
|
||||
name: Ensure 100% test coverage
|
||||
runs-on: ubuntu-latest
|
||||
needs: tests
|
||||
if: always()
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
with:
|
||||
python-version-file: .python-version-default
|
||||
- uses: hynek/setup-cached-uv@4300ec2180bc77d705e626a34e381b81a4772c51 # v2.5.0
|
||||
|
||||
- name: Download coverage data
|
||||
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
pattern: coverage-data-*
|
||||
merge-multiple: true
|
||||
|
||||
- name: Combine coverage and fail if it's <100%.
|
||||
run: |
|
||||
uv tool install coverage
|
||||
|
||||
coverage combine
|
||||
coverage html --skip-covered --skip-empty
|
||||
|
||||
# Report and write to summary.
|
||||
coverage report --format=markdown >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
# Report again and fail if under 100%.
|
||||
coverage report --fail-under=100
|
||||
|
||||
- name: Upload HTML report if check failed.
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: html-report
|
||||
path: htmlcov
|
||||
if: ${{ failure() }}
|
||||
|
||||
|
||||
system-package:
|
||||
name: Install & test with system package of Argon2
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-package
|
||||
|
||||
steps:
|
||||
- name: Download pre-built packages
|
||||
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: Packages
|
||||
path: dist
|
||||
- run: tar xf dist/*.tar.gz --strip-components=1
|
||||
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
with:
|
||||
python-version-file: .python-version-default
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get install libargon2-1 libargon2-dev
|
||||
python -VV
|
||||
python -Im site
|
||||
python -Im pip install --upgrade tox
|
||||
|
||||
- run: python -Im tox run -e system-argon2
|
||||
|
||||
typing:
|
||||
name: Check types using supported type checkers
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-package
|
||||
|
||||
steps:
|
||||
- name: Download pre-built packages
|
||||
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: Packages
|
||||
path: dist
|
||||
- run: tar xf dist/*.tar.gz --strip-components=1
|
||||
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
with:
|
||||
python-version-file: .python-version-default
|
||||
- uses: hynek/setup-cached-uv@4300ec2180bc77d705e626a34e381b81a4772c51 # v2.5.0
|
||||
|
||||
- run: uvx --with tox-uv tox run -f typing
|
||||
|
||||
docs:
|
||||
name: Run doctests
|
||||
needs: build-package
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Download pre-built packages
|
||||
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: Packages
|
||||
path: dist
|
||||
- run: tar xf dist/*.tar.gz --strip-components=1
|
||||
- uses: hynek/setup-cached-uv@4300ec2180bc77d705e626a34e381b81a4772c51 # v2.5.0
|
||||
|
||||
- run: >
|
||||
uvx --with tox-uv
|
||||
tox run -e docs-doctests
|
||||
|
||||
|
||||
install-dev:
|
||||
name: Verify dev env
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
with:
|
||||
python-version-file: .python-version-default
|
||||
|
||||
- name: Install in dev mode and run CLI
|
||||
run: |
|
||||
python -Im pip install -e . --group dev
|
||||
python -Im argon2 -n 1 -t 1 -m 8 -p 1
|
||||
|
||||
|
||||
required-checks-pass:
|
||||
if: always()
|
||||
name: Ensure everything required is passing for branch protection
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- coverage
|
||||
- typing
|
||||
- docs
|
||||
- install-dev
|
||||
- system-package
|
||||
|
||||
steps:
|
||||
- name: Decide whether the needed jobs succeeded or failed
|
||||
uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
|
||||
with:
|
||||
jobs: ${{ toJSON(needs) }}
|
||||
40
.github/workflows/codeql-analysis.yml
vendored
Normal file
40
.github/workflows/codeql-analysis.yml
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
---
|
||||
name: CodeQL
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "30 22 * * 4"
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [python]
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
|
||||
77
.github/workflows/pypi-package.yml
vendored
Normal file
77
.github/workflows/pypi-package.yml
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
---
|
||||
name: Build & upload PyPI package
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
tags: ["*"]
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
workflow_dispatch:
|
||||
|
||||
|
||||
jobs:
|
||||
# Always build & lint package.
|
||||
build-package:
|
||||
name: Build & verify package
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
attestations: write
|
||||
id-token: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
|
||||
- uses: hynek/build-and-inspect-python-package@fe0a0fb1925ca263d076ca4f2c13e93a6e92a33e # v2.17.0
|
||||
with:
|
||||
attest-build-provenance-github: 'true'
|
||||
|
||||
|
||||
# Upload to Test PyPI on every commit on main.
|
||||
release-test-pypi:
|
||||
name: Publish in-dev package to test.pypi.org
|
||||
environment: release-test-pypi
|
||||
if: github.repository_owner == 'hynek' && github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-package
|
||||
|
||||
permissions:
|
||||
id-token: write
|
||||
|
||||
steps:
|
||||
- name: Download packages built by build-and-inspect-python-package
|
||||
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: Packages
|
||||
path: dist
|
||||
|
||||
- name: Upload package to Test PyPI
|
||||
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
|
||||
with:
|
||||
repository-url: https://test.pypi.org/legacy/
|
||||
|
||||
|
||||
# Upload to real PyPI on GitHub Releases.
|
||||
release-pypi:
|
||||
name: Publish released package to pypi.org
|
||||
environment: release-pypi
|
||||
if: github.repository_owner == 'hynek' && github.event.action == 'published'
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-package
|
||||
|
||||
permissions:
|
||||
id-token: write
|
||||
|
||||
steps:
|
||||
- name: Download packages built by build-and-inspect-python-package
|
||||
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: Packages
|
||||
path: dist
|
||||
|
||||
- name: Upload package to PyPI
|
||||
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
|
||||
39
.github/workflows/zizmor.yml
vendored
Normal file
39
.github/workflows/zizmor.yml
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
# https://github.com/woodruffw/zizmor
|
||||
name: Zizmor
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
pull_request:
|
||||
branches: ["*"]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
|
||||
jobs:
|
||||
zizmor:
|
||||
name: Zizmor latest via PyPI
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
security-events: write
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: hynek/setup-cached-uv@4300ec2180bc77d705e626a34e381b81a4772c51 # v2.5.0
|
||||
|
||||
- name: Run zizmor 🌈
|
||||
run: uvx zizmor --format sarif . > results.sarif
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Upload SARIF file
|
||||
uses: github/codeql-action/upload-sarif@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
|
||||
with:
|
||||
# Path to SARIF file relative to the root of the repository
|
||||
sarif_file: results.sarif
|
||||
# Optional category for the results
|
||||
# Used to differentiate multiple results for one commit
|
||||
category: zizmor
|
||||
23
.gitignore
vendored
23
.gitignore
vendored
@ -1,15 +1,16 @@
|
||||
dist
|
||||
.tox
|
||||
.eggs
|
||||
*.pyc
|
||||
.DS_Store
|
||||
.cache
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
src/argon2/_ffi.py
|
||||
__pycache__
|
||||
*.pyc
|
||||
*.egg-info
|
||||
*.dylib
|
||||
*.so
|
||||
.direnv
|
||||
.envrc
|
||||
.hypothesis
|
||||
_build
|
||||
.mypy_cache
|
||||
.pytest_cache/
|
||||
.tox
|
||||
.vscode
|
||||
__pycache__
|
||||
dist
|
||||
docs/_build/
|
||||
Justfile
|
||||
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +0,0 @@
|
||||
[submodule "libargon2"]
|
||||
path = extras/libargon2
|
||||
url = https://github.com/p-h-c/phc-winner-argon2
|
||||
@ -1,16 +1,30 @@
|
||||
---
|
||||
ci:
|
||||
autoupdate_schedule: monthly
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/ambv/black
|
||||
rev: 18.6b4
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.15.12
|
||||
hooks:
|
||||
- id: black
|
||||
language_version: python3.6
|
||||
- repo: https://github.com/asottile/seed-isort-config
|
||||
rev: v1.0.1
|
||||
- id: ruff-check
|
||||
args: [--fix, --exit-non-zero-on-fix]
|
||||
- id: ruff-format
|
||||
|
||||
- repo: https://github.com/econchick/interrogate
|
||||
rev: 1.7.0
|
||||
hooks:
|
||||
- id: seed-isort-config
|
||||
language_version: python3.6
|
||||
- repo: https://github.com/pre-commit/mirrors-isort
|
||||
rev: v4.3.4
|
||||
- id: interrogate
|
||||
args: [tests]
|
||||
|
||||
- repo: https://github.com/codespell-project/codespell
|
||||
rev: v2.4.2
|
||||
hooks:
|
||||
- id: isort
|
||||
language_version: python3.6
|
||||
- id: codespell
|
||||
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v6.0.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
- id: check-toml
|
||||
- id: check-yaml
|
||||
|
||||
1
.python-version-default
Normal file
1
.python-version-default
Normal file
@ -0,0 +1 @@
|
||||
3.13
|
||||
20
.readthedocs.yaml
Normal file
20
.readthedocs.yaml
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
version: 2
|
||||
|
||||
build:
|
||||
os: ubuntu-lts-latest
|
||||
tools:
|
||||
# Keep version in sync with tox.ini/docs.
|
||||
python: "3.13"
|
||||
jobs:
|
||||
create_environment:
|
||||
# Need the tags to calculate the version (sometimes).
|
||||
- git fetch --tags
|
||||
|
||||
- asdf plugin add uv
|
||||
- asdf install uv latest
|
||||
- asdf global uv latest
|
||||
|
||||
build:
|
||||
html:
|
||||
- uvx --with tox-uv tox run -e docs-build -- $READTHEDOCS_OUTPUT
|
||||
@ -1,6 +0,0 @@
|
||||
---
|
||||
python:
|
||||
version: 3
|
||||
pip_install: true
|
||||
extra_requirements:
|
||||
- docs
|
||||
88
.travis.yml
88
.travis.yml
@ -1,88 +0,0 @@
|
||||
dist: trusty
|
||||
group: travis_latest
|
||||
sudo: false
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.cache/pip
|
||||
- $HOME/argon2_cffi/.eggs
|
||||
git:
|
||||
# We do this by hand depending on TOXENV.
|
||||
submodules: false
|
||||
|
||||
|
||||
language: python
|
||||
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
||||
include:
|
||||
- python: "2.7"
|
||||
env: TOXENV=py27
|
||||
- python: "3.4"
|
||||
env: TOXENV=py34
|
||||
- python: "3.5"
|
||||
env: TOXENV=py35
|
||||
- python: "3.6"
|
||||
env: TOXENV=py36
|
||||
- python: "3.7"
|
||||
env: TOXENV=py37
|
||||
dist: xenial
|
||||
sudo: true
|
||||
- python: "pypy"
|
||||
env: TOXENV=pypy
|
||||
- python: "pypy3"
|
||||
env: TOXENV=pypy3
|
||||
|
||||
# Meta
|
||||
- python: "3.6"
|
||||
env: TOXENV=lint
|
||||
- python: "3.6"
|
||||
env: TOXENV=manifest
|
||||
- python: "3.6"
|
||||
env: TOXENV=docs
|
||||
- python: "3.6"
|
||||
env: TOXENV=readme
|
||||
- python: "3.6"
|
||||
env: TOXENV=system-argon2
|
||||
|
||||
# Prevent breakage by new releases
|
||||
- python: "3.6-dev"
|
||||
env: TOXENV=py36
|
||||
- python: "3.7-dev"
|
||||
env: TOXENV=py37
|
||||
|
||||
allow_failures:
|
||||
- python: "3.6-dev"
|
||||
- python: "3.7-dev"
|
||||
|
||||
|
||||
install:
|
||||
- pip install tox
|
||||
|
||||
|
||||
script:
|
||||
- tox
|
||||
|
||||
|
||||
before_install:
|
||||
- pip install codecov
|
||||
- |
|
||||
if [[ "${TOXENV}" == "system-argon2" ]]; then
|
||||
wget http://de.archive.ubuntu.com/ubuntu/pool/universe/a/argon2/libargon2-0_0~20161029-1_amd64.deb
|
||||
wget http://de.archive.ubuntu.com/ubuntu/pool/universe/a/argon2/libargon2-0-dev_0~20161029-1_amd64.deb
|
||||
sudo dpkg -i libargon2-0_0~20161029-1_amd64.deb
|
||||
sudo dpkg -i libargon2-0-dev_0~20161029-1_amd64.deb
|
||||
else
|
||||
# If the system argon2 library should not be used, clone the submodule containing the vendored argon2 library
|
||||
git submodule update --init --recursive
|
||||
fi
|
||||
|
||||
|
||||
after_success:
|
||||
- tox -e coverage-report
|
||||
- codecov
|
||||
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
61
AUTHORS.rst
61
AUTHORS.rst
@ -1,61 +0,0 @@
|
||||
Credits & License
|
||||
=================
|
||||
|
||||
``argon2_cffi`` is maintained by Hynek Schlawack and released under the `MIT license <https://github.com/hynek/argon2_cffi/blob/master/LICENSE>`_.
|
||||
|
||||
The development is kindly supported by `Variomedia AG <https://www.variomedia.de/>`_.
|
||||
|
||||
A full list of contributors can be found in GitHub's `overview <https://github.com/hynek/argon2_cffi/graphs/contributors>`_.
|
||||
|
||||
|
||||
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 <https://blake2.net>`_ code in ``src/blake2/`` is copyright (c) Samuel Neves, 2013-2015, and under CC0_ license.
|
||||
|
||||
The authors of Argon2 also were very helpful to get the library to compile on ancient versions of Visual Studio for ancient versions of Python.
|
||||
|
||||
The documentation also quotes frequently from the Argon2 paper_ to avoid mistakes by rephrasing.
|
||||
|
||||
.. _CC0: https://creativecommons.org/publicdomain/zero/1.0/
|
||||
.. _paper: https://password-hashing.net/argon2-specs.pdf
|
||||
|
||||
msinttypes
|
||||
^^^^^^^^^^
|
||||
|
||||
In order to be able to compile on Visual Studio 2008 and Visual Studio 2010 which are required for Python 2.7 and 3.4 respectively, we also ship two C headers with integer types.
|
||||
They are from the `msinttypes project <https://code.google.com/archive/p/msinttypes>`_ (`auto-import on GitHub <https://github.com/chemeris/msinttypes>`_) 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:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. 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.
|
||||
3. 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.
|
||||
333
CHANGELOG.md
Normal file
333
CHANGELOG.md
Normal file
@ -0,0 +1,333 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Calendar Versioning](https://calver.org/).
|
||||
|
||||
The **first number** of the version is the year.
|
||||
The **second number** is incremented with each release, starting at 1 for each year.
|
||||
The **third number** is when we need to start branches for older releases (only for emergencies).
|
||||
|
||||
You can find our backwards-compatibility policy [here](https://github.com/hynek/argon2-cffi/blob/main/.github/SECURITY.md).
|
||||
|
||||
<!-- changelog follows -->
|
||||
|
||||
|
||||
## [Unreleased](https://github.com/hynek/argon2-cffi/compare/25.1.0...HEAD)
|
||||
|
||||
|
||||
## [25.1.0](https://github.com/hynek/argon2-cffi/compare/23.1.0...25.1.0) - 2025-06-03
|
||||
|
||||
### Added
|
||||
|
||||
- Official support for Python 3.13 and 3.14.
|
||||
No code changes were necessary.
|
||||
|
||||
|
||||
### Removed
|
||||
|
||||
- Python 3.7 and 3.8 are not supported anymore.
|
||||
[#186](https://github.com/hynek/argon2-cffi/pull/186)
|
||||
|
||||
|
||||
### Changed
|
||||
|
||||
- `argon2.PasswordHasher.check_needs_rehash()` now also accepts bytes like the rest of the API.
|
||||
[#174](https://github.com/hynek/argon2-cffi/pull/174)
|
||||
|
||||
- Improved parameter compatibility handling for Pyodide / WebAssembly environments.
|
||||
[#190](https://github.com/hynek/argon2-cffi/pull/190)
|
||||
|
||||
|
||||
## [23.1.0](https://github.com/hynek/argon2-cffi/compare/21.3.0...23.1.0) - 2023-08-15
|
||||
|
||||
### Removed
|
||||
|
||||
- Python 3.6 is not supported anymore.
|
||||
|
||||
|
||||
### Deprecated
|
||||
|
||||
- The `InvalidHash` exception is deprecated in favor of `InvalidHashError`.
|
||||
No plans for removal currently exist and the names can (but shouldn't) be used interchangeably.
|
||||
|
||||
- `argon2.hash_password()`, `argon2.hash_password_raw()`, and `argon2.verify_password()` that have been soft-deprecated since 2016 are now hard-deprecated.
|
||||
They now raise `DeprecationWarning`s and will be removed in 2024.
|
||||
|
||||
|
||||
### Added
|
||||
|
||||
- Official support for Python 3.11 and 3.12.
|
||||
No code changes were necessary.
|
||||
|
||||
- `argon2.exceptions.InvalidHashError` as a replacement for `InvalidHash`.
|
||||
|
||||
- *salt* parameter to `argon2.PasswordHasher.hash()` to allow for custom salts.
|
||||
This is only useful for specialized use-cases -- leave it on None unless you know exactly what you are doing.
|
||||
[#153](https://github.com/hynek/argon2-cffi/pull/153)
|
||||
|
||||
|
||||
## [21.3.0](https://github.com/hynek/argon2-cffi/compare/21.2.0...21.3.0) - 2021-12-11
|
||||
|
||||
### Fixed
|
||||
|
||||
- While the last release added type hints, the fact that it's been missing a `py.typed` file made Mypy ignore them.
|
||||
[#113](https://github.com/hynek/argon2-cffi/pull/113)
|
||||
|
||||
|
||||
## [21.2.0](https://github.com/hynek/argon2-cffi/compare/21.1.0...21.2.0) - 2021-12-08
|
||||
|
||||
### Removed
|
||||
|
||||
- Python 3.5 is not supported anymore.
|
||||
|
||||
- The CFFI bindings have been extracted into a separate project: [*argon2-cffi-bindings*]
|
||||
This makes *argon2-cffi* a Python-only project und should make it easier to contribute to and have more frequent releases with high-level features.
|
||||
|
||||
This change is breaking for users who want to use a system-wide installation of Argon2 instead of our vendored code, because the argument to the ``--no-binary`` argument changed.
|
||||
Please refer to the [installation guide](https://argon2-cffi.readthedocs.io/en/stable/installation.html).
|
||||
|
||||
|
||||
### Added
|
||||
|
||||
- Thanks to lots of work within [*argon2-cffi-bindings*], there're pre-compiled wheels for many new platforms.
|
||||
Including:
|
||||
- Apple Silicon via `universal2`
|
||||
- Linux on `amd64` and `arm64`
|
||||
- [*musl libc*](https://musl.libc.org) ([Alpine Linux!](https://www.alpinelinux.org)) on `i686`, `amd64`, and `arm64`
|
||||
- PyPy 3.8
|
||||
|
||||
We hope to provide wheels for Windows on `arm64` soon, but are waiting for GitHub Actions to support that.
|
||||
|
||||
- `argon2.Parameters.from_parameters()` together with the `argon2.profiles` module that offers easy access to the RFC-recommended configuration parameters and then some.
|
||||
[#101](https://github.com/hynek/argon2-cffi/pull/101)
|
||||
[#110](https://github.com/hynek/argon2-cffi/pull/110)
|
||||
|
||||
- The CLI interface now has a `--profile` option that takes any name from `argon2.profiles`.
|
||||
|
||||
- Types!
|
||||
*argon2-cffi* is now fully typed.
|
||||
[#112](https://github.com/hynek/argon2-cffi/pull/112)
|
||||
|
||||
|
||||
### Changed
|
||||
|
||||
- `argon2.PasswordHasher` now uses the RFC 9106 low-memory profile by default.
|
||||
The old defaults are available as `argon2.profiles.PRE_21_2`.
|
||||
|
||||
|
||||
## [21.1.0](https://github.com/hynek/argon2-cffi/compare/20.1.0...21.1.0) - 2021-08-29
|
||||
|
||||
Vendoring Argon2 @ [62358ba](https://github.com/P-H-C/phc-winner-argon2/tree/62358ba2123abd17fccf2a108a301d4b52c01a7c) (20190702)
|
||||
|
||||
### Removed
|
||||
|
||||
- Microsoft stopped providing the necessary SDKs to ship Python 2.7 wheels and currently the downloads amount to 0.09%.
|
||||
Therefore we have decided that Python 2.7 is not supported anymore.
|
||||
|
||||
|
||||
### Changed
|
||||
|
||||
- There are indeed no changes whatsoever to the code of *argon2-cffi*.
|
||||
The Argon2 project also hasn't tagged a new release since July 2019.
|
||||
There also don't seem to be any important pending fixes.
|
||||
|
||||
This release is mainly about improving the way binary wheels are built (`abi3` on all platforms).
|
||||
|
||||
|
||||
## [20.1.0](https://github.com/hynek/argon2-cffi/compare/19.2.0...20.1.0) - 2020-05-11
|
||||
|
||||
Vendoring Argon2 @ [62358ba](https://github.com/P-H-C/phc-winner-argon2/tree/62358ba2123abd17fccf2a108a301d4b52c01a7c) (20190702)
|
||||
|
||||
|
||||
### Added
|
||||
|
||||
- It is now possible to manually override the detection of SSE2 using the `ARGON2_CFFI_USE_SSE2` environment variable.
|
||||
|
||||
|
||||
## [19.2.0](https://github.com/hynek/argon2-cffi/compare/18.3.0...19.1.0) - 2019-10-27
|
||||
|
||||
Vendoring Argon2 @ [62358ba](https://github.com/P-H-C/phc-winner-argon2/tree/62358ba2123abd17fccf2a108a301d4b52c01a7c) (20190702)
|
||||
|
||||
### Removed
|
||||
|
||||
- Python 3.4 is not supported anymore. It has been unsupported by the Python core team for a while now and its PyPI downloads are negligible.
|
||||
|
||||
It's very unlikely that *argon2-cffi* will break under 3.4 anytime soon, but we don't test it and don't ship binary wheels for it anymore.
|
||||
|
||||
### Fixed
|
||||
|
||||
- The dependency on `enum34` is now protected using a PEP 508 marker.
|
||||
This fixes problems when the sdist is handled by a different interpreter version than the one running it.
|
||||
[#48](https://github.com/hynek/argon2-cffi/issues/48)
|
||||
|
||||
|
||||
## [19.1.0](https://github.com/hynek/argon2-cffi/compare/18.3.0...19.1.0) - 2019-01-17
|
||||
|
||||
Vendoring Argon2 @ [670229c](https://github.com/P-H-C/phc-winner-argon2/tree/670229c849b9fe882583688b74eb7dfdc846f9f6) (20171227)
|
||||
|
||||
### Added
|
||||
|
||||
- Added support for Argon2 v1.2 hashes in `argon2.extract_parameters()`.
|
||||
|
||||
|
||||
## [18.3.0](https://github.com/hynek/argon2-cffi/compare/18.2.0...18.3.0) - 2018-08-19
|
||||
|
||||
Vendoring Argon2 @ [670229c](https://github.com/P-H-C/phc-winner-argon2/tree/670229c849b9fe882583688b74eb7dfdc846f9f6) (20171227)
|
||||
|
||||
### Added
|
||||
|
||||
- `argon2.PasswordHasher`'s hash type is configurable now.
|
||||
|
||||
|
||||
## [18.2.0](https://github.com/hynek/argon2-cffi/compare/18.1.0...18.2.0) - 2018-08-19
|
||||
|
||||
Vendoring Argon2 @ [670229c](https://github.com/P-H-C/phc-winner-argon2/tree/670229c849b9fe882583688b74eb7dfdc846f9f6) (20171227)
|
||||
|
||||
### Changed
|
||||
|
||||
- The hash type for `argon2.PasswordHasher` is Argon2**id** now.
|
||||
|
||||
This decision has been made based on the recommendations in the latest [Argon2 RFC draft](https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-argon2-04#section-4).
|
||||
[#33](https://github.com/hynek/argon2-cffi/issues/33)
|
||||
[#34](https://github.com/hynek/argon2-cffi/pull/34)
|
||||
|
||||
- Some of the hash parameters have been made stricter to be closer to said recommendations.
|
||||
The current goal for a hash verification times is around 50ms.
|
||||
[#41](https://github.com/hynek/argon2-cffi/pull/41)
|
||||
|
||||
### Added
|
||||
|
||||
- To make the change of hash type backward compatible, `argon2.PasswordHasher.verify()` now determines the type of the hash and verifies it accordingly.
|
||||
|
||||
- To allow for bespoke decisions about upgrading Argon2 parameters, it's now possible to extract them from a hash via the `argon2.extract_parameters()` function.
|
||||
[#41](https://github.com/hynek/argon2-cffi/pull/41)
|
||||
|
||||
- Additionally `argon2.PasswordHasher` now has a `check_needs_rehash()` method that allows to verify whether a hash has been created with the instance's parameters or whether it should be rehashed.
|
||||
[#41](https://github.com/hynek/argon2-cffi/pull/41)
|
||||
|
||||
|
||||
## [18.1.0](https://github.com/hynek/argon2-cffi/compare/16.3.0...18.1.0) - 2018-01-06
|
||||
|
||||
Vendoring Argon2 @ [670229c](https://github.com/P-H-C/phc-winner-argon2/tree/670229c849b9fe882583688b74eb7dfdc846f9f6) (20171227)
|
||||
|
||||
### Added
|
||||
|
||||
- It is now possible to use the *argon2-cffi* bindings against an Argon2 library that is provided by the system.
|
||||
|
||||
|
||||
## [16.3.0](https://github.com/hynek/argon2-cffi/compare/16.2.0...16.3.0) - 2016-11-10
|
||||
|
||||
Vendoring Argon2 @ [1c4fc41f81f358283755eea88d4ecd05e43b7fd3](https://github.com/P-H-C/phc-winner-argon2/tree/1c4fc41f81f358283755eea88d4ecd05e43b7fd3) (20161029)
|
||||
|
||||
### Added
|
||||
|
||||
- Add low-level bindings for Argon2id functions.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Prevent side-effects like the installation of `cffi` if `setup.py` is called with a command that doesn't require it.
|
||||
[#20](https://github.com/hynek/argon2-cffi/pull/20)
|
||||
- Fix a bunch of warnings with new `cffi` versions and Python 3.6.
|
||||
[#14](https://github.com/hynek/argon2-cffi/pull/14)
|
||||
[#16](https://github.com/hynek/argon2-cffi/issues/16)
|
||||
|
||||
|
||||
## [16.2.0](https://github.com/hynek/argon2-cffi/compare/16.1.0...16.2.0) - 2016-09-10
|
||||
|
||||
Vendoring Argon2 @ [4844d2fee15d44cb19296ddf36029326d17c5aa3](https://github.com/P-H-C/phc-winner-argon2/tree/4844d2fee15d44cb19296ddf36029326d17c5aa3)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed compilation on Debian 8 (Jessie).
|
||||
[#13](https://github.com/hynek/argon2-cffi/pull/13)
|
||||
|
||||
|
||||
## [16.1.0](https://github.com/hynek/argon2-cffi/compare/16.0.0...16.1.0) - 2016-04-19
|
||||
|
||||
Vendoring Argon2 @ [00aaa6604501fade85853a4b2f5695611ff6e7c5](https://github.com/P-H-C/phc-winner-argon2/tree/00aaa6604501fade85853a4b2f5695611ff6e7c5).
|
||||
|
||||
### Added
|
||||
|
||||
- Add `VerifyMismatchError` that is raised if verification fails only because of a password/hash mismatch.
|
||||
It's a subclass of `VerificationError` therefore this change is completely backwards-compatible.
|
||||
|
||||
### Changed
|
||||
|
||||
- Add support for [Argon2 1.3](https://mailarchive.ietf.org/arch/msg/cfrg/beOzPh41Hz3cjl5QD7MSRNTi3lA/).
|
||||
Old hashes remain functional but opportunistic rehashing is strongly recommended.
|
||||
|
||||
### Removed
|
||||
|
||||
- Python 3.3 and 2.6 aren't supported anymore.
|
||||
They may work by chance but any support to them has been ceased.
|
||||
|
||||
The last Python 2.6 release was on October 29, 2013 and isn't supported by the CPython core team anymore.
|
||||
Major Python packages like Django and Twisted dropped Python 2.6 a while ago already.
|
||||
|
||||
Python 3.3 never had a significant user base and wasn't part of any distribution's LTS release.
|
||||
|
||||
|
||||
## [16.0.0](https://github.com/hynek/argon2-cffi/compare/15.0.1...16.0.0) - 2016-01-02
|
||||
|
||||
Vendoring Argon2 @ [421dafd2a8af5cbb215e16da5953663eb101d139](https://github.com/P-H-C/phc-winner-argon2/tree/421dafd2a8af5cbb215e16da5953663eb101d139).
|
||||
|
||||
### Deprecated
|
||||
|
||||
- `hash_password()`, `hash_password_raw()`, and `verify_password()` should not be used anymore.
|
||||
For hashing passwords, use the new `argon2.PasswordHasher`.
|
||||
If you want to implement your own higher-level abstractions, use the new low-level APIs `hash_secret()`, `hash_secret_raw()`, and `verify_secret()` from the `argon2.low_level` module.
|
||||
If you want to go *really* low-level, `core()` is for you.
|
||||
The old functions will *not* raise any warnings though and there are *no* immediate plans to remove them.
|
||||
|
||||
### Added
|
||||
|
||||
- Added `argon2.PasswordHasher`.
|
||||
A higher-level class specifically for hashing passwords that also works on Unicode strings.
|
||||
- Added `argon2.low_level` module with low-level API bindings for building own high-level abstractions.
|
||||
|
||||
|
||||
## [15.0.1](https://github.com/hynek/argon2-cffi/compare/15.0.0...15.0.1) - 2015-12-18
|
||||
|
||||
Vendoring Argon2 @ [4fe0d8cda37691228dd5a96a310be57369403a4b](https://github.com/P-H-C/phc-winner-argon2/tree/4fe0d8cda37691228dd5a96a310be57369403a4b).
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix `long_description` on PyPI.
|
||||
|
||||
|
||||
## [15.0.0](https://github.com/hynek/argon2-cffi/compare/15.0.0b5...15.0.0) - 2015-12-18
|
||||
|
||||
Vendoring Argon2 @ [4fe0d8cda37691228dd5a96a310be57369403a4b](https://github.com/P-H-C/phc-winner-argon2/tree/4fe0d8cda37691228dd5a96a310be57369403a4b).
|
||||
|
||||
### Added
|
||||
|
||||
- Conditionally use the [SSE2](https://en.wikipedia.org/wiki/SSE2)-optimized version of `argon2` on x86 architectures.
|
||||
|
||||
### Changed
|
||||
|
||||
- `verify_password()` doesn't guess the hash type if passed `None` anymore.
|
||||
Supporting this resulted in measurable overhead (~0.6ms vs 0.8ms on my notebook) since it had to happen in Python.
|
||||
That means that naïve usage of the API would give attackers an edge.
|
||||
The new behavior is that it has the same default value as `hash_password()` such that `verify_password(hash_password(b"password"), b"password")` still works.
|
||||
- Tweaked default parameters to more reasonable values.
|
||||
Verification should take between 0.5ms and 1ms on recent-ish hardware.
|
||||
|
||||
### Fixed
|
||||
|
||||
- More packaging fixes.
|
||||
Most notably compilation on Visual Studio 2010 for Python 3.3 and 3.4.
|
||||
|
||||
|
||||
## [15.0.0b5](https://github.com/hynek/argon2-cffi/tree/15.0.0b5) - 2015-12-10
|
||||
|
||||
Vendoring Argon2 @ [4fe0d8cda37691228dd5a96a310be57369403a4b](https://github.com/P-H-C/phc-winner-argon2/tree/4fe0d8cda37691228dd5a96a310be57369403a4b).
|
||||
|
||||
### Added
|
||||
|
||||
- Initial work.
|
||||
Previous betas were only for fixing Windows packaging.
|
||||
The authors of Argon2 were kind enough to [help me](https://github.com/P-H-C/phc-winner-argon2/issues/44) to get it building under Visual Studio 2008 that we’re forced to use for Python 2.7 on Windows.
|
||||
|
||||
|
||||
[*argon2-cffi-bindings*]: https://github.com/hynek/argon2-cffi-bindings
|
||||
212
CHANGELOG.rst
212
CHANGELOG.rst
@ -1,212 +0,0 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
Versions are year-based with a strict backward compatibility policy.
|
||||
The third digit is only for regressions.
|
||||
|
||||
|
||||
18.3.0 (2018-08-19)
|
||||
-------------------
|
||||
|
||||
Vendoring Argon2 @ `670229c <https://github.com/P-H-C/phc-winner-argon2/tree/670229c849b9fe882583688b74eb7dfdc846f9f6>`_ (20171227)
|
||||
|
||||
|
||||
Backward-incompatible changes:
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
*none*
|
||||
|
||||
|
||||
Deprecations:
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
*none*
|
||||
|
||||
|
||||
Changes:
|
||||
^^^^^^^^
|
||||
|
||||
- ``argon2.PasswordHasher``'s hash type is configurable now.
|
||||
|
||||
|
||||
----
|
||||
|
||||
|
||||
18.2.0 (2018-08-19)
|
||||
-------------------
|
||||
|
||||
Vendoring Argon2 @ `670229c <https://github.com/P-H-C/phc-winner-argon2/tree/670229c849b9fe882583688b74eb7dfdc846f9f6>`_ (20171227)
|
||||
|
||||
|
||||
Changes:
|
||||
^^^^^^^^
|
||||
|
||||
- The hash type for ``argon2.PasswordHasher`` is Argon2\ **id** now.
|
||||
|
||||
This decision has been made based on the recommendations in the latest `Argon2 RFC draft <https://tools.ietf.org/html/draft-irtf-cfrg-argon2-03#section-4>`_.
|
||||
`#33 <https://github.com/hynek/argon2_cffi/pull/33>`_
|
||||
`#34 <https://github.com/hynek/argon2_cffi/pull/34>`_
|
||||
- To make the change of hash type backward compatible, ``argon2.PasswordHasher.verify()`` now determines the type of the hash and verifies it accordingly.
|
||||
- Some of the hash parameters have been made stricter to be closer to said recommendations.
|
||||
The current goal for a hash verification times is around 50ms.
|
||||
`#41 <https://github.com/hynek/argon2_cffi/pull/41>`_
|
||||
- To allow for bespoke decisions about upgrading Argon2 parameters, it's now possible to extract them from a hash via the ``argon2.extract_parameters()`` function.
|
||||
`#41 <https://github.com/hynek/argon2_cffi/pull/41>`_
|
||||
- Additionally ``argon2.PasswordHasher`` now has a ``check_needs_rehash()`` method that allows to verify whether a hash has been created with the instance's parameters or whether it should be rehashed.
|
||||
`#41 <https://github.com/hynek/argon2_cffi/pull/41>`_
|
||||
|
||||
|
||||
----
|
||||
|
||||
|
||||
18.1.0 (2018-01-06)
|
||||
-------------------
|
||||
|
||||
Vendoring Argon2 @ `670229c <https://github.com/P-H-C/phc-winner-argon2/tree/670229c849b9fe882583688b74eb7dfdc846f9f6>`_ (20171227)
|
||||
|
||||
|
||||
Changes:
|
||||
^^^^^^^^
|
||||
|
||||
- It is now possible to use the ``argon2_cffi`` bindings against an Argon2 library that is provided by the system.
|
||||
|
||||
|
||||
----
|
||||
|
||||
|
||||
16.3.0 (2016-11-10)
|
||||
-------------------
|
||||
|
||||
Vendoring Argon2 @ `1c4fc41f81f358283755eea88d4ecd05e43b7fd3 <https://github.com/P-H-C/phc-winner-argon2/tree/1c4fc41f81f358283755eea88d4ecd05e43b7fd3>`_ (20161029)
|
||||
|
||||
Changes:
|
||||
^^^^^^^^
|
||||
|
||||
- Prevent side-effects like the installation of ``cffi`` if ``setup.py`` is called with a command that doesn't require it.
|
||||
`#20 <https://github.com/hynek/argon2_cffi/pull/20>`_
|
||||
- Fix a bunch of warnings with new ``cffi`` versions and Python 3.6.
|
||||
`#14 <https://github.com/hynek/argon2_cffi/pull/14>`_
|
||||
`#16 <https://github.com/hynek/argon2_cffi/pull/16>`_
|
||||
- Add low-level bindings for Argon2id functions.
|
||||
|
||||
|
||||
----
|
||||
|
||||
|
||||
16.2.0 (2016-09-10)
|
||||
-------------------
|
||||
|
||||
Vendoring Argon2 @ `4844d2fee15d44cb19296ddf36029326d17c5aa3 <https://github.com/P-H-C/phc-winner-argon2/tree/4844d2fee15d44cb19296ddf36029326d17c5aa3>`_
|
||||
|
||||
Changes:
|
||||
^^^^^^^^
|
||||
|
||||
- Fix compilation on debian jessie.
|
||||
`#13 <https://github.com/hynek/argon2_cffi/pull/13>`_
|
||||
|
||||
|
||||
----
|
||||
|
||||
|
||||
16.1.0 (2016-04-19)
|
||||
-------------------
|
||||
|
||||
Vendoring Argon2 @ 00aaa6604501fade85853a4b2f5695611ff6e7c5_.
|
||||
|
||||
Backward-incompatible changes:
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Python 3.3 and 2.6 aren't supported anymore.
|
||||
They may work by chance but any support to them has been ceased.
|
||||
|
||||
The last Python 2.6 release was on October 29, 2013 and isn't supported by the CPython core team anymore.
|
||||
Major Python packages like Django and Twisted dropped Python 2.6 a while ago already.
|
||||
|
||||
Python 3.3 never had a significant user base and wasn't part of any distribution's LTS release.
|
||||
|
||||
Changes:
|
||||
^^^^^^^^
|
||||
|
||||
- Add ``VerifyMismatchError`` that is raised if verification fails only because of a password/hash mismatch.
|
||||
It's a subclass of ``VerificationError`` therefore this change is completely backward compatible.
|
||||
- Add support for `Argon2 1.3 <https://www.ietf.org/mail-archive/web/cfrg/current/msg07948.html>`_.
|
||||
Old hashes remain functional but opportunistic rehashing is strongly recommended.
|
||||
|
||||
|
||||
----
|
||||
|
||||
|
||||
16.0.0 (2016-01-02)
|
||||
-------------------
|
||||
|
||||
Vendoring Argon2 @ 421dafd2a8af5cbb215e16da5953663eb101d139_.
|
||||
|
||||
Deprecations:
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
- ``hash_password()``, ``hash_password_raw()``, and ``verify_password()`` should not be used anymore.
|
||||
For hashing passwords, use the new ``argon2.PasswordHasher``.
|
||||
If you want to implement your own higher-level abstractions, use the new low-level APIs ``hash_secret()``, ``hash_secret_raw()``, and ``verify_secret()`` from the ``argon2.low_level`` module.
|
||||
If you want to go *really* low-level, ``core()`` is for you.
|
||||
The old functions will *not* raise any warnings though and there are *no* immediate plans to remove them.
|
||||
|
||||
Changes:
|
||||
^^^^^^^^
|
||||
|
||||
- Add ``argon2.PasswordHasher``.
|
||||
A higher-level class specifically for hashing passwords that also works on Unicode strings.
|
||||
- Add ``argon2.low_level`` module with low-level API bindings for building own high-level abstractions.
|
||||
|
||||
|
||||
----
|
||||
|
||||
|
||||
15.0.1 (2015-12-18)
|
||||
-------------------
|
||||
|
||||
Vendoring Argon2 @ 4fe0d8cda37691228dd5a96a310be57369403a4b_.
|
||||
|
||||
Changes:
|
||||
^^^^^^^^
|
||||
|
||||
- Fix ``long_description`` on PyPI.
|
||||
|
||||
|
||||
----
|
||||
|
||||
|
||||
15.0.0 (2015-12-18)
|
||||
-------------------
|
||||
|
||||
Vendoring Argon2 @ 4fe0d8cda37691228dd5a96a310be57369403a4b_.
|
||||
|
||||
Changes:
|
||||
^^^^^^^^
|
||||
|
||||
- ``verify_password()`` doesn't guess the hash type if passed ``None`` anymore.
|
||||
Supporting this resulted in measurable overhead (~ 0.6ms vs 0.8ms on my notebook) since it had to happen in Python.
|
||||
That means that naïve usage of the API would give attackers an edge.
|
||||
The new behavior is that it has the same default value as ``hash_password()`` such that ``verify_password(hash_password(b"password"), b"password")`` still works.
|
||||
- Conditionally use the `SSE2 <https://en.wikipedia.org/wiki/SSE2>`_-optimized version of ``argon2`` on x86 architectures.
|
||||
- More packaging fixes.
|
||||
Most notably compilation on Visual Studio 2010 for Python 3.3 and 3.4.
|
||||
- Tweaked default parameters to more reasonable values.
|
||||
Verification should take between 0.5ms and 1ms on recent-ish hardware.
|
||||
|
||||
|
||||
----
|
||||
|
||||
|
||||
15.0.0b5 (2015-12-10)
|
||||
---------------------
|
||||
|
||||
Vendoring Argon2 @ 4fe0d8cda37691228dd5a96a310be57369403a4b_.
|
||||
|
||||
Initial work.
|
||||
Previous betas were only for fixing Windows packaging.
|
||||
The authors of Argon2 were kind enough to `help me <https://github.com/P-H-C/phc-winner-argon2/issues/44>`_ to get it building under Visual Studio 2008 that we’re forced to use for Python 2.7 on Windows.
|
||||
|
||||
|
||||
.. _421dafd2a8af5cbb215e16da5953663eb101d139: https://github.com/P-H-C/phc-winner-argon2/tree/421dafd2a8af5cbb215e16da5953663eb101d139
|
||||
.. _4fe0d8cda37691228dd5a96a310be57369403a4b: https://github.com/P-H-C/phc-winner-argon2/tree/4fe0d8cda37691228dd5a96a310be57369403a4b
|
||||
.. _00aaa6604501fade85853a4b2f5695611ff6e7c5: https://github.com/P-H-C/phc-winner-argon2/tree/00aaa6604501fade85853a4b2f5695611ff6e7c5
|
||||
27
FAQ.md
Normal file
27
FAQ.md
Normal file
@ -0,0 +1,27 @@
|
||||
# Frequently Asked Questions
|
||||
|
||||
## I'm using *bcrypt* / *PBKDF2* / *scrypt* / *yescrypt*, do I need to migrate?
|
||||
|
||||
Using password hashes that aren't memory hard carries a certain risk but there's **no immediate danger or need for action**.
|
||||
If however you are deciding how to hash password *today*, Argon2 is the superior, future-proof choice.
|
||||
|
||||
But if you already use one of the hashes mentioned in the question, you should be fine for the foreseeable future.
|
||||
If you're using *scrypt* or *yescrypt*, you will be probably fine for good.
|
||||
|
||||
|
||||
## Why do the `verify()` methods raise an Exception instead of returning `False`?
|
||||
|
||||
1. The Argon2 library had no concept of a "wrong password" error in the beginning.
|
||||
Therefore when writing these bindings, an exception with the full error had to be raised so you could inspect what went actually wrong.
|
||||
|
||||
Changing that now would be a very dangerous break of backwards-compatibility.
|
||||
|
||||
2. In my opinion, a wrong password should raise an exception such that it can't pass unnoticed by accident.
|
||||
See also The Zen of Python: "Errors should never pass silently."
|
||||
|
||||
3. It's more [Pythonic](https://docs.python.org/3/glossary.html#term-EAFP).
|
||||
|
||||
|
||||
## Does *argon2-cffi* release the GIL?
|
||||
|
||||
[Yes](https://cffi.readthedocs.io/en/latest/ref.html#conversions).
|
||||
18
FAQ.rst
18
FAQ.rst
@ -1,18 +0,0 @@
|
||||
Frequently Asked Questions
|
||||
==========================
|
||||
|
||||
I'm using ``bcrypt``/``PBKDF2``/``scrypt``/``yescrypt``, do I need to migrate?
|
||||
Using password hashes that aren't memory hard carries a certain risk but there's **no immediate danger or need for action**.
|
||||
If however you are deciding how to hash password *today*, Argon2 is the superior, future-proof choice.
|
||||
|
||||
But if you already use one of the hashes mentioned in the question, you should be fine for the foreseeable future.
|
||||
If you're using ``scrypt`` or ``yescrypt``, you will be probably fine for good.
|
||||
|
||||
Why do the ``verify()`` methods raise an Exception instead of returning ``False``?
|
||||
#. The Argon2 library had no concept of a "wrong password" error in the beginning.
|
||||
Therefore when writing these bindings, an exception with the full error had to be raised so you could inspect what went actually wrong.
|
||||
|
||||
It goes without saying that it's impossible to switch now for backward-compatibility reasons.
|
||||
#. In my opinion, a wrong password should raise an exception such that it can't pass unnoticed by accident.
|
||||
See also The Zen of Python: "Errors should never pass silently."
|
||||
#. It's more `Pythonic <https://docs.python.org/3/glossary.html#term-eafp>`_.
|
||||
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Hynek Schlawack
|
||||
Copyright (c) 2015 Hynek Schlawack and the argon2-cffi contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
include *.rst *.txt tox.ini .coveragerc LICENSE .pre-commit-config.yaml pyproject.toml
|
||||
exclude src/argon2/_ffi.py .gitmodules extras/libargon2/.git appveyor.yml .readthedocs.yml .travis.yml codecov.yml
|
||||
graft tests
|
||||
graft .github
|
||||
recursive-exclude tests *.pyc
|
||||
graft extras
|
||||
graft docs
|
||||
prune docs/_build
|
||||
54
README.md
Normal file
54
README.md
Normal file
@ -0,0 +1,54 @@
|
||||
# *argon2-cffi*: Argon2 for Python
|
||||
|
||||
[](https://argon2-cffi.readthedocs.io/)
|
||||
[](https://bestpractices.coreinfrastructure.org/projects/6671)
|
||||
[](https://pypi.org/project/argon2-cffi/)
|
||||
[](https://pepy.tech/project/argon2-cffi)
|
||||
|
||||
<!-- begin short -->
|
||||
<!-- begin pypi -->
|
||||
|
||||
[Argon2](https://github.com/p-h-c/phc-winner-argon2) won the [Password Hashing Competition](https://www.password-hashing.net/) and *argon2-cffi* is the simplest way to use it in Python:
|
||||
|
||||
```pycon
|
||||
>>> from argon2 import PasswordHasher
|
||||
>>> ph = PasswordHasher()
|
||||
>>> hash = ph.hash("correct horse battery staple")
|
||||
>>> hash # doctest: +SKIP
|
||||
'$argon2id$v=19$m=65536,t=3,p=4$MIIRqgvgQbgj220jfp0MPA$YfwJSVjtjSU0zzV/P3S9nnQ/USre2wvJMjfCIjrTQbg'
|
||||
>>> ph.verify(hash, "correct horse battery staple")
|
||||
True
|
||||
>>> ph.check_needs_rehash(hash)
|
||||
False
|
||||
>>> ph.verify(hash, "Tr0ub4dor&3")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
argon2.exceptions.VerifyMismatchError: The password does not match the supplied hash
|
||||
|
||||
```
|
||||
<!-- end short -->
|
||||
|
||||
## Project Links
|
||||
|
||||
- [**PyPI**](https://pypi.org/project/argon2-cffi/)
|
||||
- [**GitHub**](https://github.com/hynek/argon2-cffi)
|
||||
- [**Documentation**](https://argon2-cffi.readthedocs.io/)
|
||||
- [**Changelog**](https://github.com/hynek/argon2-cffi/blob/main/CHANGELOG.md)
|
||||
- [**Funding**](https://hynek.me/say-thanks/)
|
||||
- The low-level Argon2 CFFI bindings are maintained in the separate [*argon2-cffi-bindings*](https://github.com/hynek/argon2-cffi-bindings) project.
|
||||
|
||||
<!-- end pypi -->
|
||||
|
||||
## Credits
|
||||
|
||||
*argon2-cffi* is maintained by [Hynek Schlawack](https://hynek.me/).
|
||||
|
||||
The development is kindly supported by my employer [Variomedia AG](https://www.variomedia.de/), *argon2-cffi* [Tidelift subscribers](https://tidelift.com/?utm_source=lifter&utm_medium=referral&utm_campaign=hynek), and my amazing [GitHub Sponsors](https://github.com/sponsors/hynek).
|
||||
|
||||
|
||||
## *argon2-cffi* for Enterprise
|
||||
|
||||
Available as part of the [Tidelift Subscription](https://tidelift.com/?utm_source=lifter&utm_medium=referral&utm_campaign=hynek).
|
||||
|
||||
The maintainers of *argon2-cffi* and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open-source packages you use to build your applications.
|
||||
Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use.
|
||||
58
README.rst
58
README.rst
@ -1,58 +0,0 @@
|
||||
=====================================
|
||||
CFFI-based Argon2 Bindings for Python
|
||||
=====================================
|
||||
|
||||
.. image:: https://img.shields.io/pypi/v/argon2_cffi.svg
|
||||
:target: https://pypi.org/project/argon2_cffi/
|
||||
:alt: PyPI
|
||||
|
||||
.. image:: https://readthedocs.org/projects/argon2-cffi/badge/?version=stable
|
||||
:target: http://argon2-cffi.readthedocs.io/en/stable/?badge=stable
|
||||
:alt: Documentation Status
|
||||
|
||||
.. image:: https://travis-ci.org/hynek/argon2_cffi.svg?branch=master
|
||||
:target: https://travis-ci.org/hynek/argon2_cffi
|
||||
:alt: Travis CI status
|
||||
|
||||
.. image:: https://ci.appveyor.com/api/projects/status/3faufu7qgwc8nv2v/branch/master?svg=true
|
||||
:target: https://ci.appveyor.com/project/hynek/argon2-cffi
|
||||
:alt: AppVeyor CI Status
|
||||
|
||||
.. image:: https://codecov.io/github/hynek/argon2_cffi/branch/master/graph/badge.svg
|
||||
:target: https://codecov.io/github/hynek/argon2_cffi
|
||||
:alt: Test Coverage
|
||||
|
||||
.. image:: https://www.irccloud.com/invite-svg?channel=%23cryptography-dev&hostname=irc.freenode.net&port=6697&ssl=1
|
||||
:target: https://www.irccloud.com/invite?channel=%23cryptography-dev&hostname=irc.freenode.net&port=6697&ssl=1
|
||||
:alt: IRC
|
||||
|
||||
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
|
||||
:target: https://github.com/ambv/black
|
||||
:alt: Code style: black
|
||||
|
||||
.. teaser-begin
|
||||
|
||||
`Argon2 <https://github.com/p-h-c/phc-winner-argon2>`_ won the `Password Hashing Competition <https://password-hashing.net/>`_ and ``argon2_cffi`` is the simplest way to use it in Python and PyPy:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> from argon2 import PasswordHasher
|
||||
>>> ph = PasswordHasher()
|
||||
>>> hash = ph.hash("s3kr3tp4ssw0rd")
|
||||
>>> hash # doctest: +SKIP
|
||||
'$argon2id$v=19$m=102400,t=2,p=8$tSm+JOWigOgPZx/g44K5fQ$WDyus6py50bVFIPkjA28lQ'
|
||||
>>> ph.verify(hash, "s3kr3tp4ssw0rd")
|
||||
True
|
||||
>>> ph.check_needs_rehash(hash)
|
||||
False
|
||||
>>> ph.verify(hash, "t0t411ywr0ng")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
argon2.exceptions.VerifyMismatchError: The password does not match the supplied hash
|
||||
|
||||
|
||||
.. note::
|
||||
`passlib <https://pypi.org/project/passlib/>`_ 1.7.0 and later offers `Argon2 support <https://passlib.readthedocs.io/en/stable/lib/passlib.hash.argon2.html>`_ using this library too.
|
||||
|
||||
``argon2_cffi``\ ’s documentation lives at `Read the Docs <https://argon2-cffi.readthedocs.io/>`_, the code on `GitHub <https://github.com/hynek/argon2_cffi>`_.
|
||||
It’s rigorously tested on Python 2.7, 3.4+, and PyPy.
|
||||
102
appveyor.yml
102
appveyor.yml
@ -1,102 +0,0 @@
|
||||
environment:
|
||||
global:
|
||||
# SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the
|
||||
# /E:ON and /V:ON options are not enabled in the batch script intepreter
|
||||
# See: http://stackoverflow.com/a/13751649/163740
|
||||
CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\extras\\appveyor\\run_with_env.cmd"
|
||||
|
||||
matrix:
|
||||
|
||||
# See: http://www.appveyor.com/docs/installed-software#python
|
||||
- PYTHON: "C:\\Python27"
|
||||
PYTHON_VERSION: "2.7.x"
|
||||
PYTHON_ARCH: "32"
|
||||
|
||||
- PYTHON: "C:\\Python27-x64"
|
||||
PYTHON_VERSION: "2.7.x"
|
||||
PYTHON_ARCH: "64"
|
||||
|
||||
- PYTHON: "C:\\Python27"
|
||||
PYTHON_VERSION: "2.7.x"
|
||||
PYTHON_ARCH: "32"
|
||||
|
||||
- PYTHON: "C:\\Python27-x64"
|
||||
PYTHON_VERSION: "2.7.x"
|
||||
PYTHON_ARCH: "64"
|
||||
|
||||
- PYTHON: "C:\\Python34"
|
||||
PYTHON_VERSION: "3.4.x"
|
||||
PYTHON_ARCH: "32"
|
||||
|
||||
- PYTHON: "C:\\Python34-x64"
|
||||
PYTHON_VERSION: "3.4.x"
|
||||
PYTHON_ARCH: "64"
|
||||
|
||||
- PYTHON: "C:\\Python35"
|
||||
PYTHON_VERSION: "3.5.x"
|
||||
PYTHON_ARCH: "32"
|
||||
|
||||
- PYTHON: "C:\\Python35-x64"
|
||||
PYTHON_VERSION: "3.5.x"
|
||||
PYTHON_ARCH: "64"
|
||||
|
||||
- PYTHON: "C:\\Python36"
|
||||
PYTHON_VERSION: "3.6.x"
|
||||
PYTHON_ARCH: "32"
|
||||
|
||||
- PYTHON: "C:\\Python36-x64"
|
||||
PYTHON_VERSION: "3.6.x"
|
||||
PYTHON_ARCH: "64"
|
||||
|
||||
|
||||
install:
|
||||
- ECHO "Filesystem root:"
|
||||
- ps: "ls \"C:/\""
|
||||
|
||||
- ECHO "Installed SDKs:"
|
||||
- ps: "ls \"C:/Program Files/Microsoft SDKs/Windows\""
|
||||
|
||||
# Install Python (from the official .msi of http://python.org) and pip when
|
||||
# not already installed.
|
||||
- ps: if (-not(Test-Path($env:PYTHON))) { & extras\appveyor\install.ps1 }
|
||||
|
||||
# Prepend newly installed Python to the PATH of this build (this cannot be
|
||||
# done from inside the powershell script as it would require to restart
|
||||
# the parent CMD process).
|
||||
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
|
||||
|
||||
# Check that we have the expected version and architecture for Python
|
||||
- "python --version"
|
||||
- "python -c \"import struct; print(struct.calcsize('P') * 8)\""
|
||||
|
||||
# Upgrade to the latest version of pip to avoid it displaying warnings
|
||||
# about it being out of date. Also upgrade setuptools.
|
||||
- "python -m pip install --disable-pip-version-check --user --upgrade pip setuptools"
|
||||
|
||||
# Fetch Argon2 submodule.
|
||||
- "git submodule init"
|
||||
- "git submodule update"
|
||||
|
||||
build_script:
|
||||
# Build the compiled extension
|
||||
- "%CMD_IN_ENV% python setup.py build"
|
||||
- "%CMD_IN_ENV% python -m pip install .[tests]"
|
||||
|
||||
test_script:
|
||||
# Run the project tests
|
||||
- "%CMD_IN_ENV% python -m pytest"
|
||||
- "%CMD_IN_ENV% python -m argon2 -n 1 -t 1 -m 8 -p 1"
|
||||
|
||||
after_test:
|
||||
# If tests are successful, create binary packages for the project.
|
||||
- "%CMD_IN_ENV% python -m pip install --upgrade wheel"
|
||||
- "%CMD_IN_ENV% python setup.py bdist_wheel"
|
||||
- ps: "ls dist"
|
||||
|
||||
artifacts:
|
||||
# Archive the generated packages in the ci.appveyor.com build report.
|
||||
- path: dist\*
|
||||
|
||||
#on_success:
|
||||
# - TODO: upload the content of dist/*.whl to a public wheelhouse
|
||||
#
|
||||
10
codecov.yml
10
codecov.yml
@ -1,10 +0,0 @@
|
||||
---
|
||||
comment: false
|
||||
coverage:
|
||||
status:
|
||||
patch:
|
||||
default:
|
||||
target: "100"
|
||||
project:
|
||||
default:
|
||||
target: "100"
|
||||
10
docs/_static/custom.css
vendored
Normal file
10
docs/_static/custom.css
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
@import url('https://rsms.me/inter/inter.css');
|
||||
@import url('https://assets.hynek.me/css/bm.css');
|
||||
|
||||
|
||||
:root {
|
||||
font-feature-settings: 'liga' 1, 'calt' 1; /* fix for Chrome */
|
||||
}
|
||||
@supports (font-variation-settings: normal) {
|
||||
:root { font-family: InterVariable, sans-serif; }
|
||||
}
|
||||
221
docs/api.rst
221
docs/api.rst
@ -3,38 +3,8 @@ API Reference
|
||||
|
||||
.. module:: argon2
|
||||
|
||||
``argon2_cffi`` comes with an high-level API and hopefully reasonable defaults for Argon2 parameters that result in a verification time of 40--50ms on recent-ish hardware.
|
||||
|
||||
Unless you have any special needs, all you need to know is:
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> from argon2 import PasswordHasher
|
||||
>>> ph = PasswordHasher()
|
||||
>>> hash = ph.hash("s3kr3tp4ssw0rd")
|
||||
>>> hash # doctest: +SKIP
|
||||
'$argon2id$v=19$m=102400,t=2,p=8$tSm+JOWigOgPZx/g44K5fQ$WDyus6py50bVFIPkjA28lQ'
|
||||
>>> ph.verify(hash, "s3kr3tp4ssw0rd")
|
||||
True
|
||||
>>> ph.check_needs_rehash(hash)
|
||||
False
|
||||
>>> ph.verify(hash, "t0t411ywr0ng")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
argon2.exceptions.VerifyMismatchError: The password does not match the supplied hash
|
||||
|
||||
|
||||
A login function could thus look like this:
|
||||
|
||||
.. literalinclude:: login_example.py
|
||||
:language: python
|
||||
|
||||
----
|
||||
|
||||
While the :class:`PasswordHasher` class has the aspiration to be good to use out of the box, it has all the parametrization you'll need:
|
||||
|
||||
.. autoclass:: PasswordHasher
|
||||
:members: hash, verify, check_needs_rehash
|
||||
:members: from_parameters, hash, verify, check_needs_rehash
|
||||
|
||||
If you don't specify any parameters, the following constants are used:
|
||||
|
||||
@ -44,7 +14,75 @@ If you don't specify any parameters, the following constants are used:
|
||||
.. data:: DEFAULT_MEMORY_COST
|
||||
.. data:: DEFAULT_PARALLELISM
|
||||
|
||||
You can see their values in :class:`PasswordHasher`.
|
||||
They are taken from :data:`argon2.profiles.RFC_9106_LOW_MEMORY`, but they may vary depending on the platform.
|
||||
You can use :func:`argon2.profiles.get_default_parameters` to get the current platform's defaults.
|
||||
|
||||
|
||||
Profiles
|
||||
--------
|
||||
|
||||
.. automodule:: argon2.profiles
|
||||
|
||||
|
||||
You can try them out using the :doc:`cli` interface.
|
||||
For example:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ python -m argon2 --profile RFC_9106_HIGH_MEMORY
|
||||
Running Argon2id 100 times with:
|
||||
hash_len: 32 bytes
|
||||
memory_cost: 2097152 KiB
|
||||
parallelism: 4 threads
|
||||
time_cost: 1 iterations
|
||||
|
||||
Measuring...
|
||||
|
||||
866.5ms per password verification
|
||||
|
||||
That should give you a feeling on how they perform in *your* environment.
|
||||
|
||||
.. data:: RFC_9106_HIGH_MEMORY
|
||||
|
||||
Called "FIRST RECOMMENDED option" by `RFC 9106`_.
|
||||
|
||||
Requires beefy 2 GiB, so be careful in memory-contrained systems.
|
||||
|
||||
.. versionadded:: 21.2.0
|
||||
|
||||
.. data:: RFC_9106_LOW_MEMORY
|
||||
|
||||
Called "SECOND RECOMMENDED option" by `RFC 9106`_.
|
||||
|
||||
The main difference is that it only takes 64 MiB of RAM.
|
||||
|
||||
The values from this profile are the default parameters used by :class:`argon2.PasswordHasher`.
|
||||
|
||||
.. versionadded:: 21.2.0
|
||||
|
||||
.. data:: PRE_21_2
|
||||
|
||||
The default values that *argon2-cffi* used from 18.2.0 until 21.2.0.
|
||||
|
||||
Needs 100 MiB of RAM.
|
||||
|
||||
.. versionadded:: 21.2.0
|
||||
|
||||
.. data:: CHEAPEST
|
||||
|
||||
This is the cheapest-possible profile.
|
||||
|
||||
.. warning::
|
||||
|
||||
This is only for testing purposes!
|
||||
Do **not** use in production!
|
||||
|
||||
.. versionadded:: 21.2.0
|
||||
|
||||
|
||||
.. autofunction:: argon2.profiles.get_default_parameters
|
||||
|
||||
.. _`RFC 9106`: https://www.rfc-editor.org/rfc/rfc9106.html
|
||||
|
||||
|
||||
Exceptions
|
||||
@ -56,16 +94,20 @@ Exceptions
|
||||
|
||||
.. autoexception:: argon2.exceptions.HashingError
|
||||
|
||||
.. autoexception:: argon2.exceptions.InvalidHashError
|
||||
|
||||
.. autoexception:: argon2.exceptions.InvalidHash
|
||||
|
||||
.. autoexception:: argon2.exceptions.UnsupportedParametersError
|
||||
|
||||
|
||||
|
||||
Utilities
|
||||
---------
|
||||
|
||||
.. autofunction:: argon2.extract_parameters
|
||||
|
||||
.. autofunction:: extract_parameters
|
||||
|
||||
.. autoclass:: Parameters
|
||||
.. autoclass:: argon2.Parameters
|
||||
|
||||
|
||||
Low Level
|
||||
@ -73,8 +115,23 @@ Low Level
|
||||
|
||||
.. automodule:: argon2.low_level
|
||||
|
||||
.. autoclass:: Type
|
||||
:members: D, I, ID
|
||||
.. autoclass:: Type()
|
||||
|
||||
.. attribute:: D
|
||||
|
||||
Argon2\ **d** is faster and uses data-depending memory access.
|
||||
That makes it less suitable for hashing secrets and more suitable for cryptocurrencies and applications with no threats from side-channel timing attacks.
|
||||
|
||||
.. attribute:: I
|
||||
|
||||
Argon2\ **i** uses data-independent memory access.
|
||||
Argon2i is slower as it makes more passes over the memory to protect from tradeoff attacks.
|
||||
|
||||
.. attribute:: ID
|
||||
|
||||
Argon2\ **id** is a hybrid of Argon2i and Argon2d, using a combination of data-depending and data-independent memory accesses, which gives some of Argon2i's resistance to side-channel cache timing attacks and much of Argon2d's resistance to GPU cracking attacks.
|
||||
|
||||
.. versionadded:: 16.3.0
|
||||
|
||||
.. autodata:: ARGON2_VERSION
|
||||
|
||||
@ -109,43 +166,65 @@ The super low-level ``argon2_core()`` function is exposed too if you need access
|
||||
|
||||
.. autofunction:: core
|
||||
|
||||
In order to use :func:`core`, you need access to ``argon2_cffi``'s FFI objects.
|
||||
Therefore it is OK to use ``argon2.low_level.ffi`` and ``argon2.low_level.lib`` when working with it:
|
||||
In order to use :func:`core`, you need access to *argon2-cffi*'s FFI objects.
|
||||
Therefore, it is OK to use ``argon2.low_level.ffi`` and ``argon2.low_level.lib`` when working with it.
|
||||
For example, if you wanted to check the :rfc:`9106` test vectors for Argon2id that include a secret and associated data that both get mixed into the hash and aren't exposed by the high-level APIs:
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> from argon2.low_level import ARGON2_VERSION, Type, core, ffi, lib
|
||||
>>> pwd = b"secret"
|
||||
>>> salt = b"12345678"
|
||||
>>> hash_len = 8
|
||||
>>> # Make sure you keep FFI objects alive until *after* the core call!
|
||||
>>> cout = ffi.new("uint8_t[]", hash_len)
|
||||
>>> cpwd = ffi.new("uint8_t[]", pwd)
|
||||
>>> csalt = ffi.new("uint8_t[]", salt)
|
||||
>>> ctx = ffi.new(
|
||||
... "argon2_context *", dict(
|
||||
... version=ARGON2_VERSION,
|
||||
... out=cout, outlen=hash_len,
|
||||
... pwd=cpwd, pwdlen=len(pwd),
|
||||
... salt=csalt, saltlen=len(salt),
|
||||
... secret=ffi.NULL, secretlen=0,
|
||||
... ad=ffi.NULL, adlen=0,
|
||||
... t_cost=1,
|
||||
... m_cost=8,
|
||||
... lanes=1, threads=1,
|
||||
... allocate_cbk=ffi.NULL, free_cbk=ffi.NULL,
|
||||
... flags=lib.ARGON2_DEFAULT_FLAGS,
|
||||
>>> from argon2.low_level import Type, core, ffi, lib
|
||||
|
||||
>>> def low_level_hash(
|
||||
... password, salt, secret, associated,
|
||||
... hash_len, version, t_cost, m_cost, lanes, threads):
|
||||
... cout = ffi.new("uint8_t[]", hash_len)
|
||||
... cpwd = ffi.new("uint8_t[]", password)
|
||||
... cad = ffi.new("uint8_t[]", associated)
|
||||
... csalt = ffi.new("uint8_t[]", salt)
|
||||
... csecret = ffi.new("uint8_t[]", secret)
|
||||
...
|
||||
... ctx = ffi.new(
|
||||
... "argon2_context *",
|
||||
... {
|
||||
... "out": cout,
|
||||
... "outlen": hash_len,
|
||||
... "version": version,
|
||||
... "pwd": cpwd,
|
||||
... "pwdlen": len(cpwd) - 1,
|
||||
... "salt": csalt,
|
||||
... "saltlen": len(csalt) - 1,
|
||||
... "secret": csecret,
|
||||
... "secretlen": len(csecret) - 1,
|
||||
... "ad": cad,
|
||||
... "adlen": len(cad) - 1,
|
||||
... "t_cost": t_cost,
|
||||
... "m_cost": m_cost,
|
||||
... "lanes": lanes,
|
||||
... "threads": threads,
|
||||
... "allocate_cbk": ffi.NULL,
|
||||
... "free_cbk": ffi.NULL,
|
||||
... "flags": lib.ARGON2_DEFAULT_FLAGS,
|
||||
... },
|
||||
... )
|
||||
...
|
||||
... assert lib.ARGON2_OK == core(ctx, Type.ID.value)
|
||||
...
|
||||
... return bytes(ffi.buffer(ctx.out, ctx.outlen)).hex()
|
||||
|
||||
>>> password = bytes.fromhex(
|
||||
... "0101010101010101010101010101010101010101010101010101010101010101"
|
||||
... )
|
||||
>>> associated = bytes.fromhex("040404040404040404040404")
|
||||
>>> salt = bytes.fromhex("02020202020202020202020202020202")
|
||||
>>> secret = bytes.fromhex("0303030303030303")
|
||||
|
||||
>>> assert (
|
||||
... "0d640df58d78766c08c037a34a8b53c9d01ef0452d75b65eb52520e96b01e659"
|
||||
... == low_level_hash(
|
||||
... password, salt, secret, associated,
|
||||
... 32, 19, 3, 32, 4, 4,
|
||||
... )
|
||||
... )
|
||||
>>> ctx
|
||||
<cdata 'struct Argon2_Context *' owning 120 bytes>
|
||||
>>> core(ctx, Type.D.value)
|
||||
0
|
||||
>>> out = bytes(ffi.buffer(ctx.out, ctx.outlen))
|
||||
>>> out
|
||||
b'\xb4\xe2HjO\x14d\x9b'
|
||||
>>> out == argon2.low_level.hash_secret_raw(pwd, salt, 1, 8, 1, 8, Type.D)
|
||||
True
|
||||
|
||||
All constants and types on ``argon2.low_level.lib`` are guaranteed to stay as long they are not altered by Argon2 itself.
|
||||
|
||||
@ -155,11 +234,11 @@ All constants and types on ``argon2.low_level.lib`` are guaranteed to stay as lo
|
||||
Deprecated APIs
|
||||
---------------
|
||||
|
||||
These APIs are from the first release of ``argon2_cffi`` and proved to live in an unfortunate mid-level.
|
||||
These APIs are from the first release of *argon2-cffi* and proved to live in an unfortunate mid-level.
|
||||
On one hand they have defaults and check parameters but on the other hand they only consume byte strings.
|
||||
|
||||
Therefore the decision has been made to replace them by a high-level (:class:`argon2.PasswordHasher`) and a low-level (:mod:`argon2.low_level`) solution.
|
||||
There are no immediate plans to remove them though.
|
||||
They will be removed in 2024.
|
||||
|
||||
.. autofunction:: argon2.hash_password
|
||||
.. autofunction:: argon2.hash_password_raw
|
||||
|
||||
61
docs/argon2.md
Normal file
61
docs/argon2.md
Normal file
@ -0,0 +1,61 @@
|
||||
# What is Argon2?
|
||||
|
||||
:::{note}
|
||||
**TL;DR**: Use {class}`argon2.PasswordHasher` with its default parameters to securely hash your passwords.
|
||||
|
||||
You do **not** need to read or understand anything below this box.
|
||||
:::
|
||||
|
||||
Argon2 is a secure password hashing algorithm.
|
||||
It is designed to have both a configurable runtime as well as memory consumption.
|
||||
|
||||
This means that you can decide how long it takes to hash a password and how much memory is required.
|
||||
|
||||
In September 2021, Argon2 has been standardized by the IETF in {rfc}`9106`.
|
||||
|
||||
Argon2 comes in three variants: Argon2**d**, Argon2**i**, and Argon2**id**.
|
||||
Argon2**d**'s strength is the resistance against [time–memory trade-offs], while Argon2**i**'s focus is on resistance against [side-channel attacks].
|
||||
|
||||
Accordingly, Argon2**i** was originally considered the correct choice for password hashing and password-based key derivation.
|
||||
In practice it turned out that a *combination* of d and i -- that combines their strengths -- is the better choice.
|
||||
And so Argon2**id** was born and is now considered the *main variant* -- and the only variant required by the RFC to be implemented.
|
||||
|
||||
|
||||
## Why “just use bcrypt” Is Not the Best Answer (Anymore)
|
||||
|
||||
The current workhorses of password hashing are unquestionably [*bcrypt*] and [PBKDF2].
|
||||
And while they're still fine to use, the password cracking community embraced new technologies like [GPU]s and [ASIC]s to crack password in a highly parallel fashion.
|
||||
|
||||
An effective measure against extreme parallelism proved making computation of password hashes also *memory* hard.
|
||||
The best known implementation of that approach is to date [*scrypt*].
|
||||
However according to the [Argon2 paper] [^outdated], page 2:
|
||||
|
||||
> \[…\] the existence of a trivial time-memory tradeoff allows compact implementations with the same energy cost.
|
||||
|
||||
Therefore a new algorithm was needed.
|
||||
This time future-proof and with committee-vetting instead of single implementers.
|
||||
|
||||
[^outdated]: Please note that the paper is in some parts outdated.
|
||||
For instance it predates the genesis of Argon2**id**.
|
||||
Generally please refer to {rfc}`9106` instead.
|
||||
|
||||
|
||||
## Password Hashing Competition
|
||||
|
||||
The [Password Hashing Competition] took place between 2012 and 2015 to find a new, secure, and future-proof password hashing algorithm.
|
||||
Previously the NIST was in charge but after certain events and [revelations] their integrity has been put into question by the general public.
|
||||
So a group of independent cryptographers and security researchers came together.
|
||||
|
||||
In the end, Argon2 was [announced] as the winner.
|
||||
|
||||
[announced]: https://groups.google.com/forum/#!topic/crypto-competitions/3QNdmwBS98o
|
||||
[argon2 paper]: https://www.password-hashing.net/argon2-specs.pdf
|
||||
[asic]: https://en.wikipedia.org/wiki/Application-specific_integrated_circuit
|
||||
[*bcrypt*]: https://en.wikipedia.org/wiki/Bcrypt
|
||||
[gpu]: https://hashcat.net/hashcat/
|
||||
[password hashing competition]: https://www.password-hashing.net/
|
||||
[pbkdf2]: https://en.wikipedia.org/wiki/PBKDF2
|
||||
[revelations]: https://en.wikipedia.org/wiki/Dual_EC_DRBG
|
||||
[*scrypt*]: https://en.wikipedia.org/wiki/Scrypt
|
||||
[side-channel attacks]: https://en.wikipedia.org/wiki/Side-channel_attack
|
||||
[time–memory trade-offs]: https://en.wikipedia.org/wiki/Space–time_tradeoff
|
||||
@ -1,62 +0,0 @@
|
||||
Argon2
|
||||
======
|
||||
|
||||
.. note::
|
||||
|
||||
**TL;DR**: Use :class:`argon2.PasswordHasher` with its default parameters to securely hash your passwords.
|
||||
|
||||
You do **not** need to read or understand anything below this box.
|
||||
|
||||
Argon2 is a secure password hashing algorithm.
|
||||
It is designed to have both a configurable runtime as well as memory consumption.
|
||||
|
||||
This means that you can decide how long it takes to hash a password and how much memory is required.
|
||||
|
||||
Argon2 comes in three variants:
|
||||
|
||||
Argon2d
|
||||
is faster and uses data-depending memory access, which makes it less suitable for hashing secrets and more suitable for cryptocurrencies and applications with no threats from side-channel timing attacks.
|
||||
|
||||
Argon2i
|
||||
uses data-independent memory access, which is preferred for password hashing and password-based key derivation.
|
||||
Argon2i is slower as it makes more passes over the memory to protect from tradeoff attacks.
|
||||
|
||||
Argon2id
|
||||
is a hybrid of Argon2i and Argon2d, using a combination of data-depending and data-independent memory accesses, which gives some of Argon2i's resistance to side-channel cache timing attacks and much of Argon2d's resistance to GPU cracking attacks.
|
||||
|
||||
|
||||
Why “just use bcrypt” Is Not the Best Answer (Anymore)
|
||||
------------------------------------------------------
|
||||
|
||||
The current workhorses of password hashing are unquestionably bcrypt_ and PBKDF2_.
|
||||
And while they're still fine to use, the password cracking community embraced new technologies like GPU_\ s and ASIC_\ s to crack password in a highly parallel fashion.
|
||||
|
||||
An effective measure against extreme parallelism proved making computation of password hashes also *memory* hard.
|
||||
The best known implementation of that approach is to date scrypt_.
|
||||
However according to the `Argon2 paper`_, page 2:
|
||||
|
||||
[…] the existence of a trivial time-memory tradeoff allows compact implementations with the same energy cost.
|
||||
|
||||
Therefore a new algorithm was needed.
|
||||
This time future-proof and with committee-vetting instead of single implementors.
|
||||
|
||||
.. _bcrypt: https://en.wikipedia.org/wiki/Bcrypt
|
||||
.. _PBKDF2: https://en.wikipedia.org/wiki/PBKDF2
|
||||
.. _GPU: https://hashcat.net/hashcat/
|
||||
.. _ASIC: https://en.wikipedia.org/wiki/Application-specific_integrated_circuit
|
||||
.. _scrypt: https://en.wikipedia.org/wiki/Scrypt
|
||||
.. _Argon2 paper: https://password-hashing.net/argon2-specs.pdf
|
||||
|
||||
|
||||
Password Hashing Competition
|
||||
----------------------------
|
||||
|
||||
The `Password Hashing Competition`_ took place between 2012 and 2015 to find a new, secure, and future-proof password hashing algorithm.
|
||||
Previously the NIST was in charge but after certain events and revelations_ their integrity has been put into question by the general public.
|
||||
So a group of independent cryptographers and security researchers came together.
|
||||
|
||||
In the end, Argon2 was announced_ as the winner.
|
||||
|
||||
.. _Password Hashing Competition: https://password-hashing.net/
|
||||
.. _revelations: https://en.wikipedia.org/wiki/Dual_EC_DRBG
|
||||
.. _announced: https://groups.google.com/forum/#!topic/crypto-competitions/3QNdmwBS98o
|
||||
@ -1,15 +0,0 @@
|
||||
Backward Compatibility
|
||||
======================
|
||||
|
||||
``argon2_cffi`` has a very strong backward compatibility policy.
|
||||
Generally speaking, you shouldn't ever be afraid of updating.
|
||||
|
||||
If breaking changes are needed do be done, they are:
|
||||
|
||||
#. …announced in the changelog_.
|
||||
#. …the old behavior raises a :exc:`DeprecationWarning` for a year.
|
||||
#. …are done with another announcement in the changelog_.
|
||||
|
||||
What explicitly *may* change over time are the default hashing parameters and the behavior of the :doc:`cli`.
|
||||
|
||||
.. _changelog: https://argon2-cffi.readthedocs.io/en/stable/changelog.html
|
||||
@ -1 +0,0 @@
|
||||
.. include:: ../CHANGELOG.rst
|
||||
24
docs/cli.md
Normal file
24
docs/cli.md
Normal file
@ -0,0 +1,24 @@
|
||||
# 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:
|
||||
|
||||
```console
|
||||
$ python -m argon2
|
||||
Running Argon2id 100 times with:
|
||||
hash_len: 32 bytes
|
||||
memory_cost: 65536 KiB
|
||||
parallelism: 4 threads
|
||||
time_cost: 3 iterations
|
||||
|
||||
Measuring...
|
||||
|
||||
45.7ms per password verification
|
||||
```
|
||||
|
||||
You can use command line arguments to set hashing parameters.
|
||||
Either by setting them one by one (`-t` for time, `-m` for memory, `-p` for parallelism, `-l` for hash length), or by passing `--profile` followed by one of the names from {mod}`argon2.profiles`.
|
||||
In that case, the other parameters are ignored.
|
||||
If you don't pass any arguments as above, it runs with {class}`argon2.PasswordHasher`'s default values.
|
||||
|
||||
This should make it much easier to determine the right parameters for your use case and your environment.
|
||||
21
docs/cli.rst
21
docs/cli.rst
@ -1,21 +0,0 @@
|
||||
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:
|
||||
|
||||
.. code-block:: text
|
||||
|
||||
$ python -m argon2
|
||||
Running Argon2id 100 times with:
|
||||
hash_len: 16 bytes
|
||||
memory_cost: 102400 KiB
|
||||
parallelism: 8 threads
|
||||
time_cost: 2 iterations
|
||||
|
||||
Measuring...
|
||||
|
||||
45.3ms per password verification
|
||||
|
||||
This should make it much easier to determine the right parameters for your use case and your environment.
|
||||
276
docs/conf.py
276
docs/conf.py
@ -1,271 +1,99 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# argon2_cffi documentation build configuration file, created by
|
||||
# sphinx-quickstart on Sun May 11 16:17:15 2014.
|
||||
#
|
||||
# This file is execfile()d with the current directory set to its
|
||||
# containing dir.
|
||||
#
|
||||
# Note that not all possible configuration values are present in this
|
||||
# autogenerated file.
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import codecs
|
||||
import datetime
|
||||
import os
|
||||
import re
|
||||
from importlib import metadata
|
||||
|
||||
|
||||
def read(*parts):
|
||||
"""
|
||||
Build an absolute path from *parts* and and return the contents of the
|
||||
resulting file. Assume UTF-8 encoding.
|
||||
"""
|
||||
here = os.path.abspath(os.path.dirname(__file__))
|
||||
with codecs.open(os.path.join(here, *parts), "rb", "utf-8") as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
def find_version(*file_paths):
|
||||
"""
|
||||
Build a path from *file_paths* and search for a ``__version__``
|
||||
string inside.
|
||||
"""
|
||||
version_file = read(*file_paths)
|
||||
version_match = re.search(
|
||||
r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M
|
||||
)
|
||||
if version_match:
|
||||
return version_match.group(1)
|
||||
raise RuntimeError("Unable to find version string.")
|
||||
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
# sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
# -- General configuration ------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
# needs_sphinx = '1.0'
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
|
||||
extensions = [
|
||||
"myst_parser",
|
||||
"notfound.extension",
|
||||
"sphinx.ext.autodoc",
|
||||
"sphinx.ext.doctest",
|
||||
"sphinx.ext.intersphinx",
|
||||
"sphinx.ext.todo",
|
||||
"sphinx.ext.napoleon",
|
||||
"sphinx_copybutton",
|
||||
]
|
||||
|
||||
myst_enable_extensions = ["deflist", "colon_fence"]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ["_templates"]
|
||||
|
||||
# The suffix of source filenames.
|
||||
source_suffix = ".rst"
|
||||
|
||||
# The encoding of source files.
|
||||
# source_encoding = 'utf-8-sig'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = "index"
|
||||
|
||||
# General information about the project.
|
||||
project = u"argon2_cffi"
|
||||
year = datetime.date.today().year
|
||||
copyright = u"2015, Hynek Schlawack"
|
||||
project = "argon2-cffi"
|
||||
copyright = "2015, Hynek Schlawack"
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
release = find_version("..", "src", "argon2", "__init__.py")
|
||||
version = release.rsplit(u".", 1)[0]
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
if "dev" in (release := metadata.version("argon2-cffi")):
|
||||
release = version = "UNRELEASED"
|
||||
else:
|
||||
# The short X.Y version.
|
||||
version = release.rsplit(".", 1)[0]
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
# language = None
|
||||
# Move type hints into the description block, instead of the func definition.
|
||||
autodoc_typehints = "description"
|
||||
autodoc_typehints_description_target = "documented"
|
||||
|
||||
# There are two options for replacing |today|: either, you set today to some
|
||||
# non-false value, then it is used:
|
||||
# today = ''
|
||||
# Else, today_fmt is used as the format for a strftime call.
|
||||
# today_fmt = '%B %d, %Y'
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
exclude_patterns = ["_build"]
|
||||
|
||||
# nitpick_ignore = []
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all
|
||||
# documents.
|
||||
# default_role = None
|
||||
default_role = "any"
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
# add_function_parentheses = True
|
||||
|
||||
# If true, the current module name will be prepended to all description
|
||||
# unit titles (such as .. function::).
|
||||
# add_module_names = True
|
||||
|
||||
# If true, sectionauthor and moduleauthor directives will be shown in the
|
||||
# output. They are ignored by default.
|
||||
# show_authors = False
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = "sphinx"
|
||||
|
||||
# A list of ignored prefixes for module index sorting.
|
||||
# modindex_common_prefix = []
|
||||
|
||||
# If true, keep warnings as "system message" paragraphs in the built documents.
|
||||
# keep_warnings = False
|
||||
add_function_parentheses = True
|
||||
|
||||
|
||||
# -- Options for HTML output ----------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
|
||||
html_theme = "alabaster"
|
||||
html_theme = "furo"
|
||||
html_theme_options = {
|
||||
"font_family": '"Avenir Next", Calibri, "PT Sans", sans-serif',
|
||||
"head_font_family": '"Avenir Next", Calibri, "PT Sans", sans-serif',
|
||||
"font_size": "18px",
|
||||
"page_width": "980px",
|
||||
"show_relbars": True,
|
||||
"top_of_page_buttons": [],
|
||||
"light_css_variables": {
|
||||
"font-stack": "Inter,sans-serif",
|
||||
"font-stack--monospace": "BerkeleyMono, MonoLisa, ui-monospace, "
|
||||
"SFMono-Regular, Menlo, Consolas, Liberation Mono, monospace",
|
||||
},
|
||||
}
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
# documentation.
|
||||
# html_theme_options = {}
|
||||
|
||||
# Add any paths that contain custom themes here, relative to this directory.
|
||||
# html_theme_path = []
|
||||
|
||||
# The name for this set of Sphinx documents. If None, it defaults to
|
||||
# "<project> v<release> documentation".
|
||||
# html_title = None
|
||||
|
||||
# A shorter title for the navigation bar. Default is the same as html_title.
|
||||
# html_short_title = None
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top
|
||||
# of the sidebar.
|
||||
# html_logo = None
|
||||
|
||||
# The name of an image file (within the static path) to use as favicon of the
|
||||
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
||||
# pixels large.
|
||||
# html_favicon = None
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
# html_static_path = ['_static']
|
||||
|
||||
# Add any extra paths that contain custom files (such as robots.txt or
|
||||
# .htaccess) here, relative to this directory. These files are copied
|
||||
# directly to the root of the documentation.
|
||||
# html_extra_path = []
|
||||
|
||||
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
||||
# using the given strftime format.
|
||||
# html_last_updated_fmt = '%b %d, %Y'
|
||||
|
||||
# If true, SmartyPants will be used to convert quotes and dashes to
|
||||
# typographically correct entities.
|
||||
# html_use_smartypants = True
|
||||
|
||||
# Custom sidebar templates, maps document names to template names.
|
||||
# html_sidebars = {}
|
||||
|
||||
# Additional templates that should be rendered to pages, maps page names to
|
||||
# template names.
|
||||
# html_additional_pages = {}
|
||||
|
||||
# If false, no module index is generated.
|
||||
# html_domain_indices = True
|
||||
|
||||
# If false, no index is generated.
|
||||
# html_use_index = True
|
||||
|
||||
# If true, the index is split into individual pages for each letter.
|
||||
# html_split_index = False
|
||||
|
||||
# If true, links to the reST sources are added to the pages.
|
||||
# html_show_sourcelink = True
|
||||
|
||||
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
|
||||
# html_show_sphinx = True
|
||||
|
||||
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
|
||||
# html_show_copyright = True
|
||||
|
||||
# If true, an OpenSearch description file will be output, and all pages will
|
||||
# contain a <link> tag referring to it. The value of this option must be the
|
||||
# base URL from which the finished HTML is served.
|
||||
# html_use_opensearch = ''
|
||||
|
||||
# This is the file name suffix for HTML files (e.g. ".xhtml").
|
||||
# html_file_suffix = None
|
||||
html_static_path = ["_static"]
|
||||
html_css_files = ["custom.css"]
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = "argon2_cffidoc"
|
||||
htmlhelp_basename = "argon2-cffidoc"
|
||||
|
||||
|
||||
# -- Options for LaTeX output ---------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
# 'papersize': 'letterpaper',
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
# 'pointsize': '10pt',
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
# 'preamble': '',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title,
|
||||
# author, documentclass [howto, manual, or own class]).
|
||||
latex_documents = [
|
||||
(
|
||||
"index",
|
||||
"argon2_cffi.tex",
|
||||
u"argon2_cffi Documentation",
|
||||
u"Hynek Schlawack",
|
||||
"argon2-cffi.tex",
|
||||
"argon2-cffi Documentation",
|
||||
"Hynek Schlawack",
|
||||
"manual",
|
||||
)
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
# the title page.
|
||||
# latex_logo = None
|
||||
|
||||
# For "manual" documents, if this is true, then toplevel headings are parts,
|
||||
# not chapters.
|
||||
# latex_use_parts = False
|
||||
|
||||
# If true, show page references after internal links.
|
||||
# latex_show_pagerefs = False
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
# latex_show_urls = False
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
# latex_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
# latex_domain_indices = True
|
||||
|
||||
|
||||
# -- Options for manual page output ---------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
@ -273,16 +101,13 @@ latex_documents = [
|
||||
man_pages = [
|
||||
(
|
||||
"index",
|
||||
"argon2_cffi",
|
||||
u"argon2_cffi Documentation",
|
||||
[u"Hynek Schlawack"],
|
||||
"argon2-cffi",
|
||||
"argon2-cffi Documentation",
|
||||
["Hynek Schlawack"],
|
||||
1,
|
||||
)
|
||||
]
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
# man_show_urls = False
|
||||
|
||||
|
||||
# -- Options for Texinfo output -------------------------------------------
|
||||
|
||||
@ -292,27 +117,14 @@ man_pages = [
|
||||
texinfo_documents = [
|
||||
(
|
||||
"index",
|
||||
"argon2_cffi",
|
||||
u"argon2_cffi Documentation",
|
||||
u"Hynek Schlawack",
|
||||
"argon2_cffi",
|
||||
"One line description of project.",
|
||||
"argon2-cffi",
|
||||
"argon2-cffi Documentation",
|
||||
"Hynek Schlawack",
|
||||
"argon2-cffi",
|
||||
"Argon2 for Python",
|
||||
"Miscellaneous",
|
||||
)
|
||||
]
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
# texinfo_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
# texinfo_domain_indices = True
|
||||
|
||||
# How to display URL addresses: 'footnote', 'no', or 'inline'.
|
||||
# texinfo_show_urls = 'footnote'
|
||||
|
||||
# If true, do not generate a @detailmenu in the "Top" node's menu.
|
||||
# texinfo_no_detailmenu = False
|
||||
|
||||
|
||||
# Example configuration for intersphinx: refer to the Python standard library.
|
||||
intersphinx_mapping = {"https://docs.python.org/3": None}
|
||||
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
.. _contributing:
|
||||
|
||||
.. include:: ../.github/CONTRIBUTING.rst
|
||||
2
docs/faq.md
Normal file
2
docs/faq.md
Normal file
@ -0,0 +1,2 @@
|
||||
```{include} ../FAQ.md
|
||||
```
|
||||
@ -1 +0,0 @@
|
||||
.. include:: ../FAQ.rst
|
||||
38
docs/howto.md
Normal file
38
docs/howto.md
Normal file
@ -0,0 +1,38 @@
|
||||
# How to Hash a Password
|
||||
|
||||
*argon2-cffi* comes with an high-level API and uses the officially recommended low-memory Argon2 parameters that result in a verification time of 40--50ms on recent-ish hardware.
|
||||
|
||||
:::{warning}
|
||||
The current memory requirement is set to rather conservative 64 MB.
|
||||
However, in memory constrained environments such as Docker containers that can lead to problems.
|
||||
One possible non-obvious symptom are apparent freezes that are caused by swapping.
|
||||
|
||||
Please check {doc}`parameters` for more details.
|
||||
:::
|
||||
|
||||
Unless you have any special requirements, all you need to know is:
|
||||
|
||||
```python
|
||||
>>> from argon2 import PasswordHasher
|
||||
>>> ph = PasswordHasher()
|
||||
>>> hash = ph.hash("correct horse battery staple")
|
||||
>>> hash # doctest: +SKIP
|
||||
'$argon2id$v=19$m=65536,t=3,p=4$MIIRqgvgQbgj220jfp0MPA$YfwJSVjtjSU0zzV/P3S9nnQ/USre2wvJMjfCIjrTQbg'
|
||||
>>> ph.verify(hash, "correct horse battery staple")
|
||||
True
|
||||
>>> ph.check_needs_rehash(hash)
|
||||
False
|
||||
>>> ph.verify(hash, "Tr0ub4dor&3")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
argon2.exceptions.VerifyMismatchError: The password does not match the supplied hash
|
||||
```
|
||||
|
||||
A login function could thus look like this:
|
||||
|
||||
```{literalinclude} login_example.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
While the {class}`argon2.PasswordHasher` class has the aspiration to be good to use out of the box, it has all the parametrization you'll need.
|
||||
44
docs/index.md
Normal file
44
docs/index.md
Normal file
@ -0,0 +1,44 @@
|
||||
# *argon2-cffi*: Argon2 for Python
|
||||
|
||||
Release **{sub-ref}`release`** ([What's new?](https://github.com/hynek/argon2-cffi/blob/main/CHANGELOG.md))
|
||||
|
||||
```{include} ../README.md
|
||||
:end-before: <!-- end short -->
|
||||
:start-after: <!-- begin short -->
|
||||
```
|
||||
|
||||
If you don't know where to start, learn {doc}`argon2` and take it from there!
|
||||
|
||||
|
||||
## Indices and Tables
|
||||
|
||||
- {doc}`api`
|
||||
- {ref}`genindex`
|
||||
- {ref}`search`
|
||||
|
||||
|
||||
```{toctree}
|
||||
:hidden:
|
||||
:maxdepth: 1
|
||||
|
||||
argon2
|
||||
installation
|
||||
howto
|
||||
api
|
||||
parameters
|
||||
cli
|
||||
faq
|
||||
```
|
||||
|
||||
|
||||
```{toctree}
|
||||
:hidden:
|
||||
:caption: Meta
|
||||
|
||||
PyPI <https://pypi.org/project/argon2-cffi/>
|
||||
GitHub <https://github.com/hynek/argon2-cffi/>
|
||||
Changelog <https://github.com/hynek/argon2-cffi/blob/main/CHANGELOG.md>
|
||||
Contributing <https://github.com/hynek/argon2-cffi/blob/main/.github/CONTRIBUTING.md>
|
||||
Security Policy <https://github.com/hynek/argon2-cffi/blob/main/.github/SECURITY.md>
|
||||
Funding <https://hynek.me/say-thanks/>
|
||||
```
|
||||
@ -1,41 +0,0 @@
|
||||
``argon2_cffi``
|
||||
===============
|
||||
|
||||
Release v\ |release| (:doc:`What's new? <changelog>`).
|
||||
|
||||
|
||||
.. include:: ../README.rst
|
||||
:start-after: teaser-begin
|
||||
|
||||
|
||||
User's Guide
|
||||
------------
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
argon2
|
||||
installation
|
||||
api
|
||||
parameters
|
||||
cli
|
||||
faq
|
||||
|
||||
|
||||
Project Information
|
||||
-------------------
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
backward-compatibility
|
||||
contributing
|
||||
changelog
|
||||
license
|
||||
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`search`
|
||||
78
docs/installation.md
Normal file
78
docs/installation.md
Normal file
@ -0,0 +1,78 @@
|
||||
# Installation
|
||||
|
||||
## Using a Vendored Argon2
|
||||
|
||||
```console
|
||||
$ python -Im pip install argon2-cffi
|
||||
```
|
||||
|
||||
should be all it takes.
|
||||
|
||||
But since *argon2-cffi* depends on [argon2-cffi-bindings] that vendors Argon2's C code by default, it can lead to complications depending on the platform.
|
||||
|
||||
The C code is known to compile and work on all common platforms (including x86, ARM, and PPC).
|
||||
On x86, an [SSE2]-optimized version is used.
|
||||
|
||||
If something goes wrong, please try to update your *pip* package first:
|
||||
|
||||
```console
|
||||
$ python -Im pip install -U pip
|
||||
```
|
||||
|
||||
Overall this should be the safest bet because *argon2-cffi* has been specifically tested against the vendored version.
|
||||
|
||||
|
||||
### Wheels
|
||||
|
||||
Binary [wheels](https://pythonwheels.com) for macOS, Windows, and Linux are provided on [PyPI] by [argon2-cffi-bindings].
|
||||
With a recent-enough *pip* they should be used automatically.
|
||||
|
||||
|
||||
### Source Distribution
|
||||
|
||||
A working C compiler and [CFFI environment] are required to build the [argon2-cffi-bindings] dependency.
|
||||
If you've been able to compile Python CFFI extensions before, *argon2-cffi* should install without any problems.
|
||||
|
||||
|
||||
## Using a System-wide Installation of Argon2
|
||||
|
||||
If you set `ARGON2_CFFI_USE_SYSTEM` to `1` (and *only* `1`), *argon2-cffi-bindings* will not build its bindings.
|
||||
However binary wheels are preferred by *pip* and Argon2 gets installed along with *argon2-cffi* anyway.
|
||||
|
||||
Therefore you also have to instruct *pip* to use a source distribution of [argon2-cffi-bindings]:
|
||||
|
||||
```console
|
||||
$ env ARGON2_CFFI_USE_SYSTEM=1 \
|
||||
python -m pip install --no-binary=argon2-cffi-bindings argon2-cffi
|
||||
```
|
||||
|
||||
This approach can lead to problems around your build chain and you can run into incompatibilities between Argon2 and *argon2-cffi* if the latter has been tested against a different version.
|
||||
|
||||
**It is your own responsibility to deal with these risks if you choose this path.**
|
||||
|
||||
:::{versionadded} 18.1.0
|
||||
:::
|
||||
|
||||
:::{versionchanged} 21.2.0
|
||||
The `--no-binary` option value changed due to the outsourcing of the binary bindings.
|
||||
:::
|
||||
|
||||
|
||||
## Override Automatic SSE2 Detection
|
||||
|
||||
Usually the build process tries to guess whether or not it should use [SSE2]-optimized code.
|
||||
Despite our best efforts, this can go wrong.
|
||||
|
||||
Therefore you can use the `ARGON2_CFFI_USE_SSE2` environment variable to control the process:
|
||||
|
||||
- If you set it to `1`, *argon2-cffi* will build **with** SSE2 support.
|
||||
- If you set it to `0`, *argon2-cffi* will build **without** SSE2 support.
|
||||
- If you set it to anything else, it will be ignored and *argon2-cffi* will try to guess.
|
||||
|
||||
:::{versionadded} 20.1.0
|
||||
:::
|
||||
|
||||
[argon2-cffi-bindings]: https://github.com/hynek/argon2-cffi-bindings
|
||||
[cffi environment]: https://cffi.readthedocs.io/en/latest/installation.html
|
||||
[pypi]: https://pypi.org/project/argon2-cffi-bindings/
|
||||
[sse2]: https://en.wikipedia.org/wiki/SSE2
|
||||
@ -1,62 +0,0 @@
|
||||
Installation
|
||||
============
|
||||
|
||||
Using the Vendored Argon2
|
||||
-------------------------
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
python -m pip install argon2_cffi
|
||||
|
||||
should be all it takes.
|
||||
|
||||
But since ``argon2_cffi`` vendors Argon2's C code by default, it can lead to complications depending on the platform.
|
||||
|
||||
The C code is known to compile and work on all common platforms (including x86, ARM, and PPC).
|
||||
On x86, an SSE2_-optimized version is used.
|
||||
|
||||
If something goes wrong, please try to update your ``cffi``, ``pip`` and ``setuptools`` first:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
python -m pip install -U cffi pip setuptools
|
||||
|
||||
|
||||
Overall this should be the safest bet because ``argon2_cffi`` has been specifically tested against the vendored version.
|
||||
|
||||
|
||||
Wheels
|
||||
^^^^^^
|
||||
|
||||
Binary `wheels <https://pythonwheels.com>`_ for macOS, Windows, and Linux are provided on PyPI_.
|
||||
With a recent-enough ``pip`` and ``setuptools``, they should be used automatically.
|
||||
|
||||
|
||||
Source Distribution
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
A working C compiler and `CFFI environment`_ are required.
|
||||
If you've been able to compile Python CFFI extensions before, ``argon2_cffi`` should install without any problems.
|
||||
|
||||
|
||||
Using a System-wide Installation of Argon2
|
||||
------------------------------------------
|
||||
|
||||
If you set ``ARGON2_CFFI_USE_SYSTEM`` to ``1`` (and *only* ``1``), ``argon2_cffi`` will not build its bindings.
|
||||
However binary wheels are preferred by ``pip`` and Argon2 gets installed along with ``argon2_cffi`` anyway.
|
||||
|
||||
Therefore you also have to instruct ``pip`` to use a source distribution:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
env ARGON2_CFFI_USE_SYSTEM=1 \
|
||||
python -m pip install --no-binary=argon2_cffi argon2_cffi
|
||||
|
||||
This approach can lead to problems around your build chain and you can run into incompatabilities between Argon2 and ``argon2_cffi`` if the latter has been tested against a different version.
|
||||
|
||||
**It is your own responsibility to deal with these risks if you choose this path.**
|
||||
|
||||
|
||||
.. _SSE2: https://en.wikipedia.org/wiki/SSE2
|
||||
.. _PyPI: https://pypi.org/project/argon2_cffi/
|
||||
.. _CFFI environment: https://cffi.readthedocs.io/en/latest/installation.html
|
||||
@ -1 +0,0 @@
|
||||
.. include:: ../AUTHORS.rst
|
||||
54
docs/parameters.md
Normal file
54
docs/parameters.md
Normal file
@ -0,0 +1,54 @@
|
||||
# Choosing Parameters
|
||||
|
||||
:::{note}
|
||||
You can probably just use {class}`argon2.PasswordHasher` with its default values and be fine.
|
||||
But it's good to double check using *argon2-cffi*'s {doc}`cli` client, whether its defaults are too slow or too fast for your use case.
|
||||
:::
|
||||
|
||||
Finding the right parameters for a password hashing algorithm is a daunting task.
|
||||
As of September 2021, we have the official Internet standard [RFC 9106] to help us with it.
|
||||
|
||||
It comes with two recommendations in [section 4](https://www.rfc-editor.org/rfc/rfc9106.html#section-4), that (as of *argon2-cffi* 21.2.0) you can load directly from the {mod}`argon2.profiles` module: {data}`argon2.profiles.RFC_9106_HIGH_MEMORY` (called "FIRST RECOMMENDED") and {data}`argon2.profiles.RFC_9106_LOW_MEMORY` ("SECOND RECOMMENDED") into {meth}`argon2.PasswordHasher.from_parameters()`.
|
||||
|
||||
Please use the {doc}`cli` interface together with its `--profile` argument to see if they work for you.
|
||||
|
||||
---
|
||||
|
||||
If you need finer tuning, the current recommended best practice is as follow:
|
||||
|
||||
1. Choose whether you want Argon2i, Argon2d, or Argon2id (`type`).
|
||||
If you don't know what that means, choose Argon2id ({attr}`argon2.low_level.Type.ID`).
|
||||
|
||||
2. Figure out how many threads can be used on each call to Argon2 (`parallelism`, called "lanes" in the RFC).
|
||||
They recommend 4 threads.
|
||||
|
||||
3. Figure out how much memory each call can afford (`memory_cost`).
|
||||
The APIs use [Kibibytes] (1024 bytes) as base unit.
|
||||
|
||||
4. Select the salt length.
|
||||
16 bytes is sufficient for all applications, but can be reduced to 8 bytes in the case of space constraints.
|
||||
|
||||
5. Choose a hash length (`hash_len`, called "tag length" in the documentation).
|
||||
16 bytes is sufficient for password verification.
|
||||
|
||||
6. Figure out how long each call can take.
|
||||
One [recommendation](https://web.archive.org/web/20160304024620/https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2015/march/enough-with-the-salts-updates-on-secure-password-schemes/) for concurrent user logins is to keep it under 0.5 ms.
|
||||
The RFC used to recommend under 500 ms.
|
||||
The truth is somewhere between those two values: more is more secure, less is a better user experience.
|
||||
*argon2-cffi*'s current defaults land with ~50ms somewhere in the middle, but the actual time depends on your hardware.
|
||||
|
||||
Please note though, that even a verification time of 1 second won't protect you against bad passwords from the "top 10,000 passwords" lists that you can find online.
|
||||
|
||||
7. Measure the time for hashing using your chosen parameters.
|
||||
Start with `time_cost=1` and measure the time it takes.
|
||||
Raise `time_cost` until it is within your accounted time.
|
||||
If `time_cost=1` takes too long, lower `memory_cost`.
|
||||
|
||||
*argon2-cffi*'s {doc}`cli` will help you with this process.
|
||||
|
||||
:::{note}
|
||||
Alternatively, you can also refer to the [OWASP cheatsheet](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#argon2id).
|
||||
:::
|
||||
|
||||
[kibibytes]: https://en.wikipedia.org/wiki/Kibibyte
|
||||
[rfc 9106]: https://www.rfc-editor.org/rfc/rfc9106.html
|
||||
@ -1,41 +0,0 @@
|
||||
Choosing Parameters
|
||||
===================
|
||||
|
||||
.. note::
|
||||
|
||||
You can probably just use :class:`argon2.PasswordHasher` with its default values and be fine.
|
||||
But it's good to double check using ``argon2_cffi``'s :doc:`cli` client, whether its defaults are too slow or too fast for your use case.
|
||||
|
||||
Finding the right parameters for a password hashing algorithm is a daunting task.
|
||||
The authors of Argon2 specified a method in their `paper <https://github.com/P-H-C/phc-winner-argon2/blob/master/argon2-specs.pdf>`_, however some parts of it have been revised in the `RFC draft`_ for Argon2 that is currently being written.
|
||||
|
||||
The current recommended best practice is as follow:
|
||||
|
||||
#. Choose whether you want Argon2i, Argon2d, or Argon2id (``type``).
|
||||
If you don't know what that means, choose Argon2id (:attr:`argon2.Type.ID`).
|
||||
#. Figure out how many threads can be used on each call to Argon2 (``parallelism``, called "lanes" in the RFC).
|
||||
They recommend twice as many as the number of cores dedicated to hashing passwords.
|
||||
:class:`~argon2.PasswordHasher` will *not* determine this for you and use a default value that you can find in the linked API docs.
|
||||
#. Figure out how much memory each call can afford (``memory_cost``).
|
||||
The RFC recommends 4 GB for backend authentication and 1 GB for frontend authentication.
|
||||
The APIs use Kibibytes_ (1024 bytes) as base unit.
|
||||
#. Select the salt length.
|
||||
16 bytes is sufficient for all applications, but can be reduced to 8 bytes in the case of space constraints.
|
||||
#. Choose a hash length (``hash_len``, called "tag length" in the documentation).
|
||||
16 bytes is sufficient for password verification.
|
||||
#. Figure out how long each call can take.
|
||||
One `recommendation <https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2015/march/enough-with-the-salts-updates-on-secure-password-schemes/>`_ for concurent user logins is to keep it under 0.5 ms.
|
||||
The RFC recommends under 500 ms.
|
||||
The truth is somewhere between those two values: more is more secure, less is a better user experience.
|
||||
``argon2_cffi``'s defaults try to land somewhere in the middle and aim for ~50ms, but the actual time depends on your hardware.
|
||||
|
||||
Please note though, that even a verification time of 1 second won't protect you against bad passwords from the "top 10,000 passwords" lists that you can find online.
|
||||
#. 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``.
|
||||
|
||||
``argon2_cffi``'s :doc:`cli` will help you with this process.
|
||||
|
||||
|
||||
.. _`RFC draft`: https://tools.ietf.org/html/draft-irtf-cfrg-argon2-03#section-4
|
||||
.. _kibibytes: https://en.wikipedia.org/wiki/Kibibyte
|
||||
@ -1,229 +0,0 @@
|
||||
# Sample script to install Python and pip under Windows
|
||||
# Authors: Olivier Grisel, Jonathan Helmus, Kyle Kastner, and Alex Willmer
|
||||
# License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
$MINICONDA_URL = "http://repo.continuum.io/miniconda/"
|
||||
$BASE_URL = "https://www.python.org/ftp/python/"
|
||||
$GET_PIP_URL = "https://bootstrap.pypa.io/get-pip.py"
|
||||
$GET_PIP_PATH = "C:\get-pip.py"
|
||||
|
||||
$PYTHON_PRERELEASE_REGEX = @"
|
||||
(?x)
|
||||
(?<major>\d+)
|
||||
\.
|
||||
(?<minor>\d+)
|
||||
\.
|
||||
(?<micro>\d+)
|
||||
(?<prerelease>[a-z]{1,2}\d+)
|
||||
"@
|
||||
|
||||
|
||||
function Download ($filename, $url) {
|
||||
$webclient = New-Object System.Net.WebClient
|
||||
|
||||
$basedir = $pwd.Path + "\"
|
||||
$filepath = $basedir + $filename
|
||||
if (Test-Path $filename) {
|
||||
Write-Host "Reusing" $filepath
|
||||
return $filepath
|
||||
}
|
||||
|
||||
# Download and retry up to 3 times in case of network transient errors.
|
||||
Write-Host "Downloading" $filename "from" $url
|
||||
$retry_attempts = 2
|
||||
for ($i = 0; $i -lt $retry_attempts; $i++) {
|
||||
try {
|
||||
$webclient.DownloadFile($url, $filepath)
|
||||
break
|
||||
}
|
||||
Catch [Exception]{
|
||||
Start-Sleep 1
|
||||
}
|
||||
}
|
||||
if (Test-Path $filepath) {
|
||||
Write-Host "File saved at" $filepath
|
||||
} else {
|
||||
# Retry once to get the error message if any at the last try
|
||||
$webclient.DownloadFile($url, $filepath)
|
||||
}
|
||||
return $filepath
|
||||
}
|
||||
|
||||
|
||||
function ParsePythonVersion ($python_version) {
|
||||
if ($python_version -match $PYTHON_PRERELEASE_REGEX) {
|
||||
return ([int]$matches.major, [int]$matches.minor, [int]$matches.micro,
|
||||
$matches.prerelease)
|
||||
}
|
||||
$version_obj = [version]$python_version
|
||||
return ($version_obj.major, $version_obj.minor, $version_obj.build, "")
|
||||
}
|
||||
|
||||
|
||||
function DownloadPython ($python_version, $platform_suffix) {
|
||||
$major, $minor, $micro, $prerelease = ParsePythonVersion $python_version
|
||||
|
||||
if (($major -le 2 -and $micro -eq 0) `
|
||||
-or ($major -eq 3 -and $minor -le 2 -and $micro -eq 0) `
|
||||
) {
|
||||
$dir = "$major.$minor"
|
||||
$python_version = "$major.$minor$prerelease"
|
||||
} else {
|
||||
$dir = "$major.$minor.$micro"
|
||||
}
|
||||
|
||||
if ($prerelease) {
|
||||
if (($major -le 2) `
|
||||
-or ($major -eq 3 -and $minor -eq 1) `
|
||||
-or ($major -eq 3 -and $minor -eq 2) `
|
||||
-or ($major -eq 3 -and $minor -eq 3) `
|
||||
) {
|
||||
$dir = "$dir/prev"
|
||||
}
|
||||
}
|
||||
|
||||
if (($major -le 2) -or ($major -le 3 -and $minor -le 4)) {
|
||||
$ext = "msi"
|
||||
if ($platform_suffix) {
|
||||
$platform_suffix = ".$platform_suffix"
|
||||
}
|
||||
} else {
|
||||
$ext = "exe"
|
||||
if ($platform_suffix) {
|
||||
$platform_suffix = "-$platform_suffix"
|
||||
}
|
||||
}
|
||||
|
||||
$filename = "python-$python_version$platform_suffix.$ext"
|
||||
$url = "$BASE_URL$dir/$filename"
|
||||
$filepath = Download $filename $url
|
||||
return $filepath
|
||||
}
|
||||
|
||||
|
||||
function InstallPython ($python_version, $architecture, $python_home) {
|
||||
Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home
|
||||
if (Test-Path $python_home) {
|
||||
Write-Host $python_home "already exists, skipping."
|
||||
return $false
|
||||
}
|
||||
if ($architecture -eq "32") {
|
||||
$platform_suffix = ""
|
||||
} else {
|
||||
$platform_suffix = "amd64"
|
||||
}
|
||||
$installer_path = DownloadPython $python_version $platform_suffix
|
||||
$installer_ext = [System.IO.Path]::GetExtension($installer_path)
|
||||
Write-Host "Installing $installer_path to $python_home"
|
||||
$install_log = $python_home + ".log"
|
||||
if ($installer_ext -eq '.msi') {
|
||||
InstallPythonMSI $installer_path $python_home $install_log
|
||||
} else {
|
||||
InstallPythonEXE $installer_path $python_home $install_log
|
||||
}
|
||||
if (Test-Path $python_home) {
|
||||
Write-Host "Python $python_version ($architecture) installation complete"
|
||||
} else {
|
||||
Write-Host "Failed to install Python in $python_home"
|
||||
Get-Content -Path $install_log
|
||||
Exit 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function InstallPythonEXE ($exepath, $python_home, $install_log) {
|
||||
$install_args = "/quiet InstallAllUsers=1 TargetDir=$python_home"
|
||||
RunCommand $exepath $install_args
|
||||
}
|
||||
|
||||
|
||||
function InstallPythonMSI ($msipath, $python_home, $install_log) {
|
||||
$install_args = "/qn /log $install_log /i $msipath TARGETDIR=$python_home"
|
||||
$uninstall_args = "/qn /x $msipath"
|
||||
RunCommand "msiexec.exe" $install_args
|
||||
if (-not(Test-Path $python_home)) {
|
||||
Write-Host "Python seems to be installed else-where, reinstalling."
|
||||
RunCommand "msiexec.exe" $uninstall_args
|
||||
RunCommand "msiexec.exe" $install_args
|
||||
}
|
||||
}
|
||||
|
||||
function RunCommand ($command, $command_args) {
|
||||
Write-Host $command $command_args
|
||||
Start-Process -FilePath $command -ArgumentList $command_args -Wait -Passthru
|
||||
}
|
||||
|
||||
|
||||
function InstallPip ($python_home) {
|
||||
$pip_path = $python_home + "\Scripts\pip.exe"
|
||||
$python_path = $python_home + "\python.exe"
|
||||
if (-not(Test-Path $pip_path)) {
|
||||
Write-Host "Installing pip..."
|
||||
$webclient = New-Object System.Net.WebClient
|
||||
$webclient.DownloadFile($GET_PIP_URL, $GET_PIP_PATH)
|
||||
Write-Host "Executing:" $python_path $GET_PIP_PATH
|
||||
& $python_path $GET_PIP_PATH
|
||||
} else {
|
||||
Write-Host "pip already installed."
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function DownloadMiniconda ($python_version, $platform_suffix) {
|
||||
if ($python_version -eq "3.4") {
|
||||
$filename = "Miniconda3-3.5.5-Windows-" + $platform_suffix + ".exe"
|
||||
} else {
|
||||
$filename = "Miniconda-3.5.5-Windows-" + $platform_suffix + ".exe"
|
||||
}
|
||||
$url = $MINICONDA_URL + $filename
|
||||
$filepath = Download $filename $url
|
||||
return $filepath
|
||||
}
|
||||
|
||||
|
||||
function InstallMiniconda ($python_version, $architecture, $python_home) {
|
||||
Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home
|
||||
if (Test-Path $python_home) {
|
||||
Write-Host $python_home "already exists, skipping."
|
||||
return $false
|
||||
}
|
||||
if ($architecture -eq "32") {
|
||||
$platform_suffix = "x86"
|
||||
} else {
|
||||
$platform_suffix = "x86_64"
|
||||
}
|
||||
$filepath = DownloadMiniconda $python_version $platform_suffix
|
||||
Write-Host "Installing" $filepath "to" $python_home
|
||||
$install_log = $python_home + ".log"
|
||||
$args = "/S /D=$python_home"
|
||||
Write-Host $filepath $args
|
||||
Start-Process -FilePath $filepath -ArgumentList $args -Wait -Passthru
|
||||
if (Test-Path $python_home) {
|
||||
Write-Host "Python $python_version ($architecture) installation complete"
|
||||
} else {
|
||||
Write-Host "Failed to install Python in $python_home"
|
||||
Get-Content -Path $install_log
|
||||
Exit 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function InstallMinicondaPip ($python_home) {
|
||||
$pip_path = $python_home + "\Scripts\pip.exe"
|
||||
$conda_path = $python_home + "\Scripts\conda.exe"
|
||||
if (-not(Test-Path $pip_path)) {
|
||||
Write-Host "Installing pip..."
|
||||
$args = "install --yes pip"
|
||||
Write-Host $conda_path $args
|
||||
Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru
|
||||
} else {
|
||||
Write-Host "pip already installed."
|
||||
}
|
||||
}
|
||||
|
||||
function main () {
|
||||
InstallPython $env:PYTHON_VERSION $env:PYTHON_ARCH $env:PYTHON
|
||||
InstallPip $env:PYTHON
|
||||
}
|
||||
|
||||
main
|
||||
@ -1,88 +0,0 @@
|
||||
:: To build extensions for 64 bit Python 3, we need to configure environment
|
||||
:: variables to use the MSVC 2010 C++ compilers from GRMSDKX_EN_DVD.iso of:
|
||||
:: MS Windows SDK for Windows 7 and .NET Framework 4 (SDK v7.1)
|
||||
::
|
||||
:: To build extensions for 64 bit Python 2, we need to configure environment
|
||||
:: variables to use the MSVC 2008 C++ compilers from GRMSDKX_EN_DVD.iso of:
|
||||
:: MS Windows SDK for Windows 7 and .NET Framework 3.5 (SDK v7.0)
|
||||
::
|
||||
:: 32 bit builds, and 64-bit builds for 3.5 and beyond, do not require specific
|
||||
:: environment configurations.
|
||||
::
|
||||
:: Note: this script needs to be run with the /E:ON and /V:ON flags for the
|
||||
:: cmd interpreter, at least for (SDK v7.0)
|
||||
::
|
||||
:: More details at:
|
||||
:: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows
|
||||
:: http://stackoverflow.com/a/13751649/163740
|
||||
::
|
||||
:: Author: Olivier Grisel
|
||||
:: License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
|
||||
::
|
||||
:: Notes about batch files for Python people:
|
||||
::
|
||||
:: Quotes in values are literally part of the values:
|
||||
:: SET FOO="bar"
|
||||
:: FOO is now five characters long: " b a r "
|
||||
:: If you don't want quotes, don't include them on the right-hand side.
|
||||
::
|
||||
:: The CALL lines at the end of this file look redundant, but if you move them
|
||||
:: outside of the IF clauses, they do not run properly in the SET_SDK_64==Y
|
||||
:: case, I don't know why.
|
||||
@ECHO OFF
|
||||
|
||||
SET COMMAND_TO_RUN=%*
|
||||
SET WIN_SDK_ROOT=C:\Program Files\Microsoft SDKs\Windows
|
||||
SET WIN_WDK=c:\Program Files (x86)\Windows Kits\10\Include\wdf
|
||||
|
||||
:: Extract the major and minor versions, and allow for the minor version to be
|
||||
:: more than 9. This requires the version number to have two dots in it.
|
||||
SET MAJOR_PYTHON_VERSION=%PYTHON_VERSION:~0,1%
|
||||
IF "%PYTHON_VERSION:~3,1%" == "." (
|
||||
SET MINOR_PYTHON_VERSION=%PYTHON_VERSION:~2,1%
|
||||
) ELSE (
|
||||
SET MINOR_PYTHON_VERSION=%PYTHON_VERSION:~2,2%
|
||||
)
|
||||
|
||||
:: Based on the Python version, determine what SDK version to use, and whether
|
||||
:: to set the SDK for 64-bit.
|
||||
IF %MAJOR_PYTHON_VERSION% == 2 (
|
||||
SET WINDOWS_SDK_VERSION="v7.0"
|
||||
SET SET_SDK_64=Y
|
||||
) ELSE (
|
||||
IF %MAJOR_PYTHON_VERSION% == 3 (
|
||||
SET WINDOWS_SDK_VERSION="v7.1"
|
||||
IF %MINOR_PYTHON_VERSION% LEQ 4 (
|
||||
SET SET_SDK_64=Y
|
||||
) ELSE (
|
||||
SET SET_SDK_64=N
|
||||
IF EXIST "%WIN_WDK%" (
|
||||
:: See: https://connect.microsoft.com/VisualStudio/feedback/details/1610302/
|
||||
REN "%WIN_WDK%" 0wdf
|
||||
)
|
||||
)
|
||||
) ELSE (
|
||||
ECHO Unsupported Python version: "%MAJOR_PYTHON_VERSION%"
|
||||
EXIT 1
|
||||
)
|
||||
)
|
||||
|
||||
IF %PYTHON_ARCH% == 64 (
|
||||
IF %SET_SDK_64% == Y (
|
||||
ECHO Configuring Windows SDK %WINDOWS_SDK_VERSION% for Python %MAJOR_PYTHON_VERSION% on a 64 bit architecture
|
||||
SET DISTUTILS_USE_SDK=1
|
||||
SET MSSdk=1
|
||||
"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Setup\WindowsSdkVer.exe" -q -version:%WINDOWS_SDK_VERSION%
|
||||
"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x64 /release
|
||||
ECHO Executing: %COMMAND_TO_RUN%
|
||||
call %COMMAND_TO_RUN% || EXIT 1
|
||||
) ELSE (
|
||||
ECHO Using default MSVC build environment for 64 bit architecture
|
||||
ECHO Executing: %COMMAND_TO_RUN%
|
||||
call %COMMAND_TO_RUN% || EXIT 1
|
||||
)
|
||||
) ELSE (
|
||||
ECHO Using default MSVC build environment for 32 bit architecture
|
||||
ECHO Executing: %COMMAND_TO_RUN%
|
||||
call %COMMAND_TO_RUN% || EXIT 1
|
||||
)
|
||||
@ -1 +0,0 @@
|
||||
Subproject commit 670229c849b9fe882583688b74eb7dfdc846f9f6
|
||||
@ -1,306 +0,0 @@
|
||||
// ISO C9x compliant inttypes.h for Microsoft Visual Studio
|
||||
// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
|
||||
//
|
||||
// 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:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. 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.
|
||||
//
|
||||
// 3. 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.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _MSC_VER // [
|
||||
#error "Use this header only with Microsoft Visual C++ compilers!"
|
||||
#endif // _MSC_VER ]
|
||||
|
||||
#ifndef _MSC_INTTYPES_H_ // [
|
||||
#define _MSC_INTTYPES_H_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
// 7.8 Format conversion of integer types
|
||||
|
||||
typedef struct {
|
||||
intmax_t quot;
|
||||
intmax_t rem;
|
||||
} imaxdiv_t;
|
||||
|
||||
// 7.8.1 Macros for format specifiers
|
||||
|
||||
#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198
|
||||
|
||||
// The fprintf macros for signed integers are:
|
||||
#define PRId8 "d"
|
||||
#define PRIi8 "i"
|
||||
#define PRIdLEAST8 "d"
|
||||
#define PRIiLEAST8 "i"
|
||||
#define PRIdFAST8 "d"
|
||||
#define PRIiFAST8 "i"
|
||||
|
||||
#define PRId16 "hd"
|
||||
#define PRIi16 "hi"
|
||||
#define PRIdLEAST16 "hd"
|
||||
#define PRIiLEAST16 "hi"
|
||||
#define PRIdFAST16 "hd"
|
||||
#define PRIiFAST16 "hi"
|
||||
|
||||
#define PRId32 "I32d"
|
||||
#define PRIi32 "I32i"
|
||||
#define PRIdLEAST32 "I32d"
|
||||
#define PRIiLEAST32 "I32i"
|
||||
#define PRIdFAST32 "I32d"
|
||||
#define PRIiFAST32 "I32i"
|
||||
|
||||
#define PRId64 "I64d"
|
||||
#define PRIi64 "I64i"
|
||||
#define PRIdLEAST64 "I64d"
|
||||
#define PRIiLEAST64 "I64i"
|
||||
#define PRIdFAST64 "I64d"
|
||||
#define PRIiFAST64 "I64i"
|
||||
|
||||
#define PRIdMAX "I64d"
|
||||
#define PRIiMAX "I64i"
|
||||
|
||||
#define PRIdPTR "Id"
|
||||
#define PRIiPTR "Ii"
|
||||
|
||||
// The fprintf macros for unsigned integers are:
|
||||
#define PRIo8 "o"
|
||||
#define PRIu8 "u"
|
||||
#define PRIx8 "x"
|
||||
#define PRIX8 "X"
|
||||
#define PRIoLEAST8 "o"
|
||||
#define PRIuLEAST8 "u"
|
||||
#define PRIxLEAST8 "x"
|
||||
#define PRIXLEAST8 "X"
|
||||
#define PRIoFAST8 "o"
|
||||
#define PRIuFAST8 "u"
|
||||
#define PRIxFAST8 "x"
|
||||
#define PRIXFAST8 "X"
|
||||
|
||||
#define PRIo16 "ho"
|
||||
#define PRIu16 "hu"
|
||||
#define PRIx16 "hx"
|
||||
#define PRIX16 "hX"
|
||||
#define PRIoLEAST16 "ho"
|
||||
#define PRIuLEAST16 "hu"
|
||||
#define PRIxLEAST16 "hx"
|
||||
#define PRIXLEAST16 "hX"
|
||||
#define PRIoFAST16 "ho"
|
||||
#define PRIuFAST16 "hu"
|
||||
#define PRIxFAST16 "hx"
|
||||
#define PRIXFAST16 "hX"
|
||||
|
||||
#define PRIo32 "I32o"
|
||||
#define PRIu32 "I32u"
|
||||
#define PRIx32 "I32x"
|
||||
#define PRIX32 "I32X"
|
||||
#define PRIoLEAST32 "I32o"
|
||||
#define PRIuLEAST32 "I32u"
|
||||
#define PRIxLEAST32 "I32x"
|
||||
#define PRIXLEAST32 "I32X"
|
||||
#define PRIoFAST32 "I32o"
|
||||
#define PRIuFAST32 "I32u"
|
||||
#define PRIxFAST32 "I32x"
|
||||
#define PRIXFAST32 "I32X"
|
||||
|
||||
#define PRIo64 "I64o"
|
||||
#define PRIu64 "I64u"
|
||||
#define PRIx64 "I64x"
|
||||
#define PRIX64 "I64X"
|
||||
#define PRIoLEAST64 "I64o"
|
||||
#define PRIuLEAST64 "I64u"
|
||||
#define PRIxLEAST64 "I64x"
|
||||
#define PRIXLEAST64 "I64X"
|
||||
#define PRIoFAST64 "I64o"
|
||||
#define PRIuFAST64 "I64u"
|
||||
#define PRIxFAST64 "I64x"
|
||||
#define PRIXFAST64 "I64X"
|
||||
|
||||
#define PRIoMAX "I64o"
|
||||
#define PRIuMAX "I64u"
|
||||
#define PRIxMAX "I64x"
|
||||
#define PRIXMAX "I64X"
|
||||
|
||||
#define PRIoPTR "Io"
|
||||
#define PRIuPTR "Iu"
|
||||
#define PRIxPTR "Ix"
|
||||
#define PRIXPTR "IX"
|
||||
|
||||
// The fscanf macros for signed integers are:
|
||||
#define SCNd8 "d"
|
||||
#define SCNi8 "i"
|
||||
#define SCNdLEAST8 "d"
|
||||
#define SCNiLEAST8 "i"
|
||||
#define SCNdFAST8 "d"
|
||||
#define SCNiFAST8 "i"
|
||||
|
||||
#define SCNd16 "hd"
|
||||
#define SCNi16 "hi"
|
||||
#define SCNdLEAST16 "hd"
|
||||
#define SCNiLEAST16 "hi"
|
||||
#define SCNdFAST16 "hd"
|
||||
#define SCNiFAST16 "hi"
|
||||
|
||||
#define SCNd32 "ld"
|
||||
#define SCNi32 "li"
|
||||
#define SCNdLEAST32 "ld"
|
||||
#define SCNiLEAST32 "li"
|
||||
#define SCNdFAST32 "ld"
|
||||
#define SCNiFAST32 "li"
|
||||
|
||||
#define SCNd64 "I64d"
|
||||
#define SCNi64 "I64i"
|
||||
#define SCNdLEAST64 "I64d"
|
||||
#define SCNiLEAST64 "I64i"
|
||||
#define SCNdFAST64 "I64d"
|
||||
#define SCNiFAST64 "I64i"
|
||||
|
||||
#define SCNdMAX "I64d"
|
||||
#define SCNiMAX "I64i"
|
||||
|
||||
#ifdef _WIN64 // [
|
||||
# define SCNdPTR "I64d"
|
||||
# define SCNiPTR "I64i"
|
||||
#else // _WIN64 ][
|
||||
# define SCNdPTR "ld"
|
||||
# define SCNiPTR "li"
|
||||
#endif // _WIN64 ]
|
||||
|
||||
// The fscanf macros for unsigned integers are:
|
||||
#define SCNo8 "o"
|
||||
#define SCNu8 "u"
|
||||
#define SCNx8 "x"
|
||||
#define SCNX8 "X"
|
||||
#define SCNoLEAST8 "o"
|
||||
#define SCNuLEAST8 "u"
|
||||
#define SCNxLEAST8 "x"
|
||||
#define SCNXLEAST8 "X"
|
||||
#define SCNoFAST8 "o"
|
||||
#define SCNuFAST8 "u"
|
||||
#define SCNxFAST8 "x"
|
||||
#define SCNXFAST8 "X"
|
||||
|
||||
#define SCNo16 "ho"
|
||||
#define SCNu16 "hu"
|
||||
#define SCNx16 "hx"
|
||||
#define SCNX16 "hX"
|
||||
#define SCNoLEAST16 "ho"
|
||||
#define SCNuLEAST16 "hu"
|
||||
#define SCNxLEAST16 "hx"
|
||||
#define SCNXLEAST16 "hX"
|
||||
#define SCNoFAST16 "ho"
|
||||
#define SCNuFAST16 "hu"
|
||||
#define SCNxFAST16 "hx"
|
||||
#define SCNXFAST16 "hX"
|
||||
|
||||
#define SCNo32 "lo"
|
||||
#define SCNu32 "lu"
|
||||
#define SCNx32 "lx"
|
||||
#define SCNX32 "lX"
|
||||
#define SCNoLEAST32 "lo"
|
||||
#define SCNuLEAST32 "lu"
|
||||
#define SCNxLEAST32 "lx"
|
||||
#define SCNXLEAST32 "lX"
|
||||
#define SCNoFAST32 "lo"
|
||||
#define SCNuFAST32 "lu"
|
||||
#define SCNxFAST32 "lx"
|
||||
#define SCNXFAST32 "lX"
|
||||
|
||||
#define SCNo64 "I64o"
|
||||
#define SCNu64 "I64u"
|
||||
#define SCNx64 "I64x"
|
||||
#define SCNX64 "I64X"
|
||||
#define SCNoLEAST64 "I64o"
|
||||
#define SCNuLEAST64 "I64u"
|
||||
#define SCNxLEAST64 "I64x"
|
||||
#define SCNXLEAST64 "I64X"
|
||||
#define SCNoFAST64 "I64o"
|
||||
#define SCNuFAST64 "I64u"
|
||||
#define SCNxFAST64 "I64x"
|
||||
#define SCNXFAST64 "I64X"
|
||||
|
||||
#define SCNoMAX "I64o"
|
||||
#define SCNuMAX "I64u"
|
||||
#define SCNxMAX "I64x"
|
||||
#define SCNXMAX "I64X"
|
||||
|
||||
#ifdef _WIN64 // [
|
||||
# define SCNoPTR "I64o"
|
||||
# define SCNuPTR "I64u"
|
||||
# define SCNxPTR "I64x"
|
||||
# define SCNXPTR "I64X"
|
||||
#else // _WIN64 ][
|
||||
# define SCNoPTR "lo"
|
||||
# define SCNuPTR "lu"
|
||||
# define SCNxPTR "lx"
|
||||
# define SCNXPTR "lX"
|
||||
#endif // _WIN64 ]
|
||||
|
||||
#endif // __STDC_FORMAT_MACROS ]
|
||||
|
||||
// 7.8.2 Functions for greatest-width integer types
|
||||
|
||||
// 7.8.2.1 The imaxabs function
|
||||
#define imaxabs _abs64
|
||||
|
||||
// 7.8.2.2 The imaxdiv function
|
||||
|
||||
// This is modified version of div() function from Microsoft's div.c found
|
||||
// in %MSVC.NET%\crt\src\div.c
|
||||
#ifdef STATIC_IMAXDIV // [
|
||||
static
|
||||
#else // STATIC_IMAXDIV ][
|
||||
_inline
|
||||
#endif // STATIC_IMAXDIV ]
|
||||
imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
|
||||
{
|
||||
imaxdiv_t result;
|
||||
|
||||
result.quot = numer / denom;
|
||||
result.rem = numer % denom;
|
||||
|
||||
if (numer < 0 && result.rem > 0) {
|
||||
// did division wrong; must fix up
|
||||
++result.quot;
|
||||
result.rem -= denom;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// 7.8.2.3 The strtoimax and strtoumax functions
|
||||
#define strtoimax _strtoi64
|
||||
#define strtoumax _strtoui64
|
||||
|
||||
// 7.8.2.4 The wcstoimax and wcstoumax functions
|
||||
#define wcstoimax _wcstoi64
|
||||
#define wcstoumax _wcstoui64
|
||||
|
||||
|
||||
#endif // _MSC_INTTYPES_H_ ]
|
||||
@ -1,259 +0,0 @@
|
||||
// ISO C9x compliant stdint.h for Microsoft Visual Studio
|
||||
// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
|
||||
//
|
||||
// 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:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. 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.
|
||||
//
|
||||
// 3. 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.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _MSC_VER // [
|
||||
#error "Use this header only with Microsoft Visual C++ compilers!"
|
||||
#endif // _MSC_VER ]
|
||||
|
||||
#ifndef _MSC_STDINT_H_ // [
|
||||
#define _MSC_STDINT_H_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#if _MSC_VER >= 1600 // [
|
||||
#include <stdint.h>
|
||||
#else // ] _MSC_VER >= 1600 [
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
|
||||
// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}'
|
||||
// or compiler give many errors like this:
|
||||
// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
# include <wchar.h>
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// Define _W64 macros to mark types changing their size, like intptr_t.
|
||||
#ifndef _W64
|
||||
# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
|
||||
# define _W64 __w64
|
||||
# else
|
||||
# define _W64
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
// 7.18.1 Integer types
|
||||
|
||||
// 7.18.1.1 Exact-width integer types
|
||||
|
||||
// Visual Studio 6 and Embedded Visual C++ 4 doesn't
|
||||
// realize that, e.g. char has the same size as __int8
|
||||
// so we give up on __intX for them.
|
||||
#if (_MSC_VER < 1300)
|
||||
typedef signed char int8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#else
|
||||
typedef signed __int8 int8_t;
|
||||
typedef signed __int16 int16_t;
|
||||
typedef signed __int32 int32_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
#endif
|
||||
typedef signed __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
|
||||
|
||||
// 7.18.1.2 Minimum-width integer types
|
||||
typedef int8_t int_least8_t;
|
||||
typedef int16_t int_least16_t;
|
||||
typedef int32_t int_least32_t;
|
||||
typedef int64_t int_least64_t;
|
||||
typedef uint8_t uint_least8_t;
|
||||
typedef uint16_t uint_least16_t;
|
||||
typedef uint32_t uint_least32_t;
|
||||
typedef uint64_t uint_least64_t;
|
||||
|
||||
// 7.18.1.3 Fastest minimum-width integer types
|
||||
typedef int8_t int_fast8_t;
|
||||
typedef int16_t int_fast16_t;
|
||||
typedef int32_t int_fast32_t;
|
||||
typedef int64_t int_fast64_t;
|
||||
typedef uint8_t uint_fast8_t;
|
||||
typedef uint16_t uint_fast16_t;
|
||||
typedef uint32_t uint_fast32_t;
|
||||
typedef uint64_t uint_fast64_t;
|
||||
|
||||
// 7.18.1.4 Integer types capable of holding object pointers
|
||||
#ifdef _WIN64 // [
|
||||
typedef signed __int64 intptr_t;
|
||||
typedef unsigned __int64 uintptr_t;
|
||||
#else // _WIN64 ][
|
||||
typedef _W64 signed int intptr_t;
|
||||
typedef _W64 unsigned int uintptr_t;
|
||||
#endif // _WIN64 ]
|
||||
|
||||
// 7.18.1.5 Greatest-width integer types
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
|
||||
|
||||
// 7.18.2 Limits of specified-width integer types
|
||||
|
||||
#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
|
||||
|
||||
// 7.18.2.1 Limits of exact-width integer types
|
||||
#define INT8_MIN ((int8_t)_I8_MIN)
|
||||
#define INT8_MAX _I8_MAX
|
||||
#define INT16_MIN ((int16_t)_I16_MIN)
|
||||
#define INT16_MAX _I16_MAX
|
||||
#define INT32_MIN ((int32_t)_I32_MIN)
|
||||
#define INT32_MAX _I32_MAX
|
||||
#define INT64_MIN ((int64_t)_I64_MIN)
|
||||
#define INT64_MAX _I64_MAX
|
||||
#define UINT8_MAX _UI8_MAX
|
||||
#define UINT16_MAX _UI16_MAX
|
||||
#define UINT32_MAX _UI32_MAX
|
||||
#define UINT64_MAX _UI64_MAX
|
||||
|
||||
// 7.18.2.2 Limits of minimum-width integer types
|
||||
#define INT_LEAST8_MIN INT8_MIN
|
||||
#define INT_LEAST8_MAX INT8_MAX
|
||||
#define INT_LEAST16_MIN INT16_MIN
|
||||
#define INT_LEAST16_MAX INT16_MAX
|
||||
#define INT_LEAST32_MIN INT32_MIN
|
||||
#define INT_LEAST32_MAX INT32_MAX
|
||||
#define INT_LEAST64_MIN INT64_MIN
|
||||
#define INT_LEAST64_MAX INT64_MAX
|
||||
#define UINT_LEAST8_MAX UINT8_MAX
|
||||
#define UINT_LEAST16_MAX UINT16_MAX
|
||||
#define UINT_LEAST32_MAX UINT32_MAX
|
||||
#define UINT_LEAST64_MAX UINT64_MAX
|
||||
|
||||
// 7.18.2.3 Limits of fastest minimum-width integer types
|
||||
#define INT_FAST8_MIN INT8_MIN
|
||||
#define INT_FAST8_MAX INT8_MAX
|
||||
#define INT_FAST16_MIN INT16_MIN
|
||||
#define INT_FAST16_MAX INT16_MAX
|
||||
#define INT_FAST32_MIN INT32_MIN
|
||||
#define INT_FAST32_MAX INT32_MAX
|
||||
#define INT_FAST64_MIN INT64_MIN
|
||||
#define INT_FAST64_MAX INT64_MAX
|
||||
#define UINT_FAST8_MAX UINT8_MAX
|
||||
#define UINT_FAST16_MAX UINT16_MAX
|
||||
#define UINT_FAST32_MAX UINT32_MAX
|
||||
#define UINT_FAST64_MAX UINT64_MAX
|
||||
|
||||
// 7.18.2.4 Limits of integer types capable of holding object pointers
|
||||
#ifdef _WIN64 // [
|
||||
# define INTPTR_MIN INT64_MIN
|
||||
# define INTPTR_MAX INT64_MAX
|
||||
# define UINTPTR_MAX UINT64_MAX
|
||||
#else // _WIN64 ][
|
||||
# define INTPTR_MIN INT32_MIN
|
||||
# define INTPTR_MAX INT32_MAX
|
||||
# define UINTPTR_MAX UINT32_MAX
|
||||
#endif // _WIN64 ]
|
||||
|
||||
// 7.18.2.5 Limits of greatest-width integer types
|
||||
#define INTMAX_MIN INT64_MIN
|
||||
#define INTMAX_MAX INT64_MAX
|
||||
#define UINTMAX_MAX UINT64_MAX
|
||||
|
||||
// 7.18.3 Limits of other integer types
|
||||
|
||||
#ifdef _WIN64 // [
|
||||
# define PTRDIFF_MIN _I64_MIN
|
||||
# define PTRDIFF_MAX _I64_MAX
|
||||
#else // _WIN64 ][
|
||||
# define PTRDIFF_MIN _I32_MIN
|
||||
# define PTRDIFF_MAX _I32_MAX
|
||||
#endif // _WIN64 ]
|
||||
|
||||
#define SIG_ATOMIC_MIN INT_MIN
|
||||
#define SIG_ATOMIC_MAX INT_MAX
|
||||
|
||||
#ifndef SIZE_MAX // [
|
||||
# ifdef _WIN64 // [
|
||||
# define SIZE_MAX _UI64_MAX
|
||||
# else // _WIN64 ][
|
||||
# define SIZE_MAX _UI32_MAX
|
||||
# endif // _WIN64 ]
|
||||
#endif // SIZE_MAX ]
|
||||
|
||||
// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
|
||||
#ifndef WCHAR_MIN // [
|
||||
# define WCHAR_MIN 0
|
||||
#endif // WCHAR_MIN ]
|
||||
#ifndef WCHAR_MAX // [
|
||||
# define WCHAR_MAX _UI16_MAX
|
||||
#endif // WCHAR_MAX ]
|
||||
|
||||
#define WINT_MIN 0
|
||||
#define WINT_MAX _UI16_MAX
|
||||
|
||||
#endif // __STDC_LIMIT_MACROS ]
|
||||
|
||||
|
||||
// 7.18.4 Limits of other integer types
|
||||
|
||||
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
|
||||
|
||||
// 7.18.4.1 Macros for minimum-width integer constants
|
||||
|
||||
#define INT8_C(val) val##i8
|
||||
#define INT16_C(val) val##i16
|
||||
#define INT32_C(val) val##i32
|
||||
#define INT64_C(val) val##i64
|
||||
|
||||
#define UINT8_C(val) val##ui8
|
||||
#define UINT16_C(val) val##ui16
|
||||
#define UINT32_C(val) val##ui32
|
||||
#define UINT64_C(val) val##ui64
|
||||
|
||||
// 7.18.4.2 Macros for greatest-width integer constants
|
||||
// These #ifndef's are needed to prevent collisions with <boost/cstdint.hpp>.
|
||||
// Check out Issue 9 for the details.
|
||||
#ifndef INTMAX_C // [
|
||||
# define INTMAX_C INT64_C
|
||||
#endif // INTMAX_C ]
|
||||
#ifndef UINTMAX_C // [
|
||||
# define UINTMAX_C UINT64_C
|
||||
#endif // UINTMAX_C ]
|
||||
|
||||
#endif // __STDC_CONSTANT_MACROS ]
|
||||
|
||||
#endif // _MSC_VER >= 1600 ]
|
||||
|
||||
#endif // _MSC_STDINT_H_ ]
|
||||
191
pyproject.toml
191
pyproject.toml
@ -1,2 +1,191 @@
|
||||
[tool.black]
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
[build-system]
|
||||
requires = ["hatchling", "hatch-vcs", "hatch-fancy-pypi-readme"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
|
||||
[tool.hatch.build.targets.wheel]
|
||||
packages = ["src/argon2"]
|
||||
|
||||
|
||||
[project]
|
||||
name = "argon2-cffi"
|
||||
description = "Argon2 for Python"
|
||||
authors = [{ name = "Hynek Schlawack", email = "hs@ox.cx" }]
|
||||
dynamic = ["version", "readme"]
|
||||
requires-python = ">=3.9"
|
||||
license = "MIT"
|
||||
license-files = ["LICENSE"]
|
||||
keywords = ["password", "hash", "hashing", "security"]
|
||||
classifiers = [
|
||||
"Development Status :: 5 - Production/Stable",
|
||||
"Operating System :: MacOS :: MacOS X",
|
||||
"Operating System :: Microsoft :: Windows",
|
||||
"Operating System :: POSIX",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Programming Language :: Python :: 3.11",
|
||||
"Programming Language :: Python :: 3.12",
|
||||
"Programming Language :: Python :: 3.13",
|
||||
"Programming Language :: Python :: 3.14",
|
||||
"Programming Language :: Python :: Free Threading",
|
||||
"Programming Language :: Python :: Implementation :: CPython",
|
||||
"Programming Language :: Python :: Implementation :: PyPy",
|
||||
"Topic :: Security :: Cryptography",
|
||||
"Typing :: Typed",
|
||||
]
|
||||
dependencies = ["argon2-cffi-bindings"]
|
||||
|
||||
[dependency-groups]
|
||||
tests = ["hypothesis", "pytest"]
|
||||
typing = ["mypy"]
|
||||
docs = [
|
||||
"sphinx",
|
||||
"sphinx-notfound-page",
|
||||
"sphinx-copybutton",
|
||||
"furo",
|
||||
"myst-parser",
|
||||
]
|
||||
dev = [{ include-group = "tests" }, { include-group = "typing" }, "tox>4"]
|
||||
|
||||
[project.urls]
|
||||
Documentation = "https://argon2-cffi.readthedocs.io/"
|
||||
Changelog = "https://github.com/hynek/argon2-cffi/blob/main/CHANGELOG.md"
|
||||
GitHub = "https://github.com/hynek/argon2-cffi"
|
||||
Funding = "https://github.com/sponsors/hynek"
|
||||
Tidelift = "https://tidelift.com/?utm_source=lifter&utm_medium=referral&utm_campaign=hynek"
|
||||
|
||||
|
||||
[tool.hatch.version]
|
||||
source = "vcs"
|
||||
raw-options = { local_scheme = "no-local-version" }
|
||||
|
||||
|
||||
[tool.hatch.metadata.hooks.fancy-pypi-readme]
|
||||
content-type = "text/markdown"
|
||||
|
||||
[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
|
||||
text = "# *argon2-cffi*: Argon2 for Python\n\n"
|
||||
|
||||
[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
|
||||
path = "README.md"
|
||||
start-after = "<!-- begin pypi -->\n"
|
||||
end-before = "\n<!-- end pypi -->"
|
||||
|
||||
[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
|
||||
text = """
|
||||
|
||||
## Release Information
|
||||
|
||||
"""
|
||||
|
||||
[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
|
||||
path = "CHANGELOG.md"
|
||||
start-after = "<!-- changelog follows -->"
|
||||
pattern = "\n(###.+?\n)## "
|
||||
|
||||
[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
|
||||
text = """
|
||||
---
|
||||
|
||||
[Full Changelog →](https://github.com/hynek/argon2-cffi/blob/main/CHANGELOG.md)
|
||||
|
||||
|
||||
"""
|
||||
|
||||
[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
|
||||
path = "README.md"
|
||||
start-at = "## Credits"
|
||||
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
addopts = ["-ra", "--strict-markers", "--strict-config"]
|
||||
xfail_strict = true
|
||||
testpaths = "tests"
|
||||
filterwarnings = ["once::Warning"]
|
||||
|
||||
|
||||
[tool.coverage.run]
|
||||
parallel = true
|
||||
branch = true
|
||||
source = ["argon2"]
|
||||
|
||||
[tool.coverage.paths]
|
||||
source = ["src", ".tox/py*/**/site-packages"]
|
||||
|
||||
[tool.coverage.report]
|
||||
show_missing = true
|
||||
skip_covered = true
|
||||
|
||||
|
||||
[tool.interrogate]
|
||||
verbose = 2
|
||||
fail-under = 100
|
||||
whitelist-regex = ["test_.*"]
|
||||
|
||||
|
||||
[tool.pyright]
|
||||
ignore = ["conftest.py", "docs", "tests"]
|
||||
disableBytesTypePromotions = true
|
||||
|
||||
|
||||
[tool.mypy]
|
||||
strict = true
|
||||
pretty = true
|
||||
|
||||
show_error_codes = true
|
||||
enable_error_code = ["ignore-without-code"]
|
||||
|
||||
ignore_missing_imports = true
|
||||
|
||||
[[tool.mypy.overrides]]
|
||||
module = "tests.*"
|
||||
ignore_errors = true
|
||||
|
||||
|
||||
[tool.ruff]
|
||||
src = ["src", "tests", "noxfile.py"]
|
||||
line-length = 79
|
||||
|
||||
[tool.ruff.lint]
|
||||
select = ["ALL"]
|
||||
ignore = [
|
||||
"A001", # shadowing is fine
|
||||
"A002", # shadowing is fine
|
||||
"A003", # shadowing is fine
|
||||
"ANN", # Mypy is better at this
|
||||
"ARG001", # unused arguments are normal when implementing interfaces
|
||||
"COM", # Formatter takes care of our commas
|
||||
"D", # We prefer our own docstring style.
|
||||
"E501", # leave line-length enforcement to formatter
|
||||
"ERA001", # Dead code detection is overly eager.
|
||||
"FBT", # we have one function that takes one bool; c'mon!
|
||||
"FIX", # Yes, we want XXX as a marker.
|
||||
"INP001", # sometimes we want Python files outside of packages
|
||||
"ISC001", # conflicts with ruff format
|
||||
"PLC0415", # sometimes, imports must live elsewhere
|
||||
"PLR0913", # yes, many arguments, but most have defaults
|
||||
"PLR2004", # numbers are sometimes fine
|
||||
"PLW2901", # re-assigning within loop bodies is fine
|
||||
"RUF001", # leave my smart characters alone
|
||||
"SLF001", # private members are accessed by friendly functions
|
||||
"TCH", # TYPE_CHECKING blocks break autodocs
|
||||
"TD", # we don't follow other people's todo style
|
||||
]
|
||||
|
||||
[tool.ruff.lint.per-file-ignores]
|
||||
"src/argon2/__main__.py" = ["T201"] # need print in CLI
|
||||
"tests/*" = [
|
||||
"ARG", # stubs don't care about arguments
|
||||
"S101", # assert
|
||||
"SIM300", # Yoda rocks in asserts
|
||||
"PT005", # we always add underscores and explicit name
|
||||
"PT011", # broad is fine
|
||||
"TRY002", # stock exceptions are fine in tests
|
||||
"EM101", # no need for exception msg hygiene in tests
|
||||
]
|
||||
|
||||
[tool.ruff.lint.isort]
|
||||
lines-between-types = 1
|
||||
lines-after-imports = 2
|
||||
|
||||
39
setup.cfg
39
setup.cfg
@ -1,39 +0,0 @@
|
||||
# Packaging
|
||||
|
||||
[metadata]
|
||||
# ensure LICENSE is included in wheels
|
||||
license_file = LICENSE
|
||||
|
||||
|
||||
# Testing
|
||||
[tool:pytest]
|
||||
minversion = 3.0
|
||||
strict = true
|
||||
addopts = -ra --capture=no
|
||||
testpaths = tests
|
||||
filterwarnings =
|
||||
once::Warning
|
||||
|
||||
|
||||
[flake8]
|
||||
exclude = src/argon2/_ffi.py
|
||||
ignore =
|
||||
# Ambiguous variable names
|
||||
# Ignored, since there is an enum value "I" for the algorithm type Argon2I
|
||||
E741
|
||||
# Not an actual PEP8 violation
|
||||
W503
|
||||
# Black vs flake8 conflict
|
||||
E203
|
||||
|
||||
|
||||
[isort]
|
||||
atomic=true
|
||||
include_trailing_comma=true
|
||||
lines_after_imports=2
|
||||
lines_between_types=1
|
||||
multi_line_output=3
|
||||
not_skip=__init__.py
|
||||
|
||||
known_first_party=argon2
|
||||
known_third_party=argon2,cffi,hypothesis,pytest,setuptools,six
|
||||
361
setup.py
361
setup.py
@ -1,361 +0,0 @@
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
import codecs
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import sys
|
||||
|
||||
from distutils.command.build import build
|
||||
from distutils.command.build_clib import build_clib
|
||||
from distutils.errors import DistutilsSetupError
|
||||
|
||||
from setuptools import find_packages, setup
|
||||
from setuptools.command.install import install
|
||||
|
||||
|
||||
###############################################################################
|
||||
|
||||
NAME = "argon2_cffi"
|
||||
PACKAGES = find_packages(where="src")
|
||||
|
||||
# Optimized version requires SSE2 extensions. They have been around since
|
||||
# 2001 so we try to compile it on every recent-ish x86.
|
||||
optimized = platform.machine() in ("i686", "x86", "x86_64", "AMD64")
|
||||
|
||||
CFFI_MODULES = ["src/argon2/_ffi_build.py:ffi"]
|
||||
lib_base = os.path.join("extras", "libargon2", "src")
|
||||
include_dirs = [
|
||||
os.path.join(lib_base, "..", "include"),
|
||||
os.path.join(lib_base, "blake2"),
|
||||
]
|
||||
sources = [
|
||||
os.path.join(lib_base, path)
|
||||
for path in [
|
||||
"argon2.c",
|
||||
os.path.join("blake2", "blake2b.c"),
|
||||
"core.c",
|
||||
"encoding.c",
|
||||
"opt.c" if optimized else "ref.c",
|
||||
"thread.c",
|
||||
]
|
||||
]
|
||||
|
||||
# Add vendored integer types headers if necessary.
|
||||
windows = "win32" in str(sys.platform).lower()
|
||||
if windows:
|
||||
int_base = "extras/msinttypes/"
|
||||
inttypes = int_base + "inttypes"
|
||||
stdint = int_base + "stdint"
|
||||
vi = sys.version_info[0:2]
|
||||
if vi in [(2, 6), (2, 7)]:
|
||||
# VS 2008 needs both.
|
||||
include_dirs += [inttypes, stdint]
|
||||
elif vi in [(3, 3), (3, 4)]:
|
||||
# VS 2010 needs inttypes.h and fails with both.
|
||||
include_dirs += [inttypes]
|
||||
|
||||
LIBRARIES = [("argon2", {"include_dirs": include_dirs, "sources": sources})]
|
||||
META_PATH = os.path.join("src", "argon2", "__init__.py")
|
||||
KEYWORDS = ["password", "hash", "hashing", "security"]
|
||||
PROJECT_URLS = {
|
||||
"Documentation": "https://argon2-cffi.readthedocs.io/",
|
||||
"Bug Tracker": "https://github.com/hynek/argon2-cffi/issues",
|
||||
"Source Code": "https://github.com/hynek/argon2-cffi",
|
||||
}
|
||||
CLASSIFIERS = [
|
||||
"Development Status :: 5 - Production/Stable",
|
||||
"Intended Audience :: Developers",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Natural Language :: English",
|
||||
"Operating System :: MacOS :: MacOS X",
|
||||
"Operating System :: Microsoft :: Windows",
|
||||
"Operating System :: POSIX",
|
||||
"Operating System :: Unix",
|
||||
"Programming Language :: Python :: 2",
|
||||
"Programming Language :: Python :: 2.7",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.4",
|
||||
"Programming Language :: Python :: 3.5",
|
||||
"Programming Language :: Python :: 3.6",
|
||||
"Programming Language :: Python :: 3.7",
|
||||
"Programming Language :: Python :: Implementation :: CPython",
|
||||
"Programming Language :: Python :: Implementation :: PyPy",
|
||||
"Programming Language :: Python",
|
||||
"Topic :: Security :: Cryptography",
|
||||
"Topic :: Security",
|
||||
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||
]
|
||||
|
||||
SETUP_REQUIRES = ["cffi"]
|
||||
if windows and sys.version_info[0] == 2:
|
||||
# required for "Microsoft Visual C++ Compiler for Python 2.7"
|
||||
# https://www.microsoft.com/en-us/download/details.aspx?id=44266
|
||||
SETUP_REQUIRES.append("setuptools>=6.0")
|
||||
|
||||
INSTALL_REQUIRES = ["cffi>=1.0.0", "six"]
|
||||
# We're not building an universal wheel so this works.
|
||||
if sys.version_info[0:2] < (3, 4):
|
||||
INSTALL_REQUIRES += ["enum34"]
|
||||
|
||||
EXTRAS_REQUIRE = {
|
||||
"docs": ["sphinx"],
|
||||
"tests": ["coverage", "hypothesis", "pytest"],
|
||||
}
|
||||
EXTRAS_REQUIRE["dev"] = (
|
||||
EXTRAS_REQUIRE["tests"] + EXTRAS_REQUIRE["docs"] + ["wheel", "pre-commit"]
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
|
||||
|
||||
def keywords_with_side_effects(argv):
|
||||
"""
|
||||
Get a dictionary with setup keywords that (can) have side effects.
|
||||
|
||||
:param argv: A list of strings with command line arguments.
|
||||
|
||||
:returns: A dictionary with keyword arguments for the ``setup()`` function.
|
||||
This setup.py script uses the setuptools 'setup_requires' feature
|
||||
because this is required by the cffi package to compile extension
|
||||
modules. The purpose of ``keywords_with_side_effects()`` is to avoid
|
||||
triggering the cffi build process as a result of setup.py invocations
|
||||
that don't need the cffi module to be built (setup.py serves the dual
|
||||
purpose of exposing package metadata).
|
||||
|
||||
Stolen from pyca/cryptography.
|
||||
"""
|
||||
no_setup_requires_arguments = (
|
||||
"-h",
|
||||
"--help",
|
||||
"-n",
|
||||
"--dry-run",
|
||||
"-q",
|
||||
"--quiet",
|
||||
"-v",
|
||||
"--verbose",
|
||||
"-V",
|
||||
"--version",
|
||||
"--author",
|
||||
"--author-email",
|
||||
"--classifiers",
|
||||
"--contact",
|
||||
"--contact-email",
|
||||
"--description",
|
||||
"--egg-base",
|
||||
"--fullname",
|
||||
"--help-commands",
|
||||
"--keywords",
|
||||
"--licence",
|
||||
"--license",
|
||||
"--long-description",
|
||||
"--maintainer",
|
||||
"--maintainer-email",
|
||||
"--name",
|
||||
"--no-user-cfg",
|
||||
"--obsoletes",
|
||||
"--platforms",
|
||||
"--provides",
|
||||
"--requires",
|
||||
"--url",
|
||||
"clean",
|
||||
"egg_info",
|
||||
"register",
|
||||
"sdist",
|
||||
"upload",
|
||||
)
|
||||
|
||||
def is_short_option(argument):
|
||||
"""Check whether a command line argument is a short option."""
|
||||
return len(argument) >= 2 and argument[0] == "-" and argument[1] != "-"
|
||||
|
||||
def expand_short_options(argument):
|
||||
"""Expand combined short options into canonical short options."""
|
||||
return ("-" + char for char in argument[1:])
|
||||
|
||||
def argument_without_setup_requirements(argv, i):
|
||||
"""Check whether a command line argument needs setup requirements."""
|
||||
if argv[i] in no_setup_requires_arguments:
|
||||
# Simple case: An argument which is either an option or a command
|
||||
# which doesn't need setup requirements.
|
||||
return True
|
||||
elif is_short_option(argv[i]) and all(
|
||||
option in no_setup_requires_arguments
|
||||
for option in expand_short_options(argv[i])
|
||||
):
|
||||
# Not so simple case: Combined short options none of which need
|
||||
# setup requirements.
|
||||
return True
|
||||
elif argv[i - 1 : i] == ["--egg-base"]:
|
||||
# Tricky case: --egg-info takes an argument which should not make
|
||||
# us use setup_requires (defeating the purpose of this code).
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
if all(
|
||||
argument_without_setup_requirements(argv, i)
|
||||
for i in range(1, len(argv))
|
||||
):
|
||||
return {"cmdclass": {"build": DummyBuild, "install": DummyInstall}}
|
||||
else:
|
||||
use_system_argon2 = (
|
||||
os.environ.get("ARGON2_CFFI_USE_SYSTEM", "0") == "1"
|
||||
)
|
||||
if use_system_argon2:
|
||||
disable_subcommand(build, "build_clib")
|
||||
return {
|
||||
"setup_requires": SETUP_REQUIRES,
|
||||
"cffi_modules": CFFI_MODULES,
|
||||
"libraries": LIBRARIES,
|
||||
"cmdclass": {"build_clib": BuildCLibWithCompilerFlags},
|
||||
}
|
||||
|
||||
|
||||
def disable_subcommand(command, subcommand_name):
|
||||
for name, method in command.sub_commands:
|
||||
if name == subcommand_name:
|
||||
command.sub_commands.remove((subcommand_name, method))
|
||||
break
|
||||
|
||||
|
||||
setup_requires_error = (
|
||||
"Requested setup command that needs 'setup_requires' while command line "
|
||||
"arguments implied a side effect free command or option."
|
||||
)
|
||||
|
||||
|
||||
class DummyBuild(build):
|
||||
"""
|
||||
This class makes it very obvious when ``keywords_with_side_effects()`` has
|
||||
incorrectly interpreted the command line arguments to ``setup.py build`` as
|
||||
one of the 'side effect free' commands or options.
|
||||
"""
|
||||
|
||||
def run(self):
|
||||
raise RuntimeError(setup_requires_error)
|
||||
|
||||
|
||||
class DummyInstall(install):
|
||||
"""
|
||||
This class makes it very obvious when ``keywords_with_side_effects()`` has
|
||||
incorrectly interpreted the command line arguments to ``setup.py install``
|
||||
as one of the 'side effect free' commands or options.
|
||||
"""
|
||||
|
||||
def run(self):
|
||||
raise RuntimeError(setup_requires_error)
|
||||
|
||||
|
||||
HERE = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
|
||||
def read(*parts):
|
||||
"""
|
||||
Build an absolute path from *parts* and and return the contents of the
|
||||
resulting file. Assume UTF-8 encoding.
|
||||
"""
|
||||
with codecs.open(os.path.join(HERE, *parts), "rb", "utf-8") as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
META_FILE = read(META_PATH)
|
||||
|
||||
|
||||
def find_meta(meta):
|
||||
"""
|
||||
Extract __*meta*__ from META_FILE.
|
||||
"""
|
||||
meta_match = re.search(
|
||||
r"^__{meta}__ = ['\"]([^'\"]*)['\"]".format(meta=meta), META_FILE, re.M
|
||||
)
|
||||
if meta_match:
|
||||
return meta_match.group(1)
|
||||
raise RuntimeError("Unable to find __{meta}__ string.".format(meta=meta))
|
||||
|
||||
|
||||
VERSION = find_meta("version")
|
||||
URL = find_meta("url")
|
||||
LONG = (
|
||||
read("README.rst")
|
||||
+ "\n\n"
|
||||
+ "Release Information\n"
|
||||
+ "===================\n\n"
|
||||
+ re.search(
|
||||
r"(\d+.\d.\d \(.*?\)\n.*?)\n\n\n----\n\n\n",
|
||||
read("CHANGELOG.rst"),
|
||||
re.S,
|
||||
).group(1)
|
||||
+ "\n\n`Full changelog "
|
||||
+ "<{url}en/stable/changelog.html>`_.\n\n".format(url=URL)
|
||||
+ read("AUTHORS.rst")
|
||||
)
|
||||
|
||||
|
||||
class BuildCLibWithCompilerFlags(build_clib):
|
||||
"""
|
||||
We need to pass ``-msse2`` for the optimized build.
|
||||
"""
|
||||
|
||||
def build_libraries(self, libraries):
|
||||
"""
|
||||
Mostly copy pasta from ``distutils.command.build_clib``.
|
||||
"""
|
||||
for (lib_name, build_info) in libraries:
|
||||
sources = build_info.get("sources")
|
||||
if sources is None or not isinstance(sources, (list, tuple)):
|
||||
raise DistutilsSetupError(
|
||||
"in 'libraries' option (library '%s'), "
|
||||
"'sources' must be present and must be "
|
||||
"a list of source filenames" % lib_name
|
||||
)
|
||||
sources = list(sources)
|
||||
|
||||
print("building '%s' library" % (lib_name,))
|
||||
|
||||
# First, compile the source code to object files in the library
|
||||
# directory. (This should probably change to putting object
|
||||
# files in a temporary build directory.)
|
||||
macros = build_info.get("macros")
|
||||
include_dirs = build_info.get("include_dirs")
|
||||
objects = self.compiler.compile(
|
||||
sources,
|
||||
extra_preargs=["-msse2"] if optimized and not windows else [],
|
||||
output_dir=self.build_temp,
|
||||
macros=macros,
|
||||
include_dirs=include_dirs,
|
||||
debug=self.debug,
|
||||
)
|
||||
|
||||
# Now "link" the object files together into a static library.
|
||||
# (On Unix at least, this isn't really linking -- it just
|
||||
# builds an archive. Whatever.)
|
||||
self.compiler.create_static_lib(
|
||||
objects, lib_name, output_dir=self.build_clib, debug=self.debug
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
setup(
|
||||
name=NAME,
|
||||
description=find_meta("description"),
|
||||
license=find_meta("license"),
|
||||
url=URL,
|
||||
project_urls=PROJECT_URLS,
|
||||
version=VERSION,
|
||||
author=find_meta("author"),
|
||||
author_email=find_meta("email"),
|
||||
maintainer=find_meta("author"),
|
||||
maintainer_email=find_meta("email"),
|
||||
long_description=LONG,
|
||||
keywords=KEYWORDS,
|
||||
packages=PACKAGES,
|
||||
package_dir={"": "src"},
|
||||
classifiers=CLASSIFIERS,
|
||||
install_requires=INSTALL_REQUIRES,
|
||||
extras_require=EXTRAS_REQUIRE,
|
||||
# CFFI
|
||||
zip_safe=False,
|
||||
ext_package="argon2",
|
||||
**keywords_with_side_effects(sys.argv)
|
||||
)
|
||||
@ -1,8 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
"""
|
||||
Argon2 for Python
|
||||
"""
|
||||
|
||||
from . import exceptions, low_level
|
||||
from . import exceptions, low_level, profiles
|
||||
from ._legacy import hash_password, hash_password_raw, verify_password
|
||||
from ._password_hasher import (
|
||||
DEFAULT_HASH_LENGTH,
|
||||
@ -16,19 +18,11 @@ from ._utils import Parameters, extract_parameters
|
||||
from .low_level import Type
|
||||
|
||||
|
||||
__version__ = "18.3.0"
|
||||
|
||||
__title__ = "argon2_cffi"
|
||||
__description__ = "The secure Argon2 password hashing algorithm."
|
||||
__url__ = "https://argon2-cffi.readthedocs.io/"
|
||||
__uri__ = __url__
|
||||
__doc__ = __description__ + " <" + __url__ + ">"
|
||||
__title__ = "argon2-cffi"
|
||||
|
||||
__author__ = "Hynek Schlawack"
|
||||
__email__ = "hs@ox.cx"
|
||||
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2015 " + __author__
|
||||
__license__ = "MIT"
|
||||
|
||||
|
||||
__all__ = [
|
||||
@ -45,5 +39,41 @@ __all__ = [
|
||||
"hash_password",
|
||||
"hash_password_raw",
|
||||
"low_level",
|
||||
"profiles",
|
||||
"verify_password",
|
||||
]
|
||||
|
||||
|
||||
def __getattr__(name: str) -> str:
|
||||
dunder_to_metadata = {
|
||||
"__version__": "version",
|
||||
"__description__": "summary",
|
||||
"__uri__": "",
|
||||
"__url__": "",
|
||||
"__email__": "",
|
||||
}
|
||||
if name not in dunder_to_metadata:
|
||||
msg = f"module {__name__} has no attribute {name}"
|
||||
raise AttributeError(msg)
|
||||
|
||||
import warnings
|
||||
|
||||
from importlib.metadata import metadata
|
||||
|
||||
warnings.warn(
|
||||
f"Accessing argon2.{name} is deprecated and will be "
|
||||
"removed in a future release. Use importlib.metadata directly "
|
||||
"to query for argon2-cffi's packaging metadata.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
meta = metadata("argon2-cffi")
|
||||
|
||||
if name in ("__uri__", "__url__"):
|
||||
return meta["Project-URL"].split(" ", 1)[-1]
|
||||
|
||||
if name == "__email__":
|
||||
return meta["Author-email"].split("<", 1)[1].rstrip(">")
|
||||
|
||||
return meta[dunder_to_metadata[name]]
|
||||
|
||||
@ -1,24 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
import timeit
|
||||
|
||||
import six
|
||||
|
||||
from . import (
|
||||
DEFAULT_HASH_LENGTH,
|
||||
DEFAULT_MEMORY_COST,
|
||||
DEFAULT_PARALLELISM,
|
||||
DEFAULT_TIME_COST,
|
||||
PasswordHasher,
|
||||
profiles,
|
||||
)
|
||||
|
||||
|
||||
def main(argv):
|
||||
parser = argparse.ArgumentParser(description="Benchmark Argon2.")
|
||||
def main(argv: list[str]) -> None:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Benchmark Argon2.",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
)
|
||||
parser.add_argument(
|
||||
"-n", type=int, default=100, help="Number of iterations to measure."
|
||||
)
|
||||
@ -29,61 +31,61 @@ def main(argv):
|
||||
"-m", type=int, help="`memory_cost`", default=DEFAULT_MEMORY_COST
|
||||
)
|
||||
parser.add_argument(
|
||||
"-p", type=int, help="`parallellism`", default=DEFAULT_PARALLELISM
|
||||
"-p", type=int, help="`parallelism`", default=DEFAULT_PARALLELISM
|
||||
)
|
||||
parser.add_argument(
|
||||
"-l", type=int, help="`hash_length`", default=DEFAULT_HASH_LENGTH
|
||||
)
|
||||
parser.add_argument(
|
||||
"--profile",
|
||||
type=str,
|
||||
help="A profile from `argon2.profiles. Takes precedence.",
|
||||
default=None,
|
||||
)
|
||||
|
||||
args = parser.parse_args(argv[1:])
|
||||
|
||||
password = b"secret"
|
||||
ph = PasswordHasher(
|
||||
time_cost=args.t,
|
||||
memory_cost=args.m,
|
||||
parallelism=args.p,
|
||||
hash_len=args.l,
|
||||
)
|
||||
hash = ph.hash(password)
|
||||
|
||||
params = {
|
||||
"time_cost": (args.t, "iterations"),
|
||||
"memory_cost": (args.m, "KiB"),
|
||||
"parallelism": (args.p, "threads"),
|
||||
"hash_len": (args.l, "bytes"),
|
||||
}
|
||||
|
||||
print("Running Argon2id %d times with:" % (args.n,))
|
||||
|
||||
for k, v in sorted(six.iteritems(params)):
|
||||
print("%s: %d %s" % (k, v[0], v[1]))
|
||||
|
||||
print("\nMeasuring...")
|
||||
duration = timeit.timeit(
|
||||
"ph.verify({hash!r}, {password!r})".format(
|
||||
hash=hash, password=password
|
||||
),
|
||||
setup="""\
|
||||
from argon2 import PasswordHasher, Type
|
||||
|
||||
ph = PasswordHasher(
|
||||
time_cost={time_cost!r},
|
||||
memory_cost={memory_cost!r},
|
||||
parallelism={parallelism!r},
|
||||
hash_len={hash_len!r},
|
||||
)
|
||||
gc.enable()""".format(
|
||||
if args.profile:
|
||||
ph = PasswordHasher.from_parameters(
|
||||
getattr(profiles, args.profile.upper())
|
||||
)
|
||||
else:
|
||||
ph = PasswordHasher(
|
||||
time_cost=args.t,
|
||||
memory_cost=args.m,
|
||||
parallelism=args.p,
|
||||
hash_len=args.l,
|
||||
),
|
||||
)
|
||||
hash = ph.hash(password)
|
||||
|
||||
print(f"Running Argon2id {args.n} times with:")
|
||||
|
||||
for name, value, units in [
|
||||
("hash_len", ph.hash_len, "bytes"),
|
||||
("memory_cost", ph.memory_cost, "KiB"),
|
||||
("parallelism", ph.parallelism, "threads"),
|
||||
("time_cost", ph.time_cost, "iterations"),
|
||||
]:
|
||||
print(f"{name}: {value} {units}")
|
||||
|
||||
print("\nMeasuring...")
|
||||
duration = timeit.timeit(
|
||||
f"ph.verify({hash!r}, {password!r})",
|
||||
setup=f"""\
|
||||
from argon2 import PasswordHasher
|
||||
|
||||
ph = PasswordHasher(
|
||||
time_cost={args.t!r},
|
||||
memory_cost={args.m!r},
|
||||
parallelism={args.p!r},
|
||||
hash_len={args.l!r},
|
||||
)
|
||||
gc.enable()""",
|
||||
number=args.n,
|
||||
)
|
||||
print(
|
||||
"\n{0:.3}ms per password verification".format(duration / args.n * 1000)
|
||||
)
|
||||
print(f"\n{duration / args.n * 1000:.1f}ms per password verification")
|
||||
|
||||
|
||||
if __name__ == "__main__": # pragma: nocover
|
||||
if __name__ == "__main__": # pragma: no cover
|
||||
main(sys.argv)
|
||||
|
||||
@ -1,191 +0,0 @@
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
from cffi import FFI
|
||||
|
||||
|
||||
include_dirs = [os.path.join("extras", "libargon2", "include")]
|
||||
use_system_argon2 = os.environ.get("ARGON2_CFFI_USE_SYSTEM", "0") == "1"
|
||||
if use_system_argon2:
|
||||
include_dirs = []
|
||||
|
||||
# Add vendored integer types headers.
|
||||
if "win32" in str(sys.platform).lower():
|
||||
int_base = os.path.join("extras", "msinttypes")
|
||||
inttypes = os.path.join(int_base, "inttypes")
|
||||
stdint = os.path.join(int_base, "stdint")
|
||||
vi = sys.version_info[0:2]
|
||||
if vi in [(2, 6), (2, 7)]:
|
||||
# VS 2008 needs both.
|
||||
include_dirs += [inttypes, stdint]
|
||||
elif vi in [(3, 3), (3, 4)]:
|
||||
# VS 2010 needs only inttypes.h
|
||||
include_dirs += [inttypes]
|
||||
|
||||
|
||||
ffi = FFI()
|
||||
ffi.set_source(
|
||||
"_ffi",
|
||||
"#include <argon2.h>",
|
||||
include_dirs=include_dirs,
|
||||
libraries=["argon2"],
|
||||
)
|
||||
|
||||
ffi.cdef(
|
||||
"""\
|
||||
typedef enum Argon2_type {
|
||||
Argon2_d = ...,
|
||||
Argon2_i = ...,
|
||||
Argon2_id = ...,
|
||||
} argon2_type;
|
||||
typedef enum Argon2_version {
|
||||
ARGON2_VERSION_10 = ...,
|
||||
ARGON2_VERSION_13 = ...,
|
||||
ARGON2_VERSION_NUMBER = ...
|
||||
} argon2_version;
|
||||
|
||||
int argon2_hash(const uint32_t t_cost, const uint32_t m_cost,
|
||||
const uint32_t parallelism, const void *pwd,
|
||||
const size_t pwdlen, const void *salt,
|
||||
const size_t saltlen, void *hash,
|
||||
const size_t hashlen, char *encoded,
|
||||
const size_t encodedlen, argon2_type type,
|
||||
const uint32_t version);
|
||||
|
||||
int argon2_verify(const char *encoded, const void *pwd,
|
||||
const size_t pwdlen, argon2_type type);
|
||||
|
||||
const char *argon2_error_message(int error_code);
|
||||
|
||||
|
||||
typedef int (*allocate_fptr)(uint8_t **memory, size_t bytes_to_allocate);
|
||||
typedef void (*deallocate_fptr)(uint8_t *memory, size_t bytes_to_allocate);
|
||||
|
||||
typedef struct Argon2_Context {
|
||||
uint8_t *out; /* output array */
|
||||
uint32_t outlen; /* digest length */
|
||||
|
||||
uint8_t *pwd; /* password array */
|
||||
uint32_t pwdlen; /* password length */
|
||||
|
||||
uint8_t *salt; /* salt array */
|
||||
uint32_t saltlen; /* salt length */
|
||||
|
||||
uint8_t *secret; /* key array */
|
||||
uint32_t secretlen; /* key length */
|
||||
|
||||
uint8_t *ad; /* associated data array */
|
||||
uint32_t adlen; /* associated data length */
|
||||
|
||||
uint32_t t_cost; /* number of passes */
|
||||
uint32_t m_cost; /* amount of memory requested (KB) */
|
||||
uint32_t lanes; /* number of lanes */
|
||||
uint32_t threads; /* maximum number of threads */
|
||||
|
||||
uint32_t version; /* version number */
|
||||
|
||||
allocate_fptr allocate_cbk; /* pointer to memory allocator */
|
||||
deallocate_fptr free_cbk; /* pointer to memory deallocator */
|
||||
|
||||
uint32_t flags; /* array of bool options */
|
||||
} argon2_context;
|
||||
|
||||
int argon2_ctx(argon2_context *context, argon2_type type);
|
||||
|
||||
/* Error codes */
|
||||
typedef enum Argon2_ErrorCodes {
|
||||
ARGON2_OK = ...,
|
||||
|
||||
ARGON2_OUTPUT_PTR_NULL = ...,
|
||||
|
||||
ARGON2_OUTPUT_TOO_SHORT = ...,
|
||||
ARGON2_OUTPUT_TOO_LONG = ...,
|
||||
|
||||
ARGON2_PWD_TOO_SHORT = ...,
|
||||
ARGON2_PWD_TOO_LONG = ...,
|
||||
|
||||
ARGON2_SALT_TOO_SHORT = ...,
|
||||
ARGON2_SALT_TOO_LONG = ...,
|
||||
|
||||
ARGON2_AD_TOO_SHORT = ...,
|
||||
ARGON2_AD_TOO_LONG = ...,
|
||||
|
||||
ARGON2_SECRET_TOO_SHORT = ...,
|
||||
ARGON2_SECRET_TOO_LONG = ...,
|
||||
|
||||
ARGON2_TIME_TOO_SMALL = ...,
|
||||
ARGON2_TIME_TOO_LARGE = ...,
|
||||
|
||||
ARGON2_MEMORY_TOO_LITTLE = ...,
|
||||
ARGON2_MEMORY_TOO_MUCH = ...,
|
||||
|
||||
ARGON2_LANES_TOO_FEW = ...,
|
||||
ARGON2_LANES_TOO_MANY = ...,
|
||||
|
||||
ARGON2_PWD_PTR_MISMATCH = ..., /* NULL ptr with non-zero length */
|
||||
ARGON2_SALT_PTR_MISMATCH = ..., /* NULL ptr with non-zero length */
|
||||
ARGON2_SECRET_PTR_MISMATCH = ..., /* NULL ptr with non-zero length */
|
||||
ARGON2_AD_PTR_MISMATCH = ..., /* NULL ptr with non-zero length */
|
||||
|
||||
ARGON2_MEMORY_ALLOCATION_ERROR = ...,
|
||||
|
||||
ARGON2_FREE_MEMORY_CBK_NULL = ...,
|
||||
ARGON2_ALLOCATE_MEMORY_CBK_NULL = ...,
|
||||
|
||||
ARGON2_INCORRECT_PARAMETER = ...,
|
||||
ARGON2_INCORRECT_TYPE = ...,
|
||||
|
||||
ARGON2_OUT_PTR_MISMATCH = ...,
|
||||
|
||||
ARGON2_THREADS_TOO_FEW = ...,
|
||||
ARGON2_THREADS_TOO_MANY = ...,
|
||||
|
||||
ARGON2_MISSING_ARGS = ...,
|
||||
|
||||
ARGON2_ENCODING_FAIL = ...,
|
||||
|
||||
ARGON2_DECODING_FAIL = ...,
|
||||
|
||||
ARGON2_THREAD_FAIL = ...,
|
||||
|
||||
ARGON2_DECODING_LENGTH_FAIL= ...,
|
||||
|
||||
ARGON2_VERIFY_MISMATCH = ...,
|
||||
} argon2_error_codes;
|
||||
|
||||
#define ARGON2_FLAG_CLEAR_PASSWORD ...
|
||||
#define ARGON2_FLAG_CLEAR_SECRET ...
|
||||
#define ARGON2_DEFAULT_FLAGS ...
|
||||
|
||||
#define ARGON2_MIN_LANES ...
|
||||
#define ARGON2_MAX_LANES ...
|
||||
#define ARGON2_MIN_THREADS ...
|
||||
#define ARGON2_MAX_THREADS ...
|
||||
#define ARGON2_SYNC_POINTS ...
|
||||
#define ARGON2_MIN_OUTLEN ...
|
||||
#define ARGON2_MAX_OUTLEN ...
|
||||
#define ARGON2_MIN_MEMORY ...
|
||||
#define ARGON2_MAX_MEMORY_BITS ...
|
||||
#define ARGON2_MAX_MEMORY ...
|
||||
#define ARGON2_MIN_TIME ...
|
||||
#define ARGON2_MAX_TIME ...
|
||||
#define ARGON2_MIN_PWD_LENGTH ...
|
||||
#define ARGON2_MAX_PWD_LENGTH ...
|
||||
#define ARGON2_MIN_AD_LENGTH ...
|
||||
#define ARGON2_MAX_AD_LENGTH ...
|
||||
#define ARGON2_MIN_SALT_LENGTH ...
|
||||
#define ARGON2_MAX_SALT_LENGTH ...
|
||||
#define ARGON2_MIN_SECRET ...
|
||||
#define ARGON2_MAX_SECRET ...
|
||||
|
||||
uint32_t argon2_encodedlen(uint32_t t_cost, uint32_t m_cost,
|
||||
uint32_t parallelism, uint32_t saltlen,
|
||||
uint32_t hashlen, argon2_type type);
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
ffi.compile()
|
||||
@ -1,10 +1,15 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
"""
|
||||
Legacy mid-level functions.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import warnings
|
||||
|
||||
from typing import Literal
|
||||
|
||||
from ._password_hasher import (
|
||||
DEFAULT_HASH_LENGTH,
|
||||
@ -16,21 +21,28 @@ from ._password_hasher import (
|
||||
from .low_level import Type, hash_secret, hash_secret_raw, verify_secret
|
||||
|
||||
|
||||
_INSTEAD = " is deprecated, use argon2.PasswordHasher instead"
|
||||
|
||||
|
||||
def hash_password(
|
||||
password,
|
||||
salt=None,
|
||||
time_cost=DEFAULT_TIME_COST,
|
||||
memory_cost=DEFAULT_MEMORY_COST,
|
||||
parallelism=DEFAULT_PARALLELISM,
|
||||
hash_len=DEFAULT_HASH_LENGTH,
|
||||
type=Type.I,
|
||||
):
|
||||
password: bytes,
|
||||
salt: bytes | None = None,
|
||||
time_cost: int = DEFAULT_TIME_COST,
|
||||
memory_cost: int = DEFAULT_MEMORY_COST,
|
||||
parallelism: int = DEFAULT_PARALLELISM,
|
||||
hash_len: int = DEFAULT_HASH_LENGTH,
|
||||
type: Type = Type.I,
|
||||
) -> bytes:
|
||||
"""
|
||||
Legacy alias for :func:`hash_secret` with default parameters.
|
||||
Legacy alias for :func:`argon2.low_level.hash_secret` with default
|
||||
parameters.
|
||||
|
||||
.. deprecated:: 16.0.0
|
||||
Use :class:`argon2.PasswordHasher` for passwords.
|
||||
"""
|
||||
warnings.warn(
|
||||
"argon2.hash_password" + _INSTEAD, DeprecationWarning, stacklevel=2
|
||||
)
|
||||
if salt is None:
|
||||
salt = os.urandom(DEFAULT_RANDOM_SALT_LENGTH)
|
||||
return hash_secret(
|
||||
@ -39,20 +51,24 @@ def hash_password(
|
||||
|
||||
|
||||
def hash_password_raw(
|
||||
password,
|
||||
salt=None,
|
||||
time_cost=DEFAULT_TIME_COST,
|
||||
memory_cost=DEFAULT_MEMORY_COST,
|
||||
parallelism=DEFAULT_PARALLELISM,
|
||||
hash_len=DEFAULT_HASH_LENGTH,
|
||||
type=Type.I,
|
||||
):
|
||||
password: bytes,
|
||||
salt: bytes | None = None,
|
||||
time_cost: int = DEFAULT_TIME_COST,
|
||||
memory_cost: int = DEFAULT_MEMORY_COST,
|
||||
parallelism: int = DEFAULT_PARALLELISM,
|
||||
hash_len: int = DEFAULT_HASH_LENGTH,
|
||||
type: Type = Type.I,
|
||||
) -> bytes:
|
||||
"""
|
||||
Legacy alias for :func:`hash_secret_raw` with default parameters.
|
||||
Legacy alias for :func:`argon2.low_level.hash_secret_raw` with default
|
||||
parameters.
|
||||
|
||||
.. deprecated:: 16.0.0
|
||||
Use :class:`argon2.PasswordHasher` for passwords.
|
||||
"""
|
||||
warnings.warn(
|
||||
"argon2.hash_password_raw" + _INSTEAD, DeprecationWarning, stacklevel=2
|
||||
)
|
||||
if salt is None:
|
||||
salt = os.urandom(DEFAULT_RANDOM_SALT_LENGTH)
|
||||
return hash_secret_raw(
|
||||
@ -60,11 +76,17 @@ def hash_password_raw(
|
||||
)
|
||||
|
||||
|
||||
def verify_password(hash, password, type=Type.I):
|
||||
def verify_password(
|
||||
hash: bytes, password: bytes, type: Type = Type.I
|
||||
) -> Literal[True]:
|
||||
"""
|
||||
Legacy alias for :func:`verify_secret` with default parameters.
|
||||
Legacy alias for :func:`argon2.low_level.verify_secret` with default
|
||||
parameters.
|
||||
|
||||
.. deprecated:: 16.0.0
|
||||
Use :class:`argon2.PasswordHasher` for passwords.
|
||||
"""
|
||||
warnings.warn(
|
||||
"argon2.verify_password" + _INSTEAD, DeprecationWarning, stacklevel=2
|
||||
)
|
||||
return verify_secret(hash, password, type)
|
||||
|
||||
@ -1,20 +1,32 @@
|
||||
from __future__ import absolute_import, division, print_function
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
from ._utils import Parameters, _check_types, extract_parameters
|
||||
from .exceptions import InvalidHash
|
||||
from typing import ClassVar, Literal
|
||||
|
||||
from ._utils import (
|
||||
Parameters,
|
||||
_check_types,
|
||||
extract_parameters,
|
||||
validate_params_for_platform,
|
||||
)
|
||||
from .exceptions import InvalidHashError
|
||||
from .low_level import Type, hash_secret, verify_secret
|
||||
from .profiles import get_default_parameters
|
||||
|
||||
|
||||
DEFAULT_RANDOM_SALT_LENGTH = 16
|
||||
DEFAULT_HASH_LENGTH = 16
|
||||
DEFAULT_TIME_COST = 2
|
||||
DEFAULT_MEMORY_COST = 102400
|
||||
DEFAULT_PARALLELISM = 8
|
||||
default_params = get_default_parameters()
|
||||
|
||||
DEFAULT_RANDOM_SALT_LENGTH = default_params.salt_len
|
||||
DEFAULT_HASH_LENGTH = default_params.hash_len
|
||||
DEFAULT_TIME_COST = default_params.time_cost
|
||||
DEFAULT_MEMORY_COST = default_params.memory_cost
|
||||
DEFAULT_PARALLELISM = default_params.parallelism
|
||||
|
||||
|
||||
def _ensure_bytes(s, encoding):
|
||||
def _ensure_bytes(s: bytes | str, encoding: str) -> bytes:
|
||||
"""
|
||||
Ensure *s* is a bytes string. Encode using *encoding* if it isn't.
|
||||
"""
|
||||
@ -23,56 +35,71 @@ def _ensure_bytes(s, encoding):
|
||||
return s.encode(encoding)
|
||||
|
||||
|
||||
class PasswordHasher(object):
|
||||
class PasswordHasher:
|
||||
r"""
|
||||
High level class to hash passwords with sensible defaults.
|
||||
|
||||
Uses Argon2\ **id** by default and always uses a random salt_ for hashing.
|
||||
But it can verify any type of Argon2 as long as the hash is correctly
|
||||
encoded.
|
||||
Uses Argon2\ **id** by default and uses a random salt_ for hashing. But it
|
||||
can verify any type of Argon2 as long as the hash is correctly encoded.
|
||||
|
||||
The reason for this being a class is both for convenience to carry
|
||||
parameters and to verify the parameters only *once*. Any unnecessary
|
||||
slowdown when hashing is a tangible advantage for a brute force attacker.
|
||||
slowdown when hashing is a tangible advantage for a brute-force attacker.
|
||||
|
||||
:param int time_cost: Defines the amount of computation realized and
|
||||
therefore the execution time, given in number of iterations.
|
||||
:param int memory_cost: Defines the memory usage, given in kibibytes_.
|
||||
:param int parallelism: Defines the number of parallel threads (*changes*
|
||||
the resulting hash value).
|
||||
:param int hash_len: Length of the hash in bytes.
|
||||
:param int salt_len: Length of random salt to be generated for each
|
||||
password.
|
||||
:param str encoding: The Argon2 C library expects bytes. So if
|
||||
:meth:`hash` or :meth:`verify` are passed an unicode string, it will be
|
||||
encoded using this encoding.
|
||||
:param Type type: Argon2 type to use. Only change for interoperability
|
||||
with legacy systems.
|
||||
Args:
|
||||
time_cost:
|
||||
Defines the amount of computation realized and therefore the
|
||||
execution time, given in number of iterations.
|
||||
|
||||
memory_cost: Defines the memory usage, given in kibibytes_.
|
||||
|
||||
parallelism:
|
||||
Defines the number of parallel threads (*changes* the resulting
|
||||
hash value).
|
||||
|
||||
hash_len: Length of the hash in bytes.
|
||||
|
||||
salt_len: Length of random salt to be generated for each password.
|
||||
|
||||
encoding:
|
||||
The Argon2 C library expects bytes. So if :meth:`hash` or
|
||||
:meth:`verify` are passed a ``str``, it will be encoded using this
|
||||
encoding.
|
||||
|
||||
type:
|
||||
Argon2 type to use. Only change for interoperability with legacy
|
||||
systems.
|
||||
|
||||
.. versionadded:: 16.0.0
|
||||
.. versionchanged:: 18.2.0
|
||||
Switch from Argon2i to Argon2id based on the recommendation by the
|
||||
current RFC_ draft.
|
||||
current RFC draft. See also :doc:`parameters`.
|
||||
.. versionchanged:: 18.2.0
|
||||
Changed default *memory_cost* to 100 MiB and default *parallelism* to 8.
|
||||
.. versionchanged:: 18.2.0 ``verify`` now will determine the type of hash.
|
||||
.. versionchanged:: 18.3.0 The Argon2 type is configurable now.
|
||||
.. versionadded:: 21.2.0 :meth:`from_parameters`
|
||||
.. versionchanged:: 21.2.0
|
||||
Changed defaults to :data:`argon2.profiles.RFC_9106_LOW_MEMORY`.
|
||||
|
||||
.. _salt: https://en.wikipedia.org/wiki/Salt_(cryptography)
|
||||
.. _kibibytes: https://en.wikipedia.org/wiki/Binary_prefix#kibi
|
||||
.. _RFC: https://tools.ietf.org/html/draft-irtf-cfrg-argon2-03#section-4
|
||||
"""
|
||||
|
||||
__slots__ = ["_parameters", "encoding"]
|
||||
|
||||
_parameters: Parameters
|
||||
encoding: str
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
time_cost=DEFAULT_TIME_COST,
|
||||
memory_cost=DEFAULT_MEMORY_COST,
|
||||
parallelism=DEFAULT_PARALLELISM,
|
||||
hash_len=DEFAULT_HASH_LENGTH,
|
||||
salt_len=DEFAULT_RANDOM_SALT_LENGTH,
|
||||
encoding="utf-8",
|
||||
type=Type.ID,
|
||||
time_cost: int = DEFAULT_TIME_COST,
|
||||
memory_cost: int = DEFAULT_MEMORY_COST,
|
||||
parallelism: int = DEFAULT_PARALLELISM,
|
||||
hash_len: int = DEFAULT_HASH_LENGTH,
|
||||
salt_len: int = DEFAULT_RANDOM_SALT_LENGTH,
|
||||
encoding: str = "utf-8",
|
||||
type: Type = Type.ID,
|
||||
):
|
||||
e = _check_types(
|
||||
time_cost=(time_cost, int),
|
||||
@ -86,8 +113,7 @@ class PasswordHasher(object):
|
||||
if e:
|
||||
raise TypeError(e)
|
||||
|
||||
# Cache a Parameters object for check_needs_rehash.
|
||||
self._parameters = Parameters(
|
||||
params = Parameters(
|
||||
type=type,
|
||||
version=19,
|
||||
salt_len=salt_len,
|
||||
@ -96,46 +122,83 @@ class PasswordHasher(object):
|
||||
memory_cost=memory_cost,
|
||||
parallelism=parallelism,
|
||||
)
|
||||
|
||||
validate_params_for_platform(params)
|
||||
|
||||
# Cache a Parameters object for check_needs_rehash.
|
||||
self._parameters = params
|
||||
self.encoding = encoding
|
||||
|
||||
@classmethod
|
||||
def from_parameters(cls, params: Parameters) -> PasswordHasher:
|
||||
"""
|
||||
Construct a `PasswordHasher` from *params*.
|
||||
|
||||
Returns:
|
||||
A `PasswordHasher` instance with the parameters from *params*.
|
||||
|
||||
.. versionadded:: 21.2.0
|
||||
"""
|
||||
|
||||
return cls(
|
||||
time_cost=params.time_cost,
|
||||
memory_cost=params.memory_cost,
|
||||
parallelism=params.parallelism,
|
||||
hash_len=params.hash_len,
|
||||
salt_len=params.salt_len,
|
||||
type=params.type,
|
||||
)
|
||||
|
||||
@property
|
||||
def time_cost(self):
|
||||
def time_cost(self) -> int:
|
||||
return self._parameters.time_cost
|
||||
|
||||
@property
|
||||
def memory_cost(self):
|
||||
def memory_cost(self) -> int:
|
||||
return self._parameters.memory_cost
|
||||
|
||||
@property
|
||||
def parallelism(self):
|
||||
def parallelism(self) -> int:
|
||||
return self._parameters.parallelism
|
||||
|
||||
@property
|
||||
def hash_len(self):
|
||||
def hash_len(self) -> int:
|
||||
return self._parameters.hash_len
|
||||
|
||||
@property
|
||||
def salt_len(self):
|
||||
def salt_len(self) -> int:
|
||||
return self._parameters.salt_len
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
def type(self) -> Type:
|
||||
return self._parameters.type
|
||||
|
||||
def hash(self, password):
|
||||
def hash(self, password: str | bytes, *, salt: bytes | None = None) -> str:
|
||||
"""
|
||||
Hash *password* and return an encoded hash.
|
||||
|
||||
:param password: Password to hash.
|
||||
:type password: ``bytes`` or ``unicode``
|
||||
Args:
|
||||
password: Password to hash.
|
||||
|
||||
:raises argon2.exceptions.HashingError: If hashing fails.
|
||||
salt:
|
||||
If None, a random salt is securely created.
|
||||
|
||||
:rtype: unicode
|
||||
.. danger::
|
||||
|
||||
You should **not** pass a salt unless you really know what
|
||||
you are doing.
|
||||
|
||||
Raises:
|
||||
argon2.exceptions.HashingError: If hashing fails.
|
||||
|
||||
Returns:
|
||||
Hashed *password*.
|
||||
|
||||
.. versionadded:: 23.1.0 *salt* parameter
|
||||
"""
|
||||
return hash_secret(
|
||||
secret=_ensure_bytes(password, self.encoding),
|
||||
salt=os.urandom(self.salt_len),
|
||||
salt=salt or os.urandom(self.salt_len),
|
||||
time_cost=self.time_cost,
|
||||
memory_cost=self.memory_cost,
|
||||
parallelism=self.parallelism,
|
||||
@ -143,13 +206,15 @@ class PasswordHasher(object):
|
||||
type=self.type,
|
||||
).decode("ascii")
|
||||
|
||||
_header_to_type = {
|
||||
_header_to_type: ClassVar[dict[bytes, Type]] = {
|
||||
b"$argon2i$": Type.I,
|
||||
b"$argon2d$": Type.D,
|
||||
b"$argon2id": Type.ID,
|
||||
}
|
||||
|
||||
def verify(self, hash, password):
|
||||
def verify(
|
||||
self, hash: str | bytes, password: str | bytes
|
||||
) -> Literal[True]:
|
||||
"""
|
||||
Verify that *password* matches *hash*.
|
||||
|
||||
@ -157,25 +222,27 @@ class PasswordHasher(object):
|
||||
|
||||
It is assumed that the caller is in full control of the hash. No
|
||||
other parsing than the determination of the hash type is done by
|
||||
``argon2_cffi``.
|
||||
*argon2-cffi*.
|
||||
|
||||
:param hash: An encoded hash as returned from
|
||||
:meth:`PasswordHasher.hash`.
|
||||
:type hash: ``bytes`` or ``unicode``
|
||||
Args:
|
||||
hash: An encoded hash as returned from :meth:`PasswordHasher.hash`.
|
||||
|
||||
:param password: The password to verify.
|
||||
:type password: ``bytes`` or ``unicode``
|
||||
password: The password to verify.
|
||||
|
||||
:raises argon2.exceptions.VerifyMismatchError: If verification fails
|
||||
because *hash* is not valid for *password*.
|
||||
:raises argon2.exceptions.VerificationError: If verification fails for
|
||||
other reasons.
|
||||
:raises argon2.exceptions.InvalidHash: If *hash* is so clearly
|
||||
invalid, that it couldn't be passed to Argon2.
|
||||
Raises:
|
||||
argon2.exceptions.VerifyMismatchError:
|
||||
If verification fails because *hash* is not valid for
|
||||
*password*.
|
||||
|
||||
:return: ``True`` on success, raise
|
||||
:exc:`~argon2.exceptions.VerificationError` otherwise.
|
||||
:rtype: bool
|
||||
argon2.exceptions.VerificationError:
|
||||
If verification fails for other reasons.
|
||||
|
||||
argon2.exceptions.InvalidHashError:
|
||||
If *hash* is so clearly invalid, that it couldn't be passed to
|
||||
Argon2.
|
||||
|
||||
Returns:
|
||||
``True`` on success, otherwise an exception is raised.
|
||||
|
||||
.. versionchanged:: 16.1.0
|
||||
Raise :exc:`~argon2.exceptions.VerifyMismatchError` on mismatches
|
||||
@ -185,18 +252,18 @@ class PasswordHasher(object):
|
||||
hash = _ensure_bytes(hash, "ascii")
|
||||
try:
|
||||
hash_type = self._header_to_type[hash[:9]]
|
||||
except (IndexError, KeyError, LookupError):
|
||||
raise InvalidHash()
|
||||
except LookupError:
|
||||
raise InvalidHashError from None
|
||||
|
||||
return verify_secret(
|
||||
hash, _ensure_bytes(password, self.encoding), hash_type
|
||||
)
|
||||
|
||||
def check_needs_rehash(self, hash):
|
||||
def check_needs_rehash(self, hash: str | bytes) -> bool:
|
||||
"""
|
||||
Check whether *hash* was created using the instance's parameters.
|
||||
|
||||
Whenever your Argon2 parameters -- or ``argon2_cffi``'s defaults! --
|
||||
Whenever your Argon2 parameters -- or *argon2-cffi*'s defaults! --
|
||||
change, you should rehash your passwords at the next opportunity. The
|
||||
common approach is to do that whenever a user logs in, since that
|
||||
should be the only time when you have access to the cleartext
|
||||
@ -205,8 +272,16 @@ class PasswordHasher(object):
|
||||
Therefore it's best practice to check -- and if necessary rehash --
|
||||
passwords after each successful authentication.
|
||||
|
||||
:rtype: bool
|
||||
Args:
|
||||
hash: An encoded Argon2 password hash.
|
||||
|
||||
Returns:
|
||||
Whether *hash* was created using the instance's parameters.
|
||||
|
||||
.. versionadded:: 18.2.0
|
||||
.. versionchanged:: 24.1.0 Accepts bytes for *hash*.
|
||||
"""
|
||||
if isinstance(hash, bytes):
|
||||
hash = hash.decode("ascii")
|
||||
|
||||
return self._parameters != extract_parameters(hash)
|
||||
|
||||
@ -1,51 +1,54 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
from __future__ import annotations
|
||||
|
||||
from six import iteritems
|
||||
import platform
|
||||
import sys
|
||||
|
||||
from .exceptions import InvalidHash
|
||||
from dataclasses import dataclass
|
||||
|
||||
from .exceptions import InvalidHashError, UnsupportedParametersError
|
||||
from .low_level import Type
|
||||
|
||||
|
||||
NoneType = type(None)
|
||||
|
||||
|
||||
def _check_types(**kw):
|
||||
def _check_types(**kw: tuple[object, type | tuple[type, ...]]) -> str | None:
|
||||
"""
|
||||
Check each ``name: (value, types)`` in *kw*.
|
||||
|
||||
Returns a human-readable string of all violations or `None``.
|
||||
"""
|
||||
errors = []
|
||||
for name, (value, types) in iteritems(kw):
|
||||
for name, (value, types) in kw.items():
|
||||
if not isinstance(value, types):
|
||||
if isinstance(types, tuple):
|
||||
types = ", or ".join(t.__name__ for t in types)
|
||||
type_names = ", or ".join(t.__name__ for t in types)
|
||||
else:
|
||||
types = types.__name__
|
||||
type_names = types.__name__
|
||||
errors.append(
|
||||
"'{name}' must be a {type} (got {actual})".format(
|
||||
name=name, type=types, actual=type(value).__name__
|
||||
)
|
||||
f"'{name}' must be a {type_names} (got {type(value).__name__})"
|
||||
)
|
||||
|
||||
if errors != []:
|
||||
return ", ".join(errors) + "."
|
||||
|
||||
|
||||
def _encoded_str_len(l):
|
||||
"""
|
||||
Compute how long a byte string of length *l* becomes if encoded to hex.
|
||||
"""
|
||||
return (l << 2) / 3 + 2
|
||||
return None
|
||||
|
||||
|
||||
def _decoded_str_len(l):
|
||||
def _is_wasm() -> bool:
|
||||
return sys.platform == "emscripten" or platform.machine() in [
|
||||
"wasm32",
|
||||
"wasm64",
|
||||
]
|
||||
|
||||
|
||||
def _decoded_str_len(length: int) -> int:
|
||||
"""
|
||||
Compute how long an encoded string of length *l* becomes.
|
||||
"""
|
||||
rem = l % 4
|
||||
rem = length % 4
|
||||
|
||||
if rem == 3:
|
||||
last_group_len = 2
|
||||
@ -54,119 +57,80 @@ def _decoded_str_len(l):
|
||||
else:
|
||||
last_group_len = 0
|
||||
|
||||
return l // 4 * 3 + last_group_len
|
||||
return length // 4 * 3 + last_group_len
|
||||
|
||||
|
||||
class Parameters(object):
|
||||
@dataclass
|
||||
class Parameters:
|
||||
"""
|
||||
Argon2 hash parameters.
|
||||
|
||||
See :doc:`parameters` on how to pick them.
|
||||
|
||||
:ivar Type type: Hash type.
|
||||
:ivar int version: Argon2 version.
|
||||
:ivar int salt_len: Length of the salt in bytes.
|
||||
:ivar int hash_len: Length of the hash in bytes.
|
||||
:ivar int time_cost: Time cost in iterations.
|
||||
:ivar int memory_cost: Memory cost in kibibytes.
|
||||
:ivar int parallelism: Number of parallel threads.
|
||||
Attributes:
|
||||
type: Hash type.
|
||||
|
||||
version: Argon2 version.
|
||||
|
||||
salt_len: Length of the salt in bytes.
|
||||
|
||||
hash_len: Length of the hash in bytes.
|
||||
|
||||
time_cost: Time cost in iterations.
|
||||
|
||||
memory_cost: Memory cost in kibibytes.
|
||||
|
||||
parallelism: Number of parallel threads.
|
||||
|
||||
.. versionadded:: 18.2.0
|
||||
"""
|
||||
|
||||
__slots__ = [
|
||||
"type",
|
||||
"version",
|
||||
"salt_len",
|
||||
type: Type
|
||||
version: int
|
||||
salt_len: int
|
||||
hash_len: int
|
||||
time_cost: int
|
||||
memory_cost: int
|
||||
parallelism: int
|
||||
|
||||
__slots__ = (
|
||||
"hash_len",
|
||||
"time_cost",
|
||||
"memory_cost",
|
||||
"parallelism",
|
||||
]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
type,
|
||||
version,
|
||||
salt_len,
|
||||
hash_len,
|
||||
time_cost,
|
||||
memory_cost,
|
||||
parallelism,
|
||||
):
|
||||
self.type = type
|
||||
self.version = version
|
||||
self.salt_len = salt_len
|
||||
self.hash_len = hash_len
|
||||
self.time_cost = time_cost
|
||||
self.memory_cost = memory_cost
|
||||
self.parallelism = parallelism
|
||||
|
||||
def __repr__(self):
|
||||
return (
|
||||
"<Parameters(type=%r, version=%d, hash_len=%d, salt_len=%d, "
|
||||
"time_cost=%d, memory_cost=%d, parallelelism=%d)>"
|
||||
% (
|
||||
self.type,
|
||||
self.version,
|
||||
self.hash_len,
|
||||
self.salt_len,
|
||||
self.time_cost,
|
||||
self.memory_cost,
|
||||
self.parallelism,
|
||||
)
|
||||
)
|
||||
|
||||
def __eq__(self, other):
|
||||
if self.__class__ != other.__class__:
|
||||
return NotImplemented
|
||||
|
||||
return (
|
||||
self.type,
|
||||
self.version,
|
||||
self.salt_len,
|
||||
self.hash_len,
|
||||
self.time_cost,
|
||||
self.memory_cost,
|
||||
self.parallelism,
|
||||
) == (
|
||||
other.type,
|
||||
other.version,
|
||||
other.salt_len,
|
||||
other.hash_len,
|
||||
other.time_cost,
|
||||
other.memory_cost,
|
||||
other.parallelism,
|
||||
)
|
||||
|
||||
def __ne__(self, other):
|
||||
if self.__class__ != other.__class__:
|
||||
return NotImplemented
|
||||
|
||||
return not self.__eq__(other)
|
||||
"salt_len",
|
||||
"time_cost",
|
||||
"type",
|
||||
"version",
|
||||
)
|
||||
|
||||
|
||||
_NAME_TO_TYPE = {"argon2id": Type.ID, "argon2i": Type.I, "argon2d": Type.D}
|
||||
_REQUIRED_KEYS = sorted(("v", "m", "t", "p"))
|
||||
|
||||
|
||||
def extract_parameters(hash):
|
||||
def extract_parameters(hash: str) -> Parameters:
|
||||
"""
|
||||
Extract parameters from an encoded *hash*.
|
||||
|
||||
:param str params: An encoded Argon2 hash string.
|
||||
Args:
|
||||
hash: An encoded Argon2 hash string.
|
||||
|
||||
:rtype: Parameters
|
||||
Returns:
|
||||
The parameters used to create the hash.
|
||||
|
||||
.. versionadded:: 18.2.0
|
||||
"""
|
||||
parts = hash.split("$")
|
||||
|
||||
if len(parts) != 6:
|
||||
raise InvalidHash
|
||||
# Backwards compatibility for Argon v1.2 hashes
|
||||
if len(parts) == 5:
|
||||
parts.insert(2, "v=18")
|
||||
|
||||
if parts[0] != "":
|
||||
raise InvalidHash
|
||||
if len(parts) != 6:
|
||||
raise InvalidHashError
|
||||
|
||||
if parts[0]:
|
||||
raise InvalidHashError
|
||||
|
||||
try:
|
||||
type = _NAME_TO_TYPE[parts[1]]
|
||||
@ -174,14 +138,14 @@ def extract_parameters(hash):
|
||||
kvs = {
|
||||
k: int(v)
|
||||
for k, v in (
|
||||
s.split("=") for s in [parts[2]] + parts[3].split(",")
|
||||
s.split("=") for s in [parts[2], *parts[3].split(",")]
|
||||
)
|
||||
}
|
||||
except Exception:
|
||||
raise InvalidHash
|
||||
except Exception: # noqa: BLE001
|
||||
raise InvalidHashError from None
|
||||
|
||||
if sorted(kvs.keys()) != _REQUIRED_KEYS:
|
||||
raise InvalidHash
|
||||
raise InvalidHashError
|
||||
|
||||
return Parameters(
|
||||
type=type,
|
||||
@ -192,3 +156,18 @@ def extract_parameters(hash):
|
||||
memory_cost=kvs["m"],
|
||||
parallelism=kvs["p"],
|
||||
)
|
||||
|
||||
|
||||
def validate_params_for_platform(params: Parameters) -> None:
|
||||
"""
|
||||
Validate *params* against current platform.
|
||||
|
||||
Args:
|
||||
params: Parameters to be validated
|
||||
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
if _is_wasm() and params.parallelism != 1:
|
||||
msg = "In WebAssembly environments `parallelism` must be 1."
|
||||
raise UnsupportedParametersError(msg)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
class Argon2Error(Exception):
|
||||
@ -37,9 +37,30 @@ class HashingError(Argon2Error):
|
||||
"""
|
||||
|
||||
|
||||
class InvalidHash(ValueError):
|
||||
class InvalidHashError(ValueError):
|
||||
"""
|
||||
Raised if the hash is invalid before passing it to Argon2.
|
||||
|
||||
.. versionadded:: 18.2.0
|
||||
.. versionadded:: 23.1.0
|
||||
As a replacement for :exc:`argon2.exceptions.InvalidHash`.
|
||||
"""
|
||||
|
||||
|
||||
class UnsupportedParametersError(ValueError):
|
||||
"""
|
||||
Raised if the current platform does not support the parameters.
|
||||
|
||||
For example, in WebAssembly parallelism must be set to 1.
|
||||
|
||||
.. versionadded:: 25.1.0
|
||||
"""
|
||||
|
||||
|
||||
InvalidHash = InvalidHashError
|
||||
"""
|
||||
Deprecated alias for :class:`InvalidHashError`.
|
||||
|
||||
.. versionadded:: 18.2.0
|
||||
.. deprecated:: 23.1.0
|
||||
Use :exc:`argon2.exceptions.InvalidHashError` instead.
|
||||
"""
|
||||
|
||||
@ -1,20 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
"""
|
||||
Low-level functions if you want to build your own higher level abstractions.
|
||||
|
||||
.. warning::
|
||||
This is a "Hazardous Materials" module. You should **ONLY** use it if
|
||||
you're 100% absolutely sure that you know what you’re doing because this
|
||||
you're 100% absolutely sure that you know what you're doing because this
|
||||
module is full of land mines, dragons, and dinosaurs with laser guns.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import Enum
|
||||
from typing import Any, Literal
|
||||
|
||||
from six import PY3
|
||||
from _argon2_cffi_bindings import ffi, lib
|
||||
|
||||
from ._ffi import ffi, lib
|
||||
from .exceptions import HashingError, VerificationError, VerifyMismatchError
|
||||
|
||||
|
||||
@ -44,62 +45,47 @@ class Type(Enum):
|
||||
"""
|
||||
|
||||
D = lib.Argon2_d
|
||||
r"""
|
||||
Argon2\ **d** is faster and uses data-depending memory access, which makes
|
||||
it less suitable for hashing secrets and more suitable for cryptocurrencies
|
||||
and applications with no threats from side-channel timing attacks.
|
||||
"""
|
||||
I = lib.Argon2_i
|
||||
r"""
|
||||
Argon2\ **i** uses data-independent memory access. Argon2i is slower as
|
||||
it makes more passes over the memory to protect from tradeoff attacks.
|
||||
"""
|
||||
I = lib.Argon2_i # noqa: E741
|
||||
ID = lib.Argon2_id
|
||||
r"""
|
||||
Argon2\ **id** is a hybrid of Argon2i and Argon2d, using a combination of
|
||||
data-depending and data-independent memory accesses, which gives some of
|
||||
Argon2i's resistance to side-channel cache timing attacks and much of
|
||||
Argon2d's resistance to GPU cracking attacks.
|
||||
|
||||
That makes it the preferred type for password hashing and password-based
|
||||
key derivation.
|
||||
|
||||
.. versionadded:: 16.3.0
|
||||
"""
|
||||
|
||||
|
||||
def hash_secret(
|
||||
secret,
|
||||
salt,
|
||||
time_cost,
|
||||
memory_cost,
|
||||
parallelism,
|
||||
hash_len,
|
||||
type,
|
||||
version=ARGON2_VERSION,
|
||||
):
|
||||
secret: bytes,
|
||||
salt: bytes,
|
||||
time_cost: int,
|
||||
memory_cost: int,
|
||||
parallelism: int,
|
||||
hash_len: int,
|
||||
type: Type,
|
||||
version: int = ARGON2_VERSION,
|
||||
) -> bytes:
|
||||
"""
|
||||
Hash *secret* and return an **encoded** hash.
|
||||
|
||||
An encoded hash can be directly passed into :func:`verify_secret` as it
|
||||
contains all parameters and the salt.
|
||||
|
||||
:param bytes secret: Secret to hash.
|
||||
:param bytes salt: A salt_. Should be random and different for each
|
||||
secret.
|
||||
:param Type type: Which Argon2 variant to use.
|
||||
:param int version: Which Argon2 version to use.
|
||||
Args:
|
||||
secret: Secret to hash.
|
||||
|
||||
For an explanation of the Argon2 parameters see :class:`PasswordHasher`.
|
||||
salt: A salt_. Should be random and different for each secret.
|
||||
|
||||
:rtype: bytes
|
||||
type: Which Argon2 variant to use.
|
||||
|
||||
:raises argon2.exceptions.HashingError: If hashing fails.
|
||||
version: Which Argon2 version to use.
|
||||
|
||||
For an explanation of the Argon2 parameters see
|
||||
:class:`argon2.PasswordHasher`.
|
||||
|
||||
Returns:
|
||||
An encoded Argon2 hash.
|
||||
|
||||
Raises:
|
||||
argon2.exceptions.HashingError: If hashing fails.
|
||||
|
||||
.. versionadded:: 16.0.0
|
||||
|
||||
.. _salt: https://en.wikipedia.org/wiki/Salt_(cryptography)
|
||||
.. _kibibytes: https://en.wikipedia.org/wiki/Binary_prefix#kibi
|
||||
"""
|
||||
size = (
|
||||
lib.argon2_encodedlen(
|
||||
@ -131,19 +117,19 @@ def hash_secret(
|
||||
if rv != lib.ARGON2_OK:
|
||||
raise HashingError(error_to_str(rv))
|
||||
|
||||
return ffi.string(buf)
|
||||
return ffi.string(buf) # type: ignore[no-any-return]
|
||||
|
||||
|
||||
def hash_secret_raw(
|
||||
secret,
|
||||
salt,
|
||||
time_cost,
|
||||
memory_cost,
|
||||
parallelism,
|
||||
hash_len,
|
||||
type,
|
||||
version=ARGON2_VERSION,
|
||||
):
|
||||
secret: bytes,
|
||||
salt: bytes,
|
||||
time_cost: int,
|
||||
memory_cost: int,
|
||||
parallelism: int,
|
||||
hash_len: int,
|
||||
type: Type,
|
||||
version: int = ARGON2_VERSION,
|
||||
) -> bytes:
|
||||
"""
|
||||
Hash *password* and return a **raw** hash.
|
||||
|
||||
@ -174,24 +160,30 @@ def hash_secret_raw(
|
||||
return bytes(ffi.buffer(buf, hash_len))
|
||||
|
||||
|
||||
def verify_secret(hash, secret, type):
|
||||
def verify_secret(hash: bytes, secret: bytes, type: Type) -> Literal[True]:
|
||||
"""
|
||||
Verify whether *secret* is correct for *hash* of *type*.
|
||||
|
||||
:param bytes hash: An encoded Argon2 hash as returned by
|
||||
:func:`hash_secret`.
|
||||
:param bytes secret: The secret to verify whether it matches the one
|
||||
in *hash*.
|
||||
:param Type type: Type for *hash*.
|
||||
Args:
|
||||
hash:
|
||||
An encoded Argon2 hash as returned by :func:`hash_secret`.
|
||||
|
||||
:raises argon2.exceptions.VerifyMismatchError: If verification fails
|
||||
because *hash* is not valid for *secret* of *type*.
|
||||
:raises argon2.exceptions.VerificationError: If verification fails for
|
||||
other reasons.
|
||||
secret:
|
||||
The secret to verify whether it matches the one in *hash*.
|
||||
|
||||
:return: ``True`` on success, raise
|
||||
:exc:`~argon2.exceptions.VerificationError` otherwise.
|
||||
:rtype: bool
|
||||
type: Type for *hash*.
|
||||
|
||||
Raises:
|
||||
argon2.exceptions.VerifyMismatchError:
|
||||
If verification fails because *hash* is not valid for *secret* of
|
||||
*type*.
|
||||
|
||||
argon2.exceptions.VerificationError:
|
||||
If verification fails for other reasons.
|
||||
|
||||
Returns:
|
||||
``True`` on success, raise :exc:`~argon2.exceptions.VerificationError`
|
||||
otherwise.
|
||||
|
||||
.. versionadded:: 16.0.0
|
||||
.. versionchanged:: 16.1.0
|
||||
@ -204,53 +196,58 @@ def verify_secret(hash, secret, type):
|
||||
len(secret),
|
||||
type.value,
|
||||
)
|
||||
|
||||
if rv == lib.ARGON2_OK:
|
||||
return True
|
||||
elif rv == lib.ARGON2_VERIFY_MISMATCH:
|
||||
|
||||
if rv == lib.ARGON2_VERIFY_MISMATCH:
|
||||
raise VerifyMismatchError(error_to_str(rv))
|
||||
else:
|
||||
raise VerificationError(error_to_str(rv))
|
||||
|
||||
raise VerificationError(error_to_str(rv))
|
||||
|
||||
|
||||
def core(context, type):
|
||||
def core(context: Any, type: int) -> int:
|
||||
"""
|
||||
Direct binding to the ``argon2_ctx`` function.
|
||||
|
||||
.. warning::
|
||||
This is a strictly advanced function working on raw C data structures.
|
||||
Both Argon2's and ``argon2_cffi``'s higher-level bindings do a lot of
|
||||
Both Argon2's and *argon2-cffi*'s higher-level bindings do a lot of
|
||||
sanity checks and housekeeping work that *you* are now responsible for
|
||||
(e.g. clearing buffers). The structure of the *context* object can,
|
||||
has, and will change with *any* release!
|
||||
|
||||
Use at your own peril; ``argon2_cffi`` does *not* use this binding
|
||||
Use at your own peril; *argon2-cffi* does *not* use this binding
|
||||
itself.
|
||||
|
||||
:param context: A CFFI Argon2 context object (i.e. an ``struct
|
||||
Argon2_Context``/``argon2_context``).
|
||||
:param int type: Which Argon2 variant to use. You can use the ``value``
|
||||
field of :class:`Type`'s fields.
|
||||
Args:
|
||||
context:
|
||||
A CFFI Argon2 context object (i.e. an ``struct Argon2_Context`` /
|
||||
``argon2_context``).
|
||||
|
||||
:rtype: int
|
||||
:return: An Argon2 error code. Can be transformed into a string using
|
||||
type:
|
||||
Which Argon2 variant to use. You can use the ``value`` field of
|
||||
:class:`Type`'s fields.
|
||||
|
||||
Returns:
|
||||
An Argon2 error code. Can be transformed into a string using
|
||||
:func:`error_to_str`.
|
||||
|
||||
.. versionadded:: 16.0.0
|
||||
"""
|
||||
return lib.argon2_ctx(context, type)
|
||||
return lib.argon2_ctx(context, type) # type: ignore[no-any-return]
|
||||
|
||||
|
||||
def error_to_str(error):
|
||||
def error_to_str(error: int) -> str:
|
||||
"""
|
||||
Convert an Argon2 error code into a native string.
|
||||
|
||||
:param int error: An Argon2 error code as returned by :func:`core`.
|
||||
Args:
|
||||
error: An Argon2 error code as returned by :func:`core`.
|
||||
|
||||
:rtype: str
|
||||
Returns:
|
||||
A human-readable string describing the error.
|
||||
|
||||
.. versionadded:: 16.0.0
|
||||
"""
|
||||
msg = ffi.string(lib.argon2_error_message(error))
|
||||
if PY3:
|
||||
msg = msg.decode("ascii")
|
||||
return msg
|
||||
return ffi.string(lib.argon2_error_message(error)).decode("ascii") # type: ignore[no-any-return]
|
||||
|
||||
79
src/argon2/profiles.py
Normal file
79
src/argon2/profiles.py
Normal file
@ -0,0 +1,79 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
"""
|
||||
This module offers access to standardized parameters that you can load using
|
||||
:meth:`argon2.PasswordHasher.from_parameters()`. See the `source code
|
||||
<https://github.com/hynek/argon2-cffi/blob/main/src/argon2/profiles.py>`_ for
|
||||
concrete values and :doc:`parameters` for more information.
|
||||
|
||||
.. versionadded:: 21.2.0
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
|
||||
from ._utils import Parameters, _is_wasm
|
||||
from .low_level import Type
|
||||
|
||||
|
||||
def get_default_parameters() -> Parameters:
|
||||
"""
|
||||
Create default parameters for current platform.
|
||||
|
||||
Returns:
|
||||
Default, compatible, parameters for current platform.
|
||||
|
||||
.. versionadded:: 25.1.0
|
||||
"""
|
||||
params = RFC_9106_LOW_MEMORY
|
||||
|
||||
if _is_wasm():
|
||||
params = dataclasses.replace(params, parallelism=1)
|
||||
|
||||
return params
|
||||
|
||||
|
||||
# FIRST RECOMMENDED option per RFC 9106.
|
||||
RFC_9106_HIGH_MEMORY = Parameters(
|
||||
type=Type.ID,
|
||||
version=19,
|
||||
salt_len=16,
|
||||
hash_len=32,
|
||||
time_cost=1,
|
||||
memory_cost=2097152, # 2 GiB
|
||||
parallelism=4,
|
||||
)
|
||||
|
||||
# SECOND RECOMMENDED option per RFC 9106.
|
||||
RFC_9106_LOW_MEMORY = Parameters(
|
||||
type=Type.ID,
|
||||
version=19,
|
||||
salt_len=16,
|
||||
hash_len=32,
|
||||
time_cost=3,
|
||||
memory_cost=65536, # 64 MiB
|
||||
parallelism=4,
|
||||
)
|
||||
|
||||
# The pre-RFC defaults in argon2-cffi 18.2.0 - 21.1.0.
|
||||
PRE_21_2 = Parameters(
|
||||
type=Type.ID,
|
||||
version=19,
|
||||
salt_len=16,
|
||||
hash_len=16,
|
||||
time_cost=2,
|
||||
memory_cost=102400, # 100 MiB
|
||||
parallelism=8,
|
||||
)
|
||||
|
||||
# Only for testing!
|
||||
CHEAPEST = Parameters(
|
||||
type=Type.ID,
|
||||
version=19,
|
||||
salt_len=8,
|
||||
hash_len=4,
|
||||
time_cost=1,
|
||||
memory_cost=8,
|
||||
parallelism=1,
|
||||
)
|
||||
0
src/argon2/py.typed
Normal file
0
src/argon2/py.typed
Normal file
@ -1,6 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import pytest
|
||||
|
||||
@ -14,7 +12,6 @@ from argon2 import (
|
||||
hash_password_raw,
|
||||
verify_password,
|
||||
)
|
||||
from argon2._utils import _encoded_str_len
|
||||
from argon2.exceptions import HashingError, VerificationError
|
||||
|
||||
from .test_low_level import (
|
||||
@ -30,33 +27,46 @@ from .test_low_level import (
|
||||
)
|
||||
|
||||
|
||||
class TestHash(object):
|
||||
class TestHash:
|
||||
def test_hash_defaults(self):
|
||||
"""
|
||||
Calling without arguments works.
|
||||
"""
|
||||
hash_password(b"secret")
|
||||
with pytest.deprecated_call(
|
||||
match="argon2.hash_password is deprecated"
|
||||
) as dc:
|
||||
hash_password(b"secret")
|
||||
|
||||
assert dc.pop().filename.endswith("test_legacy.py")
|
||||
|
||||
def test_raw_defaults(self):
|
||||
"""
|
||||
Calling without arguments works.
|
||||
"""
|
||||
hash_password_raw(b"secret")
|
||||
with pytest.deprecated_call(
|
||||
match="argon2.hash_password_raw is deprecated"
|
||||
) as dc:
|
||||
hash_password_raw(b"secret")
|
||||
|
||||
assert dc.pop().filename.endswith("test_legacy.py")
|
||||
|
||||
@i_and_d_encoded
|
||||
def test_hash_password(self, type, hash):
|
||||
"""
|
||||
Creates the same encoded hash as the Argon2 CLI client.
|
||||
"""
|
||||
rv = hash_password(
|
||||
TEST_PASSWORD,
|
||||
TEST_SALT,
|
||||
TEST_TIME,
|
||||
TEST_MEMORY,
|
||||
TEST_PARALLELISM,
|
||||
TEST_HASH_LEN,
|
||||
type,
|
||||
)
|
||||
with pytest.deprecated_call(
|
||||
match="argon2.hash_password is deprecated"
|
||||
):
|
||||
rv = hash_password(
|
||||
TEST_PASSWORD,
|
||||
TEST_SALT,
|
||||
TEST_TIME,
|
||||
TEST_MEMORY,
|
||||
TEST_PARALLELISM,
|
||||
TEST_HASH_LEN,
|
||||
type,
|
||||
)
|
||||
|
||||
assert hash == rv
|
||||
assert isinstance(rv, bytes)
|
||||
@ -66,15 +76,18 @@ class TestHash(object):
|
||||
"""
|
||||
Creates the same raw hash as the Argon2 CLI client.
|
||||
"""
|
||||
rv = hash_password_raw(
|
||||
TEST_PASSWORD,
|
||||
TEST_SALT,
|
||||
TEST_TIME,
|
||||
TEST_MEMORY,
|
||||
TEST_PARALLELISM,
|
||||
TEST_HASH_LEN,
|
||||
type,
|
||||
)
|
||||
with pytest.deprecated_call(
|
||||
match="argon2.hash_password_raw is deprecated"
|
||||
):
|
||||
rv = hash_password_raw(
|
||||
TEST_PASSWORD,
|
||||
TEST_SALT,
|
||||
TEST_TIME,
|
||||
TEST_MEMORY,
|
||||
TEST_PARALLELISM,
|
||||
TEST_HASH_LEN,
|
||||
type,
|
||||
)
|
||||
|
||||
assert hash == rv
|
||||
assert isinstance(rv, bytes)
|
||||
@ -83,34 +96,49 @@ class TestHash(object):
|
||||
"""
|
||||
Hashing passwords with NUL bytes works as expected.
|
||||
"""
|
||||
rv = hash_password_raw(b"abc\x00", TEST_SALT)
|
||||
with pytest.deprecated_call(
|
||||
match="argon2.hash_password_raw is deprecated"
|
||||
):
|
||||
rv = hash_password_raw(b"abc\x00", TEST_SALT)
|
||||
|
||||
assert rv != hash_password_raw(b"abc", TEST_SALT)
|
||||
with pytest.deprecated_call(
|
||||
match="argon2.hash_password_raw is deprecated"
|
||||
):
|
||||
assert rv != hash_password_raw(b"abc", TEST_SALT)
|
||||
|
||||
def test_random_salt(self):
|
||||
"""
|
||||
Omitting a salt, creates a random one.
|
||||
"""
|
||||
rv = hash_password(b"secret")
|
||||
with pytest.deprecated_call(
|
||||
match="argon2.hash_password is deprecated"
|
||||
):
|
||||
rv = hash_password(b"secret")
|
||||
salt = rv.split(b",")[-1].split(b"$")[1]
|
||||
|
||||
assert (
|
||||
# -1 for not NUL byte
|
||||
int(_encoded_str_len(DEFAULT_RANDOM_SALT_LENGTH)) - 1
|
||||
== len(salt)
|
||||
int((DEFAULT_RANDOM_SALT_LENGTH << 2) / 3 + 2) - 1 == len(salt)
|
||||
)
|
||||
|
||||
def test_hash_wrong_arg_type(self):
|
||||
"""
|
||||
Passing an argument of wrong type raises TypeError.
|
||||
"""
|
||||
with pytest.raises(TypeError):
|
||||
hash_password(u"oh no, unicode!")
|
||||
with (
|
||||
pytest.deprecated_call(match="argon2.hash_password is deprecated"),
|
||||
pytest.raises(TypeError),
|
||||
):
|
||||
hash_password("oh no, unicode!")
|
||||
|
||||
def test_illegal_argon2_parameter(self):
|
||||
"""
|
||||
Raises HashingError if hashing fails.
|
||||
"""
|
||||
with pytest.raises(HashingError):
|
||||
with (
|
||||
pytest.deprecated_call(match="argon2.hash_password is deprecated"),
|
||||
pytest.raises(HashingError),
|
||||
):
|
||||
hash_password(TEST_PASSWORD, memory_cost=1)
|
||||
|
||||
@given(st.binary(max_size=128))
|
||||
@ -118,34 +146,52 @@ class TestHash(object):
|
||||
"""
|
||||
Hash various passwords as cheaply as possible.
|
||||
"""
|
||||
hash_password(
|
||||
password,
|
||||
salt=b"12345678",
|
||||
time_cost=1,
|
||||
memory_cost=8,
|
||||
parallelism=1,
|
||||
hash_len=8,
|
||||
)
|
||||
with pytest.deprecated_call(
|
||||
match="argon2.hash_password is deprecated"
|
||||
):
|
||||
hash_password(
|
||||
password,
|
||||
salt=b"12345678",
|
||||
time_cost=1,
|
||||
memory_cost=8,
|
||||
parallelism=1,
|
||||
hash_len=8,
|
||||
)
|
||||
|
||||
|
||||
class TestVerify(object):
|
||||
class TestVerify:
|
||||
@i_and_d_encoded
|
||||
def test_success(self, type, hash):
|
||||
"""
|
||||
Given a valid hash and password and correct type, we succeed.
|
||||
"""
|
||||
assert True is verify_password(hash, TEST_PASSWORD, type)
|
||||
with pytest.deprecated_call(
|
||||
match="argon2.verify_password is deprecated"
|
||||
) as dc:
|
||||
assert True is verify_password(hash, TEST_PASSWORD, type)
|
||||
|
||||
assert dc.pop().filename.endswith("test_legacy.py")
|
||||
|
||||
def test_fail_wrong_argon2_type(self):
|
||||
"""
|
||||
Given a valid hash and password and wrong type, we fail.
|
||||
"""
|
||||
with pytest.raises(VerificationError):
|
||||
with (
|
||||
pytest.deprecated_call(
|
||||
match="argon2.verify_password is deprecated"
|
||||
),
|
||||
pytest.raises(VerificationError),
|
||||
):
|
||||
verify_password(TEST_HASH_I, TEST_PASSWORD, Type.D)
|
||||
|
||||
def test_wrong_arg_type(self):
|
||||
"""
|
||||
Passing an argument of wrong type raises TypeError.
|
||||
"""
|
||||
with pytest.raises(TypeError):
|
||||
with (
|
||||
pytest.deprecated_call(
|
||||
match="argon2.verify_password is deprecated"
|
||||
),
|
||||
pytest.raises(TypeError),
|
||||
):
|
||||
verify_password(TEST_HASH_I, TEST_PASSWORD.decode("ascii"))
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
from __future__ import absolute_import, division, print_function
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import binascii
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
from hypothesis import assume, given
|
||||
from hypothesis import assume, given, settings
|
||||
from hypothesis import strategies as st
|
||||
|
||||
from argon2.exceptions import (
|
||||
@ -95,11 +95,11 @@ TEST_PARALLELISM = 4
|
||||
TEST_HASH_LEN = 32
|
||||
|
||||
i_and_d_encoded = pytest.mark.parametrize(
|
||||
"type,hash",
|
||||
("type", "hash"),
|
||||
[(Type.I, TEST_HASH_I), (Type.D, TEST_HASH_D), (Type.ID, TEST_HASH_ID)],
|
||||
)
|
||||
i_and_d_raw = pytest.mark.parametrize(
|
||||
"type,hash",
|
||||
("type", "hash"),
|
||||
[(Type.I, TEST_RAW_I), (Type.D, TEST_RAW_D), (Type.ID, TEST_RAW_ID)],
|
||||
)
|
||||
|
||||
@ -108,7 +108,7 @@ both_hash_funcs = pytest.mark.parametrize(
|
||||
)
|
||||
|
||||
|
||||
class TestHash(object):
|
||||
class TestHash:
|
||||
@i_and_d_encoded
|
||||
def test_hash_secret(self, type, hash):
|
||||
"""
|
||||
@ -167,7 +167,7 @@ class TestHash(object):
|
||||
Passing an argument of wrong type raises TypeError.
|
||||
"""
|
||||
with pytest.raises(TypeError):
|
||||
func(u"oh no, unicode!")
|
||||
func("oh no, unicode!")
|
||||
|
||||
@both_hash_funcs
|
||||
def test_illegal_argon2_parameter(self, func):
|
||||
@ -185,13 +185,15 @@ class TestHash(object):
|
||||
Type.I,
|
||||
)
|
||||
|
||||
@both_hash_funcs
|
||||
@given(st.binary(max_size=128))
|
||||
@given(
|
||||
st.sampled_from((hash_secret, hash_secret_raw)),
|
||||
st.binary(max_size=128),
|
||||
)
|
||||
def test_hash_fast(self, func, secret):
|
||||
"""
|
||||
Hash various secrets as cheaply as possible.
|
||||
"""
|
||||
hash_secret(
|
||||
func(
|
||||
secret,
|
||||
salt=b"12345678",
|
||||
time_cost=1,
|
||||
@ -202,7 +204,7 @@ class TestHash(object):
|
||||
)
|
||||
|
||||
|
||||
class TestVerify(object):
|
||||
class TestVerify:
|
||||
@i_and_d_encoded
|
||||
def test_success(self, type, hash):
|
||||
"""
|
||||
@ -253,6 +255,7 @@ class TestVerify(object):
|
||||
hash_len=st.integers(lib.ARGON2_MIN_OUTLEN, 513),
|
||||
salt_len=st.integers(lib.ARGON2_MIN_SALT_LENGTH, 513),
|
||||
)
|
||||
@settings(deadline=None)
|
||||
def test_argument_ranges(
|
||||
password, time_cost, parallelism, memory_cost, hash_len, salt_len
|
||||
):
|
||||
@ -293,26 +296,26 @@ def test_core():
|
||||
|
||||
ctx = ffi.new(
|
||||
"argon2_context *",
|
||||
dict(
|
||||
out=cout,
|
||||
outlen=hash_len,
|
||||
version=ARGON2_VERSION,
|
||||
pwd=cpwd,
|
||||
pwdlen=len(pwd),
|
||||
salt=csalt,
|
||||
saltlen=len(salt),
|
||||
secret=ffi.NULL,
|
||||
secretlen=0,
|
||||
ad=ffi.NULL,
|
||||
adlen=0,
|
||||
t_cost=1,
|
||||
m_cost=8,
|
||||
lanes=1,
|
||||
threads=1,
|
||||
allocate_cbk=ffi.NULL,
|
||||
free_cbk=ffi.NULL,
|
||||
flags=lib.ARGON2_DEFAULT_FLAGS,
|
||||
),
|
||||
{
|
||||
"out": cout,
|
||||
"outlen": hash_len,
|
||||
"version": ARGON2_VERSION,
|
||||
"pwd": cpwd,
|
||||
"pwdlen": len(pwd),
|
||||
"salt": csalt,
|
||||
"saltlen": len(salt),
|
||||
"secret": ffi.NULL,
|
||||
"secretlen": 0,
|
||||
"ad": ffi.NULL,
|
||||
"adlen": 0,
|
||||
"t_cost": 1,
|
||||
"m_cost": 8,
|
||||
"lanes": 1,
|
||||
"threads": 1,
|
||||
"allocate_cbk": ffi.NULL,
|
||||
"free_cbk": ffi.NULL,
|
||||
"flags": lib.ARGON2_DEFAULT_FLAGS,
|
||||
},
|
||||
)
|
||||
|
||||
rv = core(ctx, Type.D.value)
|
||||
|
||||
50
tests/test_packaging.py
Normal file
50
tests/test_packaging.py
Normal file
@ -0,0 +1,50 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
|
||||
from importlib import metadata
|
||||
|
||||
import pytest
|
||||
|
||||
import argon2
|
||||
|
||||
|
||||
class TestLegacyMetadataHack:
|
||||
def test_version(self):
|
||||
"""
|
||||
argon2.__version__ returns the correct version.
|
||||
"""
|
||||
with pytest.deprecated_call():
|
||||
assert metadata.version("argon2-cffi") == argon2.__version__
|
||||
|
||||
def test_description(self):
|
||||
"""
|
||||
argon2.__description__ returns the correct description.
|
||||
"""
|
||||
with pytest.deprecated_call():
|
||||
assert "Argon2 for Python" == argon2.__description__
|
||||
|
||||
def test_uri(self):
|
||||
"""
|
||||
argon2.__uri__ returns the correct project URL.
|
||||
"""
|
||||
with pytest.deprecated_call():
|
||||
assert "https://argon2-cffi.readthedocs.io/" == argon2.__uri__
|
||||
|
||||
with pytest.deprecated_call():
|
||||
assert "https://argon2-cffi.readthedocs.io/" == argon2.__url__
|
||||
|
||||
def test_email(self):
|
||||
"""
|
||||
argon2.__email__ returns Hynek's email address.
|
||||
"""
|
||||
with pytest.deprecated_call():
|
||||
assert "hs@ox.cx" == argon2.__email__
|
||||
|
||||
def test_does_not_exist(self):
|
||||
"""
|
||||
Asking for unsupported dunders raises an AttributeError.
|
||||
"""
|
||||
with pytest.raises(
|
||||
AttributeError, match="module argon2 has no attribute __yolo__"
|
||||
):
|
||||
argon2.__yolo__ # noqa: B018
|
||||
@ -1,32 +1,41 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
import secrets
|
||||
import sys
|
||||
import threading
|
||||
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
import six
|
||||
|
||||
from argon2 import PasswordHasher, Type, extract_parameters
|
||||
from argon2 import PasswordHasher, Type, extract_parameters, profiles
|
||||
from argon2._password_hasher import _ensure_bytes
|
||||
from argon2.exceptions import InvalidHash
|
||||
from argon2._utils import Parameters
|
||||
from argon2.exceptions import (
|
||||
InvalidHash,
|
||||
InvalidHashError,
|
||||
UnsupportedParametersError,
|
||||
)
|
||||
|
||||
|
||||
class TestEnsureBytes(object):
|
||||
class TestEnsureBytes:
|
||||
def test_is_bytes(self):
|
||||
"""
|
||||
Bytes are just returned.
|
||||
"""
|
||||
s = u"föö".encode("utf-8")
|
||||
s = "föö".encode()
|
||||
|
||||
rv = _ensure_bytes(s, "doesntmatter")
|
||||
|
||||
assert isinstance(rv, bytes)
|
||||
assert s == rv
|
||||
|
||||
def test_is_unicode(self):
|
||||
def test_is_str(self):
|
||||
"""
|
||||
Unicode is encoded using the specified encoding.
|
||||
Unicode str is encoded using the specified encoding.
|
||||
"""
|
||||
s = u"föö"
|
||||
s = "föö"
|
||||
|
||||
rv = _ensure_bytes(s, "latin1")
|
||||
|
||||
@ -34,41 +43,53 @@ class TestEnsureBytes(object):
|
||||
assert s.encode("latin1") == rv
|
||||
|
||||
|
||||
bytes_and_unicode_password = pytest.mark.parametrize(
|
||||
"password", [u"pässword".encode("latin1"), u"pässword"]
|
||||
bytes_and_str_password = pytest.mark.parametrize(
|
||||
"password", ["pässword".encode("latin1"), "pässword"]
|
||||
)
|
||||
|
||||
|
||||
class TestPasswordHasher(object):
|
||||
@bytes_and_unicode_password
|
||||
class TestPasswordHasher:
|
||||
@bytes_and_str_password
|
||||
def test_hash(self, password):
|
||||
"""
|
||||
Hashing works with unicode and bytes. Uses correct parameters.
|
||||
Hashing works with str and bytes. Uses correct parameters.
|
||||
"""
|
||||
ph = PasswordHasher(1, 8, 1, 16, 16, "latin1")
|
||||
|
||||
h = ph.hash(password)
|
||||
|
||||
prefix = u"$argon2id$v=19$m=8,t=1,p=1$"
|
||||
prefix = "$argon2id$v=19$m=8,t=1,p=1$"
|
||||
|
||||
assert isinstance(h, six.text_type)
|
||||
assert isinstance(h, str)
|
||||
assert h[: len(prefix)] == prefix
|
||||
|
||||
@bytes_and_unicode_password
|
||||
def test_custom_salt(self):
|
||||
"""
|
||||
A custom salt can be specified.
|
||||
"""
|
||||
ph = PasswordHasher.from_parameters(profiles.CHEAPEST)
|
||||
|
||||
h = ph.hash(b"password", salt=b"1234567890123456")
|
||||
|
||||
assert h == (
|
||||
"$argon2id$v=19$m=8,t=1,p=1$MTIzNDU2Nzg5MDEyMzQ1Ng$maTa5w"
|
||||
)
|
||||
|
||||
@bytes_and_str_password
|
||||
def test_verify_agility(self, password):
|
||||
"""
|
||||
Verification works with unicode and bytes and variant is correctly
|
||||
Verification works with str and bytes and variant is correctly
|
||||
detected.
|
||||
"""
|
||||
ph = PasswordHasher(1, 8, 1, 16, 16, "latin1")
|
||||
hash = ( # handrolled artisanal test vector
|
||||
u"$argon2i$m=8,t=1,p=1$"
|
||||
u"bL/lLsegFKTuR+5vVyA8tA$VKz5CHavCtFOL1N5TIXWSA"
|
||||
"$argon2i$m=8,t=1,p=1$"
|
||||
"bL/lLsegFKTuR+5vVyA8tA$VKz5CHavCtFOL1N5TIXWSA"
|
||||
)
|
||||
|
||||
assert ph.verify(hash, password)
|
||||
|
||||
@bytes_and_unicode_password
|
||||
@bytes_and_str_password
|
||||
def test_hash_verify(self, password):
|
||||
"""
|
||||
Hashes are valid and can be verified.
|
||||
@ -86,29 +107,46 @@ class TestPasswordHasher(object):
|
||||
|
||||
assert "'time_cost' must be a int (got str)." == e.value.args[0]
|
||||
|
||||
def test_verify_invalid_hash_error(self):
|
||||
"""
|
||||
If the hash can't be parsed, InvalidHashError is raised.
|
||||
"""
|
||||
with pytest.raises(InvalidHashError):
|
||||
PasswordHasher().verify("tiger", "does not matter")
|
||||
|
||||
def test_verify_invalid_hash(self):
|
||||
"""
|
||||
If the hash can't be parsed, InvalidHash is raised.
|
||||
InvalidHashError and the deprecrated InvalidHash are the same.
|
||||
"""
|
||||
with pytest.raises(InvalidHash):
|
||||
PasswordHasher().verify("tiger", "does not matter")
|
||||
|
||||
def test_check_needs_rehash_no(self):
|
||||
@pytest.mark.parametrize("use_bytes", [True, False])
|
||||
def test_check_needs_rehash_no(self, use_bytes):
|
||||
"""
|
||||
Return False if the hash has the correct parameters.
|
||||
"""
|
||||
ph = PasswordHasher(1, 8, 1, 16, 16)
|
||||
|
||||
assert not ph.check_needs_rehash(ph.hash("foo"))
|
||||
hash = ph.hash("foo")
|
||||
if use_bytes:
|
||||
hash = hash.encode()
|
||||
|
||||
def test_check_needs_rehash_yes(self):
|
||||
assert not ph.check_needs_rehash(hash)
|
||||
|
||||
@pytest.mark.parametrize("use_bytes", [True, False])
|
||||
def test_check_needs_rehash_yes(self, use_bytes):
|
||||
"""
|
||||
Return True if any of the parameters changes.
|
||||
"""
|
||||
ph = PasswordHasher(1, 8, 1, 16, 16)
|
||||
ph_old = PasswordHasher(1, 8, 1, 8, 8)
|
||||
|
||||
assert ph.check_needs_rehash(ph_old.hash("foo"))
|
||||
hash = ph_old.hash("foo")
|
||||
if use_bytes:
|
||||
hash = hash.encode()
|
||||
|
||||
assert ph.check_needs_rehash(hash)
|
||||
|
||||
def test_type_is_configurable(self):
|
||||
"""
|
||||
@ -125,3 +163,74 @@ class TestPasswordHasher(object):
|
||||
assert Type.I is ph.type is ph._parameters.type
|
||||
assert Type.I is extract_parameters(ph.hash("foo")).type
|
||||
assert ph.check_needs_rehash(default_hash)
|
||||
|
||||
@mock.patch("sys.platform", "emscripten")
|
||||
@pytest.mark.parametrize("machine", ["wasm32", "wasm64"])
|
||||
def test_params_on_wasm(self, machine):
|
||||
"""
|
||||
Parameter validation catches invalid parameters on WebAssembly.
|
||||
"""
|
||||
with mock.patch("platform.machine", return_value=machine):
|
||||
with pytest.raises(
|
||||
UnsupportedParametersError,
|
||||
match="In WebAssembly environments `parallelism` must be 1",
|
||||
):
|
||||
PasswordHasher(parallelism=2)
|
||||
|
||||
# last param is parallelism so it should fail
|
||||
params = Parameters(Type.I, 2, 8, 8, 3, 256, 8)
|
||||
with pytest.raises(
|
||||
UnsupportedParametersError,
|
||||
match="In WebAssembly environments `parallelism` must be 1",
|
||||
):
|
||||
ph = PasswordHasher.from_parameters(params)
|
||||
|
||||
# explicitly correct parameters
|
||||
ph = PasswordHasher(parallelism=1)
|
||||
|
||||
hash = ph.hash("hello")
|
||||
|
||||
assert ph.verify(hash, "hello") is True
|
||||
|
||||
# explicit, but still default parameters
|
||||
default_params = profiles.get_default_parameters()
|
||||
ph = PasswordHasher.from_parameters(default_params)
|
||||
|
||||
hash = ph.hash("hello")
|
||||
|
||||
assert ph.verify(hash, "hello") is True
|
||||
|
||||
|
||||
def test_multithreaded_hashing():
|
||||
"""
|
||||
Hash passwords in a thread pool and check for thread safety
|
||||
"""
|
||||
hasher = PasswordHasher(parallelism=2)
|
||||
|
||||
num_passwords = 100
|
||||
|
||||
passwords = [secrets.token_urlsafe(15) for _ in range(num_passwords)]
|
||||
|
||||
def closure(b, passwords):
|
||||
b.wait()
|
||||
for password in passwords:
|
||||
assert hasher.verify(hasher.hash(password), password)
|
||||
|
||||
max_workers = 4
|
||||
|
||||
chunks = [passwords[i::max_workers] for i in range(max_workers)]
|
||||
orig_interval = sys.getswitchinterval()
|
||||
|
||||
with ThreadPoolExecutor(max_workers=max_workers) as tpe:
|
||||
barrier = threading.Barrier(max_workers)
|
||||
futures = []
|
||||
try:
|
||||
sys.setswitchinterval(0.00001)
|
||||
for chunk in chunks:
|
||||
futures.append(tpe.submit(closure, barrier, chunk)) # noqa: PERF401
|
||||
finally:
|
||||
sys.setswitchinterval(orig_interval)
|
||||
if len(futures) < max_workers:
|
||||
barrier.abort()
|
||||
for f in futures:
|
||||
f.result()
|
||||
|
||||
@ -1,21 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
from base64 import b64encode
|
||||
from dataclasses import replace
|
||||
|
||||
import pytest
|
||||
|
||||
from hypothesis import given
|
||||
from hypothesis import strategies as st
|
||||
from six import PY3
|
||||
|
||||
from argon2 import Parameters, Type, extract_parameters
|
||||
from argon2._utils import NoneType, _check_types, _decoded_str_len
|
||||
from argon2.exceptions import InvalidHash
|
||||
from argon2.exceptions import InvalidHashError
|
||||
|
||||
|
||||
class TestCheckTypes(object):
|
||||
class TestCheckTypes:
|
||||
def test_success(self):
|
||||
"""
|
||||
Returns None if all types are okay.
|
||||
@ -31,16 +29,13 @@ class TestCheckTypes(object):
|
||||
Returns summary of failures.
|
||||
"""
|
||||
rv = _check_types(
|
||||
bytes=(u"not bytes", bytes), str_or_None=(42, (str, NoneType))
|
||||
bytes=("not bytes", bytes), str_or_None=(42, (str, NoneType))
|
||||
)
|
||||
|
||||
assert "." == rv[-1] # proper grammar FTW
|
||||
assert "'str_or_None' must be a str, or NoneType (got int)" in rv
|
||||
|
||||
if PY3:
|
||||
assert "'bytes' must be a bytes (got str)" in rv
|
||||
else:
|
||||
assert "'bytes' must be a str (got unicode)" in rv
|
||||
assert "'bytes' must be a bytes (got str)" in rv
|
||||
|
||||
|
||||
@given(st.binary())
|
||||
@ -65,8 +60,22 @@ VALID_PARAMETERS = Parameters(
|
||||
parallelism=4,
|
||||
)
|
||||
|
||||
VALID_HASH_V18 = (
|
||||
"$argon2i$m=8,t=1,p=1$c29tZXNhbHQ$gwQOXSNhxiOxPOA0+PY10P9QFO"
|
||||
"4NAYysnqRt1GSQLE55m+2GYDt9FEjPMHhP2Cuf0nOEXXMocVrsJAtNSsKyfg"
|
||||
)
|
||||
VALID_PARAMETERS_V18 = Parameters(
|
||||
type=Type.I,
|
||||
salt_len=8,
|
||||
hash_len=64,
|
||||
version=18,
|
||||
memory_cost=8,
|
||||
time_cost=1,
|
||||
parallelism=1,
|
||||
)
|
||||
|
||||
class TestExtractParameters(object):
|
||||
|
||||
class TestExtractParameters:
|
||||
def test_valid_hash(self):
|
||||
"""
|
||||
A valid hash is parsed.
|
||||
@ -75,6 +84,15 @@ class TestExtractParameters(object):
|
||||
|
||||
assert VALID_PARAMETERS == parsed
|
||||
|
||||
def test_valid_hash_v18(self):
|
||||
"""
|
||||
A valid Argon v1.2 hash is parsed.
|
||||
"""
|
||||
|
||||
parsed = extract_parameters(VALID_HASH_V18)
|
||||
|
||||
assert VALID_PARAMETERS_V18 == parsed
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"hash",
|
||||
[
|
||||
@ -88,41 +106,40 @@ class TestExtractParameters(object):
|
||||
"""
|
||||
Invalid hashes of various types raise an InvalidHash error.
|
||||
"""
|
||||
with pytest.raises(InvalidHash):
|
||||
with pytest.raises(InvalidHashError):
|
||||
extract_parameters(hash)
|
||||
|
||||
|
||||
class TestParameters(object):
|
||||
class TestParameters:
|
||||
def test_eq(self):
|
||||
"""
|
||||
Parameters are iff every attribute is equal.
|
||||
Parameters are equal iff every attribute is equal.
|
||||
"""
|
||||
assert VALID_PARAMETERS == VALID_PARAMETERS
|
||||
assert not VALID_PARAMETERS != VALID_PARAMETERS
|
||||
assert VALID_PARAMETERS == VALID_PARAMETERS # noqa: PLR0124
|
||||
assert VALID_PARAMETERS != replace(VALID_PARAMETERS, salt_len=9)
|
||||
|
||||
def test_eq_wrong_type(self):
|
||||
"""
|
||||
Parameters are only compared if they have the same type.
|
||||
"""
|
||||
assert VALID_PARAMETERS != "foo"
|
||||
assert not VALID_PARAMETERS == object()
|
||||
assert VALID_PARAMETERS != object()
|
||||
|
||||
def test_repr(self):
|
||||
"""
|
||||
__repr__ returns s ensible string.
|
||||
"""
|
||||
assert (
|
||||
"<Parameters(type=<Type.ID: 2>, version=19, hash_len=32, "
|
||||
"salt_len=8, time_cost=2, memory_cost=65536, parallelelism=4)>"
|
||||
== repr(
|
||||
Parameters(
|
||||
type=Type.ID,
|
||||
salt_len=8,
|
||||
hash_len=32,
|
||||
version=19,
|
||||
memory_cost=65536,
|
||||
time_cost=2,
|
||||
parallelism=4,
|
||||
)
|
||||
assert repr(
|
||||
Parameters(
|
||||
type=Type.ID,
|
||||
salt_len=8,
|
||||
hash_len=32,
|
||||
version=19,
|
||||
memory_cost=65536,
|
||||
time_cost=2,
|
||||
parallelism=4,
|
||||
)
|
||||
) == (
|
||||
"Parameters(type=<Type.ID: 2>, version=19, salt_len=8, "
|
||||
"hash_len=32, time_cost=2, memory_cost=65536, parallelism=4)"
|
||||
)
|
||||
|
||||
19
tests/typing/api.py
Normal file
19
tests/typing/api.py
Normal file
@ -0,0 +1,19 @@
|
||||
import argon2
|
||||
|
||||
|
||||
argon2.PasswordHasher.from_parameters(argon2.profiles.RFC_9106_HIGH_MEMORY)
|
||||
ph = argon2.PasswordHasher()
|
||||
|
||||
ph.hash("pw")
|
||||
ph.hash("pw", salt=b"salt")
|
||||
ph.hash(b"pw")
|
||||
ph.hash(b"pw", salt=b"salt")
|
||||
ph.verify("hash", "pw")
|
||||
ph.verify(b"hash", "pw")
|
||||
ph.verify(b"hash", b"pw")
|
||||
ph.verify("hash", b"pw")
|
||||
|
||||
if ph.check_needs_rehash("hash") is True:
|
||||
...
|
||||
|
||||
params: argon2.Parameters = argon2.profiles.get_default_parameters()
|
||||
180
tox.ini
180
tox.ini
@ -1,74 +1,134 @@
|
||||
[tox]
|
||||
envlist = pre-commit,lint,py27,py34,py35,py36,py37,pypy,pypy3,system-argon2,docs,manifest,readme,coverage-report
|
||||
|
||||
|
||||
[testenv:pre-commit]
|
||||
skip_install = true
|
||||
basepython = python3.6
|
||||
deps = pre-commit
|
||||
passenv = HOMEPATH # needed on Windows
|
||||
commands = pre-commit run --all-files --verbose
|
||||
min_version = 4.25
|
||||
env_list =
|
||||
pre-commit,
|
||||
py3{9-14}-{tests,mypy},
|
||||
py314t-tests,
|
||||
py314-tests-{bindings-main,system-argon2},
|
||||
pypy3-tests,
|
||||
typing-{pyright,ty,pyrefly,mypy}
|
||||
docs-doctests,
|
||||
coverage-{combine,report}
|
||||
|
||||
|
||||
[testenv]
|
||||
extras = tests
|
||||
description = Run tests / check types and do NOT measure coverage.
|
||||
package = wheel
|
||||
wheel_build_env = .pkg
|
||||
dependency_groups =
|
||||
tests: tests
|
||||
mypy: typing
|
||||
pass_env =
|
||||
FORCE_COLOR
|
||||
NO_COLOR
|
||||
commands =
|
||||
coverage run --parallel -m pytest {posargs}
|
||||
coverage run --parallel -m argon2 -n 1 -t 1 -m 8 -p 1
|
||||
tests: pytest {posargs}
|
||||
tests: python -Im argon2 -n 1 -t 1 -m 8 -p 1
|
||||
mypy: mypy tests/typing
|
||||
|
||||
|
||||
[testenv:py3{9,14}-tests]
|
||||
# Keep coverage-combine's depends with the versions.
|
||||
description = Run tests and measure coverage.
|
||||
deps = coverage[toml]
|
||||
commands =
|
||||
coverage run -m pytest {posargs}
|
||||
coverage run -m argon2 -n 1 -t 1 -m 8 -p 1
|
||||
coverage run -m argon2 --profile CHEAPEST
|
||||
|
||||
|
||||
# Split combine/report in 2 to avoid excessive "Combined data file ..." output.
|
||||
[testenv:coverage-combine]
|
||||
# Keep base_python in-sync with .python-version-default
|
||||
base_python = py313
|
||||
# Keep in-sync with test env definition above.
|
||||
depends = py3{9,14}-tests
|
||||
skip_install = true
|
||||
deps = coverage
|
||||
commands = coverage combine
|
||||
|
||||
[testenv:coverage-report]
|
||||
description = Report coverage over oldest and latest supported Python
|
||||
# Keep base_python in-sync with .python-version-default
|
||||
base_python = py313
|
||||
skip_install = true
|
||||
depends = coverage-combine
|
||||
deps = coverage
|
||||
parallel_show_output = true
|
||||
commands = coverage report
|
||||
|
||||
[testenv:system-argon2]
|
||||
description = Run tests against bindings that use a system installation of Argon2.
|
||||
basepython = python3.6
|
||||
setenv = ARGON2_CFFI_USE_SYSTEM=1
|
||||
extras = tests
|
||||
install_command = pip install {opts} --no-binary=argon2_cffi {packages}
|
||||
commands =
|
||||
python -m pytest {posargs}
|
||||
python -m argon2 -n 1 -t 1 -m 8 -p 1
|
||||
set_env = ARGON2_CFFI_USE_SYSTEM=1
|
||||
install_command = pip install {opts} --no-binary=argon2-cffi-bindings {packages}
|
||||
|
||||
|
||||
[testenv:docs]
|
||||
basepython = python3.6
|
||||
extras = docs
|
||||
commands =
|
||||
python -m doctest README.rst
|
||||
sphinx-build -W -b html -d {envtmpdir}/doctrees docs docs/_build/html
|
||||
sphinx-build -W -b doctest -d {envtmpdir}/doctrees docs docs/_build/html
|
||||
|
||||
|
||||
[testenv:lint]
|
||||
skip_install = true
|
||||
basepython = python3.6
|
||||
[testenv:py312-bindings-main]
|
||||
description = Run tests against the current main branch of argon2-cffi-bindings
|
||||
dependency_groups =
|
||||
deps =
|
||||
flake8
|
||||
flake8-isort
|
||||
black
|
||||
commands_pre = pip install -I hypothesis pytest git+https://github.com/hynek/argon2-cffi-bindings
|
||||
install_command = pip install {opts} --no-deps {packages}
|
||||
|
||||
|
||||
[testenv:pre-commit]
|
||||
description = Run all pre-commit hooks.
|
||||
skip_install = true
|
||||
deps = pre-commit-uv
|
||||
commands = pre-commit run --all-files
|
||||
|
||||
|
||||
[testenv:typing-mypy]
|
||||
description = Check own code with Mypyy.
|
||||
# Keep base_python in-sync with .python-version-default
|
||||
base_python = py313
|
||||
deps = mypy
|
||||
dependency_groups = typing
|
||||
commands = mypy src
|
||||
|
||||
[testenv:typing-pyright]
|
||||
description = Check API and own code with Pyright
|
||||
deps = pyright
|
||||
dependency_groups = typing
|
||||
commands = pyright src tests/typing
|
||||
|
||||
[testenv:typing-ty]
|
||||
description = Check API with ty
|
||||
deps = ty
|
||||
dependency_groups = typing
|
||||
commands = ty check src tests/typing
|
||||
|
||||
[testenv:typing-pyrefly]
|
||||
description = Check API with pyrefly
|
||||
deps = pyrefly
|
||||
dependency_groups = typing
|
||||
commands = pyrefly check src tests/typing
|
||||
|
||||
|
||||
[testenv:docs-{build,doctests,linkcheck}]
|
||||
# Keep base_python in sync with .readthedocs.yaml.
|
||||
base_python = py313
|
||||
dependency_groups = docs
|
||||
commands =
|
||||
flake8 src tests setup.py docs/conf.py
|
||||
black --check setup.py src tests docs/conf.py
|
||||
build: sphinx-build -n -T -W -b html -d {envtmpdir}/doctrees docs {posargs:docs/_build/}html
|
||||
doctests: python -m doctest README.md
|
||||
doctests: sphinx-build -n -T -W -b doctest -d {envtmpdir}/doctrees docs {posargs:docs/_build/}html
|
||||
linkcheck: sphinx-build -W -b linkcheck -d {envtmpdir}/doctrees docs docs/_build/html
|
||||
|
||||
|
||||
[testenv:manifest]
|
||||
description = Ensure MANIFEST.in is up to date.
|
||||
basepython = python3.6
|
||||
deps = check-manifest
|
||||
skip_install = true
|
||||
commands = check-manifest
|
||||
|
||||
|
||||
[testenv:readme]
|
||||
description = Ensure README.rst renders on PyPI.
|
||||
basepython = python3.6
|
||||
deps = readme_renderer
|
||||
skip_install = true
|
||||
commands = python setup.py check -r -s
|
||||
|
||||
|
||||
[testenv:coverage-report]
|
||||
basepython = python3.6
|
||||
deps = coverage
|
||||
skip_install = true
|
||||
[testenv:docs-watch]
|
||||
package = editable
|
||||
base_python = {[testenv:docs-build]base_python}
|
||||
dependency_groups = {[testenv:docs-build]dependency_groups}
|
||||
deps = watchfiles
|
||||
commands =
|
||||
coverage combine
|
||||
coverage report
|
||||
watchfiles \
|
||||
--ignore-paths docs/_build/ \
|
||||
'sphinx-build -W -n --jobs auto -b html -d {envtmpdir}/doctrees docs docs/_build/html' \
|
||||
src \
|
||||
docs \
|
||||
README.md \
|
||||
CHANGELOG.md
|
||||
|
||||
[testenv:docs-linkcheck]
|
||||
base_python = {[testenv:docs]base_python}
|
||||
dependency_groups = {[testenv:docs]dependency_groups}
|
||||
commands = sphinx-build -W -b linkcheck -d {envtmpdir}/doctrees docs docs/_build/html
|
||||
|
||||
Loading…
Reference in New Issue
Block a user