@@ -180,3 +180,63 @@ void wc_CryptoCb_SetDeviceFindCb(CryptoDevCallbackFind cb);
180180 \sa wc_CryptoCb_RegisterDevice
181181*/
182182void wc_CryptoCb_InfoString (wc_CryptoInfo * info );
183+
184+ /*!
185+ \ingroup CryptoCb
186+
187+ \brief Import an AES key into a CryptoCB device for hardware offload.
188+
189+ This function allows AES keys to be handled by an external device
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.
192+
193+ When CryptoCB AES SetKey support is enabled
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 (devKey) 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 in wolfCrypt memory (true key isolation)
204+ - GCM tables skipped (true hardware offload)
205+ - Callback must handle all GCM operations (SetKey, Encrypt, Decrypt, Free)
206+
207+ If the callback returns success (0), full AES-GCM offload is assumed.
208+ The callback must handle SetKey, Encrypt, Decrypt, and Free operations.
209+
210+ \param aes AES context
211+ \param key Pointer to raw AES key material
212+ \param keySz Size of key in bytes
213+
214+ \return 0 on success
215+ \return CRYPTOCB_UNAVAILABLE if device does not support this operation
216+ \return BAD_FUNC_ARG on invalid parameters
217+
218+ _Example_
219+ \code
220+ #include <wolfssl/wolfcrypt/cryptocb.h>
221+ #include <wolfssl/wolfcrypt/aes.h>
222+
223+ Aes aes;
224+ byte key[32] = { /* 256-bit key */ };
225+ int devId = 1 ;
226+
227+ /* Register your CryptoCB callback first */
228+ wc_CryptoCb_RegisterDevice (devId , myCryptoCallback , NULL );
229+
230+ wc_AesInit (& aes , NULL , devId );
231+ /* wc_AesGcmSetKey internally calls wc_CryptoCb_AesSetKey */
232+ if (wc_CryptoCb_AesSetKey (& aes , key , sizeof (key )) == 0 ) {
233+ /* Key successfully imported to device via callback */
234+ /* aes.devCtx now contains device handle */
235+ /* Full GCM offload is assumed - callback must handle all operations */
236+ }
237+ \endcode
238+
239+ \sa wc_CryptoCb_RegisterDevice
240+ \sa wc_AesInit
241+ * /
242+ int wc_CryptoCb_AesSetKey (Aes * aes , const byte * key , word32 keySz );
0 commit comments