@@ -81,7 +81,10 @@ static const char* GetAlgoTypeStr(int algo)
8181 case WC_ALGO_TYPE_CMAC : return "CMAC" ;
8282 case WC_ALGO_TYPE_CERT : return "Cert" ;
8383 case WC_ALGO_TYPE_KDF : return "KDF" ;
84+ #ifdef WOLFSSL_HAVE_COPY_FREE_CB
8485 case WC_ALGO_TYPE_COPY : return "Copy" ;
86+ case WC_ALGO_TYPE_FREE : return "Free" ;
87+ #endif /* WOLFSSL_HAVE_COPY_FREE_CB */
8588 }
8689 return NULL ;
8790}
@@ -174,15 +177,6 @@ static const char* GetCryptoCbCmdTypeStr(int type)
174177}
175178#endif
176179
177- #ifndef NO_COPY_CB
178- static const char * GetCryptoCbCopyTypeStr (int type )
179- {
180- switch (type ) {
181- case WC_CRYPTOCB_COPY_TYPE_SHA256 : return "SHA256-Copy" ;
182- }
183- return NULL ;
184- }
185- #endif /* !NO_COPY_CB */
186180
187181#if (defined(HAVE_HKDF ) && !defined(NO_HMAC )) || defined(HAVE_CMAC_KDF )
188182static const char * GetKdfTypeStr (int type )
@@ -263,13 +257,18 @@ void wc_CryptoCb_InfoString(wc_CryptoInfo* info)
263257 GetCryptoCbCmdTypeStr (info -> cmd .type ), info -> cmd .type );
264258 }
265259#endif
266- #ifndef NO_COPY_CB
260+ #ifdef WOLFSSL_HAVE_COPY_FREE_CB
267261 else if (info -> algo_type == WC_ALGO_TYPE_COPY ) {
268- printf ("Crypto CB: %s %s (%d) \n" ,
262+ printf ("Crypto CB: %s %s Type=%d \n" ,
269263 GetAlgoTypeStr (info -> algo_type ),
270- GetCryptoCbCopyTypeStr (info -> copy .type ), info -> copy .type );
264+ GetAlgoTypeStr (info -> copy .algo ), info -> copy .type );
271265 }
272- #endif
266+ else if (info -> algo_type == WC_ALGO_TYPE_FREE ) {
267+ printf ("Crypto CB: %s %s Type=%d\n" ,
268+ GetAlgoTypeStr (info -> algo_type ),
269+ GetAlgoTypeStr (info -> free .algo ), info -> free .type );
270+ }
271+ #endif /* WOLFSSL_HAVE_COPY_FREE_CB */
273272#if (defined(HAVE_HKDF ) && !defined(NO_HMAC )) || \
274273 defined(HAVE_CMAC_KDF )
275274 else if (info -> algo_type == WC_ALGO_TYPE_KDF ) {
@@ -2045,40 +2044,65 @@ int wc_CryptoCb_Hkdf(int hashType, const byte* inKey, word32 inKeySz,
20452044}
20462045#endif /* HAVE_HKDF && !NO_HMAC */
20472046
2048- #ifndef NO_COPY_CB
2047+ #ifdef WOLFSSL_HAVE_COPY_FREE_CB
20492048/* General copy callback function for algorithm structures
20502049 * devId: The device ID to use for the callback
2051- * copyType: The type of structure being copied (enum wc_CryptoCbCopyType)
2050+ * algo: Algorithm type (enum wc_AlgoType) - WC_ALGO_TYPE_HASH, WC_ALGO_TYPE_CIPHER, etc
2051+ * type: Specific type - for HASH: enum wc_HashType, for CIPHER: enum wc_CipherType
20522052 * src: Pointer to source structure
20532053 * dst: Pointer to destination structure
20542054 * Returns: 0 on success, negative on error, CRYPTOCB_UNAVAILABLE if not handled
20552055 */
2056- int wc_CryptoCb_Copy (int devId , int copyType , void * src , void * dst )
2056+ int wc_CryptoCb_Copy (int devId , int algo , int type , void * src , void * dst )
20572057{
20582058 int ret = WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE );
20592059 CryptoCb * dev ;
20602060
2061- /* Validate inputs */
2062- if (src == NULL || dst == NULL ) {
2063- return BAD_FUNC_ARG ;
2064- }
2065-
20662061 /* Find registered callback device */
20672062 dev = wc_CryptoCb_FindDevice (devId , WC_ALGO_TYPE_COPY );
20682063 if (dev && dev -> cb ) {
20692064 wc_CryptoInfo cryptoInfo ;
20702065 XMEMSET (& cryptoInfo , 0 , sizeof (cryptoInfo ));
20712066 cryptoInfo .algo_type = WC_ALGO_TYPE_COPY ;
2072- cryptoInfo .copy .type = copyType ;
2067+ cryptoInfo .copy .algo = algo ;
2068+ cryptoInfo .copy .type = type ;
20732069 cryptoInfo .copy .src = src ;
20742070 cryptoInfo .copy .dst = dst ;
2075-
2071+
20762072 ret = dev -> cb (dev -> devId , & cryptoInfo , dev -> ctx );
20772073 }
2078-
2074+
2075+ return wc_CryptoCb_TranslateErrorCode (ret );
2076+ }
2077+
2078+ /* General free callback function for algorithm structures
2079+ * devId: The device ID to use for the callback
2080+ * algo: Algorithm type (enum wc_AlgoType) - WC_ALGO_TYPE_HASH, WC_ALGO_TYPE_CIPHER, etc
2081+ * type: Specific type - for HASH: enum wc_HashType, for CIPHER: enum wc_CipherType
2082+ * obj: Pointer to object structure to free
2083+ * Returns: 0 on success, negative on error, CRYPTOCB_UNAVAILABLE if not handled
2084+ */
2085+ int wc_CryptoCb_Free (int devId , int algo , int type , void * obj )
2086+ {
2087+ int ret = WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE );
2088+ CryptoCb * dev ;
2089+
2090+ /* Find registered callback device */
2091+ dev = wc_CryptoCb_FindDevice (devId , WC_ALGO_TYPE_FREE );
2092+ if (dev && dev -> cb ) {
2093+ wc_CryptoInfo cryptoInfo ;
2094+ XMEMSET (& cryptoInfo , 0 , sizeof (cryptoInfo ));
2095+ cryptoInfo .algo_type = WC_ALGO_TYPE_FREE ;
2096+ cryptoInfo .free .algo = algo ;
2097+ cryptoInfo .free .type = type ;
2098+ cryptoInfo .free .obj = obj ;
2099+
2100+ ret = dev -> cb (dev -> devId , & cryptoInfo , dev -> ctx );
2101+ }
2102+
20792103 return wc_CryptoCb_TranslateErrorCode (ret );
20802104}
2081- #endif /* !NO_COPY_CB */
2105+ #endif /* WOLFSSL_HAVE_COPY_FREE_CB */
20822106
20832107
20842108#if defined(HAVE_CMAC_KDF )
0 commit comments