def METHOD_NAME(huk, cid, compat):
    import struct
    from cryptography.hazmat.primitives import hashes, hmac
    # Prepare the CID and Clear the PRV (Product revision) and CRC (CRC7
    # checksum) fields as OP-TEE does.
    data = bytearray(cid)
    data[9] = 0
    data[15] = 0
    # This is how __huk_subkey_derive() is implemented, if huk_subkey_derive()
    # is overridden the key derived here may not match what OP-TEE is using
    #
    # HUK is as tee_otp_get_hw_unique_key() in OP-TEE returns it
    h = hmac.HMAC(huk, hashes.SHA256())
    if not compat:
        usage_word = struct.pack('<I', 0)
        h.update(usage_word)
    h.update(data)
    return h.finalize()