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

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

Uploaded Source

Built Distributions

cryptoauthlib-20181027-cp37-cp37m-win_amd64.whl (90.3 kB view details)

Uploaded CPython 3.7m Windows x86-64

cryptoauthlib-20181027-cp37-cp37m-win32.whl (79.6 kB view details)

Uploaded CPython 3.7m Windows x86

cryptoauthlib-20181027-cp37-cp37m-macosx_10_6_intel.whl (94.0 kB view details)

Uploaded CPython 3.7m macOS 10.6+ intel

cryptoauthlib-20181027-cp36-cp36m-win_amd64.whl (90.3 kB view details)

Uploaded CPython 3.6m Windows x86-64

cryptoauthlib-20181027-cp36-cp36m-win32.whl (79.6 kB view details)

Uploaded CPython 3.6m Windows x86

cryptoauthlib-20181027-cp36-cp36m-macosx_10_6_intel.whl (94.0 kB view details)

Uploaded CPython 3.6m macOS 10.6+ intel

cryptoauthlib-20181027-cp35-cp35m-win_amd64.whl (90.3 kB view details)

Uploaded CPython 3.5m Windows x86-64

cryptoauthlib-20181027-cp35-cp35m-win32.whl (79.6 kB view details)

Uploaded CPython 3.5m Windows x86

cryptoauthlib-20181027-cp35-cp35m-macosx_10_6_intel.whl (94.0 kB view details)

Uploaded CPython 3.5m macOS 10.6+ intel

cryptoauthlib-20181027-cp27-cp27m-win_amd64.whl (90.3 kB view details)

Uploaded CPython 2.7m Windows x86-64

cryptoauthlib-20181027-cp27-cp27m-win32.whl (79.7 kB view details)

Uploaded CPython 2.7m Windows x86

cryptoauthlib-20181027-cp27-cp27m-macosx_10_6_intel.whl (94.0 kB view details)

Uploaded CPython 2.7m macOS 10.6+ intel

File details

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

File metadata

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

File hashes

Hashes for cryptoauthlib-20181027.tar.gz
Algorithm Hash digest
SHA256 32c3c026edf171faa39b6719e31b2f17e6eda5dc7114f9069ba77f48d675116e
MD5 8ef7fc9169ea7d7f675b2ba4b280b10f
BLAKE2b-256 d904ac1d220fe18d7d84e2f385d3fe81544eb99aa9a4993250f584385acfe062

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20181027-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 90.3 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.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for cryptoauthlib-20181027-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ffb99c23b862694109cc5cc14ce6c268ae4004b3de225ea4d3043ac00b24b7df
MD5 6d2a9a7664fd14b637b4e3adbf6a095c
BLAKE2b-256 1f9a1ac49b60afb8917ea7a5f9e967ee10c1d673fd775b3feb3f72bbca4db617

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cryptoauthlib-20181027-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 3a7e41645334f47c2c206f8f5a71204ecd3e9a72ea0341c8e5f4c52b3b8e16c1
MD5 199681d205b0966f3311377525c4fa52
BLAKE2b-256 7113ed5ea51cf16d7173852a7d9f57c2408cd9d42f95803cb4292692c1382900

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20181027-cp37-cp37m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 94.0 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.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20181027-cp37-cp37m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 b68a956ef965d8d890494ff18d8e248e54e0b65878921a7f34bb422b089cab77
MD5 bab18ba3b777a47f2af35446d486a562
BLAKE2b-256 952dace22b30ac74cc8f5e0db3a0a429b1c7d339bd823e3a45c2f846705dd625

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20181027-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 90.3 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.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for cryptoauthlib-20181027-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 7b6df523fd3f734347cdafb21ec1dd906dda78ef6b94372ada8d8af2150d0017
MD5 150acae420b14d91608f2ad876a12375
BLAKE2b-256 e3c805492dbf6e51e7bf4147596611f9368d2c47de18c2092e7f31c979c6f57a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cryptoauthlib-20181027-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 e35ae5073f87a6d47e1c6ba13e97843011b0f9a51350e306f3eea6fffb36ffb6
MD5 3118a5a6c5cc61c4a281d99a970d3419
BLAKE2b-256 6492645111080d973cad28a0085e24e72392720aa0752320366a473ec4fbc711

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20181027-cp36-cp36m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 94.0 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.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20181027-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 bdfa34aee1b0c0820fad1f89384bd6bec18f1ada77ee5df8709ae9211afb7095
MD5 624057386682720b94125b7484ee1b7a
BLAKE2b-256 fa04320a846541b924dea907e44ec06c3b1f863ffd83b4abd1e7c915374999b2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20181027-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 90.3 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.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.4

File hashes

Hashes for cryptoauthlib-20181027-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 1af773911959f05b2269835b8967f19a9a7554d453b3829ecb0fe64bc4b9c7a4
MD5 351c725f21d0801be4998a9778610d06
BLAKE2b-256 4402e1c5b666fa1436b27e81e227f4273ecd30ed2cffd339bf2caac75fc52076

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cryptoauthlib-20181027-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 3e910943786f5cd058fe84948a93eb97883a2643577c5c192862699c2578f539
MD5 980cd8221dff862ed163954b3dd2d5ed
BLAKE2b-256 e27215d46aab04ba077f756bfc823c33380cd2062d21b30d2f8a775cf5cf6f9e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20181027-cp35-cp35m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 94.0 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.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20181027-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 e29271a997dded3f27a2e8a2c651f388d5bd5e17c2ac3b402570902d571c29fe
MD5 39c93d99ef8845209bffc4560bb63b3b
BLAKE2b-256 98e4bc46395fdca353ac93f5e250274cdce5903e6921d2ec8502a5f3a37248a3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20181027-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 90.3 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.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20181027-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 b2aa4cdbdc4078b77a0ab846e070d12bfcf3b4d6489155ba5a4b0c4d374e49a7
MD5 22d53f205b9d84910bbd5a4f705cfde2
BLAKE2b-256 d26df8cc4440b667c61acc7a14f936c043b8741c65ee63f2c7c3e6138f9532a1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cryptoauthlib-20181027-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 8db6d81bfd68349b1ced26f54850f8f48328eab9f2b61ccad05ff10c9f52b4f4
MD5 7a279b6cecebdb70a8004d450f59f8ec
BLAKE2b-256 ba3b2c17b75e325fe7c4aabc6471c7b0d58c5abb10ec2a8ab4a2e6597bd8e9fc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cryptoauthlib-20181027-cp27-cp27m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 94.0 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.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for cryptoauthlib-20181027-cp27-cp27m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 99b012d98e085cd4277afdf02aff5085c7f1aae58d7bb7c44bdc33fb7ae743f5
MD5 8e6e0a62297bb638d92db0d348c09a22
BLAKE2b-256 7b0cb84b6306a185269c40d261ee109a06004f7f5aac706b5fd2b9fe5695fd50

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