Skip to main content

Python Wrapper Library for Microchip Security Products

Project description

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cryptoauthlib-20190105.tar.gz (250.6 kB view details)

Uploaded Source

Built Distributions

cryptoauthlib-20190105-cp37-cp37m-win_amd64.whl (92.8 kB view details)

Uploaded CPython 3.7m Windows x86-64

cryptoauthlib-20190105-cp37-cp37m-win32.whl (81.9 kB view details)

Uploaded CPython 3.7m Windows x86

cryptoauthlib-20190105-cp37-cp37m-macosx_10_6_intel.whl (96.8 kB view details)

Uploaded CPython 3.7m macOS 10.6+ intel

cryptoauthlib-20190105-cp36-cp36m-win_amd64.whl (92.8 kB view details)

Uploaded CPython 3.6m Windows x86-64

cryptoauthlib-20190105-cp36-cp36m-win32.whl (81.9 kB view details)

Uploaded CPython 3.6m Windows x86

cryptoauthlib-20190105-cp36-cp36m-macosx_10_6_intel.whl (96.8 kB view details)

Uploaded CPython 3.6m macOS 10.6+ intel

cryptoauthlib-20190105-cp35-cp35m-win_amd64.whl (92.8 kB view details)

Uploaded CPython 3.5m Windows x86-64

cryptoauthlib-20190105-cp35-cp35m-win32.whl (81.9 kB view details)

Uploaded CPython 3.5m Windows x86

cryptoauthlib-20190105-cp35-cp35m-macosx_10_6_intel.whl (96.8 kB view details)

Uploaded CPython 3.5m macOS 10.6+ intel

cryptoauthlib-20190105-cp27-cp27m-win_amd64.whl (92.8 kB view details)

Uploaded CPython 2.7m Windows x86-64

cryptoauthlib-20190105-cp27-cp27m-win32.whl (82.0 kB view details)

Uploaded CPython 2.7m Windows x86

cryptoauthlib-20190105-cp27-cp27m-macosx_10_6_intel.whl (96.8 kB view details)

Uploaded CPython 2.7m macOS 10.6+ intel

File details

Details for the file cryptoauthlib-20190105.tar.gz.

File metadata

  • Download URL: cryptoauthlib-20190105.tar.gz
  • Upload date:
  • Size: 250.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20190105.tar.gz
Algorithm Hash digest
SHA256 da1d45faf327d3328257de5588c42065b235c2eea19b729eb1bd7d6a297918bc
MD5 ac317fa31493d2848ad7b35cbae9ce31
BLAKE2b-256 cff3779e3c01c5592500219fe7300f8095ede130abab027a2ff0158f4834c769

See more details on using hashes here.

File details

Details for the file cryptoauthlib-20190105-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: cryptoauthlib-20190105-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 92.8 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for cryptoauthlib-20190105-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 f8c5f19b1d17eef0167a4e8db0df815aa74e4e1aa8110331aa56a5fc6b25d239
MD5 6cf1ef6fedb4b974e59181c4fc9fd6fb
BLAKE2b-256 fb1003efa56174464bac3662206960c2da4079725d31a592c135e7ce21c2250c

See more details on using hashes here.

File details

Details for the file cryptoauthlib-20190105-cp37-cp37m-win32.whl.

File metadata

  • Download URL: cryptoauthlib-20190105-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 81.9 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for cryptoauthlib-20190105-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 aa7e5a15496f64db49e69c2d0b8d25568d67aa33942d289eeb0a7fc4990bdb18
MD5 e3c85bd1e7140e9ef7d049b62e7a6de8
BLAKE2b-256 fc05253f4718cef9fca34169e5ebc28c6e77f2811e25f3674e5c428cfa87158f

See more details on using hashes here.

File details

Details for the file cryptoauthlib-20190105-cp37-cp37m-macosx_10_6_intel.whl.

File metadata

  • Download URL: cryptoauthlib-20190105-cp37-cp37m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 96.8 kB
  • Tags: CPython 3.7m, macOS 10.6+ intel
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20190105-cp37-cp37m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 10cf65f05131b77d389385cbbc33fd87423b433041551782a9d8e6a0637818f9
MD5 2180c8913a2237a6fbbeb9c9a45c0e58
BLAKE2b-256 45ed3bf211717a7cc381bcd9db087b42e99e3426727be8970de93eefdc20dcc6

See more details on using hashes here.

File details

Details for the file cryptoauthlib-20190105-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: cryptoauthlib-20190105-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 92.8 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for cryptoauthlib-20190105-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 c25580d0ab30c926aab20102465e69dc49b29c803f19f0b6fe525319c22408ba
MD5 f473641ad2b4374626f402d6e9159e26
BLAKE2b-256 50b005e87f2c15cdfd18e25a9f37a9aeb010a6d3456666da56a163ab989daac0

