mheyman / Isopoh.Cryptography.Argon2

Fully managed .Net Core implementation of Argon2
Other
196 stars 9 forks source link

Hashing becomes slower and slower over time #22

Closed mrdevrobert closed 3 years ago

mrdevrobert commented 4 years ago

The more lanes are configured, the faster the issue occurs. Run this simple loop with the latest version, after about 10-15 iterations the hash time increases a lot and eventually it will take minutes. Reproduced on multiple computers.

It looks like we get more and more LockFailException being thrown when constructing SecuryArrays. On top of that it looks like the GetMaxLockable method takes a long time to execute.

See attached test cs file.

Program.zip

Here is the output of a sample run (expected time is around 2 sec):

Time elapsed: 1996 ms Time elapsed: 1526 ms Time elapsed: 1507 ms Time elapsed: 1737 ms Time elapsed: 1935 ms Time elapsed: 1665 ms Time elapsed: 1904 ms Time elapsed: 1952 ms Time elapsed: 1565 ms Time elapsed: 2080 ms Time elapsed: 1745 ms Time elapsed: 1525 ms Time elapsed: 1660 ms Time elapsed: 4944 ms Time elapsed: 10502 ms Time elapsed: 5073 ms Time elapsed: 9015 ms Time elapsed: 8111 ms

mheyman commented 4 years ago

I saw something similar occur when the SecureArray values created under the hood failed to create lockable memory. The time was being spent in a call to determine the maximum lockable amount of RAM. That call was only there for reporting to help with debugging or just curiosity. It now doesn't do that by default in v1.1.7 on nuget.org and I think this issue should go away for you.