|
| 1 | +# wolfSSL TROPIC01 Secure Element Integration Guide |
| 2 | + |
| 3 | + |
| 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