ecc.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. cleanup() {
  4. rm -f pass1_ecc.q pass2_ecc.q ecc.ctr
  5. if [ "$1" != "no-shut-down" ]; then
  6. shut_down
  7. fi
  8. }
  9. trap cleanup EXIT
  10. start_up
  11. cleanup "no-shut-down"
  12. # TPM2_EC_Ephemeral
  13. ## Check if commit counter is zero on first invocation
  14. tpm2 ecephemeral -u pass1_ecc.q -t pass1_ecc.ctr ecc256
  15. xxd -p pass1_ecc.ctr | grep 0000
  16. ## Check if commit counter increments to 1 on second invocation
  17. tpm2 ecephemeral -u pass2_ecc.q -t pass2_ecc.ctr ecc256
  18. xxd -p pass2_ecc.ctr | grep 0001
  19. # TPM2_Commit
  20. ## Check if commit counter in incremented after successful execution of commit
  21. tpm2 createprimary -C o -c prim.ctx -Q
  22. tpm2 create -C prim.ctx -c commit_key.ctx -u commit_key.pub -r commit_key.priv \
  23. -G ecc256:ecdaa
  24. tpm2 commit -c commit_key.ctx -t commit.ctr --eccpoint-K K.bin \
  25. --eccpoint-L L.bin -u E.bin
  26. xxd -p commit.ctr | grep 0002
  27. # TPM2_ECDH_KeyGen
  28. ## Check if ecdhkeygen creates ephemeral key with loaded ECC key of type ECDAA
  29. tpm2 ecdhkeygen -u ecc256ecdaa.pub -o ecc256ecdaa.priv -c commit_key.ctx
  30. ## Check if ecdhkeygen creates ephemeral key with loaded ECC key of type ECDH
  31. tpm2 create -C prim.ctx -c ecdh_key.ctx -u ecdh_key.pub -r ecdh_key.priv \
  32. -G ecc256:ecdh
  33. tpm2 ecdhkeygen -u ecc256ecdh.pub -o ecc256ecdh.priv -c ecdh_key.ctx
  34. # TPM2_ECDH_ZGen
  35. ## Check if the recovered Z point matches
  36. tpm2 ecdhzgen -u ecc256ecdh.pub -o ecdhZgen.dat -c ecdh_key.ctx
  37. diff ecdhZgen.dat ecc256ecdh.priv
  38. # TPM2_ZGen_2Phase
  39. ## Check if output Z points are generated using separate commit count values
  40. tpm2 zgen2phase -c ecdh_key.ctx --static-public ecc256ecdh.pub \
  41. --ephemeral-public pass1_ecc.q -t 0 --output-Z1 pass1.z1 --output-Z2 pass1.z2
  42. tpm2 zgen2phase -c ecdh_key.ctx --static-public ecc256ecdh.pub \
  43. --ephemeral-public pass2_ecc.q -t 1 --output-Z1 pass2.z1 --output-Z2 pass2.z2
  44. tpm2 zgen2phase -c ecdh_key.ctx --static-public ecc256ecdh.pub \
  45. --ephemeral-public E.bin -t 2 --output-Z1 pass3.z1 --output-Z2 pass3.z2
  46. ## Check to ensure the Z1 points are always the same value
  47. diff pass1.z1 pass2.z1
  48. diff pass2.z1 pass3.z1
  49. ## Check to ensure the Z2 points are different
  50. trap - ERR
  51. diff pass1.z2 pass2.z2
  52. diff pass1.z2 pass3.z2
  53. diff pass2.z2 pass3.z2
  54. trap onerror ERR
  55. exit 0