See more details on using hashes here.

File details

Details for the file cryptoauthlib-20190105-cp36-cp36m-win32.whl.

File metadata

  • Download URL: cryptoauthlib-20190105-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 81.9 kB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for cryptoauthlib-20190105-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 fdeb66df982b56f89e9af7f22f8ea04c1eeaee483c6b65f27589ce61e98e78ae
MD5 5c95ad9ccd441c259628614830c5ad0c
BLAKE2b-256 70382a0b58c981f14df8417c2bdd31deb2f7de083a705b8d1988c8bd81b69f8b

See more details on using hashes here.

File details

Details for the file cryptoauthlib-20190105-cp36-cp36m-macosx_10_6_intel.whl.

File metadata

  • Download URL: cryptoauthlib-20190105-cp36-cp36m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 96.8 kB
  • Tags: CPython 3.6m, macOS 10.6+ intel
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20190105-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 4b5ff519f87e394e45bbac0fe62097c924cd528cb79c2b3be247c7e8d0add51a
MD5 0c592d54860510d99bad31afaf91adbf
BLAKE2b-256 e692f2fd3a16989181bd9228fb3692d078d77b9d3adf53fa29396117b240c446

See more details on using hashes here.

File details

Details for the file cryptoauthlib-20190105-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: cryptoauthlib-20190105-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 92.8 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.4

File hashes

Hashes for cryptoauthlib-20190105-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 f8a2d0bc089016b6a5ddd60610be57f6c0515e5a9586bedb63a121e755a40c40
MD5 6e535dbb6b022e4732bbacf069febccc
BLAKE2b-256 74eb8f7c36a8a564602f2bba8c88345a85b9df57bad81f660d422a30fe8d88b1

See more details on using hashes here.

File details

Details for the file cryptoauthlib-20190105-cp35-cp35m-win32.whl.

File metadata

  • Download URL: cryptoauthlib-20190105-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 81.9 kB
  • Tags: CPython 3.5m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.4

File hashes

Hashes for cryptoauthlib-20190105-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 619d3386a0653e19558abe23e2a4d5cb0d643e3e03c7906d2c23ee79d5e8e18b
MD5 e21722b4ef2e55b03d6b7662aa34dc7b
BLAKE2b-256 26c414395a132ef775561610ad7c3cf7a1cf1fb38d96d83a4d43bbaa03730f62

See more details on using hashes here.

File details

Details for the file cryptoauthlib-20190105-cp35-cp35m-macosx_10_6_intel.whl.

File metadata

  • Download URL: cryptoauthlib-20190105-cp35-cp35m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 96.8 kB
  • Tags: CPython 3.5m, macOS 10.6+ intel
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20190105-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 89737715160cc3c025d9e64ce73d32296bdcef9f449c35753acadcc2a709e0ed
MD5 2dd0467b27584c2375bc2c729a3d0341
BLAKE2b-256 1aa5bca310f756e48e44529c75bd74549fec7986808089c91c494c6a8fc43627

See more details on using hashes here.

File details

Details for the file cryptoauthlib-20190105-cp27-cp27m-win_amd64.whl.

File metadata

  • Download URL: cryptoauthlib-20190105-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 92.8 kB
  • Tags: CPython 2.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20190105-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 7c50cd001c480a7625ec4b525cd6151ab62f359a96a643d153f744ec56b7c73c
MD5 0a53881c8892b8448fe878e38f3c6ca3
BLAKE2b-256 b5d97719a14589d90c8367a7427a372c26b14661d6df48276d05e3b066305da0

See more details on using hashes here.

File details

Details for the file cryptoauthlib-20190105-cp27-cp27m-win32.whl.

File metadata

  • Download URL: cryptoauthlib-20190105-cp27-cp27m-win32.whl
  • Upload date:
  • Size: 82.0 kB
  • Tags: CPython 2.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20190105-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 37408e49a8362f65459c97e0ba7532b47c53a25518b3e6ee593b4ef22db9eca0
MD5 a7315e641142f9ba1671a19c87bb698b
BLAKE2b-256 a0a19850ec06f5634832926d16ce253c8509d0b9b8aed8a93cae70fd9e651c4a

See more details on using hashes here.

File details

Details for the file cryptoauthlib-20190105-cp27-cp27m-macosx_10_6_intel.whl.

File metadata

  • Download URL: cryptoauthlib-20190105-cp27-cp27m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 96.8 kB
  • Tags: CPython 2.7m, macOS 10.6+ intel
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20190105-cp27-cp27m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 d813d84a51b6510d838994ac5e68e55d958736e4276fd90bb646b52e28ce061f
MD5 5384e235e2431c99950076299e26591e
BLAKE2b-256 e6f81d3867fdf171bc50a630cbae310c333c3f02fba05dca8f666f34387b814a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page