05-system-scrypt-encrypt-decrypt.sh 1.8 KB

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