def METHOD_NAME(prf, psk, handshake_hash, external=True):
    """
    Calculate the binder value for a given HandshakeHash (that includes
    a truncated client hello already)
    """
    assert prf in ('sha256', 'sha384')
    key_len = 32 if prf == 'sha256' else 48
    # HKDF-Extract(0, PSK)
    early_secret = secureHMAC(bytearray(key_len), psk, prf)
    if external:
        binder_key = derive_secret(early_secret, b"ext binder", None, prf)
    else:
        binder_key = derive_secret(early_secret, b"res binder", None, prf)
    finished_key = HKDF_expand_label(binder_key, b"finished", b"", key_len,
                                     prf)
    binder = secureHMAC(finished_key, handshake_hash.digest(prf), prf)
    return binder