pcrextend.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. start_up
  4. declare -A alg_hashes=(
  5. ["sha1"]="f1d2d2f924e986ac86fdf7b36c94bcdf32beec15"
  6. ["sha256"]="6ea40aa7267bb71251c1de1c3605a3df759b86b22fa9f62aa298d4197cd88a38"
  7. ["sha384"]="ecf669bad80a9b2b267d8671bd7d012d92e8cd30fd28d88dcdbcc2ddffbb995c7f226011ac24ae92dcfb493e0a5ecf89"
  8. ["sha512"]="18b7381f36cdf5dd7c0b64835e0bf5041a52a38e3c3f4cbabcc4099d52590bf9916808138de511fb172cb64fcc11601f07d114f03e95e3d5ceacb330ce0f856a"
  9. ["sm3_256"]="2b14a1fc49869413b0beb707069cffc0c6b0a51f3fedb9ce072c80709652b3ae"
  10. )
  11. digests=""
  12. # test a single algorithm based on what is supported
  13. for alg in `tpm2 getcap pcrs | grep sha |awk {'print $2'} | awk -F: {'print $1'}`; do
  14. hash=${alg_hashes[$alg]}
  15. if [ ! -z $digests ]; then
  16. digests="$digests,"
  17. fi
  18. digests="$digests$alg=$hash"
  19. tpm2 pcrextend 9:$alg=$hash
  20. done;
  21. #
  22. # To keep things simple, compound specifications are just done with
  23. # the supported sha1 algorithms to guarantee the command to succeed.
  24. #
  25. tpm2 pcrextend 8:$digests
  26. # Extend a PCR for all supported banks like in the previous test but
  27. # try extending two PCR in the same command.
  28. tpm2 pcrextend 8:$digests 9:$digests
  29. # Over-length hash should fail
  30. if tpm2 pcrextend 8:$digests,sha1=${alg_hashes["sha256"]}; then
  31. echo "tpm2 pcrextend with over-length hash didn't fail!"
  32. exit 1
  33. else
  34. true
  35. fi
  36. exit 0