How to use the cryptoauthlib.constant.NONCE_MODE_PASSTHROUGH function in cryptoauthlib

To help you get started, we’ve selected a few cryptoauthlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dmazzella / ucryptoauthlib / tests / ateccX08a / tests_nonce.py View on Github external
def run(device=None):
    if not device:
        raise ValueError("device")

    numbers = b'\x00' * 32

    packet = device.atcab_nonce_base(NONCE_MODE_SEED_UPDATE, numbers=numbers)
    log.debug("atcab_nonce_base NONCE_MODE_SEED_UPDATE: %s", hexlify(packet.response_data))

    packet = device.atcab_nonce_base(NONCE_MODE_NO_SEED_UPDATE, numbers=numbers)
    log.debug("atcab_nonce_base NONCE_MODE_NO_SEED_UPDATE: %s", hexlify(packet.response_data))

    packet = device.atcab_nonce_base(NONCE_MODE_PASSTHROUGH, numbers=numbers)
    log.debug("atcab_nonce_base NONCE_MODE_PASSTHROUGH: %s", hexlify(packet.response_data))

    packet = device.atcab_nonce(numbers=numbers)
    log.debug("atcab_nonce: %s", hexlify(packet.response_data))

    packet = device.atcab_nonce_load(NONCE_MODE_TARGET_TEMPKEY, numbers=numbers)
    log.debug("atcab_nonce_load NONCE_MODE_TARGET_TEMPKEY: %s", hexlify(packet.response_data))

    packet = device.atcab_nonce_load(NONCE_MODE_TARGET_MSGDIGBUF, numbers=numbers)
    log.debug("atcab_nonce_load NONCE_MODE_TARGET_MSGDIGBUF: %s", hexlify(packet.response_data))

    packet = device.atcab_nonce_load(NONCE_MODE_TARGET_ALTKEYBUF, numbers=numbers)
    log.debug("atcab_nonce_load NONCE_MODE_TARGET_ALTKEYBUF: %s", hexlify(packet.response_data))

    packet = device.atcab_nonce_rand(numbers=numbers)
    log.debug("atcab_nonce_rand: %s", hexlify(packet.response_data))
github dmazzella / ucryptoauthlib / cryptoauthlib / basic.py View on Github external
def atcab_nonce_load(self, target, numbers=None):
        if not isinstance(numbers, _BYTES_LIKE_OBJECT):
            raise ATCA_EXCEPTIONS.BadArgumentError()

        mode = ATCA_CONSTANTS.NONCE_MODE_PASSTHROUGH
        mode = mode | (ATCA_CONSTANTS.NONCE_MODE_TARGET_MASK & target)

        if len(numbers) == 32:
            mode = mode | ATCA_CONSTANTS.NONCE_MODE_INPUT_LEN_32
        elif len(numbers) == 64:
            mode = mode | ATCA_CONSTANTS.NONCE_MODE_INPUT_LEN_64
        else:
            raise ATCA_EXCEPTIONS.BadArgumentError()

        return self.atcab_nonce_base(mode, numbers=numbers)
github dmazzella / ucryptoauthlib / cryptoauthlib / basic.py View on Github external
def atcab_nonce(self, numbers=None):
        return self.atcab_nonce_base(
            ATCA_CONSTANTS.NONCE_MODE_PASSTHROUGH,
            numbers=numbers
        )
github dmazzella / ucryptoauthlib / cryptoauthlib / basic.py View on Github external
def atcab_nonce_base(self, mode, zero=0, numbers=None):
        nonce_mode = mode & ATCA_CONSTANTS.NONCE_MODE_MASK
        if nonce_mode not in (
            ATCA_CONSTANTS.NONCE_MODE_SEED_UPDATE,
            ATCA_CONSTANTS.NONCE_MODE_NO_SEED_UPDATE,
            ATCA_CONSTANTS.NONCE_MODE_PASSTHROUGH
        ):
            raise ATCA_EXCEPTIONS.BadArgumentError()

        if not isinstance(numbers, _BYTES_LIKE_OBJECT):
            raise ATCA_EXCEPTIONS.BadArgumentError()

        txsize = 0
        if nonce_mode in (
            ATCA_CONSTANTS.NONCE_MODE_SEED_UPDATE,
            ATCA_CONSTANTS.NONCE_MODE_NO_SEED_UPDATE
        ):
            txsize = ATCA_CONSTANTS.NONCE_COUNT_SHORT
        elif nonce_mode == ATCA_CONSTANTS.NONCE_MODE_PASSTHROUGH:
            nonce_mode_input = mode & ATCA_CONSTANTS.NONCE_MODE_INPUT_LEN_MASK
            if nonce_mode_input == ATCA_CONSTANTS.NONCE_MODE_INPUT_LEN_64:
                txsize = ATCA_CONSTANTS.NONCE_COUNT_LONG_64