Exemplo n.º 1
0
def calculate_card_challenge_SCP03(data, key):
    '''
    Calculate the card challenge in case of pseudo ramdom

    :param data (str): Data uses to calculate card challenge.
    :param key (str) : The Secure Channel Message Authentication Code Key.

    :returns: (tuple): tuple containing:
            - class:`ErrorStatus` with error status ERROR_STATUS_SUCCESS if no error occurs, otherwise error code and error message are contained in the class :class:`ErrorStatus`.
            - The card challenge (str) if no error occurs, None otherwize.
    '''
    logger.log_start("calculate_card_challenge_SCP03")

    logger.log_debug(" Calculate card challenge using %s " % data)
    SCP03_CST_DERIVATION_CARD_CHALLENGE = '02'

    # 1. first build the derivation data
    der_data = ''
    der_data = '00 00 00 00 00 00 00 00 00 00 00' + SCP03_CST_DERIVATION_CARD_CHALLENGE
    der_data += '00'

    der_data += '0040'
    der_data += '01'

    der_data += data
    # 2. calculate cryptogram
    cryptogram = __SCP03_KDF_CounterMode__(der_data, key, 0x01)

    logger.log_end("calculate_card_challenge_SCP03")

    return cryptogram
Exemplo n.º 2
0
def calculate_host_cryptogram_SCP03(cardChallenge, hostChallenge,
                                    session_mac_key):

    # padd data if needed
    logger.log_start("calculate_host_cryptogram_SCP03")

    SCP03_CST_DERIVATION_HOST_CRYPTO = '01'

    data = hostChallenge + cardChallenge

    # 1. first build the derivation data
    der_data = ''
    der_data = '00 00 00 00 00 00 00 00 00 00 00' + SCP03_CST_DERIVATION_HOST_CRYPTO
    der_data += '00'

    der_data += '0040'
    der_data += '01'

    der_data += data

    logger.log_debug("\tCalculates host cryptogram using %s " % der_data)

    cryptogram = __SCP03_KDF_CounterMode__(der_data, session_mac_key, 0x01)

    logger.log_debug("\tHost cryptogram: %s " % cryptogram)

    logger.log_end("calculate_host_cryptogram_SCP03")

    return cryptogram
Exemplo n.º 3
0
def calculate_card_cryptogram_SCP03(cardChallenge, hostChallenge,
                                    session_mac_key):
    '''
    Calculates the card cryptogram for SCP03.
    
    :param cardChallenge (str): The card challenge.
    :param hostChallenge (str): The host challenge.
    :param key (str) : The Secure Channel Message Authentication Code Key.

    :returns: str: The card cryptogram if no error occurs, None otherwize.
    

    '''
    SCP03_CST_DERIVATION_CARD_CRYPTO = '00'
    logger.log_start("calculate_card_cryptogram_SCP03")

    data = hostChallenge + cardChallenge

    # 1. first build the derivation data
    der_data = ''
    der_data = '00 00 00 00 00 00 00 00 00 00 00' + SCP03_CST_DERIVATION_CARD_CRYPTO
    der_data += '00'

    der_data += '0040'
    der_data += '01'

    der_data += data

    logger.log_debug("\tCalculates card cryptogram using %s " % der_data)

    # 2. calculate cryptogram
    cryptogram = __SCP03_KDF_CounterMode__(der_data, session_mac_key, 0x01)

    logger.log_debug("\tCard cryptogram: %s " % cryptogram)

    logger.log_end("calculate_card_cryptogram_SCP03")

    return cryptogram

    # padd data if needed
    data = crypto.ISO_9797_M2_Padding(data, 8)

    logger.log_debug("\tData padded: %s " % data)

    #calculate the cryptogram
    cryptogram = crypto.MAC33(data, session_enc_key, crypto.ICV_NULL_8)

    logger.log_debug("\tCard cryptogram: %s " % cryptogram)

    logger.log_end("calculate_card_cryptogram_SCP02")

    return cryptogram
Exemplo n.º 4
0
def calculate_host_cryptogram_SCP02(sequenceCounter, cardChallenge,
                                    hostChallenge, session_enc_key):

    # padd data if needed
    logger.log_start("calculate_host_cryptogram_SCP02")

    data = sequenceCounter + cardChallenge + hostChallenge

    logger.log_debug(" Calculates host cryptogram using %s " % data)

    data = crypto.ISO_9797_M2_Padding(data, 8)

    cryptogram = crypto.MAC33(data, session_enc_key, crypto.ICV_NULL_8)

    logger.log_debug("host cryptogram: %s " % cryptogram)

    logger.log_end("calculate_host_cryptogram_SCP02")

    return cryptogram
Exemplo n.º 5
0
def calculate_card_challenge_SCP02(data, key):
    '''
    Calculate the card challenge in case of pseudo ramdom

    :param data (str): Data uses to calculate card challenge.
    :param key (str) : The Secure Channel Message Authentication Code Key.

    :returns: (tuple): tuple containing:
            - class:`ErrorStatus` with error status ERROR_STATUS_SUCCESS if no error occurs, otherwise error code and error message are contained in the class :class:`ErrorStatus`.
            - The card challenge (str) if no error occurs, None otherwize.
    '''
    logger.log_start("calculate_card_challenge_SCP02")

    logger.log_debug(" Calculate card challenge using %s " % data)

    error_status, challenge = compute_mac(data, key, crypto.ICV_NULL_8)

    logger.log_end("calculate_card_challenge_SCP02", error_status.status)

    # card challenge is the 6 first bytes of the MAC
    return challenge[0:6 * 2]
Exemplo n.º 6
0
def calculate_card_cryptogram_SCP02(sequenceCounter, cardChallenge,
                                    hostChallenge, session_enc_key):
    '''
    Calculates the card cryptogram for SCP02.
    
    :param sequenceCounter (str): The sequence counter.
    :param cardChallenge (str): The card challenge.
    :param hostChallenge (str): The host challenge.
    :param session_enc_key (str) : The Session Encryption Key for calculating the card cryptogram.

    :returns: (tuple): tuple containing:
            - class:`ErrorStatus` with error status ERROR_STATUS_SUCCESS if no error occurs, otherwise error code and error message are contained in the class :class:`ErrorStatus`.
            - The card cryptogram (str) if no error occurs, None otherwize.
    

    '''

    logger.log_start("calculate_card_cryptogram_SCP02")

    data = hostChallenge + sequenceCounter + cardChallenge

    logger.log_debug("\tCalculates card cryptogram using %s " % data)

    # padd data if needed
    data = crypto.ISO_9797_M2_Padding(data, 8)

    logger.log_debug("\tData padded: %s " % data)

    #calculate the cryptogram
    cryptogram = crypto.MAC33(data, session_enc_key, crypto.ICV_NULL_8)

    logger.log_debug("\tCard cryptogram: %s " % cryptogram)

    logger.log_end("calculate_card_cryptogram_SCP02")

    return cryptogram