mheyman / Isopoh.Cryptography.Argon2

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

SecureArray crashes when MemoryCost is over 3000000 and memory is not freed after hashing. #28

Closed firepacket closed 4 years ago

firepacket commented 4 years ago

When memory cost is set to be over a couple GB (in my testing it was set around 3000000), SecureArray throws an exception saying "'Array dimensions exceeded supported range."

Also, after the hashing is complete memory is not correctly freed even after manually calling Dispose and GC.Collect().

Sadly, this implementation is not suitable for my purposes because of these issues.

mheyman commented 4 years ago

You ran into a fundamental limitation of C#! C# cannot have arrays over 2G elements (ulong arrays over 16GB). C# has really disappointed me in this regard. I've gone to extraordinary lengths on other projects involving P/Invoke and C++ code to get around this limit. Since one of the goals of this project was to be fully managed, I cannot do that here - I know I cheated a little with SecureArray ;-)

For you, the problem is that I followed the reference design a little close. It uses a single array that it breaks up into blocks. I simply broke up that array into chunks if it tried to go over 16GB and it worked!

Changes pushed and available in v1.1.6 on nuget.org

mheyman commented 4 years ago

Got integer overflow that must be fixed...

mheyman commented 4 years ago

Nuget v1.1.7 doesn't overflow. It should work with any number of large memory cost values until the OS fails to allocate. At that point, a OutOfMemoryException gets thrown with a message showing the memory cost and lanes (the two values that go into how much memory gets allocated).