diff --git a/CMakeLists.txt b/CMakeLists.txt index 08ca29eec..40375958a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,10 +2,10 @@ cmake_minimum_required(VERSION 2.6.4) project (cryptoauthlib C) # Set the current release version -set(VERSION "3.3.1") +set(VERSION "3.3.2") set(VERSION_MAJOR 3) set(VERSION_MINOR 3) -set(VERSION_PATCH 1) +set(VERSION_PATCH 2) # Build Options option(BUILD_TESTS "Create Test Application with library" OFF) diff --git a/app/ip_protection/symmetric_authentication.c b/app/ip_protection/symmetric_authentication.c index c41bc9533..fc3bd0585 100644 --- a/app/ip_protection/symmetric_authentication.c +++ b/app/ip_protection/symmetric_authentication.c @@ -133,4 +133,4 @@ ATCA_STATUS symmetric_authenticate(uint8_t slot, const uint8_t *master_key, cons while (0); return status; -} \ No newline at end of file +} diff --git a/app/ip_protection/symmetric_authentication.h b/app/ip_protection/symmetric_authentication.h index 636a9c603..dfb41b46c 100644 --- a/app/ip_protection/symmetric_authentication.h +++ b/app/ip_protection/symmetric_authentication.h @@ -44,4 +44,4 @@ ATCA_STATUS symmetric_authenticate(uint8_t slot, const uint8_t *master_key, cons #endif -#endif /* SYMMETRIC_AUTHENTICATION_H_ */ \ No newline at end of file +#endif /* SYMMETRIC_AUTHENTICATION_H_ */ diff --git a/app/kit_host/ascii_kit_host.c b/app/kit_host/ascii_kit_host.c new file mode 100644 index 000000000..a8ca2fda9 --- /dev/null +++ b/app/kit_host/ascii_kit_host.c @@ -0,0 +1,685 @@ +/** + * \file + * + * \brief KIT protocol intepreter + * + * \copyright (c) 2018 Microchip Technology Inc. and its subsidiaries. + * You may use this software and any derivatives exclusively with + * Microchip products. + * + * \page License + * + * (c) 2018 Microchip Technology Inc. and its subsidiaries. You may use this + * software and any derivatives exclusively with Microchip products. + * + * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED + * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A + * PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION + * WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION. + * + * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS + * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE + * FULLEST EXTENT ALLOWED BY LAW, MICROCHIPS TOTAL LIABILITY ON ALL CLAIMS IN + * ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, + * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. + * + * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE + * TERMS. + */ + +#include + +#include "ascii_kit_host.h" +#include "hal/kit_protocol.h" + +/** \brief Send bytes through a cryptoauthlib hal */ +static ATCA_STATUS kit_host_send_data(void* ctx, uint8_t* txdata, uint16_t txlen) +{ + ATCA_STATUS status = ATCA_BAD_PARAM; + atca_hal_kit_phy_t * phy = (atca_hal_kit_phy_t*)ctx; + + if (phy) + { + ATCAIface iface = (ATCAIface)phy->hal_data; + if (iface) + { + if (iface->phy) + { + status = iface->phy->halsend(iface, 0, txdata, txlen); + } + else if (iface->hal) + { + status = iface->hal->halsend(iface, 0, txdata, txlen); + } + } + } + return status; +} + +/** \brief Receive bytes from a cryptoauthlib hal */ +static ATCA_STATUS kit_host_recv_data(void* ctx, uint8_t* rxdata, uint16_t* rxlen) +{ + ATCA_STATUS status = ATCA_BAD_PARAM; + atca_hal_kit_phy_t* phy = (atca_hal_kit_phy_t*)ctx; + + if (phy) + { + ATCAIface iface = (ATCAIface)phy->hal_data; + if (iface) + { + if (iface->phy) + { + status = iface->phy->halreceive(iface, 0, rxdata, rxlen); + } + else if (iface->hal) + { + status = iface->hal->halreceive(iface, 0, rxdata, rxlen); + } + } + } + return status; +} + + +/** \brief Initializes a phy structure with a cryptoauthlib hal adapter + * \return ATCA_SUCCESS on success, otherwise an error code + */ +ATCA_STATUS kit_host_init_phy( + atca_hal_kit_phy_t* phy, + ATCAIface iface + ) +{ + ATCA_STATUS status = ATCA_BAD_PARAM; + + if (phy && iface) + { + if (ATCA_SUCCESS == (status = hal_iface_init(iface->mIfaceCFG, &iface->hal, &iface->phy))) + { + phy->hal_data = iface; + phy->send = kit_host_send_data; + phy->recv = kit_host_recv_data; + } + } + return status; +} + +/** \brief Initializes the kit protocol parser context + * \return ATCA_SUCCESS on success, otherwise an error code + */ +ATCA_STATUS kit_host_init( + ascii_kit_host_context_t * ctx, /**< Kit protocol parser context */ + ATCAIfaceCfg * iface[], /**< List of device configurations which will be used */ + const size_t iface_count, /**< Number of configurations provided */ + const atca_hal_kit_phy_t* phy, /**< Kit protocol physical adapter */ + const uint32_t flags /**< Option Flags */ + ) +{ + ATCA_STATUS ret = ATCA_BAD_PARAM; + + if (ctx && iface && iface_count && phy) + { + ctx->iface = iface; + ctx->iface_count = iface_count; + ctx->phy = phy; + ctx->flags = (uint32_t)flags; + ret = ATCA_SUCCESS; + } + return ret; +} + +static const char* kit_host_get_iface_type(ATCAIfaceType iface_type) +{ + char* ret = "unknown"; + + switch (iface_type) + { + case ATCA_I2C_IFACE: + ret = "TWI"; + break; + case ATCA_SWI_IFACE: + ret = "SWI"; + break; + case ATCA_SPI_IFACE: + ret = "SPI"; + break; + default: + break; + } + + return ret; +} + +static uint8_t kit_host_get_device_id(ATCAIfaceCfg * cfg) +{ + uint8_t id = 0; + + if (cfg) + { + switch (cfg->iface_type) + { + case ATCA_I2C_IFACE: + id = cfg->atcai2c.address; + break; + case ATCA_SWI_IFACE: + id = cfg->atcaswi.address; + break; + case ATCA_SPI_IFACE: + id = cfg->atcaspi.select_pin; + break; + default: + break; + } + } + return id; +} + +/** \brief Format the status and data into the kit protocol response format */ +size_t kit_host_format_response(uint8_t* response, size_t rlen, ATCA_STATUS status, uint8_t* data, size_t dlen) +{ + char* ptr = (char*)response; + size_t ret = rlen; + + if (ATCA_SUCCESS == atcab_bin2hex_(&status, sizeof(uint8_t), (char*)ptr, &ret, false, false, true)) + { + ptr += ret; + *ptr++ = '('; + if (data && dlen) + { + ret = rlen - (ptr - (char*)response); + atcab_bin2hex_(data, dlen, ptr, &ret, false, false, true); + ptr += ret; + } + *ptr++ = ')'; + *ptr++ = '\n'; + ret = ptr - (char*)response; + } + return ret; +} + +/** \brief Iterate through a command list to match the given command and then will execute it */ +ATCA_STATUS kit_host_process_cmd( + ascii_kit_host_context_t* ctx, + const kit_host_map_entry_t * cmd_list, + int argc, char* argv[], + uint8_t* response, + size_t* rlen + ) +{ + ATCA_STATUS status = ATCA_BAD_PARAM; + const kit_host_map_entry_t* cmd; + + for (cmd = cmd_list; cmd->id && cmd->fp_command; cmd++) + { + if (!strncmp(cmd->id, argv[0], strlen(argv[0]))) + { + status = cmd->fp_command(ctx, argc - 1, &argv[1], response, rlen); + break; + } + } + return status; +} + +#if ATCA_CA_SUPPORT + +static ATCA_STATUS kit_host_ca_wake(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + ATCA_STATUS status = ATCA_BAD_PARAM; + const uint8_t expected_response[4] = { 0x04, 0x11, 0x33, 0x43 }; + const uint8_t selftest_fail_resp[4] = { 0x04, 0x07, 0xC4, 0x40 }; + + if (ctx && response && rlen) + { + status = calib_wakeup(ctx->device); + if (ATCA_SUCCESS == status) + { + *rlen = kit_host_format_response(response, *rlen, status, (uint8_t*)expected_response, sizeof(expected_response)); + } + else if (ATCA_STATUS_SELFTEST_ERROR == status) + { + *rlen = kit_host_format_response(response, *rlen, status, (uint8_t*)selftest_fail_resp, sizeof(selftest_fail_resp)); + } + else + { + *rlen = kit_host_format_response(response, *rlen, status, NULL, 0); + } + } + return status; +} + +static ATCA_STATUS kit_host_ca_idle(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + ATCA_STATUS status = ATCA_BAD_PARAM; + + if (ctx && response && rlen) + { + status = calib_idle(ctx->device); + *rlen = 0; + } + + return status; +} + +static ATCA_STATUS kit_host_ca_sleep(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + ATCA_STATUS status = ATCA_BAD_PARAM; + + if (ctx && response && rlen) + { + status = calib_sleep(ctx->device); + *rlen = 0; + } + + return status; +} + +static ATCA_STATUS kit_host_ca_talk(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + ATCA_STATUS status = ATCA_BAD_PARAM; + + if (ctx && argc && response && rlen) + { + ATCAPacket packet; + size_t plen = sizeof(packet) - 2; + + atcab_hex2bin(argv[0], strlen(argv[0]), (uint8_t*)&packet.txsize, &plen); + if (ATCA_SUCCESS == (status = calib_execute_command(&packet, ctx->device))) + { + *rlen = kit_host_format_response(response, *rlen, status, (uint8_t*)&packet.data, packet.data[0]); + } + else + { + *rlen = kit_host_format_response(response, *rlen, status, NULL, 0); + } + } + return status; +} +#endif + +static ATCA_STATUS kit_host_ca_select(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + ATCA_STATUS status = ATCA_FUNC_FAIL; + + if (argc > 0) + { + uint8_t id = (uint8_t)strtol(argv[0], NULL, 16); + int i; + + for (i = 0; i < ctx->iface_count && status; i++) + { + ATCAIfaceCfg * cfg = ctx->iface[i]; + switch (cfg->iface_type) + { + case ATCA_I2C_IFACE: + if (id == cfg->atcai2c.address) + { + status = atcab_init_ext(&ctx->device, cfg); + } + break; + case ATCA_SWI_IFACE: + if (id == cfg->atcaswi.address) + { + status = atcab_init_ext(&ctx->device, cfg); + } + break; + case ATCA_SPI_IFACE: + if (id == cfg->atcaspi.select_pin) + { + status = atcab_init_ext(&ctx->device, cfg); + } + break; + default: + break; + } + } + } + + *rlen = 0; + return ATCA_SUCCESS; +} + +#if ATCA_CA_SUPPORT +static kit_host_map_entry_t kit_host_ca_physical_map[] = { + { "select", kit_host_ca_select }, + { NULL, NULL } +}; + +static ATCA_STATUS kit_host_ca_physical(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + return kit_host_process_cmd(ctx, kit_host_ca_physical_map, argc, argv, response, rlen); +} + +/* Cryptoauth Device commands */ +static kit_host_map_entry_t kit_host_ca_map[] = { + { "wake", kit_host_ca_wake }, + { "idle", kit_host_ca_idle }, + { "sleep", kit_host_ca_sleep }, + { "talk", kit_host_ca_talk }, + { "physical", kit_host_ca_physical }, + { NULL, NULL } +}; + +static ATCA_STATUS kit_host_process_ca(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + return kit_host_process_cmd(ctx, kit_host_ca_map, argc, argv, response, rlen); +} +#endif + +#if ATCA_TA_SUPPORT +static ATCA_STATUS kit_host_ta_wake(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + *rlen = 0; + return ATCA_SUCCESS; +} + +static ATCA_STATUS kit_host_ta_idle(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + *rlen = 0; + return ATCA_SUCCESS; +} + +static ATCA_STATUS kit_host_ta_sleep(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + *rlen = 0; + return ATCA_UNIMPLEMENTED; +} + +static ATCA_STATUS kit_host_ta_talk(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + ATCA_STATUS status = ATCA_BAD_PARAM; + + if (ctx && argc && response && rlen) + { + ATCA_TA_CmdPacket* packet = (ATCA_TA_CmdPacket*)ctx->buffer; + + if (packet) + { + size_t plen = sizeof(ctx->buffer) - 2; + + atcab_hex2bin(argv[0], strlen(argv[0]), (uint8_t*)&packet->length, &plen); + if (ATCA_SUCCESS == (status = talib_execute_command_raw(packet, ctx->device))) + { + ATCA_TA_RspPacket * resp = (ATCA_TA_RspPacket*)packet; + *rlen = kit_host_format_response(response, *rlen, status, resp->data, resp->resp_code); + } + else + { + *rlen = kit_host_format_response(response, *rlen, status, NULL, 0); + } + } + } + return status; +} + +#include "talib/talib_fce.h" + +static ATCA_STATUS kit_host_ta_send(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + ATCA_STATUS status = ATCA_BAD_PARAM; + + if (ctx && argc && response && rlen) + { + size_t plen = sizeof(ctx->buffer) - 2; + atcab_hex2bin(argv[0], strlen(argv[0]), ctx->buffer, &plen); + + uint8_t address = atgetifacecfg(&ctx->device->mIface)->atcai2c.address; + + status = atsend(&ctx->device->mIface, address, ctx->buffer, plen); + *rlen = 0; + } + return status; +} + +static ATCA_STATUS kit_host_ta_receive(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + ATCA_STATUS status = ATCA_BAD_PARAM; + uint16_t rxdata_max_size = ATCA_CMD_DATA_MAX_LENGTH; + uint16_t length_size = 2; + uint16_t read_length = 0; + + if (ctx && argc && response && rlen) + { + do + { + size_t plen = sizeof(ctx->buffer) - 2; + atcab_hex2bin(argv[0], strlen(argv[0]), ctx->buffer, &plen); + + uint8_t address = atgetifacecfg(&ctx->device->mIface)->atcai2c.address; + uint8_t word_address = ctx->buffer[0]; + + rxdata_max_size = ((uint16_t)ctx->buffer[1] * 256) + ctx->buffer[2]; + + if (ATCA_SUCCESS != (status = atsend(&ctx->device->mIface, address, &word_address, sizeof(word_address)))) + { + return status; + } + + /*Set read length.. Check for register reads or 1 byte reads*/ + if ((word_address == ATCA_MAIN_PROCESSOR_RD_CMD) || (word_address == 0xFF)) + { + /* Read length bytes to know number of bytes to read */ + if (ATCA_SUCCESS != (status = atreceive(&ctx->device->mIface, address, &ctx->buffer[sizeof(ctx->buffer) / 2], &length_size))) + { + break; + } + read_length = ((uint16_t)ctx->buffer[sizeof(ctx->buffer) / 2] * 256) + ctx->buffer[sizeof(ctx->buffer) / 2 + 1]; + + if (read_length > rxdata_max_size) + { + status = ATCA_SMALL_BUFFER; + break; + } + if (read_length < (3 + length_size)) //status(1) and CRC(2) size are same for CA and TA, length is variable. + { + status = ATCA_RX_FAIL; + break; + } + + /* Read given length bytes from device */ + read_length -= length_size; + if (ATCA_SUCCESS != (status = atreceive(&ctx->device->mIface, address, &ctx->buffer[sizeof(ctx->buffer) / 2 + length_size], + &read_length))) + { + break; + } + read_length += length_size; + } + else if ((word_address == ATCA_MAIN_PROCESSOR_RD_CSR) || (word_address == ATCA_FAST_CRYPTO_RD_FSR) || + (rxdata_max_size == 1)) + { + read_length = 1; + length_size = 0; + if (ATCA_SUCCESS != (status = atreceive(&ctx->device->mIface, address, &ctx->buffer[sizeof(ctx->buffer) / 2], &read_length))) + { + break; + } + } + else + { + read_length = rxdata_max_size; + length_size = 0; + if (ATCA_SUCCESS != (status = atreceive(&ctx->device->mIface, address, &ctx->buffer[sizeof(ctx->buffer) / 2], &read_length))) + { + break; + } + } + } + while (0); + if (ATCA_SUCCESS == status) + { + *rlen = kit_host_format_response(ctx->buffer, sizeof(ctx->buffer), status, &ctx->buffer[sizeof(ctx->buffer) / 2], read_length + length_size); + } + else + { + *rlen = 0; + } + } + return status; +} + +static kit_host_map_entry_t kit_host_ta_physical_map[] = { + { "select", kit_host_ca_select }, /* Selection logic is the same */ + { NULL, NULL } +}; + +static ATCA_STATUS kit_host_ta_physical(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + return kit_host_process_cmd(ctx, kit_host_ta_physical_map, argc, argv, response, rlen); +} + +static kit_host_map_entry_t kit_host_ta_map[] = { + { "wake", kit_host_ta_wake }, + { "idle", kit_host_ta_idle }, + { "sleep", kit_host_ta_sleep }, + { "talk", kit_host_ta_talk }, + { "send", kit_host_ta_send }, + { "receive", kit_host_ta_receive }, + { "physical", kit_host_ta_physical }, + { NULL, NULL } +}; + +ATCA_STATUS kit_host_process_ta(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + return kit_host_process_cmd(ctx, kit_host_ta_map, argc, argv, response, rlen); +} + +#endif + +static ATCA_STATUS kit_host_board_get_version(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + return ATCA_SUCCESS; +} + +static ATCA_STATUS kit_host_board_get_firmware(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + return ATCA_SUCCESS; +} + +static ATCA_STATUS kit_host_board_get_device(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + ATCA_STATUS status = ATCA_FUNC_FAIL; + + if (argc > 0) + { + uint8_t idx = (uint8_t)strtol(argv[0], NULL, 16); + if (idx < ctx->iface_count) + { + ATCAIfaceCfg * cfg = ctx->iface[idx]; + + *rlen = snprintf((char*)response, *rlen, "%s %s 00(%02X)\n", kit_id_from_devtype(cfg->devtype), + kit_host_get_iface_type(cfg->iface_type), kit_host_get_device_id(cfg)); + status = ATCA_SUCCESS; + } + } + return status; +} + + +static kit_host_map_entry_t kit_host_board_map[] = { + { "version", kit_host_board_get_version }, + { "firmware", kit_host_board_get_firmware }, + { "device", kit_host_board_get_device }, + { NULL, NULL } +}; + +static ATCA_STATUS kit_host_process_board(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + return kit_host_process_cmd(ctx, kit_host_board_map, argc, argv, response, rlen); +} + + +static const kit_host_map_entry_t kit_host_target_map[] = { + { "board", kit_host_process_board }, +#if ATCA_CA_SUPPORT + { "ecc", kit_host_process_ca }, + { "sha", kit_host_process_ca }, +#endif +#if ATCA_TA_SUPPORT + { "ta", kit_host_process_ta }, +#endif + { NULL, NULL } +}; + +static ATCA_STATUS kit_host_process_target(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen) +{ + return kit_host_process_cmd(ctx, kit_host_target_map, argc, argv, response, rlen); +} + +/** \brief Parse a line as a kit protocol command. The kit protocol is printable + * ascii and each line ends with a newline character */ +ATCA_STATUS kit_host_process_line( + ascii_kit_host_context_t* ctx, /**< */ + uint8_t * input_line, /**< */ + size_t ilen, /**< */ + uint8_t* response, /**< */ + size_t* rlen /**< */ + ) +{ + ATCA_STATUS status = ATCA_BAD_PARAM; + size_t i; + char* ptr; + int argc = 0; + char* argv[4]; + + if (ctx && input_line && ilen && response && rlen) + { + argc = 1; + argv[0] = (char*)input_line; + for (i = 0, ptr = (char*)input_line; i < ilen; i++, ptr++) + { + switch (*ptr) + { + case KIT_LAYER_DELIMITER: + /* fallthrough */ + case KIT_DATA_BEGIN_DELIMITER: + argv[argc++] = ptr + 1; + /* fallthrough */ + case KIT_DATA_END_DELIMITER: + *ptr = '\0'; + break; + case KIT_MESSAGE_DELIMITER: + status = kit_host_process_target(ctx, argc, argv, response, rlen); + break; + default: + if (isalpha(*ptr)) + { + *ptr = tolower(*ptr); + } + break; + } + } + } + return status; +} + +/** \brief Non returning kit protocol runner using the configured physical interface + that was provided when the context was initialized */ +void kit_host_task(ascii_kit_host_context_t* ctx) +{ + uint8_t* ptr = ctx->buffer; + uint16_t rxlen = 1; + size_t txlen; + ATCA_STATUS status; + + for (;; ) + { + if (ATCA_SUCCESS == ctx->phy->recv((void*)ctx->phy, ptr, &rxlen)) + { + if (KIT_MESSAGE_DELIMITER == *ptr++) + { + txlen = sizeof(ctx->buffer); + status = kit_host_process_line(ctx, ctx->buffer, ptr - ctx->buffer, ctx->buffer, &txlen); + + if ((ATCA_SUCCESS != status) || !txlen) + { + txlen = snprintf((char*)ctx->buffer, sizeof(ctx->buffer), "%02X()\n", status); + } + ctx->phy->send((void*)ctx->phy, ctx->buffer, txlen); + + ptr = ctx->buffer; + } + } + } +} diff --git a/app/kit_host/ascii_kit_host.h b/app/kit_host/ascii_kit_host.h new file mode 100644 index 000000000..37d2f6e7b --- /dev/null +++ b/app/kit_host/ascii_kit_host.h @@ -0,0 +1,104 @@ +/** + * \file + * + * \brief KIT protocol intepreter + * + * \copyright (c) 2018 Microchip Technology Inc. and its subsidiaries. + * You may use this software and any derivatives exclusively with + * Microchip products. + * + * \page License + * + * (c) 2018 Microchip Technology Inc. and its subsidiaries. You may use this + * software and any derivatives exclusively with Microchip products. + * + * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED + * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A + * PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION + * WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION. + * + * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS + * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE + * FULLEST EXTENT ALLOWED BY LAW, MICROCHIPS TOTAL LIABILITY ON ALL CLAIMS IN + * ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, + * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. + * + * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE + * TERMS. + */ + +#ifndef ASCII_KIT_HOST_H +#define ASCII_KIT_HOST_H + +#include "cryptoauthlib.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +#define KIT_LAYER_DELIMITER ':' +#define KIT_DATA_BEGIN_DELIMITER '(' +#define KIT_DATA_END_DELIMITER ')' +#define KIT_MESSAGE_DELIMITER '\n' + +/** + * \brief The Kit Protocol maximum message size. + * \note + * Send: :(optional hex bytes to send)\n + * Receive: (optional hex bytes of response)\n + */ +#ifdef KIT_PROTOCOL_MESSAGE_MAX +#define KIT_MESSAGE_SIZE_MAX KIT_PROTOCOL_MESSAGE_MAX +#elif ATCA_TA_SUPPORT +#define KIT_MESSAGE_SIZE_MAX (2500) +#else +#define KIT_MESSAGE_SIZE_MAX (512) +#endif // KIT_PROTOCOL_MESSAGE_MAX + +#define KIT_SECTION_NAME_SIZE_MAX KIT_MESSAGE_SIZE_MAX //! The maximum message section size +#define KIT_VERSION_SIZE_MAX (32) //! The maximum Kit Protocol version size +#define KIT_FIRMWARE_SIZE_MAX (32) //! The maximum Kit Protocol firmware size + + +typedef struct _ascii_kit_host_context +{ + const atca_hal_kit_phy_t* phy; + uint8_t buffer[KIT_MESSAGE_SIZE_MAX]; + ATCADevice device; + ATCAIfaceCfg** iface; + size_t iface_count; + uint32_t flags; +} ascii_kit_host_context_t; + +/** Used to create command tables for the kit host parser */ +typedef struct _kit_host_map_entry +{ + const char* id; + ATCA_STATUS (*fp_command)(ascii_kit_host_context_t* ctx, int argc, char* argv[], uint8_t* response, size_t* rlen); +} kit_host_map_entry_t; + +/* Kit Initialization */ +ATCA_STATUS kit_host_init_phy(atca_hal_kit_phy_t* phy, ATCAIface iface); + +ATCA_STATUS kit_host_init(ascii_kit_host_context_t * ctx, ATCAIfaceCfg * iface[], + const size_t iface_count, const atca_hal_kit_phy_t* phy, const uint32_t flags); + +/* Kit APIs for commands - can be used to create custom board commands */ +size_t kit_host_format_response(uint8_t* response, size_t rlen, ATCA_STATUS status, uint8_t* data, size_t dlen); +ATCA_STATUS kit_host_process_cmd(ascii_kit_host_context_t* ctx, const kit_host_map_entry_t * cmd_list, + int argc, char* argv[], uint8_t* response, size_t* rlen); + +/* Kit Protocol Runners */ +ATCA_STATUS kit_host_process_line(ascii_kit_host_context_t* ctx, uint8_t * input_line, + size_t ilen, uint8_t* response, size_t* rlen); + +void kit_host_task(ascii_kit_host_context_t* ctx); + +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif diff --git a/app/pkcs11/example_pkcs11_config.c b/app/pkcs11/example_pkcs11_config.c index 7fdfdfb7f..4eadc3ca4 100644 --- a/app/pkcs11/example_pkcs11_config.c +++ b/app/pkcs11/example_pkcs11_config.c @@ -1,4 +1,3 @@ - #include "cryptoauthlib.h" #include "pkcs11_config.h" #include "pkcs11/pkcs11_object.h" diff --git a/app/pkcs11/trust_pkcs11_config.c b/app/pkcs11/trust_pkcs11_config.c index 99f4b9bb6..ed0ab18b7 100644 --- a/app/pkcs11/trust_pkcs11_config.c +++ b/app/pkcs11/trust_pkcs11_config.c @@ -38,8 +38,21 @@ const char pkcs11_trust_device_label[] = "device"; const char pkcs11_trust_signer_label[] = "signer"; const char pkcs11_trust_root_label[] = "root"; + + +/* Per PKCS11 ECDSA private keys must have a matching public key. It is + consider best practice for these keys to have the same label and the + library will create the matching public key object whenever a private + key is specified in the configuration or is created with the genkey + mechanism. However in a static configuration it is possible to + circumvent this alignment by defining PKCS11_TNG_NONMATCHING_LABELS */ +#ifdef PKCS11_TNG_NONMATCHING_LABELS const char pkcs11_trust_device_private_key_label[] = "device private"; const char pkcs11_trust_device_public_key_label[] = "device public"; +#else +const char pkcs11_trust_device_private_key_label[] = "device"; +const char pkcs11_trust_device_public_key_label[] = "device"; +#endif /* Helper function to assign the proper fields to an certificate object from a cert def */ CK_RV pkcs11_trust_config_cert(pkcs11_lib_ctx_ptr pLibCtx, pkcs11_slot_ctx_ptr pSlot, pkcs11_object_ptr pObject, CK_ATTRIBUTE_PTR pLabel) diff --git a/app/secure_boot/io_protection_key.h b/app/secure_boot/io_protection_key.h index a0fe6a72b..45a13e7fc 100644 --- a/app/secure_boot/io_protection_key.h +++ b/app/secure_boot/io_protection_key.h @@ -43,6 +43,3 @@ extern ATCA_STATUS io_protection_set_key(uint8_t* io_key); #endif #endif - - - diff --git a/app/secure_boot/secure_boot.c b/app/secure_boot/secure_boot.c index b103e0364..cebd7c7b8 100644 --- a/app/secure_boot/secure_boot.c +++ b/app/secure_boot/secure_boot.c @@ -272,4 +272,4 @@ ATCA_STATUS bind_host_and_secure_element_with_io_protection(uint16_t slot) while (0); return status; -} \ No newline at end of file +} diff --git a/app/secure_boot/secure_boot.h b/app/secure_boot/secure_boot.h index 9497896f0..8a204251f 100644 --- a/app/secure_boot/secure_boot.h +++ b/app/secure_boot/secure_boot.h @@ -87,6 +87,3 @@ extern ATCA_STATUS host_generate_random_number(uint8_t *rand); #endif #endif - - - diff --git a/app/secure_boot/secure_boot_memory.h b/app/secure_boot/secure_boot_memory.h index 9322efd58..5fca2a3da 100644 --- a/app/secure_boot/secure_boot_memory.h +++ b/app/secure_boot/secure_boot_memory.h @@ -59,6 +59,3 @@ extern bool secure_boot_check_full_copy_completion(void); #endif #endif - - - diff --git a/app/tng/readme.md b/app/tng/readme.md index da4439894..c8f7f0264 100644 --- a/app/tng/readme.md +++ b/app/tng/readme.md @@ -7,4 +7,3 @@ These devices have standard certificates that can be easily read using the functions in tng_atcacert_client.h @ingroup tng_ - diff --git a/app/tng/tflxtls_cert_def_4_device.h b/app/tng/tflxtls_cert_def_4_device.h index fd871734f..bf051e063 100644 --- a/app/tng/tflxtls_cert_def_4_device.h +++ b/app/tng/tflxtls_cert_def_4_device.h @@ -44,4 +44,4 @@ extern const atcacert_def_t g_tflxtls_cert_def_4_device; } #endif -#endif \ No newline at end of file +#endif diff --git a/app/tng/tng_atca.c b/app/tng/tng_atca.c index 0d6a03ab0..8fd753733 100644 --- a/app/tng/tng_atca.c +++ b/app/tng/tng_atca.c @@ -45,22 +45,22 @@ typedef struct static tng_cert_map_element g_tng_cert_def_map[] = { #ifdef ATCA_TNG_LEGACY_SUPPORT - { "wdNxAjae", &g_tngtls_cert_def_2_device }, - { "Rsuy5YJh", &g_tngtls_cert_def_2_device }, - { "BxZvm6q2", &g_tnglora_cert_def_2_device }, + { "wdNxAjae", &g_tngtls_cert_def_2_device }, + { "Rsuy5YJh", &g_tngtls_cert_def_2_device }, + { "BxZvm6q2", &g_tnglora_cert_def_2_device }, #endif #ifdef ATCA_TFLEX_SUPPORT - { "MKMwyhP1", &g_tflxtls_cert_def_4_device }, + { "MKMwyhP1", &g_tflxtls_cert_def_4_device }, #endif #ifdef ATCA_TNGTLS_SUPPORT - { "KQp2ZkD8", &g_tngtls_cert_def_3_device }, - { "x6tjuZMy", &g_tngtls_cert_def_3_device }, + { "KQp2ZkD8", &g_tngtls_cert_def_3_device }, + { "x6tjuZMy", &g_tngtls_cert_def_3_device }, #endif #ifdef ATCA_TNGLORA_SUPPORT - { "jsMu7iYO", &g_tnglora_cert_def_4_device }, - { "09qJNxI3", &g_tnglora_cert_def_4_device }, + { "jsMu7iYO", &g_tnglora_cert_def_4_device }, + { "09qJNxI3", &g_tnglora_cert_def_4_device }, #endif - { "", NULL } + { "", NULL } }; static const size_t g_tng_cert_def_cnt = sizeof(g_tng_cert_def_map) / sizeof(tng_cert_map_element) - 1; diff --git a/app/tng/tng_atca.h b/app/tng/tng_atca.h index a5b2bbead..3dc0ebc02 100644 --- a/app/tng/tng_atca.h +++ b/app/tng/tng_atca.h @@ -77,4 +77,4 @@ ATCA_STATUS tng_get_device_pubkey(uint8_t *public_key); } #endif -#endif \ No newline at end of file +#endif diff --git a/app/tng/tng_atcacert_client.h b/app/tng/tng_atcacert_client.h index 41a99d89d..7e4d7cf45 100644 --- a/app/tng/tng_atcacert_client.h +++ b/app/tng/tng_atcacert_client.h @@ -152,4 +152,4 @@ int tng_atcacert_root_public_key(uint8_t* public_key); } #endif -#endif \ No newline at end of file +#endif diff --git a/app/tng/tng_root_cert.h b/app/tng/tng_root_cert.h index ca1c27357..5388e8da4 100644 --- a/app/tng/tng_root_cert.h +++ b/app/tng/tng_root_cert.h @@ -49,4 +49,4 @@ extern const size_t g_cryptoauth_root_ca_002_cert_size; } #endif -#endif \ No newline at end of file +#endif diff --git a/cryptoauthlib-manual.pdf b/cryptoauthlib-manual.pdf index 2cfc191db..366d69012 100644 Binary files a/cryptoauthlib-manual.pdf and b/cryptoauthlib-manual.pdf differ diff --git a/dist-tools/format/call_Uncrustify.cfg b/dist-tools/format/call_Uncrustify.cfg new file mode 100644 index 000000000..9cf3a3b04 --- /dev/null +++ b/dist-tools/format/call_Uncrustify.cfg @@ -0,0 +1,158 @@ +tok_split_gte=false +utf8_byte=false +utf8_force=false +indent_cmt_with_tabs=false +indent_align_string=false +indent_braces=false +indent_braces_no_func=false +indent_braces_no_class=false +indent_braces_no_struct=false +indent_brace_parent=false +indent_namespace=false +indent_extern=false +indent_class=false +indent_class_colon=false +indent_else_if=false +indent_var_def_cont=false +indent_func_call_param=false +indent_func_def_param=false +indent_func_proto_param=false +indent_func_class_param=false +indent_func_ctor_var_param=false +indent_template_param=false +indent_func_param_double=false +indent_relative_single_line_comments=false +indent_col1_comment=false +indent_access_spec_body=false +indent_paren_nl=false +indent_comma_paren=false +indent_bool_paren=false +indent_first_bool_expr=false +indent_square_nl=false +indent_preserve_sql=false +indent_align_assign=true +sp_balance_nested_parens=false +align_keep_tabs=false +align_with_tabs=false +align_on_tabstop=false +align_number_left=false +align_func_params=true +align_same_func_call_params=false +align_var_def_colon=false +align_var_def_attribute=false +align_var_def_inline=false +align_right_cmt_mix=false +align_on_operator=false +align_mix_var_proto=false +align_single_line_func=false +align_single_line_brace=false +align_nl_cont=false +align_left_shift=true +align_oc_decl_colon=false +nl_collapse_empty_body=false +nl_assign_leave_one_liners=false +nl_class_leave_one_liners=false +nl_enum_leave_one_liners=false +nl_getset_leave_one_liners=false +nl_func_leave_one_liners=false +nl_if_leave_one_liners=false +nl_multi_line_cond=false +nl_multi_line_define=false +nl_before_case=false +nl_after_case=false +nl_after_return=false +nl_after_semicolon=false +nl_after_brace_open=false +nl_after_brace_open_cmt=false +nl_after_vbrace_open=false +nl_after_vbrace_open_empty=false +nl_after_brace_close=false +nl_after_vbrace_close=false +nl_define_macro=false +nl_squeeze_ifdef=false +nl_ds_struct_enum_cmt=false +nl_ds_struct_enum_close_brace=false +nl_create_if_one_liner=false +nl_create_for_one_liner=false +nl_create_while_one_liner=false +ls_for_split_full=false +ls_func_split_full=false +nl_after_multiline_comment=false +eat_blanks_after_open_brace=false +eat_blanks_before_close_brace=false +mod_full_brace_if_chain=false +mod_pawn_semicolon=false +mod_full_paren_if_bool=false +mod_remove_extra_semicolon=false +mod_sort_import=false +mod_sort_using=false +mod_sort_include=false +mod_move_case_break=false +mod_remove_empty_return=false +cmt_indent_multi=true +cmt_c_group=false +cmt_c_nl_start=false +cmt_c_nl_end=false +cmt_cpp_group=false +cmt_cpp_nl_start=false +cmt_cpp_nl_end=false +cmt_cpp_to_c=false +cmt_star_cont=false +cmt_multi_check_last=true +cmt_insert_before_preproc=false +pp_indent_at_level=false +pp_region_indent_code=false +pp_if_indent_code=false +pp_define_at_level=false +input_tab_size=4 +output_tab_size=4 +indent_columns=4 +indent_label=1 +align_enum_equ_span=4 +align_var_struct_span=1 +align_struct_init_span=3 +align_right_cmt_span=3 +nl_func_var_def_blk=1 +mod_full_brace_nl=3 +newlines=lf +indent_with_tabs=0 +sp_arith=add +sp_assign=add +sp_bool=add +sp_compare=add +sp_before_sparen=force +sp_inside_sparen=remove +sp_after_sparen=force +sp_after_comma=add +sp_after_cast=remove +sp_sizeof_paren=remove +sp_inside_braces_enum=add +sp_inside_braces_struct=add +sp_inside_braces=add +sp_func_proto_paren=remove +sp_func_def_paren=remove +sp_inside_fparen=remove +sp_func_call_paren=remove +nl_fcall_brace=add +nl_enum_brace=add +nl_struct_brace=add +nl_union_brace=add +nl_if_brace=add +nl_brace_else=add +nl_else_brace=add +nl_for_brace=add +nl_while_brace=add +nl_do_brace=add +nl_brace_while=add +nl_switch_brace=add +nl_fdef_brace=add +mod_full_brace_do=add +mod_full_brace_for=add +mod_full_brace_function=add +mod_full_brace_if=add +mod_full_brace_while=add +mod_paren_on_return=remove +nl_end_of_file_min=1 +nl_start_of_file=remove +nl_end_of_file=add + diff --git a/harmony/config/cryptoauthlib.py b/harmony/config/cryptoauthlib.py index 80e1fd75b..3a7b3b665 100644 --- a/harmony/config/cryptoauthlib.py +++ b/harmony/config/cryptoauthlib.py @@ -73,8 +73,6 @@ def updateHalTracker(id, inc): elif cnt > 0: cnt -= 1 - print('updateHalTracker', id) - symbol = Database.getComponentByID('cryptoauthlib').getSymbolByID('CAL_FILE_SRC_HAL_' + id) symbol.setEnabled(cnt > 0) @@ -111,6 +109,24 @@ def updatePlibTracker(id, inc): add_value_to_list(calPlibList, id) +def updateDevCfgTracker(id, inc): + calDevCfgList = Database.getComponentByID('cryptoauthlib').getSymbolByID('CAL_DEV_CFG_LIST_ENTRIES') + + if inc: + add_value_to_list(calDevCfgList, id) + else: + del_value_from_list(calDevCfgList, id) + + +def extendDevCfgList(new_list, cnt): + calDevCfgList = Database.getComponentByID('cryptoauthlib').getSymbolByID('CAL_DEV_CFG_LIST_ENTRIES') + + for value in new_list: + values = list(calDevCfgList.getValues()) + if value not in values: + calDevCfgList.addValue(value) + + def handleMessage(messageID, args): global calPlibTracker @@ -118,6 +134,14 @@ def handleMessage(messageID, args): if isinstance(args, dict): updatePlibTracker(**args) + if (messageID == 'UPDATE_DEV_CFG_LIST'): + if isinstance(args, dict): + updateDevCfgTracker(**args) + + if (messageID == 'EXTEND_DEV_CFG_LIST'): + if isinstance(args, dict): + extendDevCfgList(**args) + return {} @@ -256,8 +280,7 @@ def onAttachmentDisconnected(source, target): calTaEnableAesAuth = srcComponent.getSymbolByID('CAL_ENABLE_TA100_AES_AUTH') calTaEnableAesAuth.setValue(False) - - print('disconnected lib_wolfcrypt') + def instantiateComponent(calComponent): @@ -426,7 +449,12 @@ def instantiateComponent(calComponent): calDeviceList = calComponent.createListSymbol('CAL_DEVICE_LIST', None) calDeviceList = calComponent.createListEntrySymbol('CAL_DEVICE_LIST_ENTRIES', None) calDeviceList.setTarget('cryptoauthlib.CAL_DEVICE_LIST') - + + # List of specific device instances + calDevCfgList = calComponent.createListSymbol('CAL_DEV_CFG_LIST', None) + calDevCfgList = calComponent.createListEntrySymbol('CAL_DEV_CFG_LIST_ENTRIES', None) + calDevCfgList.setTarget('cryptoauthlib.CAL_DEV_CFG_LIST') + # Add device specific options calTaEnableAesAuth = calComponent.createBooleanSymbol('CAL_ENABLE_TA100_AES_AUTH', None) calTaEnableAesAuth.setValue(False) diff --git a/harmony/config/device_instance.py b/harmony/config/device_instance.py index 5920600bd..df7d5100b 100644 --- a/harmony/config/device_instance.py +++ b/harmony/config/device_instance.py @@ -27,6 +27,12 @@ _I2C_DEVICES = ['ATSHA204A', 'ATECC108A', 'ATECC508A', 'ATECC608', 'TA100', 'ECC204'] _SPI_DEVICES = ['TA100'] +caldevcfglist = [] + + +def handleMessage(messageID, args): + return {} + def CALSecFileUpdate(symbol, event): symObj = event['symbol'] @@ -38,6 +44,16 @@ def CALSecFileUpdate(symbol, event): symbol.setSecurity("NON_SECURE") +def add_value_to_list(symbol_list, value): + if value not in symbol_list: + symbol_list.append(value) + + +def del_value_from_list(symbol_list, value): + if value in symbol_list: + symbol_list.remove(value) + + def updateSercomPlibList(plib, inc): Database.sendMessage('cryptoauthlib', 'UPDATE_PLIB_LIST', {'id': plib.lower(), 'inc': inc}) @@ -46,6 +62,21 @@ def updateTngCapability(id, src): Database.sendMessage('cryptoauthlib_tng', 'UPDATE_TNG_TYPE', {'id': id, 'src': src}) +def updateDevCfgList(dev_cfg, inc): + global caldevcfglist + Database.sendMessage('cryptoauthlib', 'UPDATE_DEV_CFG_LIST', {'id': dev_cfg.lower(), 'inc': inc}) + + if inc: + add_value_to_list(caldevcfglist, dev_cfg.lower()) + else: + del_value_from_list(caldevcfglist, dev_cfg.lower()) + + +def calExtendDevCfgList(symbol, event): + global caldevcfglist + Database.sendMessage('cryptoauthlib', 'EXTEND_DEV_CFG_LIST', {'new_list': caldevcfglist, 'cnt': len(caldevcfglist)}) + + def updateSwiBbInterfaceSettings(symbol, swi_bb_iface): if swi_bb_iface: symbol.getComponent().getSymbolByID('HAL_INTERFACE').setValue("GPIO") @@ -229,11 +260,20 @@ def instantiateComponent(deviceComponent, index): pass devInitDataFile.setDependencies(CALSecFileUpdate, ["cryptoauthlib.CAL_NON_SECURE"]) + devCfgList = deviceComponent.createBooleanSymbol('DEV_CFG_LIST', None) + devCfgList.setVisible(False) + devCfgList.setDependencies(calExtendDevCfgList, ["cryptoauthlib_test.MULTIPLE_IFACE_SELECTED"]) + def onAttachmentConnected(source, target): sourceID = source['id'].upper() targetID = target['component'].getID().upper() + name = source['component'].getID().lower() + + dev_cfg_init_data = name + '_init_data' + updateDevCfgList(dev_cfg_init_data, True) + if 'I2C' in sourceID: source['component'].getSymbolByID('HAL_INTERFACE').setValue(targetID) source['component'].getSymbolByID('INTERFACE').setReadOnly(True) @@ -257,6 +297,11 @@ def onAttachmentDisconnected(source, target): sourceID = source['id'].upper() targetID = target['component'].getID().upper() + name = source['component'].getID().lower() + + dev_cfg_init_data = name + '_init_data' + updateDevCfgList(dev_cfg_init_data, False) + if 'I2C' in sourceID: try: source['component'].getSymbolByID('HAL_INTERFACE').clearValue() diff --git a/harmony/config/kit_host.py b/harmony/config/kit_host.py new file mode 100644 index 000000000..9a630ad75 --- /dev/null +++ b/harmony/config/kit_host.py @@ -0,0 +1,124 @@ +# coding: utf-8 +"""***************************************************************************** +* Copyright (C) 2019 Microchip Technology Inc. and its subsidiaries. +* +* Subject to your compliance with these terms, you may use Microchip software +* and any derivatives exclusively with Microchip products. It is your +* responsibility to comply with third party license terms applicable to your +* use of third party software (including open source software) that may +* accompany Microchip software. +* +* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER +* EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED +* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A +* PARTICULAR PURPOSE. +* +* IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, +* INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND +* WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS +* BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE +* FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN +* ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, +* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. +*****************************************************************************""" +import os +import glob + +fileSymbolName = "CAL_FILE_SRC_KIT_HOST_" +numFileCntr = 0 + + +def handleMessage(messageID, args): + return {} + + +def updateSercomPlibList(plib, inc): + Database.sendMessage('cryptoauthlib', 'UPDATE_PLIB_LIST', {'id': plib.lower(), 'inc': inc}) + + +def onAttachmentConnected(source, target): + if "uart" in target['id'].lower(): + source['component'].getSymbolByID('HAL_INTERFACE').setValue(target['id']) + updateSercomPlibList(target['id'], True) + + +def onAttachmentDisconnected(source, target): + if "uart" in target['id'].lower(): + source['component'].getSymbolByID('HAL_INTERFACE').clearValue() + updateSercomPlibList(target['id'], False) + + +def CALSecFileUpdate(symbol, event): + symObj = event['symbol'] + selected_key = symObj.getSelectedKey() + + if selected_key == "SECURE": + symbol.setSecurity("SECURE") + elif selected_key == "NON_SECURE": + symbol.setSecurity("NON_SECURE") + + +def AddFile(component, src_path, dest_path, proj_path, file_type = "SOURCE", isMarkup = False, enable=True): + global fileSymbolName + global numFileCntr + srcFile = component.createFileSymbol(fileSymbolName + str(numFileCntr) , None) + srcFile.setSourcePath(src_path) + srcFile.setDestPath(dest_path) + srcFile.setProjectPath(proj_path) + srcFile.setType(file_type) + srcFile.setOutputName(os.path.basename(src_path)) + srcFile.setMarkup(isMarkup) + srcFile.setEnabled(enable) + srcFile.setDependencies(CALSecFileUpdate, ["CAL_NON_SECURE"]) + numFileCntr += 1 + + +def AddFilesDir(component, base_path, search_pattern, destination_path, project_path, enable=True): + modulePath = os.path.expanduser(Module.getPath()) + + filelist = glob.iglob(modulePath + os.sep + base_path + os.sep + search_pattern) + + for x in filelist: + _, ext = os.path.splitext(x) + if ext in ['.c','.h']: + source_path = os.path.relpath(os.path.abspath(x), modulePath) + file_path = str(os.path.dirname(os.path.relpath(source_path, base_path))) + file_destination = destination_path + os.sep + file_path + file_project = project_path + '/' + file_path + AddFile(component, source_path, file_destination, file_project.replace('\\','/'), + file_type='HEADER' if ext is 'h' else 'SOURCE', enable=enable) + + +def instantiateComponent(kitHostComponent): + # Makes sure the Library is included as well. + Database.activateComponents(['cryptoauthlib']) + + configName = Variables.get("__CONFIGURATION_NAME") + + kitHostPlib = kitHostComponent.createStringSymbol("HAL_INTERFACE", None) + kitHostPlib.setLabel("PLIB Used") + kitHostPlib.setReadOnly(True) + kitHostPlib.setDefaultValue("") + + AddFilesDir(kitHostComponent, 'app/kit_host', 'ascii_kit_host.c', 'library/cryptoauthlib/kit_host', + 'config/{}/library/cryptoauthlib/kit_host'.format(configName)) + AddFilesDir(kitHostComponent, 'app/kit_host', 'ascii_kit_host.h', 'library/cryptoauthlib/kit_host', + 'config/{}/library/cryptoauthlib/kit_host'.format(configName)) + + AddFilesDir(kitHostComponent, 'lib/hal', 'kit_protocol.c', 'library/cryptoauthlib/hal', + 'config/{}/library/cryptoauthlib/hal'.format(configName)) + AddFilesDir(kitHostComponent, 'lib/hal', 'kit_protocol.h', 'library/cryptoauthlib/hal', + 'config/{}/library/cryptoauthlib/hal'.format(configName)) + + + calKitHostInitFile = kitHostComponent.createFileSymbol("CAL_KIT_HOST_DATA", None) + calKitHostInitFile.setSourcePath("harmony/templates/kit_host_init.c.ftl") + calKitHostInitFile.setOutputName("kit_host_init.c") + calKitHostInitFile.setDestPath("library/cryptoauthlib/kit_host") + calKitHostInitFile.setProjectPath("config/" + configName + "/library/cryptoauthlib/kit_host") + calKitHostInitFile.setType("SOURCE") + calKitHostInitFile.setOverwrite(True) + calKitHostInitFile.setMarkup(True) + calKitHostInitFile.setDependencies(CALSecFileUpdate, ["cryptoauthlib.CAL_NON_SECURE"]) + + diff --git a/harmony/config/test_app.py b/harmony/config/test_app.py index ec6cc7240..953747248 100644 --- a/harmony/config/test_app.py +++ b/harmony/config/test_app.py @@ -43,6 +43,21 @@ def CALSecFileUpdate(symbol, event): symbol.setSecurity("NON_SECURE") +def add_value_to_list(symbol_list, value): + values = list(symbol_list.getValues()) + if value not in values: + symbol_list.addValue(value) + + +def del_value_from_list(symbol_list, value): + values = list(symbol_list.getValues()) + if value in values: + symbol_list.clearValues() + values.remove(value) + for v in values: + symbol_list.addValue(v) + + def AddFile(component, src_path, dest_path, proj_path, file_type = "SOURCE", isMarkup = False, enable=True): global fileSymbolName global numFileCntr @@ -81,6 +96,9 @@ def AddFilesDir(component, base_path, search_pattern, destination_path, project_ file_type='HEADER' if ext is 'h' else 'SOURCE', enable=enable) +def handleMessage(messageID, args): + return {} + def onAttachmentConnected(source, target): pass @@ -125,3 +143,21 @@ def instantiateComponent(calTestingApplication): AddFilesDir(calTestingApplication, 'third_party/unity', '*', 'library/cryptoauthlib/third_party/unity', 'config/{}/library/cryptoauthlib/third_party/unity'.format(configName)) + calLibDevCfgFile = calTestingApplication.createFileSymbol("CAL_LIB_DEV_CFG_DATA", None) + calLibDevCfgFile.setSourcePath("harmony/templates/atca_devcfg_list.h.ftl") + calLibDevCfgFile.setOutputName("atca_devcfg_list.h") + calLibDevCfgFile.setDestPath("library/cryptoauthlib") + calLibDevCfgFile.setProjectPath("config/" + configName + "/library/cryptoauthlib/") + calLibDevCfgFile.setType("HEADER") + calLibDevCfgFile.setOverwrite(True) + calLibDevCfgFile.setMarkup(True) + calLibDevCfgFile.setDependencies(CALSecFileUpdate, ["cryptoauthlib.CAL_NON_SECURE"]) + + calTester = calTestingApplication.createBooleanSymbol("MULTIPLE_IFACE_SELECTED", None) + calTester.setLabel("TEST MULTIPLE INSTANCES") + calTester.setDefaultValue(False) + calTester.setVisible(True) + + calTesterCmnt = calTestingApplication.createCommentSymbol("MULTIPLE_IFACE_COMMENT", calTester) + calTesterCmnt.setLabel("!! Set if Multiple devices and interfaces are selected !! ") + calTesterCmnt.setVisible(True) diff --git a/harmony/module.py b/harmony/module.py index 815d67242..7cd8ab204 100644 --- a/harmony/module.py +++ b/harmony/module.py @@ -45,6 +45,11 @@ def loadModule(): cryptoAuthLibTest.setDisplayType("Library Testing Application") cryptoAuthLibTest.addDependency("CAL_LIB_CAP", "CA_LIB", True, False) + cryptoAuthLibKitHost = Module.CreateSharedComponent("cryptoauthlib_kit_host", "Kit Host", "/Libraries/Cryptoauthlib", "/harmony/config/kit_host.py") + cryptoAuthLibKitHost.setDisplayType("Cryptoauth Kit Protocol Host") + cryptoAuthLibKitHost.addDependency("CAL_LIB_CAP", "CA_LIB", True, False) + cryptoAuthLibKitHost.addDependency("UART", "UART", None, False, False) + # cryptoAuthLibSwiBB = Module.CreateSharedComponent("cryptoauthlib_swibb", "SWI_BB", "/Libraries/Cryptoauthlib", "/harmony/config/swi_bb.py") # cryptoAuthLibSwiBB.setDisplayType("SWI BitBang Hal Interface") # cryptoAuthLibSwiBB.addDependency("CAL_LIB_CAP", "CA_LIB", True, False) diff --git a/harmony/templates/atca_config.h.ftl b/harmony/templates/atca_config.h.ftl index 384d22dcd..1d4eecda2 100644 --- a/harmony/templates/atca_config.h.ftl +++ b/harmony/templates/atca_config.h.ftl @@ -61,13 +61,22 @@ <#if CAL_ENABLE_RTOS> +/** Define platform malloc/free */ +#define ATCA_PLATFORM_MALLOC OSAL_Malloc +#define ATCA_PLATFORM_FREE OSAL_Free + /** Use RTOS timers (i.e. delays that yield when the scheduler is running) */ #ifndef ATCA_USE_RTOS_TIMER #define ATCA_USE_RTOS_TIMER (1) #endif + #define atca_delay_ms hal_rtos_delay_ms #define atca_delay_us hal_delay_us <#else> +/** Define platform malloc/free */ +#define ATCA_PLATFORM_MALLOC malloc +#define ATCA_PLATFORM_FREE free + #define atca_delay_ms hal_delay_ms #define atca_delay_us hal_delay_us @@ -88,11 +97,16 @@ /* Define generic interfaces to the processor libraries */ +<#assign is_atca_plib_i2c_exists = "False"> +<#assign is_atca_plib_spi_exists = "False"> +<#assign is_atca_plib_uart_exists = "False"> +<#assign is_atca_plib_bb_exists = "False"> <#assign pliblist = CAL_PLIB_LIST?word_list> <#if pliblist?size != 0> <#list pliblist as plib_id> <#assign plib_info = plib_id?split("_", 1)> <#if plib_info[1] == "i2c"> +<#if is_atca_plib_i2c_exists == "False"> <#assign size_var = "size_t"> <#if plib_id?contains("sercom")> #define PLIB_I2C_ERROR SERCOM_I2C_ERROR @@ -119,7 +133,7 @@ typedef bool (* atca_i2c_plib_is_busy)( void ); typedef PLIB_I2C_ERROR (* atca_i2c_error_get)( void ); typedef bool (* atca_i2c_plib_transfer_setup)(PLIB_I2C_TRANSFER_SETUP* setup, uint32_t srcClkFreq); -typedef struct atca_plib_api +typedef struct atca_plib_i2c_api { atca_i2c_plib_read read; atca_i2c_plib_write write; @@ -127,9 +141,12 @@ typedef struct atca_plib_api atca_i2c_error_get error_get; atca_i2c_plib_transfer_setup transfer_setup; } atca_plib_i2c_api_t; +<#assign is_atca_plib_i2c_exists = "True"> + <#if plib_info[1] == "spi"> +<#if is_atca_plib_spi_exists == "False"> typedef bool (* atca_spi_plib_read)( void * , size_t ); typedef bool (* atca_spi_plib_write)( void *, size_t ); typedef bool (* atca_spi_plib_is_busy)( void ); @@ -142,10 +159,12 @@ typedef struct atca_plib_spi_api atca_spi_plib_is_busy is_busy; atca_spi_plib_select select; } atca_plib_spi_api_t; +<#assign is_atca_plib_spi_exists = "True"> + -<#if plib_info[1] == "swi"> -<#if plib_info[2] == "uart"> +<#if plib_info[1] == "swi" && plib_info[2] == "uart" || plib_info[1] == "uart"> +<#if is_atca_plib_uart_exists == "False"> <#if plib_id?contains("flexcom")> #define PLIB_SWI_ERROR FLEXCOM_USART_ERROR #define PLIB_SWI_SERIAL_SETUP FLEXCOM_USART_SERIAL_SETUP @@ -175,26 +194,29 @@ typedef struct atca_plib_spi_api #define PLIB_SWI_EVENT USART_EVENT -typedef size_t (* atca_swi_plib_read)( uint8_t *, const size_t ); -typedef size_t (* atca_swi_plib_write)( uint8_t *, const size_t ); -typedef PLIB_SWI_ERROR (* atca_swi_error_get)( void ); -typedef bool (* atca_swi_plib_serial_setup)(PLIB_SWI_SERIAL_SETUP* , uint32_t ); -typedef size_t (* atca_swi_plib_readcount_get)( void ); -typedef void (* atca_swi_plib_readcallbackreg)(PLIB_SWI_READ_CALLBACK, uintptr_t ); +typedef size_t (* atca_uart_plib_read)( uint8_t *, const size_t ); +typedef size_t (* atca_uart_plib_write)( uint8_t *, const size_t ); +typedef PLIB_SWI_ERROR (* atca_uart_error_get)( void ); +typedef bool (* atca_uart_plib_serial_setup)(PLIB_SWI_SERIAL_SETUP* , uint32_t ); +typedef size_t (* atca_uart_plib_readcount_get)( void ); +typedef void (* atca_uart_plib_readcallbackreg)(PLIB_SWI_READ_CALLBACK, uintptr_t ); -typedef struct atca_plib_swi_api +typedef struct atca_plib_uart_api { - atca_swi_plib_read read; - atca_swi_plib_write write; - atca_swi_error_get error_get; - atca_swi_plib_serial_setup serial_setup; - atca_swi_plib_readcount_get readcount_get; - atca_swi_plib_readcallbackreg readcallback_reg; -} atca_plib_swi_uart_api_t; + atca_uart_plib_read read; + atca_uart_plib_write write; + atca_uart_error_get error_get; + atca_uart_plib_serial_setup serial_setup; + atca_uart_plib_readcount_get readcount_get; + atca_uart_plib_readcallbackreg readcallback_reg; +} atca_plib_uart_api_t; + +<#assign is_atca_plib_uart_exists = "True"> /** SWI Transmit delay */ #define SWI_TX_DELAY ((uint32_t)90) <#elseif plib_info[2] == "bb"> +<#if is_atca_plib_bb_exists == "False"> typedef bool (* atca_swi_plib_read)( uint8_t ); typedef void (* atca_swi_plib_write)( uint8_t, bool ); typedef void (* atca_swi_set_pin_output)( uint8_t ); @@ -207,6 +229,7 @@ typedef struct atca_plib_swi_api atca_swi_set_pin_output set_pin_output_dir; atca_swi_set_pin_input set_pin_input_dir; }atca_plib_swi_bb_api_t; +<#assign is_atca_plib_bb_exists = "True"> /** * \name Macros for Bit-Banged SWI Timing @@ -233,6 +256,7 @@ typedef struct atca_plib_swi_api //! should be 93 us (Setting little less value as there would be other process before these steps) #define RX_TX_DELAY atca_delay_us(65) + @@ -275,5 +299,10 @@ extern atca_plib_${plib_drv!"i2c"}_api_t ${plib_info[0]}_plib_${plib_drv!"i2c"}_ #define ATCA_WOLFSSL +<#assign devcfglist = CAL_DEV_CFG_LIST?word_list> +<#if devcfglist?size != 0> +#define ATCA_TEST_MULTIPLE_INSTANCES + + #endif // ATCA_CONFIG_H diff --git a/harmony/templates/atca_devcfg_list.h.ftl b/harmony/templates/atca_devcfg_list.h.ftl new file mode 100644 index 000000000..9583ee4e2 --- /dev/null +++ b/harmony/templates/atca_devcfg_list.h.ftl @@ -0,0 +1,16 @@ +#include "cryptoauthlib.h" + +<#assign devcfglist = cryptoauthlib.CAL_DEV_CFG_LIST?word_list> +<#if devcfglist?size != 0> +<#list devcfglist as devcfg_id> +extern ATCAIfaceCfg ${devcfg_id}; + + + +<#if devcfglist?size != 0> +ATCAIfaceCfg *devcfg_list[] = { +<#list devcfglist as devcfg_id> + &${devcfg_id}, + +}; + \ No newline at end of file diff --git a/harmony/templates/hal_harmony_init.c.ftl b/harmony/templates/hal_harmony_init.c.ftl index 2d4e77973..2f59eb396 100644 --- a/harmony/templates/hal_harmony_init.c.ftl +++ b/harmony/templates/hal_harmony_init.c.ftl @@ -44,6 +44,7 @@ atca_plib_i2c_api_t ${plib_info[0]}_plib_i2c_api = { .is_busy = ${.vars["${plib_info[0]}"].I2C_PLIB_API_PREFIX}_IsBusy, .error_get = ${.vars["${plib_info[0]}"].I2C_PLIB_API_PREFIX}_ErrorGet, .transfer_setup = ${.vars["${plib_info[0]}"].I2C_PLIB_API_PREFIX}_TransferSetup +}; <#elseif plib_info[1] == "spi"> static void ${plib_info[0]}_select_pin(uint32_t pin, bool value) { @@ -55,15 +56,16 @@ atca_plib_spi_api_t ${plib_info[0]}_plib_spi_api = { .write = ${.vars["${plib_info[0]}"].SPI_PLIB_API_PREFIX}_Write, .is_busy = ${.vars["${plib_info[0]}"].SPI_PLIB_API_PREFIX}_IsBusy, .select = &${plib_info[0]}_select_pin -<#elseif plib_info[1] == "swi"> -<#if plib_info[2] == "uart"> -atca_plib_swi_uart_api_t ${plib_info[0]}_plib_swi_uart_api = { +}; +<#elseif plib_info[1] == "swi" && plib_info[2] == "uart" || plib_info[1] == "uart"> +atca_plib_uart_api_t ${plib_info[0]}_plib_uart_api = { .read = ${.vars["${plib_info[0]}"].USART_PLIB_API_PREFIX}_Read, .write = ${.vars["${plib_info[0]}"].USART_PLIB_API_PREFIX}_Write, .error_get = ${.vars["${plib_info[0]}"].USART_PLIB_API_PREFIX}_ErrorGet, .serial_setup = ${.vars["${plib_info[0]}"].USART_PLIB_API_PREFIX}_SerialSetup, .readcount_get = ${.vars["${plib_info[0]}"].USART_PLIB_API_PREFIX}_ReadCountGet, .readcallback_reg = ${.vars["${plib_info[0]}"].USART_PLIB_API_PREFIX}_ReadCallbackRegister +}; <#elseif plib_info[1] == "gpio"> static void ${plib_info[0]}_SetupPinDirection(uint32_t pin, uint8_t pin_dir) { @@ -90,9 +92,9 @@ atca_plib_gpio_api_t ${plib_info[0]}_plib_gpio_api = { .read = ${.vars["${plib_info[0]}"].GPIO_PLIB_API_PREFIX}_Read, .write = ${.vars["${plib_info[0]}"].GPIO_PLIB_API_PREFIX}_Write, .pin_setup = ${.vars["${plib_info[0]}"].GPIO_PLIB_API_PREFIX}_SetupPinDirection - - }; + + diff --git a/harmony/templates/kit_host_init.c.ftl b/harmony/templates/kit_host_init.c.ftl new file mode 100644 index 000000000..62ccb3c6d --- /dev/null +++ b/harmony/templates/kit_host_init.c.ftl @@ -0,0 +1,72 @@ +/** + * \file + * \brief Kit Host Initialization Structures and Functions + + * \copyright (c) 2021 Microchip Technology Inc. and its subsidiaries. + * + * \page License + * + * Subject to your compliance with these terms, you may use Microchip software + * and any derivatives exclusively with Microchip products. It is your + * responsibility to comply with third party license terms applicable to your + * use of third party software (including open source software) that may + * accompany Microchip software. + * + * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED + * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A + * PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, + * SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE + * OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + * MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + * FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL + * LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED + * THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR + * THIS SOFTWARE. + */ + +#include "cryptoauthlib.h" +#include "kit_host/ascii_kit_host.h" + +<#assign plib_name = HAL_INTERFACE?split("_")[0]> +static ATCAIfaceCfg kit_host_init_data = { + .iface_type = ATCA_UART_IFACE, + .cfg_data = &${plib_name?lower_case}_plib_uart_api +}; + +<#assign devcfglist = cryptoauthlib.CAL_DEV_CFG_LIST?word_list> + +<#list devcfglist as devcfg_id> +extern ATCAIfaceCfg ${devcfg_id}; + + +static ATCAIfaceCfg * kit_host_iface_list[] = { +<#list devcfglist as devcfg_id> + &${devcfg_id}, + +}; + +static size_t kit_host_iface_list_count = sizeof(kit_host_iface_list) / sizeof(kit_host_iface_list[0]); + +static atca_hal_kit_phy_t kit_host_phy; +static atca_iface_t kit_host_iface; + + +ATCA_STATUS kit_host_app_init(ascii_kit_host_context_t * ctx) +{ + ATCA_STATUS status = initATCAIface(&kit_host_init_data, &kit_host_iface); + + if (ATCA_SUCCESS == status) + { + status = kit_host_init_phy(&kit_host_phy, &kit_host_iface); + } + + if (ATCA_SUCCESS == status) + { + status = kit_host_init(ctx, kit_host_iface_list, kit_host_iface_list_count, + &kit_host_phy, 0); + } + + return status; + +} diff --git a/harmony/templates/pkcs11_config.h.ftl b/harmony/templates/pkcs11_config.h.ftl index 86c08c63c..e863ce282 100644 --- a/harmony/templates/pkcs11_config.h.ftl +++ b/harmony/templates/pkcs11_config.h.ftl @@ -117,7 +117,9 @@ CK_RV pkcs11_config_load_objects(pkcs11_slot_ctx_ptr pSlot); CK_RV pkcs11_config_load(pkcs11_slot_ctx_ptr slot_ctx); CK_RV pkcs11_config_cert(pkcs11_lib_ctx_ptr pLibCtx, pkcs11_slot_ctx_ptr pSlot, pkcs11_object_ptr pObject, CK_ATTRIBUTE_PTR pcLabel); CK_RV pkcs11_config_key(pkcs11_lib_ctx_ptr pLibCtx, pkcs11_slot_ctx_ptr pSlot, pkcs11_object_ptr pObject, CK_ATTRIBUTE_PTR pcLabel); +#if !PKCS11_USE_STATIC_CONFIG CK_RV pkcs11_config_remove_object(pkcs11_lib_ctx_ptr pLibCtx, pkcs11_slot_ctx_ptr pSlot, pkcs11_object_ptr pObject); +#endif void pkcs11_config_init_private(pkcs11_object_ptr pObject, char * label, size_t len); void pkcs11_config_init_public(pkcs11_object_ptr pObject, char * label, size_t len); diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 254c43434..bdc7891f8 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -10,6 +10,7 @@ option(ATCA_HAL_KIT_BRIDGE "General purpose kit protocol (Packet and Stream)") option(ATCA_HAL_I2C "Include the I2C Hal Driver - Linux & MCU only") option(ATCA_HAL_SPI "Include the SPI HAL Driver - Linux & MCU only") option(ATCA_HAL_CUSTOM "Include support for Custom/Plug-in Hal Driver") +option(ATCA_HAL_KIT_UART "Include th UART HAL Driver") # Library Options option(ATCA_PRINTF "Enable Debug print statements in library") @@ -262,7 +263,7 @@ set(USB_INCLUDE_DIR ${LIBUSB_INCLUDE_DIR}) set(HID_SRC ../third_party/hidapi/libusb/hid.c) endif(USE_LIBUSB) -if(NEED_USB) +if(NEED_USB OR ATCA_HAL_KIT_UART) set(CRYPTOAUTH_SRC ${CRYPTOAUTH_SRC} hal/kit_protocol.c) endif() @@ -270,6 +271,14 @@ if(ATCA_HAL_KIT_HID) set(CRYPTOAUTH_SRC ${CRYPTOAUTH_SRC} ${HID_SRC} hal/hal_all_platforms_kit_hidapi.c) endif(ATCA_HAL_KIT_HID) +if(ATCA_HAL_KIT_UART) +if(WIN32) +set(CRYPTOAUTH_SRC ${CRYPTOAUTH_SRC} hal/hal_windows_kit_uart.c) +elseif(LINUX) +set(CRYPTOAUTH_SRC ${CRYPTOAUTH_SRC} hal/hal_linux_uart_userspace.c) +endif() +endif(ATCA_HAL_KIT_UART) + if(ATCA_HAL_KIT_CDC) set(CRYPTOAUTH_SRC ${CRYPTOAUTH_SRC} ${CDC_SRC}) endif(ATCA_HAL_KIT_CDC) diff --git a/lib/atca_basic.c b/lib/atca_basic.c index f63b0bb7f..685e1d93c 100644 --- a/lib/atca_basic.c +++ b/lib/atca_basic.c @@ -106,6 +106,16 @@ ATCA_STATUS atcab_init_ext(ATCADevice* device, ATCAIfaceCfg *cfg) (*device)->clock_divider &= ATCA_CHIPMODE_CLOCK_DIV_MASK; } #endif + +#ifdef ATCA_ECC204_SUPPORT + /* To compatible with kitprotocol firmware on otherside */ + /* On kitprotocol firmware, during discovery time itself ECC204 would have woke up */ + if ((ECC204 == cfg->devtype) && (atca_iface_is_kit(atGetIFace(*device)))) + { + (*device)->device_state = ATCA_DEVICE_STATE_ACTIVE; + } +#endif + } return ATCA_SUCCESS; diff --git a/lib/atca_bool.h b/lib/atca_bool.h index 37ae1e065..5707b71bc 100644 --- a/lib/atca_bool.h +++ b/lib/atca_bool.h @@ -40,4 +40,4 @@ #include #endif -#endif \ No newline at end of file +#endif diff --git a/lib/atca_cfgs.c b/lib/atca_cfgs.c index 0ad7a7e77..2e5f158ed 100644 --- a/lib/atca_cfgs.c +++ b/lib/atca_cfgs.c @@ -49,8 +49,11 @@ ATCAIfaceCfg cfg_ateccx08a_i2c_default = { .atcai2c.address = 0xC0, #endif .atcai2c.bus = 2, +#ifdef __linux__ + .atcai2c.baud = 100000, +#else .atcai2c.baud = 400000, - //.atcai2c.baud = 100000, +#endif }, .wake_delay = 1500, .rx_retries = 20 @@ -114,7 +117,11 @@ ATCAIfaceCfg cfg_atsha20xa_i2c_default = { .atcai2c.address = 0xC8, #endif .atcai2c.bus = 2, +#ifdef __linux__ + .atcai2c.baud = 100000, +#else .atcai2c.baud = 400000, +#endif }, .wake_delay = 2560, .rx_retries = 20 @@ -176,8 +183,11 @@ ATCAIfaceCfg cfg_ecc204_i2c_default = { .atcai2c.address = 0x33, #endif .atcai2c.bus = 2, +#ifdef __linux__ + .atcai2c.baud = 100000, +#else .atcai2c.baud = 400000, - //.atcai2c.baud = 100000, +#endif }, .wake_delay = 1500, .rx_retries = 20 diff --git a/lib/atca_cfgs.h b/lib/atca_cfgs.h index c6b4077e0..72f0f4a31 100644 --- a/lib/atca_cfgs.h +++ b/lib/atca_cfgs.h @@ -75,4 +75,4 @@ extern ATCAIfaceCfg cfg_ecc204_kithid_default; #ifdef __cplusplus } #endif -#endif /* ATCA_CFGS_H_ */ \ No newline at end of file +#endif /* ATCA_CFGS_H_ */ diff --git a/lib/atca_config.h.in b/lib/atca_config.h.in index 379b4eba8..720794cb8 100644 --- a/lib/atca_config.h.in +++ b/lib/atca_config.h.in @@ -3,6 +3,7 @@ #define ATCA_CONFIG_H /* Included HALS */ +#cmakedefine ATCA_HAL_KIT_UART #cmakedefine ATCA_HAL_KIT_HID #cmakedefine ATCA_HAL_I2C #cmakedefine ATCA_HAL_SPI diff --git a/lib/atca_debug.h b/lib/atca_debug.h index bcaec219a..fbe6847b1 100644 --- a/lib/atca_debug.h +++ b/lib/atca_debug.h @@ -1,5 +1,3 @@ - - #ifndef _ATCA_DEBUG_H #define _ATCA_DEBUG_H diff --git a/lib/atca_device.c b/lib/atca_device.c index 5ab897070..855e63883 100644 --- a/lib/atca_device.c +++ b/lib/atca_device.c @@ -47,7 +47,7 @@ ATCADevice newATCADevice(ATCAIfaceCfg *cfg) return NULL; } - ca_dev = (ATCADevice)malloc(sizeof(*ca_dev)); + ca_dev = (ATCADevice)hal_malloc(sizeof(*ca_dev)); if (ca_dev == NULL) { return NULL; @@ -58,7 +58,7 @@ ATCADevice newATCADevice(ATCAIfaceCfg *cfg) status = initATCADevice(cfg, ca_dev); if (status != ATCA_SUCCESS) { - free(ca_dev); + hal_free(ca_dev); ca_dev = NULL; return NULL; } @@ -78,7 +78,7 @@ void deleteATCADevice(ATCADevice *ca_dev) releaseATCADevice(*ca_dev); - free(*ca_dev); + hal_free(*ca_dev); *ca_dev = NULL; } #endif diff --git a/lib/atca_devtypes.h b/lib/atca_devtypes.h index 4c24e39ee..ba8f82d46 100644 --- a/lib/atca_devtypes.h +++ b/lib/atca_devtypes.h @@ -56,4 +56,4 @@ typedef enum } #endif /** @} */ -#endif /* ATCA_DEVTYPES_H_ */ \ No newline at end of file +#endif /* ATCA_DEVTYPES_H_ */ diff --git a/lib/atca_iface.c b/lib/atca_iface.c index d2a72cc33..b7010e38d 100644 --- a/lib/atca_iface.c +++ b/lib/atca_iface.c @@ -70,11 +70,11 @@ ATCAIface newATCAIface(ATCAIfaceCfg *cfg) ATCAIface ca_iface; ATCA_STATUS status; - ca_iface = (ATCAIface)malloc(sizeof(struct atca_iface)); + ca_iface = (ATCAIface)hal_malloc(sizeof(struct atca_iface)); status = initATCAIface(cfg, ca_iface); if (status != ATCA_SUCCESS) { - free(ca_iface); + hal_free(ca_iface); ca_iface = NULL; return NULL; } @@ -336,7 +336,8 @@ bool atca_iface_is_kit(ATCAIface ca_iface) if (ca_iface && ca_iface->mIfaceCFG) { - if (ATCA_HID_IFACE == ca_iface->mIfaceCFG->iface_type || ATCA_KIT_IFACE == ca_iface->mIfaceCFG->iface_type) + if (ATCA_HID_IFACE == ca_iface->mIfaceCFG->iface_type || ATCA_KIT_IFACE == ca_iface->mIfaceCFG->iface_type + || ATCA_UART_IFACE == ca_iface->mIfaceCFG->iface_type) { ret = true; } @@ -407,7 +408,7 @@ void deleteATCAIface(ATCAIface *ca_iface) if (ca_iface) { releaseATCAIface(*ca_iface); - free(*ca_iface); + hal_free(*ca_iface); *ca_iface = NULL; } } diff --git a/lib/atca_iface.h b/lib/atca_iface.h index f98e1fe4e..58d35f185 100644 --- a/lib/atca_iface.h +++ b/lib/atca_iface.h @@ -40,8 +40,11 @@ extern "C" { #endif -#include "atca_devtypes.h" #include +#include + +#include "atca_config.h" +#include "atca_devtypes.h" #include "atca_status.h" @@ -69,7 +72,8 @@ typedef enum ATCA_KIT_I2C_IFACE, ATCA_KIT_SWI_IFACE, ATCA_KIT_SPI_IFACE, - ATCA_KIT_UNKNOWN_IFACE } ATCAKitType; + ATCA_KIT_UNKNOWN_IFACE +} ATCAKitType; /* ATCAIfaceCfg is the configuration object for a device @@ -109,11 +113,13 @@ typedef struct struct { - int port; // logic port number - uint32_t baud; // typically 115200 - uint8_t wordsize; // usually 8 - uint8_t parity; // 0 == even, 1 == odd, 2 == none - uint8_t stopbits; // 0,1,2 + ATCAKitType dev_interface; // Kit interface type + uint8_t dev_identity; // I2C address for the I2C interface device or the bus number for the SWI interface device. + uint8_t port; // Port numbers where supported - otherwise accept the device through config data + uint32_t baud; // typically 115200 + uint8_t wordsize; // usually 8 + uint8_t parity; // 0 == even, 1 == odd, 2 == none + uint8_t stopbits; // 0,1,2 } atcauart; struct @@ -207,6 +213,3 @@ uint16_t atca_iface_get_wake_delay(ATCAIface ca_iface); /*lint -flb*/ /** @} */ #endif - - - diff --git a/lib/atca_version.h b/lib/atca_version.h index b2eccb5fc..f46f169a1 100644 --- a/lib/atca_version.h +++ b/lib/atca_version.h @@ -30,9 +30,9 @@ #define _ATCA_VERSION_H // Version format yyyymmdd -#define ATCA_LIBRARY_VERSION_DATE "20210514" +#define ATCA_LIBRARY_VERSION_DATE "20210126" #define ATCA_LIBRARY_VERSION_MAJOR 3 #define ATCA_LIBRARY_VERSION_MINOR 3 -#define ATCA_LIBRARY_VERSION_BUILD 1 +#define ATCA_LIBRARY_VERSION_BUILD 0 #endif /* _ATCA_VERSION_H */ diff --git a/lib/atcacert/atcacert.h b/lib/atcacert/atcacert.h index 23b755dbc..fb765f260 100644 --- a/lib/atcacert/atcacert.h +++ b/lib/atcacert/atcacert.h @@ -63,4 +63,4 @@ #define ATCACERT_E_INVALID_TRANSFORM 13 //!< Invalid transform passed to function. /** @} */ -#endif \ No newline at end of file +#endif diff --git a/lib/atcacert/atcacert_client.h b/lib/atcacert/atcacert_client.h index 380772928..fcc71aa6c 100644 --- a/lib/atcacert/atcacert_client.h +++ b/lib/atcacert/atcacert_client.h @@ -172,4 +172,4 @@ int atcacert_read_cert_size(const atcacert_def_t* cert_def, } #endif -#endif \ No newline at end of file +#endif diff --git a/lib/atcacert/atcacert_def.c b/lib/atcacert/atcacert_def.c index a9a970227..097d2bc05 100644 --- a/lib/atcacert/atcacert_def.c +++ b/lib/atcacert/atcacert_def.c @@ -1778,4 +1778,4 @@ int atcacert_max_cert_size(const atcacert_def_t* cert_def, } return ATCACERT_E_SUCCESS; -} \ No newline at end of file +} diff --git a/lib/atcacert/atcacert_def.h b/lib/atcacert/atcacert_def.h index dd9eddd5c..1a48557ef 100644 --- a/lib/atcacert/atcacert_def.h +++ b/lib/atcacert/atcacert_def.h @@ -822,4 +822,3 @@ int atcacert_max_cert_size(const atcacert_def_t* cert_def, #endif #endif - diff --git a/lib/atcacert/atcacert_der.h b/lib/atcacert/atcacert_der.h index c1f71cb8c..98d3c3f3f 100644 --- a/lib/atcacert/atcacert_der.h +++ b/lib/atcacert/atcacert_der.h @@ -162,4 +162,4 @@ int atcacert_der_dec_ecdsa_sig_value(const uint8_t * der_sig, } #endif -#endif \ No newline at end of file +#endif diff --git a/lib/atcacert/atcacert_host_hw.c b/lib/atcacert/atcacert_host_hw.c index 5cd0322c1..7388aad5e 100644 --- a/lib/atcacert/atcacert_host_hw.c +++ b/lib/atcacert/atcacert_host_hw.c @@ -102,4 +102,4 @@ int atcacert_verify_response_hw(const uint8_t device_public_key[64], } return is_verified ? ATCACERT_E_SUCCESS : ATCACERT_E_VERIFY_FAILED; -} \ No newline at end of file +} diff --git a/lib/atcacert/atcacert_host_hw.h b/lib/atcacert/atcacert_host_hw.h index 756545b96..a646201e3 100644 --- a/lib/atcacert/atcacert_host_hw.h +++ b/lib/atcacert/atcacert_host_hw.h @@ -103,4 +103,4 @@ int atcacert_verify_response_hw(const uint8_t device_public_key[64], } #endif -#endif \ No newline at end of file +#endif diff --git a/lib/atcacert/atcacert_host_sw.c b/lib/atcacert/atcacert_host_sw.c index 6fbebd9a8..e3069c616 100644 --- a/lib/atcacert/atcacert_host_sw.c +++ b/lib/atcacert/atcacert_host_sw.c @@ -94,4 +94,4 @@ int atcacert_verify_response_sw(const uint8_t device_public_key[64], } return atcac_sw_ecdsa_verify_p256(challenge, response, device_public_key); -} \ No newline at end of file +} diff --git a/lib/atcacert/atcacert_host_sw.h b/lib/atcacert/atcacert_host_sw.h index 70d5d399f..0531afcfe 100644 --- a/lib/atcacert/atcacert_host_sw.h +++ b/lib/atcacert/atcacert_host_sw.h @@ -103,4 +103,4 @@ int atcacert_verify_response_sw(const uint8_t device_public_key[64], } #endif -#endif \ No newline at end of file +#endif diff --git a/lib/atcacert/atcacert_pem.h b/lib/atcacert/atcacert_pem.h index 14fc79ae6..f7fb4df32 100644 --- a/lib/atcacert/atcacert_pem.h +++ b/lib/atcacert/atcacert_pem.h @@ -123,4 +123,4 @@ int atcacert_decode_pem_csr(const char* pem_csr, size_t pem_csr_size, uint8_t* d } #endif -#endif \ No newline at end of file +#endif diff --git a/lib/calib/calib_aes_gcm.h b/lib/calib/calib_aes_gcm.h index 287d9f794..c242f59c7 100644 --- a/lib/calib/calib_aes_gcm.h +++ b/lib/calib/calib_aes_gcm.h @@ -73,4 +73,4 @@ ATCA_STATUS calib_aes_gcm_decrypt_finish(ATCADevice device, atca_aes_gcm_ctx_t* /** @} */ -#endif \ No newline at end of file +#endif diff --git a/lib/calib/calib_basic.h b/lib/calib/calib_basic.h index dbd972f5d..ee93ae07b 100644 --- a/lib/calib/calib_basic.h +++ b/lib/calib/calib_basic.h @@ -232,4 +232,4 @@ ATCA_STATUS calib_write_config_counter(ATCADevice device, uint16_t counter_id, u /** @} */ -#endif \ No newline at end of file +#endif diff --git a/lib/calib/calib_command.h b/lib/calib/calib_command.h index 5fcac6d7b..949eb675c 100644 --- a/lib/calib/calib_command.h +++ b/lib/calib/calib_command.h @@ -742,4 +742,3 @@ ATCA_STATUS atCheckCrc(const uint8_t *response); } #endif #endif - diff --git a/lib/calib/calib_ecdh.c b/lib/calib/calib_ecdh.c index bb1f12612..895efc753 100644 --- a/lib/calib/calib_ecdh.c +++ b/lib/calib/calib_ecdh.c @@ -272,4 +272,3 @@ ATCA_STATUS calib_ecdh_tempkey_ioenc(ATCADevice device, const uint8_t* public_ke return status; } - diff --git a/lib/calib/calib_execution.c b/lib/calib/calib_execution.c index 376eebf09..86449ea81 100644 --- a/lib/calib/calib_execution.c +++ b/lib/calib/calib_execution.c @@ -476,6 +476,10 @@ ATCA_STATUS calib_execute_command(ATCAPacket* packet, ATCADevice device) } else { + if (ATCA_DEVICE_STATE_ACTIVE != device->device_state) + { + device->device_state = ATCA_DEVICE_STATE_ACTIVE; + } retries = 0; } diff --git a/lib/calib/calib_execution.h b/lib/calib/calib_execution.h index 963156424..df94884e5 100644 --- a/lib/calib/calib_execution.h +++ b/lib/calib/calib_execution.h @@ -76,4 +76,3 @@ ATCA_STATUS calib_execute_command(ATCAPacket* packet, ATCADevice device); } #endif #endif - diff --git a/lib/calib/calib_genkey.c b/lib/calib/calib_genkey.c index 82562b065..539f4b69f 100644 --- a/lib/calib/calib_genkey.c +++ b/lib/calib/calib_genkey.c @@ -196,4 +196,4 @@ ATCA_STATUS calib_genkey_mac(ATCADevice device, uint8_t* public_key, uint8_t* ma } return status; -} \ No newline at end of file +} diff --git a/lib/calib/calib_lock.c b/lib/calib/calib_lock.c index defb6e317..6c3e91466 100644 --- a/lib/calib/calib_lock.c +++ b/lib/calib/calib_lock.c @@ -209,4 +209,4 @@ ATCA_STATUS calib_ecc204_lock_config_zone(ATCADevice device) ATCA_STATUS calib_ecc204_lock_data_slot(ATCADevice device, uint8_t slot) { return calib_lock(device, LOCK_ECC204_ZONE_DATA | (slot << 1), 0); -} \ No newline at end of file +} diff --git a/lib/calib/calib_nonce.c b/lib/calib/calib_nonce.c index 9f134e4d4..35e65fd73 100644 --- a/lib/calib/calib_nonce.c +++ b/lib/calib/calib_nonce.c @@ -233,4 +233,4 @@ ATCA_STATUS calib_nonce_gen_session_key(ATCADevice device, uint16_t param2, uint uint8_t* rand_out) { return calib_nonce_base(device, NONCE_MODE_GEN_SESSION_KEY, param2, num_in, rand_out); -} \ No newline at end of file +} diff --git a/lib/calib/calib_privwrite.c b/lib/calib/calib_privwrite.c index 28cdd1c34..db0733c36 100644 --- a/lib/calib/calib_privwrite.c +++ b/lib/calib/calib_privwrite.c @@ -188,4 +188,3 @@ ATCA_STATUS calib_priv_write(ATCADevice device, uint16_t key_id, const uint8_t p return status; } - diff --git a/lib/calib/calib_secureboot.c b/lib/calib/calib_secureboot.c index 2f0e882bf..0908cedf8 100644 --- a/lib/calib/calib_secureboot.c +++ b/lib/calib/calib_secureboot.c @@ -214,4 +214,4 @@ ATCA_STATUS calib_secureboot_mac(ATCADevice device, uint8_t mode, const uint8_t* while (0); return status; -} \ No newline at end of file +} diff --git a/lib/calib/calib_selftest.c b/lib/calib/calib_selftest.c index c23fb27a6..d49ab2f51 100644 --- a/lib/calib/calib_selftest.c +++ b/lib/calib/calib_selftest.c @@ -105,4 +105,3 @@ ATCA_STATUS calib_selftest(ATCADevice device, uint8_t mode, uint16_t param2, uin return status; } - diff --git a/lib/calib/calib_verify.c b/lib/calib/calib_verify.c index 241cc9d35..b810a48dd 100644 --- a/lib/calib/calib_verify.c +++ b/lib/calib/calib_verify.c @@ -461,4 +461,3 @@ ATCA_STATUS calib_verify_invalidate(ATCADevice device, uint16_t key_id, const ui return status; } - diff --git a/lib/calib/calib_write.c b/lib/calib/calib_write.c index 97d861196..5f8503b84 100644 --- a/lib/calib/calib_write.c +++ b/lib/calib/calib_write.c @@ -876,4 +876,4 @@ ATCA_STATUS calib_ecc204_write_bytes_zone(ATCADevice device, uint8_t zone, uint1 return status; } -#endif \ No newline at end of file +#endif diff --git a/lib/crypto/atca_crypto_hw_aes_cbc.c b/lib/crypto/atca_crypto_hw_aes_cbc.c index d7f2b9deb..3d92ffe43 100644 --- a/lib/crypto/atca_crypto_hw_aes_cbc.c +++ b/lib/crypto/atca_crypto_hw_aes_cbc.c @@ -160,4 +160,3 @@ ATCA_STATUS atcab_aes_cbc_decrypt_block(atca_aes_cbc_ctx_t* ctx, const uint8_t* return status; } - diff --git a/lib/crypto/atca_crypto_hw_aes_cbcmac.c b/lib/crypto/atca_crypto_hw_aes_cbcmac.c index ced6dd818..ef5f504ba 100644 --- a/lib/crypto/atca_crypto_hw_aes_cbcmac.c +++ b/lib/crypto/atca_crypto_hw_aes_cbcmac.c @@ -158,4 +158,4 @@ ATCA_STATUS atcab_aes_cbcmac_finish(atca_aes_cbcmac_ctx_t* ctx, uint8_t* mac, ui } return ATCA_SUCCESS; -} \ No newline at end of file +} diff --git a/lib/crypto/atca_crypto_hw_aes_cmac.c b/lib/crypto/atca_crypto_hw_aes_cmac.c index 3b28c85ad..b3425e7a2 100644 --- a/lib/crypto/atca_crypto_hw_aes_cmac.c +++ b/lib/crypto/atca_crypto_hw_aes_cmac.c @@ -232,4 +232,3 @@ ATCA_STATUS atcab_aes_cmac_finish(atca_aes_cmac_ctx_t* ctx, uint8_t* cmac, uint3 return ATCA_SUCCESS; } - diff --git a/lib/crypto/atca_crypto_hw_aes_ctr.c b/lib/crypto/atca_crypto_hw_aes_ctr.c index e647a6695..d580956f0 100644 --- a/lib/crypto/atca_crypto_hw_aes_ctr.c +++ b/lib/crypto/atca_crypto_hw_aes_ctr.c @@ -278,4 +278,3 @@ ATCA_STATUS atcab_aes_ctr_decrypt_block(atca_aes_ctr_ctx_t* ctx, const uint8_t* { return atcab_aes_ctr_block(ctx, ciphertext, plaintext); } - diff --git a/lib/crypto/atca_crypto_sw_ecdsa.h b/lib/crypto/atca_crypto_sw_ecdsa.h index 5644eba56..bb33b43c4 100644 --- a/lib/crypto/atca_crypto_sw_ecdsa.h +++ b/lib/crypto/atca_crypto_sw_ecdsa.h @@ -59,4 +59,4 @@ int atcac_sw_ecdsa_verify_p256(const uint8_t msg[ATCA_ECC_P256_FIELD_SIZE], #endif /** @} */ -#endif \ No newline at end of file +#endif diff --git a/lib/crypto/atca_crypto_sw_rand.h b/lib/crypto/atca_crypto_sw_rand.h index 9af8aee0e..dc282c150 100644 --- a/lib/crypto/atca_crypto_sw_rand.h +++ b/lib/crypto/atca_crypto_sw_rand.h @@ -50,4 +50,4 @@ int atcac_sw_random(uint8_t* data, size_t data_size); #endif /** @} */ -#endif \ No newline at end of file +#endif diff --git a/lib/crypto/atca_crypto_sw_sha1.c b/lib/crypto/atca_crypto_sw_sha1.c index 3f7af1d95..534a8c50e 100644 --- a/lib/crypto/atca_crypto_sw_sha1.c +++ b/lib/crypto/atca_crypto_sw_sha1.c @@ -104,4 +104,4 @@ int atcac_sw_sha1(const uint8_t* data, size_t data_size, uint8_t digest[ATCA_SHA } return ATCA_SUCCESS; -} \ No newline at end of file +} diff --git a/lib/crypto/atca_crypto_sw_sha1.h b/lib/crypto/atca_crypto_sw_sha1.h index 174df863f..7dd9979d2 100644 --- a/lib/crypto/atca_crypto_sw_sha1.h +++ b/lib/crypto/atca_crypto_sw_sha1.h @@ -56,4 +56,4 @@ int atcac_sw_sha1(const uint8_t * data, size_t data_size, uint8_t digest[ATCA_SH #endif /** @} */ -#endif \ No newline at end of file +#endif diff --git a/lib/crypto/atca_crypto_sw_sha2.h b/lib/crypto/atca_crypto_sw_sha2.h index be5266d06..def293b47 100644 --- a/lib/crypto/atca_crypto_sw_sha2.h +++ b/lib/crypto/atca_crypto_sw_sha2.h @@ -59,4 +59,4 @@ ATCA_STATUS atcac_sha256_hmac_counter(atcac_hmac_sha256_ctx* ctx, uint8_t* label #endif /** @} */ -#endif \ No newline at end of file +#endif diff --git a/lib/crypto/hashes/sha1_routines.c b/lib/crypto/hashes/sha1_routines.c index 745e54e6a..f386911e6 100644 --- a/lib/crypto/hashes/sha1_routines.c +++ b/lib/crypto/hashes/sha1_routines.c @@ -321,4 +321,4 @@ void shaEngine(U32 *buf, U32 *h) //p += 4; //} -} \ No newline at end of file +} diff --git a/lib/crypto/hashes/sha1_routines.h b/lib/crypto/hashes/sha1_routines.h index 16ee8e90a..8d69084a2 100644 --- a/lib/crypto/hashes/sha1_routines.h +++ b/lib/crypto/hashes/sha1_routines.h @@ -91,4 +91,3 @@ void CL_hash(U8 *msg, int msgBytes, U8 *dest); #endif #endif // __SHA1_ROUTINES_DOT_H__ - diff --git a/lib/crypto/hashes/sha2_routines.c b/lib/crypto/hashes/sha2_routines.c index 2dd6b9e9d..43f4deffc 100644 --- a/lib/crypto/hashes/sha2_routines.c +++ b/lib/crypto/hashes/sha2_routines.c @@ -254,4 +254,4 @@ void sw_sha256(const uint8_t* message, unsigned int len, uint8_t digest[SHA256_D sw_sha256_init(&ctx); sw_sha256_update(&ctx, message, len); sw_sha256_final(&ctx, digest); -} \ No newline at end of file +} diff --git a/lib/crypto/hashes/sha2_routines.h b/lib/crypto/hashes/sha2_routines.h index 7c7dd6d66..b01460603 100644 --- a/lib/crypto/hashes/sha2_routines.h +++ b/lib/crypto/hashes/sha2_routines.h @@ -58,4 +58,3 @@ void sw_sha256(const uint8_t * message, unsigned int len, uint8_t digest[SHA256_ #endif #endif // SHA2_ROUTINES_H - diff --git a/lib/hal/atca_hal.c b/lib/hal/atca_hal.c index 92f9a9403..790161896 100644 --- a/lib/hal/atca_hal.c +++ b/lib/hal/atca_hal.c @@ -61,7 +61,7 @@ static ATCAHAL_t hal_swi_uart = { }; #endif -#ifdef ATCA_HAL_UART +#if defined(ATCA_HAL_UART) || defined(ATCA_HAL_SWI_UART) || defined(ATCA_HAL_KIT_UART) static ATCAHAL_t hal_uart = { hal_uart_init, hal_uart_post_init, @@ -146,25 +146,27 @@ typedef struct static atca_hal_list_entry_t atca_registered_hal_list[ATCA_MAX_HAL_CACHE] = { #ifdef ATCA_HAL_I2C - { ATCA_I2C_IFACE, &hal_i2c, NULL }, + { ATCA_I2C_IFACE, &hal_i2c, NULL }, #endif #ifdef ATCA_HAL_SWI_UART - { ATCA_SWI_IFACE, &hal_swi_uart, &hal_uart }, + { ATCA_SWI_IFACE, &hal_swi_uart, &hal_uart }, #endif #ifdef ATCA_HAL_KIT_UART - { ATCA_UART_IFACE, &hal_kit_v1, &hal_uart }, + { ATCA_UART_IFACE, &hal_kit_v1, &hal_uart }, +#elif defined(ATCA_HAL_UART) + { ATCA_UART_IFACE, &hal_uart, NULL }, #endif #ifdef ATCA_HAL_SPI - { ATCA_SPI_IFACE, &hal_spi, NULL }, + { ATCA_SPI_IFACE, &hal_spi, NULL }, #endif #ifdef ATCA_HAL_KIT_HID - { ATCA_HID_IFACE, &hal_kit_v1, &hal_hid }, + { ATCA_HID_IFACE, &hal_kit_v1, &hal_hid }, #endif #ifdef ATCA_HAL_KIT_BRIDGE - { ATCA_KIT_IFACE, &hal_kit_bridge, NULL }, + { ATCA_KIT_IFACE, &hal_kit_bridge, NULL }, #endif #if ATCA_HAL_SWI_GPIO - { ATCA_SWI_GPIO_IFACE, &hal_gpio, NULL }, + { ATCA_SWI_GPIO_IFACE, &hal_gpio, NULL }, #endif }; @@ -331,6 +333,7 @@ ATCA_STATUS hal_iface_release(ATCAIfaceType iface_type, void *hal_data) if (ATCA_SUCCESS == status) { status = hal->halrelease ? hal->halrelease(hal_data) : ATCA_BAD_PARAM; + status = phy->halrelease ? phy->halrelease(hal_data) : ATCA_BAD_PARAM; } return status; diff --git a/lib/hal/atca_hal.h b/lib/hal/atca_hal.h index 121c0bbd2..654a2434a 100644 --- a/lib/hal/atca_hal.h +++ b/lib/hal/atca_hal.h @@ -35,8 +35,6 @@ #include "atca_status.h" #include "atca_iface.h" -#include "atca_start_config.h" -#include "atca_start_iface.h" /** \defgroup hal_ Hardware abstraction layer (hal_) @@ -105,7 +103,7 @@ ATCA_STATUS hal_gpio_release(void *hal_data); ATCA_STATUS hal_gpio_device_discovery(ATCAIface iface); #endif -#ifdef ATCA_HAL_UART +#if defined(ATCA_HAL_SWI_UART) || defined(ATCA_HAL_KIT_UART) || defined(ATCA_HAL_UART) ATCA_STATUS hal_uart_init(ATCAIface iface, ATCAIfaceCfg *cfg); ATCA_STATUS hal_uart_post_init(ATCAIface iface); ATCA_STATUS hal_uart_send(ATCAIface iface, uint8_t word_address, uint8_t *txdata, int txlength); diff --git a/lib/hal/atca_start_iface.h b/lib/hal/atca_start_iface.h index c290da949..0dd4ce0f0 100644 --- a/lib/hal/atca_start_iface.h +++ b/lib/hal/atca_start_iface.h @@ -3,4 +3,4 @@ when used with Atmel START, this file will be overwritten with the user configuration generated by Atmel START - */ \ No newline at end of file + */ diff --git a/lib/hal/hal_esp32_i2c.c b/lib/hal/hal_esp32_i2c.c new file mode 100644 index 000000000..1d023cc7c --- /dev/null +++ b/lib/hal/hal_esp32_i2c.c @@ -0,0 +1,277 @@ +/* + * Copyright 2018 Espressif Systems (Shanghai) PTE LTD + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "esp_err.h" +#include "esp_log.h" +#include "cryptoauthlib.h" + +#define I2C0_SDA_PIN 16 +#define I2C0_SCL_PIN 17 +#define I2C1_SDA_PIN 21 +#define I2C1_SCL_PIN 22 +#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/ +#define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */ +#define ACK_VAL 0x0 /*!< I2C ack value */ +#define NACK_VAL 0x1 /*!< I2C nack value */ + +#ifndef LOG_LOCAL_LEVEL +#define LOG_LOCAL_LEVEL ESP_LOG_INFO +#endif + +#define MAX_I2C_BUSES 2 //ESP32 has 2 I2C bus + +typedef struct atcaI2Cmaster +{ + int id; + i2c_config_t conf; + int ref_ct; +} ATCAI2CMaster_t; + +ATCAI2CMaster_t i2c_hal_data[MAX_I2C_BUSES]; + +const char* TAG = "HAL_I2C"; + +ATCA_STATUS status; + +/** \brief method to change the bus speec of I2C + * \param[in] iface interface on which to change bus speed + * \param[in] speed baud rate (typically 100000 or 400000) + */ +ATCA_STATUS hal_i2c_change_baud(ATCAIface iface, uint32_t speed) +{ + esp_err_t rc; + ATCAIfaceCfg *cfg = atgetifacecfg(iface); + int bus = cfg->atcai2c.bus; + + i2c_hal_data[bus].conf.master.clk_speed = speed; + + rc = i2c_param_config(i2c_hal_data[bus].id, &i2c_hal_data[bus].conf); + if (rc == ESP_OK) + { + //ESP_LOGD(TAG, "Baudrate Changed"); + return ATCA_SUCCESS; + } + else + { + //ESP_LOGW(TAG, "Baudrate Change Failed"); + return ATCA_COMM_FAIL; + } +} + +/** \brief + - this HAL implementation assumes you've included the START Twi libraries in your project, otherwise, + the HAL layer will not compile because the START TWI drivers are a dependency * + */ + +/** \brief hal_i2c_init manages requests to initialize a physical interface. it manages use counts so when an interface + * has released the physical layer, it will disable the interface for some other use. + * You can have multiple ATCAIFace instances using the same bus, and you can have multiple ATCAIFace instances on + * multiple i2c buses, so hal_i2c_init manages these things and ATCAIFace is abstracted from the physical details. + */ + +/** \brief initialize an I2C interface using given config + * \param[in] hal - opaque ptr to HAL data + * \param[in] cfg - interface configuration + * \return ATCA_SUCCESS on success, otherwise an error code. + */ +ATCA_STATUS hal_i2c_init(ATCAIface iface, ATCAIfaceCfg *cfg) +{ + esp_err_t rc = ESP_FAIL; + int bus = cfg->atcai2c.bus; + + if (bus >= 0 && bus < MAX_I2C_BUSES) + { + if (0 == i2c_hal_data[bus].ref_ct) + { + i2c_hal_data[bus].ref_ct = 1; + i2c_hal_data[bus].conf.mode = I2C_MODE_MASTER; + i2c_hal_data[bus].conf.sda_pullup_en = GPIO_PULLUP_DISABLE; + i2c_hal_data[bus].conf.scl_pullup_en = GPIO_PULLUP_DISABLE; + i2c_hal_data[bus].conf.master.clk_speed = 100000; //cfg->atcai2c.baud; + + switch (bus) + { + case 0: + i2c_hal_data[bus].id = I2C_NUM_0; + i2c_hal_data[bus].conf.sda_io_num = I2C0_SDA_PIN; + i2c_hal_data[bus].conf.scl_io_num = I2C0_SCL_PIN; + break; + case 1: + i2c_hal_data[bus].id = I2C_NUM_1; + i2c_hal_data[bus].conf.sda_io_num = I2C1_SDA_PIN; + i2c_hal_data[bus].conf.scl_io_num = I2C1_SCL_PIN; + break; + default: + break; + } + +// ESP_LOGI(TAG, "Configuring I2C"); + rc = i2c_param_config(i2c_hal_data[bus].id, &i2c_hal_data[bus].conf); +// ESP_LOGD(TAG, "I2C Param Config: %s", esp_err_to_name(rc)); + rc = i2c_driver_install(i2c_hal_data[bus].id, I2C_MODE_MASTER, 0, 0, 0); +// ESP_LOGD(TAG, "I2C Driver Install; %s", esp_err_to_name(rc)); + } + else + { + i2c_hal_data[bus].ref_ct++; + } + + iface->hal_data = &i2c_hal_data[bus]; + } + + if (ESP_OK == rc) + { + return ATCA_SUCCESS; + } + else + { + //ESP_LOGE(TAG, "I2C init failed"); + return ATCA_COMM_FAIL; + } +} + +/** \brief HAL implementation of I2C post init + * \param[in] iface instance + * \return ATCA_SUCCESS + */ +ATCA_STATUS hal_i2c_post_init(ATCAIface iface) +{ + return ATCA_SUCCESS; +} + +/** \brief HAL implementation of I2C send + * \param[in] iface instance + * \param[in] word_address device transaction type + * \param[in] txdata pointer to space to bytes to send + * \param[in] txlength number of bytes to send + * \return ATCA_SUCCESS on success, otherwise an error code. + */ +ATCA_STATUS hal_i2c_send(ATCAIface iface, uint8_t address, uint8_t *txdata, int txlength) +{ + ATCAIfaceCfg *cfg = iface->mIfaceCFG; + esp_err_t rc; + + if (!cfg) + { + return ATCA_BAD_PARAM; + } + + //ESP_LOGD(TAG, "txdata: %p , txlength: %d", txdata, txlength); + //ESP_LOG_BUFFER_HEXDUMP(TAG, txdata, txlength, 3); + + i2c_cmd_handle_t cmd = i2c_cmd_link_create(); + (void)i2c_master_start(cmd); + (void)i2c_master_write_byte(cmd, address | I2C_MASTER_WRITE, ACK_CHECK_EN); + (void)i2c_master_write(cmd, txdata, txlength, ACK_CHECK_EN); + (void)i2c_master_stop(cmd); + rc = i2c_master_cmd_begin(cfg->atcai2c.bus, cmd, 10); + (void)i2c_cmd_link_delete(cmd); + + if (ESP_OK != rc) + { + return ATCA_COMM_FAIL; + } + else + { + return ATCA_SUCCESS; + } +} + +/** \brief HAL implementation of I2C receive function + * \param[in] iface Device to interact with. + * \param[in] address Device address + * \param[out] rxdata Data received will be returned here. + * \param[in,out] rxlength As input, the size of the rxdata buffer. + * As output, the number of bytes received. + * \return ATCA_SUCCESS on success, otherwise an error code. + */ +ATCA_STATUS hal_i2c_receive(ATCAIface iface, uint8_t address, uint8_t *rxdata, uint16_t *rxlength) +{ + ATCAIfaceCfg *cfg = iface->mIfaceCFG; + esp_err_t rc; + i2c_cmd_handle_t cmd; + ATCA_STATUS status = ATCA_COMM_FAIL; + + if ((NULL == cfg) || (NULL == rxlength) || (NULL == rxdata)) + { + return ATCA_TRACE(ATCA_INVALID_POINTER, "NULL pointer encountered"); + } + + cmd = i2c_cmd_link_create(); + (void)i2c_master_start(cmd); + (void)i2c_master_write_byte(cmd, address | I2C_MASTER_READ, ACK_CHECK_EN); + if (*rxlength > 1) + { + (void)i2c_master_read(cmd, rxdata, *rxlength - 1, ACK_VAL); + } + (void)i2c_master_read_byte(cmd, rxdata + (size_t)*rxlength - 1, NACK_VAL); + (void)i2c_master_stop(cmd); + rc = i2c_master_cmd_begin(cfg->atcai2c.bus, cmd, 10); + (void)i2c_cmd_link_delete(cmd); + + //ESP_LOG_BUFFER_HEXDUMP(TAG, rxdata, *rxlength, 3); + + if (ESP_OK == rc) + { + status = ATCA_SUCCESS; + } + + return status; + +} + +/** \brief manages reference count on given bus and releases resource if no more refences exist + * \param[in] hal_data - opaque pointer to hal data structure - known only to the HAL implementation + * \return ATCA_SUCCESS on success, otherwise an error code. + */ +ATCA_STATUS hal_i2c_release(void *hal_data) +{ + ATCAI2CMaster_t *hal = (ATCAI2CMaster_t*)hal_data; + + if (hal && --(hal->ref_ct) <= 0) + { + i2c_driver_delete(hal->id); + } + return ATCA_SUCCESS; +} + +/** \brief Perform control operations for the kit protocol + * \param[in] iface Interface to interact with. + * \param[in] option Control parameter identifier + * \param[in] param Optional pointer to parameter value + * \param[in] paramlen Length of the parameter + * \return ATCA_SUCCESS on success, otherwise an error code. + */ +ATCA_STATUS hal_i2c_control(ATCAIface iface, uint8_t option, void* param, size_t paramlen) +{ + (void)param; + (void)paramlen; + + if (iface && iface->mIfaceCFG) + { + if (ATCA_HAL_CHANGE_BAUD == option) + { + return hal_i2c_change_baud(iface, *(uint32_t*)param); + } + else + { + return ATCA_UNIMPLEMENTED; + } + } + return ATCA_BAD_PARAM; +} diff --git a/lib/hal/hal_esp32_timer.c b/lib/hal/hal_esp32_timer.c new file mode 100644 index 000000000..0cf6f566d --- /dev/null +++ b/lib/hal/hal_esp32_timer.c @@ -0,0 +1,34 @@ +/* + * Copyright 2018 Espressif Systems (Shanghai) PTE LTD + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "atca_hal.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + +extern void ets_delay_us(uint32_t); + +void atca_delay_us(uint32_t delay) +{ + ets_delay_us(delay); +} + +#ifdef ATCA_USE_RTOS_TIMER +void atca_delay_ms_internal(uint32_t msec) +#else +void atca_delay_ms(uint32_t msec) +#endif +{ + ets_delay_us(msec * 1000); +} diff --git a/lib/hal/hal_linux_uart_userspace.c b/lib/hal/hal_linux_uart_userspace.c new file mode 100644 index 000000000..0033dd9c1 --- /dev/null +++ b/lib/hal/hal_linux_uart_userspace.c @@ -0,0 +1,329 @@ +/** + * \file + * \brief ATCA Hardware abstraction layer for Linux using UART. + * + * \copyright (c) 2015-2020 Microchip Technology Inc. and its subsidiaries. + * + * \page License + * + * Subject to your compliance with these terms, you may use Microchip software + * and any derivatives exclusively with Microchip products. It is your + * responsibility to comply with third party license terms applicable to your + * use of third party software (including open source software) that may + * accompany Microchip software. + * + * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED + * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A + * PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, + * SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE + * OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + * MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + * FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL + * LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED + * THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR + * THIS SOFTWARE. + */ + +#include "cryptoauthlib.h" +#include "atca_hal.h" + +#include +#include +#include +#include + +typedef struct atca_uart_host_s +{ + char uart_file[20]; + int fd_uart; + int uart_baud; + int uart_wordsize; + uint8_t uart_parity; + uint8_t uart_stopbit; + int ref_ct; +} atca_uart_host_t; + +/** \brief Open and configure serial COM Uart + * \param[out] fd resulting file descriptor + * + * \return ATCA_SUCCESS on success, else an error code + */ +ATCA_STATUS hal_uart_open_file(atca_uart_host_t * hal_data) +{ + ATCA_STATUS status = ATCA_BAD_PARAM; + + if (hal_data) + { + struct termios tty; + + hal_data->fd_uart = open(hal_data->uart_file, O_RDWR | O_NOCTTY); + + if (0 < hal_data->fd_uart) + { + /* Get existing device attributes */ + tcgetattr(hal_data->fd_uart, &tty); + + /* Raw Mode */ + tty.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); + + /* No flow control */ + tty.c_iflag &= ~(IXON | IXOFF | IXANY); + + /* No output translation */ + tty.c_oflag &= ~OPOST; + + //Enable read timeout + tty.c_cc[VTIME] = 5; + + cfsetispeed(&tty, hal_data->uart_baud); + cfsetospeed(&tty, hal_data->uart_baud); + + // set number of stopbits + if (1 < hal_data->uart_stopbit) + { + tty.c_cflag |= CSTOPB; + } + + // set parity bits + if (0 == hal_data->uart_parity) // even parity + { + tty.c_cflag |= PARENB; + } + else if (1 == hal_data->uart_parity) // odd parity + { + tty.c_cflag |= PARENB; + tty.c_cflag |= PARODD; + } + + if (tcsetattr(hal_data->fd_uart, TCSANOW, &tty)) + { + close(hal_data->fd_uart); + return ATCA_COMM_FAIL; + } + + status = ATCA_SUCCESS; + } + else + { + status = ATCA_COMM_FAIL; + } + } + + return status; +} + +/** \brief HAL implementation of UART init + * + * this implementation assumes UART SERIAL PORT peripheral has been enabled by user . It only initialize an + * UART interface using given config. + * + * \param[in] hal pointer to HAL specific data that is maintained by this HAL + * \param[in] cfg pointer to HAL specific configuration data that is used to initialize this HAL + * \return ATCA_SUCCESS on success, otherwise an error code. + */ + +ATCA_STATUS hal_uart_init(ATCAIface iface, ATCAIfaceCfg *cfg) +{ + ATCA_STATUS status = ATCA_BAD_PARAM; + + if (iface && cfg) + { + if (!iface->hal_data) + { + atca_uart_host_t * hal_data = malloc(sizeof(atca_uart_host_t)); + memset(hal_data, 0, sizeof(atca_uart_host_t)); + + if (hal_data) + { + if (cfg->cfg_data) + { + (void)snprintf(hal_data->uart_file, sizeof(hal_data->uart_file) - 1, + "%s", (char*)cfg->cfg_data); + } + else + { + (void)snprintf(hal_data->uart_file, sizeof(hal_data->uart_file) - 1, + "/dev/ttyS%d", (uint8_t)cfg->atcauart.port); + } + + // Set linux uart baudrate mask + switch (cfg->atcauart.baud) + { + case 0: hal_data->uart_baud = B0; break; + case 4800: hal_data->uart_baud = B4800; break; + case 9600: hal_data->uart_baud = B9600; break; + case 115200: hal_data->uart_baud = B115200; break; + default: hal_data->uart_baud = B115200; break; + } + // set linux uart character size + switch (cfg->atcauart.wordsize) + { + case 5: hal_data->uart_wordsize = CS5; break; + case 6: hal_data->uart_wordsize = CS6; break; + case 7: hal_data->uart_wordsize = CS7; break; + case 8: hal_data->uart_wordsize = CS8; break; + default: hal_data->uart_wordsize = CS8; break; + } + + hal_data->uart_parity = iface->mIfaceCFG->atcauart.parity; + hal_data->uart_stopbit = iface->mIfaceCFG->atcauart.stopbits; + iface->hal_data = hal_data; + + if (ATCA_SUCCESS == (status = hal_uart_open_file(hal_data))) + { + hal_data->ref_ct = 1; + } + } + else + { + status = ATCA_ALLOC_FAILURE; + } + } + else + { + atca_uart_host_t * hal_data = (atca_uart_host_t*)atgetifacehaldat(iface); + + if (hal_data) + { + hal_data->ref_ct++; + status = ATCA_SUCCESS; + } + } + + } + return status; +} + +/** \brief HAL implementation of UART post init + * \param[in] iface instance + * \return ATCA_SUCCESS on success, otherwise an error code. + */ +ATCA_STATUS hal_uart_post_init(ATCAIface iface) +{ + ((void)iface); + return ATCA_SUCCESS; +} + +/** \brief HAL implementation of UART send + * \param[in] iface instance + * \param[in] word_address transaction type + * \param[in] txdata data to be send to device + * \param[in] txdata pointer to space to bytes to send + * + * \return ATCA_SUCCESS on success, otherwise an error code. + */ +ATCA_STATUS hal_uart_send(ATCAIface iface, uint8_t word_address, uint8_t *txdata, int txlength) +{ + (void)word_address; + ATCA_STATUS status = ATCA_BAD_PARAM; + + if (iface && txdata && txlength) + { + atca_uart_host_t * hal_data = (atca_uart_host_t*)atgetifacehaldat(iface); + + if (hal_data && (hal_data->fd_uart > 0)) + { + if (write(hal_data->fd_uart, txdata, txlength) != txlength) + { + status = ATCA_COMM_FAIL; + } + else + { + status = ATCA_SUCCESS; + } + } + + if (ATCA_SUCCESS != status) + { + close(hal_data->fd_uart); + hal_data->fd_uart = -1; + } + } + + return status; +} + +/** \brief HAL implementation of UART receive function + * \param[in] iface Device to interact with. + * \param[in] word_address device transaction type + * \param[out] rxdata Data received will be returned here. + * \param[in,out] rxlength As input, the size of the rxdata buffer. + * As output, the number of bytes received. + * \return ATCA_SUCCESS on success, otherwise an error code. + */ +ATCA_STATUS hal_uart_receive(ATCAIface iface, uint8_t word_address, uint8_t *rxdata, uint16_t *rxlength) +{ + (void)word_address; + ATCA_STATUS status = ATCA_BAD_PARAM; + + if (iface && rxdata && rxlength && *rxlength) + { + atca_uart_host_t * hal_data = (atca_uart_host_t*)atgetifacehaldat(iface); + + if (hal_data && (hal_data->fd_uart > 0)) + { + if (*rxlength > 1) + { + *rxlength = 1; // packetsize to read + } + + if (read(hal_data->fd_uart, rxdata, *rxlength) != *rxlength) + { + status = ATCA_COMM_FAIL; + } + else + { + status = ATCA_SUCCESS; + } + } + + if (ATCA_SUCCESS != status) + { + close(hal_data->fd_uart); + hal_data->fd_uart = -1; + } + + } + + return status; +} + +/** \brief Perform control operations for the UART + * \param[in] iface Interface to interact with. + * \param[in] option Control parameter identifier + * \param[in] param Optional pointer to parameter value + * \param[in] paramlen Length of the parameter + * \return ATCA_SUCCESS on success, otherwise an error code. + */ +ATCA_STATUS hal_uart_control(ATCAIface iface, uint8_t option, void* param, size_t paramlen) +{ + (void)option; + (void)param; + (void)paramlen; + + if (iface && iface->mIfaceCFG) + { + /* This HAL does not support any of the control functions */ + return ATCA_UNIMPLEMENTED; + } + return ATCA_BAD_PARAM; +} + +/** \brief manages reference count on given bus and releases resource if no more refences exist + * + * \param[in] hal_data - opaque pointer to hal data structure - known only to the HAL implementation + * \return ATCA_SUCCESS on success, otherwise an error code. + */ +ATCA_STATUS hal_uart_release(void *hal_data) +{ + atca_uart_host_t *hal = (atca_uart_host_t*)hal_data; + + if (hal) + { + close(hal->fd_uart); + free(hal); + } + + return ATCA_SUCCESS; +} diff --git a/lib/hal/hal_sam0_i2c_asf.h b/lib/hal/hal_sam0_i2c_asf.h index 52388b6ee..2f107cd7e 100644 --- a/lib/hal/hal_sam0_i2c_asf.h +++ b/lib/hal/hal_sam0_i2c_asf.h @@ -41,4 +41,4 @@ typedef struct i2c_sam0_instance sam0_change_baudrate change_baudrate; } i2c_sam0_instance_t; -#endif /* HAL_SAMD21_I2C_ASF_H_ */ \ No newline at end of file +#endif /* HAL_SAMD21_I2C_ASF_H_ */ diff --git a/lib/hal/hal_sam_i2c_asf.h b/lib/hal/hal_sam_i2c_asf.h index a126171ac..0f2ea15c9 100644 --- a/lib/hal/hal_sam_i2c_asf.h +++ b/lib/hal/hal_sam_i2c_asf.h @@ -54,4 +54,4 @@ typedef struct i2c_sam_instance /** @} */ -#endif /* HAL_SAMG55_I2C_ASF_H_ */ \ No newline at end of file +#endif /* HAL_SAMG55_I2C_ASF_H_ */ diff --git a/lib/hal/hal_swi_bitbang_harmony.c b/lib/hal/hal_swi_bitbang_harmony.c index b709a8aea..606c62da5 100644 --- a/lib/hal/hal_swi_bitbang_harmony.c +++ b/lib/hal/hal_swi_bitbang_harmony.c @@ -585,4 +585,4 @@ ATCA_STATUS hal_swi_release(void *hal_data) return ATCA_SUCCESS; } -/** @} */ \ No newline at end of file +/** @} */ diff --git a/lib/hal/hal_uart_harmony.c b/lib/hal/hal_uart_harmony.c index a3e2c0da7..ff4489a1c 100644 --- a/lib/hal/hal_uart_harmony.c +++ b/lib/hal/hal_uart_harmony.c @@ -44,12 +44,12 @@ PLIB_SWI_SERIAL_SETUP serial_setup = { static ATCA_STATUS hal_uart_flush_buffer(ATCAIface iface) { ATCAIfaceCfg *cfg = atgetifacecfg(iface); - atca_plib_swi_uart_api_t* plib; + atca_plib_uart_api_t* plib; uint8_t dummy_read; if (cfg && cfg->cfg_data) { - plib = (atca_plib_swi_uart_api_t*)cfg->cfg_data; + plib = (atca_plib_uart_api_t*)cfg->cfg_data; // Until rx ring buffer gets cleared, read out all data from rx buffer while (plib->readcount_get() >= 1) @@ -70,12 +70,12 @@ static ATCA_STATUS hal_uart_flush_buffer(ATCAIface iface) static ATCA_STATUS hal_uart_set_baudrate(ATCAIface iface, uint32_t baudrate) { ATCAIfaceCfg *cfg = atgetifacecfg(iface); - atca_plib_swi_uart_api_t* plib; + atca_plib_uart_api_t* plib; ATCA_STATUS status = ATCA_BAD_PARAM; if (cfg && cfg->cfg_data) { - plib = (atca_plib_swi_uart_api_t*)cfg->cfg_data; + plib = (atca_plib_uart_api_t*)cfg->cfg_data; serial_setup.baudRate = baudrate; @@ -95,14 +95,14 @@ static ATCA_STATUS hal_uart_set_baudrate(ATCAIface iface, uint32_t baudrate) */ ATCA_STATUS hal_uart_init(ATCAIface iface, ATCAIfaceCfg *cfg) { - atca_plib_swi_uart_api_t* plib; + atca_plib_uart_api_t* plib; if (cfg == NULL) { return ATCA_TRACE(ATCA_BAD_PARAM, "NULL pointer encountered"); } - plib = (atca_plib_swi_uart_api_t*)cfg->cfg_data; + plib = (atca_plib_uart_api_t*)cfg->cfg_data; if (plib == NULL) { return ATCA_TRACE(ATCA_BAD_PARAM, "NULL pointer encountered"); @@ -135,12 +135,12 @@ ATCA_STATUS hal_uart_post_init(ATCAIface iface) ATCA_STATUS hal_uart_send(ATCAIface iface, uint8_t word_address, uint8_t* txdata, int txlength) { ATCAIfaceCfg *cfg = atgetifacecfg(iface); - atca_plib_swi_uart_api_t* plib; + atca_plib_uart_api_t* plib; ATCA_STATUS status = ATCA_BAD_PARAM; if (cfg && cfg->cfg_data && txdata && txlength) { - plib = (atca_plib_swi_uart_api_t*)cfg->cfg_data; + plib = (atca_plib_uart_api_t*)cfg->cfg_data; (void)plib->error_get(); if (txlength == plib->write(txdata, txlength)) @@ -169,13 +169,13 @@ ATCA_STATUS hal_uart_send(ATCAIface iface, uint8_t word_address, uint8_t* txdata ATCA_STATUS hal_uart_receive(ATCAIface iface, uint8_t word_address, uint8_t *rxdata, uint16_t* rxlength) { ATCAIfaceCfg *cfg = atgetifacecfg(iface); - atca_plib_swi_uart_api_t* plib; + atca_plib_uart_api_t* plib; ATCA_STATUS status = ATCA_BAD_PARAM; int16_t timeout = 300; if (cfg && cfg->cfg_data && rxdata && rxlength) { - plib = (atca_plib_swi_uart_api_t*)cfg->cfg_data; + plib = (atca_plib_uart_api_t*)cfg->cfg_data; while ((plib->readcount_get() < *rxlength) && (timeout > 0)) { diff --git a/lib/hal/hal_uc3_i2c_asf.h b/lib/hal/hal_uc3_i2c_asf.h index 21b54bdb3..1178d110a 100644 --- a/lib/hal/hal_uc3_i2c_asf.h +++ b/lib/hal/hal_uc3_i2c_asf.h @@ -58,4 +58,4 @@ typedef struct atcaI2Cmaster ATCA_STATUS change_i2c_speed(ATCAIface iface, uint32_t speed); /** @} */ -#endif /* HAL_SAMD21_I2C_ASF_H_ */ \ No newline at end of file +#endif /* HAL_SAMD21_I2C_ASF_H_ */ diff --git a/lib/hal/hal_windows_kit_uart.c b/lib/hal/hal_windows_kit_uart.c new file mode 100644 index 000000000..4b434de85 --- /dev/null +++ b/lib/hal/hal_windows_kit_uart.c @@ -0,0 +1,339 @@ +/** + * \file + * \brief ATCA Hardware abstraction layer for Windows using UART. + * + * \copyright (c) 2015-2020 Microchip Technology Inc. and its subsidiaries. + * + * \page License + * + * Subject to your compliance with these terms, you may use Microchip software + * and any derivatives exclusively with Microchip products. It is your + * responsibility to comply with third party license terms applicable to your + * use of third party software (including open source software) that may + * accompany Microchip software. + * + * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED + * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A + * PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, + * SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE + * OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + * MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + * FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL + * LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED + * THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR + * THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#include "cryptoauthlib.h" +#include "atca_hal.h" + +typedef struct atca_uart_host_s +{ + char uart_file[20]; + HANDLE hSerial; + int ref_ct; +} atca_uart_host_t; + +/** \brief Open and configure serial COM Uart + * \param[in,out] hal_data As Input, structure contain uart config info + * As Output, com port HANDLE value + * + * \return ATCA_SUCCESS on success, else an error code + */ +static ATCA_STATUS hal_uart_open_file(ATCAIface iface) +{ + ATCA_STATUS status = ATCA_BAD_PARAM; + ATCAIfaceCfg* cfg = atgetifacecfg(iface); + atca_uart_host_t* hal_data = atgetifacehaldat(iface); + + if (hal_data && cfg) + { + DCB dcbSerialParams = { 0 }; + COMMTIMEOUTS timeouts = { 0 }; + + hal_data->hSerial = CreateFileA(TEXT(hal_data->uart_file), + GENERIC_READ | GENERIC_WRITE, + 0, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + + if (hal_data->hSerial == INVALID_HANDLE_VALUE) + { + return ATCA_COMM_FAIL; + } + + FlushFileBuffers(hal_data->hSerial); + + SecureZeroMemory(&dcbSerialParams, sizeof(DCB)); + dcbSerialParams.DCBlength = sizeof(DCB); + + if (!GetCommState(hal_data->hSerial, &dcbSerialParams)) + { + CloseHandle(hal_data->hSerial); + return ATCA_COMM_FAIL; + } + + + // Set com settings + switch (cfg->atcauart.parity) + { + case 0: + dcbSerialParams.Parity = EVENPARITY; + break; + case 1: + dcbSerialParams.Parity = ODDPARITY; + break; + default: + dcbSerialParams.Parity = NOPARITY; + break; + } + + dcbSerialParams.BaudRate = cfg->atcauart.baud; // baud rate + dcbSerialParams.ByteSize = cfg->atcauart.wordsize; // data size, xmit and rcv + dcbSerialParams.StopBits = cfg->atcauart.stopbits; // stop bit + + if (!SetCommState(hal_data->hSerial, &dcbSerialParams)) + { + CloseHandle(hal_data->hSerial); + return ATCA_COMM_FAIL; + } + + timeouts.ReadIntervalTimeout = 50; + timeouts.ReadTotalTimeoutConstant = 50; + timeouts.ReadTotalTimeoutMultiplier = 10; + timeouts.WriteTotalTimeoutConstant = 50; + timeouts.WriteTotalTimeoutMultiplier = 10; + + if (!SetCommTimeouts(hal_data->hSerial, &timeouts)) + { + CloseHandle(hal_data->hSerial); + return ATCA_COMM_FAIL; + } + + status = ATCA_SUCCESS; + } + + return status; +} + +/** \brief HAL implementation of UART init + * + * this implementation assumes UART SERIAL PORT peripheral has been enabled by user . It only initialize an + * UART interface using given config. + * + * \param[in] hal pointer to HAL specific data that is maintained by this HAL + * \param[in] cfg pointer to HAL specific configuration data that is used to initialize this HAL + * \return ATCA_SUCCESS on success, otherwise an error code. + */ + +ATCA_STATUS hal_uart_init(ATCAIface iface, ATCAIfaceCfg *cfg) +{ + ATCA_STATUS status = ATCA_BAD_PARAM; + + if (iface && cfg) + { + if (!iface->hal_data) + { + atca_uart_host_t * hal_data = malloc(sizeof(atca_uart_host_t)); + + if (hal_data) + { + memset(hal_data, 0, sizeof(atca_uart_host_t)); + + // Set COM port + (void)snprintf(hal_data->uart_file, sizeof(hal_data->uart_file) - 1, + "\\\\.\\COM%d", (uint8_t)cfg->atcauart.port); + + + iface->hal_data = hal_data; + + // open com port file + if (ATCA_SUCCESS == (status = hal_uart_open_file(iface))) + { + hal_data->ref_ct = 1; + } + } + else + { + status = ATCA_ALLOC_FAILURE; + } + } + else + { + atca_uart_host_t * hal_data = (atca_uart_host_t*)atgetifacehaldat(iface); + + if (hal_data) + { + hal_data->ref_ct++; + status = ATCA_SUCCESS; + } + } + + } + return status; +} + +/** \brief HAL implementation of UART post init + * \param[in] iface instance + * \return ATCA_SUCCESS on success, otherwise an error code. + */ +ATCA_STATUS hal_uart_post_init(ATCAIface iface) +{ + ((void)iface); + return ATCA_SUCCESS; +} + +/** \brief HAL implementation of UART send + * \param[in] iface instance + * \param[in] word_address transaction type + * \param[in] txdata data to be send to device + * \param[in] txdata pointer to space to bytes to send + * \param[in] len number of bytes to send + * \return ATCA_SUCCESS on success, otherwise an error code. + */ +ATCA_STATUS hal_uart_send(ATCAIface iface, uint8_t word_address, uint8_t *txdata, int txlength) +{ + (void)word_address; + ATCA_STATUS status = ATCA_BAD_PARAM; + DWORD bytes_written = 0; + + if (iface && txdata && txlength) + { + atca_uart_host_t * hal_data = (atca_uart_host_t*)atgetifacehaldat(iface); + + if (hal_data && (INVALID_HANDLE_VALUE != hal_data->hSerial)) + { + if (!WriteFile(hal_data->hSerial, txdata, txlength, &bytes_written, NULL)) + { + status = ATCA_COMM_FAIL; + } + else + { + status = ATCA_SUCCESS; + } + } + + if (status == ATCA_SUCCESS) + { + if ((DWORD)txlength != bytes_written) + { + status = ATCA_COMM_FAIL; + } + } + + if (ATCA_SUCCESS != status) + { + CloseHandle(hal_data->hSerial); + hal_data->hSerial = INVALID_HANDLE_VALUE; + } + + } + + return status; +} + +/** \brief HAL implementation of UART receive function + * \param[in] iface Device to interact with. + * \param[in] word_address device transaction type + * \param[out] rxdata Data received will be returned here. + * \param[in,out] rxlength As input, the size of the rxdata buffer. + * As output, the number of bytes received. + * \return ATCA_SUCCESS on success, otherwise an error code. + */ +ATCA_STATUS hal_uart_receive(ATCAIface iface, uint8_t word_address, uint8_t *rxdata, uint16_t *rxlength) +{ + (void)word_address; + DWORD bytes_read = 0; + ATCA_STATUS status = ATCA_BAD_PARAM; + + if (iface && rxdata && rxlength && *rxlength) + { + atca_uart_host_t * hal_data = (atca_uart_host_t*)atgetifacehaldat(iface); + + if (hal_data && (INVALID_HANDLE_VALUE != hal_data->hSerial)) + { + if (*rxlength > 1) + { + *rxlength = 1; // packetsize to read + } + + if (!ReadFile(hal_data->hSerial, rxdata, *rxlength, &bytes_read, NULL)) + { + status = ATCA_COMM_FAIL; + } + else + { + status = ATCA_SUCCESS; + } + } + + if (status == ATCA_SUCCESS) + { + if (bytes_read > 0) + { + *rxlength = (uint16_t)bytes_read; + } + else + { + status = ATCA_COMM_FAIL; + } + } + + if (ATCA_SUCCESS != status) + { + CloseHandle(hal_data->hSerial); + hal_data->hSerial = INVALID_HANDLE_VALUE; + } + + } + + return status; +} + +/** \brief Perform control operations for the UART + * \param[in] iface Interface to interact with. + * \param[in] option Control parameter identifier + * \param[in] param Optional pointer to parameter value + * \param[in] paramlen Length of the parameter + * \return ATCA_SUCCESS on success, otherwise an error code. + */ +ATCA_STATUS hal_uart_control(ATCAIface iface, uint8_t option, void* param, size_t paramlen) +{ + (void)option; + (void)param; + (void)paramlen; + + if (iface && iface->mIfaceCFG) + { + /* This HAL does not support any of the control functions */ + return ATCA_UNIMPLEMENTED; + } + return ATCA_BAD_PARAM; +} + +/** \brief manages reference count on given bus and releases resource if no more refences exist + * + * \param[in] hal_data - opaque pointer to hal data structure - known only to the HAL implementation + * \return ATCA_SUCCESS on success, otherwise an error code. + */ +ATCA_STATUS hal_uart_release(void *hal_data) +{ + atca_uart_host_t *hal = (atca_uart_host_t*)hal_data; + + if (hal) + { + CloseHandle(hal->hSerial); + hal_free(hal); + } + + return ATCA_SUCCESS; +} diff --git a/lib/hal/kit_protocol.c b/lib/hal/kit_protocol.c index 53efbf975..115518f00 100644 --- a/lib/hal/kit_protocol.c +++ b/lib/hal/kit_protocol.c @@ -102,6 +102,8 @@ const char * kit_interface_from_kittype(ATCAKitType kittype) } } +#if defined(ATCA_HAL_KIT_HID) || defined(ATCA_HAL_KIT_UART) + /** \brief HAL implementation of send over USB HID * \param[in] iface instance * \param[in] txdata pointer to bytes to send @@ -141,6 +143,10 @@ ATCA_STATUS kit_phy_send(ATCAIface iface, uint8_t* txdata, int txlength) return ATCA_BAD_PARAM; } +#ifdef KIT_DEBUG + printf("Kit Send (%d): %s", txlength, txdata); +#endif + bytes_left = txlength; while (bytes_left > 0) { @@ -155,13 +161,36 @@ ATCA_STATUS kit_phy_send(ATCAIface iface, uint8_t* txdata, int txlength) bytes_to_send = bytes_left; } - memcpy(&buffer[1], &txdata[(txlength - bytes_left)], bytes_to_send); + if (ATCA_HID_IFACE == iface->mIfaceCFG->iface_type) + { +#ifdef ATCA_HAL_KIT_HID + memcpy(&buffer[1], &txdata[(txlength - bytes_left)], bytes_to_send); +#endif + } + else if (ATCA_UART_IFACE == iface->mIfaceCFG->iface_type) + { +#ifdef ATCA_HAL_KIT_UART + memcpy(&buffer[0], &txdata[(txlength - bytes_left)], bytes_to_send); +#endif + } + else + { + return ATCA_BAD_PARAM; + } + if (ATCA_SUCCESS != (status = iface->phy->halsend(iface, 0xFF, buffer, packetsize))) { break; } +#ifdef ATCA_HAL_KIT_UART + if (buffer[0] == '\n') // sizeof will include \0 and count will increase + { + break; + } +#endif + bytes_left -= bytes_to_send; } @@ -179,7 +208,7 @@ ATCA_STATUS kit_phy_receive(ATCAIface iface, uint8_t* rxdata, int* rxsize) ATCA_STATUS status = ATCA_BAD_PARAM; size_t total_bytes_read = 0; size_t bytes_to_read = 0; - char *location; + char* location = NULL; uint16_t rxlen; if ((NULL == iface) || (NULL == iface->phy) || (NULL == iface->phy->halreceive) || @@ -188,23 +217,34 @@ ATCA_STATUS kit_phy_receive(ATCAIface iface, uint8_t* rxdata, int* rxsize) return status; } - bytes_to_read = (size_t)*rxsize; - rxlen = (uint16_t)bytes_to_read--; + status = ATCA_SUCCESS; - do +#ifdef ATCA_HAL_KIT_UART + if (ATCA_UART_IFACE == iface->mIfaceCFG->iface_type) { - if (ATCA_SUCCESS != (status = iface->phy->halreceive(iface, 0x00, &rxdata[total_bytes_read], &rxlen))) + rxlen = 1; + do { - break; + /* Clear out nulls if they are in the buffer */ + status = iface->phy->halreceive(iface, 0x00, rxdata, &rxlen); } + while (ATCA_SUCCESS == status && *rxdata == '\0'); + total_bytes_read = 1; + } +#endif + + bytes_to_read = (size_t)*rxsize; + rxlen = (uint16_t)bytes_to_read--; + + while (ATCA_SUCCESS == status && (NULL == location) && (0 < bytes_to_read)) + { + status = iface->phy->halreceive(iface, 0x00, &rxdata[total_bytes_read], &rxlen); location = memchr(&rxdata[total_bytes_read], '\n', (size_t)rxlen); total_bytes_read += rxlen; bytes_to_read -= rxlen; - } - while ((NULL == location) && (0 < bytes_to_read)); if (ATCA_SUCCESS != status) { @@ -221,6 +261,10 @@ ATCA_STATUS kit_phy_receive(ATCAIface iface, uint8_t* rxdata, int* rxsize) *rxsize = (int)total_bytes_read; } +#ifdef KIT_DEBUG + printf("Kit Recv (%d): %s", *rxsize, rxdata); +#endif + return ATCA_SUCCESS; } @@ -243,11 +287,34 @@ ATCA_STATUS kit_init(ATCAIface iface, ATCAIfaceCfg* cfg) char *token; /* string token */ int i; int address; + ATCAKitType iface_type; + uint8_t dev_identity; ((void)cfg); device_match = kit_id_from_devtype(iface->mIfaceCFG->devtype); - interface_match = kit_interface_from_kittype(iface->mIfaceCFG->atcahid.dev_interface); + + switch (iface->mIfaceCFG->iface_type) + { +#ifdef ATCA_HAL_KIT_HID + case ATCA_HID_IFACE: + iface_type = iface->mIfaceCFG->atcahid.dev_interface; + dev_identity = iface->mIfaceCFG->atcahid.dev_identity; + break; +#endif +#ifdef ATCA_HAL_KIT_UART + case ATCA_UART_IFACE: + iface_type = iface->mIfaceCFG->atcauart.dev_interface; + dev_identity = iface->mIfaceCFG->atcauart.dev_identity; + break; +#endif + default: + iface_type = ATCA_KIT_AUTO_IFACE; + dev_identity = 0; + break; + } + + interface_match = kit_interface_from_kittype(iface_type); /* Iterate to find the target device */ for (i = 0; i < KIT_MAX_SCAN_COUNT; i++) @@ -292,7 +359,7 @@ ATCA_STATUS kit_init(ATCAIface iface, ATCAIfaceCfg* cfg) } /*Selects the first device type if both device interface and device identity is not defined*/ - if (iface->mIfaceCFG->atcahid.dev_interface == ATCA_KIT_AUTO_IFACE && iface->mIfaceCFG->atcahid.dev_identity == 0 && (strncmp(device_match, dev_type, 3) == 0)) + if (iface_type == ATCA_KIT_AUTO_IFACE && dev_identity == 0 && (strncmp(device_match, dev_type, 3) == 0)) { txlen = snprintf(txbuf, sizeof(txbuf) - 1, kit_device_select, device_match[0], address); @@ -311,16 +378,11 @@ ATCA_STATUS kit_init(ATCAIface iface, ATCAIfaceCfg* cfg) rxlen = sizeof(rxbuf); status = kit_phy_receive(iface, rxbuf, &rxlen); break; - - } - else { - - /*Selects the device only if the device type, device interface and device identity matches*/ - if ((strncmp(device_match, dev_type, 4) == 0) && (iface->mIfaceCFG->atcahid.dev_identity == address) && (strcmp(interface_match, dev_interface) == 0)) + if ((strncmp(device_match, dev_type, 4) == 0) && (dev_identity == address) && (strcmp(interface_match, dev_interface) == 0)) { @@ -461,7 +523,7 @@ ATCA_STATUS kit_send(ATCAIface iface, uint8_t word_address, uint8_t* txdata, int { // Wrap in kit protocol nkitbuf = txlength * 2 + KIT_TX_WRAP_SIZE; - pkitbuf = malloc(nkitbuf); + pkitbuf = hal_malloc(nkitbuf); memset(pkitbuf, 0, nkitbuf); target = kit_id_from_devtype(iface->mIfaceCFG->devtype); @@ -493,7 +555,7 @@ ATCA_STATUS kit_send(ATCAIface iface, uint8_t word_address, uint8_t* txdata, int while (0); // Free the bytes - free(pkitbuf); + hal_free(pkitbuf); return status; } @@ -536,7 +598,7 @@ ATCA_STATUS kit_receive(ATCAIface iface, uint8_t word_address, uint8_t* rxdata, // Receive the response bytes nkitbuf = (*rxsize * 2) + KIT_RX_WRAP_SIZE; - pkitbuf = malloc(nkitbuf); + pkitbuf = hal_malloc(nkitbuf); memset(pkitbuf, 0, nkitbuf); if (ATCA_SUCCESS != (status = kit_phy_receive(iface, pkitbuf, &nkitbuf))) @@ -564,7 +626,7 @@ ATCA_STATUS kit_receive(ATCAIface iface, uint8_t word_address, uint8_t* rxdata, while (0); // Free the bytes - free(pkitbuf); + hal_free(pkitbuf); return status; } @@ -844,4 +906,6 @@ ATCA_STATUS kit_release(void* hal_data) return ATCA_SUCCESS; } +#endif + /** @} */ diff --git a/lib/hal/kit_protocol.h b/lib/hal/kit_protocol.h index 9af9cae6f..6bd18cd94 100644 --- a/lib/hal/kit_protocol.h +++ b/lib/hal/kit_protocol.h @@ -66,6 +66,10 @@ ATCA_STATUS kit_wake(ATCAIface iface); ATCA_STATUS kit_idle(ATCAIface iface); ATCA_STATUS kit_sleep(ATCAIface iface); + +const char* kit_id_from_devtype(ATCADeviceType devtype); +const char* kit_interface_from_kittype(ATCAKitType kittype); + #ifdef __cplusplus } #endif diff --git a/lib/pkcs11/pkcs11.h b/lib/pkcs11/pkcs11.h index 76ab3d78e..2496e3209 100644 --- a/lib/pkcs11/pkcs11.h +++ b/lib/pkcs11/pkcs11.h @@ -263,4 +263,3 @@ struct CK_FUNCTION_LIST #endif #endif /* _PKCS11_H_ */ - diff --git a/lib/pkcs11/pkcs11_attrib.c b/lib/pkcs11/pkcs11_attrib.c index 3d494ff46..880d60f15 100644 --- a/lib/pkcs11/pkcs11_attrib.c +++ b/lib/pkcs11/pkcs11_attrib.c @@ -120,4 +120,3 @@ CK_RV pkcs11_attrib_empty(const CK_VOID_PTR pObject, CK_ATTRIBUTE_PTR pAttribute /** @} */ - diff --git a/lib/pkcs11/pkcs11_cert.c b/lib/pkcs11/pkcs11_cert.c index e41267513..2030222aa 100644 --- a/lib/pkcs11/pkcs11_cert.c +++ b/lib/pkcs11/pkcs11_cert.c @@ -377,62 +377,62 @@ CK_RV pkcs11_cert_get_trusted_flag(CK_VOID_PTR pObject, CK_ATTRIBUTE_PTR pAttrib */ const pkcs11_attrib_model pkcs11_cert_x509public_attributes[] = { /** Object Class - CK_OBJECT_CLASS */ - { CKA_CLASS, pkcs11_object_get_class }, + { CKA_CLASS, pkcs11_object_get_class }, /** CK_TRUE if object is a token object; CK_FALSE if object is a session object. Default is CK_FALSE. */ - { CKA_TOKEN, pkcs11_attrib_true }, + { CKA_TOKEN, pkcs11_attrib_true }, /** CK_TRUE if object is a private object; CK_FALSE if object is a public object. */ - { CKA_PRIVATE, pkcs11_token_get_access_type }, + { CKA_PRIVATE, pkcs11_token_get_access_type }, /** CK_TRUE if object can be modified. Default is CK_TRUE. */ - { CKA_MODIFIABLE, pkcs11_token_get_writable }, + { CKA_MODIFIABLE, pkcs11_token_get_writable }, /** Description of the object(default empty). */ - { CKA_LABEL, pkcs11_object_get_name }, + { CKA_LABEL, pkcs11_object_get_name }, /** CK_TRUE if object can be copied using C_CopyObject.Defaults to CK_TRUE. */ - { CKA_COPYABLE, pkcs11_attrib_false }, + { CKA_COPYABLE, pkcs11_attrib_false }, /** CK_TRUE if the object can be destroyed using C_DestroyObject. Default is CK_TRUE. */ - { CKA_DESTROYABLE, pkcs11_object_get_destroyable }, + { CKA_DESTROYABLE, pkcs11_object_get_destroyable }, /** Type of certificate */ - { CKA_CERTIFICATE_TYPE, pkcs11_cert_get_type }, + { CKA_CERTIFICATE_TYPE, pkcs11_cert_get_type }, /** The certificate can be trusted for the application that it was created. */ - { CKA_TRUSTED, pkcs11_cert_get_trusted_flag }, + { CKA_TRUSTED, pkcs11_cert_get_trusted_flag }, /** Default CK_CERTIFICATE_CATEGORY_UNSPECIFIED) */ - { CKA_CERTIFICATE_CATEGORY, pkcs11_object_get_type }, + { CKA_CERTIFICATE_CATEGORY, pkcs11_object_get_type }, /** Checksum */ - { CKA_CHECK_VALUE, NULL_PTR }, + { CKA_CHECK_VALUE, NULL_PTR }, /** Start date for the certificate (default empty) */ - { CKA_START_DATE, pkcs11_attrib_empty }, + { CKA_START_DATE, pkcs11_attrib_empty }, /** End date for the certificate (default empty) */ - { CKA_END_DATE, pkcs11_attrib_empty }, + { CKA_END_DATE, pkcs11_attrib_empty }, /** ALL: DER-encoding of the SubjectPublicKeyInfo for the public key contained in this certificate (default empty) SubjectPublicKeyInfo ::= SEQUENCE { algorithm AlgorithmIdentifier, subjectPublicKey BIT_STRING } */ - { CKA_PUBLIC_KEY_INFO, pkcs11_attrib_empty }, + { CKA_PUBLIC_KEY_INFO, pkcs11_attrib_empty }, /** DER-encoded Certificate subject name */ - { CKA_SUBJECT, pkcs11_cert_get_subject }, + { CKA_SUBJECT, pkcs11_cert_get_subject }, /** Key identifier for public/private key pair (default empty) */ - { CKA_ID, pkcs11_attrib_empty }, + { CKA_ID, pkcs11_attrib_empty }, /** DER-encoded Certificate issuer name (default empty)*/ - { CKA_ISSUER, pkcs11_attrib_empty }, + { CKA_ISSUER, pkcs11_attrib_empty }, /** DER-encoding of the certificate serial number (default empty) */ - { CKA_SERIAL_NUMBER, pkcs11_attrib_empty }, + { CKA_SERIAL_NUMBER, pkcs11_attrib_empty }, /** BER-encoded Complete Certificate */ - { CKA_VALUE, pkcs11_cert_get_encoded }, + { CKA_VALUE, pkcs11_cert_get_encoded }, /** If not empty this attribute gives the URL where the complete certificate can be obtained (default empty) */ - { CKA_URL, pkcs11_attrib_empty }, + { CKA_URL, pkcs11_attrib_empty }, /** Hash of the subject public key (default empty). Hash algorithm is defined by CKA_NAME_HASH_ALGORITHM */ - { CKA_HASH_OF_SUBJECT_PUBLIC_KEY, pkcs11_cert_get_subject_key_id }, + { CKA_HASH_OF_SUBJECT_PUBLIC_KEY, pkcs11_cert_get_subject_key_id }, /** Hash of the issuer public key (default empty). Hash algorithm is defined by CKA_NAME_HASH_ALGORITHM */ - { CKA_HASH_OF_ISSUER_PUBLIC_KEY, pkcs11_cert_get_authority_key_id }, + { CKA_HASH_OF_ISSUER_PUBLIC_KEY, pkcs11_cert_get_authority_key_id }, /** Java MIDP security domain. (default CK_SECURITY_DOMAIN_UNSPECIFIED) */ - { CKA_JAVA_MIDP_SECURITY_DOMAIN, NULL_PTR }, + { CKA_JAVA_MIDP_SECURITY_DOMAIN, NULL_PTR }, /** Defines the mechanism used to calculate CKA_HASH_OF_SUBJECT_PUBLIC_KEY and CKA_HASH_OF_ISSUER_PUBLIC_KEY. If the attribute is not present then the type defaults to SHA-1. */ - { CKA_NAME_HASH_ALGORITHM, pkcs11_attrib_empty }, + { CKA_NAME_HASH_ALGORITHM, pkcs11_attrib_empty }, }; const CK_ULONG pkcs11_cert_x509public_attributes_count = PKCS11_UTIL_ARRAY_SIZE(pkcs11_cert_x509public_attributes); @@ -442,56 +442,56 @@ const CK_ULONG pkcs11_cert_x509public_attributes_count = PKCS11_UTIL_ARRAY_SIZE( */ const pkcs11_attrib_model pkcs11_cert_wtlspublic_attributes[] = { /** Object Class - CK_OBJECT_CLASS */ - { CKA_CLASS, pkcs11_object_get_class }, + { CKA_CLASS, pkcs11_object_get_class }, /** CK_TRUE if object is a token object; CK_FALSE if object is a session object. Default is CK_FALSE. */ - { CKA_TOKEN, pkcs11_attrib_true }, + { CKA_TOKEN, pkcs11_attrib_true }, /** CK_TRUE if object is a private object; CK_FALSE if object is a public object. */ - { CKA_PRIVATE, pkcs11_token_get_access_type }, + { CKA_PRIVATE, pkcs11_token_get_access_type }, /** CK_TRUE if object can be modified. Default is CK_TRUE. */ - { CKA_MODIFIABLE, NULL_PTR }, + { CKA_MODIFIABLE, NULL_PTR }, /** Description of the object(default empty). */ - { CKA_LABEL, pkcs11_object_get_name }, + { CKA_LABEL, pkcs11_object_get_name }, /** CK_TRUE if object can be copied using C_CopyObject.Defaults to CK_TRUE. */ - { CKA_COPYABLE, pkcs11_attrib_false }, + { CKA_COPYABLE, pkcs11_attrib_false }, /** CK_TRUE if the object can be destroyed using C_DestroyObject. Default is CK_TRUE. */ - { CKA_DESTROYABLE, pkcs11_object_get_destroyable }, + { CKA_DESTROYABLE, pkcs11_object_get_destroyable }, /** Type of certificate */ - { CKA_CERTIFICATE_TYPE, pkcs11_cert_get_type }, + { CKA_CERTIFICATE_TYPE, pkcs11_cert_get_type }, /** The certificate can be trusted for the application that it was created. */ - { CKA_TRUSTED, NULL_PTR }, + { CKA_TRUSTED, NULL_PTR }, /** Default CK_CERTIFICATE_CATEGORY_UNSPECIFIED) */ - { CKA_CERTIFICATE_CATEGORY, pkcs11_object_get_type }, + { CKA_CERTIFICATE_CATEGORY, pkcs11_object_get_type }, /** Checksum */ - { CKA_CHECK_VALUE, NULL_PTR }, + { CKA_CHECK_VALUE, NULL_PTR }, /** Start date for the certificate (default empty) */ - { CKA_START_DATE, pkcs11_attrib_empty }, + { CKA_START_DATE, pkcs11_attrib_empty }, /** End date for the certificate (default empty) */ - { CKA_END_DATE, pkcs11_attrib_empty }, + { CKA_END_DATE, pkcs11_attrib_empty }, /** ALL: DER-encoding of the SubjectPublicKeyInfo for the public key contained in this certificate (default empty) SubjectPublicKeyInfo ::= SEQUENCE { algorithm AlgorithmIdentifier, subjectPublicKey BIT_STRING } */ - { CKA_PUBLIC_KEY_INFO, pkcs11_attrib_empty }, + { CKA_PUBLIC_KEY_INFO, pkcs11_attrib_empty }, /** WTLS-encoded Certificate subject name */ - { CKA_SUBJECT, pkcs11_attrib_empty }, + { CKA_SUBJECT, pkcs11_attrib_empty }, /** WTLS-encoded Certificate issuer name (default empty)*/ - { CKA_ISSUER, pkcs11_attrib_empty }, + { CKA_ISSUER, pkcs11_attrib_empty }, /** WTLS-encoded Complete Certificate */ - { CKA_VALUE, pkcs11_cert_get_encoded }, + { CKA_VALUE, pkcs11_cert_get_encoded }, /** If not empty this attribute gives the URL where the complete certificate can be obtained (default empty) */ - { CKA_URL, pkcs11_attrib_empty }, + { CKA_URL, pkcs11_attrib_empty }, /** Hash of the subject public key (default empty). Hash algorithm is defined by CKA_NAME_HASH_ALGORITHM */ - { CKA_HASH_OF_SUBJECT_PUBLIC_KEY, pkcs11_cert_get_subject_key_id }, + { CKA_HASH_OF_SUBJECT_PUBLIC_KEY, pkcs11_cert_get_subject_key_id }, /** Hash of the issuer public key (default empty). Hash algorithm is defined by CKA_NAME_HASH_ALGORITHM */ - { CKA_HASH_OF_ISSUER_PUBLIC_KEY, pkcs11_attrib_empty }, + { CKA_HASH_OF_ISSUER_PUBLIC_KEY, pkcs11_attrib_empty }, /** Defines the mechanism used to calculate CKA_HASH_OF_SUBJECT_PUBLIC_KEY and CKA_HASH_OF_ISSUER_PUBLIC_KEY. If the attribute is not present then the type defaults to SHA-1. */ - { CKA_NAME_HASH_ALGORITHM, pkcs11_attrib_empty }, + { CKA_NAME_HASH_ALGORITHM, pkcs11_attrib_empty }, }; const CK_ULONG pkcs11_cert_wtlspublic_attributes_count = PKCS11_UTIL_ARRAY_SIZE(pkcs11_cert_wtlspublic_attributes); @@ -501,56 +501,56 @@ const CK_ULONG pkcs11_cert_wtlspublic_attributes_count = PKCS11_UTIL_ARRAY_SIZE( */ const pkcs11_attrib_model pkcs11_cert_x509_attributes[] = { /** Object Class - CK_OBJECT_CLASS */ - { CKA_CLASS, pkcs11_object_get_class }, + { CKA_CLASS, pkcs11_object_get_class }, /** CK_TRUE if object is a token object; CK_FALSE if object is a session object. Default is CK_FALSE. */ - { CKA_TOKEN, pkcs11_attrib_true }, + { CKA_TOKEN, pkcs11_attrib_true }, /** CK_TRUE if object is a private object; CK_FALSE if object is a public object. */ - { CKA_PRIVATE, pkcs11_token_get_access_type }, + { CKA_PRIVATE, pkcs11_token_get_access_type }, /** CK_TRUE if object can be modified. Default is CK_TRUE. */ - { CKA_MODIFIABLE, NULL_PTR }, + { CKA_MODIFIABLE, NULL_PTR }, /** Description of the object(default empty). */ - { CKA_LABEL, pkcs11_object_get_name }, + { CKA_LABEL, pkcs11_object_get_name }, /** CK_TRUE if object can be copied using C_CopyObject.Defaults to CK_TRUE. */ - { CKA_COPYABLE, pkcs11_attrib_false }, + { CKA_COPYABLE, pkcs11_attrib_false }, /** CK_TRUE if the object can be destroyed using C_DestroyObject. Default is CK_TRUE. */ - { CKA_DESTROYABLE, pkcs11_object_get_destroyable }, + { CKA_DESTROYABLE, pkcs11_object_get_destroyable }, /** Type of certificate */ - { CKA_CERTIFICATE_TYPE, pkcs11_cert_get_type }, + { CKA_CERTIFICATE_TYPE, pkcs11_cert_get_type }, /** The certificate can be trusted for the application that it was created. */ - { CKA_TRUSTED, NULL_PTR }, + { CKA_TRUSTED, NULL_PTR }, /** Default CK_CERTIFICATE_CATEGORY_UNSPECIFIED) */ - { CKA_CERTIFICATE_CATEGORY, pkcs11_object_get_type }, + { CKA_CERTIFICATE_CATEGORY, pkcs11_object_get_type }, /** Checksum */ - { CKA_CHECK_VALUE, NULL_PTR }, + { CKA_CHECK_VALUE, NULL_PTR }, /** Start date for the certificate (default empty) */ - { CKA_START_DATE, pkcs11_attrib_empty }, + { CKA_START_DATE, pkcs11_attrib_empty }, /** End date for the certificate (default empty) */ - { CKA_END_DATE, pkcs11_attrib_empty }, + { CKA_END_DATE, pkcs11_attrib_empty }, /** ALL: DER-encoding of the SubjectPublicKeyInfo for the public key contained in this certificate (default empty) SubjectPublicKeyInfo ::= SEQUENCE { algorithm AlgorithmIdentifier, subjectPublicKey BIT_STRING } */ - { CKA_PUBLIC_KEY_INFO, pkcs11_attrib_empty }, + { CKA_PUBLIC_KEY_INFO, pkcs11_attrib_empty }, /** X509: DER-encoding of the attribute certificate's subject field. This is distinct from the CKA_SUBJECT attribute contained in CKC_X_509 certificates because the ASN.1 syntax and encoding are different. */ - { CKA_OWNER, pkcs11_attrib_empty }, + { CKA_OWNER, pkcs11_attrib_empty }, /** X509: DER-encoding of the attribute certificate's issuer field. This is distinct from the CKA_ISSUER attribute contained in CKC_X_509 certificates because the ASN.1 syntax and encoding are different. (default empty) */ - { CKA_AC_ISSUER, pkcs11_attrib_empty }, + { CKA_AC_ISSUER, pkcs11_attrib_empty }, /** DER-encoding of the certificate serial number (default empty) */ - { CKA_SERIAL_NUMBER, pkcs11_attrib_empty }, + { CKA_SERIAL_NUMBER, pkcs11_attrib_empty }, /** X509: BER-encoding of a sequence of object identifier values corresponding to the attribute types contained in the certificate. When present, this field offers an opportunity for applications to search for a particular attribute certificate without fetching and parsing the certificate itself. (default empty) */ - { CKA_ATTR_TYPES, pkcs11_attrib_empty }, + { CKA_ATTR_TYPES, pkcs11_attrib_empty }, /** BER-encoded Complete Certificate */ - { CKA_VALUE, pkcs11_cert_get_encoded }, + { CKA_VALUE, pkcs11_cert_get_encoded }, }; const CK_ULONG pkcs11_cert_x509_attributes_count = PKCS11_UTIL_ARRAY_SIZE(pkcs11_cert_x509_attributes); @@ -609,4 +609,3 @@ CK_RV pkcs11_cert_x509_write(CK_VOID_PTR pObject, CK_ATTRIBUTE_PTR pAttribute) /** @} */ - diff --git a/lib/pkcs11/pkcs11_config.h.in b/lib/pkcs11/pkcs11_config.h.in index 62cad8fc6..dbe85a3b4 100644 --- a/lib/pkcs11/pkcs11_config.h.in +++ b/lib/pkcs11/pkcs11_config.h.in @@ -129,7 +129,9 @@ CK_RV pkcs11_config_load_objects(pkcs11_slot_ctx_ptr pSlot); CK_RV pkcs11_config_load(pkcs11_slot_ctx_ptr slot_ctx); CK_RV pkcs11_config_cert(pkcs11_lib_ctx_ptr pLibCtx, pkcs11_slot_ctx_ptr pSlot, pkcs11_object_ptr pObject, CK_ATTRIBUTE_PTR pcLabel); CK_RV pkcs11_config_key(pkcs11_lib_ctx_ptr pLibCtx, pkcs11_slot_ctx_ptr pSlot, pkcs11_object_ptr pObject, CK_ATTRIBUTE_PTR pcLabel); +#if !PKCS11_USE_STATIC_CONFIG CK_RV pkcs11_config_remove_object(pkcs11_lib_ctx_ptr pLibCtx, pkcs11_slot_ctx_ptr pSlot, pkcs11_object_ptr pObject); +#endif void pkcs11_config_init_private(pkcs11_object_ptr pObject, char * label, size_t len); void pkcs11_config_init_public(pkcs11_object_ptr pObject, char * label, size_t len); diff --git a/lib/pkcs11/pkcs11_debug.c b/lib/pkcs11/pkcs11_debug.c index ddce8ffca..1a8e5653d 100644 --- a/lib/pkcs11/pkcs11_debug.c +++ b/lib/pkcs11/pkcs11_debug.c @@ -332,4 +332,4 @@ const char * pkcs11_debug_get_ckr_name(CK_RV rv) return pkcs11_debug_get_name(rv, pkcs11_debug_ckr_names, pkcs11_debug_ckr_names_count); } -#endif \ No newline at end of file +#endif diff --git a/lib/pkcs11/pkcs11_digest.c b/lib/pkcs11/pkcs11_digest.c index c7ac9de30..9250ae172 100644 --- a/lib/pkcs11/pkcs11_digest.c +++ b/lib/pkcs11/pkcs11_digest.c @@ -1,4 +1,3 @@ - #include "pkcs11_init.h" #include "pkcs11_digest.h" #include "pkcs11_object.h" diff --git a/lib/pkcs11/pkcs11_digest.h b/lib/pkcs11/pkcs11_digest.h index 1ccb20de2..58c104ee7 100644 --- a/lib/pkcs11/pkcs11_digest.h +++ b/lib/pkcs11/pkcs11_digest.h @@ -43,4 +43,4 @@ CK_RV pkcs11_digest(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDa CK_RV pkcs11_digest_update(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, CK_ULONG ulPartLen); CK_RV pkcs11_digest_final(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pDigest, CK_ULONG_PTR pulDigestLen); -#endif /* PKCS11_DIGEST_H_ */ \ No newline at end of file +#endif /* PKCS11_DIGEST_H_ */ diff --git a/lib/pkcs11/pkcs11_find.c b/lib/pkcs11/pkcs11_find.c index ec36bcf82..5098d10b5 100644 --- a/lib/pkcs11/pkcs11_find.c +++ b/lib/pkcs11/pkcs11_find.c @@ -451,4 +451,3 @@ CK_RV pkcs11_find_get_attribute(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hOb } /** @} */ - diff --git a/lib/pkcs11/pkcs11_key.c b/lib/pkcs11/pkcs11_key.c index b2507b906..4b75b82cc 100644 --- a/lib/pkcs11/pkcs11_key.c +++ b/lib/pkcs11/pkcs11_key.c @@ -166,8 +166,20 @@ static CK_RV pkcs11_key_get_allowed_mechanisms(CK_VOID_PTR pObject, CK_ATTRIBUTE } else { - return pkcs11_attrib_fill(pAttribute, (CK_VOID_PTR)pkcs11_key_608_secret_mech, - sizeof(pkcs11_key_608_secret_mech)); + switch (((uint8_t*)&pConfig->RevNum)[2]) + { + case 0x60: + return pkcs11_attrib_fill(pAttribute, (CK_VOID_PTR)pkcs11_key_608_secret_mech, + sizeof(pkcs11_key_608_secret_mech)); + break; + case 0x50: + return pkcs11_attrib_fill(pAttribute, (CK_VOID_PTR)pkcs11_key_508_secret_mech, + sizeof(pkcs11_key_508_secret_mech)); + break; + default: + break; + } + } #endif } @@ -253,8 +265,6 @@ static CK_RV pkcs11_key_get_ec_point(CK_VOID_PTR pObject, CK_ATTRIBUTE_PTR pAttr if (CKR_OK == (rv = pkcs11_object_is_private(obj_ptr, &is_private))) { - - if (is_private) { status = atcab_get_pubkey(obj_ptr->slot, &ec_asn1_key[3]); @@ -368,73 +378,73 @@ static CK_RV pkcs11_key_auth_required(CK_VOID_PTR pObject, CK_ATTRIBUTE_PTR pAtt */ const pkcs11_attrib_model pkcs11_key_public_attributes[] = { /** Object Class - CK_OBJECT_CLASS */ - { CKA_CLASS, pkcs11_object_get_class }, + { CKA_CLASS, pkcs11_object_get_class }, /** CK_TRUE if object is a token object; CK_FALSE if object is a session object. Default is CK_FALSE. */ - { CKA_TOKEN, pkcs11_attrib_true }, + { CKA_TOKEN, pkcs11_attrib_true }, /** CK_TRUE if object is a private object; CK_FALSE if object is a public object. */ - { CKA_PRIVATE, pkcs11_attrib_false }, + { CKA_PRIVATE, pkcs11_attrib_false }, /** CK_TRUE if object can be modified. Default is CK_TRUE. */ - { CKA_MODIFIABLE, pkcs11_token_get_writable }, + { CKA_MODIFIABLE, pkcs11_token_get_writable }, /** Description of the object(default empty). */ - { CKA_LABEL, pkcs11_object_get_name }, + { CKA_LABEL, pkcs11_object_get_name }, /** CK_TRUE if object can be copied using C_CopyObject.Defaults to CK_TRUE. */ - { CKA_COPYABLE, pkcs11_attrib_false }, + { CKA_COPYABLE, pkcs11_attrib_false }, /** CK_TRUE if the object can be destroyed using C_DestroyObject. Default is CK_TRUE. */ - { CKA_DESTROYABLE, pkcs11_object_get_destroyable }, + { CKA_DESTROYABLE, pkcs11_object_get_destroyable }, /** Type of key */ - { CKA_KEY_TYPE, pkcs11_object_get_type }, + { CKA_KEY_TYPE, pkcs11_object_get_type }, /** Key identifier for key (default empty) */ - { CKA_ID, pkcs11_attrib_empty }, + { CKA_ID, pkcs11_attrib_empty }, /** Start date for the key (default empty) */ - { CKA_START_DATE, pkcs11_attrib_empty }, + { CKA_START_DATE, pkcs11_attrib_empty }, /** End date for the key (default empty) */ - { CKA_END_DATE, pkcs11_attrib_empty }, + { CKA_END_DATE, pkcs11_attrib_empty }, /** CK_TRUE if key supports key derivation (i.e., if other keys can be derived from this one (default CK_FALSE) */ - { CKA_DERIVE, pkcs11_key_get_derivekey_flag }, + { CKA_DERIVE, pkcs11_key_get_derivekey_flag }, /** CK_TRUE only if key was either generated locally (i.e., on the token) with a C_GenerateKey or C_GenerateKeyPair call created with a C_CopyObject call as a copy of a key which had its CKA_LOCAL attribute set to CK_TRUE */ - { CKA_LOCAL, pkcs11_attrib_true }, + { CKA_LOCAL, pkcs11_attrib_true }, /** Identifier of the mechanism used to generate the key material. */ - { CKA_KEY_GEN_MECHANISM, NULL_PTR }, + { CKA_KEY_GEN_MECHANISM, NULL_PTR }, /** A list of mechanisms allowed to be used with this key. The number of mechanisms in the array is the ulValueLen component of the attribute divided by the size of CK_MECHANISM_TYPE. */ - { CKA_ALLOWED_MECHANISMS, pkcs11_key_get_allowed_mechanisms }, + { CKA_ALLOWED_MECHANISMS, pkcs11_key_get_allowed_mechanisms }, /** DER-encoding of the key subject name (default empty) */ - { CKA_SUBJECT, pkcs11_attrib_empty }, + { CKA_SUBJECT, pkcs11_attrib_empty }, /** CK_TRUE if key supports encryption */ - { CKA_ENCRYPT, NULL_PTR }, + { CKA_ENCRYPT, NULL_PTR }, /** CK_TRUE if key supports verification where the signature is an appendix to the data */ - { CKA_VERIFY, pkcs11_attrib_true }, + { CKA_VERIFY, pkcs11_attrib_true }, /** CK_TRUE if key supports verification where the data is recovered from the signature */ - { CKA_VERIFY_RECOVER, NULL_PTR }, + { CKA_VERIFY_RECOVER, NULL_PTR }, /** CK_TRUE if key supports wrapping (i.e., can be used to wrap other keys) */ - { CKA_WRAP, NULL_PTR }, + { CKA_WRAP, NULL_PTR }, /** The key can be trusted for the application that it was created. The wrapping key can be used to wrap keys with CKA_WRAP_WITH_TRUSTED set to CK_TRUE. */ - { CKA_TRUSTED, NULL_PTR }, + { CKA_TRUSTED, NULL_PTR }, /** For wrapping keys. The attribute template to match against any keys wrapped using this wrapping key. Keys that do not match cannot be wrapped. The number of attributes in the array is the ulValueLen component of the attribute divided by the size of CK_ATTRIBUTE. */ - { CKA_WRAP_TEMPLATE, NULL_PTR }, + { CKA_WRAP_TEMPLATE, NULL_PTR }, /** DER-encoding of the SubjectPublicKeyInfo for this public key. (MAY be empty, DEFAULT derived from the underlying public key data) SubjectPublicKeyInfo ::= SEQUENCE { algorithm AlgorithmIdentifier, subjectPublicKey BIT_STRING } */ - { CKA_PUBLIC_KEY_INFO, pkcs11_key_get_public_key }, + { CKA_PUBLIC_KEY_INFO, pkcs11_key_get_public_key }, /** DER - encoding of an ANSI X9.62 Parameters value Parameters ::= CHOICE { ecParameters ECParameters, namedCurve CURVES.&id({CurveNames}), implicitlyCA NULL } */ - { CKA_EC_PARAMS, pkcs11_key_get_ec_params }, + { CKA_EC_PARAMS, pkcs11_key_get_ec_params }, /** DER - encoding of ANSI X9.62 ECPoint value Q */ - { CKA_EC_POINT, pkcs11_key_get_ec_point }, + { CKA_EC_POINT, pkcs11_key_get_ec_point }, }; const CK_ULONG pkcs11_key_public_attributes_count = PKCS11_UTIL_ARRAY_SIZE(pkcs11_key_public_attributes); @@ -448,9 +458,9 @@ const pkcs11_attrib_model pkcs11_key_ec_public_attributes[] = { ecParameters ECParameters, namedCurve CURVES.&id({CurveNames}), implicitlyCA NULL } */ - { CKA_EC_PARAMS, pkcs11_key_get_ec_params }, + { CKA_EC_PARAMS, pkcs11_key_get_ec_params }, /** DER - encoding of ANSI X9.62 ECPoint value Q */ - { CKA_EC_POINT, pkcs11_key_get_ec_point }, + { CKA_EC_POINT, pkcs11_key_get_ec_point }, }; /** @@ -458,81 +468,81 @@ const pkcs11_attrib_model pkcs11_key_ec_public_attributes[] = { */ const pkcs11_attrib_model pkcs11_key_private_attributes[] = { /** Object Class - CK_OBJECT_CLASS */ - { CKA_CLASS, pkcs11_object_get_class }, + { CKA_CLASS, pkcs11_object_get_class }, /** CK_TRUE if object is a token object; CK_FALSE if object is a session object. Default is CK_FALSE. */ - { CKA_TOKEN, pkcs11_attrib_true }, + { CKA_TOKEN, pkcs11_attrib_true }, /** CK_TRUE if object is a private object; CK_FALSE if object is a public object. */ - { CKA_PRIVATE, pkcs11_attrib_true }, + { CKA_PRIVATE, pkcs11_attrib_true }, /** CK_TRUE if object can be modified. Default is CK_TRUE. */ - { CKA_MODIFIABLE, pkcs11_token_get_writable }, + { CKA_MODIFIABLE, pkcs11_token_get_writable }, /** Description of the object(default empty). */ - { CKA_LABEL, pkcs11_object_get_name }, + { CKA_LABEL, pkcs11_object_get_name }, /** CK_TRUE if object can be copied using C_CopyObject.Defaults to CK_TRUE. */ - { CKA_COPYABLE, pkcs11_attrib_false }, + { CKA_COPYABLE, pkcs11_attrib_false }, /** CK_TRUE if the object can be destroyed using C_DestroyObject. Default is CK_TRUE. */ - { CKA_DESTROYABLE, pkcs11_object_get_destroyable }, + { CKA_DESTROYABLE, pkcs11_object_get_destroyable }, /** Type of key */ - { CKA_KEY_TYPE, pkcs11_object_get_type }, + { CKA_KEY_TYPE, pkcs11_object_get_type }, /** Key identifier for key (default empty) */ - { CKA_ID, pkcs11_attrib_empty }, + { CKA_ID, pkcs11_attrib_empty }, /** Start date for the key (default empty) */ - { CKA_START_DATE, pkcs11_attrib_empty }, + { CKA_START_DATE, pkcs11_attrib_empty }, /** End date for the key (default empty) */ - { CKA_END_DATE, pkcs11_attrib_empty }, + { CKA_END_DATE, pkcs11_attrib_empty }, /** CK_TRUE if key supports key derivation (i.e., if other keys can be derived from this one (default CK_FALSE) */ - { CKA_DERIVE, pkcs11_key_get_derivekey_flag }, + { CKA_DERIVE, pkcs11_key_get_derivekey_flag }, /** CK_TRUE only if key was either generated locally (i.e., on the token) with a C_GenerateKey or C_GenerateKeyPair call created with a C_CopyObject call as a copy of a key which had its CKA_LOCAL attribute set to CK_TRUE */ - { CKA_LOCAL, pkcs11_key_get_local_flag }, + { CKA_LOCAL, pkcs11_key_get_local_flag }, /** Identifier of the mechanism used to generate the key material. */ - { CKA_KEY_GEN_MECHANISM, NULL_PTR }, + { CKA_KEY_GEN_MECHANISM, NULL_PTR }, /** A list of mechanisms allowed to be used with this key. The number of mechanisms in the array is the ulValueLen component of the attribute divided by the size of CK_MECHANISM_TYPE. */ - { CKA_ALLOWED_MECHANISMS, pkcs11_key_get_allowed_mechanisms }, + { CKA_ALLOWED_MECHANISMS, pkcs11_key_get_allowed_mechanisms }, /** DER-encoding of the key subject name (default empty) */ - { CKA_SUBJECT, pkcs11_attrib_empty }, + { CKA_SUBJECT, pkcs11_attrib_empty }, /** CK_TRUE if key is sensitive */ - { CKA_SENSITIVE, pkcs11_token_get_access_type }, + { CKA_SENSITIVE, pkcs11_token_get_access_type }, /** CK_TRUE if key supports decryption */ - { CKA_DECRYPT, NULL_PTR }, + { CKA_DECRYPT, NULL_PTR }, /** CK_TRUE if key supports signatures where the signature is an appendix to the data */ - { CKA_SIGN, pkcs11_attrib_true }, + { CKA_SIGN, pkcs11_attrib_true }, /** CK_TRUE if key supports signatures where the data can be recovered from the signature9 */ - { CKA_SIGN_RECOVER, NULL_PTR }, + { CKA_SIGN_RECOVER, NULL_PTR }, /** CK_TRUE if key supports unwrapping (i.e., can be used to unwrap other keys)9 */ - { CKA_UNWRAP, NULL_PTR }, + { CKA_UNWRAP, NULL_PTR }, /** CK_TRUE if key is extractable and can be wrapped 9 */ - { CKA_EXTRACTABLE, NULL_PTR }, + { CKA_EXTRACTABLE, NULL_PTR }, /** CK_TRUE if key has always had the CKA_SENSITIVE attribute set to CK_TRUE */ - { CKA_ALWAYS_SENSITIVE, pkcs11_token_get_access_type }, + { CKA_ALWAYS_SENSITIVE, pkcs11_token_get_access_type }, /** CK_TRUE if key has never had the CKA_EXTRACTABLE attribute set to CK_TRUE */ - { CKA_NEVER_EXTRACTABLE, NULL_PTR }, + { CKA_NEVER_EXTRACTABLE, NULL_PTR }, /** CK_TRUE if the key can only be wrapped with a wrapping key that has CKA_TRUSTED set to CK_TRUE. Default is CK_FALSE. */ - { CKA_WRAP_WITH_TRUSTED, NULL_PTR }, + { CKA_WRAP_WITH_TRUSTED, NULL_PTR }, /** For wrapping keys. The attribute template to match against any keys wrapped using this wrapping key. Keys that do not match cannot be wrapped. The number of attributes in the array is the ulValueLen component of the attribute divided by the size of CK_ATTRIBUTE. */ - { CKA_UNWRAP_TEMPLATE, NULL_PTR }, + { CKA_UNWRAP_TEMPLATE, NULL_PTR }, /** If CK_TRUE, the user has to supply the PIN for each use (sign or decrypt) with the key. Default is CK_FALSE. */ - { CKA_ALWAYS_AUTHENTICATE, pkcs11_key_auth_required }, + { CKA_ALWAYS_AUTHENTICATE, pkcs11_key_auth_required }, /** DER-encoding of the SubjectPublicKeyInfo for the associated public key (MAY be empty; DEFAULT derived from the underlying private key data; MAY be manually set for specific key types; if set; MUST be consistent with the underlying private key data) */ - { CKA_PUBLIC_KEY_INFO, pkcs11_key_get_public_key }, + { CKA_PUBLIC_KEY_INFO, pkcs11_key_get_public_key }, /** DER - encoding of an ANSI X9.62 Parameters value Parameters ::= CHOICE { ecParameters ECParameters, namedCurve CURVES.&id({CurveNames}), implicitlyCA NULL } */ - { CKA_EC_PARAMS, pkcs11_key_get_ec_params }, + { CKA_EC_PARAMS, pkcs11_key_get_ec_params }, /** DER - encoding of ANSI X9.62 ECPoint value Q */ - { CKA_EC_POINT, pkcs11_key_get_ec_point }, + { CKA_EC_POINT, pkcs11_key_get_ec_point }, /** The value of the private key should remain private. A NULL function pointer is interpreted as a sensitive attribute. */ - { CKA_VALUE, NULL_PTR }, + { CKA_VALUE, NULL_PTR }, }; const CK_ULONG pkcs11_key_private_attributes_count = PKCS11_UTIL_ARRAY_SIZE(pkcs11_key_private_attributes); @@ -542,21 +552,21 @@ const CK_ULONG pkcs11_key_private_attributes_count = PKCS11_UTIL_ARRAY_SIZE(pkcs */ const pkcs11_attrib_model pkcs11_key_rsa_private_attributes[] = { /** Big integer Modulus n */ - { CKA_MODULUS, NULL_PTR }, + { CKA_MODULUS, NULL_PTR }, /** Big integer Public exponent e */ - { CKA_PUBLIC_EXPONENT, NULL_PTR }, + { CKA_PUBLIC_EXPONENT, NULL_PTR }, /** Big integer Private exponent d */ - { CKA_PRIVATE_EXPONENT, NULL_PTR }, + { CKA_PRIVATE_EXPONENT, NULL_PTR }, /** Big integer Prime p */ - { CKA_PRIME_1, NULL_PTR }, + { CKA_PRIME_1, NULL_PTR }, /** Big integer Prime q */ - { CKA_PRIME_2, NULL_PTR }, + { CKA_PRIME_2, NULL_PTR }, /** Big integer Private exponent d modulo p - 1 */ - { CKA_EXPONENT_1, NULL_PTR }, + { CKA_EXPONENT_1, NULL_PTR }, /** Big integer Private exponent d modulo q - 1 */ - { CKA_EXPONENT_2, NULL_PTR }, + { CKA_EXPONENT_2, NULL_PTR }, /** Big integer CRT coefficient q - 1 mod p */ - { CKA_COEFFICIENT, NULL_PTR }, + { CKA_COEFFICIENT, NULL_PTR }, }; /** @@ -568,9 +578,9 @@ const pkcs11_attrib_model pkcs11_key_ec_private_attributes[] = { ecParameters ECParameters, namedCurve CURVES.&id({CurveNames}), implicitlyCA NULL } */ - { CKA_EC_PARAMS, pkcs11_key_get_ec_params }, + { CKA_EC_PARAMS, pkcs11_key_get_ec_params }, /** DER - encoding of ANSI X9.62 ECPoint value Q */ - { CKA_EC_POINT, pkcs11_key_get_ec_point }, + { CKA_EC_POINT, pkcs11_key_get_ec_point }, }; @@ -579,82 +589,82 @@ const pkcs11_attrib_model pkcs11_key_ec_private_attributes[] = { */ const pkcs11_attrib_model pkcs11_key_secret_attributes[] = { /** Object Class - CK_OBJECT_CLASS */ - { CKA_CLASS, pkcs11_object_get_class }, + { CKA_CLASS, pkcs11_object_get_class }, /** CK_TRUE if object is a token object; CK_FALSE if object is a session object. Default is CK_FALSE. */ - { CKA_TOKEN, pkcs11_token_get_storage }, + { CKA_TOKEN, pkcs11_token_get_storage }, /** CK_TRUE if object is a private object; CK_FALSE if object is a public object. */ - { CKA_PRIVATE, pkcs11_token_get_access_type }, + { CKA_PRIVATE, pkcs11_token_get_access_type }, /** CK_TRUE if object can be modified. Default is CK_TRUE. */ - { CKA_MODIFIABLE, pkcs11_token_get_writable }, + { CKA_MODIFIABLE, pkcs11_token_get_writable }, /** Description of the object(default empty). */ - { CKA_LABEL, pkcs11_object_get_name }, + { CKA_LABEL, pkcs11_object_get_name }, /** CK_TRUE if object can be copied using C_CopyObject.Defaults to CK_TRUE. */ - { CKA_COPYABLE, pkcs11_attrib_false }, + { CKA_COPYABLE, pkcs11_attrib_false }, /** CK_TRUE if the object can be destroyed using C_DestroyObject. Default is CK_TRUE. */ - { CKA_DESTROYABLE, pkcs11_object_get_destroyable }, + { CKA_DESTROYABLE, pkcs11_object_get_destroyable }, /** Type of key */ - { CKA_KEY_TYPE, pkcs11_object_get_type }, + { CKA_KEY_TYPE, pkcs11_object_get_type }, /** Key identifier for key (default empty) */ - { CKA_ID, pkcs11_attrib_empty }, + { CKA_ID, pkcs11_attrib_empty }, /** Start date for the key (default empty) */ - { CKA_START_DATE, pkcs11_attrib_empty }, + { CKA_START_DATE, pkcs11_attrib_empty }, /** End date for the key (default empty) */ - { CKA_END_DATE, pkcs11_attrib_empty }, + { CKA_END_DATE, pkcs11_attrib_empty }, /** CK_TRUE if key supports key derivation (i.e., if other keys can be derived from this one (default CK_FALSE) */ - { CKA_DERIVE, pkcs11_attrib_true }, + { CKA_DERIVE, pkcs11_attrib_true }, /** CK_TRUE only if key was either generated locally (i.e., on the token) with a C_GenerateKey or C_GenerateKeyPair call created with a C_CopyObject call as a copy of a key which had its CKA_LOCAL attribute set to CK_TRUE */ - { CKA_LOCAL, pkcs11_key_get_local_flag }, + { CKA_LOCAL, pkcs11_key_get_local_flag }, /** Identifier of the mechanism used to generate the key material. */ - { CKA_KEY_GEN_MECHANISM, NULL_PTR }, + { CKA_KEY_GEN_MECHANISM, NULL_PTR }, /** A list of mechanisms allowed to be used with this key. The number of mechanisms in the array is the ulValueLen component of the attribute divided by the size of CK_MECHANISM_TYPE. */ - { CKA_ALLOWED_MECHANISMS, pkcs11_key_get_allowed_mechanisms }, + { CKA_ALLOWED_MECHANISMS, pkcs11_key_get_allowed_mechanisms }, /** CK_TRUE if key is sensitive */ - { CKA_SENSITIVE, pkcs11_token_get_access_type }, + { CKA_SENSITIVE, pkcs11_token_get_access_type }, /** CK_TRUE if key supports encryption */ - { CKA_ENCRYPT, NULL_PTR }, + { CKA_ENCRYPT, NULL_PTR }, /** CK_TRUE if key supports decryption */ - { CKA_DECRYPT, NULL_PTR }, + { CKA_DECRYPT, NULL_PTR }, /** CK_TRUE if key supports signatures (i.e., authentication codes) where the signature is an appendix to the data */ - { CKA_SIGN, NULL_PTR }, + { CKA_SIGN, NULL_PTR }, /** CK_TRUE if key supports verification (i.e., of authentication codes) where the signature is an appendix to the data */ - { CKA_VERIFY, NULL_PTR }, + { CKA_VERIFY, NULL_PTR }, /** CK_TRUE if key supports wrapping (i.e., can be used to wrap other keys) */ - { CKA_WRAP, NULL_PTR }, + { CKA_WRAP, NULL_PTR }, /** CK_TRUE if key supports unwrapping (i.e., can be used to unwrap other keys) */ - { CKA_UNWRAP, NULL_PTR }, + { CKA_UNWRAP, NULL_PTR }, /** CK_TRUE if key is extractable and can be wrapped */ - { CKA_EXTRACTABLE, NULL_PTR }, + { CKA_EXTRACTABLE, NULL_PTR }, /** CK_TRUE if key has always had the CKA_SENSITIVE attribute set to CK_TRUE */ - { CKA_ALWAYS_SENSITIVE, pkcs11_token_get_access_type }, + { CKA_ALWAYS_SENSITIVE, pkcs11_token_get_access_type }, /** CK_TRUE if key has never had the CKA_EXTRACTABLE attribute set to CK_TRUE */ - { CKA_NEVER_EXTRACTABLE, NULL_PTR }, + { CKA_NEVER_EXTRACTABLE, NULL_PTR }, /** Key checksum */ - { CKA_CHECK_VALUE, pkcs11_key_get_check_value }, + { CKA_CHECK_VALUE, pkcs11_key_get_check_value }, /** CK_TRUE if the key can only be wrapped with a wrapping key that has CKA_TRUSTED set to CK_TRUE. Default is CK_FALSE. */ - { CKA_WRAP_WITH_TRUSTED, NULL_PTR }, + { CKA_WRAP_WITH_TRUSTED, NULL_PTR }, /** The wrapping key can be used to wrap keys with CKA_WRAP_WITH_TRUSTED set to CK_TRUE. */ - { CKA_TRUSTED, NULL_PTR }, + { CKA_TRUSTED, NULL_PTR }, /** For wrapping keys. The attribute template to match against any keys wrapped using this wrapping key. Keys that do not match cannot be wrapped. The number of attributes in the array is the ulValueLen component of the attribute divided by the size of CK_ATTRIBUTE */ - { CKA_WRAP_TEMPLATE, NULL_PTR }, + { CKA_WRAP_TEMPLATE, NULL_PTR }, /** For wrapping keys. The attribute template to apply to any keys unwrapped using this wrapping key. Any user supplied template is applied after this template as if the object has already been created. The number of attributes in the array is the ulValueLen component of the attribute divided by the size of CK_ATTRIBUTE. */ - { CKA_UNWRAP_TEMPLATE, NULL_PTR }, + { CKA_UNWRAP_TEMPLATE, NULL_PTR }, /* Key value */ - { CKA_VALUE, pkcs11_key_get_secret }, + { CKA_VALUE, pkcs11_key_get_secret }, /* Length in bytes of the key */ - { CKA_VALUE_LEN, pkcs11_key_get_secret_length }, + { CKA_VALUE_LEN, pkcs11_key_get_secret_length }, }; const CK_ULONG pkcs11_key_secret_attributes_count = PKCS11_UTIL_ARRAY_SIZE(pkcs11_key_secret_attributes); diff --git a/lib/pkcs11/pkcs11_mech.c b/lib/pkcs11/pkcs11_mech.c index 6541a94e5..96dac65da 100644 --- a/lib/pkcs11/pkcs11_mech.c +++ b/lib/pkcs11/pkcs11_mech.c @@ -48,25 +48,25 @@ typedef struct _pcks11_mech_table_e static pcks11_mech_table_e pkcs11_mech_list_ecc508[] = { //CKM_DH_PKCS_KEY_PAIR_GEN, //CKM_DH_PKCS_DERIVE, - { CKM_SHA256, { 256, 256, CKF_HW | CKF_DIGEST } }, - { CKM_SHA256_HMAC, { 256, 256, CKF_HW | CKF_SIGN | CKF_VERIFY } }, - { CKM_SHA256_HMAC_GENERAL, { 256, 256, CKF_HW | CKF_SIGN | CKF_VERIFY } }, - { CKM_GENERIC_SECRET_KEY_GEN, { 0, 0, CKF_HW | CKF_GENERATE | CKF_GENERATE_KEY_PAIR } }, - { CKM_CONCATENATE_BASE_AND_KEY, { 0, 0, CKF_HW | CKF_DERIVE } }, - { CKM_CONCATENATE_BASE_AND_DATA, { 0, 0, CKF_HW | CKF_DERIVE } }, - { CKM_CONCATENATE_DATA_AND_BASE, { 0, 0, CKF_HW | CKF_DERIVE } }, - { CKM_XOR_BASE_AND_DATA, { 0, 0, CKF_HW | CKF_DERIVE } }, - { CKM_EXTRACT_KEY_FROM_KEY, { 0, 0, CKF_HW | CKF_DERIVE } }, - { CKM_SSL3_PRE_MASTER_KEY_GEN, { 0, 0, CKF_HW | CKF_GENERATE | CKF_GENERATE_KEY_PAIR } }, - { CKM_SSL3_MASTER_KEY_DERIVE, { 0, 0, CKF_HW | CKF_DERIVE } }, - { CKM_SSL3_KEY_AND_MAC_DERIVE, { 0, 0, CKF_HW | CKF_DERIVE } }, - { CKM_SSL3_MASTER_KEY_DERIVE_DH, { 0, 0, CKF_HW | CKF_DERIVE } }, - { CKM_TLS_PRE_MASTER_KEY_GEN, { 0, 0, CKF_HW | CKF_GENERATE | CKF_GENERATE_KEY_PAIR } }, - { CKM_TLS_MASTER_KEY_DERIVE, { 0, 0, CKF_HW | CKF_DERIVE } }, - { CKM_TLS_KEY_AND_MAC_DERIVE, { 0, 0, CKF_HW | CKF_DERIVE } }, - { CKM_TLS_MASTER_KEY_DERIVE_DH, { 0, 0, CKF_HW | CKF_DERIVE } }, - { CKM_TLS_PRF, { 0, 0, CKF_HW | CKF_DERIVE } }, - { CKM_SHA256_KEY_DERIVATION, { 256, 256, CKF_HW | CKF_DERIVE } }, + { CKM_SHA256, { 256, 256, CKF_HW | CKF_DIGEST } }, + { CKM_SHA256_HMAC, { 256, 256, CKF_HW | CKF_SIGN | CKF_VERIFY } }, + { CKM_SHA256_HMAC_GENERAL, { 256, 256, CKF_HW | CKF_SIGN | CKF_VERIFY } }, + { CKM_GENERIC_SECRET_KEY_GEN, { 0, 0, CKF_HW | CKF_GENERATE | CKF_GENERATE_KEY_PAIR } }, + { CKM_CONCATENATE_BASE_AND_KEY, { 0, 0, CKF_HW | CKF_DERIVE } }, + { CKM_CONCATENATE_BASE_AND_DATA, { 0, 0, CKF_HW | CKF_DERIVE } }, + { CKM_CONCATENATE_DATA_AND_BASE, { 0, 0, CKF_HW | CKF_DERIVE } }, + { CKM_XOR_BASE_AND_DATA, { 0, 0, CKF_HW | CKF_DERIVE } }, + { CKM_EXTRACT_KEY_FROM_KEY, { 0, 0, CKF_HW | CKF_DERIVE } }, + { CKM_SSL3_PRE_MASTER_KEY_GEN, { 0, 0, CKF_HW | CKF_GENERATE | CKF_GENERATE_KEY_PAIR } }, + { CKM_SSL3_MASTER_KEY_DERIVE, { 0, 0, CKF_HW | CKF_DERIVE } }, + { CKM_SSL3_KEY_AND_MAC_DERIVE, { 0, 0, CKF_HW | CKF_DERIVE } }, + { CKM_SSL3_MASTER_KEY_DERIVE_DH, { 0, 0, CKF_HW | CKF_DERIVE } }, + { CKM_TLS_PRE_MASTER_KEY_GEN, { 0, 0, CKF_HW | CKF_GENERATE | CKF_GENERATE_KEY_PAIR } }, + { CKM_TLS_MASTER_KEY_DERIVE, { 0, 0, CKF_HW | CKF_DERIVE } }, + { CKM_TLS_KEY_AND_MAC_DERIVE, { 0, 0, CKF_HW | CKF_DERIVE } }, + { CKM_TLS_MASTER_KEY_DERIVE_DH, { 0, 0, CKF_HW | CKF_DERIVE } }, + { CKM_TLS_PRF, { 0, 0, CKF_HW | CKF_DERIVE } }, + { CKM_SHA256_KEY_DERIVATION, { 256, 256, CKF_HW | CKF_DERIVE } }, //CKM_WTLS_PRE_MASTER_KEY_GEN, //CKM_WTLS_MASTER_KEY_DERIVE, //CKM_WTLS_MASTER_KEY_DERIVE_DH_ECC, @@ -97,13 +97,13 @@ static pcks11_mech_table_e pkcs11_mech_list_ecc508[] = { //CKM_SEED_CBC_PAD, //CKM_SEED_ECB_ENCRYPT_DATA, //CKM_SEED_CBC_ENCRYPT_DATA, - { CKM_EC_KEY_PAIR_GEN, { 0, 0, CKF_HW | CKF_GENERATE | CKF_GENERATE_KEY_PAIR | PCKS11_MECH_ECC508_EC_CAPABILITY } }, - { CKM_ECDSA, { 256, 256, CKF_HW | CKF_SIGN | CKF_VERIFY | PCKS11_MECH_ECC508_EC_CAPABILITY } }, - { CKM_ECDSA_SHA256, { 256, 256, CKF_HW | CKF_SIGN | CKF_VERIFY | PCKS11_MECH_ECC508_EC_CAPABILITY } }, - { CKM_ECDH1_DERIVE, { 0, 0, CKF_HW | CKF_DERIVE | PCKS11_MECH_ECC508_EC_CAPABILITY } }, - { CKM_ECDH1_COFACTOR_DERIVE, { 0, 0, CKF_HW | CKF_DERIVE | PCKS11_MECH_ECC508_EC_CAPABILITY } }, - { CKM_ECMQV_DERIVE, { 0, 0, CKF_HW | CKF_DERIVE | PCKS11_MECH_ECC508_EC_CAPABILITY } }, - { CKM_ECDH_AES_KEY_WRAP, { 0, 0, CKF_HW | CKF_WRAP | CKF_UNWRAP | PCKS11_MECH_ECC508_EC_CAPABILITY } }, + { CKM_EC_KEY_PAIR_GEN, { 0, 0, CKF_HW | CKF_GENERATE | CKF_GENERATE_KEY_PAIR | PCKS11_MECH_ECC508_EC_CAPABILITY } }, + { CKM_ECDSA, { 256, 256, CKF_HW | CKF_SIGN | CKF_VERIFY | PCKS11_MECH_ECC508_EC_CAPABILITY } }, + { CKM_ECDSA_SHA256, { 256, 256, CKF_HW | CKF_SIGN | CKF_VERIFY | PCKS11_MECH_ECC508_EC_CAPABILITY } }, + { CKM_ECDH1_DERIVE, { 0, 0, CKF_HW | CKF_DERIVE | PCKS11_MECH_ECC508_EC_CAPABILITY } }, + { CKM_ECDH1_COFACTOR_DERIVE, { 0, 0, CKF_HW | CKF_DERIVE | PCKS11_MECH_ECC508_EC_CAPABILITY } }, + { CKM_ECMQV_DERIVE, { 0, 0, CKF_HW | CKF_DERIVE | PCKS11_MECH_ECC508_EC_CAPABILITY } }, + { CKM_ECDH_AES_KEY_WRAP, { 0, 0, CKF_HW | CKF_WRAP | CKF_UNWRAP | PCKS11_MECH_ECC508_EC_CAPABILITY } }, //CKM_FASTHASH, //CKM_AES_KEY_GEN, //CKM_AES_ECB, @@ -122,7 +122,7 @@ static pcks11_mech_table_e pkcs11_mech_list_ecc508[] = { //{CKM_AES_GMAC, //CKM_AES_ECB_ENCRYPT_DATA, //CKM_AES_CBC_ENCRYPT_DATA, - { CKM_DH_PKCS_PARAMETER_GEN, { 0, 0, CKF_HW | CKF_GENERATE | CKF_GENERATE_KEY_PAIR } } + { CKM_DH_PKCS_PARAMETER_GEN, { 0, 0, CKF_HW | CKF_GENERATE | CKF_GENERATE_KEY_PAIR } } //CKM_AES_OFB, //CKM_AES_CFB64, //CKM_AES_CFB8, @@ -136,9 +136,9 @@ static pcks11_mech_table_e pkcs11_mech_list_ecc508[] = { static pcks11_mech_table_e pkcs11_mech_list_ecc608[] = { //CKM_DH_PKCS_KEY_PAIR_GEN, //CKM_DH_PKCS_DERIVE, - { CKM_SHA256, { 256, 256, CKF_HW | CKF_DIGEST } }, - { CKM_SHA256_HMAC, { 256, 256, CKF_HW | CKF_SIGN | CKF_VERIFY } }, - { CKM_SHA256_HMAC_GENERAL, { 256, 256, CKF_HW | CKF_SIGN | CKF_VERIFY } }, + { CKM_SHA256, { 256, 256, CKF_HW | CKF_DIGEST } }, + { CKM_SHA256_HMAC, { 256, 256, CKF_HW | CKF_SIGN | CKF_VERIFY } }, + { CKM_SHA256_HMAC_GENERAL, { 256, 256, CKF_HW | CKF_SIGN | CKF_VERIFY } }, //{ CKM_GENERIC_SECRET_KEY_GEN,{ 0, 0, CKF_HW | CKF_GENERATE | CKF_GENERATE_KEY_PAIR } }, //{ CKM_CONCATENATE_BASE_AND_KEY,{ 0, 0, CKF_HW | CKF_DERIVE } }, //{ CKM_CONCATENATE_BASE_AND_DATA,{ 0, 0, CKF_HW | CKF_DERIVE } }, @@ -185,8 +185,8 @@ static pcks11_mech_table_e pkcs11_mech_list_ecc608[] = { //CKM_SEED_CBC_PAD, //CKM_SEED_ECB_ENCRYPT_DATA, //CKM_SEED_CBC_ENCRYPT_DATA, - { CKM_EC_KEY_PAIR_GEN, { 256, 256, CKF_HW | CKF_GENERATE | CKF_GENERATE_KEY_PAIR | PCKS11_MECH_ECC508_EC_CAPABILITY } }, - { CKM_ECDSA, { 256, 256, CKF_HW | CKF_SIGN | CKF_VERIFY | PCKS11_MECH_ECC508_EC_CAPABILITY } }, + { CKM_EC_KEY_PAIR_GEN, { 256, 256, CKF_HW | CKF_GENERATE | CKF_GENERATE_KEY_PAIR | PCKS11_MECH_ECC508_EC_CAPABILITY } }, + { CKM_ECDSA, { 256, 256, CKF_HW | CKF_SIGN | CKF_VERIFY | PCKS11_MECH_ECC508_EC_CAPABILITY } }, //{ CKM_ECDSA_SHA256,{ 256, 256, CKF_HW | CKF_SIGN | CKF_VERIFY | PCKS11_MECH_ECC508_EC_CAPABILITY } }, //{ CKM_ECDH1_DERIVE,{ 0, 0, CKF_HW | CKF_DERIVE | PCKS11_MECH_ECC508_EC_CAPABILITY } }, //{ CKM_ECDH1_COFACTOR_DERIVE,{ 0, 0, CKF_HW | CKF_DERIVE | PCKS11_MECH_ECC508_EC_CAPABILITY } }, @@ -194,22 +194,22 @@ static pcks11_mech_table_e pkcs11_mech_list_ecc608[] = { //{ CKM_ECDH_AES_KEY_WRAP,{ 0, 0, CKF_HW | CKF_WRAP | CKF_UNWRAP | PCKS11_MECH_ECC508_EC_CAPABILITY } }, //CKM_FASTHASH, //CKM_AES_KEY_GEN, - { CKM_AES_ECB, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, - { CKM_AES_CBC, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, + { CKM_AES_ECB, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, + { CKM_AES_CBC, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, //{CKM_AES_MAC, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT} }, //{CKM_AES_MAC_GENERAL, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT} }, //CKM_AES_CBC_PAD, - { CKM_AES_CTR, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, - { CKM_AES_GCM, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, - { CKM_AES_CCM, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, + { CKM_AES_CTR, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, + { CKM_AES_GCM, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, + { CKM_AES_CCM, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, //CKM_AES_CTS, - { CKM_AES_CMAC, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, - { CKM_AES_CMAC_GENERAL, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, + { CKM_AES_CMAC, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, + { CKM_AES_CMAC_GENERAL, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, //CKM_AES_XCBC_MAC, //CKM_AES_XCBC_MAC_96, //{CKM_AES_GMAC, - { CKM_AES_ECB_ENCRYPT_DATA, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, - { CKM_AES_CBC_ENCRYPT_DATA, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, + { CKM_AES_ECB_ENCRYPT_DATA, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, + { CKM_AES_CBC_ENCRYPT_DATA, { 128, 128, CKF_HW | CKF_ENCRYPT | CKF_DECRYPT } }, //{ CKM_DH_PKCS_PARAMETER_GEN,{ 0, 0, CKF_HW | CKF_GENERATE | CKF_GENERATE_KEY_PAIR } } //CKM_AES_OFB, //CKM_AES_CFB64, @@ -360,4 +360,3 @@ CK_RV pkcs_mech_get_info(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type, CK_MECHANISM } /** @} */ - diff --git a/lib/pkcs11/pkcs11_object.c b/lib/pkcs11/pkcs11_object.c index 869beb990..44ab9aeb6 100644 --- a/lib/pkcs11/pkcs11_object.c +++ b/lib/pkcs11/pkcs11_object.c @@ -68,16 +68,16 @@ static CK_OBJECT_HANDLE pkcs11_object_alloc_handle(void) */ const pkcs11_attrib_model pkcs11_object_monotonic_attributes[] = { /** Object Class - CK_OBJECT_CLASS */ - { CKA_CLASS, pkcs11_object_get_class }, + { CKA_CLASS, pkcs11_object_get_class }, /** Hardware Feature Type - CK_HW_FEATURE_TYPE */ - { CKA_HW_FEATURE_TYPE, pkcs11_object_get_type }, + { CKA_HW_FEATURE_TYPE, pkcs11_object_get_type }, /** Counter will reset to a previously returned value if the token is initialized using C_InitToken. */ - { CKA_RESET_ON_INIT, pkcs11_attrib_false }, + { CKA_RESET_ON_INIT, pkcs11_attrib_false }, /** Counter has been reset at least once at some point in time. */ - { CKA_HAS_RESET, pkcs11_attrib_false }, + { CKA_HAS_RESET, pkcs11_attrib_false }, /** Current value of the monotonic counter. Big endian order. */ - { CKA_VALUE, NULL_PTR }, + { CKA_VALUE, NULL_PTR }, }; const CK_ULONG pkcs11_object_monotonic_attributes_count = PKCS11_UTIL_ARRAY_SIZE(pkcs11_object_monotonic_attributes); @@ -491,7 +491,9 @@ CK_RV pkcs11_object_create rv = pkcs11_key_write(pSession, pObject, pData); if (rv) { +#if !PKCS11_USE_STATIC_CONFIG (void)pkcs11_config_remove_object(pLibCtx, pSession->slot, pObject); +#endif } } break; @@ -502,7 +504,9 @@ CK_RV pkcs11_object_create rv = pkcs11_key_write(pSession, pObject, pData); if (rv) { +#if !PKCS11_USE_STATIC_CONFIG (void)pkcs11_config_remove_object(pLibCtx, pSession->slot, pObject); +#endif } } break; @@ -656,4 +660,3 @@ CK_RV pkcs11_object_is_private(pkcs11_object_ptr pObject, CK_BBOOL * is_private) /** @} */ - diff --git a/lib/pkcs11/pkcs11_os.h b/lib/pkcs11/pkcs11_os.h index 9825da36f..33f13ab3d 100644 --- a/lib/pkcs11/pkcs11_os.h +++ b/lib/pkcs11/pkcs11_os.h @@ -40,4 +40,3 @@ CK_RV pkcs11_os_unlock_mutex(CK_VOID_PTR pMutex); #define pkcs11_os_free hal_free #endif /* PKCS11_OS_H_ */ - diff --git a/lib/pkcs11/pkcs11_session.c b/lib/pkcs11/pkcs11_session.c index 05648f281..16821a94d 100644 --- a/lib/pkcs11/pkcs11_session.c +++ b/lib/pkcs11/pkcs11_session.c @@ -370,7 +370,10 @@ CK_RV pkcs11_session_login(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, CK bool is_ca_device = atcab_is_ca_device(atcab_get_device_type()); uint16_t key_len = is_ca_device ? 32 : 16; CK_RV rv; + +#if ATCA_TA_SUPPORT ATCA_STATUS status; +#endif if (!pLibCtx || !pLibCtx->initialized) { diff --git a/lib/pkcs11/pkcs11_signature.c b/lib/pkcs11/pkcs11_signature.c index 0e2a71395..aa4d4c2a8 100644 --- a/lib/pkcs11/pkcs11_signature.c +++ b/lib/pkcs11/pkcs11_signature.c @@ -351,4 +351,3 @@ CK_RV pkcs11_signature_verify_finish(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSi /** @} */ - diff --git a/lib/pkcs11/pkcs11_slot.c b/lib/pkcs11/pkcs11_slot.c index 61619b306..25eef4925 100644 --- a/lib/pkcs11/pkcs11_slot.c +++ b/lib/pkcs11/pkcs11_slot.c @@ -161,9 +161,7 @@ CK_RV pkcs11_slot_init(CK_SLOT_ID slotID) pkcs11_slot_ctx_ptr slot_ctx; ATCA_STATUS status = CKR_OK; int retries; -#if PKCS11_USE_STATIC_CONFIG - CK_RV rv; -#endif + if (!lib_ctx) { return CKR_CRYPTOKI_NOT_INITIALIZED; @@ -175,13 +173,14 @@ CK_RV pkcs11_slot_init(CK_SLOT_ID slotID) { return CKR_SLOT_ID_INVALID; } + #if PKCS11_USE_STATIC_CONFIG - rv = pkcs11_config_interface(slot_ctx); - if (rv != CKR_OK) + if (CKR_OK != pkcs11_config_interface(slot_ctx)) { return CKR_DEVICE_ERROR; } -#endif +#endif + if (!slot_ctx->initialized) { ATCAIfaceCfg * ifacecfg = &slot_ctx->interface_config; diff --git a/module.xml b/module.xml index 7c2183cdb..3326a34d0 100644 --- a/module.xml +++ b/module.xml @@ -1,4 +1,4 @@ - + diff --git a/python/MANIFEST.in b/python/MANIFEST.in index a23935c9f..2a18b782d 100644 --- a/python/MANIFEST.in +++ b/python/MANIFEST.in @@ -1,4 +1,5 @@ recursive-include lib *.c *.h atca_config.h.in CMakeLists.txt 90-cryptohid.rules recursive-include third_party *.c *.h recursive-include app *.c *.h +include cryptoauthlib/cryptoauth.json include MANIFEST.in setup.py setup.cfg README.md VERSION LICENSE.txt diff --git a/python/README.md b/python/README.md index 46b4775b7..e8673e7de 100644 --- a/python/README.md +++ b/python/README.md @@ -21,7 +21,7 @@ directory ``` pip install -U cryptoauthlib ``` - + ### If you ever need to remove your installation: ``` pip uninstall cryptoauthlib @@ -32,7 +32,7 @@ CryptoAuthLib module gives access to most functions available as part of standar (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: +Microchip cryptoauthlib product page: [Link]( http://www.microchip.com/SWLibraryWeb/product.aspx?product=CryptoAuthLib) ## Supported hardware @@ -82,7 +82,7 @@ void main() } } ``` - + The same code in python would be: ```python @@ -167,7 +167,7 @@ argument, attempt to return a list of valid attributes for that object. For exam 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 +Code examples for python are available on github as part of [CryptoAuthTools](https://github.com/MicrochipTech/cryptoauthtools/tree/master/python/examples) under the python/examples directory @@ -183,3 +183,413 @@ Release notes See [Release Notes](release_notes.md) +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + +Release notes +----------- +See [Release Notes](release_notes.md) + + diff --git a/python/cryptoauthlib/cryptoauth.json b/python/cryptoauthlib/cryptoauth.json new file mode 100644 index 000000000..b9b01d753 --- /dev/null +++ b/python/cryptoauthlib/cryptoauth.json @@ -0,0 +1,5765 @@ +{ + "atcab_get_device": { + "restype": "ctypes.c_void_p", + "argtypes": null, + "docstring": "Get the global device object. ", + "parameters": [] + }, + "atcab_get_device_type_ext": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "Get the selected device type of rthe device context. ", + "parameters": [ + [ + "device", + "Device context pointer " + ] + ] + }, + "atcab_get_device_type": { + "restype": "ctypes.c_uint8", + "argtypes": null, + "docstring": "Get the current device type configured for the global ATCADevice. ", + "parameters": [] + }, + "talib_wakeup": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": null, + "parameters": [] + }, + "talib_idle": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": null, + "parameters": [] + }, + "talib_sleep": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": null, + "parameters": [] + }, + "_talib_exit": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": null, + "parameters": [] + }, + "talib_get_zone_size": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.POINTER(ctypes.c_size_t)" + ], + "docstring": "Gets the size of the specified zone in bytes. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "zone", + "Zone to get size information from. Config(0), OTP(1), or Data(2) which requires a slot. " + ], + [ + "handle", + "If zone is Data(2), report the handle size " + ], + [ + "size", + "Zone size is returned here." + ] + ] + }, + "talib_cfg_discover": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ATCAIfaceCfg*", + "ctypes.c_int" + ], + "docstring": null, + "parameters": [] + }, + "talib_aes_keyload": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint8", + "ctypes.c_uint8", + "ctypes.c_uint16" + ], + "docstring": "TA API - Loads a Key into internal key memory for AES operation. This must be called before performing AES operations. ", + "parameters": [ + [ + "device", + "Device object that holds the device related informations " + ], + [ + "mode", + "Mode value for key load operation " + ], + [ + "iv_index", + "IV offset in the Key handle. Applicable only for TLS1.2 IV mode " + ], + [ + "key_index", + "Key Offset in the Key group / Handle " + ], + [ + "key_handle", + "Handle of the Symmetric key to be used" + ] + ] + }, + "talib_aes_ecb": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_char_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Perform an AES-128 ECB encrypt or decrypt operation with a key in the device. ", + "parameters": [ + [ + "device", + "Device object that holds the device related informations " + ], + [ + "mode", + "Mode value for AES operation, including encryption or decryption setting " + ], + [ + "aes_in", + "Input text to be encrypted or decrypted (16 bytes). " + ], + [ + "aes_out", + "Output plaintext or ciphertext is returned here (16 bytes)." + ] + ] + }, + "talib_aes_gcm": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Perform an AES-128 GCM encrypt or decrypt operation with a key in the device. ", + "parameters": [ + [ + "device", + "Device object that holds the device related informations " + ], + [ + "mode", + "Mode value for AES operation, including encryption or decryption setting " + ], + [ + "aad_length", + "Length of the auth_data to include in GCM operation " + ], + [ + "message_length", + "Length of the message to include in GCM operation " + ], + [ + "iv", + "Initialization vector. " + ], + [ + "aad", + "AAD data " + ], + [ + "message", + "Cipher text for decrypt or Plain text for encrypt " + ], + [ + "tag", + "Authentication tag to be used or returned " + ], + [ + "data_out", + "The output data plain text or decrypt text. " + ] + ] + }, + "talib_aes_encrypt": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint8", + "ctypes.c_char_p", + "ctypes.c_char_p" + ], + "docstring": "Perform an AES-128 encrypt operation with a key in the device. ", + "parameters": [ + [ + "device", + "Device object that holds the device related informations " + ], + [ + "key_id", + "Key handle containing the AES key. " + ], + [ + "key_block", + "Index within the key handle to be used as AES key. " + ], + [ + "plaintext", + "Input plaintext to be encrypted (16 bytes). " + ], + [ + "ciphertext", + "Output ciphertext is returned here (16 bytes)." + ] + ] + }, + "talib_aes_decrypt": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint8", + "ctypes.c_char_p", + "ctypes.c_char_p" + ], + "docstring": "Perform an AES-128 decrypt operation with a key in the device. ", + "parameters": [ + [ + "device", + "Device object that holds the device related informations " + ], + [ + "key_id", + "Key handle containing the AES key. " + ], + [ + "key_block", + "Index of the 16-byte block to use within the key location for the actual key. " + ], + [ + "ciphertext", + "Input ciphertext to be decrypted (16 bytes). " + ], + [ + "plaintext", + "Output plaintext is returned here (16 bytes)." + ] + ] + }, + "talib_aes_gcm_keyload": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint8" + ], + "docstring": "Performs loading of an AES-128 key to the engine in device. ", + "parameters": [ + [ + "device", + "Device object that holds the device related informations " + ], + [ + "key_id", + "Key handle containing the AES key. " + ], + [ + "key_block", + "Index of the byte block to use within the key location for the actual key." + ] + ] + }, + "talib_aes_gcm_keyload_with_implicit_iv": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint8", + "ctypes.c_uint8" + ], + "docstring": "Performs loading of an AES-128 key & 4 byte iv to the engine in device. ", + "parameters": [ + [ + "device", + "Device object that holds the device related informations " + ], + [ + "key_id", + "Key handle containing the AES key. " + ], + [ + "key_block", + "Index of the byte block to use within the key location for the actual key. " + ], + [ + "iv_index", + "Index to the 4 byte IV in the key_id handle for GCM operation." + ] + ] + }, + "talib_aes_gcm_encrypt": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Perform an AES-128 GCM encrypt operation with a key in the device and with given Additional authentication data, Initialization vector and the plain text. ", + "parameters": [ + [ + "device", + "Device object that holds the device related informations " + ], + [ + "aad", + "AAD data " + ], + [ + "aad_length", + "Length of the auth_data to include in GCM operation " + ], + [ + "iv", + "The 12 byte Initialization vector for GCP operation. " + ], + [ + "plaintext", + "Plain text to be encrypted " + ], + [ + "plaintext_length", + "Length of the plaintext to include in GCM operation " + ], + [ + "ciphertext", + "The output cipher text " + ], + [ + "tag", + "Authentication tag to be returned " + ] + ] + }, + "talib_aes_gcm_encrypt_with_rand_iv": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Perform an AES-128 GCM encrypt operation with a key in the device, with given Additional authentication data, plain text and random Initialization vector generated within device. ", + "parameters": [ + [ + "device", + "Device object that holds the device related informations " + ], + [ + "aad", + "AAD data " + ], + [ + "aad_length", + "Length of the auth_data to include in GCM operation " + ], + [ + "plaintext", + "Plain text to be encrypted " + ], + [ + "plaintext_length", + "Length of the plaintext to include in GCM operation " + ], + [ + "ciphertext", + "The output cipher text " + ], + [ + "tag", + "Authentication tag to be returned " + ], + [ + "iv", + "The 12 byte Initialization vector returned. " + ] + ] + }, + "talib_aes_gcm_decrypt": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "TA API - Perform an AES-128 GCM decrypt operation with a key in the device and with given Additional authentication data, Initialization vector, TAG and the cipher text. ", + "parameters": [ + [ + "device", + "Device object that holds the device related informations " + ], + [ + "aad", + "AAD data " + ], + [ + "aad_length", + "Length of the auth_data to include in GCM operation " + ], + [ + "iv", + "The 12 byte Initialization vector for GCP operation " + ], + [ + "tag", + "Authentication tag to be verified " + ], + [ + "ciphertext", + "Cipher text to be decrypted " + ], + [ + "ciphertext_length", + "Length of the ciphertext to include in GCM operation " + ], + [ + "plaintext", + "The output cipher text " + ] + ] + }, + "talib_auth_hmac_kdf": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char*16", + "ctypes.c_char*16" + ], + "docstring": "TA API - Calculate the session key for the authenticated session. ", + "parameters": [] + }, + "talib_auth_create_hmac": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p", + "ctypes.c_size_t", + "ctypes.c_char_p", + "ctypes.POINTER(ctypes.c_size_t)" + ], + "docstring": "TA API - Create an hmac for a packet in an authenticated session. ", + "parameters": [] + }, + "talib_auth_generate_nonce": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char*16" + ], + "docstring": "TA API - Exchange nonces between host and device. ", + "parameters": [] + }, + "talib_auth_startup": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_uint8", + "ctypes.c_char*32", + "ctypes.c_char*16", + "ctypes.c_char*16" + ], + "docstring": "TA API - Initiate an authorization session. ", + "parameters": [] + }, + "talib_auth_execute_nested": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_void_p", + "ctypes.c_uint16" + ], + "docstring": "TA API - Executes a nested command. ", + "parameters": [] + }, + "talib_auth_terminate": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "TA API - Terminate an authorization session. ", + "parameters": [] + }, + "talib_counter": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.POINTER(ctypes.c_uint32)" + ], + "docstring": "TA API - Compute the Counter functions. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "the mode used for the counter " + ], + [ + "counter_id", + "The counter to be used " + ], + [ + "counter_value", + "pointer to the counter value returned from device " + ] + ] + }, + "talib_counter_read": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.POINTER(ctypes.c_uint32)" + ], + "docstring": "Read one of the device's nonvolatile counter. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "counter_id", + "Counter to be read " + ], + [ + "counter_value", + "Counter value is returned here." + ] + ] + }, + "talib_counter_increment": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.POINTER(ctypes.c_uint32)" + ], + "docstring": "Increment one of the device's nonvolatile counter. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "counter_id", + "Counter to be increment " + ], + [ + "counter_value", + "Counter value is returned here." + ] + ] + }, + "talib_create": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.POINTER(ta_element_attributes_t)", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes Create command to create elements on shared data or volatile register. This cannot create Secure_boot special handles. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "mode parameter for the create operations " + ], + [ + "details", + "Additional details for HMAC and Ephemeral elements " + ], + [ + "handle_in", + "handle to use to create an element " + ], + [ + "handle_config", + "Attributes information for the element to be created. Size must be 8 bytes " + ], + [ + "handle_out", + "handle created by TA100 is returned here" + ] + ] + }, + "talib_create_element": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.POINTER(ta_element_attributes_t)", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes Create command to create elements on TA100 shared data memory. The handle is created by vega and handle value is copied into output buffer. This function wont create handle for ephemeral or HMAC symmetric key. This cannot create Secure_boot special handles. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "handle_cfg", + "Attributes information for the element to be created. Size must be 8 bytes " + ], + [ + "handle_out", + "handle created by TA100 is returned here" + ] + ] + }, + "talib_create_element_with_handle": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.POINTER(ta_element_attributes_t)" + ], + "docstring": "TA API - Executes Create command to create elements on TA100 shared data memory or volatile register. This cannot create Secure_boot special handles. This function wont create handle for ephemeral or HMAC symmetric key. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "handle_in", + "handle to use to create an element " + ], + [ + "handle_config", + "Attributes information for the element to be created. Size must be 8 bytes" + ] + ] + }, + "talib_create_ephemeral_element_with_handle": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.POINTER(ta_element_attributes_t)" + ], + "docstring": "TA API - Executes Create command to create Ephemeral element on volatile register This cannot create Secure_boot special handles. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "details", + "Additional details for HMAC and Ephemeral elements " + ], + [ + "handle_in", + "handle to use to create an element " + ], + [ + "handle_config", + "Attributes information for the element to be created. Size must be 8 bytes" + ] + ] + }, + "talib_create_hmac_element": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_size_t", + "ctypes.POINTER(ta_element_attributes_t)", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes Create command to create HMAC symmetric elements on shared data. The handle is created by vega and handle value is copied into output buffer. This cannot create Secure_boot special handles. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "hmac_key_size", + "size of hmac symmetric key size " + ], + [ + "handle_config", + "Attributes information for the element to be created. Size must be 8 bytes " + ], + [ + "handle_out", + "handle created by vega" + ] + ] + }, + "talib_create_hmac_element_with_handle": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_size_t", + "ctypes.c_uint16", + "ctypes.POINTER(ta_element_attributes_t)" + ], + "docstring": "TA API - Executes Create command to create HMAC symmetric elements on shared data memory or volatile register. This cannot create Secure_boot special handles. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "hmac_key_size", + "size of hmac symmetric key size " + ], + [ + "handle_in", + "handle to use to create an element " + ], + [ + "handle_config", + "Attributes information for the element to be created. Size must be 8 bytes" + ] + ] + }, + "talib_create_linked_shared_data": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.POINTER(ta_element_attributes_t)", + "ctypes.c_uint16_p" + ], + "docstring": "TA-API Execute the create command to create handle by TA100 in linked shared data. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "details", + "Additional details for HMAC and Ephemeral elements " + ], + [ + "handle_config", + "Attributes information for the element to be created. Size must be 8 bytes " + ], + [ + "handle_out", + "handle created by TA100 is returned here" + ] + ] + }, + "talib_delete_base": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint32" + ], + "docstring": "TA API - Executes delete command to delete elements on TA100. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "mode for delete entire chip or handle " + ], + [ + "handle", + "Element handle to delete. Should point to shared or volatile register" + ] + ] + }, + "talib_delete_handle": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint32" + ], + "docstring": "TA API - Executes delete command to delete handle on shared data or volatile register. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "handle", + "Element handle to delete. Should point to shared or volatile register" + ] + ] + }, + "talib_chip_erase": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "TA API - Executes delete command to delete/erase entire chip. ", + "parameters": [ + [ + "device", + "Device context pointer " + ] + ] + }, + "talib_devupdate_base": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_char_p", + "ctypes.c_uint16" + ], + "docstring": "TA API - Executes devupdate command to Update one block of the nonvolatile operating code within the Vega device. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "mode", + "Block ID. 0x00 through 0xFE legal " + ], + [ + "data", + "data to Update image block " + ], + [ + "data_length", + "length of update image block in bytes (maximum size is 1024)" + ] + ] + }, + "talib_devupdate_init_ctx": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_int16" + ], + "docstring": "TA API - Initialize the Devupdate context stucture. ", + "parameters": [ + [ + "ctx", + "devupdate context pointer " + ], + [ + "first_block_size", + "size of first block " + ], + [ + "second_block_szie", + "size of remaining block" + ] + ] + }, + "talib_devupdate_first_block": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_void_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes devupdate command to Update the first block (image) of the nonvolatile operating code within the Vega device. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "ctx", + "As input, devupdate context pointer As output, Update the block id after successful first block update " + ], + [ + "first_block", + "first block of the image" + ] + ] + }, + "talib_devupdate_subsequent_block": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_void_p", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes devupdate command to Update the subsequent block (image) of the nonvolatile operating code within the Vega device. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "ctx", + "As input, devupdate context pointer As output, Update the block id and remaining size " + ], + [ + "block", + "block of the image to be updated in the device " + ], + [ + "block_len", + "As input, length of the block As output, updated block length" + ] + ] + }, + "talib_devupdate_image": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes devupdate command to Update the complete image of the nonvolatile operating code within the Vega device. ", + "parameters": [ + [ + "image", + "Update image of the non volatile operating code" + ] + ] + }, + "talib_ecdh_base": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_size_t", + "ctypes.c_char_p" + ], + "docstring": "TA API - Base function for generating premaster secret key using ECDH. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "Mode to be used for ECDH computation " + ], + [ + "priv_handle", + "Private key handle for ECDH computation, can be Volatile or Shared memory " + ], + [ + "target_handle", + "Handle for ECDH computation result, can be IO, Volatile or Shared memory " + ], + [ + "public_key", + "Public key input to ECDH calculation. X and Y integers in big-endian format. 64 bytes for P256 key , 56 bytes for P224 key and 96 bytes for P384 " + ], + [ + "public_key_size", + "Length of the Public key parameter " + ], + [ + "pms", + "Computed ECDH pre-master secret is returned here (28 or 32 or 48 bytes) if returned directly. Otherwise NULL." + ] + ] + }, + "talib_ecdh_compat": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char*64", + "ctypes.c_char_p" + ], + "docstring": "TA API - Generate pre master secret using ECDH and secret key copied into output buffer. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "priv_handle", + "Private key handle for ECDH computation, can be Volatile or Shared memory " + ], + [ + "public_key", + "Public key input to ECDH calculation. X and Y integers in big-endian format. 64 bytes for P256 key and 56 bytes for P224 key " + ], + [ + "pms", + "Computed ECDH pre-master secret is returned here (28 or 32 bytes) if returned directly. Otherwise NULL. " + ] + ] + }, + "talib_ecdh_io_buffer": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_size_t", + "ctypes.c_char_p" + ], + "docstring": "TA API - Generate pre master secret using ECDH and secret key copied into output buffer (premaster secret key size is equal to the public key size divide by 2) ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "priv_handle", + "Private key handle for ECDH computation, can be Volatile or Shared memory " + ], + [ + "public_key", + "Public key input to ECDH calculation. " + ], + [ + "pubkey_len", + "Length of the Public key parameter " + ], + [ + "pms", + "Computed ECDH pre-master secret is returned here (public key size/2) if returned directly. Otherwise NULL. " + ] + ] + }, + "talib_ecdh_xy_in_io_buffer": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_size_t", + "ctypes.c_char_p" + ], + "docstring": "TA API - Generate pre master secret using ECDH and secret key copied into output buffer (premaster secret key size is same as the public key size) ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "priv_handle", + "Private key handle for ECDH computation, can be Volatile or Shared memory " + ], + [ + "public_key", + "Public key input to ECDH calculation. " + ], + [ + "pubkey_len", + "Length of the Public key parameter " + ], + [ + "pms", + "Computed ECDH pre-master secret is returned here (public key size) if returned directly. Otherwise NULL. " + ] + ] + }, + "talib_ecdh_to_handle": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_size_t" + ], + "docstring": "TA API - Generating premaster secret key using ECDH and stores in shared data or volatile register (premaster secret key size is equal to the public key size divided by 2) ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "priv_handle", + "Private key handle for ECDH computation, can be Volatile or Shared memory " + ], + [ + "target_handle", + "Handle for ECDH computation result can go to Volatile or Shared memory " + ], + [ + "public_key", + "Public key input to ECDH calculation. X and Y integers in big-endian format. 64 bytes for P256 key and 56 bytes for P224 key " + ], + [ + "pubkey_len", + "Length of the Public key parameter " + ] + ] + }, + "talib_ecdh_xy_to_handle": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_size_t" + ], + "docstring": "TA API - Generating premaster secret key using ECDH and stores in shared data or volatile register.(premaster secret key size is same as the public key size) ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "priv_handle", + "Private key handle for ECDH computation, can be Volatile or Shared memory " + ], + [ + "target_handle", + "Handle for ECDH computation result can go to Volatile or Shared memory " + ], + [ + "public_key", + "Public key input to ECDH calculation. X and Y integers in big-endian format. 64 bytes for P256 key and 56 bytes for P224 key " + ], + [ + "pubkey_len", + "Length of the Public key parameter " + ] + ] + }, + "talib_export": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes the Export command, which exports the contents of a key/data element in the shared data memory. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "The key_handle that contains key/data to be exported. " + ], + [ + "export_data", + "The buffer to the store the exported data. " + ], + [ + "export_data_length", + "As input, the size of the export_data buffer and as output the size of the exported data." + ] + ] + }, + "talib_fcconfig_base": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint32", + "ctypes.POINTER(ctypes.c_uint32)" + ], + "docstring": "TA API - Execute the FC config command to Configure the Fast Crypto engine for the desired algorithm and select the key group. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "mode", + "Mode Algorithm Encoding " + ], + [ + "handle", + "handle of the group of symmetric keys for use " + ], + [ + "written_map", + "map of those keys that were successfully written to the FCE" + ] + ] + }, + "talib_import_base": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint32", + "ctypes.c_char_p", + "ctypes.c_uint16" + ], + "docstring": "TA API - Executes Import command to import the encrypted key/data blob into the handle. The target handle should be created prior to this command and the value of its attribute fields must match exactly that which is contained in the exported blob with the exception of the link fields. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "either link keys are as per target handle or exported blob handle " + ], + [ + "handle", + "Element handle where to import the data blob " + ], + [ + "blob", + "Encrypted key/data blob " + ], + [ + "blob_length", + "Length of encrypted key/data blob" + ] + ] + }, + "talib_import_handle": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16" + ], + "docstring": "TA API - Executes Import command to import the encrypted key/data blob into the handle. The target handle should be created prior to this command and the value of its attribute fields must match exactly that which is contained in the exported blob. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "handle", + "Element handle where to import the data blob " + ], + [ + "blob", + "Encrypted key/data blob " + ], + [ + "blob_length", + "Length of encrypted key/data blob" + ] + ] + }, + "talib_import_handle_with_target_links": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16" + ], + "docstring": "TA API - Executes Import command to import the encrypted key/data blob into the handle. The target handle should be created prior to this command and the value of its attribute fields must match exactly that which is contained in the exported blob with the exception of the link fields. Link keys are as per target handle (where blob going to import) ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "handle", + "Element handle where to import the data blob " + ], + [ + "blob", + "Encrypted key/data blob " + ], + [ + "blob_length", + "Length of encrypted key/data blob" + ] + ] + }, + "talib_info_base": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint32", + "ctypes.c_char_p", + "ctypes.POINTER(ctypes.c_size_t)" + ], + "docstring": "TA API - Issues an Info command, which return internal device information. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "Selects which mode to be used for info command. " + ], + [ + "param2", + "Handle for mode 2 & 3. " + ], + [ + "out_data", + "Response from info command " + ], + [ + "data_size", + "out_data buffer size as input and valid data length as output" + ] + ] + }, + "talib_info": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char*8" + ], + "docstring": "TA API - Issues an Info command to return revision of the internal hardware, configuration or firmware of the device. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "revision", + "device revision number returned here" + ] + ] + }, + "talib_info_compat": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char*4" + ], + "docstring": "TA API - Issues an Info command to return revision of the internal hardware (compatible with cryptoauthlib info command) ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "revision", + "device revision number returned here" + ] + ] + }, + "talib_info_serial_number": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char*8" + ], + "docstring": "The function returns 8 byte serial number of the device. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "serial_number", + "8 byte serial number is returned here." + ] + ] + }, + "talib_info_serial_number_compat": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char*9" + ], + "docstring": "The function return 8 byte serial number of the device in 9 byte buffer (compatibility mode - cryptoauth devices have a 9 byte serial number) ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "serial_number", + "8 byte serial number is returned here." + ] + ] + }, + "talib_info_get_nv_remain": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.POINTER(ctypes.c_uint32)" + ], + "docstring": "TA API - Issues an Info command to return remaining bytes in Non Volatile memory. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "nv_remain", + "remaining non volatile memory in the device is returned here" + ] + ] + }, + "talib_is_handle_valid": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint32", + "ctypes.c_char_p" + ], + "docstring": "TA API - Issues an Info command to return handle validity. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "target_handle", + "Target handle to read info " + ], + [ + "is_valid", + "True if handle is created, irrespective of written or used status" + ] + ] + }, + "talib_info_get_handle_info": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint32", + "ctypes.c_char*(9)" + ], + "docstring": "TA API - Issues an Info command to return attributes & status of a handle. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "target_handle", + "Target handle to read handle info " + ], + [ + "handle_info", + "Handle info (handle attributes) returned here" + ] + ] + }, + "talib_info_get_handles_array": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16_p", + "ctypes.POINTER(ctypes.c_size_t)" + ], + "docstring": "TA API - Issues an Info command to return handles list. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "handle_array", + "List of handles received as response.. " + ], + [ + "array_size", + "As input, handle_array buffer size As output, number of elements in handle_array" + ] + ] + }, + "talib_info_get_handle_size": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint32", + "ctypes.POINTER(ctypes.c_size_t)" + ], + "docstring": "TA API - Get the data stored in a handle. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "target_handle", + "Target handle to read info " + ], + [ + "out_size", + "data handle size is returned here" + ] + ] + }, + "talib_is_auth_session_valid": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_char_p" + ], + "docstring": "TA API - Issues an Info command to get auth session validity. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "auth_session_id", + "Target Auth session id to check validity, 0-1 are only valid " + ], + [ + "is_valid", + "Auth session validity. True if session is valid for use" + ] + ] + }, + "talib_is_volatile_register_valid": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_char_p" + ], + "docstring": "TA API - Issues an Info command to get volatile register status. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "volatile_register_id", + "Target Volatile register id to check validity, 0-3 are only valid " + ], + [ + "is_valid", + "True if handle is created, irrespective of written or used status" + ] + ] + }, + "talib_info_get_dedicated_memory": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Issues an Info command to return dedicated memory contents. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "dedicated_memory", + "dedicated memory content of 16 byte is return here" + ] + ] + }, + "talib_info_get_chip_status": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char*(6)" + ], + "docstring": "TA API - Issues an Info command to return chip status. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "chip_status", + "chip status (config lock status, setup lock status, latch status) returned here" + ] + ] + }, + "talib_is_config_locked": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.POINTER(ctypes.c_bool)" + ], + "docstring": "TA API - Issues an Info command to get config lock status. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "is_locked", + "True if config is locked or else false" + ] + ] + }, + "talib_is_setup_locked": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.POINTER(ctypes.c_bool)" + ], + "docstring": "TA API - Issues an Info command to get setup lock status. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "is_locked", + "True if setup is locked or else false" + ] + ] + }, + "talib_is_locked_compat": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.POINTER(ctypes.c_bool)" + ], + "docstring": "Executes Read command, which reads the configuration zone to see if the specified zone is locked. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "zone", + "The zone to query for locked (use LOCK_ZONE_CONFIG or LOCK_ZONE_SETUP). " + ], + [ + "is_locked", + "Lock state returned here. True if locked. " + ] + ] + }, + "talib_info_get_vcc_latch": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Issues an Info command to get Vcc latch state. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "latch_value", + "return current state of the vcc latches" + ] + ] + }, + "talib_info_get_failure_log": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Issues an Info command to get Failure logs. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "failure_log", + "previous self test failure log is returned here (64 byte)" + ] + ] + }, + "talib_info_get_rom_id": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Issues an Info command to get ROM ID. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "rom_id", + "Device rom version id is returned here" + ] + ] + }, + "talib_info_get_crl_handle": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Issues an Info command to get CRL handle. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "crl_handle", + "valid crl handle is returned here" + ] + ] + }, + "talib_is_handle_locked": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.POINTER(ctypes.c_bool)" + ], + "docstring": "Executes info command, which reads the handle info to see if the specified handle element is locked. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "handle", + "Handle to query for locked " + ], + [ + "is_locked", + "Lock state returned here. True if locked." + ] + ] + }, + "talib_kdf_aesA": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes AES OptionA operations using KDF command. Output_Handle = AESencrypt(key, Message[16:31]) ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "msg_handle", + "handle refers to the message which present in device " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "output_handle", + "kdf output will be stored in this handle " + ], + [ + "message", + "Message to send on IO if indicated by message_handle if present, should be 32 bytes " + ], + [ + "kdf_out", + "Output of the KDF AES-A function is retuned here." + ] + ] + }, + "talib_kdf_aesA_io": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes AES OptionA operations using KDF command, result is on IO buffer. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "msg_handle", + "Input handle for the message " + ], + [ + "message", + "Message to send on IO if indicated by message_handle if present, should be 32 bytes " + ], + [ + "kdf_output", + "Output of the KDF - AESA function is retuned here." + ] + ] + }, + "talib_kdf_aesA_stored": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16" + ], + "docstring": "TA API - Executes AES OptionA operations using KDF command, result is stored inside device either in shared data memory or volatile register. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "message_handle", + "handle refers to the message which present in device " + ], + [ + "message", + "Message to send on IO if indicated by message_handle if present, should be 32 bytes " + ], + [ + "output_handle", + "Stores the KDF output result in this handle" + ] + ] + }, + "talib_kdf_aesB": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes AES OptionB operations using KDF command. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "msg_handle", + "handle refers to the message (which present in device) " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "output_handle", + "Holds the KDF output result " + ], + [ + "input_data", + "Application data to include in computation, should be 16 bytes " + ], + [ + "kdf_out", + "Output of the HKDF function is retuned here." + ] + ] + }, + "talib_kdf_aesB_io": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes AES OptionB operations using KDF command, result is on IO buffer. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "message_handle", + "Input handle for the message " + ], + [ + "input_data", + "Message to send on IO if indicated by message_handle if present, should be 16 bytes " + ], + [ + "kdf_output", + "Output of the KDF - AESA function is retuned here." + ] + ] + }, + "talib_kdf_aesB_stored": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes AES OptionB operations using KDF command, result is stored inside device in either shared data memory or volatile register. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "output_handle", + "Holds the KDF output result " + ], + [ + "message_handle", + "handle refers to the message (which present in device) " + ], + [ + "input_data", + "Application data to include in computation, should be 16 bytes" + ] + ] + }, + "talib_hkdf": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes HKDF operation using KDF command. Extract_key = HMAC(Salt, Key_Handle) Out_Handle[0-31] = HMAC(Key_ Extract_key, Info | 1) Out_Handle[32-63] = HMAC(Key_ Extract_key, Out_Handle[0-31] | Info | 2) Out_Handle[64-95] = HMAC(Key_ Extract_key, Out_Handle[32-63] | Info | 3) Out_Handle[96-127] = HMAC(Key_ Extract_key, Out_Handle[64-95] | Info | 4) ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "output_handle", + "Holds the KDF output result " + ], + [ + "salt_len", + "Input Salt size " + ], + [ + "info_len", + "Input Info size " + ], + [ + "salt", + "Input Salt for HKDF-Extract phase " + ], + [ + "info", + "Application specific info for HKDF-Exapnd phase " + ], + [ + "kdf_out", + "Output of the HKDF function is retuned here. " + ], + [ + "kdf_length", + "As input, expected Key Material size As output, length of the Key Material in kdf_output" + ] + ] + }, + "talib_hkdf_io": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes HKDF operation using KDF command, result in IO buffer. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "salt", + "Input Salt for HKDF-Extract phase " + ], + [ + "salt_len", + "Input Salt size " + ], + [ + "info", + "Application specific info for HKDF-Exapnd phase " + ], + [ + "info_len", + "Input Info size " + ], + [ + "kdf_output", + "Output of the HKDF function is retuned here. " + ], + [ + "kdf_length", + "As input, expected Key Material size As output, length of the Key Material in kdf_output" + ] + ] + }, + "talib_hkdf_stored": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_size_t", + "ctypes.c_char_p", + "ctypes.c_size_t", + "ctypes.c_uint16", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes HKDF operation using KDF command, result is stored inside device either in shared data memory or volatile register. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "salt", + "Input Salt for HKDF-Extract phase " + ], + [ + "salt_len", + "Input Salt size " + ], + [ + "info", + "Application specific info for HKDF-Exapnd phase " + ], + [ + "info_len", + "Input Info size " + ], + [ + "target_handle", + "Holds the KDF output result " + ], + [ + "kdf_length", + "As input, expected Key Material size As output, length of the Key Material in kdf_output" + ] + ] + }, + "talib_kdf_prf": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes PRF operation using KDF command. A1 = HMAC(Key_Handle, Input_Data) Out_Handle[0-31] = HMAC(Key_Handle, A1 | Input_Data) A2 = HMAC(Key_Handle, A1) Out_Handle[32-63] = HMAC(Key_Handle, A2 | Input_Data) A3 = HMAC(Key_Handle, A2) Out_Handle[64-95] = HMAC(Key_Handle, A3 | Input_Data) A4 = HMAC(Key_Handle, A3) Out_Handle[96-127] = HMAC(Key_Handle, A4 | Input_Data) ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "output_handle", + "Holds the KDF output result " + ], + [ + "input_len", + "Input \"input\" size " + ], + [ + "input_data", + "concatenated value of label and seed " + ], + [ + "kdf_out", + "Output of the HKDF function is retuned here. " + ], + [ + "kdf_length", + "As input, expected Key Material size As output, length of the Key Material in kdf_output" + ] + ] + }, + "talib_kdf_prf_io": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint8", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes PRF operation using KDF command, result in IO buffer. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "src_key_length", + "Source Key length in bytes. 16, 32, 48 and 64 are only valid " + ], + [ + "input", + "concatenated value of label and seed " + ], + [ + "input_len", + "Input \"input\" size " + ], + [ + "kdf_output", + "Output of the HKDF function is retuned here. " + ], + [ + "kdf_length", + "As input, expected Key Material size As output, length of the Key Material in kdf_output" + ] + ] + }, + "talib_kdf_prf_stored": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint8", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes PRF operation using KDF command, result is stored inside device either in shared data memory or volatile register. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "src_key_length", + "Source Key length in bytes. 16, 32, 48 and 64 are only valid " + ], + [ + "input", + "concatenated value of label and seed " + ], + [ + "input_len", + "Input \"input\" size " + ], + [ + "target_handle", + "Holds the KDF output result " + ], + [ + "kdf_length", + "As input, expected Key Material size As output, length of the Key Material in kdf_output" + ] + ] + }, + "talib_kdf_hmac_counter": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes HMAC-Counter operation using KDF command. Bytes 0-31: HMAC(key_handle, 1 | Label | 0 | Context | Length) Bytes 32-63: HMAC(key_handle, 2 | Label | 0 | Context | Length) Bytes 64-95: HMAC(key_handle, 3 | Label | 0 | Context | Length) Bytes 95-127: HMAC(key_handle, 4 | Label | 0 | Context | Length) ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "output_handle", + "Holds the KDF output result " + ], + [ + "label_len", + "Input label size " + ], + [ + "context_len", + "Input context size " + ], + [ + "label", + "Input label string provided by host " + ], + [ + "context", + "Input context provided by host " + ], + [ + "kdf_out", + "Output of the HKDF function is retuned here. " + ], + [ + "kdf_length", + "As input, expected Key Material size As output, length of the Key Material in kdf_output" + ] + ] + }, + "talib_kdf_hmac_counter_io": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes HMAC-Counter operation using KDF command, result is in IO buffer. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "label", + "Input label string provided by host " + ], + [ + "label_len", + "Input label size " + ], + [ + "context", + "Input context provided by host " + ], + [ + "context_len", + "Input context size " + ], + [ + "kdf_output", + "Output of the HKDF function is retuned here. " + ], + [ + "kdf_length", + "As input, expected Key Material size As output, length of the Key Material in kdf_output" + ] + ] + }, + "talib_kdf_hmac_counter_stored": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes HMAC-Counter operation using KDF command, result is stored inside device either in shared data memory or volatile register. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "label", + "Input label string provided by host " + ], + [ + "label_len", + "Input label size " + ], + [ + "context", + "Input context provided by host " + ], + [ + "context_len", + "Input context size " + ], + [ + "target_handle", + "Holds the KDF output result " + ], + [ + "kdf_length", + "As input, expected Key Material size As output, length of the Key Material in kdf_output" + ] + ] + }, + "talib_kdf_sha256": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes SHA256 operation using KDF command. Bytes 0-31: SHA256(Pre_pad | key_handle | Post_pad) ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "output_handle", + "Holds the KDF output result " + ], + [ + "pre_pad", + "Host data to prepad IKM " + ], + [ + "pre_len", + "Input pre-pad size " + ], + [ + "post_pad", + "Host data to prepad IKM " + ], + [ + "post_len", + "Input post-pad size " + ], + [ + "kdf_out", + "Output of the HKDF function is retuned here. " + ], + [ + "kdf_length", + "As input, expected Key Material size As output, length of the Key Material in kdf_output" + ] + ] + }, + "talib_kdf_sha256_io": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes SHA256 operation using KDF command, result in IO buffer. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "pre_pad", + "Host data to prepad IKM " + ], + [ + "pre_pad_len", + "Input pre-pad size " + ], + [ + "post_pad", + "Host data to prepad IKM " + ], + [ + "post_pad_len", + "Input post-pad size " + ], + [ + "kdf_output", + "Output of the HKDF function is retuned here. " + ], + [ + "kdf_length", + "As input, expected Key Material size As output, length of the Key Material in kdf_output" + ] + ] + }, + "talib_kdf_sha256_stored": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes SHA256 operation using KDF command, result is stored inside device either in shared data memory or volatile register. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Contains Input Key Material " + ], + [ + "pre_pad", + "Host data to prepad IKM " + ], + [ + "pre_pad_len", + "Input pre-pad size " + ], + [ + "post_pad", + "Host data to prepad IKM " + ], + [ + "post_pad_len", + "Input post-pad size " + ], + [ + "target_handle", + "Holds the KDF output result " + ], + [ + "kdf_length", + "As input, expected Key Material size As output, length of the Key Material in kdf_output" + ] + ] + }, + "talib_genkey_base": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint32", + "ctypes.c_char_p", + "ctypes.POINTER(ctypes.c_size_t)" + ], + "docstring": "TA API - Issues GenKey command, which generates a new random key in handle and returns the public key if applicable. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "Mode determines what operations the GenKey command performs " + ], + [ + "key_handle", + "Handle for a Symmetric or private key " + ], + [ + "public_key", + "Public key will be returned here. Format will be the X and Y integers in big-endian format. Length depends on the Key attributes. Set to NULL if public key isn't required. " + ], + [ + "pubkey_len", + "As input, expected public key length As output, public key length received from device." + ] + ] + }, + "talib_genkey": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.POINTER(ctypes.c_size_t)" + ], + "docstring": "TA API - Issues GenKey command, which generates a new random key in handle and returns the public key if applicable. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Handle for a Symmetric or private key " + ], + [ + "public_key", + "Public key will be returned here. Format will be the X and Y integers in big-endian format. Length depends on the Key attributes. Set to NULL if public key isn't required. " + ], + [ + "pubkey_len", + "As input, expected public key length As output, public key length received from device." + ] + ] + }, + "talib_genkey_compat": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char*64" + ], + "docstring": "Issue Keygen command, which generates a new random ECCP256 private key in handle and returns the public key. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Handle of a private key. " + ], + [ + "public_key", + "Public key will be returned here. Format will be the X and Y integers in big-endian format. 64 bytes for P256 curve. Set to NULL if public key isn't required." + ] + ] + }, + "talib_get_pubkey_compat": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char*64" + ], + "docstring": "Uses GenKey command to calculate the public key from an existing ECCP256 private key in a handle. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Handle of a private key. " + ], + [ + "public_key", + "Public key will be returned here. Format will be the X and Y integers in big-endian format. 64 bytes for P256 curve. Set to NULL if public key isn't required." + ] + ] + }, + "talib_get_pubkey": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.POINTER(ctypes.c_size_t)" + ], + "docstring": "Uses GenKey command to calculate the public key from an existing private key in a handle. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Handle of a private key. " + ], + [ + "public_key", + "Public key will be returned here. " + ], + [ + "pubkey_len", + "As input, expected public key length As output, public key length received from device." + ] + ] + }, + "talib_genkey_symmetric_key": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16" + ], + "docstring": "Uses GenKey command to calculate the symmetric key and load into given handle. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "generated symmetric key write into handle." + ] + ] + }, + "talib_lock": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint32" + ], + "docstring": "TA API - Executes Lock command to prevent further updates to Configuration or Setup or shared data or one time based on the mode. Once locked, these can't be unlocked. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "Parameter to select the memory type and options to lock " + ], + [ + "param2", + "CRC if locking Config, Handle if locking a shared element" + ] + ] + }, + "talib_lock_config": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "Lock the config zone without CRC. ", + "parameters": [ + [ + "device", + "Device context pointer " + ] + ] + }, + "talib_lock_config_with_crc": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16" + ], + "docstring": "Lock the config zone with summary CRC. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "summary_crc", + "Expected CRC over the config zone." + ] + ] + }, + "talib_lock_handle": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16" + ], + "docstring": "Lock an individual handle in the data zone on an ATECC device. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "handle", + "handle to be locked in nv shared data zone." + ] + ] + }, + "talib_lock_setup": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "Locks Setup memory. ", + "parameters": [ + [ + "device", + "Device context pointer " + ] + ] + }, + "talib_lock_onetime_latch": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "Locks one time latch. Applicable only when enabled in Chip Options. ", + "parameters": [ + [ + "device", + "Device context pointer " + ] + ] + }, + "talib_mac_base": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes MAC command for CMAC and HMAC calculations. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Handle of the Symmetric key to be used either present in Shared data or Volatile register " + ], + [ + "key_index", + "Key index in the Key grup if handle points to a group " + ], + [ + "message", + "Challenge message of max size 1022 bytes " + ], + [ + "msg_length", + "Carries the message length " + ], + [ + "digest", + "CMAC or HMAC response is returned here (16 or 32 bytes) " + ], + [ + "mac_length", + "As input, digest buffer size As output, mac size in digest buffer" + ] + ] + }, + "talib_cmac": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "Executes MAC command for CMAC calculations. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Handle of the Symmetric key to be used either present in Shared data or Volatile register " + ], + [ + "key_index", + "Key index in the Key grup if handle points to a group " + ], + [ + "message", + "Challenge message of max size 1022 bytes " + ], + [ + "length", + "carries the message length " + ], + [ + "cmac", + "CMAC response is returned here (16 bytes)" + ] + ] + }, + "talib_hmac": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "Executes MAC command for HMAC calculations. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Handle of the Symmetric key to be used either present in Shared data or Volatile register " + ], + [ + "key_index", + "Key index in the Key grup if handle points to a group " + ], + [ + "message", + "Challenge message of max size 1022 bytes " + ], + [ + "length", + "carries the message length " + ], + [ + "hmac", + "HMAC response is returned here (32 bytes)" + ] + ] + }, + "talib_hmac_compat": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p", + "ctypes.c_size_t", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint8" + ], + "docstring": "Executes MAC command for HMAC calculation (compatible with sha-hmac command) ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "data", + "Challenge message of max size 1022 bytes " + ], + [ + "data_size", + "carries the message length " + ], + [ + "key_slot", + "Handle of the Symmetric key to be used either present in Shared data or Volatile register " + ], + [ + "digest", + "HMAC response is returned here (32 bytes) " + ], + [ + "target", + "Where to save the digest internal to the device." + ] + ] + }, + "talib_manage_cert": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16" + ], + "docstring": "TA API - Executes ManageCert command to parse and verify x.509 certs or manage an input certificate revocation list. ", + "parameters": [ + [ + "device", + "Device object that holds the device related informations " + ], + [ + "mode", + "mode parameter for ManageCert command " + ], + [ + "parent_handle", + "Verifying certificate handle. This can be in Shared or Volatile " + ], + [ + "target_handle", + "Handle to write verified certificate or CRL element. After successful verification, extracted element is written to this handle. A value of 0xFFFF, skips write to handle but returns verification status " + ], + [ + "source_handle", + "Handle pointing to Full certificate or CRL. Only supports IO buffer or shared memory, but not Volatile register. CRL must point to IO buffer. " + ], + [ + "in_cert", + "Incoming certificate or CRL when source handle pointing to IO buffer. Maximum size is 1020. Should be NULL if source_handle points to internal memory " + ], + [ + "length", + "Length of the incoming certificate or CRL. Applicable only when in_cert exists on the IO buffer" + ] + ] + }, + "talib_store_extracted_cert_io": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16" + ], + "docstring": "TA API - Executes ManageCert command to verify x.509 incoming cert and store extracted certificate to shared element. ", + "parameters": [ + [ + "device", + "Device object that holds the device related informations " + ], + [ + "parent_handle", + "Verifying certificate handle. This can be in Shared or Volatile " + ], + [ + "target_handle", + "Handle to write verified certificate. After successful verification, extracted elements are written to this handle. " + ], + [ + "in_cert", + "Incoming certificate to verify and extract " + ], + [ + "cert_length", + "Length of the incoming certificate" + ] + ] + }, + "talib_store_extracted_cert": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16" + ], + "docstring": "TA API - Executes ManageCert command to verify x.509 stored cert and store extracted certificate to shared element. ", + "parameters": [ + [ + "device", + "Device object that holds the device related informations " + ], + [ + "parent_handle", + "Verifying certificate handle. This can be in Shared or Volatile " + ], + [ + "target_handle", + "Handle to write verified certificate. After successful verification, extracted elements are written to this handle. " + ], + [ + "source_handle", + "Handle pointing to Full certificate only supports shared memory" + ] + ] + }, + "talib_verify_cert_io": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16" + ], + "docstring": "TA API - Executes ManageCert command to verify x.509 incoming cert and returns verification status. ", + "parameters": [ + [ + "device", + "Device object that holds the device related informations " + ], + [ + "parent_handle", + "Verifying certificate handle. This can be in Shared or Volatile " + ], + [ + "in_cert", + "Incoming certificate to verify and extract " + ], + [ + "cert_length", + "Length of the incoming certificate" + ] + ] + }, + "talib_verify_cert": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16" + ], + "docstring": "TA API - Executes ManageCert command to verify x.509 stored cert and returns verification status. ", + "parameters": [ + [ + "device", + "Device object that holds the device related informations " + ], + [ + "parent_handle", + "Verifying certificate handle. This can be in Shared or Volatile " + ], + [ + "source_handle", + "Handle pointing to Full certificate only supports shared memory" + ] + ] + }, + "talib_power": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8" + ], + "docstring": "TA API - Executes MAC command for CMAC and HMAC calculations. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "Mode parameter to control the power state of the device" + ] + ] + }, + "talib_power_reboot": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "TA API - Executes Power command to reboot the TA100. ", + "parameters": [ + [ + "device", + "Device context pointer " + ] + ] + }, + "talib_power_sleep": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "TA API - Executes Power command to sleep the TA100. ", + "parameters": [ + [ + "device", + "Device context pointer " + ] + ] + }, + "talib_random": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char*16", + "ctypes.c_char_p", + "ctypes.c_uint32" + ], + "docstring": "TA API - Executes Random command and returns requested number of random bytes. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "stir_data", + "Extra data to be stirred into the random number calculation. Should be 16 bytes " + ], + [ + "rand_out", + "Requested number of random bytes are returned here " + ], + [ + "rand_length", + "Contains number of random bytes to read" + ] + ] + }, + "talib_random_compat": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char*32" + ], + "docstring": "Compatibility mode which generates a 32 byte random number from the TA100 device. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "rand_out", + "32 bytes of random data is returned here." + ] + ] + }, + "talib_read": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16_p", + "ctypes.c_char_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes Read command to read an element from shared data memory. This supports both partial and completed writes Restrictions apply based on attributes of the element Volatile registers can never be read. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "mode parameter for the read operations " + ], + [ + "transfer_handle", + "Remote device write handle in case of transfer operation " + ], + [ + "key_handle", + "Target handle to initiate read operation " + ], + [ + "offset", + "Offset to the first byte to be read... Applicable only to Shared data memory only Valid only for partial reads " + ], + [ + "length", + "As Input, number of bytes to read. Cannot exceed element size Valid only for partial reads As Output, number bytes read is returned here " + ], + [ + "data_read", + "Actual data read is returned here " + ], + [ + "mac", + "MAC for the transfer function." + ] + ] + }, + "talib_read_element": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes Read command to read complete element from shared data memory. Restrictions apply based on attributes of the element. Volatile registers can never be read. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Target handle to initiate read operation " + ], + [ + "length", + "As Input, number of bytes to read. Cannot exceed element size " + ], + [ + "data_out", + "Actual data read is returned here" + ] + ] + }, + "talib_read_partial_element": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes Read command to read partial element from shared date memory. Restrictions apply based on attributes of the element. Volatile registers can never be read. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Target handle to initiate read operation " + ], + [ + "offset", + "Offset to the first byte to be read... Applicable only to Shared data memory only " + ], + [ + "length", + "As Input, number of bytes to read. Cannot exceed element size As Output, number bytes read is returned here " + ], + [ + "data", + "Actual data read is returned here" + ] + ] + }, + "talib_read_config_zone": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p" + ], + "docstring": "Executes Read command to read the complete device configuration handle. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "config_data", + "Configuration zone data is returned here." + ] + ] + }, + "talib_read_gpio_pin_state": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "Executes Read command to read the gpio pin state. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "gpio_handle", + "refer to gpio handle (gpio1, gpio2, gpio2) " + ], + [ + "pin_state", + "state of the gpio pin returned here" + ] + ] + }, + "talib_read_pubkey_compat": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char*64" + ], + "docstring": "Executes Read command to read an ECC P256 public key from a handle for clear reads. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "handle", + "Handle number to read from. " + ], + [ + "public_key", + "Public key is returned here." + ] + ] + }, + "talib_read_bytes_zone": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_size_t", + "ctypes.c_char_p", + "ctypes.c_size_t" + ], + "docstring": "Used to read an arbitrary number of bytes from internal memory for clear reads. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "zone", + "Zone to read data from. Unused " + ], + [ + "handle", + "handle number to read " + ], + [ + "offset", + "Byte offset within the handle to read from. " + ], + [ + "data", + "Read data is returned here. " + ], + [ + "length", + "Number of bytes to read starting from the offset." + ] + ] + }, + "talib_read_sig_compat": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char*64" + ], + "docstring": "Executes Read command to read a 64 byte ECDSA P256 signature from a slot configured for clear reads. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "handle", + "Handle number to read from. " + ], + [ + "signature", + "Signature will be returned here (64 bytes). Format will be the 32 byte R and S big-endian integers concatenated." + ] + ] + }, + "talib_read_data_transfer": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p" + ], + "docstring": "Executes Read command to transfer key to another vega device. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "transfer_handle", + "handle where data need to be written " + ], + [ + "data", + "transfer package is returned here " + ], + [ + "transfer_mac", + "mac for transfer read" + ] + ] + }, + "talib_cmp_config_zone": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char*(48)", + "ctypes.POINTER(ctypes.c_bool)" + ], + "docstring": "Compares a specified configuration zone with the configuration zone currently on the device. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "config_data", + "Full configuration data to compare the device against. " + ], + [ + "same_config", + "Result is returned here. True if the static portions on the configuration zones are the same." + ] + ] + }, + "talib_rsaenc": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes RSAEnc command to perform RSA Encryption and Decryption operations Maximum number of bytes that can be encrypted or decrypted is 62. This is available only for RSA-1024 bit keys. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "mode parameter for RSAEnc command " + ], + [ + "in_length", + "number of bytes in data_in " + ], + [ + "handle", + "RSA Key handle for encrypt or decrypt operation " + ], + [ + "data_in", + "Input data to encrypt or decrypt" + ], + [ + "data_out", + "Encrypt or decrypt result is returned here " + ], + [ + "public_key", + "RSA-1024 bit public key for encryption if handle is IO buffer, otherwise NULL. " + ], + [ + "out_length", + "As Input, size of data_out As output, number of bytes in data_out" + ] + ] + }, + "talib_rsaenc_encrypt": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes RSAEnc command to perform RSA Encryption. Encrypt using shared data element which is referred by handle. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "handle", + "RSA public Key handle for encrypt operation " + ], + [ + "text_size", + "number of bytes of plain text (maximum 62 bytes) " + ], + [ + "plain_text", + "Input data to encrypt " + ], + [ + "cipher_text_size", + "The size of the ciphertext buffer " + ], + [ + "cipher_text", + "Encrypted result is returned here " + ] + ] + }, + "talib_rsaenc_encrypt_with_iobuffer": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes RSAEnc command to perform RSA Encryption. Encrypt using given public key in input buffer. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "pub_key", + "public key used to encrypt the plain text " + ], + [ + "text_size", + "number of bytes of plain text (maximum 62 bytes) " + ], + [ + "plain_text", + "Input data to encrypt " + ], + [ + "cipher_text_size", + "The size of the ciphertext buffer " + ], + [ + "cipher_text", + "Encrypted result is returned here" + ] + ] + }, + "talib_rsaenc_decrypt": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes RSAEnc command to perform RSA Decryption. Decrypt using private key referred by the handle. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "handle", + "RSA private Key handle to decrypt cipher text " + ], + [ + "text_size", + "number of bytes of cipher text which is always 128 bytes. " + ], + [ + "cipher_text", + "Input data to decrypt " + ], + [ + "plain_text_size", + "Size of the plain_text buffer. " + ], + [ + "plain_text", + "decrypted result is returned here" + ] + ] + }, + "talib_secureboot_full_asymmetric": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_size_t", + "ctypes.POINTER(ctypes.c_bool)" + ], + "docstring": "TA API - Execute secureboot command with full asymmetric mode. signature is validated against extracted certificates or secure boot public key. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "dig_handle", + "Handle for the code digest " + ], + [ + "pub_handle", + "Handle for the validating public key which must be a root key or extracted certificate element " + ], + [ + "digest", + "Input digest " + ], + [ + "signature", + "Input code signature " + ], + [ + "sig_len", + "length of the input signature " + ], + [ + "is_validated", + "result of secure boot validation (True or False)" + ] + ] + }, + "talib_secureboot_preset": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "TA API - Execute secure boot command preset phase mode for full stored, partial and pre boot config mode. This phase allocates the necessary space for the stored digest in the secureboot handle. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "mode", + "determine full store or partial or pre-boot For full stored, 0x10 For partial, 0x20 For pre-boot, 0x40 " + ], + [ + "dig_handle", + "handle for the code digest. For full stored and pre-boot, it is always 0x4800 For partial, it is always 0x0000 " + ], + [ + "param", + "determine digest present in io buffer or not For full stored and pre-boot, it is either 0x0001 or 0x0000 For partial, it is always 0x0000 " + ], + [ + "digest", + "input code digest" + ] + ] + }, + "talib_secureboot_update": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_size_t", + "ctypes.POINTER(ctypes.c_bool)" + ], + "docstring": "TA API - Execute secureboot command with update phase mode for full stored and pre-boot For partial config mode, this phase is similar with complete phase This phase writes a new digest to the special handle allocated during the Preset phase. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "mode", + "determine config mode For full stored, 0x11 For partial, 0x24 For pre-boot, 0x41 " + ], + [ + "dig_handle", + "Handle for the code digest For partial, 0x0000 " + ], + [ + "pub_handle", + "Handle for the validating public key which must be a root key or extracted certificate element " + ], + [ + "digest", + "Input digest For partial, no input digest required " + ], + [ + "signature", + "Input code signature " + ], + [ + "sig_len", + "length of the input signature " + ], + [ + "is_validated", + "result of secure boot validation (True or False)" + ] + ] + }, + "talib_secureboot_boot": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.POINTER(ctypes.c_bool)" + ], + "docstring": "TA API - Execute secureboot command with boot phase mode for full store, partial and pre boot config mode. Validate the code digest from the host against stored digest. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "mode", + "Determine config mode For full store, 0x12 For partial, 0x26 For pre boot, 0x42 " + ], + [ + "dig_handle", + "Handle for the code digest " + ], + [ + "digest", + "input code digest " + ], + [ + "is_validated", + "result of secure boot validation (True or False)" + ] + ] + }, + "talib_secureboot_fullstore_preset": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Execute secure boot command preset phase mode for full stored config mode. This phase allocates the necessary space for the stored digest in the secureboot handle. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "digest", + "input code digest" + ] + ] + }, + "talib_secureboot_fullstore_update": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_size_t", + "ctypes.POINTER(ctypes.c_bool)" + ], + "docstring": "TA API - Execute secureboot command with update phase mode for full stored config mode. This phase writes a new digest to the special handle allocated during the Preset phase. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "dig_handle", + "Handle for the code digest " + ], + [ + "pub_handle", + "Handle for the validating public key which must be a root key or extracted certificate element " + ], + [ + "digest", + "Input digest " + ], + [ + "signature", + "Input code signature " + ], + [ + "sig_len", + "length of the input signature " + ], + [ + "is_validated", + "result of secure boot validation (True or False)" + ] + ] + }, + "talib_secureboot_fullstore_boot": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.POINTER(ctypes.c_bool)" + ], + "docstring": "TA API - Execute secureboot command with boot phase mode for full store config mode. Validate the code digest from the host against stored digest. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "dig_handle", + "Handle for the code digest " + ], + [ + "digest", + "input code digest " + ], + [ + "is_validated", + "result of secure boot validation (True or False)" + ] + ] + }, + "talib_secureboot_partial_preset": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "TA API - Execute secure boot command preset phase mode for partial config mode. This phase allocates the necessary space for the stored digest in the secureboot handle. ", + "parameters": [ + [ + "device", + "device context pointer" + ] + ] + }, + "talib_secureboot_partial_setup": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint32" + ], + "docstring": "TA API - Execute secure boot command for setup phase in partial config mode This phase initializes the code update sequence. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "code_size", + "Total size of the code over which the signature was generated" + ] + ] + }, + "talib_secureboot_partial_code_base": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_char_p", + "ctypes.c_size_t" + ], + "docstring": "TA API - Execute Secureboot command in partial config mode to update the code Pass a full SHA256 (64 byte) block of code to the Vega device as part of the overall code load/upgrade procedure. This phase is run repeatedly till the final full or partial block has been sent. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "mode", + "determine initial block or final block " + ], + [ + "code", + "Subsequent block of operating code bytes " + ], + [ + "code_size", + "size of the operating code" + ] + ] + }, + "talib_secureboot_partial_code": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Execute Secureboot command in partial config mode to update the initial code Pass a full SHA256 (64 byte) block of code to the Vega device as part of the overall code load/upgrade procedure. This phase is run repeatedly till before the final full or partial block has been sent. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "code", + "Subsequent block of operating code bytes Data must be of 64 bytes" + ] + ] + }, + "talib_secureboot_partial_final": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p", + "ctypes.c_size_t" + ], + "docstring": "TA API - Execute Secureboot command in partial config mode to update the final code This phase update the final code block. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "code", + "Subsequent block of operating code bytes " + ], + [ + "code_size", + "size of the operating code" + ] + ] + }, + "talib_secureboot_partial_complete": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_size_t", + "ctypes.POINTER(ctypes.c_bool)" + ], + "docstring": "TA API - Execute secureboot command in partial config mode of complete phase This phase verifies the signature and updated the partial digests. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "pub_handle", + "Handle for the validating public key which must be a root key or extracted certificate element " + ], + [ + "signature", + "Input code signature " + ], + [ + "sig_len", + "length of the input signature " + ], + [ + "is_validated", + "result of secure boot validation (True or False)" + ] + ] + }, + "talib_secureboot_partial_address": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.POINTER(ctypes.c_uint32)", + "ctypes.POINTER(ctypes.c_uint32)" + ], + "docstring": "TA API - Execute secureboot command in partial config mode of address phase This pahse retrieve address min/max bounds from the Vega device. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "begin", + "The begin address (inclusive) for the current portion over which host should calculate digest " + ], + [ + "end", + "The ending address (inclusive) for the current portion" + ] + ] + }, + "talib_secureboot_partial_boot": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.POINTER(ctypes.c_bool)" + ], + "docstring": "TA API - Execute secureboot command with boot phase mode for partial config mode. Validate the code digest from the host against stored digest. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "dig_handle", + "Handle for the code digest " + ], + [ + "digest", + "input code digest " + ], + [ + "is_validated", + "result of secure boot validation (True or False)" + ] + ] + }, + "talib_secureboot_preboot_preset": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Execute secure boot command preset phase mode for pre boot config mode. This phase allocates the necessary space for the stored digest in the secureboot handle. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "digest", + "input code digest" + ] + ] + }, + "talib_secureboot_preboot_update": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_size_t", + "ctypes.POINTER(ctypes.c_bool)" + ], + "docstring": "TA API - Execute secureboot command with update phase mode for pre boot config mode. This phase writes a new digest to the special handle allocated during the Preset phase. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "dig_handle", + "Handle for the code digest " + ], + [ + "pub_handle", + "Handle for the validating public key which must be a root key or extracted certificate element " + ], + [ + "digest", + "Input digest " + ], + [ + "signature", + "Input code signature " + ], + [ + "sig_len", + "length of the input signature " + ], + [ + "is_validated", + "result of secure boot validation (True or False)" + ] + ] + }, + "talib_secureboot_preboot_boot": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.POINTER(ctypes.c_bool)" + ], + "docstring": "TA API - Execute secureboot command with boot phase mode for pre boot config mode. Validate the code digest from the host against stored digest. ", + "parameters": [ + [ + "device", + "device context pointer " + ], + [ + "dig_handle", + "Handle for the code digest " + ], + [ + "digest", + "input code digest " + ], + [ + "is_validated", + "result of secure boot validation (True or False)" + ] + ] + }, + "talib_secureboot_common_lock": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "TA API - Execute secureboot command to prevents further Secure_Boot commands from executing until the next power/reset cycle or the passing of 50% of the secure boot timer. ", + "parameters": [ + [ + "device", + "device context pointer" + ] + ] + }, + "talib_selftest": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint32", + "ctypes.POINTER(ctypes.c_uint32)" + ], + "docstring": "TA API - Executes the SelfTest command, which performs a test of one or more of the cryptographic engines within the chip. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "Mode for self test command " + ], + [ + "tests_bitmap", + "Bit map of tests to be run for self tests " + ], + [ + "result_bitmap", + "Bit map of tests that failed self tests" + ] + ] + }, + "talib_sha_base": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes SHA command, which computes a SHA-256 digest for general purpose use by the host system. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "SHA command mode Start(0), Update/Compute(1), Finalize(2) or Entire message is in IO buffer(3). " + ], + [ + "length", + "Number of bytes in the input stream " + ], + [ + "context_handle", + "Target handle to write digest or SHA context handle of prior calculation " + ], + [ + "message", + "Data bytes to be hashed " + ], + [ + "data_out", + "Data returned by the command (digest or context). " + ], + [ + "data_out_size", + "As input, the size of the data_out buffer. As output, the number of bytes returned in data_out." + ] + ] + }, + "talib_sha_base_compat": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes SHA command, which computes a SHA-256 digest for general purpose use by the host system. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "SHA command mode Start(0), Update/Compute(1), Finalize(2) or Entire message is in IO buffer(3). " + ], + [ + "length", + "Number of bytes in the input stream " + ], + [ + "message", + "Data bytes to be hashed " + ], + [ + "digest", + "Data returned by the command (digest or context). " + ], + [ + "digest_size", + "As input, the size of the data_out buffer. As output, the number of bytes returned in data_out." + ] + ] + }, + "talib_sha_start": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "Executes SHA command to initialize SHA-256 calculation engine. ", + "parameters": [ + [ + "device", + "Device context pointer " + ] + ] + }, + "talib_sha_start_with_handle": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16" + ], + "docstring": "Executes SHA command to initialize SHA-256 calculation engine. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "context_handle", + "SHA context handle of prior calculation" + ] + ] + }, + "talib_sha_update": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "Executes SHA command to add message data to the current context. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "message_length", + "length of input message for SHA operation " + ], + [ + "message", + "message data to add to SHA operation." + ] + ] + }, + "talib_sha_update_with_handle": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "Executes SHA command to add message data to the current context. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "context_handle", + "SHA context handle of prior calculation " + ], + [ + "message_length", + "length of input message for SHA operation " + ], + [ + "message", + "message data to add to SHA operation." + ] + ] + }, + "talib_sha_update_compat": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p" + ], + "docstring": "Executes SHA command to add message data to the current context. (compatibility function) ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "message", + "message data to add to SHA operation." + ] + ] + }, + "talib_sha_end": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p" + ], + "docstring": "Executes SHA command to finalize SHA-256 calculation engine. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "digest", + "Digest is returned here (32 bytes)." + ] + ] + }, + "talib_sha_end_with_handle": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "Executes SHA command to finalize SHA-256 calculation engine. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "context_handle", + "SHA context handle of prior calculation " + ], + [ + "digest", + "Digest is returned here (32 bytes)." + ] + ] + }, + "talib_sha_end_compat": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "Executes SHA command to finalize SHA-256 calculation engine. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "digest", + "Digest is returned here (32 bytes). " + ], + [ + "length", + "input message length to update the context " + ], + [ + "message", + "message to compute SHA" + ] + ] + }, + "talib_sha": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char*32" + ], + "docstring": "Use the SHA command to compute a SHA-256 digest for given message in input stream. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "length", + "Size of message parameter in bytes. " + ], + [ + "message", + "Message data to be hashed. " + ], + [ + "digest", + "Digest is returned here (32 bytes)." + ] + ] + }, + "talib_sha_with_handle": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p" + ], + "docstring": "Use the SHA command to compute a SHA-256 digest for given message in input stream. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "context_handle", + "Target to write the digest " + ], + [ + "length", + "Size of message parameter in bytes. " + ], + [ + "message", + "Message data to be hashed. " + ], + [ + "digest", + "Digest is returned here (32 bytes)." + ] + ] + }, + "talib_sha_read_context": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": null, + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "context", + "Context data is returned here. " + ], + [ + "context_size", + "As input, the size of the context buffer in bytes. As output, the size of the returned context data." + ] + ] + }, + "talib_sha_read_context_with_handle": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "Executes Read command to read the SHA-256 context from given input handle. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "context_handle", + "SHA context handle of prior calculation " + ], + [ + "context", + "Context data is returned here. " + ], + [ + "context_size", + "As input, the size of the context buffer in bytes. As output, the size of the returned context data." + ] + ] + }, + "talib_sha_write_context": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char_p", + "ctypes.c_uint16" + ], + "docstring": "Executes SHA command to write (restore) a SHA-256 context into the the device SHA context0 handle. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "context", + "Context data to be restored. " + ], + [ + "context_size", + "Size of the context data in bytes." + ] + ] + }, + "talib_sha_write_context_with_handle": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16" + ], + "docstring": "Executes SHA command to write (restore) a SHA-256 context into the the device in given input handle. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "context_handle", + "SHA context handle of prior calculation " + ], + [ + "context", + "Context data to be restored. " + ], + [ + "context_size", + "Size of the context data in bytes." + ] + ] + }, + "talib_sign_internal": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes the Sign command for sign internally generated messages using ECDSA or RSA algorithm. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "Mode determines algorithm, key and algorithm options " + ], + [ + "priv_handle", + "Private key handle used to sign the message. " + ], + [ + "template_handle", + "Message template handle... Should be in Shared Data memory " + ], + [ + "target_handle", + "Private key corresponding to Public Key to be included in the message... Should be in Shared Data memory " + ], + [ + "signature", + "Signature is returned here. " + ], + [ + "sign_size", + "As input, the size of the data_out buffer. As output, the number of bytes returned in data_out." + ] + ] + }, + "talib_sign_external": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - Executes the Sign command for sign the external messages using ECDSA or RSA algorithm. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "Mode determines algorithm, key and algorithm options " + ], + [ + "priv_handle", + "Private key handle used to sign the message " + ], + [ + "msg_handle", + "Message handle that contains message to be signed " + ], + [ + "message", + "Message to be signed when msg_handle points to Input buffer Should be 28, 32 or 48 bytes when sent on Input buffer " + ], + [ + "message_length", + "number of bytes in message buffer " + ], + [ + "signature", + "Signature is returned here. " + ], + [ + "sign_size", + "As input, the size of the signature buffer. As output, the number of bytes returned in data_out." + ] + ] + }, + "talib_sign_compat": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char*32", + "ctypes.c_char*64" + ], + "docstring": "Executes Sign command, to sign a 32-byte external message using the private key in the specified slot. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_id", + "Slot of the private key to be used to sign the message. " + ], + [ + "msg", + "32-byte message to be signed. Typically the SHA256 hash of the full message. " + ], + [ + "signature", + "Signature will be returned here. Format is R and S integers in big-endian format. 64 bytes for P256 curve." + ] + ] + }, + "talib_verify": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.POINTER(ctypes.c_bool)" + ], + "docstring": "TA API - Executes the Verify command, to Verify a signature using given the message and a public key. The message and public key can either be stored within Vega or passed on the command line. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "Verify command mode options " + ], + [ + "msg_handle", + "Message handle that contains message used for Signature calculation " + ], + [ + "pub_handle", + "Public key Handle to be used to verify signature " + ], + [ + "signature", + "Signature to be verified " + ], + [ + "sign_size", + "Size of the signature passed. Varies based on Key type and Algorithm " + ], + [ + "message", + "If msg_handle is IO buffer, message used for Signature calculation. NULL if message is coming from other than IO buffer " + ], + [ + "message_len", + "input message length " + ], + [ + "public_key", + "If pub_handle is IO buffer, the public key to be used for verification. NULL if Public key is stored internally " + ], + [ + "pubkey_len", + "Size of the public_key passed. Varies based on Key type and Algorithm " + ], + [ + "is_verified", + "if verified true returned here or else false." + ] + ] + }, + "talib_verify_extern_compat": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char*32", + "ctypes.c_char*64", + "ctypes.c_char*64", + "ctypes.POINTER(ctypes.c_bool)" + ], + "docstring": "Executes the Verify command for ECCP256, which verifies a signature (ECDSA verify operation) with all components (message, signature, and public key) supplied. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "message", + "32 byte message to be verified. Typically the SHA256 hash of the full message. " + ], + [ + "signature", + "Signature to be verified. R and S integers in big-endian format. 64 bytes for P256 curve. " + ], + [ + "public_key", + "The public key to be used for verification. X and Y integers in big-endian format. 64 bytes for P256 curve. " + ], + [ + "is_verified", + "Boolean whether or not the message, signature, public key verified." + ] + ] + }, + "talib_verify_stored_compat": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char*32", + "ctypes.c_char*64", + "ctypes.c_uint16", + "ctypes.POINTER(ctypes.c_bool)" + ], + "docstring": "Executes the Verify command for ECCP256, which verifies a signature (ECDSA verify operation) with a public key stored in the device. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "message", + "32 byte message to be verified. Typically the SHA256 hash of the full message. " + ], + [ + "signature", + "Signature to be verified. R and S integers in big-endian format. 64 bytes for P256 curve. " + ], + [ + "key_id", + "Handle containing the public key to be used in the verification. " + ], + [ + "is_verified", + "Boolean whether or not the message, signature, public key verified." + ] + ] + }, + "talib_verify_point_exp": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_char_p", + "ctypes.c_char_p" + ], + "docstring": "Executes the Verify command, to expand a point for known X - value and return Y - val. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "y_odd", + "2 if Y is even or 3 if Y is odd" + ], + [ + "x_val", + "Known X value" + ], + [ + "y_val", + "Y value for corresponding X value returned here" + ] + ] + }, + "talib_write": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes Write command to write an element. This supports both partial and completed writes Restrictions apply based on attributes of the element. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "mode", + "mode parameter for the write operations " + ], + [ + "source_handle", + "Memory handle to source data from... Must be IO buffer or volatile register " + ], + [ + "target_handle", + "Target handle to write data " + ], + [ + "length", + "Number of bytes to write. Cannot exceed element size " + ], + [ + "offset", + "Offset to the first byte to be written... Valid only for partial writes " + ], + [ + "write_data", + "Data to write if source_handle points to IO buffer " + ], + [ + "mac", + "MAC returned for the transfer function. " + ] + ] + }, + "talib_write_element": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes Write command to write an entire element. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "target_handle", + "Target handle to write data " + ], + [ + "length", + "Number of bytes to write. Cannot exceed element size Valid only for partial writes " + ], + [ + "write_data", + "Data to write if source_handle points to IO buffer" + ] + ] + }, + "talib_write_partial_element": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes Write command to write a partial element. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "target_handle", + "Target handle to write data " + ], + [ + "length", + "Number of bytes to write. Cannot exceed element size " + ], + [ + "offset", + "Offset to the first byte to be written... Valid only for partial writes " + ], + [ + "write_data", + "Data to write if source_handle points to IO buffer" + ] + ] + }, + "talib_write_config_zone": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_char*(48)" + ], + "docstring": "Executes the Write command, which writes the configuration zone. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "config_data", + "Data to the config zone data. ." + ] + ] + }, + "talib_write_pubkey_compat": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char*64" + ], + "docstring": "Executes the Write command, which writes a public key to a data handle in the device format. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "handle", + "refer to handle where public key reside " + ], + [ + "public_key", + "Public key to write into the handle specified. X and Y integers in big-endian format. 64 bytes for P256 curve." + ] + ] + }, + "talib_write_zone": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_uint8", + "ctypes.c_uint8", + "ctypes.c_char_p", + "ctypes.c_uint8" + ], + "docstring": "Executes the Write command in compability mode. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "zone", + "Unused parameter " + ], + [ + "handle", + "the handle number to write to. " + ], + [ + "block", + "Block number (cryptoauth block size is 32 bytes) " + ], + [ + "offset", + "Byte offset within the \"block\" to write to. " + ], + [ + "data", + "Data to be written. " + ], + [ + "length", + "Number of bytes to be written." + ] + ] + }, + "talib_write_bytes_zone": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint16", + "ctypes.c_size_t", + "ctypes.c_char_p", + "ctypes.c_size_t" + ], + "docstring": "Executes the Write command. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "zone", + "Unused parameter " + ], + [ + "handle", + "the handle number to write to. " + ], + [ + "offset_bytes", + "Byte offset within the handle to write to. " + ], + [ + "data", + "Data to be written. " + ], + [ + "length", + "Number of bytes to be written." + ] + ] + }, + "talib_write_gpio_pin_state": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "Executes write command to write the gpio pin state. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "gpio_handle", + "refer to gpio handle (gpio1, gpio2, gpio2) " + ], + [ + "pin_state", + "state of the gpio pin" + ] + ] + }, + "talib_write_volatile_shared_transfer": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16" + ], + "docstring": "Executes write command to transfer key from vol_reg to shared data. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "source_handle", + "handle from data will be copied " + ], + [ + "target_handle", + "handle where data will be written" + ] + ] + }, + "talib_write_priv_key": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes Write command to write a private key. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Target handle to write data " + ], + [ + "length", + "Number of bytes to write. Cannot exceed element size Valid only for partial writes " + ], + [ + "private_key", + "private key to write into key_handle mentioned" + ] + ] + }, + "talib_write_pub_key": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_char_p" + ], + "docstring": "TA API - Executes Write command to write a public key. ", + "parameters": [ + [ + "device", + "Device context pointer " + ], + [ + "key_handle", + "Target handle to write data " + ], + [ + "length", + "The size of the public key. Cannot exceed element size " + ], + [ + "public_key", + "Public key to write into key_handle mentioned" + ] + ] + }, + "talib_handle_init_public_key": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.POINTER(ta_element_attributes_t)", + "ctypes.c_uint8", + "ctypes.c_uint8", + "ctypes.c_uint8", + "ctypes.c_uint8" + ], + "docstring": "TA API - Helper function to create the Handle attributes for Public key. This function will not create the handle and it is only a helper function for Create command. ", + "parameters": [ + [ + "element_attributes", + "Pointer to store the 8 byte Handle attributes. " + ], + [ + "key_type", + "The key type for the Handle. " + ], + [ + "alg_mode", + "The algorithm mode for the key_type and is applicable to rsa key only. " + ], + [ + "secure_boot_enable", + "Mode for the Secure boot functions. " + ], + [ + "root_key_enable", + "Mode for the Public key functions. " + ] + ] + }, + "talib_handle_init_private_key": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.POINTER(ta_element_attributes_t)", + "ctypes.c_uint8", + "ctypes.c_uint8", + "ctypes.c_uint8", + "ctypes.c_uint8" + ], + "docstring": "TA API - Helper function to create the Handle attributes for Private key. This function will not create the handle and it is only a helper function for Create command. ", + "parameters": [ + [ + "element_attributes", + "Pointer to store the 8 byte Handle attributes. " + ], + [ + "key_type", + "The key type for the Handle. " + ], + [ + "alg_mode", + "The algorithm mode for the key_type and is applicable to rsa key only. " + ], + [ + "sign_use", + "Modes for signature generation. " + ], + [ + "key_agreement_use", + "Modes for Key agreement. " + ] + ] + }, + "talib_handle_init_symmetric_key": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.POINTER(ta_element_attributes_t)", + "ctypes.c_uint8", + "ctypes.c_uint8" + ], + "docstring": "TA API - Helper function to create the Handle attributes for Symmetric key. This function will not create the handle and it is only a helper function for Create command. ", + "parameters": [ + [ + "element_attributes", + "Pointer to store the 8 byte Handle attributes. " + ], + [ + "key_type", + "The key type for the Handle. " + ], + [ + "sym_usage", + "Modes for MAC/ENC/KDF operations. " + ] + ] + }, + "talib_handle_init_data": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.POINTER(ta_element_attributes_t)", + "ctypes.c_uint16" + ], + "docstring": "TA API - Helper function to create the Handle attributes for Symmetric key. This function will not create the handle and it is only a helper function for Create command. ", + "parameters": [ + [ + "element_attributes", + "Pointer to store the 8 byte Handle attributes. " + ], + [ + "data_size", + "The size of the data element and the maximum size is 2048. " + ] + ] + }, + "talib_handle_init_extracated_certificate": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.POINTER(ta_element_attributes_t)", + "ctypes.c_uint8", + "ctypes.c_uint8", + "ctypes.c_uint8", + "ctypes.c_uint8" + ], + "docstring": "TA API - Helper function to create the Handle attributes for Extracted Certificates. This function will not create the handle and it is only a helper function for Create command. ", + "parameters": [ + [ + "element_attributes", + "Pointer to store the 8 byte Handle attributes. " + ], + [ + "key_type", + "The key type the extracted cert. " + ], + [ + "alg_mode", + "The algorithm mode for the extracted cert and is applicable to rsa key only. " + ], + [ + "secure_boot_use", + "Modes for the Secure boot use. " + ], + [ + "intermediate_CA_enable", + "Mode for the extracted cert use as parent CA or not. " + ] + ] + }, + "talib_handle_init_fast_crypto_key_group": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.POINTER(ta_element_attributes_t)", + "ctypes.c_uint8", + "ctypes.c_uint8", + "ctypes.c_uint8" + ], + "docstring": "TA API - Helper function to create the Handle attributes for Fast Crypto key group. This function will not create the handle and it is only a helper function for Create command. ", + "parameters": [ + [ + "element_attributes", + "Pointer to store the 8 byte Handle attributes. " + ], + [ + "key_type", + "The key type for the handle. Applicable only for symmetric key. " + ], + [ + "no_of_keys", + "No of key space in the handle. " + ], + [ + "handles", + "Mode for single key or for a group of keys space. " + ] + ] + }, + "talib_handle_set_permissions": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.POINTER(ta_element_attributes_t)", + "ctypes.c_uint8", + "ctypes.c_uint8", + "ctypes.c_uint8", + "ctypes.c_uint8" + ], + "docstring": "TA API - Helper function to create the permission for the handle. This function will not create the handle and it is only a helper function for Create command. ", + "parameters": [ + [ + "element_attributes", + "Pointer the handle attributes. " + ], + [ + "usage_perm", + "Usage permissions for the handle. " + ], + [ + "write_perm", + "Write permissions for the handle. " + ], + [ + "read_perm", + "Read permissions for the handle. " + ], + [ + "delete_perm", + "Delete permissions for the handle.. " + ] + ] + }, + "talib_handle_set_usage_permission": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.POINTER(ta_element_attributes_t)", + "ctypes.c_uint8" + ], + "docstring": "TA API - Helper function to create the permission for the handle. This function will not create the handle and it is only a helper function for Create command. ", + "parameters": [ + [ + "element_attributes", + "Pointer the handle attributes. " + ], + [ + "usage_perm", + "Usage permissions for the handle. " + ] + ] + }, + "talib_handle_set_write_permission": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.POINTER(ta_element_attributes_t)", + "ctypes.c_uint8" + ], + "docstring": "TA API - Helper function to create the permission for the handle. This function will not create the handle and it is only a helper function for Create command. ", + "parameters": [ + [ + "element_attributes", + "Pointer the handle attributes. " + ], + [ + "write_perm", + "Usage permissions for the handle. " + ] + ] + }, + "talib_handle_set_read_permission": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.POINTER(ta_element_attributes_t)", + "ctypes.c_uint8" + ], + "docstring": "TA API - Helper function to create the permission for the handle. This function will not create the handle and it is only a helper function for Create command. ", + "parameters": [ + [ + "element_attributes", + "Pointer the handle attributes. " + ], + [ + "read_perm", + "Usage permissions for the handle. " + ] + ] + }, + "talib_handle_set_delete_permission": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.POINTER(ta_element_attributes_t)", + "ctypes.c_uint8" + ], + "docstring": "TA API - Helper function to create the permission for the handle. This function will not create the handle and it is only a helper function for Create command. ", + "parameters": [ + [ + "element_attributes", + "Pointer the handle attributes. " + ], + [ + "delete_perm", + "Usage permissions for the handle. " + ] + ] + }, + "talib_sequence_base": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_uint8", + "ctypes.c_uint32", + "ctypes.c_char_p", + "ctypes.c_uint16", + "ctypes.c_char_p", + "ctypes.c_uint16_p" + ], + "docstring": "TA API - To pass data from host to TA100 or TA100 to host for sequence calculation. ", + "parameters": [ + [ + "device", + "Device object that holds the device related informations " + ], + [ + "mode", + "Mode value for sequence operation " + ], + [ + "param", + "TA100 parameter for sequence command " + ], + [ + "data_in", + "Input data for the sequence command " + ], + [ + "data_in_length", + "Input data length " + ], + [ + "data_out", + "Output data buffer where sequence command output is copied " + ], + [ + "data_out_length", + "As input, the size of the data_out buffer and as output the size of the data." + ] + ] + }, + "talib_sharekey_sequence_init": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p", + "ctypes.c_void_p", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_uint16", + "ctypes.c_bool", + "ctypes.c_void_p" + ], + "docstring": "TA API - To initialize share key sequence context with given input parameters. ", + "parameters": [ + [ + "ctx", + "Share key sequence object that holds the share key related informations " + ], + [ + "target_handle", + "Handle where shared secret to be created " + ], + [ + "ephe_handle", + "Handle where local ephemeral to be created " + ], + [ + "sign_handle", + "Signing handle to create singature to be send to remote " + ], + [ + "cert_handle", + "Handle where remote certificate is extracted " + ], + [ + "symm_key_size", + "Share key size to be created " + ], + [ + "is_local_first", + "It is Set, if local nonce and public key to be used in first for TBS message " + ], + [ + "sharekey_cb", + "Call back function used to share IO buffers between application and CAL" + ] + ] + }, + "talib_sequence_sharekey_step1": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "Share Key - Step 1: Random. ", + "parameters": [ + [ + "ctx", + "Share key sequence object that holds the share key related informations" + ] + ] + }, + "talib_sequence_sharekey_step2": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "Share Key - Step 2: Remote Nonce. ", + "parameters": [ + [ + "ctx", + "Share key sequence object that holds the share key related informations" + ] + ] + }, + "talib_sequence_sharekey_step3": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "Share Key - Step 3: Create Target Handle. ", + "parameters": [ + [ + "ctx", + "Share key sequence object that holds the share key related informations" + ] + ] + }, + "talib_sequence_sharekey_step4": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "Share Key - Step 4: Create Ephemeral Key Handle. ", + "parameters": [ + [ + "ctx", + "Share key sequence object that holds the share key related informations" + ] + ] + }, + "talib_sequence_sharekey_step5": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "Share Key - Step 5: Key Gen Ephemeral Private Key. ", + "parameters": [ + [ + "ctx", + "Share key sequence object that holds the share key related informations" + ] + ] + }, + "talib_sequence_sharekey_step6": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "Share Key - Step 6: Receive Remote Ephemeral Public Key. ", + "parameters": [ + [ + "ctx", + "Share key sequence object that holds the share key related informations" + ] + ] + }, + "talib_sequence_sharekey_step7": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "Share Key - Step 7: Sign. ", + "parameters": [ + [ + "ctx", + "Share key sequence object that holds the share key related informations" + ] + ] + }, + "talib_sequence_sharekey_step8": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "Share Key - Step 8: Verify Remote Signature. ", + "parameters": [ + [ + "ctx", + "Share key sequence object that holds the share key related informations" + ] + ] + }, + "talib_sequence_sharekey_step9": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "Share Key - Step 9: Ephemeral ECDH. ", + "parameters": [ + [ + "ctx", + "Share key sequence object that holds the share key related informations" + ] + ] + }, + "talib_sequence_sharekey_step10": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "Share Key - Step 10: KDF (HMAC-counter) ", + "parameters": [ + [ + "ctx", + "Share key sequence object that holds the share key related informations" + ] + ] + }, + "talib_sharekey_sequence_execute": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "TA API - To execute share key sequence steps. ", + "parameters": [ + [ + "ctx", + "Share key sequence object that holds the share key related informations" + ] + ] + }, + "talib_sharekey_sequence_terminate": { + "restype": "ctypes.c_uint8", + "argtypes": [ + "ctypes.c_void_p" + ], + "docstring": "TA API - To terminate the share key sequence steps. ", + "parameters": [ + [ + "ctx", + "Share key sequence object that holds the share key related informations" + ] + ] + } +} \ No newline at end of file diff --git a/python/cryptoauthlib/iface.py b/python/cryptoauthlib/iface.py index 4caec8e22..130bf37c5 100644 --- a/python/cryptoauthlib/iface.py +++ b/python/cryptoauthlib/iface.py @@ -74,11 +74,16 @@ class ATCADeviceType(AtcaEnum): # The following must match atca_iface.h exactly +class _U_Address(Union): + """Hidden union to provide backward compatibility with the api change""" + _fields_ = [('slave_address', c_uint8), + ('address', c_uint8)] class _ATCAI2C(Structure): """I2C/TWI HAL configuration""" - _fields_ = [('slave_address', c_uint8), + _anonymous_ = ('u') + _fields_ = [('u', _U_Address), ('bus', c_uint8), ('baud', c_uint32)] diff --git a/python/cryptoauthlib/library.py b/python/cryptoauthlib/library.py index 390fbddc5..1f02226de 100644 --- a/python/cryptoauthlib/library.py +++ b/python/cryptoauthlib/library.py @@ -95,13 +95,13 @@ def load_cryptoauthlib(lib=None): _CRYPTO_LIB = lib else: try: - os.environ['PATH'] = os.path.dirname(__file__) + os.pathsep + os.environ['PATH'] - library_file = find_library('cryptoauth') - if library_file is None: - library_file = _force_local_library() - _CRYPTO_LIB = cdll.LoadLibrary(library_file) + _CRYPTO_LIB = cdll.LoadLibrary(find_library('cryptoauth')) except: - raise LibraryLoadError('Unable to find cryptoauthlib. You may need to reinstall') + try: + _CRYPTO_LIB = cdll.LoadLibrary(_force_local_library()) + except: + raise LibraryLoadError('Unable to find cryptoauthlib. You may need to reinstall') + def get_cryptoauthlib(): diff --git a/python/cryptoauthlib/talib.py b/python/cryptoauthlib/talib.py new file mode 100644 index 000000000..2882eb4fa --- /dev/null +++ b/python/cryptoauthlib/talib.py @@ -0,0 +1,333 @@ +""" +Trust Anchor Interface +""" +# (c) 2015-2018 Microchip Technology Inc. and its subsidiaries. +# +# Subject to your compliance with these terms, you may use Microchip software +# and any derivatives exclusively with Microchip products. It is your +# responsibility to comply with third party license terms applicable to your +# use of third party software (including open source software) that may +# accompany Microchip software. +# +# THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER +# EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED +# WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A +# PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, +# SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE +# OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF +# MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE +# FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL +# LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED +# THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR +# THIS SOFTWARE. + +from ctypes import c_uint8, byref, create_string_buffer, c_uint16, c_size_t, POINTER, cast, Array +from .status import Status +from .library import get_cryptoauthlib, AtcaReference, AtcaStructure, AtcaUnion, create_byte_buffer + + +class ta_handle_properties_public_key(AtcaStructure): + """ + Class: 0 + """ + _fields_ = [ + ('Path_Length', c_uint8), + ('Secure_Boot', c_uint8, 1), + ('Root', c_uint8, 2), + ('CRL_Sign', c_uint8, 1), + ('Special_Only', c_uint8, 1), + ('Reserved', c_uint8, 3) + ] + _pack_ = 1 + + +class ta_handle_properties_private_key(AtcaStructure): + """ + Class 1: + """ + _fields_ = [ + ('Pub_Key', c_uint8), + ('Session', c_uint8, 1), + ('Key_Gen', c_uint8, 1), + ('Sign_Use', c_uint8, 2), + ('Agree_Use', c_uint8, 2), + ('Reserved', c_uint8, 2) + ] + _pack_ = 1 + + +class ta_handle_properties_symmetric_key(AtcaStructure): + """ + Class 2 + """ + _fields_ = [ + ('Granted_Rights', c_uint8), + ('Sym_Usage', c_uint8, 2), + ('Session_Use', c_uint8, 3), + ('Key_Group_OK', c_uint8, 1), + ('Reserved', c_uint8, 2) + ] + _pack_ = 1 + +class ta_handle_properties_data(AtcaStructure): + """ + Class 3 + """ + _fields_ = [ + ('Size', c_uint16, 12), + ('Template', c_uint16, 1), + ('Reserved', c_uint16, 3) + ] + _pack_ = 1 + + +class ta_handle_properties_certificate(AtcaStructure): + """ + Class 4 + """ + _fields_ = [ + ('Granted_Rights', c_uint8), + ('Secure_Boot', c_uint8, 1), + ('CA_OK', c_uint8, 1), + ('CA_Parent', c_uint8, 1), + ('CRL_Sign', c_uint8, 1), + ('Special_Only', c_uint8, 1), + ('Reserved', c_uint8, 3) + ] + _pack_ = 1 + + +class ta_handle_properties_key_group(AtcaStructure): + """ + Class 6 + """ + _fields_ = [ + ('Num_Keys', c_uint8, 5), + ('Handles', c_uint8, 1), + ('Reserved0', c_uint8, 2), + ('Reserved1', c_uint8) + ] + _pack_ = 1 + + +class ta_handle_properties_crl(AtcaStructure): + _fields_ = [ + ('Num_Digests', c_uint8), + ('Reserved', c_uint8) + ] + _pack_ = 1 + + +class ta_element_attributes_properties(AtcaUnion): + _fields_ = [ + ('public', ta_handle_properties_public_key), + ('private', ta_handle_properties_private_key), + ('symmetric', ta_handle_properties_symmetric_key), + ('data', ta_handle_properties_data), + ('certificate', ta_handle_properties_certificate), + ('key_group', ta_handle_properties_key_group), + ('crl', ta_handle_properties_crl) + ] + _pack_ = 1 + + +class ta_element_attributes_t(AtcaStructure): + _fields_ = [ + ('Class', c_uint8, 3), + ('Key_Type', c_uint8, 4), + ('Alg_Mode', c_uint8, 1), + ('Property', ta_element_attributes_properties), + ('Usage_Key', c_uint8), + ('Write_Key', c_uint8), + ('Read_Key', c_uint8), + ('Usage_Perm', c_uint8, 2), + ('Write_Perm', c_uint8, 2), + ('Read_Perm', c_uint8, 2), + ('Delete_Perm', c_uint8, 2), + ('Use_Count', c_uint8, 2), + ('Reserved0', c_uint8, 1), + ('Exportable', c_uint8, 1), + ('Lockable', c_uint8, 1), + ('Access_Limit', c_uint8, 2), + ('Reserved1', c_uint8, 1) + ] + _pack_ = 1 + + +def talib_handle_init_public_key(attributes, key_type, alg_mode, secure_boot_enable, root_key_enable): + return get_cryptoauthlib().talib_handle_init_public_key(byref(attributes), key_type, alg_mode, secure_boot_enable, + root_key_enable) + +def talib_handle_init_private_key(attributes, key_type, alg_mode, sign_use, key_agreement_use): + return get_cryptoauthlib().talib_handle_init_private_key(byref(attributes), key_type, alg_mode, sign_use, + key_agreement_use) + + +def talib_handle_init_symmetric_key(attributes, key_type, sym_usage): + return get_cryptoauthlib().talib_handle_init_symmetric_key(byref(attributes), key_type, sym_usage) + + +def talib_handle_init_data(attributes, data_size): + return get_cryptoauthlib().talib_handle_init_data(byref(attributes), data_size) + + +def talib_handle_init_extracated_certificate(attributes, key_type, alg_mode, secure_boot_use, intermediate_ca_enable): + return get_cryptoauthlib().talib_handle_init_extracated_certificate(byref(attributes), key_type, alg_mode, + secure_boot_use, intermediate_ca_enable) + + +def talib_handle_init_fast_crypto_key_group(attributes, key_type, num_keys, handles): + return get_cryptoauthlib().talib_handle_init_fast_crypto_key_group(byref(attributes), key_type, num_keys, handles) + + +def talib_handle_set_permissions(attributes, usage_perm, write_perm, read_perm, delete_perm): + return get_cryptoauthlib().talib_handle_set_permissions(byref(attributes), usage_perm, write_perm, read_perm, + delete_perm) + +def talib_handle_set_usage_permission(attributes, usage_perm): + return get_cryptoauthlib().talib_handle_set_usage_permission(byref(attributes), usage_perm) + + +def talib_handle_set_write_permission(attributes, write_perm): + return get_cryptoauthlib().talib_handle_set_write_permission(byref(attributes), write_perm) + + +def talib_handle_set_read_permission(attributes, read_perm): + return get_cryptoauthlib().talib_handle_set_read_permission(byref(attributes), read_perm) + + +def talib_handle_set_delete_permission(attributes, delete_perm): + return get_cryptoauthlib().talib_handle_set_delete_permission(byref(attributes), delete_perm) + + +def talib_create(device, mode, details, handle_in, handle_config, handle_out): + if not isinstance(handle_out, AtcaReference): + status = Status.ATCA_BAD_PARAM + else: + c_handle_out = c_uint16(handle_out.value) + status = get_cryptoauthlib().talib_create(device, details, handle_in, byref(handle_config), byref(c_handle_out)) + handle_out.value = c_handle_out.value + return status + + +def talib_create_element(device, handle_config, handle_out): + if not isinstance(handle_out, AtcaReference): + status = Status.ATCA_BAD_PARAM + else: + c_handle_out = c_uint16(handle_out.value) + status = get_cryptoauthlib().talib_create_element(device, handle_config, byref(c_handle_out)) + handle_out.value = c_handle_out.value + return status + + +def talib_create_element_with_handle(device, handle_in, handle_config): + return get_cryptoauthlib().talib_create_element_with_handle(device, handle_in, byref(handle_config)) + + +def talib_create_ephemeral_element_with_handle(device, details, handle_in, handle_config): + return get_cryptoauthlib().talib_create_ephemeral_element_with_handle(device, details, handle_in, + byref(handle_config)) + + +def talib_create_hmac_element(device, key_size, handle_config, handle_out): + if not isinstance(handle_out, AtcaReference): + status = Status.ATCA_BAD_PARAM + else: + c_handle_out = c_uint16(handle_out.value) + status = get_cryptoauthlib().talib_create_hmac_element(device, key_size, byref(handle_config), + byref(c_handle_out)) + handle_out.value = c_handle_out.value + return status + + +def talib_create_hmac_element_with_handle(device, key_size, handle_in, handle_config): + return get_cryptoauthlib().talib_create_hmac_element_with_handle(device, key_size, handle_in, byref(handle_config)) + + +def talib_delete_handle(device, handle): + return get_cryptoauthlib().talib_delete_handle(device, handle) + + +def talib_is_handle_valid(device, target_handle, is_valid): + if not isinstance(is_valid, AtcaReference): + status = Status.ATCA_BAD_PARAM + else: + c_is_valid = c_uint8(is_valid.value) + status = get_cryptoauthlib().talib_is_handle_valid(device, target_handle, byref(c_is_valid)) + is_valid.value = c_is_valid.value + return status + + +def talib_info(device, revision): + """ + Used to get the device revision number. (DevRev) + + Args: + revision 8-byte bytearray receiving the revision number + from the device. (Expects bytearray) + + Returns: + Status code + """ + c_revision = create_string_buffer(8) + if not isinstance(revision, bytearray): + status = Status.ATCA_BAD_PARAM + else: + status = get_cryptoauthlib().talib_info(device, c_revision) + revision[0:] = bytes(c_revision.raw) + return status + + +def talib_info_get_handle_info(device, target_handle, handle_info): + if not isinstance(handle_info, ta_element_attributes_t): + status = Status.ATCA_BAD_PARAM + else: + info_array = create_string_buffer(9) + status = get_cryptoauthlib().talib_info_get_handle_info(device, target_handle, info_array) + handle_info.update_from_buffer(info_array) + return status + + +#ATCA_STATUS talib_info_get_handle_info(ATCADevice device, uint32_t target_handle, uint8_t handle_info[STATIC_ARRAY TA_HANDLE_INFO_SIZE]); + + +def talib_info_get_handles_array(device, handles): + if not isinstance(handles, list): + status = Status.ATCA_BAD_PARAM + else: + results = (c_uint16*100)() + count = c_size_t(100) + status = get_cryptoauthlib().talib_info_get_handles_array(device, cast(results, POINTER(c_uint16)), byref(count)) + handles[0:] = results[:count.value] + return status + + +#ATCA_STATUS talib_info_get_handle_size(ATCADevice device, uint32_t target_handle, size_t* out_size); + + +def talib_write_element(device, handle, length, data): + status = get_cryptoauthlib().talib_write_element(device, handle, length, bytes(data)) + + return status + + +def talib_auth_generate_nonce(device, handle, options, i_nonce): + cbuf = create_string_buffer(16) + cbuf[0:] = i_nonce[0:16] + status = get_cryptoauthlib().talib_auth_generate_nonce(device, handle, options, cbuf) + i_nonce[0:] = cbuf[:len(cbuf)] + return status + + +def talib_auth_startup(device, handle, alg_id, max_cmd, key_len, key, i_nonce, r_nonce): + status = get_cryptoauthlib().talib_auth_startup(device, handle, alg_id, max_cmd, key_len, key, + create_byte_buffer(i_nonce), create_byte_buffer(r_nonce)) + return status + + +def talib_auth_terminate(device): + return get_cryptoauthlib().talib_auth_terminate(device) + +# Make module import * safe - keep at the end of the file +__all__ = ['ta_element_attributes_t'] +__all__ += [x for x in dir() if x.startswith(__name__.split('.')[-1])] diff --git a/python/setup.py b/python/setup.py index b3d550f92..d6857f6f1 100644 --- a/python/setup.py +++ b/python/setup.py @@ -41,7 +41,7 @@ } # Include the compiled library in the resulting distribution -_PACKAGE_DATA = {} +_PACKAGE_DATA = {'cryptoauth_signatures': ['cryptoauth.json']} if sys.platform == 'win32': _PACKAGE_DATA['libcryptoauth'] = ['cryptoauth.dll'] #elif sys.platform is 'darwin': @@ -145,9 +145,10 @@ def build_extension(self, ext): build_args = [] cmake_args = ['-DATCA_HAL_CUSTOM=ON', '-DATCA_TNGTLS_SUPPORT=ON', + '-DATCA_ATSHA206A_SUPPORT=ON', '-DATCA_TNGLORA_SUPPORT=ON', '-DATCA_TFLEX_SUPPORT=ON', '-DATCA_TNG_LEGACY_SUPPORT=ON', '-DATCA_USE_ATCAB_FUNCTIONS=ON'] - + if os.path.exists('../lib/talib' if not _sdist_build else 'lib/talib'): cmake_args += ['-DATCA_TA100_SUPPORT=ON'] if sys.platform.startswith('linux'): @@ -164,8 +165,7 @@ def build_extension(self, ext): if cmake_gen is not None: cmake_args += ['-G', cmake_gen] elif sys.maxsize > 2**32: - cmake_args += ['-A', 'x64'] - + cmake_args += ['-A', 'x64'] else: cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir] diff --git a/python/tests/test_jwt.py b/python/tests/test_jwt.py index c02da6b92..01a9ede5d 100644 --- a/python/tests/test_jwt.py +++ b/python/tests/test_jwt.py @@ -118,7 +118,7 @@ def test_jwt_round_trip_hmac_qa(test_jwt_init_live, slot, config): # A Dummy/Test Audience to verify against 'aud': 'test_audience' } - + token = PyJWT(slot, config) encoded = token.encode(claims, b'', algorithm='HS256') diff --git a/release_notes.md b/release_notes.md index 44a44f6ca..3a402dfc1 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,6 +1,32 @@ # Microchip Cryptoauthlib Release Notes +## Release v3.3.2 (06/20/2021) + + +### New features + - All memory allocations now go through the hal_ platform definitions. + In harmony these are the OSAL_ fuctions which work with any of the supported + RTOS'. + - Enable multiple intefaces in the Harmony 3 test project through the + user interface. + - Kit protocol over UART has been added. This can be paired with the + included hosting application + - Simple kit protocol hosting application has been added. It is available + in app/kit_host and through Harmony 3. This is a preview release of the + application. + +### Fixes + - Enable ATSHA206A api in the python extension + - Made the linux i2c configuration default to 100khz so they should work + again without having to make modifications to the baud rate field. + - Fix pkcs11 static configuration option when used with the trust platform + configuration file + - Fix PKCS11 ec_point return value when pValue is null (libp11 checks the + size in this manner before requesting it for real). + - Fix warnings generated by missing end of file newlines. + - Removed legacy (empty) START header references. + ## Release v3.3.1 (04/23/2021) ### New features diff --git a/test/api_atcab/atca_tests_hmac.c b/test/api_atcab/atca_tests_hmac.c index eb9553a82..31faf5801 100644 --- a/test/api_atcab/atca_tests_hmac.c +++ b/test/api_atcab/atca_tests_hmac.c @@ -120,4 +120,4 @@ t_test_case_info hmac_basic_test_info[] = { { (fp_test_case)NULL, (uint8_t)0 }, }; -#endif \ No newline at end of file +#endif diff --git a/test/atca_crypto_sw_tests.c b/test/atca_crypto_sw_tests.c index 8bbc4154d..c06456bc9 100644 --- a/test/atca_crypto_sw_tests.c +++ b/test/atca_crypto_sw_tests.c @@ -208,9 +208,9 @@ static int read_rsp_hex_value(FILE* file, const char* name, uint8_t* data, size_ else { size_t ln = strlen(line); - if (ln > 0 && line[ln-2] == '\r') + if (ln > 0 && line[ln - 2] == '\r') { - line[ln-1] = 0; + line[ln - 1] = 0; } } @@ -249,9 +249,9 @@ static int read_rsp_int_value(FILE* file, const char* name, int* value) else { size_t ln = strlen(line); - if (ln > 0 && line[ln-2] == '\r') + if (ln > 0 && line[ln - 2] == '\r') { - line[ln-1] = 0; + line[ln - 1] = 0; } } @@ -301,7 +301,7 @@ static void test_atcac_sw_sha1_nist_simple(const char* filename) continue; } - msg = malloc(len_bits == 0 ? 1 : len_bits / 8); + msg = hal_malloc(len_bits == 0 ? 1 : len_bits / 8); TEST_ASSERT_NOT_NULL_MESSAGE(msg, "malloc failed"); ret = read_rsp_hex_value(rsp_file, "Msg = ", msg, len_bits == 0 ? 1 : len_bits / 8); @@ -314,7 +314,7 @@ static void test_atcac_sw_sha1_nist_simple(const char* filename) TEST_ASSERT_EQUAL(ret, ATCA_SUCCESS); TEST_ASSERT_EQUAL_MEMORY(md_ref, md, sizeof(md_ref)); - free(msg); + hal_free(msg); msg = NULL; count++; } @@ -457,7 +457,7 @@ static void test_atcac_sw_sha2_256_nist_simple(const char* filename) continue; } - msg = malloc(len_bits == 0 ? 1 : len_bits / 8); + msg = hal_malloc(len_bits == 0 ? 1 : len_bits / 8); TEST_ASSERT_NOT_NULL_MESSAGE(msg, "malloc failed"); ret = read_rsp_hex_value(rsp_file, "Msg = ", msg, len_bits == 0 ? 1 : len_bits / 8); @@ -470,7 +470,7 @@ static void test_atcac_sw_sha2_256_nist_simple(const char* filename) TEST_ASSERT_EQUAL(ret, ATCA_SUCCESS); TEST_ASSERT_EQUAL_MEMORY(md_ref, md, sizeof(md_ref)); - free(msg); + hal_free(msg); msg = NULL; count++; } @@ -491,7 +491,7 @@ void test_atcac_sw_sha2_256_nist_long(void) void test_atcac_sw_sha2_256_nist_monte(void) { -#if !defined(_WIN32) && !defined(__linux__) +#if !defined(_WIN32) && !defined(__linux__) TEST_IGNORE_MESSAGE("Test is not available for this platform."); #else FILE* rsp_file = NULL; @@ -704,7 +704,7 @@ void test_atcac_aes128_cmac(void) void test_atcac_sha256_hmac(void) { ATCA_STATUS status = ATCA_GEN_FAIL; - uint8_t hmac[ATCA_SHA_DIGEST_SIZE]; + uint8_t hmac[ATCA_SHA256_DIGEST_SIZE]; size_t hmac_size; uint8_t data_input[] = { 0x6f, 0xb3, 0xec, 0x66, 0xf9, 0xeb, 0x07, 0x0a, @@ -717,7 +717,7 @@ void test_atcac_sha256_hmac(void) 0x03, 0xd7, 0x60, 0xe8, 0x57, 0xa6, 0xd6, 0x21, 0x1c }; - const uint8_t hmac_ref[ATCA_SHA_DIGEST_SIZE] = { + const uint8_t hmac_ref[ATCA_SHA256_DIGEST_SIZE] = { 0x29, 0x7f, 0x22, 0xb8, 0xd2, 0x51, 0xb0, 0x63, 0xa7, 0xc0, 0x8d, 0xcf, 0x4d, 0xba, 0x0d, 0x1f, 0xb3, 0x5d, 0x32, 0xa3, 0xba, 0xab, 0x15, 0xac, @@ -742,12 +742,12 @@ void test_atcac_sha256_hmac(void) status = atcac_sha256_hmac_finish(&ctx, hmac, &hmac_size); TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); - TEST_ASSERT_EQUAL_MEMORY(hmac_ref, hmac, ATCA_SHA_DIGEST_SIZE); + TEST_ASSERT_EQUAL_MEMORY(hmac_ref, hmac, ATCA_SHA256_DIGEST_SIZE); } void test_atcac_sha256_hmac_nist(void) { -#if !defined(_WIN32) && !defined(__linux__) +#if !defined(_WIN32) && !defined(__linux__) TEST_IGNORE_MESSAGE("Test is not available for this platform."); #else FILE* rsp_file = NULL; diff --git a/test/atca_crypto_sw_tests.h b/test/atca_crypto_sw_tests.h index 603489051..f544257b7 100644 --- a/test/atca_crypto_sw_tests.h +++ b/test/atca_crypto_sw_tests.h @@ -56,4 +56,4 @@ void test_atcac_sign(void); void test_atcac_derive_nist(void); -#endif \ No newline at end of file +#endif diff --git a/test/atca_test.c b/test/atca_test.c index 83b070c5e..1fd38050c 100644 --- a/test/atca_test.c +++ b/test/atca_test.c @@ -436,4 +436,3 @@ TEST_TEAR_DOWN(atca_cmd_basic_test) UnityMalloc_EndTest(); } - diff --git a/test/atca_test_config.c b/test/atca_test_config.c index 0b0f10293..0933dc1e2 100644 --- a/test/atca_test_config.c +++ b/test/atca_test_config.c @@ -28,6 +28,11 @@ #include "atca_test.h" #include "cryptoauthlib.h" +#ifdef ATCA_TEST_MULTIPLE_INSTANCES +#include "atca_devcfg_list.h" +void select_dev_cfg_data(); +#endif + #ifdef ATCA_HAL_CUSTOM extern int select_204_custom(int argc, char* argv[]); extern int select_108_custom(int argc, char* argv[]); @@ -203,6 +208,10 @@ static int opt_device_type(int argc, char* argv[]) return ret; } +#ifndef _WIN32 +static char opt_device_name[20]; +#endif + /** \brief Sets the interface the command or test suite will use * * \param[in] argc Number of arguments in the arg list @@ -311,10 +320,118 @@ static int opt_iface_type(int argc, char* argv[]) gCfg->atcaspi.baud = 200000; } } + else if (0 == strcmp("uart", argv[1])) + { + gCfg->iface_type = ATCA_UART_IFACE; + gCfg->atcauart.dev_interface = ATCA_KIT_AUTO_IFACE; + gCfg->atcauart.dev_identity = 0; + + if (argc >= 3 && argv[2][0] != '-') + { + /* Port/Device */ +#ifdef _WIN32 + gCfg->atcauart.port = (uint8_t)strtol(argv[2], NULL, 10); +#else + size_t len = strlen(argv[2]); + if (len < sizeof(opt_device_name)) + { + memcpy(opt_device_name, argv[2], len); + gCfg->cfg_data = opt_device_name; + } +#endif + ret = 3; + } + + if (argc >= 4 && argv[3][0] != '-') + { + /* Baud rate */ + gCfg->atcauart.baud = (uint8_t)strtol(argv[3], NULL, 10); + ret++; + } + else + { + gCfg->atcauart.baud = 115200UL; + } + + if (argc >= 5 && argv[4][0] != '-') + { + /* Word size */ + gCfg->atcauart.wordsize = (uint8_t)strtol(argv[4], NULL, 10); + ret++; + } + else + { + gCfg->atcauart.wordsize = 8; + } + + if (argc >= 6 && argv[5][0] != '-') + { + /* Stop Bits */ + gCfg->atcauart.stopbits = (uint8_t)strtol(argv[5], NULL, 10); + ret++; + } + else + { + gCfg->atcauart.stopbits = 1; + } + + if (argc >= 7 && argv[6][0] != '-') + { + /* Parity Bits */ + //gCfg->atcauart.parity = (uint8_t)strtol(argv[6], NULL, 16); + ret++; + } + else + { + gCfg->atcauart.parity = 2; + } + } } + +#ifdef ATCA_TEST_MULTIPLE_INSTANCES + select_dev_cfg_data(); +#endif return ret; } +#ifdef ATCA_TEST_MULTIPLE_INSTANCES +void select_dev_cfg_data() +{ + size_t num_of_elements; + int i; + + num_of_elements = sizeof(devcfg_list) / sizeof(devcfg_list[0]); + for (i = 0; i < num_of_elements; i++) + { + if ((gCfg->iface_type == ATCA_I2C_IFACE) && (devcfg_list[i]->iface_type == ATCA_I2C_IFACE)) + { +#ifdef ATCA_ENABLE_DEPRECATED + if (gCfg->atcai2c.slave_address == devcfg_list[i]->atcai2c.slave_address) +#else + if (gCfg->atcai2c.address == devcfg_list[i]->atcai2c.address) +#endif + { + gCfg->cfg_data = devcfg_list[i]->cfg_data; + } + } + else if ((gCfg->iface_type == ATCA_SPI_IFACE) && (devcfg_list[i]->iface_type == ATCA_SPI_IFACE)) + { + if (gCfg->atcaspi.select_pin == devcfg_list[i]->atcaspi.select_pin) + { + gCfg->cfg_data = devcfg_list[i]->cfg_data; + } + } + else if ((gCfg->iface_type == ATCA_SWI_IFACE) && (devcfg_list[i]->iface_type == ATCA_SWI_IFACE)) + { + if (gCfg->atcaswi.bus == devcfg_list[i]->atcaswi.bus) + { + gCfg->cfg_data = devcfg_list[i]->cfg_data; + } + } + } +} +#endif + /** \brief Sets the device address based on interface type (this option must be provided after * specifying the interface type otherwise it might produce unexpected results). * @@ -325,25 +442,71 @@ static int opt_iface_type(int argc, char* argv[]) static int opt_address(int argc, char* argv[]) { int ret = 0; + ATCAKitType kit_type = ATCA_KIT_AUTO_IFACE; if (argc >= 2) { uint32_t val = strtol(argv[1], NULL, 16); - if (ATCA_HID_IFACE == gCfg->iface_type) + + if (argc >= 3 && argv[2][0] != '-') { - gCfg->atcahid.dev_identity = (uint8_t)val; + if (0 == strcmp("i2c", argv[2])) + { + kit_type = ATCA_KIT_I2C_IFACE; + } + else if (0 == strcmp("swi", argv[2])) + { + kit_type = ATCA_KIT_SWI_IFACE; + } + else if (0 == strcmp("spi", argv[2])) + { + kit_type = ATCA_KIT_SPI_IFACE; + } + ret = 3; } - else if (ATCA_I2C_IFACE == gCfg->iface_type) + else + { + ret = 2; + } + + switch (gCfg->iface_type) { + case ATCA_I2C_IFACE: #ifdef ATCA_ENABLE_DEPRECATED gCfg->atcai2c.slave_address = (uint8_t)val; #else gCfg->atcai2c.address = (uint8_t)val; #endif + break; + case ATCA_SWI_IFACE: + gCfg->atcaswi.address = (uint8_t)val; + break; + case ATCA_UART_IFACE: + gCfg->atcauart.dev_identity = (uint8_t)val; + if (argc >= 3) + { + gCfg->atcauart.dev_interface = kit_type; + } + break; + case ATCA_SPI_IFACE: + gCfg->atcaspi.select_pin = (uint8_t)val; + break; + case ATCA_HID_IFACE: + gCfg->atcahid.dev_identity = (uint8_t)val; + if (argc >= 3) + { + gCfg->atcahid.dev_interface = kit_type; + } + break; + default: + break; } - - ret = 2; } + +#ifdef ATCA_TEST_MULTIPLE_INSTANCES + select_dev_cfg_data(); +#endif + return ret; } diff --git a/test/atcacert/all_atcacert_tests.c b/test/atcacert/all_atcacert_tests.c index 479414086..087a9d3f7 100644 --- a/test/atcacert/all_atcacert_tests.c +++ b/test/atcacert/all_atcacert_tests.c @@ -96,5 +96,5 @@ void RunAllCertIOTests(void) RUN_TEST_GROUP(atcacert_client); RUN_TEST_GROUP(atcacert_host_hw); } - + #endif diff --git a/test/cmd-processor.c b/test/cmd-processor.c index c782636ce..837361d22 100644 --- a/test/cmd-processor.c +++ b/test/cmd-processor.c @@ -113,6 +113,8 @@ static t_menu_info mas_menu_info[] = { "handles", "Print info for stored handles in TA100 device", talib_config_print_handles }, { "clear", "Delete Handles", talib_config_clear_handles }, { "talib", "Run talib tests", run_talib_tests }, + { "fce", "Run FCE test", talib_fce_cmd }, + { "power", "Change device power state", talib_power_cmd }, #endif #if defined(_WIN32) || defined(__linux__) || defined(__APPLE__) { "exit", "Exit the test application", call_exit }, diff --git a/test/cmd-processor.h b/test/cmd-processor.h index 9f5752283..5367e4e16 100644 --- a/test/cmd-processor.h +++ b/test/cmd-processor.h @@ -45,4 +45,4 @@ volatile struct uint8_t m_entry[ cmdQ_SIZE ]; } cmdQ; -#endif /* CMD-PROCESSOR_H_ */ \ No newline at end of file +#endif /* CMD-PROCESSOR_H_ */ diff --git a/third_party/atca_mbedtls_patch.c b/third_party/atca_mbedtls_patch.c new file mode 100644 index 000000000..bc6de7a58 --- /dev/null +++ b/third_party/atca_mbedtls_patch.c @@ -0,0 +1,63 @@ +/* + * Resources copied from mbedtls internals - Some of these may be version + * dependent as mbedtls exposes more internals + * + * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of mbed TLS (https://tls.mbed.org) + */ + +/* mbedTLS boilerplate includes */ + +#include "cryptoauthlib.h" + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#ifdef MBEDTLS_ECDSA_C + +#include "mbedtls/asn1.h" +#include "mbedtls/asn1write.h" +#include "mbedtls/ecdsa.h" + + /* + * Convert a signature (given by context) to ASN.1 + */ +int mbedtls_ecdsa_signature_to_asn1(const mbedtls_mpi* r, const mbedtls_mpi* s, + unsigned char* sig, size_t* slen) +{ + int ret; + unsigned char buf[MBEDTLS_ECDSA_MAX_LEN]; + unsigned char* p = buf + sizeof(buf); + size_t len = 0; + + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_mpi(&p, buf, s)); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_mpi(&p, buf, r)); + + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&p, buf, len)); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&p, buf, + MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)); + + memcpy(sig, p, len); + *slen = len; + + return(0); +} +#endif + diff --git a/third_party/atca_mbedtls_patch.h b/third_party/atca_mbedtls_patch.h new file mode 100644 index 000000000..5cd36c5c0 --- /dev/null +++ b/third_party/atca_mbedtls_patch.h @@ -0,0 +1,30 @@ +/* + * Resources copied from mbedtls internals + * + * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of mbed TLS (https://tls.mbed.org) + */ + +#ifndef ATCA_MBEDTLS_PATCH_H +#define ATCA_MBEDTLS_PATCH_H + +#ifdef MBEDTLS_ECDSA_C +int mbedtls_ecdsa_signature_to_asn1(const mbedtls_mpi* r, const mbedtls_mpi* s, unsigned char* sig, size_t* slen); +#endif + + +#endif