fscrypt
fscrypt copied to clipboard
Fix Parallelism Cost when NumCPU() > 255
As pointed out in #363, we are not currently handling cases with 256 or more CPUs correctly. Our current behavior:
- Casts
costs.parallelismto auint8 - Panics if
NumCPUis a multiple of 256 - If
costs.parallelismis > 256, we silently use the truncated parallelism cost. This is the worst part.
This PR does multiple things (see the commits for more detailed information):
- Increases cost error checking before calling into the Argon2 library.
- Adds a
truncation_fixedboolean field to theHashingCostsproto, indicating that this bug is fixed. - In
getHashingCosts, cap the number of threads to 255.
Thanks for doing this! Two comments:
- Bug: at the bottom of
getHashingCosts(), aHashingCostsis being initialized withoutTruncationFixed: true. func (h *HashingCosts) CheckValidity()already does some of the new checks that are being added toPassphraseHash(). Should they be consolidated into one place?