Skip to content

Commit bff9699

Browse files
committed
allow full offload (with GCM)
Signed-off-by: Sameeh Jubran <sameeh@wolfssl.com>
1 parent 74a94c0 commit bff9699

File tree

9 files changed

+445
-64
lines changed

9 files changed

+445
-64
lines changed

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,21 @@ not using TLS cipher suites.
5959

6060
### AES CryptoCB Key Import Support
6161

62-
wolfSSL supports offloading AES key handling to external devices
63-
(e.g., Secure Elements or HSMs) using the Crypto Callback (CryptoCB)
64-
interface - the same mechanism used for RSA, ECC, and other algorithms.
65-
66-
When `WOLF_CRYPTO_CB_AES_SETKEY` is enabled, AES keys can be imported
67-
into a device via the CryptoCB callback. The device stores the key
68-
internally and provides an opaque handle via `aes->devCtx`. Subsequent
69-
AES-GCM operations are routed through CryptoCB, and wolfCrypt does not
70-
retain the raw key material.
62+
wolfSSL supports hardware-accelerated AES operations via CryptoCB.
63+
64+
**TLS Builds (Default):**
65+
- Provides hardware **acceleration** with automatic software fallback
66+
- Key material IS copied to wolfSSL memory for fallback capability
67+
- Safe for production TLS servers
68+
- HSMs/SEs accelerate crypto but don't provide key isolation
69+
70+
**Crypto-Only Builds (--disable-tls):**
71+
- Provides true hardware **offload**
72+
- Key material NOT copied to wolfSSL memory
73+
- Requires robust error handling in callbacks
74+
- Suitable for embedded crypto-only applications
75+
76+
Enable with: `CPPFLAGS="-DWOLF_CRYPTO_CB_AES_SETKEY"`
7177

7278
This feature is commonly used for TLS 1.3 traffic key protection on
7379
embedded platforms with hardware security modules.

doc/dox_comments/header_files/cryptocb.h

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,36 @@ void wc_CryptoCb_InfoString(wc_CryptoInfo* info);
187187
\brief Import an AES key into a CryptoCB device for hardware offload.
188188
189189
This function allows AES keys to be handled by an external device
190-
(e.g. Secure Element or HSM) without exposing raw key material to
191-
wolfCrypt. When supported, the device callback stores the key internally
192-
and sets an opaque handle in aes->devCtx.
190+
(e.g. Secure Element or HSM). When supported, the device callback stores
191+
the key internally and sets an opaque handle in aes->devCtx.
193192
194193
When CryptoCB AES SetKey support is enabled
195-
(WOLF_CRYPTO_CB_AES_SETKEY), wolfCrypt will route AES-GCM operations
196-
through the CryptoCB interface and avoid storing key bytes or
197-
generating GCM tables in software.
198-
199-
\param aes AES context
200-
\param key Pointer to raw AES key material
201-
\param keySz Size of key in bytes
194+
(WOLF_CRYPTO_CB_AES_SETKEY), wolfCrypt routes AES-GCM operations
195+
through the CryptoCB interface.
196+
197+
**TLS Builds (Default):**
198+
- Key bytes ARE stored in wolfCrypt memory for fallback
199+
- GCM tables ARE generated for software fallback
200+
- Provides hardware acceleration with automatic fallback
201+
202+
**Crypto-Only Builds (--disable-tls):**
203+
- Key bytes NOT stored (true key isolation)
204+
- GCM tables skipped when WC_CRYPTOCB_AES_GCM is set
205+
- True hardware offload
206+
207+
The callback declares its capabilities by setting flags in the
208+
capabilities parameter. If WC_CRYPTOCB_AES_GCM is set, the callback
209+
supports AES-GCM acceleration. In TLS builds, tables are still generated
210+
for fallback. In crypto-only builds, tables are skipped for true offload.
211+
If not set, wolfCrypt generates tables for software fallback.
212+
213+
\param aes AES context
214+
\param key Pointer to raw AES key material
215+
\param keySz Size of key in bytes
216+
\param capabilities Output parameter receiving capability flags set by
217+
callback. May be NULL if capabilities are not needed.
218+
Callback sets WC_CRYPTOCB_AES_GCM to indicate full
219+
GCM offload support.
202220
203221
\return 0 on success
204222
\return CRYPTOCB_UNAVAILABLE if device does not support this operation
@@ -212,20 +230,28 @@ void wc_CryptoCb_InfoString(wc_CryptoInfo* info);
212230
Aes aes;
213231
byte key[32] = { /* 256-bit key */ };
214232
int devId = 1;
233+
int capabilities = 0;
215234

216-
// Register your CryptoCB callback first
235+
/* Register your CryptoCB callback first */
217236
wc_CryptoCb_RegisterDevice(devId, myCryptoCallback, NULL);
218237

219238
wc_AesInit(&aes, NULL, devId);
220-
// wc_AesGcmSetKey internally calls wc_CryptoCb_AesSetKey
221-
if (wc_AesGcmSetKey(&aes, key, sizeof(key)) == 0) {
222-
// Key successfully imported to device via callback
223-
// aes.devCtx now contains device handle
224-
// Subsequent AES-GCM operations will use the device
239+
/* wc_AesGcmSetKey internally calls wc_CryptoCb_AesSetKey */
240+
if (wc_CryptoCb_AesSetKey(&aes, key, sizeof(key), &capabilities) == 0) {
241+
/* Key successfully imported to device via callback */
242+
/* aes.devCtx now contains device handle */
243+
/* Check if GCM acceleration is supported */
244+
if (capabilities & WC_CRYPTOCB_AES_GCM) {
245+
/* GCM acceleration active */
246+
/* Note: In TLS builds, tables still generated for fallback */
247+
/* In crypto-only builds, tables skipped (true offload) */
248+
}
225249
}
226250
\endcode
227251

228252
\sa wc_CryptoCb_RegisterDevice
229253
\sa wc_AesInit
254+
\sa WC_CRYPTOCB_AES_GCM
230255
*/
231-
int wc_CryptoCb_AesSetKey(Aes* aes, const byte* key, word32 keySz);
256+
int wc_CryptoCb_AesSetKey(Aes* aes, const byte* key, word32 keySz,
257+
int* capabilities);

doc/dox_comments/header_files/doxygen_pages.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,15 @@
7979
8080
When enabled via WOLF_CRYPTO_CB_AES_SETKEY, wolfSSL allows AES keys
8181
to be imported into external cryptographic devices using the Crypto
82-
Callback interface. In key import mode, AES keys are not retained in
83-
wolfCrypt memory. Instead, an opaque device handle is used for all
84-
subsequent AES-GCM operations.
82+
Callback interface.
83+
84+
**TLS Builds (Default):**
85+
- Keys ARE retained in memory for fallback.
86+
- Provides acceleration, not key isolation.
87+
88+
**Crypto-Only Builds (--disable-tls):**
89+
- Keys NOT retained in memory.
90+
- Provides true offload with key isolation.
8591
8692
This mode is compatible with Secure Elements and hardware-backed
8793
key storage and is intended for protecting TLS traffic keys.

0 commit comments

Comments
 (0)