30 lines
481 B
Python
30 lines
481 B
Python
import hmac
|
|
import hashlib
|
|
|
|
|
|
# Import shared secret
|
|
with open('k', 'rb') as file:
|
|
shared_key = file.read()
|
|
|
|
# Compute hmac
|
|
with open('mactext', 'rb') as file:
|
|
data = file.read()
|
|
|
|
m = data[:18]
|
|
m_hash = data[18:]
|
|
|
|
hmac_oject: hmac.HMAC = hmac.new(shared_key, m, hashlib.sha256)
|
|
derived_hmac = hmac_oject.digest()
|
|
print(f'Derived HMAC: {hmac_oject.digest()}')
|
|
|
|
if derived_hmac == m_hash:
|
|
print("HMAC matches message")
|
|
|
|
else:
|
|
print("HMAC does not match message")
|
|
|
|
|
|
|
|
|
|
|