Skip to content

Commit

Permalink
refactor: Get rid of the logarithm computation.
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Huigens <[email protected]>
  • Loading branch information
lubux and twiss committed Nov 11, 2024
1 parent 42c5666 commit cec76d0
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions openpgp/s2k/s2k.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)<<ceiledLogarithm != params.parallelism {
ceiledLogarithm += 1
}
if params.memoryExp < 3+ceiledLogarithm || params.memoryExp > 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")
}

Expand Down

0 comments on commit cec76d0

Please sign in to comment.