How to use the cryptoauthlib.constant.ATCA_CMD_SIZE_MIN 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 / cryptoauthlib / packet.py View on Github external
def __init__(
        self,
        txsize=ATCA.ATCA_CMD_SIZE_MIN,
        opcode=0,
        param1=0,
        param2=0,
        request_data=b'',
        response_data=b'',
        device="ATECC508A"
    ):
        self.txsize = txsize
        self.opcode = opcode
        self.param1 = param1
        self.param2 = param2
        self.device = device
        self._request_data = request_data
        self._response_data = response_data or bytearray(ATCA.ATCA_CMD_SIZE_MAX)
github dmazzella / ucryptoauthlib / cryptoauthlib / basic.py View on Github external
raise ATCA_EXCEPTIONS.BadArgumentError()

        txsize = 0
        cmd_mode = mode & ATCA_CONSTANTS.SHA_MODE_MASK
        if cmd_mode in (
            ATCA_CONSTANTS.SHA_MODE_SHA256_START,
            ATCA_CONSTANTS.SHA_MODE_HMAC_START,
            ATCA_CONSTANTS.SHA_MODE_SHA256_PUBLIC
        ):
            txsize = ATCA_CONSTANTS.ATCA_CMD_SIZE_MIN
        elif cmd_mode in (
            ATCA_CONSTANTS.SHA_MODE_SHA256_UPDATE,
            ATCA_CONSTANTS.SHA_MODE_SHA256_END,
            ATCA_CONSTANTS.SHA_MODE_HMAC_END
        ):
            txsize = ATCA_CONSTANTS.ATCA_CMD_SIZE_MIN + len(data)
        else:
            raise ATCA_EXCEPTIONS.BadArgumentError()

        packet = ATCAPacket(
            txsize=txsize,
            opcode=ATCA_CONSTANTS.ATCA_SHA,
            param1=mode,
            param2=len(data) if not isinstance(key_slot, int) else key_slot,
            request_data=data
        )
        self.execute(packet)
        return packet
github dmazzella / ucryptoauthlib / cryptoauthlib / basic.py View on Github external
txsize += ATCA_CONSTANTS.ATCA_BLOCK_SIZE
            # Only 32-byte writes can have a MAC
            if isinstance(mac, _BYTES_LIKE_OBJECT):
                data[32:64] = mac
                txsize += ATCA_CONSTANTS.WRITE_MAC_SIZE
        else:
            # 4-byte write
            data[0:4] = value
            txsize += ATCA_CONSTANTS.ATCA_WORD_SIZE

        packet = ATCAPacket(
            txsize=txsize,
            opcode=ATCA_CONSTANTS.ATCA_WRITE,
            param1=zone,
            param2=address,
            request_data=data[:txsize-ATCA_CONSTANTS.ATCA_CMD_SIZE_MIN]
        )
        self.execute(packet)
        return packet
github dmazzella / ucryptoauthlib / cryptoauthlib / basic.py View on Github external
def atcab_write(self, zone, address, value=None, mac=None):
        if not isinstance(value, _BYTES_LIKE_OBJECT):
            raise ATCA_EXCEPTIONS.BadArgumentError()

        txsize = ATCA_CONSTANTS.ATCA_CMD_SIZE_MIN
        data = bytearray(64)
        if zone & ATCA_CONSTANTS.ATCA_ZONE_READWRITE_32:
            # 32-byte write
            data[0:32] = value
            txsize += ATCA_CONSTANTS.ATCA_BLOCK_SIZE
            # Only 32-byte writes can have a MAC
            if isinstance(mac, _BYTES_LIKE_OBJECT):
                data[32:64] = mac
                txsize += ATCA_CONSTANTS.WRITE_MAC_SIZE
        else:
            # 4-byte write
            data[0:4] = value
            txsize += ATCA_CONSTANTS.ATCA_WORD_SIZE

        packet = ATCAPacket(
            txsize=txsize,