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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file cryptoauthlib-20180817.tar.gz
.
File metadata
- Download URL: cryptoauthlib-20180817.tar.gz
- Upload date:
- Size: 233.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa0907fc0d2186072cc91905be8ea2493474827155892653695b13cc0292ae00 |
|
MD5 | 46db2808da2a1903df0debe58f9b23f7 |
|
BLAKE2b-256 | f1613ae3376d6a1842d809b7c81bb42c035066e73c329b5dfcd2ab5fc5937af0 |
File details
Details for the file cryptoauthlib-20180817-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: cryptoauthlib-20180817-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 80.5 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.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8570497a0bb9e14b2451b092188eac8e1fe624cde8df0b3db152dbe45cba5cd |
|
MD5 | 40d64c2d0acfcccc6058edc50c21d25a |
|
BLAKE2b-256 | 0ff23a7c4f5783d06a7768b4755092bb5903e0883ce1000c39b5f785167287de |
File details
Details for the file cryptoauthlib-20180817-cp37-cp37m-win32.whl
.
File metadata
- Download URL: cryptoauthlib-20180817-cp37-cp37m-win32.whl
- Upload date:
- Size: 69.8 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.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72422b2a362c69577c0733814c0c5a5dc3f3c159cdf700df780fdb755e737aea |
|
MD5 | aa81d7ad5eebd052ec7fff20e756f1a3 |
|
BLAKE2b-256 | a4bb9519459a4c018de30aa78474afdcaaa3f01262cdd6f174847ba8a2a82786 |
File details
Details for the file cryptoauthlib-20180817-cp37-cp37m-macosx_10_6_intel.whl
.
File metadata
- Download URL: cryptoauthlib-20180817-cp37-cp37m-macosx_10_6_intel.whl
- Upload date:
- Size: 83.7 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.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbd92e80a72e3f3ec8aead3a31f6fc00f70554d687bef5d544ca6b90bb74d99d |
|
MD5 | 88237c8ca6ef5e540c52a08c0efaac54 |
|
BLAKE2b-256 | 6adfce0626039cb20749cf090556dc24f7fbefbefc213097b247aa2260c68982 |
File details
Details for the file cryptoauthlib-20180817-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: cryptoauthlib-20180817-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 80.5 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.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b728e19750f1805ba409af2108c771455105be49ccf46828e76fda6ed21f10b3 |
|
MD5 | e1926b2e7cc9043ece8c40f6c4cd738e |
|
BLAKE2b-256 | 8a42f9852004690583b4300c41e4b31b07a7c4155c1eaa5640670ef32a1a7d7f |
File details
Details for the file cryptoauthlib-20180817-cp36-cp36m-win32.whl
.
File metadata
- Download URL: cryptoauthlib-20180817-cp36-cp36m-win32.whl
- Upload date:
- Size: 69.8 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.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bb6c03e3fe3c15914f7deea4114b98fa0fe9d4134866931b21c48edcb8c5413 |
|
MD5 | 9f5ee6d561edb2bd62287d916917ea13 |
|
BLAKE2b-256 | 3fd8085d89ccb004200668f03797de71447f66ed072b4a95e40e5753ac5f5d06 |
File details
Details for the file cryptoauthlib-20180817-cp36-cp36m-macosx_10_6_intel.whl
.
File metadata
- Download URL: cryptoauthlib-20180817-cp36-cp36m-macosx_10_6_intel.whl
- Upload date:
- Size: 83.7 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.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 662bec887eced0b3d6acf39c4c3ece15718aee3fbee77d4a8ce766ba5a40ec25 |
|
MD5 | 562b20a433a96a08d3bdc95630d9a71d |
|
BLAKE2b-256 | 0826ba860fbb6c29f30fe99a8c9bd0aae0b7507f85b7f6f1c0aaaa9ac13d81ab |
File details
Details for the file cryptoauthlib-20180817-cp35-cp35m-win_amd64.whl
.
File metadata
- Download URL: cryptoauthlib-20180817-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 80.5 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.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.5.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c36d814be2ce63bf758ed5b2d096ffdf0ce7c2e2d038b5b6623b3725b086a30 |
|
MD5 | c1b88e34c5e5612c0e7fc2553237d22a |
|
BLAKE2b-256 | 327e2436e6acb4e069b2b68fbf35554d7b2be0b8c170fb0a161785ea9c9462c3 |
File details
Details for the file cryptoauthlib-20180817-cp35-cp35m-win32.whl
.
File metadata
- Download URL: cryptoauthlib-20180817-cp35-cp35m-win32.whl
- Upload date:
- Size: 69.8 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.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.5.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73615d19291babd0bc2fc99202a803f9dea01574732631cbd4d6496eaf96c67e |
|
MD5 | 6d7d65bedff9ff0b6b3c6536539eb3b4 |
|
BLAKE2b-256 | 1eac0fc8505bacbbce5e2a54202a5bb7f8899d3ad46cee1f594ae2c26c6f82b7 |
File details
Details for the file cryptoauthlib-20180817-cp35-cp35m-macosx_10_6_intel.whl
.
File metadata
- Download URL: cryptoauthlib-20180817-cp35-cp35m-macosx_10_6_intel.whl
- Upload date:
- Size: 83.7 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.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e52508ede51d0aaca995f82d1985bc99acb53a62c282eccab40a49e9efd3d9d |
|
MD5 | ce55a149dea1d5c4c1925f862bcef2bd |
|
BLAKE2b-256 | 06d2f5a38725eef265590aeead986918806a4fed7ab918f13e8a3efdb106b8f7 |
File details
Details for the file cryptoauthlib-20180817-cp27-cp27m-win_amd64.whl
.
File metadata
- Download URL: cryptoauthlib-20180817-cp27-cp27m-win_amd64.whl
- Upload date:
- Size: 80.5 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.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 487cc0f1f51a86ab6341e1a1ef5223eee0a9239a58f3b33c50378f45dfe123db |
|
MD5 | 2df8729f9cdcbeb9803de541c1887779 |
|
BLAKE2b-256 | b73b287bb5f180fbbb2e506d6f0ff01ea26ebafed59a3962a72135b4bd424377 |
File details
Details for the file cryptoauthlib-20180817-cp27-cp27m-win32.whl
.
File metadata
- Download URL: cryptoauthlib-20180817-cp27-cp27m-win32.whl
- Upload date:
- Size: 69.9 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.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af56dd8a1d229da3fbc3ed498f63df656ae04ef2cb64d91acabc16d3d564ac07 |
|
MD5 | e7a2d293b8096e385e39f8e72e0a1f4b |
|
BLAKE2b-256 | 0d111464d30520bfcce463df6926dfd4274e4ab8d87505a4e927663b1974f8f6 |
File details
Details for the file cryptoauthlib-20180817-cp27-cp27m-macosx_10_6_intel.whl
.
File metadata
- Download URL: cryptoauthlib-20180817-cp27-cp27m-macosx_10_6_intel.whl
- Upload date:
- Size: 83.7 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.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f700d38846e4a71f360de7550de189d6a8cde1733a49e24ff5736ba96dc8fb3b |
|
MD5 | 7ea7160ac79bd8e737313f769fe1ba70 |
|
BLAKE2b-256 | 4e2ba516ba7318126605b73d6d5389e621f6223f80250e2849d5725e18677354 |