import hashlib
import hmac


def _HMAC(K, C, Mode=hashlib.sha1):
    """
    Generate an HMAC value.

    The default mode is to generate an HMAC-SHA-1 value w/ the SHA-1 algorithm.

    :param K: shared secret between client and server.
            Each HOTP generator has a different and unique secret K.
    :type K: bytes
    :param C: 8-byte counter value, the moving factor.
            This counter MUST be synchronized between the HOTP generator
            (client) and the HOTP validator (server).
    :type C: bytes
    :param Mode: The algorithm to use when generating the HMAC value
    :type Mode: hashlib.sha1, hashlib.sha256, hashlib.sha512, or hashlib.md5
    :return: HMAC result. If HMAC-SHA-1, result is 160-bits (20-bytes) long.
    :rtype: bytes
    """
    return hmac.new(K, C, Mode).digest()