Skip to content

Commit 8395410

Browse files
authored
Merge pull request #8812 from kosmax871/tropic01-dev
Added crypto callback functions for TROPIC01 secure element
2 parents 5e6c1ba + 037ccba commit 8395410

7 files changed

Lines changed: 923 additions & 1 deletion

File tree

configure.ac

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,6 +2852,39 @@ AC_ARG_WITH([cryptoauthlib],
28522852
]
28532853
)
28542854

2855+
2856+
# TropicSquare TROPIC01
2857+
# Example: "./configure --with-tropic01=/home/pi/libtropic"
2858+
ENABLED_TROPIC01="no"
2859+
trylibtropicdir=""
2860+
AC_ARG_WITH([tropic01],
2861+
[AS_HELP_STRING([--with-tropic01=PATH],[PATH to install (default /usr/)])],
2862+
[
2863+
AC_MSG_CHECKING([for libtropic])
2864+
if test "x$withval" != "xno" ; then
2865+
trylibtropicdir=$withval
2866+
fi
2867+
if test "x$withval" = "xyes" ; then
2868+
trylibtropicdir="libtropic"
2869+
fi
2870+
if test -e $trylibtropicdir/build/libtropic.a
2871+
then
2872+
LIB_STATIC_ADD="$LIB_STATIC_ADD $trylibtropicdir/build/libtropic.a"
2873+
LIB_STATIC_ADD="$LIB_STATIC_ADD $trylibtropicdir/build/trezor_crypto/libtrezor_crypto.a"
2874+
AM_CFLAGS="$AM_CFLAGS -I$trylibtropicdir/include"
2875+
else
2876+
ENABLED_TROPIC01="no"
2877+
AC_MSG_ERROR([Could not find libtropic - TropicSquare library])
2878+
fi
2879+
enable_shared=no
2880+
enable_static=yes
2881+
ENABLED_TROPIC01="yes"
2882+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_TROPIC01"
2883+
AC_MSG_RESULT([yes])
2884+
]
2885+
)
2886+
2887+
28552888
# NXP SE050
28562889
# Example: "./configure --with-se050=/home/pi/simw_top"
28572890
ENABLED_SE050="no"
@@ -10705,6 +10738,7 @@ AM_CONDITIONAL([BUILD_QNXCAAM],[test "x$ENABLED_CAAM_QNX" = "xyes"])
1070510738
AM_CONDITIONAL([BUILD_IOTSAFE],[test "x$ENABLED_IOTSAFE" = "xyes"])
1070610739
AM_CONDITIONAL([BUILD_IOTSAFE_HWRNG],[test "x$ENABLED_IOTSAFE_HWRNG" = "xyes"])
1070710740
AM_CONDITIONAL([BUILD_SE050],[test "x$ENABLED_SE050" = "xyes"])
10741+
AM_CONDITIONAL([BUILD_TROPIC01],[test "x$ENABLED_TROPIC01" = "xyes"])
1070810742
AM_CONDITIONAL([BUILD_KDF],[test "x$ENABLED_KDF" = "xyes"])
1070910743
AM_CONDITIONAL([BUILD_HMAC],[test "x$ENABLED_HMAC" = "xyes"])
1071010744
AM_CONDITIONAL([BUILD_ERROR_STRINGS],[test "x$ENABLED_ERROR_STRINGS" = "xyes"])
@@ -11233,6 +11267,7 @@ echo " * i.MX CAAM: $ENABLED_CAAM"
1123311267
echo " * IoT-Safe: $ENABLED_IOTSAFE"
1123411268
echo " * IoT-Safe HWRNG: $ENABLED_IOTSAFE_HWRNG"
1123511269
echo " * NXP SE050: $ENABLED_SE050"
11270+
echo " * TROPIC01: $ENABLED_TROPIC01"
1123611271
echo " * Maxim Integrated MAXQ10XX: $ENABLED_MAXQ10XX"
1123711272
echo " * PSA: $ENABLED_PSA"
1123811273
echo " * System CA certs: $ENABLED_SYS_CA_CERTS"

