Package: cryptoauthlib
Python CryptoAuthLib moduleIntroductionThis module provides a thin python ctypes layer to evaluate the cryptoauthlib
interface to Microchip CryptoAuthentication devices.Code ExamplesCode examples for python are available on github as part ofCryptoAuthToolsunder thepython/examplesdirectoryInstallationCryptoAuthLib python module can be installed through Python's pip tool:pip install cryptoauthlibTo upgrade your installation when new releases are made:pip install -U cryptoauthlibIf you ever need to remove your installation:pip uninstall cryptoauthlibWhat does python CryptoAuthLib package do?CryptoAuthLib module gives access to most functions available as part of standard cryptoauthlib
(which is written in 'C'). These python functions for the most part are very similar to 'C'
functions. The module in short acts as a wrapper over the 'C' cryptoauth library functions.Microchip cryptoauthlib product page:LinkSupported hardwareAT88CK101CryptoAuthentication SOIC XPRO Starter Kit (DM320109)Supported devicesThe family of devices supported currently are:ATSHA204AATECC108AATECC508AATECC608AUsing cryptoauthlib python moduleThe following is a 'C' code made using cryptoauthlib 'C' library.#include"cryptoauthlib.h"voidmain(){ATCA_STATUSstatus;uint8_trevision[4];uint8_trandomnum[32];status=atcab_init(cfg_ateccx08a_kitcdc_default);if(status!=ATCA_SUCCESS){printf("Error");exit();}status=atcab_info(revision);if(status!=ATCA_SUCCESS){printf("Error");exit();}status=atcab_random(randomnum);if(status!=ATCA_SUCCESS){printf("Error");exit();}}The same code in python would be:fromcryptoauthlibimport*ATCA_SUCCESS=0x00revision=bytearray(4)randomnum=bytearray(32)# Locate and load the compiled libraryload_cryptoauthlib()assertATCA_SUCCESS==atcab_init(cfg_ateccx08a_kithid_default())assertATCA_SUCCESS==atcab_info(revision)print(''.join(['%02X'%xforxinrevision]))assertATCA_SUCCESS==atcab_random(randomnum)print(''.join(['%02X'%xforxinrandomnum]))In the above python code, "import cryptoauthlib" imports the python module. load_cryptoauthlib()
function loads the compiled library. The load_cryptoauthlib() is a function that you will not
see in the 'C' library, this is a python specific utility function and is required for python
scripts to locate and load the compiled library.In SummaryStep I: Import the modulefrom cryptoauthlib import *Step II: Initilize the moduleload_cryptoauthlib()

assert ATCA_SUCCESS == atcab_init(cfg_ateccx08a_kithid_default())Step III: Use Cryptoauthlib APIsCall library APIs of your choiceCode portabilityMicrochip's CryptoAuthentication products can now be evaluated with the power and flexibility of
python. Once the evaluation stage is done the python code can be ported to 'C' code.As seen above the python API maintains a 1 to 1 equivalence to the 'C' API in order to easy the
transition between the two.Cryptoauthlib module API documentationhelp() commandAll of the python function's documentation can be viewed through python's built in help() function.For example, to get the documentation of atcab_info() function:>>> help(cryptoauthlib.atcab_info)
    Help on function atcab_info in module cryptoauthlib.atcab:

    atcab_info(revision)
    Used to get the device revision number. (DevRev)

    Args:
        revision            4-byte bytearray receiving the revision number
                            from the device. (Expects bytearray)

    Returns:
        Status codedir() commandThe dir command without arguments, return the list of names in the current local scope. With an
argument, attempt to return a list of valid attributes for that object. For example
dir(cryptoauthlib) will return all the methods available in the cryptoauthlib module.Code ExamplesCode examples for python are available on github as part ofCryptoAuthToolsunder the
python/examples directoryTestsModule tests can be located in thepython/testsof the main cryptoauthlib repository. TheREADME.mdhas details for how to run the tests. The module tests are not comprehensive for the entire functionality
of cryptoauthlib but rather are meant to test the python module code only against the library to ensure
the interfaces are correct and ctypes structures match the platform.Release notesSeeRelease Notes