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.

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-20210117.tar.gz (390.5 kB view hashes)

Uploaded Source

Built Distributions

cryptoauthlib-20210117-pp37-pypy37_pp73-win32.whl (121.1 kB view hashes)

Uploaded PyPy Windows x86

cryptoauthlib-20210117-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (123.6 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

cryptoauthlib-20210117-pp36-pypy36_pp73-win32.whl (121.1 kB view hashes)

Uploaded PyPy Windows x86

cryptoauthlib-20210117-pp36-pypy36_pp73-macosx_10_9_x86_64.whl (123.6 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

cryptoauthlib-20210117-pp27-pypy_73-win32.whl (121.1 kB view hashes)

Uploaded PyPy Windows x86

cryptoauthlib-20210117-pp27-pypy_73-macosx_10_9_x86_64.whl (123.6 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

cryptoauthlib-20210117-cp39-cp39-win_amd64.whl (121.1 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

cryptoauthlib-20210117-cp39-cp39-win32.whl (121.1 kB view hashes)

Uploaded CPython 3.9 Windows x86

cryptoauthlib-20210117-cp39-cp39-macosx_10_9_x86_64.whl (123.6 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

cryptoauthlib-20210117-cp38-cp38-win_amd64.whl (121.1 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

cryptoauthlib-20210117-cp38-cp38-win32.whl (121.1 kB view hashes)

Uploaded CPython 3.8 Windows x86

cryptoauthlib-20210117-cp38-cp38-macosx_10_9_x86_64.whl (123.6 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

cryptoauthlib-20210117-cp37-cp37m-win_amd64.whl (121.1 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

cryptoauthlib-20210117-cp37-cp37m-win32.whl (121.1 kB view hashes)

Uploaded CPython 3.7m Windows x86

cryptoauthlib-20210117-cp37-cp37m-macosx_10_9_x86_64.whl (123.6 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

cryptoauthlib-20210117-cp36-cp36m-win_amd64.whl (121.1 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

cryptoauthlib-20210117-cp36-cp36m-win32.whl (121.1 kB view hashes)

Uploaded CPython 3.6m Windows x86

cryptoauthlib-20210117-cp36-cp36m-macosx_10_9_x86_64.whl (123.6 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

cryptoauthlib-20210117-cp35-cp35m-win_amd64.whl (121.1 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

cryptoauthlib-20210117-cp35-cp35m-win32.whl (121.1 kB view hashes)

Uploaded CPython 3.5m Windows x86

cryptoauthlib-20210117-cp35-cp35m-macosx_10_9_x86_64.whl (123.6 kB view hashes)

Uploaded CPython 3.5m macOS 10.9+ x86-64

cryptoauthlib-20210117-cp27-cp27m-win_amd64.whl (121.1 kB view hashes)

Uploaded CPython 2.7m Windows x86-64

cryptoauthlib-20210117-cp27-cp27m-win32.whl (121.1 kB view hashes)

Uploaded CPython 2.7m Windows x86

cryptoauthlib-20210117-cp27-cp27m-macosx_10_9_x86_64.whl (123.6 kB view hashes)

Uploaded CPython 2.7m macOS 10.9+ x86-64

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