wolfcrypt/src/include.am

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ EXTRA_DIST += wolfcrypt/src/port/ti/ti-aes.c \
105105
wolfcrypt/src/port/st/README.md \
106106
wolfcrypt/src/port/st/STM32MP13.md \
107107
wolfcrypt/src/port/st/STM32MP25.md \
108+
wolfcrypt/src/port/tropicsquare/tropic01.c \
109+
wolfcrypt/src/port/tropicsquare/README.md \
108110
wolfcrypt/src/port/af_alg/afalg_aes.c \
109111
wolfcrypt/src/port/af_alg/afalg_hash.c \
110112
wolfcrypt/src/port/kcapi/kcapi_aes.c \
@@ -221,6 +223,10 @@ if BUILD_SE050
221223
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/nxp/se050_port.c
222224
endif
223225

226+
if BUILD_TROPIC01
227+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/tropicsquare/tropic01.c
228+
endif
229+
224230
if BUILD_PSA
225231
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/psa/psa.c
226232
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/port/psa/psa_hash.c
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
# wolfSSL TROPIC01 Secure Element Integration Guide
2+
3+
![wolfSSL+TROPIC01](https://img.shields.io/badge/wolfSSL-TROPIC01-blue)
4+
5+
6+
Integration guide for using Tropic Square's TROPIC01 secure element with wolfSSL/wolfCrypt cryptography library.
7+
8+
## Table of Contents
9+
- [wolfSSL TROPIC01 Secure Element Integration Guide](#wolfssl-tropic01-secure-element-integration-guide)
10+
- [Table of Contents](#table-of-contents)
11+
- [TROPIC01 Secure Element with an open architecture](#tropic01-secure-element-with-an-open-architecture)
12+
- [Hardware Overview](#hardware-overview)
13+
- [TROPIC01 Specifications](#tropic01-specifications)
14+
- [Available Evaluation and Development Kits](#available-evaluation-and-development-kits)
15+
- [Get samples](#get-samples)
16+
- [Build Configuration](#build-configuration)
17+
- [Pre-requirements](#pre-requirements)
18+
- [Keys installation](#keys-installation)
19+
- [Build TROPIC01 SDK (libtropic)](#build-tropic01-sdk-libtropic)
20+
- [Build wolfSSL](#build-wolfssl)
21+
- [Build test application](#build-test-application)
22+
23+
## TROPIC01 Secure Element with an open architecture
24+
25+
The TROPIC01 secure element is built with tamper-proof technology and advanced attack countermeasures to ensure robust asset protection, securing electronic devices against a wide range of potential attacks. It securely supplies and stores the cryptographic keys of embedded solutions.
26+
The TROPIC01 datasheet is available via [this link](https://github.com/tropicsquare/tropic01/blob/main/doc/datasheet/ODD_tropic01_datasheet_revA6.pdf)
27+
28+
## Hardware Overview
29+
30+
### TROPIC01 Specifications
31+
- **Crypto Accelerators**:
32+
- Elliptic curve cryptography
33+
- Ed25519 EdDSA signing
34+
- P-256 ECDSA signing
35+
- Diffie-Hellman X25519 key exchange
36+
- Keccak-based PIN authentication engine
37+
- **Tamper Resistance**:
38+
- Voltage glitch detector
39+
- Temperature detector
40+
- Electromagnetic pulse detector
41+
- Laser detector
42+
- Active shield
43+
- **Interface to Host MCU/MPU**:
44+
- SPI
45+
- Encrypted channel with forward secrecy
46+
- **Entropy Source**:
47+
- Physically Unclonable Function (PUF)
48+
- True Random Number Generator (TRNG)
49+
50+
### Available Evaluation and Development Kits
51+
- USB Stick with TROPIC01 ([here](https://github.com/tropicsquare/tropic01?tab=readme-ov-file#usb-stick-with-tropic01))
52+
- Raspberry PI shield ([here](https://github.com/tropicsquare/tropic01?tab=readme-ov-file#rpi-shield-ts1501))
53+
- Arduino shield ([here](https://github.com/tropicsquare/tropic01?tab=readme-ov-file#arduino-shield-ts14))
54+
55+
### Get samples
56+
To get samples and DevKits, please fill in [this form](https://tropicsquare.com/tropic01-samples#form)
57+
58+
## Build Configuration
59+
60+
### Pre-requirements
61+
1. Get one of the targeted hardware platforms. For example, Linux PC + TROPIC01 USB stick or Raspberry PI 3/4/5 + TROPIC01 RPI shield
62+
2. Install toolchain (incl. compiler or cross-compiler). For example, GNU Toolchain (gcc) or ARM cross-compiling toolchain (armv8-rpi3-linux-gnueabihf)
63+
3. Install CMake and Autotools
64+
4. Install Git
65+
66+
Some guidelines for RPi are available [here](https://earthly.dev/blog/cross-compiling-raspberry-pi/)
67+
68+
Also, for Raspberry PI, there are a few more steps:
69+
70+
1. In raspi-config go to "Interface Options" and enable SPI
71+
2. Install wiringPI:
72+
73+
```sh
74+
$ wget https://github.com/WiringPi/WiringPi/releases/download/3.14/wiringpi_3.14_arm64.deb
75+
$ sudo apt install ./wiringpi_3.14_arm64.deb
76+
```
77+
78+
### Keys installation
79+
80+
For the integration with wolfSSL, there are a few pre-defined slots for the secure keys storage (the slots mapping might be changed in tropic01.h):
81+
```sh
82+
TROPIC01_AES_KEY_RMEM_SLOT 0 // slot in R-memory for AES key
83+
TROPIC01_AES_IV_RMEM_SLOT 1 // slot in R-memory for AES IV
84+
TROPIC01_ED25519_PUB_RMEM_SLOT_DEFAULT 2 // slot in R-memory for ED25519 Public key
85+
TROPIC01_ED25519_PRIV_RMEM_SLOT_DEFAULT 3 //slot in R-memory for ED25519 Private key
86+
TROPIC01_ED25519_ECC_SLOT_DEFAULT 1 // slot in ECC keys storage for both public and private keys
87+
PAIRING_KEY_SLOT_INDEX_0 0 //pairing keys slot
88+
```
89+
All R-memory based keys must be pre-provisioned in the TROPIC01 Secure Element separately. For example, it might be done with the libtropic-util tool available [here] (https://github.com/tropicsquare/libtropic-util)
90+
91+
### Build TROPIC01 SDK (libtropic)
92+
93+
wolfSSL uses the "TROPIC01 SDK" (aka libtropic) to interface with TROPIC01. This SDK can be cloned from the TropicSquare GitHub https://github.com/tropicsquare/libtropic
94+
95+
Once the repo was downloaded, please follow [this guideline](https://github.com/tropicsquare/libtropic/blob/master/docs/index.md#integration-examples) on how to configure and build TROPIC01 SDK
96+
97+
Or run the following commands:
98+
```sh
99+
$ git clone https://github.com/tropicsquare/libtropic.git
100+
$ cd libtropic
101+
$ mkdir build && cd build
102+
$ cmake -DLT_USE_TREZOR_CRYPTO=1 ..
103+
$ make
104+
```
105+
106+
### Build wolfSSL
107+
1. Clone wolfSSL from the wolfSSL GitHub (https://github.com/wolfSSL/wolfssl)
108+
109+
2. Make sure that the version of wolfSSL supports TROPIC01 - check if the folder wolfssl/wolfcrypt/src/port/tropicsquare exists
110+
111+
3. To compile wolfSSL with TROPIC01 support using Autoconf/configure:
112+
113+
```sh
114+
$ cd wolfssl
115+
$ ./autogen.sh
116+
$ ./configure --with-tropic01=PATH --enable-cryptocb --enable-static --disable-crypttests --disable-examples --disable-shared --enable-ed25519
117+
$ make
118+
$ sudo make install
119+
```
120+
where PATH is an absolute path to the libtropic folder, for example
121+
122+
--with-tropic01=/home/pi/git/libtropic
123+
124+
For the debugging output, add
125+
126+
--enable-debug
127+
128+
### Build test application
129+
130+
The test application for Raspberry Shield and USB stick can be cloned from the TropicSquare GitHub https://github.com/tropicsquare/tropic01-wolfssl-test
131+
132+
To build and run the test application, please run the following commands
133+
134+
```sh
135+
$ git clone git@github.com:tropicsquare/tropic01-wolfssl-test.git
136+
$ cd tropic01-wolfssl-test
137+
```
138+
If necessary, open and edit the Makefile in this folder
139+
140+
Set correct values for CC and LIBTROPIC_DIR variables, for example:
141+
142+
CC = gcc
143+
144+
LIBTROPIC_DIR = /home/pi/git/libtropic
145+
146+
Then run the following commands to build and run the test application for the USB stick:
147+
148+
```sh
149+
$ make
150+
$ ./lt-wolfssl-test
151+
```
152+
or for Raspberry PI shield (make sure you fulfill all prerequisites first):
153+
154+
155+
```sh
156+
$ make RPI_SPI=1
157+
$ ./lt-wolfssl-test
158+
```
159+
160+
In case of success, the output of the test application should look like this:
161+
162+
```sh
163+
wolfSSL Crypto Callback Test Application
164+
========================================
165+
wolfSSL Entering wolfCrypt_Init
166+
TROPIC01: Crypto device initialized successfully
167+
wolfCrypt initialized successfully
168+
Registering crypto callback with device ID 481111...
169+
Crypto callback registered successfully
170+
RNG_HEALTH_TEST_CHECK_SIZE = 128
171+
sizeof(seedB_data) = 128
172+
TROPIC01: CryptoCB: SEED generation request (52 bytes)
173+
TROPIC01: GetRandom: Requesting 52 bytes
174+
TROPIC01: GetRandom: Completed with ret=0
175+
TROPIC01: CryptoCB: RNG generation request (32 bytes)
176+
TROPIC01: GetRandom: Requesting 32 bytes
177+
TROPIC01: GetRandom: Completed with ret=0
178+
Generated 32 random bytes:
179+
94F589E8 9C59B5A2 C8426FB6 9C548623
180+
358551CE 07238D37 EBF7FEE5 42BEB299
181+
182+
RNG test completed successfully
183+
184+
AES test starting:
185+
TROPIC01: CryptoCB: AES request
186+
TROPIC01: Get AES Key: Retrieving key from slot 1
187+
TROPIC01: Get AES Key: Key retrieved successfully
188+
Plain message:
189+
01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10
190+
Encrypted message:
191+
89 44 11 3E 2E 07 52 9C CB 5F B1 70 7E 9C 42 D6
192+
AES test completed successfully
193+
194+
ED25519 COMPREHENSIVE TESTING SUITE
195+
196+
=== Ed25519 Key Generation Test ===
197+
✓ Ed25519 key structure initialized successfully
198+
TROPIC01: CryptoCB: RNG generation request (32 bytes)
199+
TROPIC01: GetRandom: Requesting 32 bytes
200+
TROPIC01: GetRandom: Completed with ret=0
201+
✓ Ed25519 key pair generated successfully
202+
Generated Public Key (32 bytes):
203+
5D28BB98 AF86844E 5C2D48B6 473EA116
204+
0A98B568 3313915D 1565C540 AA3EB250
205+
✓ Ed25519 key generation test completed successfully
206+
207+
=== Ed25519 Message Signing Test ===
208+
DEV_ID: 481111
209+
TROPIC01: CryptoCB: RNG generation request (64 bytes)
210+
TROPIC01: GetRandom: Requesting 64 bytes
211+
TROPIC01: GetRandom: Completed with ret=0
212+
Test Message (64 bytes):
213+
000CD9C2 0FA2E218 67737744 4550F217
214+
5082408B 9F21F92B 06A570C4 C18AA073
215+
1B23836F 1CDC760B 7242F8A7 83B8EC9A
216+
BF9E6D84 2E605AA1 0A168E88 FDEF38DA
217+
TROPIC01: CryptoCB: ED25519 signing request
218+
TROPIC01: Get ECC Key: Retrieving key from slot 3
219+
TROPIC01: Get ECC Key: Key retrieved successfully
220+
✓ Message signed successfully
221+
Signature length: 64 bytes
222+
Generated Signature (64 bytes):
223+
AE4B42CF 46F8F369 4F559390 0EDDA701
224+
A73A562B 3D03F429 8706309D 63E2120B
225+
82B2A91F 6D7A7519 0CD62215 CABE3183
226+
433F4125 2CC017EB BD1E59A1 4A22CC09
227+
✓ Ed25519 message signing test completed successfully
228+
wolfSSL Entering wolfCrypt_Cleanup
229+
```
230+
231+
232+

0 commit comments

Comments
 (0)