Skip to main content

Python CryptoAuthLib module

Introduction

This module provides a thin python ctypes layer to evaluate the cryptoauthlib interface to Microchip CryptoAuthentication devices.

Code Examples

Code examples for python are available on github as part of CryptoAuthTools under the python/examples directory

Installation

CryptoAuthLib python module can be installed through Python's pip tool:

    pip install cryptoauthlib

To upgrade your installation when new releases are made:

    pip install -U cryptoauthlib

If you ever need to remove your installation:

    pip uninstall cryptoauthlib

What 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: Link

Supported hardware

Supported devices

The family of devices supported currently are:

Using cryptoauthlib python module

The following is a 'C' code made using cryptoauthlib 'C' library.

#include "cryptoauthlib.h"

void main()
{
    ATCA_STATUS status;
    uint8_t revision[4];
    uint8_t randomnum[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:

from cryptoauthlib import *

ATCA_SUCCESS = 0x00
revision = bytearray(4)
randomnum = bytearray(32)

# Locate and load the compiled library
load_cryptoauthlib()

assert ATCA_SUCCESS == atcab_init(cfg_ateccx08a_kithid_default())

assert ATCA_SUCCESS == atcab_info(revision)
print(''.join(['%02X ' % x for x in revision]))

assert ATCA_SUCCESS == atcab_random(randomnum)
print(''.join(['%02X ' % x for x in randomnum]))

In the above python code, "import cryptoauthlib" imports the python module. load_cryptoauthlib() function loads the ompiled 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 Summary

Step I: Import the module

from cryptoauthlib import *

Step II: Initilize the module

load_cryptoauthlib()

assert ATCA_SUCCESS == atcab_init(cfg_ateccx08a_kithid_default())

Step III: Use Cryptoauthlib APIs

Call library APIs of your choice

Code portability

Microchip'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 documentation

help() command

All 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 code

dir() command

The 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 Examples

Code examples for python are available on github as part of CryptoAuthTools under the python/examples directory

Tests

Module tests can be located in the python/tests of the main cryptoauthlib repository. The README.md has 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 notes

11/22/2019

  • Patches for CVE-2019-16128 & CVE-2019-16129: Ensure reported packet length is valid for the packet being processed.
  • Improvement to encrypted read operations to allow supply of a host nonce (prevent replay of a read sequence to the host). Default API is changed but can be reverted by setting the option ATCA_USE_CONSTANT_HOST_NONCE
  • Added Azure compatible TNGTLS and TNGLORA certificates. Use the TNG client API to retrieve the proper certificate based on the device.
  • Misc Python updates (updated APIs for encrypted reads to match the C-API change) atcacert_cert_element_t now initializes properly

08/30/2019

  • Added big-endian architecture support
  • Fixes to atcah_gen_dig() and atcah_nonce()

05/17/2019

  • Added support for TNG devices (cert transforms, new API)
  • atcab_write_pub_key() now works when the data zone is unlocked

03/04/2019

  • mbed TLS wrapper added
  • Minor bug fixes

01/25/2019

  • Python JWT support
  • Python configuration structures added
  • Restructure of secure boot app

01/04/2019

  • Added GCM functions
  • Split AES modes into separate files
  • Bug fix in SWI START driver

10/25/2018

  • Added basic certificate functions to the python wrapper.
  • Added Espressif ESP32 I2C driver.
  • Made generic Atmel START drivers to support most MCUs in START.
  • Added AES-CTR mode functions.
  • Python wrapper functions now return single values with AtcaReference.
  • Added mutex support to HAL and better support for freeRTOS.

08/17/2018

  • Better support for multiple kit protocol devices

07/25/2018

  • Clean up python wrapper

07/18/2018

  • Added ATCA_NO_HEAP define to remove use of malloc/free.
  • Moved PEM functions to their own file in atcacert.
  • Added wake retry to accomodate power on self test delay.
  • Added ca_cert_def member to atcacert_def_s so cert chains can be traversed as a linked list.

03/29/2018

  • Added support for response polling by default, which will make commands return faster (define ATCA_NO_POLL to use old delay method).
  • Removed atcatls related files as they were of limited value.
  • Test framework generates a prompt before locking test configuration.
  • Test framework puts device to sleep between tests.
  • Fixed mode parameter issue in atcah_gen_key_msg().
  • ATECC608A health test error code added.

01/15/2018

  • Added AES-128 CBC implementation using AES command
  • Added AES-128 CMAC implementation using AES command

11/22/2017

  • Added support for FLEXCOM6 on SAMG55 driver

11/17/2017

  • Added library support for the ATECC608A device
  • Added support for Counter command
  • atca_basic functions and tests now split into multiple files based on command
  • Added support for multiple base64 encoding rules
  • Added support for JSON Web Tokens (jwt)
  • Fixed atcab_write_enc() function to encrypt the data even when the device is unlocked
  • Fixed atcab_base64encode_() for the extra newline
  • Updated atcab_ecdh_enc() to work more consistently

07/01/2017

  • Removed assumption of SN[0:1]=0123, SN[8]=EE. SN now needs to be passed in for functions in atca_host and atca_basic functions will now read the config zone for the SN if needed.
  • Renamed atcab_gendig_host() to atcab_gendig() since it's not a host function. Removed original atcab_gendig(), which had limited scope.
  • Fixed atcah_hmac() for host side HMAC calculations. Added atcab_hmac().
  • Removed unnecessary ATCADeviceType parameters from some atca_basic functions.
  • Added atcacert_create_csr() to create a signed CSR.
  • New HAL implementation for Kit protocol over HID on Linux. Please see the Incorporating CryptoAuthLib in a Linux project using USB HID devices section in this file for more information.
  • Added atcacert_write_cert() for writing certificates to the device.
  • Added support for dynamic length certificate serial numbers in atcacert.
  • Added atcab_write() for lower level write commands.
  • Fixed atcah_write_auth_mac(), which had wrong OpCode.
  • Added atcab_verify() command for lower level verify commands.
  • Added atcab_verify_stored() for verifying data with a stored public key.
  • Removed atcab_write_bytes_slot(). Use atcab_write_bytes_zone() instead.
  • Modified atcab_write_bytes_zone() and atcab_read_bytes_zone() to specify a slot
  • Added atcab_verify_validate() and atcab_verify_invalidate()
  • Improvements to host functions to handle more cases.
  • Added atcab_updateextra(), atcab_derive_key()
  • Added support for more certificate formats.
  • Added general purpose hardware SHA256 functions. See atcab_hw_sha2_256().
  • Removed device specific config read/write. Generic now handles both.
  • Removed unnecessary response parameter from lock commands.
  • Enhanced and added unit tests.
  • Encrypted read and write functions now handle keys with SlotConfig.NoMac set
  • atcab_cmp_config_zone() handles all devices now.
  • Fixed some edge cases in atcab_read_bytes_zone().
  • Updated atSHA() to work with all devices.
  • Fixed atcacert_get_device_locs() when using stored sn.

01/08/2016

  • New HAL implementations for
    • Single Wire interface for SAMD21 / SAMR21
    • SAMV71 I2C HAL implementation
    • XMega A3Bu HAL implementation
  • Added atcab_version() method to return current version string of libary to application
  • New Bus and Discovery API
    • returns a list of ATCA device configurations for each CryptoAuth device found
    • currently implemented on SAMD21/R21 I2C, SAMV71
    • additional discovery implementations to come
  • TLS APIs solidified and documented
  • Added missing doxygen documentation for some CryptoAuthLib methods
  • Stubs for HAL SPI removed as they are unused for SHA204A and ECC508A support
  • bug fixes
  • updated atcab_sha() to accept a variable length message that is > 64 bytes and not a multiple of 64 bytes (the SHA block size).
  • refactored Cert I/O and Cert Data tests to be smaller
  • 'uncrustify' source formatting
  • published on GitHub

9/19/2015

  • Kit protocol over HID on Windows
  • Kit protocol over CDC on Linux
  • TLS integration with ATECC508A
  • Certificate I/O and reconstruction
  • New SHA2 implementation
  • Major update to API docs, Doxygen files found in cryptoauthlib/docs
  • load cryptoauthlib/docs/index.html with your browser

Metadata

Release files for cryptoauthlib 20191122

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cryptoauthlib 20191122
File Size Uploaded
cryptoauthlib-20191122.tar.gz 270.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for cryptoauthlib 20191122
File
cryptoauthlib-20191122-cp38-cp38-macosx_10_9_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.9+ x86-64 Details
cryptoauthlib-20191122-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
cryptoauthlib-20191122-cp37-cp37m-win32.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-32 Details
cryptoauthlib-20191122-cp37-cp37m-macosx_10_6_intel.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.6+ Intel (x86-64, i386) Details
cryptoauthlib-20191122-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
cryptoauthlib-20191122-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details
cryptoauthlib-20191122-cp36-cp36m-macosx_10_6_intel.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.6+ Intel (x86-64, i386) Details
cryptoauthlib-20191122-cp35-cp35m-win_amd64.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-64 Details
cryptoauthlib-20191122-cp35-cp35m-win32.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-32 Details
cryptoauthlib-20191122-cp35-cp35m-macosx_10_6_intel.whl CPython 3.5 CPython 3.5 pymalloc macOS 10.6+ Intel (x86-64, i386) Details
cryptoauthlib-20191122-cp27-cp27m-win_amd64.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-64 Details
cryptoauthlib-20191122-cp27-cp27m-win32.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-32 Details
cryptoauthlib-20191122-cp27-cp27m-macosx_10_6_intel.whl CPython 2.7 CPython 2.7 pymalloc macOS 10.6+ Intel (x86-64, i386) Details

Total release size: 1.6 MB

Release files / cryptoauthlib-20191122.tar.gz

Download URL cryptoauthlib-20191122.tar.gz
Size 270.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4e8568400371769e462d00b7231382fc712fe6f8506ba023cf528390f812e389
BLAKE2b-256 checksum
How to use checksums
e2a5d95c2951bbfd6dd6195e5a411cbf323ed324f446785991d5b6582535be6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/2.7.17

Release files / cryptoauthlib-20191122-cp38-cp38-macosx_10_9_x86_64.whl

Download URL cryptoauthlib-20191122-cp38-cp38-macosx_10_9_x86_64.whl
Size 109.1 kB
Tags CPython 3.8 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
361e2483913dd4a122b695c68d65a0369b02f349790df5f4977e4c6823eab430
BLAKE2b-256 checksum
How to use checksums
a4a0896dec8075ebe0c2e70431ca99f6f7d739483ec195175f521938758cd8c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/2.7.17

Release files / cryptoauthlib-20191122-cp37-cp37m-win_amd64.whl

Download URL cryptoauthlib-20191122-cp37-cp37m-win_amd64.whl
Size 104.7 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
ffc171e8cc12f80252ac6cd517a928b12a4c434ec690f6913399451d6b6258ef
BLAKE2b-256 checksum
How to use checksums
c0856410f1ca08c43938466740a3208a99bc47589ed44d067c14524e78092c73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.5

Release files / cryptoauthlib-20191122-cp37-cp37m-win32.whl

Download URL cryptoauthlib-20191122-cp37-cp37m-win32.whl
Size 93.7 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
f5cd3bf4897049f945a47054f916a86e9bd8765bd4e5a617d91381036fb55581
BLAKE2b-256 checksum
How to use checksums
10a934f562ce6e693ff00113af477290147e6c361e02988be8a95d8251f24acc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.5

Release files / cryptoauthlib-20191122-cp37-cp37m-macosx_10_6_intel.whl

Download URL cryptoauthlib-20191122-cp37-cp37m-macosx_10_6_intel.whl
Size 109.1 kB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.6+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
092db0d7277727960384996a5dd3c293789301f75d25dd5239d96f6799643f01
BLAKE2b-256 checksum
How to use checksums
38baa6b2ec62921366e38b1ea4806b937fef486e95f5f44119d07d7501c62bab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/2.7.17

Release files / cryptoauthlib-20191122-cp36-cp36m-win_amd64.whl

Download URL cryptoauthlib-20191122-cp36-cp36m-win_amd64.whl
Size 104.7 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
99f9c279313c1ae2f576f29451463393ae3d50566ba557d09dcd583f03a4252f
BLAKE2b-256 checksum
How to use checksums
b54b7b464138d51e46564b686e62d61c9d27ae1f824a6806305113d7d7b70df3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.6.8

Release files / cryptoauthlib-20191122-cp36-cp36m-win32.whl

Download URL cryptoauthlib-20191122-cp36-cp36m-win32.whl
Size 93.7 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
95002aa77a662bd724a5995b5be37285ef2f9293e6efc471bc23be7428ecf484
BLAKE2b-256 checksum
How to use checksums
da2140538469cefd15898d9b67417bcf08c13e4d233adf9285e292aa2200fdd5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.6.8

Release files / cryptoauthlib-20191122-cp36-cp36m-macosx_10_6_intel.whl

Download URL cryptoauthlib-20191122-cp36-cp36m-macosx_10_6_intel.whl
Size 109.1 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.6+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
3469df90d6ba091e073ed4107de64b97977d4635887c21007962be7aacd49755
BLAKE2b-256 checksum
How to use checksums
cb99dbebebe7d1b9b259bfe9bdfbd0545eff176d2a1a68738fa38f8b9db00e75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/2.7.17

Release files / cryptoauthlib-20191122-cp35-cp35m-win_amd64.whl

Download URL cryptoauthlib-20191122-cp35-cp35m-win_amd64.whl
Size 104.7 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
fffa5b6599814337bc46cac9e9b5807c4f9f1f8dd39fe69053f2bf0a0457d84e
BLAKE2b-256 checksum
How to use checksums
cc3d97c0e60493cf2378ee3e4b4f05188bf6c0d39bb3d09fb23df9ac8686a159
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.5.4

Release files / cryptoauthlib-20191122-cp35-cp35m-win32.whl

Download URL cryptoauthlib-20191122-cp35-cp35m-win32.whl
Size 93.7 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
80c805d102baaae04f475903bb61324935668be3f6d634f9fb0145e6c60a877d
BLAKE2b-256 checksum
How to use checksums
122606ec11b4452f96748142164bd6ad85a902b792eea7424b6e1711e0e30165
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.5.4

Release files / cryptoauthlib-20191122-cp35-cp35m-macosx_10_6_intel.whl

Download URL cryptoauthlib-20191122-cp35-cp35m-macosx_10_6_intel.whl
Size 109.1 kB
Tags CPython 3.5 CPython 3.5 pymalloc macOS 10.6+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
6221677a92cbf540b35f33cd84352a874f96731e5e2118c1c251cdef08528a7d
BLAKE2b-256 checksum
How to use checksums
0e913c326198583b1932cc12e4dbeedf36f2bc691c60dee10ad48d08bd7d062a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/2.7.17

Release files / cryptoauthlib-20191122-cp27-cp27m-win_amd64.whl

Download URL cryptoauthlib-20191122-cp27-cp27m-win_amd64.whl
Size 104.7 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
79cb7211817c335a86d96aa8499c6f70307335c41e2fe1b17c89b3f7cf660924
BLAKE2b-256 checksum
How to use checksums
994783f2ee23ec408d87dc45ebfeffaa57ad36c49d71d7fd198d358d1e17ea92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/2.7.17

Release files / cryptoauthlib-20191122-cp27-cp27m-win32.whl

Download URL cryptoauthlib-20191122-cp27-cp27m-win32.whl
Size 93.7 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
26cbdc66e5cba477d4b89186fcd90d002c850a5389b78123e0949d2d8567d0d8
BLAKE2b-256 checksum
How to use checksums
d3178ccbd99621ef7efdb65fb18acfcd7c8247c8dc17c8fcf63685c0bf6b5842
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/2.7.17

Release files / cryptoauthlib-20191122-cp27-cp27m-macosx_10_6_intel.whl

Download URL cryptoauthlib-20191122-cp27-cp27m-macosx_10_6_intel.whl
Size 109.1 kB
Tags CPython 2.7 CPython 2.7 pymalloc macOS 10.6+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
31b14e57ec05abbb7d8bd3737c2eedf9b52163016a870fea5f51cfad44e8b9d6
BLAKE2b-256 checksum
How to use checksums
d3f86319a6fe123c9868ec5122752e4d23272733df96555562ee8be9cbc62e0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/2.7.17

Release history Release notifications | RSS feed

This release

20191122 This release

14 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page