mheyman / Isopoh.Cryptography.Argon2

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

Incorrect output when generating more than 64 bytes #47

Closed camerondm9 closed 1 year ago

camerondm9 commented 1 year ago

When comparing outputs and performance between this library and Konscious.Security.Cryptography.Argon2, I noticed that your output is different when requesting more than 64 bytes. I verified that your output is also different from that produced by antelle.net/argon2-browser, which means there is probably a bug in this library. This difference is present for all addressing modes (Argon2i, Argon2id, Argon2d).

There also isn't any kind of error when setting the memory cost to less than 8 (the minimum in the spec), but your output is different from Konscious.Security.Cryptography.Argon2 again. Not sure whose bug it is, but if you want to match the spec you should probably throw an ArgumentException when memory cost < 8.

mheyman commented 1 year ago

Thanks! Will look into it...

mheyman commented 1 year ago

I've looked into it...

mheyman commented 1 year ago

Found it! The issue was the length passed into in the final blake2 block. That was a fun bug.

It is a breaking change unfortunately. Since I'm breaking things, I removed the $data field from the argon hash string for the additional data input. This must have been a pre-releasism I included back when I first wrote this code that got elided before the real reference code was released.

The code now builds the reference command line utility (slightly modified with some additional fields the original didn't allow setting). It then creates 5-600 "reference" vectors to check against (looking at corner cases) in a C# code generation build step. I'm pretty confident this code now behaves correctly at all hash lengths (the code does handle >2GB hashes on C#). I'm disappointed I didn't do this back at the start because I'm usually more aware of testing crypto code properly.

Currently I have a certificate issue pushing a nuget package - working on that...

mheyman commented 1 year ago

Fix pushed to nuget

camerondm9 commented 8 months ago

Finally got back to testing this.

Looks like it's fixed. Thank you!