Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Initial release

See merge request internal/sw-design/libtropic!36
  • Loading branch information
Pavel Polach committed Oct 1, 2024
2 parents 388a8de + b0f8501 commit f375016
Show file tree
Hide file tree
Showing 121 changed files with 9,225 additions and 8,477 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#name: Build documentation
#on:
# push:
# branches:
# - 'master'
# - 'develop'
#
#jobs:
# build:
# runs-on: ubuntu-22.04
#
# steps:
# - name: Checkout Repository
# uses: actions/[email protected]
#
# - name: Build Docs
# uses: mattnotmitt/[email protected]
# with:
# doxyfile-path: 'docs/Doxyfile.in'
# enable-latex: false


name: Build documentation
on:
push:
branches:
- 'master'
- 'develop'

jobs:
build:
runs-on: ubuntu-22.04

steps:
- name: Checkout Repository
uses: actions/[email protected]

- uses: ssciwr/doxygen-install@v1
# with:
# version: "1.12.0"

- name: Build docs
uses: threeal/[email protected]
with:
source-dir: ./
build-dir: build
options: |
BUILD_DOCS=ON
USE_TREZOR_CRYPTO=ON
- name: Create html release
uses: svenstaro/upload-release-action@latest
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: build/docs/doxygen/html/
release_name: HTML Documentation
make_latest: true
overwrite: true
file_glob: true
20 changes: 20 additions & 0 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Integration test
on:
push:
branches:
- 'master'
- 'develop'

jobs:
build:
runs-on: ubuntu-22.04

steps:
- name: Checkout Repository
uses: actions/[email protected]

- name: Build Integration tests
uses: threeal/[email protected]
with:
source-dir: tests/integration/
build-dir: tests/integration/build
20 changes: 0 additions & 20 deletions .github/workflows/main.yml

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Unit tests and coverage
on:
push:
branches:
- 'master'
- 'develop'

jobs:
build:
runs-on: ubuntu-22.04

steps:
- name: Checkout Repository
uses: actions/[email protected]

- name: Run Ceedling Unit Tests
uses: pavelpolach321/[email protected]
with:
unit-test-path: '${{ github.workspace }}/'
25 changes: 19 additions & 6 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
stages:
- test
- build
- build_lib
- build_integration
- docs

run_ceedling_tests:
Expand Down Expand Up @@ -29,28 +30,40 @@ run_ceedling_tests:


build_library:
stage: build
stage: build_lib
tags:
- shell
script:
- source setup_env
- cd examples/unix_example
- rm -rf build/
- mkdir build
- cd build
- cmake ..
- cmake -DUSE_TREZOR_CRYPTO=1 ..
- make

build_integration_tests:
stage: build_integration
tags:
- shell
script:
- source setup_env
- cd tests/integration/
- mkdir build
- cd build
- cmake -DUSE_TREZOR_CRYPTO=1 ..
- make

build_docs:
stage: docs
tags:
- shell
script:
- source setup_env
- ls -la
- rm -rf build/
- mkdir build
- cd build
- cmake -DBUILD_DOCS=1 ..
- make
- make doc_doxygen
- cd docs/doxygen/latex
- make
- mv refman.pdf libtropic.pdf
Expand Down
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "vendor/STM32CubeF4"]
path = vendor/STM32CubeF4
[submodule "stm32_example/drivers/STM32CubeF4"]
path = stm32_example/drivers/STM32CubeF4
url = https://github.com/STMicroelectronics/STM32CubeF4
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
155 changes: 72 additions & 83 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,120 +1,109 @@
cmake_minimum_required(VERSION 3.21.0)


project(libtropic_SDK
VERSION 0.0.1
DESCRIPTION "Tropic Square software development kit"
HOMEPAGE_URL "www.tropicsquare.com"
LANGUAGES C)


###########################################################################
# #
# Library setup #
# Setup #
# #
###########################################################################

