@@ -44807,6 +44807,271 @@ static int test_CryptoCb_Func(int thisDevId, wc_CryptoInfo* info, void* ctx)
4480744807 }
4480844808 #endif /* HAVE_ED25519 */
4480944809 }
44810+ #ifdef WOLF_CRYPTO_CB_COPY
44811+ else if (info->algo_type == WC_ALGO_TYPE_COPY) {
44812+ #ifdef DEBUG_WOLFSSL
44813+ fprintf(stderr, "test_CryptoCb_Func: Copy Algo=%d Type=%d\n",
44814+ info->copy.algo, info->copy.type);
44815+ #endif
44816+ if (info->copy.algo == WC_ALGO_TYPE_HASH) {
44817+ switch (info->copy.type) {
44818+ #ifndef NO_SHA
44819+ case WC_HASH_TYPE_SHA:
44820+ {
44821+ wc_Sha* src = (wc_Sha*)info->copy.src;
44822+ wc_Sha* dst = (wc_Sha*)info->copy.dst;
44823+ src->devId = INVALID_DEVID;
44824+ ret = wc_ShaCopy(src, dst);
44825+ src->devId = thisDevId;
44826+ if (ret == 0) {
44827+ dst->devId = thisDevId;
44828+ }
44829+ break;
44830+ }
44831+ #endif
44832+ #ifdef WOLFSSL_SHA224
44833+ case WC_HASH_TYPE_SHA224:
44834+ {
44835+ wc_Sha224* src = (wc_Sha224*)info->copy.src;
44836+ wc_Sha224* dst = (wc_Sha224*)info->copy.dst;
44837+ src->devId = INVALID_DEVID;
44838+ ret = wc_Sha224Copy(src, dst);
44839+ src->devId = thisDevId;
44840+ if (ret == 0) {
44841+ dst->devId = thisDevId;
44842+ }
44843+ break;
44844+ }
44845+ #endif
44846+ #ifndef NO_SHA256
44847+ case WC_HASH_TYPE_SHA256:
44848+ {
44849+ wc_Sha256* src = (wc_Sha256*)info->copy.src;
44850+ wc_Sha256* dst = (wc_Sha256*)info->copy.dst;
44851+ /* set devId to invalid, so software is used */
44852+ src->devId = INVALID_DEVID;
44853+ ret = wc_Sha256Copy(src, dst);
44854+
44855+ /* reset devId */
44856+ src->devId = thisDevId;
44857+ if (ret == 0) {
44858+ /* Set the devId of the destination to the same */
44859+ /* since we used the software implementation of copy */
44860+ /* so dst would have been set to INVALID_DEVID */
44861+ dst->devId = thisDevId;
44862+ }
44863+ break;
44864+ }
44865+ #endif /* !NO_SHA256 */
44866+ #ifdef WOLFSSL_SHA384
44867+ case WC_HASH_TYPE_SHA384:
44868+ {
44869+ wc_Sha384* src = (wc_Sha384*)info->copy.src;
44870+ wc_Sha384* dst = (wc_Sha384*)info->copy.dst;
44871+ src->devId = INVALID_DEVID;
44872+ ret = wc_Sha384Copy(src, dst);
44873+ src->devId = thisDevId;
44874+ if (ret == 0) {
44875+ dst->devId = thisDevId;
44876+ }
44877+ break;
44878+ }
44879+ #endif
44880+ #ifdef WOLFSSL_SHA512
44881+ case WC_HASH_TYPE_SHA512:
44882+ {
44883+ wc_Sha512* src = (wc_Sha512*)info->copy.src;
44884+ wc_Sha512* dst = (wc_Sha512*)info->copy.dst;
44885+ src->devId = INVALID_DEVID;
44886+ ret = wc_Sha512Copy(src, dst);
44887+ src->devId = thisDevId;
44888+ if (ret == 0) {
44889+ dst->devId = thisDevId;
44890+ }
44891+ break;
44892+ }
44893+ #endif
44894+ #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
44895+ case WC_HASH_TYPE_SHA3_224:
44896+ {
44897+ wc_Sha3* src = (wc_Sha3*)info->copy.src;
44898+ wc_Sha3* dst = (wc_Sha3*)info->copy.dst;
44899+ src->devId = INVALID_DEVID;
44900+ ret = wc_Sha3_224_Copy(src, dst);
44901+ src->devId = thisDevId;
44902+ if (ret == 0) {
44903+ dst->devId = thisDevId;
44904+ }
44905+ break;
44906+ }
44907+ #endif
44908+ #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
44909+ case WC_HASH_TYPE_SHA3_256:
44910+ {
44911+ wc_Sha3* src = (wc_Sha3*)info->copy.src;
44912+ wc_Sha3* dst = (wc_Sha3*)info->copy.dst;
44913+ src->devId = INVALID_DEVID;
44914+ ret = wc_Sha3_256_Copy(src, dst);
44915+ src->devId = thisDevId;
44916+ if (ret == 0) {
44917+ dst->devId = thisDevId;
44918+ }
44919+ break;
44920+ }
44921+ #endif
44922+ #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384)
44923+ case WC_HASH_TYPE_SHA3_384:
44924+ {
44925+ wc_Sha3* src = (wc_Sha3*)info->copy.src;
44926+ wc_Sha3* dst = (wc_Sha3*)info->copy.dst;
44927+ src->devId = INVALID_DEVID;
44928+ ret = wc_Sha3_384_Copy(src, dst);
44929+ src->devId = thisDevId;
44930+ if (ret == 0) {
44931+ dst->devId = thisDevId;
44932+ }
44933+ break;
44934+ }
44935+ #endif
44936+ #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512)
44937+ case WC_HASH_TYPE_SHA3_512:
44938+ {
44939+ wc_Sha3* src = (wc_Sha3*)info->copy.src;
44940+ wc_Sha3* dst = (wc_Sha3*)info->copy.dst;
44941+ src->devId = INVALID_DEVID;
44942+ ret = wc_Sha3_512_Copy(src, dst);
44943+ src->devId = thisDevId;
44944+ if (ret == 0) {
44945+ dst->devId = thisDevId;
44946+ }
44947+ break;
44948+ }
44949+ #endif
44950+ default:
44951+ ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
44952+ break;
44953+ }
44954+ }
44955+ else {
44956+ ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
44957+ }
44958+ }
44959+ #endif /* WOLF_CRYPTO_CB_COPY */
44960+ #ifdef WOLF_CRYPTO_CB_FREE
44961+ else if (info->algo_type == WC_ALGO_TYPE_FREE) {
44962+ #ifdef DEBUG_WOLFSSL
44963+ fprintf(stderr, "test_CryptoCb_Func: Free Algo=%d Type=%d\n",
44964+ info->free.algo, info->free.type);
44965+ #endif
44966+
44967+ if (info->free.algo == WC_ALGO_TYPE_HASH) {
44968+ switch (info->free.type) {
44969+ #ifndef NO_SHA
44970+ case WC_HASH_TYPE_SHA:
44971+ {
44972+ wc_Sha* sha = (wc_Sha*)info->free.obj;
44973+ sha->devId = INVALID_DEVID;
44974+ wc_ShaFree(sha);
44975+ ret = 0;
44976+ break;
44977+ }
44978+ #endif
44979+ #ifdef WOLFSSL_SHA224
44980+ case WC_HASH_TYPE_SHA224:
44981+ {
44982+ wc_Sha224* sha = (wc_Sha224*)info->free.obj;
44983+ sha->devId = INVALID_DEVID;
44984+ wc_Sha224Free(sha);
44985+ ret = 0;
44986+ break;
44987+ }
44988+ #endif
44989+ #ifndef NO_SHA256
44990+ case WC_HASH_TYPE_SHA256:
44991+ {
44992+ wc_Sha256* sha = (wc_Sha256*)info->free.obj;
44993+
44994+ /* set devId to invalid, so software is used */
44995+ sha->devId = INVALID_DEVID;
44996+
44997+ /* Call the actual free function */
44998+ wc_Sha256Free(sha);
44999+
45000+ /* Note: devId doesn't need to be restored as object is freed */
45001+ ret = 0;
45002+ break;
45003+ }
45004+ #endif
45005+ #ifdef WOLFSSL_SHA384
45006+ case WC_HASH_TYPE_SHA384:
45007+ {
45008+ wc_Sha384* sha = (wc_Sha384*)info->free.obj;
45009+ sha->devId = INVALID_DEVID;
45010+ wc_Sha384Free(sha);
45011+ ret = 0;
45012+ break;
45013+ }
45014+ #endif
45015+ #ifdef WOLFSSL_SHA512
45016+ case WC_HASH_TYPE_SHA512:
45017+ {
45018+ wc_Sha512* sha = (wc_Sha512*)info->free.obj;
45019+ sha->devId = INVALID_DEVID;
45020+ wc_Sha512Free(sha);
45021+ ret = 0;
45022+ break;
45023+ }
45024+ #endif
45025+ #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
45026+ case WC_HASH_TYPE_SHA3_224:
45027+ {
45028+ wc_Sha3* sha = (wc_Sha3*)info->free.obj;
45029+ sha->devId = INVALID_DEVID;
45030+ wc_Sha3_224_Free(sha);
45031+ ret = 0;
45032+ break;
45033+ }
45034+ #endif
45035+ #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
45036+ case WC_HASH_TYPE_SHA3_256:
45037+ {
45038+ wc_Sha3* sha = (wc_Sha3*)info->free.obj;
45039+ sha->devId = INVALID_DEVID;
45040+ wc_Sha3_256_Free(sha);
45041+ ret = 0;
45042+ break;
45043+ }
45044+ #endif
45045+ #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384)
45046+ case WC_HASH_TYPE_SHA3_384:
45047+ {
45048+ wc_Sha3* sha = (wc_Sha3*)info->free.obj;
45049+ sha->devId = INVALID_DEVID;
45050+ wc_Sha3_384_Free(sha);
45051+ ret = 0;
45052+ break;
45053+ }
45054+ #endif
45055+ #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512)
45056+ case WC_HASH_TYPE_SHA3_512:
45057+ {
45058+ wc_Sha3* sha = (wc_Sha3*)info->free.obj;
45059+ sha->devId = INVALID_DEVID;
45060+ wc_Sha3_512_Free(sha);
45061+ ret = 0;
45062+ break;
45063+ }
45064+ #endif
45065+ default:
45066+ ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
45067+ break;
45068+ }
45069+ }
45070+ else {
45071+ ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
45072+ }
45073+ }
45074+ #endif /* WOLF_CRYPTO_CB_FREE */
4481045075 (void)thisDevId;
4481145076 (void)keyFormat;
4481245077
0 commit comments