stirrandom.sh 997 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. goodfile=$(mktemp)
  4. bigfile=$(mktemp)
  5. {
  6. dd if=/dev/urandom of="${bigfile}" bs=1 count=256
  7. dd if=/dev/urandom of="${goodfile}" bs=1 count=42
  8. } &>/dev/null
  9. cleanup() {
  10. if [ "$1" != "no-shut-down" ]; then
  11. shut_down
  12. rm -f "${bigfile}"
  13. rm -f "${goodfile}"
  14. fi
  15. }
  16. trap cleanup EXIT
  17. start_up
  18. cleanup "no-shut-down"
  19. # Sending bytes from stdin (pipe)
  20. echo -n "return 4" | tpm2 stirrandom -V 2>&1 1>/dev/null | \
  21. grep -q "Submitting 8 bytes to TPM"
  22. # Sending bytes from stdin (file)
  23. tpm2 stirrandom -V < "${goodfile}" 2>&1 1>/dev/null | \
  24. grep -q "Submitting 42 bytes to TPM"
  25. # Sending bytes from a file path
  26. tpm2 stirrandom "${goodfile}" -V 2>&1 1>/dev/null | \
  27. grep -q "Submitting 42 bytes to TPM"
  28. # Try to read more than 128 bytes from file and get an error
  29. if tpm2 stirrandom "${bigfile}"; then
  30. echo "tpm2 stirrandom didn't fail on exceeding requested size"
  31. exit 1
  32. else
  33. true
  34. fi
  35. exit 0