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 = ["927B8BBD968D0B233962AF2D453B8DE39ABB5FAFADF322431C2FA48DEB1D109BCE53E057AF701F57D6047D0B65EF05EDEB4391D2CA4B78E8147B8B0535D155C6",
  26. "B9365069F0386B30F418FF0C32514F3BA00D25D8F6D98F06E36B3DA38E6423A4F19E2C61146835B9CF41E14B680211625AFF2F7956BDB7F7A174DE4F4D2D958B",
  27. "C8B839EC99B7835F61634F83B0BAB90A2726E43FCBD50074616A0A03CDD2C374CED2E26AA0BEFB983D2009F47BD449648BD222123E3CFB019323B5529D1C259F",
  28. "C75944C34D6DE50E73EB47C2EDF62309E7D7EFD3D45F1F4FBBB96CAD31419AAE6CBB42961EAD8630C054A8108B7035648E2A184DD3EB1B7E009C09B34C2CB487"]
  29. result_pcr0 = get_expected_pcr_value(hash_list).decode("utf-8")
  30. print(result_pcr0)
Success #stdin #stdout 0.02s 9312KB
stdin
Standard input is empty
stdout
CFF748914ADACF32EA790CB8C9EEF8F8F91FF06ECD7D015745D73B958A4E78A0