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
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
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-20190831.tar.gz
.
File metadata
- Download URL: cryptoauthlib-20190831.tar.gz
- Upload date:
- Size: 262.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/2.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33fa5d10bf95180119e13ebe4db6e0114a14703da2d7fb752ed3f6fa063c278b |
|
MD5 | 3e46aa839775281c0d87cf4f473bd27c |
|
BLAKE2b-256 | 12fe59a2eb0e1a9fb9c1a5a4fdaa052da6d736f19f56a529931519d0b45e429d |
File details
Details for the file cryptoauthlib-20190831-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: cryptoauthlib-20190831-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 103.6 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bbb846529614f3923a7622459fc2f2822d6889cd3b8137d4237c5677c1b06c8 |
|
MD5 | acfb81b6fea53eefcd440c453313ab42 |
|
BLAKE2b-256 | 59ef7613d103424e23cd5c31d8b2f73022fdb81899ff5fe0ae4cd2f6f41c3105 |
File details
Details for the file cryptoauthlib-20190831-cp37-cp37m-win32.whl
.
File metadata
- Download URL: cryptoauthlib-20190831-cp37-cp37m-win32.whl
- Upload date:
- Size: 92.5 kB
- Tags: CPython 3.7m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af7f55b3454ba5ec2c22fe8b77630e85ed10e1c921e15407fdc53f9a5da8662e |
|
MD5 | 48e48f38750dfdf235e79999b03013aa |
|
BLAKE2b-256 | 50a562deb0162437d5eee59deab79ec322cb12263cc2a038aea5f5372b435a57 |
File details
Details for the file cryptoauthlib-20190831-cp37-cp37m-macosx_10_6_intel.whl
.
File metadata
- Download URL: cryptoauthlib-20190831-cp37-cp37m-macosx_10_6_intel.whl
- Upload date:
- Size: 105.9 kB
- Tags: CPython 3.7m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/2.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 999da765683a79a730baa3835efe966976852d8769686779eaa090b7b1ba1987 |
|
MD5 | e749c06cf2b1cae032fb71bac1cf1fb7 |
|
BLAKE2b-256 | 5e1b7acc607691433d27d259c542bcfdecbf115e2f38de845b4f24ea81ccb95f |
File details
Details for the file cryptoauthlib-20190831-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: cryptoauthlib-20190831-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 103.6 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dce7254ce8663a8367eacf96ae30dbf0804d9736d92ca0e3cbc6370e5d2a175b |
|
MD5 | eca11a2630fb6eb3edd548f1eada52b1 |
|
BLAKE2b-256 | 11a00c4f3122d20b7078082cb32b4ce8bf33a66304ad7160ed33012082c22716 |
File details
Details for the file cryptoauthlib-20190831-cp36-cp36m-win32.whl
.
File metadata
- Download URL: cryptoauthlib-20190831-cp36-cp36m-win32.whl
- Upload date:
- Size: 92.5 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc37ca0bad2a965fe99e5dffcf50193edbb883edcf4ae2b7d2bb7769191626f9 |
|
MD5 | 0cf798726e74a1f8d7f80cf23889bd0e |
|
BLAKE2b-256 | 80c92c76f31ac89b46f51e9a27084424538c7ca31320f8e134cb0634e5d3c48b |
File details
Details for the file cryptoauthlib-20190831-cp36-cp36m-macosx_10_6_intel.whl
.
File metadata
- Download URL: cryptoauthlib-20190831-cp36-cp36m-macosx_10_6_intel.whl
- Upload date:
- Size: 105.9 kB
- Tags: CPython 3.6m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/2.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 284147bd14e8e1be73eddbd89b9ff8d066f02b4bfa93a5d188d3e3b1e458012a |
|
MD5 | 0c0d5e68808813c459f2510636c5aa3d |
|
BLAKE2b-256 | 77571a8b505aac719dbf8f7dabf9be8a26a59ac21d7a2292d34fb54d19099529 |
File details
Details for the file cryptoauthlib-20190831-cp35-cp35m-win_amd64.whl
.
File metadata
- Download URL: cryptoauthlib-20190831-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 103.6 kB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.5.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c8a6907397827b5713adc0367b0f5e98a39714d65a6cd160d3f90a14a2b595e |
|
MD5 | 26a564314bddfe7d6f461ca4813098e7 |
|
BLAKE2b-256 | a34a677220eebe0622262502c4d1526a6d988b5a0cf2ec362be3206c2eebab8d |
File details
Details for the file cryptoauthlib-20190831-cp35-cp35m-win32.whl
.
File metadata
- Download URL: cryptoauthlib-20190831-cp35-cp35m-win32.whl
- Upload date:
- Size: 92.5 kB
- Tags: CPython 3.5m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.5.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bf98cd03f08b69f3d009fe9006c3d19aea18d0542b4240c63c3ca53bb72862a |
|
MD5 | 2b03ecfd92714d587a2bee401386d1ad |
|
BLAKE2b-256 | 076a112b4b34c507c3465d0ada69e20c66b91527152548dcaa28f4b46ecaf9b7 |
File details
Details for the file cryptoauthlib-20190831-cp35-cp35m-macosx_10_6_intel.whl
.
File metadata
- Download URL: cryptoauthlib-20190831-cp35-cp35m-macosx_10_6_intel.whl
- Upload date:
- Size: 105.9 kB
- Tags: CPython 3.5m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/2.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2be51f91ef9ecbe4ea42f729ae949563330ffe4d7023db22cdd1f46e605348a9 |
|
MD5 | fe11e24771d9144645e3d0de35399c64 |
|
BLAKE2b-256 | b0a4514ef2ca9c951a7a8adde2851e7180fdd85449db005db325540aac32b186 |
File details
Details for the file cryptoauthlib-20190831-cp27-cp27m-win_amd64.whl
.
File metadata
- Download URL: cryptoauthlib-20190831-cp27-cp27m-win_amd64.whl
- Upload date:
- Size: 103.7 kB
- Tags: CPython 2.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/2.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c4adad07ac5905129cfd93e542ad2068c6f5654971e661ab72718e384ef7d58 |
|
MD5 | 208e5bffeda3ca7a9097636e96eca987 |
|
BLAKE2b-256 | 452a14e03d6863945795c1d93a8f48580b900fb6b59989de1bac2a37b25fda53 |
File details
Details for the file cryptoauthlib-20190831-cp27-cp27m-win32.whl
.
File metadata
- Download URL: cryptoauthlib-20190831-cp27-cp27m-win32.whl
- Upload date:
- Size: 92.5 kB
- Tags: CPython 2.7m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/2.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38110bb49166f17eb45011e331a92ca31bd5621a27839a01efb6e02510eddf98 |
|
MD5 | 85998e9f60df78f21b13baca71a79640 |
|
BLAKE2b-256 | 385907f647045b9c43b629fe65a010157fedb30d19374fe06b3202eba32ddc7a |
File details
Details for the file cryptoauthlib-20190831-cp27-cp27m-macosx_10_6_intel.whl
.
File metadata
- Download URL: cryptoauthlib-20190831-cp27-cp27m-macosx_10_6_intel.whl
- Upload date:
- Size: 105.9 kB
- Tags: CPython 2.7m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/2.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d537f5e0cebf113f37bd3db05fbb14589726cc86fce4d88503db6e6f21bb677f |
|
MD5 | 31de3896e2a96383aba7393855222a4a |
|
BLAKE2b-256 | 6f63ef29f66c72f29fd73647050a262004e4ae9209965b5f228728bcc2a555be |