option(TS_HAL_UNIX "Use TCP and connect to model" OFF)
option(TS_HAL_STM32_UART "Use UART and connect to model" OFF)
option(TS_HAL_STM32_SPI "Use SPI and connect to real chip" OFF)
option(USE_TREZOR_CRYPTO "Use trezor_crypto as a cryptography provider" OFF)
option(LT_CRYPTO_MBEDTLS "Use mbedtls as a cryptography provider" OFF)
option(BUILD_DOCS "Build documentation" OFF)
option(EXPERIMENTAL_SPI_UART "Experimental feature for spi slave to serial hw convertor" OFF)
option(EXPERIMENTAL_SPI_RASPBERRYPI "Experimental feature for spi slave on rpi 4" OFF)

option(TS_CRYPTO_TREZOR "Use trezor_crypto as a cryptography provider" ON)
option(TS_CRYPTO_MBEDTLS "Use mbedtls as a cryptography provider" OFF)
###########################################################################
# #
# Building documentation #
# #
###########################################################################

option(DEBUG "Compile with -g -Wextra -Wpedantic -Werror" ON)
option(BUILD_DOCS "Build documentation" OFF)
if(BUILD_DOCS)
find_package(Doxygen)
if(Doxygen_FOUND)
add_subdirectory(docs)
message(STATUS "Doxygen found, building docs")
else()
message(STATUS "Doxygen not found, not building docs")
endif()
endif()

# Check if cryptography provider is defined
if((NOT USE_TREZOR_CRYPTO) AND (NOT LT_CRYPTO_MBEDTLS) AND (NOT BUILD_DOCS))
message(FATAL_ERROR "Mbed TLS or trezor_crypto must be enabled!")
endif()

###########################################################################
# #
# libtropic source files #
# Collect files #
# #
###########################################################################

# Enable l1 implementation for a target platform
if (TS_HAL_UNIX)
message(DEBUG "UNIX TCP HAL selected (for model)")
add_definitions(-DTS_HAL_UNIX=1)
# Main program is responsible for adding file from
# appropriate hal/XXX/XXX/folder into its sources and compile it,
# For more info check examples.
elseif(TS_HAL_STM32_SPI)
message(DEBUG "STM32 HAL selected ")
add_definitions(-DTS_HAL_STM32_SPI=1)
# TODO get rid of HOST_KEY_* once get info req with cert is working
add_definitions(-DHOST_KEY_FPGA=1)
# Main program is responsible for adding file from
# appropriate hal/XXX/XXX/folder into its sources and compile it,
# For more info check examples.
elseif(TS_HAL_STM32_UART)
message(DEBUG "STM32 HAL selected ")
add_definitions(-DTS_HAL_STM32_UART=1)
# Main program is responsible for adding file from
# appropriate hal/XXX/XXX/folder into its sources and compile it,
# For more info check examples.
else()
message(WARNING "No HAL enabled, add your own implementation for L1 functions !! ")
set(SDK_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/ts_l1.c)
endif()
project(libtropic_SDK
VERSION 0.0.1
DESCRIPTION "TROPIC01 software development kit"
HOMEPAGE_URL "www.tropicsquare.com"
LANGUAGES C)

