fork download
  1. import binascii
  2. from Crypto.Hash import SHA as SHA1
  3. from Crypto.Hash import SHA256
  4.  
  5. def get_expected_pcr_value(hash_list):
  6. """
  7. Description:
  8. Given a list of hash strings, calculate the expected PCR values
  9. For PCR0, extend by the Boot 0 hash and then the Boot Loader Hash
  10. For PCR8, extend by the OS hash
  11. Arg:
  12. hash_list(list): PCR0 and PCR8 hashes
  13. Return:
  14. The calculated PCR value
  15. """
  16. init = "0000000000000000000000000000000000000000000000000000000000000000"
  17. pcr_init = init
  18. pcr_bin = binascii.a2b_hex(pcr_init)
  19. for hash_str in hash_list:
  20. hash_bin = binascii.a2b_hex(hash_str)
  21. hash_sha256_bin = SHA256.new(hash_bin).digest()
  22. pcr_bin = SHA256.new(pcr_bin + hash_sha256_bin).digest()
  23. return binascii.b2a_hex(pcr_bin).upper()
  24.  
  25. hash_list = ["06A33C4BDA63FF62738CD0D333C299090AE95C8CE429A3DC9847909D84E9326D",
  26. "4C89F4201B140F8D5E4DEBA53616291FCA66F2A82EE757A966C5684203ED4A10D3BF7E8A4E211FD6BA9B5CEC6E3E1DBEE9DD2073642A941BDE28803AA0224F59"]
  27. result_pcr0 = get_expected_pcr_value(hash_list).decode("utf-8")
  28. print(result_pcr0)
Success #stdin #stdout 0.02s 9448KB
stdin
Standard input is empty
stdout
CFA37D00C0EC42D9BC1BBF7DE6C8D0DCC90D18B6AE58D10FFAD4DCB2FC5F03B5