From cec76d0ab83e9a5925785fc1b753a37d5a5d96cf Mon Sep 17 00:00:00 2001 From: Lukas Burkhalter <10532077+lubux@users.noreply.github.com> Date: Mon, 11 Nov 2024 12:43:01 +0100 Subject: [PATCH] refactor: Get rid of the logarithm computation. Co-authored-by: Daniel Huigens --- openpgp/s2k/s2k.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) 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") }