Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Libcperciva import #377

Merged
merged 4 commits into from
Oct 21, 2023
Merged
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
4 changes: 2 additions & 2 deletions tests/01-known-values.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ reference_small="${scriptdir}/verify-strings/test_scrypt_small.good"
### Actual command
scenario_cmd() {
# Run the binary which tests known input/output strings.
setup_check_variables "test_scrypt"
setup_check "test_scrypt"
(
${c_valgrind_cmd} "${bindir}/tests/verify-strings/test_scrypt" \
"${SMALLMEM:-0}" 1> "${test_output}"
echo $? > "${c_exitfile}"
)

# The generated values should match the known good values.
setup_check_variables "test_scrypt output against reference"
setup_check "test_scrypt output against reference"
if [ "${SMALLMEM:-0}" -gt "0" ]; then
cmp -s "${test_output}" "${reference_small}"
else
Expand Down
12 changes: 6 additions & 6 deletions tests/02-decrypt-reference-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ decrypted_badpass_log="${s_basename}-decrypt-badpass.log"

scenario_cmd() {
# Decrypt a reference file.
setup_check_variables "scrypt dec"
setup_check "scrypt dec"
(
echo "${password}" | ${c_valgrind_cmd} "${bindir}/scrypt" \
dec -P "${encrypted_reference_file}" \
Expand All @@ -21,18 +21,18 @@ scenario_cmd() {
)

# The decrypted reference file should match the reference.
setup_check_variables "scrypt dec output against reference"
setup_check "scrypt dec output against reference"
cmp -s "${decrypted_reference_file}" "${reference_file}"
echo $? > "${c_exitfile}"

# We should not have any output on stderr.
setup_check_variables "scrypt dec no stderr"
setup_check "scrypt dec no stderr"
test -s "${decrypted_reference_file_stderr}"
expected_exitcode 1 $? > "${c_exitfile}"

# Attempt to decrypt the reference file with an incorrect passphrase.
# We want this command to fail with 1.
setup_check_variables "scrypt dec bad passphrase"
setup_check "scrypt dec bad passphrase"
(
echo "bad-pass" | ${c_valgrind_cmd} "${bindir}/scrypt" \
dec -P "${encrypted_reference_file}" \
Expand All @@ -42,7 +42,7 @@ scenario_cmd() {
)

# We should have received an error message.
setup_check_variables "scrypt dec bad passphrase error"
setup_check "scrypt dec bad passphrase error"
if grep -q "scrypt: Passphrase is incorrect" \
"${decrypted_badpass_log}"; then
echo "0"
Expand All @@ -51,7 +51,7 @@ scenario_cmd() {
fi > "${c_exitfile}"

# We should not have created a file.
setup_check_variables "scrypt dec bad passphrase no file"
setup_check "scrypt dec bad passphrase no file"
if [ -e "${decrypted_badpass_file}" ]; then
echo "1"
else
Expand Down
8 changes: 4 additions & 4 deletions tests/03-encrypt-decrypt-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ decrypted_file="${s_basename}-attempt.txt"

scenario_cmd() {
# Encrypt a file. Use --passphrase dev:stdin-once instead of -P.
setup_check_variables "scrypt enc"
setup_check "scrypt enc"
(
echo "${password}" | ${c_valgrind_cmd} "${bindir}/scrypt" \
enc --passphrase dev:stdin-once -t 1 \
Expand All @@ -20,20 +20,20 @@ scenario_cmd() {
# We cannot check against the "reference" encrypted file, because
# encrypted files include random salt. If successful, don't delete
# ${encrypted_file} yet; we need it for the next test.
setup_check_variables "scrypt enc random salt"
setup_check "scrypt enc random salt"
cmp -s "${encrypted_file}" "${reference_file}"
expected_exitcode 1 $? > "${c_exitfile}"

# Decrypt the file we just encrypted.
setup_check_variables "scrypt enc decrypt"
setup_check "scrypt enc decrypt"
(
echo "${password}" | ${c_valgrind_cmd} "${bindir}/scrypt" \
dec -P "${encrypted_file}" "${decrypted_file}"
echo $? > "${c_exitfile}"
)

# The decrypted file should match the reference.
setup_check_variables "scrypt enc decrypt output against reference"
setup_check "scrypt enc decrypt output against reference"
cmp -s "${decrypted_file}" "${reference_file}"
echo $? > "${c_exitfile}"
}
10 changes: 5 additions & 5 deletions tests/04-force-resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ longwait_failed_log="${s_basename}-failed.log"

scenario_cmd() {
# Encrypt file which should take a long time to decrypt.
setup_check_variables "scrypt enc 10 seconds"
setup_check "scrypt enc 10 seconds"
(
echo "${password}" | ${c_valgrind_cmd} "${bindir}/scrypt" \
enc -P -t 10 "${reference_file}" \
Expand All @@ -19,7 +19,7 @@ scenario_cmd() {

# Attempt to decrypt it with limited time. We want this
# command to fail, so we negate the normal return code.
setup_check_variables "scrypt dec 1 second"
setup_check "scrypt dec 1 second"
(
echo "${password}" | ${c_valgrind_cmd} "${bindir}/scrypt" \
dec -P -t 1 "${longwait_encrypted_file}" \
Expand All @@ -29,13 +29,13 @@ scenario_cmd() {
)

# We should have received an error message.
setup_check_variables "scrypt dec 1 second error"
setup_check "scrypt dec 1 second error"
grep -q "scrypt: Decrypting file would take too much CPU time" \
"${longwait_failed_log}"
echo "$?" > "${c_exitfile}"

# Attempt to decrypt it with limited time, but force success.
setup_check_variables "scrypt dec force"
setup_check "scrypt dec force"
(
echo "${password}" | ${c_valgrind_cmd} "${bindir}/scrypt" \
dec -P -t 1 -f "${longwait_encrypted_file}" \
Expand All @@ -44,7 +44,7 @@ scenario_cmd() {
)

# The decrypted reference file should match the reference.
setup_check_variables "scrypt dec force output against reference"
setup_check "scrypt dec force output against reference"
cmp -s "${longwait_decrypted_file}" "${reference_file}"
echo $? > "${c_exitfile}"
}
14 changes: 7 additions & 7 deletions tests/05-system-scrypt-encrypt-decrypt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ scenario_cmd() {
if [ -z "${system_scrypt}" ]; then
printf "no suitable system scrypt: " 1>&2
# Inform test suite that we are skipping.
setup_check_variables "system scrypt skip"
setup_check "system scrypt skip"
echo "-1" > "${c_exitfile}"
return
fi

# Encrypt a file with our scrypt.
setup_check_variables "scrypt enc for system"
setup_check "scrypt enc for system"
(
echo "${password}" | ${c_valgrind_cmd} "${bindir}/scrypt" \
enc -P -t 1 "${reference_file}" "${encrypted_file_1}"
Expand All @@ -27,37 +27,37 @@ scenario_cmd() {

# Use the system scrypt to decrypt the file we just
# encrypted. Don't use valgrind for this.
setup_check_variables "system scrypt dec"
setup_check "system scrypt dec"
(
echo "${password}" | ${system_scrypt} \
dec -P "${encrypted_file_1}" "${decrypted_file_1}"
echo $? > "${c_exitfile}"
)

# The decrypted file should match the reference.
setup_check_variables "system scrypt dec output against reference"
setup_check "system scrypt dec output against reference"
cmp -s "${decrypted_file_1}" "${reference_file}"
echo $? > "${c_exitfile}"

# Encrypt a file with the system scrypt. Don't use
# valgrind for this.
setup_check_variables "system scrypt enc"
setup_check "system scrypt enc"
(
echo "${password}" | ${system_scrypt} \
enc -P -t 1 "${reference_file}" "${encrypted_file_2}"
echo $? > "${c_exitfile}"
)

# Use our scrypt to decrypt the file we just encrypted.
setup_check_variables "scrypt dec for system"
setup_check "scrypt dec for system"
(
echo "${password}" | ${c_valgrind_cmd} "${bindir}/scrypt" \
dec -P "${encrypted_file_2}" "${decrypted_file_2}"
echo $? > "${c_exitfile}"
)

# The decrypted file should match the reference.
setup_check_variables "scrypt dec for system output against reference"
setup_check "scrypt dec for system output against reference"
cmp -s "${decrypted_file_2}" "${reference_file}"
echo $? > "${c_exitfile}"
}
6 changes: 3 additions & 3 deletions tests/06-decrypt-fail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ non_encoded_file_output="${s_basename}-nonfile.txt"
scenario_cmd() {
# Attempt to decrypt a non-scrypt-encoded file.
# We want this command to fail with 1.
setup_check_variables "scrypt dec non-scrypt"
setup_check "scrypt dec non-scrypt"
(
echo "" | ${c_valgrind_cmd} "${bindir}/scrypt" \
dec -P "${non_encoded_file}" \
Expand All @@ -19,13 +19,13 @@ scenario_cmd() {
)

# We should have received an error message.
setup_check_variables "scrypt dec non-scrypt error"
setup_check "scrypt dec non-scrypt error"
grep -q "scrypt: Input is not valid scrypt-encrypted block" \
"${non_encoded_file_stderr}"
echo "$?" > "${c_exitfile}"

# We should not have created a file.
setup_check_variables "scrypt dec non-scrypt no file"
setup_check "scrypt dec non-scrypt no file"
if [ -e "${non_encoded_file_output}" ]; then
echo "1"
else
Expand Down
16 changes: 8 additions & 8 deletions tests/07-passphrase-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,42 @@ decrypted_no_envvar_log="${s_basename}-decrypt-no-envvar.log"

scenario_cmd() {
# Decrypt a reference file using --passphrase env:VAR.
setup_check_variables "scrypt dec env"
setup_check "scrypt dec env"
PASSPHRASE="${password}" \
${c_valgrind_cmd} "${bindir}/scrypt" \
dec --passphrase env:PASSPHRASE \
"${encrypted_reference_file}" "${decrypted_reference_file}"
echo $? > "${c_exitfile}"

# The decrypted reference file should match the reference.
setup_check_variables "scrypt dec env output against reference"
setup_check "scrypt dec env output against reference"
cmp -s "${decrypted_reference_file}" "${reference_file}"
echo $? > "${c_exitfile}"

# Attempt to decrypt the reference file with a non-existent envvar.
# We want this command to fail with 1.
setup_check_variables "scrypt dec env none"
setup_check "scrypt dec env none"
${c_valgrind_cmd} "${bindir}/scrypt" \
dec --passphrase env:THIS_ENVVAR_DOES_NOT_EXIST \
"${encrypted_reference_file}" "${decrypted_reference_file}" \
2> "${decrypted_no_envvar_log}"
expected_exitcode 1 $? > "${c_exitfile}"

# We should have received an error message.
setup_check_variables "scrypt dec env none error"
setup_check "scrypt dec env none error"
grep -q \
"scrypt: Failed to read from \${THIS_ENVVAR_DOES_NOT_EXIST}" \
"${decrypted_no_envvar_log}"
echo "$?" > "${c_exitfile}"

# We should not have created a file.
setup_check_variables "scrypt dec env no file"
setup_check "scrypt dec env no file"
test -e "${decrypted_badpass_file}"
expected_exitcode 1 $? > "${c_exitfile}"

# Attempt to decrypt the reference file with an incorrect passphrase.
# We want this command to fail with 1.
setup_check_variables "scrypt dec env bad"
setup_check "scrypt dec env bad"
PASSPHRASE="bad-pass" \
${c_valgrind_cmd} "${bindir}/scrypt" \
dec --passphrase env:PASSPHRASE \
Expand All @@ -55,11 +55,11 @@ scenario_cmd() {
expected_exitcode 1 $? > "${c_exitfile}"

# We should have received an error message.
setup_check_variables "scrypt dec env bad error"
setup_check "scrypt dec env bad error"
grep -q "scrypt: Passphrase is incorrect" "${decrypted_badpass_log}"
echo "$?" > "${c_exitfile}"

setup_check_variables "scrypt dec env bad no file"
setup_check "scrypt dec env bad no file"
# We should not have created a file.
test -e "${decrypted_badpass_file}"
expected_exitcode 1 $? > "${c_exitfile}"
Expand Down
16 changes: 8 additions & 8 deletions tests/08-passphrase-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,40 @@ scenario_cmd() {
echo "${password}" > "${passphrase_file}"

# Decrypt a reference file using --passphrase file:FILENAME.
setup_check_variables "scrypt dec file"
setup_check "scrypt dec file"
${c_valgrind_cmd} "${bindir}/scrypt" \
dec --passphrase file:"${passphrase_file}" \
"${encrypted_reference_file}" "${decrypted_reference_file}"
echo $? > "${c_exitfile}"

# The decrypted reference file should match the reference.
setup_check_variables "scrypt dec file output against reference"
setup_check "scrypt dec file output against reference"
cmp -s "${decrypted_reference_file}" "${reference_file}"
echo $? > "${c_exitfile}"

# Attempt to decrypt the reference file with a non-existent file.
# We want this command to fail with 1.
setup_check_variables "scrypt dec file none"
setup_check "scrypt dec file none"
${c_valgrind_cmd} "${bindir}/scrypt" \
dec --passphrase file:THIS_FILE_DOES_NOT_EXIST \
"${encrypted_reference_file}" "${decrypted_reference_file}" \
2> "${decrypted_no_file_log}"
expected_exitcode 1 $? > "${c_exitfile}"

# We should have received an error message.
setup_check_variables "scrypt dec file none error"
setup_check "scrypt dec file none error"
grep -q "scrypt: fopen(THIS_FILE_DOES_NOT_EXIST)" \
"${decrypted_no_file_log}"
echo "$?" > "${c_exitfile}"

# We should not have created a file.
setup_check_variables "scrypt dec file none no file"
setup_check "scrypt dec file none no file"
test -e "${decrypted_badpass_file}"
expected_exitcode 1 $? > "${c_exitfile}"

# Attempt to decrypt the reference file with an incorrect passphrase.
# We want this command to fail with 1.
setup_check_variables "scrypt dec file bad"
setup_check "scrypt dec file bad"
echo "bad-pass" > "${bad_passphrase_file}"
${c_valgrind_cmd} "${bindir}/scrypt" \
dec --passphrase file:"${bad_passphrase_file}" \
Expand All @@ -58,12 +58,12 @@ scenario_cmd() {
expected_exitcode 1 $? > "${c_exitfile}"

# We should have received an error message.
setup_check_variables "scrypt dec file bad error"
setup_check "scrypt dec file bad error"
grep -q "scrypt: Passphrase is incorrect" "${decrypted_badpass_log}"
echo "$?" > "${c_exitfile}"

# We should not have created a file.
setup_check_variables "scrypt dec file bad no file"
setup_check "scrypt dec file bad no file"
test -e "${decrypted_badpass_file}"
expected_exitcode 1 $? > "${c_exitfile}"
}
Loading