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

Release notes

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-20180728.tar.gz (231.7 kB view details)

Uploaded Source

Built Distributions

cryptoauthlib-20180728-cp37-cp37m-win_amd64.whl (77.4 kB view details)

Uploaded CPython 3.7m Windows x86-64

cryptoauthlib-20180728-cp37-cp37m-win32.whl (67.0 kB view details)

Uploaded CPython 3.7m Windows x86

cryptoauthlib-20180728-cp37-cp37m-macosx_10_6_intel.whl (80.8 kB view details)

Uploaded CPython 3.7m macOS 10.6+ intel

cryptoauthlib-20180728-cp36-cp36m-win_amd64.whl (77.4 kB view details)

Uploaded CPython 3.6m Windows x86-64

cryptoauthlib-20180728-cp36-cp36m-win32.whl (67.0 kB view details)

Uploaded CPython 3.6m Windows x86

cryptoauthlib-20180728-cp36-cp36m-macosx_10_6_intel.whl (80.8 kB view details)

Uploaded CPython 3.6m macOS 10.6+ intel

cryptoauthlib-20180728-cp35-cp35m-win_amd64.whl (77.4 kB view details)

Uploaded CPython 3.5m Windows x86-64

cryptoauthlib-20180728-cp35-cp35m-win32.whl (67.0 kB view details)

Uploaded CPython 3.5m Windows x86

cryptoauthlib-20180728-cp35-cp35m-macosx_10_6_intel.whl (80.8 kB view details)

Uploaded CPython 3.5m macOS 10.6+ intel

cryptoauthlib-20180728-cp27-cp27m-win_amd64.whl (77.4 kB view details)

Uploaded CPython 2.7m Windows x86-64

cryptoauthlib-20180728-cp27-cp27m-win32.whl (67.1 kB view details)

Uploaded CPython 2.7m Windows x86

cryptoauthlib-20180728-cp27-cp27m-macosx_10_6_intel.whl (80.8 kB view details)

Uploaded CPython 2.7m macOS 10.6+ intel

File details

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

File metadata

  • Download URL: cryptoauthlib-20180728.tar.gz
  • Upload date:
  • Size: 231.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20180728.tar.gz
Algorithm Hash digest
SHA256 1d04d8ed4ee265d73d1ec15d5ff4e2dfc0fb3f6f6eea4ec17bd65f6355c047b8
MD5 20b4a401059b47e2884b77315072c329
BLAKE2b-256 2a6a0b6f99da5451d1fd0c8ba4eb6553c2b27e61e961983395f5598ffbceca20

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20180728-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 77.4 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for cryptoauthlib-20180728-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 20be665d5f9891f00cc430031206b0efa7ee8e9281290039ae7069f556e1f856
MD5 6884fe4d71ebeabdaa58b2ae72b6e4d0
BLAKE2b-256 2559833df88cb6fcda0af35aa659bb5bcafad08a5e58a2adbf9ae2a406beb741

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20180728-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 67.0 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for cryptoauthlib-20180728-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 b73373410449e2cc31ab5e8ec41aadc75640d99e57f736334e74310687f6b670
MD5 9b72e05ed16fabb9e6090dcb33c21b3e
BLAKE2b-256 c80df7874c36176a90f65d94638ca0f00256bc0753e9b7893c726810185bbaf8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20180728-cp37-cp37m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 80.8 kB
  • Tags: CPython 3.7m, macOS 10.6+ intel
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20180728-cp37-cp37m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 00493f4c02647d48bc5f74e0ea3874fda66c0d1869c37bdfff02f91f4f452b70
MD5 d65118dcf978aadde305b7533863b45d
BLAKE2b-256 fb23abaa27adbb4e9e949235bb4d66f6dc3cf3dee5d50fdc4ab7f467a103e128

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20180728-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 77.4 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6

File hashes

Hashes for cryptoauthlib-20180728-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 e71837d88b95b008fd1008670d76f8a0a7df069e6f69fc131479db428ff9f6e4
MD5 11c5b4487810a45e11878608ec41ea36
BLAKE2b-256 0dba752925a9f3da9fc151e95344f7fc73a56f9473089f8847c51bc1396e7161

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20180728-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 67.0 kB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6

File hashes

Hashes for cryptoauthlib-20180728-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 40a0316d2b951b2827657c7ea0294dbcb16ce3040074779f396796c17f133569
MD5 52ed542d85671a5b88e073e453454000
BLAKE2b-256 84ef66857a428c92e19622f2b0c2f67f5a2c4004dabe9127b9e6f126df0f960e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20180728-cp36-cp36m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 80.8 kB
  • Tags: CPython 3.6m, macOS 10.6+ intel
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20180728-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 0b9a4d8ec534474dafef444422697d4df268632b84abe63e3889321a314567fd
MD5 50a7738a60735c4456d442af33121979
BLAKE2b-256 0ceb30baa1a977ff9b77bac01bc681cdd5be26462e30b537305c80d03b91e176

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20180728-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 77.4 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.5.3

File hashes

Hashes for cryptoauthlib-20180728-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 bb0d2c8a321e7c7de6649cad9e0a6acb864c19945f05c78f8e0815cbc461f87b
MD5 197f9261d3be8233d0f848eed6c6e456
BLAKE2b-256 0c41c53f779dae8d532c846b6fffe5e4109772faa9d9ade1666c981b6006fd3b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20180728-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 67.0 kB
  • Tags: CPython 3.5m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.5.3

File hashes

Hashes for cryptoauthlib-20180728-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 243a9c1fe93d9eeb10f97d2870d7877caf4f5454f2f9d2cb7e3ea0a6b514f266
MD5 dd80af9b5bf46201ca06fc1211c41aa4
BLAKE2b-256 006c1c734af6bfdd051008e52c83fb04757b65ea7c8cc02147b3d94797be12b0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20180728-cp35-cp35m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 80.8 kB
  • Tags: CPython 3.5m, macOS 10.6+ intel
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20180728-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 743a209e60f507e8d9737e044a5a9f52388e7da5c04df987f9008d13b2fb536d
MD5 cc73acbf20cf7c3b2ab4fa831ab9f2ef
BLAKE2b-256 15e889195d769bf370e3baf839c9b49a72172a7d8187ffc78ff2516421bf2598

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20180728-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 77.4 kB
  • Tags: CPython 2.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20180728-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 e8d856dd9610a4c248168b5c673a2ed4b437c510b9848d322028017d70c6dee1
MD5 55260d11cd3918db5c9984034ef7e6f4
BLAKE2b-256 bc7263524aea003666771e408bb28d3987a04487fcda6c1a6ae82c78deaecdba

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20180728-cp27-cp27m-win32.whl
  • Upload date:
  • Size: 67.1 kB
  • Tags: CPython 2.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20180728-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 6b7ba08bcb38e0e8d8fd6916683bc29eb41c0f7312be351195a29fa01600bd8f
MD5 f7552384810f72ce4b846291c11568fa
BLAKE2b-256 4af4b3ad0889a4954f0cb98e163b2a40e4f12113c8547750e4f1ca1be2368c2e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20180728-cp27-cp27m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 80.8 kB
  • Tags: CPython 2.7m, macOS 10.6+ intel
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20180728-cp27-cp27m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 6bf3af038e2a8fe138fda52e764c77d1577dbd2b615ba01bd34fcc0b360b849b
MD5 fcd3b3120fe20199b4d3fcab72739cfb
BLAKE2b-256 bdbd657f53c2650c81b75bdb60cc683c3a557562deb5ada2179b91269b7002ee

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