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 authored Nov 11, 2024
1 parent 42c5666 commit ff472ee
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*params.parallelism {

Check failure on line 431 in openpgp/s2k/s2k.go

View workflow job for this annotation

GitHub Actions / test-old

invalid operation: decodeMemory(params.memoryExp) < 8 * params.parallelism (mismatched types uint32 and byte)

Check failure on line 431 in openpgp/s2k/s2k.go

View workflow job for this annotation

GitHub Actions / test-old

invalid operation: decodeMemory(params.memoryExp) < 8 * params.parallelism (mismatched types uint32 and byte)

Check failure on line 431 in openpgp/s2k/s2k.go

View workflow job for this annotation

GitHub Actions / test

invalid operation: decodeMemory(params.memoryExp) < 8 * params.parallelism (mismatched types uint32 and byte)

Check failure on line 431 in openpgp/s2k/s2k.go

View workflow job for this annotation

GitHub Actions / Build gosop from branch v1-api

invalid operation: decodeMemory(params.memoryExp) < 8 * params.parallelism (mismatched types uint32 and byte)

Check failure on line 431 in openpgp/s2k/s2k.go

View workflow job for this annotation

GitHub Actions / Build gosop from branch v2-api

invalid operation: decodeMemory(params.memoryExp) < 8 * params.parallelism (mismatched types uint32 and byte)
return errors.StructuralError("invalid argon2 params: memory is out of bounds")
}

Expand Down

0 comments on commit ff472ee

Please sign in to comment.