Skip to content

Commit

Permalink
Release 20190830 with support for new kits and big endian architectures
Browse files Browse the repository at this point in the history
  • Loading branch information
bryan-hunt committed Aug 30, 2019
1 parent 90591bb commit 7b39ad2
Show file tree
Hide file tree
Showing 34 changed files with 1,448 additions and 243 deletions.
27 changes: 27 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 2.6.4)
project (cryptoauthlib)

# Set the current release version
set(VERSION "2018.10.26")
set(VERSION_MAJOR 2028)
set(VERSION_MINOR 10)
set(VERSION_PATCH 26)

# Build Options
option(BUILD_TESTS "Create Test Application with library" OFF)
#set(ATCA_PKCS11 ON CACHE INTERNAL "")

message(STATUS "Building Configuration: ${CMAKE_BUILD_TYPE}")


if(BUILD_TESTS)
set(ATCA_BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
endif(BUILD_TESTS)

add_subdirectory(lib)

# Tests
if(BUILD_TESTS)
add_subdirectory(test)
endif(BUILD_TESTS)

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Examples

Release notes
-----------
Next Release
- Added big-endian architecture support
- Fixes to atcah_gen_dig() and atcah_nonce()

05/17/2019
- Added support for TNG devices (cert transforms, new API)
- atcab_write_pub_key() now works when the data zone is unlocked
Expand Down
8 changes: 2 additions & 6 deletions app/secure_boot/secure_boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@
* THIS SOFTWARE.
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "secure_boot.h"
#include "atca_iface.h"
#include "hal/atca_hal.h"
#include "test/atca_test.h"
#include "io_protection_key.h"
#include "crypto_device_app.h"
#include "basic/atca_basic.h"

/*Initialization routines */
static ATCA_STATUS secure_boot_init(secure_boot_parameters* secure_boot_params);
Expand Down
4 changes: 1 addition & 3 deletions app/secure_boot/secure_boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ extern "C" {
#include "atca_status.h"
#include "secure_boot_memory.h"
#include "atca_command.h"
#include "crypto\atca_crypto_sw_sha2.h"
#include "host/atca_host.h"

#include "crypto/atca_crypto_sw_sha2.h"

#define SECURE_BOOT_CONFIG_DISABLE 0
#define SECURE_BOOT_CONFIG_FULL_BOTH 1
Expand Down
2 changes: 2 additions & 0 deletions app/tng/tng_root_cert.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#ifndef TNG_ROOT_CERT_H
#define TNG_ROOT_CERT_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
59 changes: 46 additions & 13 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ project(cryptoauth)

# Various Options for Build
option(ATCA_HAL_KIT_HID "Include the HID HAL Driver")
option(ATCA_HAL_KIT_CDC "Include the CDC HAL Driver (Legacy)" OFF)
option(ATCA_HAL_I2C "Include the I2C Hal Driver - Linux & MCU only")
option(ATCA_HAL_CUSTOM "Include support for Custom/Plug-in Hal Driver")
option(ATCA_PRINTF "Enable Debug print statements in library")
Expand All @@ -25,9 +26,14 @@ file(GLOB TNG_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "../app/tng/*.c")
# Add the basic sources to the library
set(CRYPTOAUTH_SRC ${LIB_SRC} ${ATCACERT_SRC} ${BASIC_SRC} ${CRYPTO_SRC} ${HOST_SRC} ${JWT_SRC} hal/atca_hal.c ${TNG_SRC})

if(ATCA_HAL_KIT_HID OR ATCA_HAL_KIT_CDC)
set(NEED_USB true)
endif()

if(WIN32)
set(CRYPTOAUTH_SRC ${CRYPTOAUTH_SRC} hal/hal_win_timer.c)
set(HID_SRC ../third_party/hidapi/windows/hid.c)
set(CDC_SRC hal/hal_win_kit_cdc.c)
elseif(APPLE)
set(CRYPTOAUTH_SRC ${CRYPTOAUTH_SRC} hal/hal_linux_timer.c)
set(HID_SRC ../third_party/hidapi/mac/hid.c)
Expand All @@ -37,28 +43,55 @@ set(TWI_SRC hal/hal_linux_i2c_userspace.c)
set(LINUX TRUE)
endif()

if(LINUX AND ATCA_HAL_KIT_HID)
if(LINUX AND NEED_USB)
find_path(LIBUSB_INCLUDE_DIR NAMES libusb.h PATH_SUFFIXES "include" "libusb" "libusb-1.0")
find_path(LIBUDEV_INCLUDE_DIR NAMES libudev.h PATH_SUFFIXES "include")
find_library(HAS_LIBUSB usb-1.0)
find_library(HAS_LIBUDEV udev)

if(HAS_LIBUSB AND LIBUSB_INCLUDE_DIR)
set(HID_SRC ../third_party/hidapi/libusb/hid.c)
elseif(HAS_LIBUDEV AND LIBUDEV_INCLUDE_DIR)
set(LIBUSB_INCLUDE_DIR ${LIBUDEV_INCLUDE_DIR})
set(HID_SRC ../third_party/hidapi/linux/hid.c)
else()
message(FATAL_ERROR, "Missing Build Dependencies for ATCA_HAL_KIT_HID - install libusb-1.0-0-dev or libudev-dev")
set(LIBUSB_GOOD TRUE)
endif()

if(HAS_LIBUDEV AND LIBUDEV_INCLUDE_DIR)
set(LIBUDEV_GOOD TRUE)
endif()

if(ATCA_HAL_KIT_CDC AND LIBUDEV_GOOD)
set(USE_UDEV TRUE)
elseif(LIBUSB_GOOD AND NOT ATCA_HAL_KIT_CDC)
set(USE_LIBUSB TRUE)
else()
set(LIBUSD_INCLUDE_DIR "")
message(FATAL_ERROR, "Missing Build Dependencies for USB - install libusb-1.0-0-dev or libudev-dev")
endif()

endif(LINUX AND NEED_USB)

if(USE_UDEV)
set(USB_INCLUDE_DIR ${LIBUDEV_INCLUDE_DIR})
set(HID_SRC ../third_party/hidapi/linux/hid.c)
set(CDC_SRC hal/hal_linux_kit_cdc.c)
endif(USE_UDEV)

if(USE_LIBUSB)
set(USB_INCLUDE_DIR ${LIBUSB_INCLUDE_DIR})
set(HID_SRC ../third_party/hidapi/libusb/hid.c)
endif(USE_LIBUSB)

if(NEED_USB)
set(CRYPTOAUTH_SRC ${CRYPTOAUTH_SRC} hal/kit_protocol.c)
endif()

if(ATCA_HAL_KIT_HID)
add_definitions(-DATCA_HAL_KIT_HID)
set(CRYPTOAUTH_SRC ${CRYPTOAUTH_SRC} hal/kit_protocol.c hal/hal_all_platforms_kit_hidapi.c ${HID_SRC})
set(CRYPTOAUTH_SRC ${CRYPTOAUTH_SRC} ${HID_SRC} hal/hal_all_platforms_kit_hidapi.c)
endif(ATCA_HAL_KIT_HID)

if(ATCA_HAL_KIT_CDC)
add_definitions(-DATCA_HAL_KIT_CDC)
set(CRYPTOAUTH_SRC ${CRYPTOAUTH_SRC} ${CDC_SRC})
endif(ATCA_HAL_KIT_CDC)

if(ATCA_HAL_I2C)
add_definitions(-DATCA_HAL_I2C)
set(CRYPTOAUTH_SRC ${CRYPTOAUTH_SRC} ${TWI_SRC})
Expand Down Expand Up @@ -90,7 +123,7 @@ if(ATCA_PRINTF)
add_definitions(-DATCAPRINTF)
endif(ATCA_PRINTF)

include_directories(cryptoauth PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ../third_party/hidapi/hidapi ${LIBUSB_INCLUDE_DIR})
include_directories(cryptoauth PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ../third_party/hidapi/hidapi ${USB_INCLUDE_DIR})

if(WIN32)
set_target_properties(cryptoauth PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS true)
Expand All @@ -104,11 +137,11 @@ target_link_libraries(cryptoauth ${IO_KIT_LIB} ${CORE_LIB})
endif()

if(LINUX)
if(HAS_LIBUSB AND ATCA_HAL_KIT_HID)
if(USE_LIBUSB)
target_link_libraries(cryptoauth usb-1.0)
elseif(HAS_LIBUDEV AND ATCA_HAL_KIT_HID)
elseif(USE_UDEV)
target_link_libraries(cryptoauth udev)
endif()
target_link_libraries(cryptoauth rt)
endif()
endif(LINUX)

127 changes: 72 additions & 55 deletions lib/atca_cfgs.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,89 +38,106 @@

/** \brief default configuration for an ECCx08A device */
ATCAIfaceCfg cfg_ateccx08a_i2c_default = {
.iface_type = ATCA_I2C_IFACE,
.devtype = ATECC508A,
.atcai2c.slave_address = 0xC0,
.atcai2c.bus = 2,
.atcai2c.baud = 400000,
//.atcai2c.baud = 100000,
.wake_delay = 1500,
.rx_retries = 20
.iface_type = ATCA_I2C_IFACE,
.devtype = ATECC608A,
{
.atcai2c.slave_address = 0xC0,
.atcai2c.bus = 2,
.atcai2c.baud = 400000,
//.atcai2c.baud = 100000,
},
.wake_delay = 1500,
.rx_retries = 20
};

/** \brief default configuration for an ECCx08A device on the logical SWI bus over UART*/
ATCAIfaceCfg cfg_ateccx08a_swi_default = {
.iface_type = ATCA_SWI_IFACE,
.devtype = ATECC508A,
.atcaswi.bus = 4,
.wake_delay = 1500,
.rx_retries = 10
.iface_type = ATCA_SWI_IFACE,
.devtype = ATECC608A,
{
.atcaswi.bus = 4,
},
.wake_delay = 1500,
.rx_retries = 10
};

/** \brief default configuration for Kit protocol over the device's async interface */
ATCAIfaceCfg cfg_ateccx08a_kitcdc_default = {
.iface_type = ATCA_UART_IFACE,
.devtype = ATECC508A,
.atcauart.port = 0,
.atcauart.baud = 115200,
.atcauart.wordsize = 8,
.atcauart.parity = 2,
.atcauart.stopbits = 1,
.rx_retries = 1,
.iface_type = ATCA_UART_IFACE,
.devtype = ATECC608A,
{
.atcauart.port = 0,
.atcauart.baud = 115200,
.atcauart.wordsize = 8,
.atcauart.parity = 2,
.atcauart.stopbits = 1,
},
.rx_retries = 1,
};

/** \brief default configuration for Kit protocol over the device's async interface */
ATCAIfaceCfg cfg_ateccx08a_kithid_default = {
.iface_type = ATCA_HID_IFACE,
.devtype = ATECC508A,
.atcahid.idx = 0,
.atcahid.vid = 0x03EB,
.atcahid.pid = 0x2312,
.atcahid.packetsize = 64,
.atcahid.guid = { 0x4d, 0x1e, 0x55, 0xb2, 0xf1, 0x6f, 0x11, 0xcf, 0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 },
.iface_type = ATCA_HID_IFACE,
.devtype = ATECC608A,
{
.atcahid.dev_interface = ATCA_KIT_AUTO_IFACE,
.atcahid.dev_identity = 0,
.atcahid.idx = 0,
.atcahid.vid = 0x03EB,
.atcahid.pid = 0x2312,
.atcahid.packetsize = 64,
}
};


/** \brief default configuration for a SHA204A device on the first logical I2C bus */
ATCAIfaceCfg cfg_atsha204a_i2c_default = {
.iface_type = ATCA_I2C_IFACE,
.devtype = ATSHA204A,
.atcai2c.slave_address = 0xC8,
.atcai2c.bus = 2,
.atcai2c.baud = 400000,
.wake_delay = 2560,
.rx_retries = 20
.iface_type = ATCA_I2C_IFACE,
.devtype = ATSHA204A,
{
.atcai2c.slave_address = 0xC8,
.atcai2c.bus = 2,
.atcai2c.baud = 400000,
},
.wake_delay = 2560,
.rx_retries = 20
};

/** \brief default configuration for an SHA204A device on the logical SWI bus over UART*/
ATCAIfaceCfg cfg_atsha204a_swi_default = {
.iface_type = ATCA_SWI_IFACE,
.devtype = ATSHA204A,
.atcaswi.bus = 4,
.wake_delay = 2560,
.rx_retries = 10
.iface_type = ATCA_SWI_IFACE,
.devtype = ATSHA204A,
{
.atcaswi.bus = 4,
},
.wake_delay = 2560,
.rx_retries = 10
};

/** \brief default configuration for Kit protocol over the device's async interface */
ATCAIfaceCfg cfg_atsha204a_kitcdc_default = {
.iface_type = ATCA_UART_IFACE,
.devtype = ATSHA204A,
.atcauart.port = 0,
.atcauart.baud = 115200,
.atcauart.wordsize = 8,
.atcauart.parity = 2,
.atcauart.stopbits = 1,
.rx_retries = 1,
.iface_type = ATCA_UART_IFACE,
.devtype = ATSHA204A,
{
.atcauart.port = 0,
.atcauart.baud = 115200,
.atcauart.wordsize = 8,
.atcauart.parity = 2,
.atcauart.stopbits = 1,
},
.rx_retries = 1,
};

/** \brief default configuration for Kit protocol over the device's async interface */
ATCAIfaceCfg cfg_atsha204a_kithid_default = {
.iface_type = ATCA_HID_IFACE,
.devtype = ATSHA204A,
.atcahid.idx = 0,
.atcahid.vid = 0x03EB,
.atcahid.pid = 0x2312,
.atcahid.packetsize = 64,
.atcahid.guid = { 0x4d, 0x1e, 0x55, 0xb2, 0xf1, 0x6f, 0x11, 0xcf, 0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 },
.iface_type = ATCA_HID_IFACE,
.devtype = ATSHA204A,
.atcahid.dev_interface = ATCA_KIT_AUTO_IFACE,
.atcahid.dev_identity = 0,
.atcahid.idx = 0,
.atcahid.vid = 0x03EB,
.atcahid.pid = 0x2312,
.atcahid.packetsize = 64,
};

/** @} */
2 changes: 2 additions & 0 deletions lib/atca_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,8 @@ void atCalcCrc(ATCAPacket *packet)
{
uint8_t length, *crc;

packet->param2 = ATCA_UINT16_HOST_TO_LE(packet->param2);

length = packet->txsize - ATCA_CRC_SIZE;
// computer pointer to CRC in the packet
crc = &(packet->txsize) + length;
Expand Down
11 changes: 9 additions & 2 deletions lib/atca_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,16 @@ void deleteATCACommand(ATCACommand *ca_cmd);
// Note: pack @ 2 is required, @ 1 causes word alignment crash (though it should not), a known bug in GCC.
// @2, the wire still has the intended byte alignment with arm-eabi. this is likely the least portable part of atca

#pragma pack( push, ATCAPacket, 2 )

#ifdef ATCA_NO_PRAGMA_PACK
typedef struct __attribute__ ((packed))
#else
#pragma pack( push, ATCAPacket, 2 )
typedef struct
#endif
/** \brief an ATCA packet structure. This is a superset of the packet transmitted on the wire. It's also
* used as a buffer for receiving the response
*/
typedef struct
{

// used for transmit/send
Expand All @@ -115,7 +119,9 @@ typedef struct

} ATCAPacket;

#ifndef ATCA_NO_PRAGMA_PACK
#pragma pack( pop, ATCAPacket)
#endif


ATCA_STATUS atCheckMAC(ATCACommand ca_cmd, ATCAPacket *packet);
Expand Down Expand Up @@ -340,6 +346,7 @@ ATCA_STATUS atCheckCrc(const uint8_t *response);
#define COUNTER_MODE_READ ((uint8_t)0x00) //!< Counter command mode for reading
#define COUNTER_MODE_INCREMENT ((uint8_t)0x01) //!< Counter command mode for incrementing
#define COUNTER_RSP_SIZE ATCA_RSP_SIZE_4 //!< Counter command response packet size
#define COUNTER_SIZE ATCA_RSP_SIZE_MIN //!< Counter size in binary
/** @} */

/** \name Definitions for the DeriveKey Command
Expand Down
Loading

0 comments on commit 7b39ad2

Please sign in to comment.