diff --git a/openpgp/s2k/s2k.go b/openpgp/s2k/s2k.go index 5a5b31b5..6871b84f 100644 --- a/openpgp/s2k/s2k.go +++ b/openpgp/s2k/s2k.go @@ -426,17 +426,9 @@ func validateArgon2Params(params *Params) error { return errors.StructuralError("invalid argon2 params: iterations is 0") } - // The encoded memory size MUST be a value from 3+ceil(log2(p)) to 31. - p := params.parallelism - ceiledLogarithm := byte(0) - for p > 1 { - p /= 2 - ceiledLogarithm += 1 - } - if byte(1)< 31 { + // The encoded memory size MUST be a value from 3+ceil(log2(p)) to 31, + // such that the decoded memory size m is a value from 8*p to 2^31. + if params.memoryExp > 31 || decodeMemory(params.memoryExp) < 8*uint32(params.parallelism) { return errors.StructuralError("invalid argon2 params: memory is out of bounds") }