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

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