Skip to content

Commit 95b1505

Browse files
committed
Add VaultIC wolfCrypt crypto callback (devId) support
1 parent 0f15af3 commit 95b1505

6 files changed

Lines changed: 389 additions & 104 deletions

File tree

.wolfssl_known_macro_extras

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ USE_TLSV13
688688
USE_WINDOWS_API
689689
USE_WOLF_STRNSTR
690690
USS_API
691+
VLT_TLS_NO_ECDH
691692
W64LIT_FORCE_LONG_LONG
692693
WC_AESXTS_STREAM_NO_REQUEST_ACCOUNTING
693694
WC_AES_BS_WORD_SIZE

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,11 @@ endif()
524524
add_option("WOLFSSL_VAULTIC" "Enable WISeKey/SealSQ VaultIC support (default: disabled)" "no" "yes;no")
525525
if(WOLFSSL_VAULTIC)
526526
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_VAULTIC")
527-
# VaultIC port requires PK callbacks (mirror autotools --enable-vaultic).
528-
# WOLFSSL_PKCALLBACKS is declared later, so force it before its add_option().
527+
# VaultIC port supports PK callbacks and crypto callbacks (mirror autotools
528+
# --enable-vaultic). These options are declared later, so force them before
529+
# their add_option() calls.
529530
force_option(WOLFSSL_PKCALLBACKS "yes")
531+
force_option(WOLFSSL_CRYPTOCB "yes")
530532
endif()
531533

532534
add_option("WOLFSSL_WOLFSENTRY" "Enable wolfSentry support (default: disabled)" "no" "yes;no")

configure.ac

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12488,11 +12488,15 @@ if test "$ENABLED_VAULTIC" != "no"
1248812488
then
1248912489
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_VAULTIC"
1249012490
ENABLED_VAULTIC=yes
12491-
# VaultIC port is implemented via PK callbacks
12491+
# VaultIC port supports TLS PK callbacks and wolfCrypt crypto callbacks
1249212492
if test "$ENABLED_PKCALLBACKS" = "no"; then
1249312493
ENABLED_PKCALLBACKS=yes
1249412494
AM_CFLAGS="$AM_CFLAGS -DHAVE_PK_CALLBACKS"
1249512495
fi
12496+
if test "$ENABLED_CRYPTOCB" = "no"; then
12497+
ENABLED_CRYPTOCB=yes
12498+
AM_CFLAGS="$AM_CFLAGS -DWOLF_CRYPTO_CB"
12499+
fi
1249612500
fi
1249712501
1249812502
if test "x$ENABLED_WOLFENGINE" = "xyes"

wolfcrypt/src/port/sealsq/README.md

Lines changed: 76 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
11
# WISeKey / SealSQ VaultIC Port
22

3-
This port offloads TLS ECC P-256 operations to a WISeKey/SealSQ VaultIC secure
4-
element (for example the VaultIC 408 on the DEVKIT_VIC408) using wolfSSL's
5-
public-key (PK) callbacks. The private key never leaves the chip.
3+
This port offloads ECC P-256 operations to a WISeKey/SealSQ VaultIC secure
4+
element (for example the VaultIC 408 on the DEVKIT_VIC408). The private key
5+
never leaves the chip.
6+
7+
It exposes the device through two mechanisms, which can be used independently
8+
or together:
9+
10+
* **TLS PK callbacks** - route the ECC operations of a TLS handshake
11+
(`WOLFSSL_CTX` / `WOLFSSL`) to the device via wolfSSL's public-key (PK)
12+
callback framework.
13+
* **wolfCrypt crypto callback (devId)** - route wolfCrypt ECC operations (not
14+
just the TLS handshake) to the device via the `WOLF_CRYPTO_CB` / devId
15+
framework, so bare `wc_ecc_*` calls and a whole `WOLFSSL_CTX` can be pointed
16+
at the chip with a single devId.
17+
18+
Both share the same underlying VaultIC-TLS SDK entry points; see "Usage" for
19+
which one to pick.
620

721
## What it does
822

923
`wolfcrypt/src/port/sealsq/vaultic.c` provides:
1024

25+
ECC operations on the device (used by both mechanisms):
26+
1127
* `WOLFSSL_VAULTIC_EccSignCb` - ECDSA P-256 sign on the device
1228
* `WOLFSSL_VAULTIC_EccVerifyCb` - ECDSA P-256 verify on the device
1329
* `WOLFSSL_VAULTIC_EccKeyGenCb` - ephemeral P-256 key generation on the device
1430
* `WOLFSSL_VAULTIC_EccSharedSecretCb` - ECDH P-256 shared secret on the device
31+
32+
TLS PK callback registration:
33+
34+
* `WOLFSSL_VAULTIC_SetupPkCallbacks` / `WOLFSSL_VAULTIC_SetupPkCallbackCtx` -
35+
register the PK callbacks on a `WOLFSSL_CTX` / `WOLFSSL`
36+
37+
Crypto callback (devId) registration:
38+
39+
* `WOLFSSL_VAULTIC_RegisterCryptoCb` - register the VaultIC crypto callback
40+
under a devId (`WOLF_VAULTIC_DEVID`)
41+
42+
Certificate helper:
43+
1544
* `WOLFSSL_VAULTIC_LoadCertificates` - read the device and CA certificates
1645
stored on the chip into a `WOLFSSL_CTX`
17-
* `WOLFSSL_VAULTIC_SetupPkCallbacks` / `WOLFSSL_VAULTIC_SetupPkCallbackCtx` -
18-
register the callbacks on a `WOLFSSL_CTX` / `WOLFSSL`
1946

