@@ -80,8 +80,8 @@ static const char* GetAlgoTypeStr(int algo)
8080 case WC_ALGO_TYPE_HMAC : return "HMAC" ;
8181 case WC_ALGO_TYPE_CMAC : return "CMAC" ;
8282 case WC_ALGO_TYPE_CERT : return "Cert" ;
83- case WC_ALGO_TYPE_KDF :
84- return "KDF " ;
83+ case WC_ALGO_TYPE_KDF : return "KDF" ;
84+ case WC_ALGO_TYPE_COPY : return "Copy " ;
8585 }
8686 return NULL ;
8787}
@@ -174,6 +174,16 @@ static const char* GetCryptoCbCmdTypeStr(int type)
174174}
175175#endif
176176
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 */
186+
177187#if (defined(HAVE_HKDF ) && !defined(NO_HMAC )) || defined(HAVE_CMAC_KDF )
178188static const char * GetKdfTypeStr (int type )
179189{
@@ -253,6 +263,13 @@ void wc_CryptoCb_InfoString(wc_CryptoInfo* info)
253263 GetCryptoCbCmdTypeStr (info -> cmd .type ), info -> cmd .type );
254264 }
255265#endif
266+ #ifndef NO_COPY_CB
267+ else if (info -> algo_type == WC_ALGO_TYPE_COPY ) {
268+ printf ("Crypto CB: %s %s (%d)\n" ,
269+ GetAlgoTypeStr (info -> algo_type ),
270+ GetCryptoCbCopyTypeStr (info -> copy .type ), info -> copy .type );
271+ }
272+ #endif
256273#if (defined(HAVE_HKDF ) && !defined(NO_HMAC )) || \
257274 defined(HAVE_CMAC_KDF )
258275 else if (info -> algo_type == WC_ALGO_TYPE_KDF ) {
@@ -2028,6 +2045,41 @@ int wc_CryptoCb_Hkdf(int hashType, const byte* inKey, word32 inKeySz,
20282045}
20292046#endif /* HAVE_HKDF && !NO_HMAC */
20302047
2048+ #ifndef NO_COPY_CB
2049+ /* General copy callback function for algorithm structures
2050+ * devId: The device ID to use for the callback
2051+ * copyType: The type of structure being copied (enum wc_CryptoCbCopyType)
2052+ * src: Pointer to source structure
2053+ * dst: Pointer to destination structure
2054+ * Returns: 0 on success, negative on error, CRYPTOCB_UNAVAILABLE if not handled
2055+ */
2056+ int wc_CryptoCb_Copy (int devId , int copyType , void * src , void * dst )
2057+ {
2058+ int ret = WC_NO_ERR_TRACE (CRYPTOCB_UNAVAILABLE );
2059+ CryptoCb * dev ;
2060+
2061+ /* Validate inputs */
2062+ if (src == NULL || dst == NULL ) {
2063+ return BAD_FUNC_ARG ;
2064+ }
2065+
2066+ /* Find registered callback device */
2067+ dev = wc_CryptoCb_FindDevice (devId , WC_ALGO_TYPE_COPY );
2068+ if (dev && dev -> cb ) {
2069+ wc_CryptoInfo cryptoInfo ;
2070+ XMEMSET (& cryptoInfo , 0 , sizeof (cryptoInfo ));
2071+ cryptoInfo .algo_type = WC_ALGO_TYPE_COPY ;
2072+ cryptoInfo .copy .type = copyType ;
2073+ cryptoInfo .copy .src = src ;
2074+ cryptoInfo .copy .dst = dst ;
2075+
2076+ ret = dev -> cb (dev -> devId , & cryptoInfo , dev -> ctx );
2077+ }
2078+
2079+ return wc_CryptoCb_TranslateErrorCode (ret );
2080+ }
2081+ #endif /* !NO_COPY_CB */
2082+
20312083
20322084#if defined(HAVE_CMAC_KDF )
20332085/* Crypto callback for NIST SP 800 56C two-step CMAC KDF. See software
0 commit comments