Skip to content

Commit

Permalink
Patch 1 (#160)
Browse files Browse the repository at this point in the history
* using hypothesys `func` param instead fixed

* rst doc: not used link definition

* small refactor in cli

* Retain param order

---------

Co-authored-by: Hynek Schlawack <hs@ox.cx>
  • Loading branch information
isidroas and hynek committed Nov 28, 2023
1 parent d0e4c35 commit 5c13aa6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
23 changes: 12 additions & 11 deletions src/argon2/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@


def main(argv: list[str]) -> None:
parser = argparse.ArgumentParser(description="Benchmark Argon2.")
parser = argparse.ArgumentParser(
description="Benchmark Argon2.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"-n", type=int, default=100, help="Number of iterations to measure."
)
Expand Down Expand Up @@ -56,23 +59,21 @@ def main(argv: list[str]) -> None:
)
hash = ph.hash(password)

params = {
"time_cost": (ph.time_cost, "iterations"),
"memory_cost": (ph.memory_cost, "KiB"),
"parallelism": (ph.parallelism, "threads"),
"hash_len": (ph.hash_len, "bytes"),
}

print("Running Argon2id %d times with:" % (args.n,))

for k, v in sorted(params.items()):
print("%s: %d %s" % (k, v[0], v[1]))
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("%s: %d %s" % (name, value, units))

print("\nMeasuring...")
duration = timeit.timeit(
f"ph.verify({hash!r}, {password!r})",
setup=f"""\
from argon2 import PasswordHasher, Type
from argon2 import PasswordHasher
ph = PasswordHasher(
time_cost={args.t!r},
Expand Down
1 change: 0 additions & 1 deletion src/argon2/low_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def hash_secret(
.. 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(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_low_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def test_hash_fast(self, func, secret):
"""
Hash various secrets as cheaply as possible.
"""
hash_secret(
func(
secret,
salt=b"12345678",
time_cost=1,
Expand Down

0 comments on commit 5c13aa6

Please sign in to comment.