import hashlib


def HashToCurve(curve, hash_oid, hv):
    """
    Hash the provided input data into a curve point. The data (hv) is
    either raw unhashed data, or a hash value if the data was pre-hashed.
    'hash_oid' identifies the hash function used for pre-hashing; use b''
    (empty string) for raw unhashed data. Returned point can be any point
    on the group, including the neutral N.
    """
    n = curve.K.encodedLen
    sh = hashlib.shake_256()
    sh.update(curve.bname)
    sh.update(b'-hash-to-curve:')
    sh.update(hash_oid)
    sh.update(b':')
    sh.update(hv)
    blob = sh.digest(2 * n)
    return curve.MapToCurve(blob[:n]) + curve.MapToCurve(blob[n:])