|
| 1 | +# wolfSSL STSAFE-A120 Test Suite |
| 2 | + |
| 3 | +Test harness for wolfSSL integration with ST STSAFE-A120 secure element on Raspberry Pi 5. |
| 4 | + |
| 5 | +## Hardware Requirements |
| 6 | + |
| 7 | +- Raspberry Pi 5 (or compatible Linux system with I2C) |
| 8 | +- STSAFE-A120 secure element connected via I2C |
| 9 | +- I2C enabled on the system |
| 10 | + |
| 11 | +## Software Requirements |
| 12 | + |
| 13 | +- wolfSSL library (compiled with ECC, CMAC, SHA-384 support) |
| 14 | +- STSELib (ST Secure Element Library) |
| 15 | +- GCC compiler |
| 16 | +- Linux I2C development headers (`libi2c-dev`) |
| 17 | + |
| 18 | +## Quick Start |
| 19 | + |
| 20 | +### 1. Enable I2C on Raspberry Pi |
| 21 | + |
| 22 | +```bash |
| 23 | +sudo raspi-config |
| 24 | +# Navigate to: Interface Options -> I2C -> Enable |
| 25 | +``` |
| 26 | + |
| 27 | +Reboot if prompted, then verify the STSAFE device is detected: |
| 28 | + |
| 29 | +```bash |
| 30 | +sudo i2cdetect -y 1 |
| 31 | +# STSAFE should appear at address 0x20 |
| 32 | +``` |
| 33 | + |
| 34 | +Optional: Allow non-root I2C access: |
| 35 | +```bash |
| 36 | +sudo usermod -a -G i2c $USER |
| 37 | +# Logout and login again |
| 38 | +``` |
| 39 | + |
| 40 | +### 2. Build wolfSSL |
| 41 | + |
| 42 | +```bash |
| 43 | +cd ~/wolfssl |
| 44 | +./configure --enable-cryptocb --enable-ecc --enable-cmac --enable-sha384 |
| 45 | +make |
| 46 | +``` |
| 47 | + |
| 48 | +### 3. Clone STSELib |
| 49 | + |
| 50 | +```bash |
| 51 | +git clone https://github.com/STMicroelectronics/STSELib.git ~/STSELib |
| 52 | +``` |
| 53 | + |
| 54 | +### 4. Build and Run Tests |
| 55 | + |
| 56 | +```bash |
| 57 | +cd ~/wolfssl-examples/stsafe |
| 58 | + |
| 59 | +# Build all test executables |
| 60 | +make |
| 61 | + |
| 62 | +# Run all tests |
| 63 | +make test-all |
| 64 | +``` |
| 65 | + |
| 66 | +## Test Suites |
| 67 | + |
| 68 | +### Basic STSELib Tests (`stsafe_test`) |
| 69 | + |
| 70 | +Tests core STSAFE-A120 functionality: |
| 71 | +- Echo command (I2C communication) |
| 72 | +- Random number generation |
| 73 | +- ECC P-256 key generation |
| 74 | +- ECDSA P-256 signing |
| 75 | +- ECC P-384 key generation |
| 76 | + |
| 77 | +```bash |
| 78 | +make && ./stsafe_test |
| 79 | +``` |
| 80 | + |
| 81 | +### wolfSSL Crypto Callback Tests (`wolfssl_stsafe_test`) |
| 82 | + |
| 83 | +Tests wolfSSL crypto callbacks with STSAFE: |
| 84 | +- RNG with STSAFE-A120 |
| 85 | +- ECC P-256/P-384 key generation via crypto callback |
| 86 | +- ECDSA P-256/P-384 sign/verify |
| 87 | +- ECDHE P-256 ephemeral key generation |
| 88 | +- ECDHE P-256 shared secret computation |
| 89 | + |
| 90 | +```bash |
| 91 | +make wolfssl && ./wolfssl_stsafe_test |
| 92 | +``` |
| 93 | + |
| 94 | +### Full Integration Tests (`wolfssl_stsafe_full_test`) |
| 95 | + |
| 96 | +Comprehensive tests with benchmarks: |
| 97 | +- RNG benchmark |
| 98 | +- ECDSA P-256 benchmark (keygen, sign, verify timing) |
| 99 | +- ECDH P-256 key exchange (uses ECDHE ephemeral keys) |
| 100 | +- Multiple sequential operations |
| 101 | + |
| 102 | +```bash |
| 103 | +make wolfssl-full && ./wolfssl_stsafe_full_test |
| 104 | +``` |
| 105 | + |
| 106 | +## Build Targets |
| 107 | + |
| 108 | +| Target | Description | |
| 109 | +|--------|-------------| |
| 110 | +| `make` | Build all test executables | |
| 111 | +| `make test-all` | Build and run all tests | |
| 112 | +| `make basic` | Build without wolfSSL (basic I2C tests only) | |
| 113 | +| `make clean` | Clean build artifacts | |
| 114 | +| `make info` | Show configuration | |
| 115 | + |
| 116 | +## Expected Output |
| 117 | + |
| 118 | +``` |
| 119 | +================================================ |
| 120 | +STSAFE-A120 Test Suite for wolfSSL Integration |
| 121 | +================================================ |
| 122 | +
|
| 123 | +Initializing STSAFE handler... |
| 124 | +STSAFE-A120 initialized successfully. |
| 125 | +
|
| 126 | +Test: Echo Command |
| 127 | + Echo response matches! |
| 128 | +[PASS] Echo command |
| 129 | +
|
| 130 | +Test: Random Number Generation |
| 131 | + Random data: A1 B2 C3 D4 ... |
| 132 | +[PASS] Random number generation |
| 133 | +
|
| 134 | +Test: ECC Key Generation (P-256) |
| 135 | + Public Key X: 12345678... |
| 136 | + Public Key Y: ABCDEF01... |
| 137 | +[PASS] ECC P-256 key generation |
| 138 | +
|
| 139 | +... |
| 140 | +
|
| 141 | +================================================ |
| 142 | +Test Summary: 5 passed, 0 failed |
| 143 | +================================================ |
| 144 | +``` |
| 145 | + |
| 146 | +## Performance Results (Raspberry Pi 5) |
| 147 | + |
| 148 | +| Operation | Time | Throughput | |
| 149 | +|-----------|------|------------| |
| 150 | +| RNG (256 bytes) | <1 ms | ~9 MB/s | |
| 151 | +| ECC P-256 KeyGen | ~40 ms | 25 ops/sec | |
| 152 | +| ECDSA P-256 Sign | ~51 ms | 19.5 ops/sec | |
| 153 | +| ECDSA P-256 Verify | ~79 ms | 12.7 ops/sec | |
| 154 | +| ECDHE P-256 KeyGen | ~42 ms | ~24 ops/sec | |
| 155 | +| ECDHE P-256 Shared Secret | ~38 ms | ~26 ops/sec | |
| 156 | + |
| 157 | +## Directory Structure |
| 158 | + |
| 159 | +``` |
| 160 | +stsafe/ |
| 161 | +├── Makefile # Build configuration |
| 162 | +├── README.md # This file |
| 163 | +├── user_settings.h # wolfSSL configuration |
| 164 | +├── stsafe_test.c # STSELib basic tests |
| 165 | +├── wolfssl_stsafe_test.c # wolfSSL crypto callback tests |
| 166 | +├── wolfssl_stsafe_full_test.c # Full integration tests with benchmarks |
| 167 | +└── platform/ |
| 168 | + ├── stse_conf.h # STSELib configuration |
| 169 | + ├── stse_platform_generic.h # Platform type definitions |
| 170 | + ├── stse_platform_linux.c # Linux I2C platform implementation |
| 171 | + └── stse_platform_crypto_wolfssl.c # wolfSSL crypto for STSELib |
| 172 | +``` |
| 173 | + |
| 174 | +## Environment Variables |
| 175 | + |
| 176 | +Default paths assume `~/wolfssl` and `~/STSELib`. Override if needed: |
| 177 | + |
| 178 | +```bash |
| 179 | +export WOLFSSL_DIR=/path/to/wolfssl |
| 180 | +export STSELIB_DIR=/path/to/STSELib |
| 181 | +``` |
| 182 | + |
| 183 | +## Troubleshooting |
| 184 | + |
| 185 | +### Error 0x0104 (STSE_PLATFORM_BUS_ERR) |
| 186 | + |
| 187 | +I2C communication error. Check: |
| 188 | +1. I2C is enabled: `ls /dev/i2c*` |
| 189 | +2. Device detected: `sudo i2cdetect -y 1` (should show `20`) |
| 190 | +3. Wiring connections are secure |
| 191 | + |
| 192 | +### Build errors |
| 193 | + |
| 194 | +Ensure wolfSSL is built with required features: |
| 195 | +```bash |
| 196 | +./configure --enable-cryptocb --enable-ecc --enable-cmac --enable-sha384 |
| 197 | +``` |
| 198 | + |
| 199 | +## References |
| 200 | + |
| 201 | +- [wolfSSL Documentation](https://www.wolfssl.com/docs/) |
| 202 | +- [STSELib GitHub](https://github.com/STMicroelectronics/STSELib) |
| 203 | +- [STSAFE-A120 Datasheet](https://www.st.com/en/secure-mcus/stsafe-a120.html) |
| 204 | +- [Raspberry Pi I2C Documentation](https://www.raspberrypi.com/documentation/computers/raspberry-pi.html) |
0 commit comments