diff --git a/main.c b/main.c index 2b05e252..a6f913af 100644 --- a/main.c +++ b/main.c @@ -346,6 +346,17 @@ main(int argc, char * argv[]) goto err0; } + /* + * Explicit parameters only apply to encryption; when decrypting we + * always use the values from the file header. Reject them here + * rather than violating scryptdec_file_prep's API contract. The + * all-or-none checks above mean that testing logN is sufficient. + */ + if (dec && (params.logN != 0)) { + warn0("--logN, -r and -p cannot be used when decrypting"); + goto err0; + } + /* We can't have a maxmemfrac of 0. */ if (params.maxmemfrac == 0.0) { warn0("-m must be greater than 0"); diff --git a/tests/09-explicit-params.sh b/tests/09-explicit-params.sh index 7b75b05b..1587ec49 100644 --- a/tests/09-explicit-params.sh +++ b/tests/09-explicit-params.sh @@ -63,4 +63,14 @@ scenario_cmd() { enc -p 12 "${reference_file}" 2>&1 | \ grep -q "If -p is set, --logN and -r must also be set" echo $? > "${c_exitfile}" + + # Explicit parameters are encryption-only; "dec" must reject them + # instead of reaching the assertion in scryptdec_file_prep. + setup_check "scrypt dec Nrp rejected" + echo "${password}" | ${c_valgrind_cmd} "${bindir}/scrypt" \ + dec --logN 12 -r 2 -p 3 \ + --passphrase dev:stdin-once \ + "${encrypted_file}" 2>&1 | \ + grep -q "\--logN, -r and -p cannot be used when decrypting" + echo $? > "${c_exitfile}" }