2047
The key-generation and shared-secret (ECDH) callbacks can be compiled out by
2148
defining `VLT_TLS_NO_ECDH`, matching the vendor library configuration.
@@ -37,8 +64,9 @@ Enable the port and point the compiler/linker at the vendor SDK:
3764
make
3865
```
3966

40-
`--enable-vaultic` defines `WOLFSSL_VAULTIC` and enables PK callbacks
41-
(`HAVE_PK_CALLBACKS`) automatically. The port compiles to nothing when
67+
`--enable-vaultic` defines `WOLFSSL_VAULTIC` and automatically enables both PK
68+
callbacks (`HAVE_PK_CALLBACKS`) and crypto callbacks (`WOLF_CRYPTO_CB`), so
69+
either mechanism is available out of the box. The port compiles to nothing when
4270
`WOLFSSL_VAULTIC` is not defined.
4371

4472
### Building the port outside libwolfssl
@@ -50,8 +78,11 @@ separate target (for example the SealSQ devkit builds it into its own
5078
`vaultic_wolfssl` library alongside an `add_subdirectory(wolfssl)` CMake
5179
build), two things are required so the file sees the wolfSSL configuration:
5280

53-
* Define `WOLFSSL_USE_OPTIONS_H` when compiling `vaultic.c`, so
54-
`settings.h` pulls in the generated `wolfssl/options.h`. Without it the
81+
* Make the file see the wolfSSL configuration. For an autotools build define
82+
`WOLFSSL_USE_OPTIONS_H`, so `settings.h` pulls in the generated
83+
`wolfssl/options.h`. For a build that does not use `./configure` (so there is
84+
no generated `options.h`), define `WOLFSSL_USER_SETTINGS` instead and provide
85+
a `user_settings.h` that lists all the build options. Without one of these the
5586
wolfSSL headers fall back to defaults (`ecc_key` is incomplete,
5687
`ECC_SECP256R1` is undeclared).
5788
* Enable PK callbacks through the wolfSSL build option
@@ -62,6 +93,14 @@ build), two things are required so the file sees the wolfSSL configuration:
6293

6394
## Usage
6495

96+
The port offers two ways to route ECC to the chip (see the overview at the
97+
top). Use the PK callbacks when you only need the TLS handshake offloaded and
98+
want per-`WOLFSSL` control; use the crypto callback (devId) when you want all
99+
wolfCrypt ECC - including bare `wc_ecc_*` calls - routed to the device, or
100+
prefer a single devId on the `WOLFSSL_CTX`.
101+
102+
### TLS PK callbacks
103+
65104
```c
66105
WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfTLS_client_method());
67106

@@ -76,9 +115,34 @@ WOLFSSL_VAULTIC_SetupPkCallbackCtx(ssl, NULL);
76115
/* ... proceed with the TLS handshake ... */
77116
```
78117
79-
The VaultIC-TLS SDK must be initialized (`vlt_tls_init()`) before the
80-
handshake and closed (`vlt_tls_close()`) afterwards; see the SealSQ devkit
81-
sample applications.
118+
### Crypto callback (devId)
119+
120+
The crypto callback dispatches wolfCrypt ECC operations (not just the TLS
121+
handshake) to the VaultIC through the `WOLF_CRYPTO_CB` / devId framework.
122+
Register the device once, then select it with a devId:
123+
124+
```c
125+
/* register the VaultIC crypto callback under a devId */
126+
WOLFSSL_VAULTIC_RegisterCryptoCb(WOLF_VAULTIC_DEVID);
127+
128+
/* TLS: route this CTX's crypto to the device */
129+
wolfSSL_CTX_SetDevId(ctx, WOLF_VAULTIC_DEVID);
130+
131+
/* or bare wolfCrypt: init a key against the device */
132+
wc_ecc_init_ex(&key, NULL, WOLF_VAULTIC_DEVID);
133+
```
134+
135+
The VaultIC-TLS SDK must be initialized (`vlt_tls_init()`) before use and
136+
closed (`vlt_tls_close()`) afterwards; see the SealSQ devkit sample
137+
applications.
138+
139+
### Curve support
140+
141+
The port offloads P-256 (SECP256R1) only. The VaultIC 408 silicon supports
142+
P-384, but the vendor `vlt_tls` API exposes P-256 entry points only, so
143+
P-384 would require vendor `vlt_tls_*_P384` functions. For any other curve
144+
the crypto callback returns `CRYPTOCB_UNAVAILABLE` and the PK callbacks
145+
return `NOT_COMPILED_IN`, so wolfSSL falls back to software.
82146

83147
## Building and provisioning with the SealSQ devkit
84148

0 commit comments

Comments
 (0)