set(SDK_SRCS ${SDK_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/src/ts_common.c
${CMAKE_CURRENT_SOURCE_DIR}/src/libtropic.c
${CMAKE_CURRENT_SOURCE_DIR}/src/ts_crc16.c
${CMAKE_CURRENT_SOURCE_DIR}/src/ts_l1.c
${CMAKE_CURRENT_SOURCE_DIR}/src/ts_l2.c
${CMAKE_CURRENT_SOURCE_DIR}/src/ts_l3.c
${CMAKE_CURRENT_SOURCE_DIR}/src/ts_hkdf.c
${CMAKE_CURRENT_SOURCE_DIR}/src/ts_random.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_crc16.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l1_port_wrap.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l1.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l2.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l2_frame_check.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l3.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_hkdf.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_random.c
)

add_library(tropic ${SDK_SRCS})
set(SDK_INCS ${SDK_INCS}
${CMAKE_CURRENT_SOURCE_DIR}/include/libtropic_common.h
${CMAKE_CURRENT_SOURCE_DIR}/include/libtropic.h
${CMAKE_CURRENT_SOURCE_DIR}/include/libtropic_port.h
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_crc16.h
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l1_port_wrap.h
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l1.h
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l2.h
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l2_frame_check.h
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l3.h
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_hkdf.h
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_random.h
)

target_include_directories(tropic PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include/
${CMAKE_CURRENT_SOURCE_DIR}/src/
set(SDK_SRCS ${SDK_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/hal/crypto/trezor_crypto/lt_crypto_trezor_aesgcm.c
${CMAKE_CURRENT_SOURCE_DIR}/hal/crypto/trezor_crypto/lt_crypto_trezor_ed25519.c
${CMAKE_CURRENT_SOURCE_DIR}/hal/crypto/trezor_crypto/lt_crypto_trezor_sha256.c
${CMAKE_CURRENT_SOURCE_DIR}/hal/crypto/trezor_crypto/lt_crypto_trezor_x25519.c
)

target_compile_options(tropic PRIVATE -Wall)
add_library(tropic ${SDK_SRCS} ${SDK_INCS})

if(DEBUG)
target_compile_options(tropic PRIVATE -g -Wextra -Wpedantic -Werror)
endif()
target_include_directories(tropic PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/)
target_include_directories(tropic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/)

target_compile_definitions(tropic PRIVATE "$<$<CONFIG:DEBUG>:LIBT_DEBUG>")

###########################################################################
# #
# Setting up crypto backend based on option switches #
# Compile and link #
# #
###########################################################################

if (TS_CRYPTO_TREZOR)
# Trezor library
add_subdirectory(vendor/trezor_crypto/ "trezor_crypto")
target_link_libraries(tropic PUBLIC trezor_crypto)

# libtropic wrappers for trezor library
add_subdirectory(hal/crypto/trezor_crypto)
target_compile_definitions(tropic PRIVATE USE_TS_CRYPTO)
# This options just add 10ms synchronisation delay before read and write functions.
# Needed for hardware spi slave to uart converter.
if(EXPERIMENTAL_SPI_UART)
target_compile_definitions(tropic PRIVATE EXPERIMENTAL_SPI_UART=1)
endif()

if (TS_CRYPTO_MBEDTLS)
message(FATAL_ERROR "Mbedtls support is not implemented yet")
if(EXPERIMENTAL_SPI_RASPBERRYPI)
target_compile_definitions(tropic PRIVATE EXPERIMENTAL_SPI_RASPBERRYPI=1)
endif()


###########################################################################
# #
# Building documentation is off by default #
# #
###########################################################################

if(BUILD_DOCS)
find_package(Doxygen)
if(Doxygen_FOUND)
add_subdirectory(docs)
message(STATUS "Doxygen found, building docs")
else()
message(STATUS "Doxygen not found, not building docs")
endif()
if(USE_TREZOR_CRYPTO)
add_subdirectory(vendor/trezor_crypto/ "trezor_crypto")
target_compile_definitions(trezor_crypto PRIVATE AES_VAR)
target_link_libraries(tropic PRIVATE trezor_crypto)
target_compile_definitions(tropic PRIVATE USE_TREZOR_CRYPTO)
endif()
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Contributing

To make contributing simple for both sides:

## [1] Open an Issue

- Describe how you would like to contribute and discuss details with us
- We will create a branch for you

## [2] Create a Pull Request:

- Make sure the code is properly tested and must pass on CI
- MAke sure the code is properly formatted
Loading

0 comments on commit f375016

Please sign in to comment.