@@ -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 );
0 commit comments