Skip to content

Commit f1faefe

Browse files
committed
Added callbacks for copy and free to SHA, 224, 384, 512, and SHA3. Also split macros for FREE and COPY Callbacks, and add configure.ac option.
1 parent 0dca3bc commit f1faefe

11 files changed

Lines changed: 701 additions & 46 deletions

File tree

.wolfssl_known_macro_extras

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,6 @@ WOLFSSL_HARDEN_TLS_ALLOW_OLD_TLS
731731
WOLFSSL_HARDEN_TLS_ALLOW_TRUNCATED_HMAC
732732
WOLFSSL_HARDEN_TLS_NO_PKEY_CHECK
733733
WOLFSSL_HARDEN_TLS_NO_SCR_CHECK
734-
WOLFSSL_HAVE_COPY_FREE_CB
735734
WOLFSSL_HOSTNAME_VERIFY_ALT_NAME_ONLY
736735
WOLFSSL_I2D_ECDSA_SIG_ALLOC
737736
WOLFSSL_IAR_ARM_TIME
@@ -918,7 +917,9 @@ WOLFSSL_XMSS_LARGE_SECRET_KEY
918917
WOLFSSL_ZEPHYR
919918
WOLF_ALLOW_BUILTIN
920919
WOLF_CRYPTO_CB_CMD
920+
WOLF_CRYPTO_CB_COPY
921921
WOLF_CRYPTO_CB_FIND
922+
WOLF_CRYPTO_CB_FREE
922923
WOLF_CRYPTO_CB_ONLY_ECC
923924
WOLF_CRYPTO_CB_ONLY_RSA
924925
WOLF_CRYPTO_DEV

configure.ac

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9448,6 +9448,44 @@ then
94489448
AM_CFLAGS="$AM_CFLAGS -DWC_TEST_NO_CRYPTOCB_SW_TEST"
94499449
fi
94509450
9451+
# Crypto Callbacks Utils (Copy/Free/etc)
9452+
AC_ARG_ENABLE([cryptocbutils],
9453+
[AS_HELP_STRING([--enable-cryptocbutils@<:@=copy,free,...@:>@],
9454+
[Enable crypto callback utilities (default: all)])],
9455+
[ ENABLED_CRYPTOCB_UTILS=$enableval ],
9456+
[ ENABLED_CRYPTOCB_UTILS=no ]
9457+
)
9458+
9459+
if test "$ENABLED_CRYPTOCB_UTILS" != "no"; then
9460+
if test "$ENABLED_CRYPTOCB" = "no"; then
9461+
AC_MSG_ERROR([--enable-cryptocbutils requires --enable-cryptocb])
9462+
fi
9463+
9464+
if test "$ENABLED_CRYPTOCB_UTILS" = "yes"; then
9465+
# Enable all utilities
9466+
AM_CFLAGS="$AM_CFLAGS -DWOLF_CRYPTO_CB_COPY -DWOLF_CRYPTO_CB_FREE"
9467+
# Future utilities go here when added
9468+
else
9469+
# Parse comma-separated list
9470+
OIFS="$IFS"
9471+
IFS=','
9472+
for util in $ENABLED_CRYPTOCB_UTILS; do
9473+
case "$util" in
9474+
copy)
9475+
AM_CFLAGS="$AM_CFLAGS -DWOLF_CRYPTO_CB_COPY"
9476+
;;
9477+
free)
9478+
AM_CFLAGS="$AM_CFLAGS -DWOLF_CRYPTO_CB_FREE"
9479+
;;
9480+
# Add future options here (e.g., malloc, realloc, etc)
9481+
*)
9482+
AC_MSG_ERROR([Unknown cryptocbutils option: $util. Valid options: copy, free])
9483+
;;
9484+
esac
9485+
done
9486+
IFS="$OIFS"
9487+
fi
9488+
fi
94519489
94529490
94539491
# Asynchronous Crypto

tests/api.c

Lines changed: 196 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44807,14 +44807,42 @@ static int test_CryptoCb_Func(int thisDevId, wc_CryptoInfo* info, void* ctx)
4480744807
}
4480844808
#endif /* HAVE_ED25519 */
4480944809
}
44810-
#ifdef WOLFSSL_HAVE_COPY_FREE_CB
44810+
#ifdef WOLF_CRYPTO_CB_COPY
4481144811
else if (info->algo_type == WC_ALGO_TYPE_COPY) {
4481244812
#ifdef DEBUG_WOLFSSL
4481344813
fprintf(stderr, "test_CryptoCb_Func: Copy Algo=%d Type=%d\n",
4481444814
info->copy.algo, info->copy.type);
4481544815
#endif
4481644816
if (info->copy.algo == WC_ALGO_TYPE_HASH) {
4481744817
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
4481844846
#ifndef NO_SHA256
4481944847
case WC_HASH_TYPE_SHA256:
4482044848
{
@@ -44835,6 +44863,90 @@ static int test_CryptoCb_Func(int thisDevId, wc_CryptoInfo* info, void* ctx)
4483544863
break;
4483644864
}
4483744865
#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
4483844950
default:
4483944951
ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
4484044952
break;
@@ -44844,6 +44956,8 @@ static int test_CryptoCb_Func(int thisDevId, wc_CryptoInfo* info, void* ctx)
4484444956
ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
4484544957
}
4484644958
}
44959+
#endif /* WOLF_CRYPTO_CB_COPY */
44960+
#ifdef WOLF_CRYPTO_CB_FREE
4484744961
else if (info->algo_type == WC_ALGO_TYPE_FREE) {
4484844962
#ifdef DEBUG_WOLFSSL
4484944963
fprintf(stderr, "test_CryptoCb_Func: Free Algo=%d Type=%d\n",
@@ -44852,6 +44966,26 @@ static int test_CryptoCb_Func(int thisDevId, wc_CryptoInfo* info, void* ctx)
4485244966

4485344967
if (info->free.algo == WC_ALGO_TYPE_HASH) {
4485444968
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
4485544989
#ifndef NO_SHA256
4485644990
case WC_HASH_TYPE_SHA256:
4485744991
{
@@ -44867,6 +45001,66 @@ static int test_CryptoCb_Func(int thisDevId, wc_CryptoInfo* info, void* ctx)
4486745001
ret = 0;
4486845002
break;
4486945003
}
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+
}
4487045064
#endif
4487145065
default:
4487245066
ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
@@ -44877,7 +45071,7 @@ static int test_CryptoCb_Func(int thisDevId, wc_CryptoInfo* info, void* ctx)
4487745071
ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
4487845072
}
4487945073
}
44880-
#endif /* WOLFSSL_HAVE_COPY_FREE_CB */
45074+
#endif /* WOLF_CRYPTO_CB_FREE */
4488145075
(void)thisDevId;
4488245076
(void)keyFormat;
4488345077

0 commit comments

Comments
 (0)