| 1 | #!/bin/sh |
| 2 | |
| 3 | ### Constants |
| 4 | c_valgrind_min=1 |
| 5 | reference_file="${scriptdir}/test_scrypt.good" |
| 6 | encrypted_file_1="${out}/sys-scrypt.enc" |
| 7 | decrypted_file_1="${out}/sys-scrypt.txt" |
| 8 | encrypted_file_2="${out}/our-scrypt.enc" |
| 9 | decrypted_file_2="${out}/our-scrypt.txt" |
| 10 | |
| 11 | scenario_cmd() { |
| 12 | if [ -z "${system_scrypt}" ]; then |
| 13 | printf "no suitable system scrypt: " |
| 14 | # Inform test suite that we are skipping. |
| 15 | setup_check_variables |
| 16 | echo "-1" > ${c_exitfile} |
| 17 | return |
| 18 | fi |
| 19 | |
| 20 | # Encrypt a file with our scrypt. |
| 21 | setup_check_variables |
| 22 | ( |
| 23 | echo ${password} | ${c_valgrind_cmd} ${bindir}/scrypt \ |
| 24 | enc -P -t 1 ${reference_file} ${encrypted_file_1} |
| 25 | echo $? > ${c_exitfile} |
| 26 | ) |
| 27 | |
| 28 | # Use the system scrypt to decrypt the file we just |
| 29 | # encrypted. Don't use valgrind for this. |
| 30 | setup_check_variables |
| 31 | ( |
| 32 | echo ${password} | ${system_scrypt} \ |
| 33 | dec -P ${encrypted_file_1} ${decrypted_file_1} |
| 34 | echo $? > ${c_exitfile} |
| 35 | ) |
| 36 | |
| 37 | # The decrypted file should match the reference. |
| 38 | setup_check_variables |
| 39 | if cmp -s ${decrypted_file_1} ${reference_file}; then |
| 40 | echo "0" |
| 41 | else |
| 42 | echo "1" |
| 43 | fi > ${c_exitfile} |
| 44 | |
| 45 | # Encrypt a file with the system scrypt. Don't use |
| 46 | # valgrind for this. |
| 47 | setup_check_variables |
| 48 | ( |
| 49 | echo ${password} | ${system_scrypt} \ |
| 50 | enc -P -t 1 ${reference_file} ${encrypted_file_2} |
| 51 | echo $? > ${c_exitfile} |
| 52 | ) |
| 53 | |
| 54 | # Use our scrypt to decrypt the file we just encrypted. |
| 55 | setup_check_variables |
| 56 | ( |
| 57 | echo ${password} | ${c_valgrind_cmd} ${bindir}/scrypt \ |
| 58 | dec -P ${encrypted_file_2} ${decrypted_file_2} |
| 59 | echo $? > ${c_exitfile} |
| 60 | ) |
| 61 | |
| 62 | # The decrypted file should match the reference. |
| 63 | setup_check_variables |
| 64 | if cmp -s ${decrypted_file_2} ${reference_file}; then |
| 65 | echo "0" |
| 66 | else |
| 67 | echo "1" |
| 68 | fi > ${c_exitfile} |
| 69 | } |