Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
10 changes: 10 additions & 0 deletions tests/09-explicit-params.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}