Skip to content

Commit

Permalink
Updating Based on Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
night1rider committed Sep 19, 2024
1 parent 98e5cbe commit f2ccfb3
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 30 deletions.
5 changes: 0 additions & 5 deletions wolfcrypt/src/cryptocb.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@
#ifdef WOLFSSL_CAAM
#include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
#endif

#if defined (WOLFSSL_MAX3266X) || defined (WOLFSSL_MAX3266X_OLD)
#include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
#endif

/* TODO: Consider linked list with mutex */
#ifndef MAX_CRYPTO_DEVID_CALLBACKS
#define MAX_CRYPTO_DEVID_CALLBACKS 8
Expand Down
11 changes: 3 additions & 8 deletions wolfcrypt/src/port/arm/armv8-sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ static int InitSha256(wc_Sha256* sha256)
sha256->flags = 0;
#endif

#ifdef WOLF_CRYPTO_CB
sha256->devId = wc_CryptoCb_DefaultDevID();
#endif

return ret;
}

Expand Down Expand Up @@ -1530,6 +1526,9 @@ int wc_InitSha256_ex(wc_Sha256* sha256, void* heap, int devId)

sha256->heap = heap;
#ifdef WOLF_CRYPTO_CB
if (devId == NULL) { /* If NULL is passed set devId to Default Id */
devId = wc_CryptoCb_DefaultDevID();
}
sha256->devId = devId;
sha256->devCtx = NULL;
#endif
Expand Down Expand Up @@ -1628,11 +1627,7 @@ int wc_Sha256Final(wc_Sha256* sha256, byte* hash)
if (ret != 0)
return ret;

#ifdef WOLF_CRYPTO_CB /* Use to reset state but keep devId info */
return wc_InitSha256_ex(sha256, sha256->heap, sha256->devId);
#else
return InitSha256(sha256); /* reset state */
#endif
}

int wc_Sha256GetHash(wc_Sha256* sha256, byte* hash)
Expand Down
6 changes: 6 additions & 0 deletions wolfcrypt/src/port/arm/armv8-sha512.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ static int InitSha512_Family(wc_Sha512* sha512, void* heap, int devId,
sha512->W = NULL;
#endif
#ifdef WOLF_CRYPTO_CB
if (devId == NULL) { /* If NULL is passed set devId to Default Id */
devId = wc_CryptoCb_DefaultDevID();
}
sha512->devId = devId;
sha512->devCtx = NULL;
#endif
Expand Down Expand Up @@ -846,6 +849,9 @@ int wc_InitSha384_ex(wc_Sha384* sha384, void* heap, int devId)
sha384->W = NULL;
#endif
#ifdef WOLF_CRYPTO_CB
if (devId == NULL) { /* If NULL is passed set devId to Default Id */
devId = wc_CryptoCb_DefaultDevID();
}
sha384->devId = devId;
sha384->devCtx = NULL;
#endif
Expand Down
1 change: 0 additions & 1 deletion wolfcrypt/src/port/maxim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ Crypto Callbacks only support using the hardware for these Algorithms:
- AES ECB: 128, 192, 256
- AES CBC: 128, 192, 256
- SHA-1
- SHA-224
- SHA-256
- SHA-384
- SHA-512
Expand Down
9 changes: 4 additions & 5 deletions wolfcrypt/src/sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@ int wc_InitSha_ex(wc_Sha* sha, void* heap, int devId)

sha->heap = heap;
#ifdef WOLF_CRYPTO_CB
if (devId == NULL) { /* If NULL is passed set devId to Default Id */
devId = wc_CryptoCb_DefaultDevID();
}
sha->devId = devId;
sha->devCtx = NULL;
#endif
Expand Down Expand Up @@ -1014,11 +1017,7 @@ if (sha->ctx.mode == ESP32_SHA_HW) {
/* we'll always reset state upon exit and return the error code from above,
* which may cause fall back to SW if HW is busy. we do not return result
* of initSha here */
#ifdef WOLF_CRYPTO_CB /* Use to reset state but keep devId info */
(void)wc_InitSha_ex(sha, sha->heap, sha->devId);
#else
(void)InitSha(sha); /* reset state */
#endif
(void)InitSha(sha); /* reset state */
return ret;
}

Expand Down
11 changes: 3 additions & 8 deletions wolfcrypt/src/sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,6 @@ static int InitSha256(wc_Sha256* sha256)
#endif
#endif

#ifdef WOLF_CRYPTO_CB
sha256->devId = wc_CryptoCb_DefaultDevID();
#endif

#ifdef WOLFSSL_MAXQ10XX_CRYPTO
XMEMSET(&sha256->maxq_ctx, 0, sizeof(sha256->maxq_ctx));
#endif
Expand Down Expand Up @@ -1093,6 +1089,9 @@ static int InitSha256(wc_Sha256* sha256)

sha256->heap = heap;
#ifdef WOLF_CRYPTO_CB
if (devId == NULL) { /* If NULL is passed set devId to Default Id */
devId = wc_CryptoCb_DefaultDevID();
}
sha256->devId = devId;
sha256->devCtx = NULL;
#endif
Expand Down Expand Up @@ -1740,11 +1739,7 @@ static int InitSha256(wc_Sha256* sha256)
#endif
XMEMCPY(hash, sha256->digest, WC_SHA256_DIGEST_SIZE);

#ifdef WOLF_CRYPTO_CB /* Use to reset state but keep devId info */
return wc_InitSha256_ex(sha256, sha256->heap, sha256->devId);
#else
return InitSha256(sha256); /* reset state */
#endif
}

#if defined(OPENSSL_EXTRA) || defined(HAVE_CURL)
Expand Down
6 changes: 6 additions & 0 deletions wolfcrypt/src/sha512.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,9 @@ static int InitSha512_Family(wc_Sha512* sha512, void* heap, int devId,
sha512->W = NULL;
#endif
#ifdef WOLF_CRYPTO_CB
if (devId == NULL) { /* If NULL is passed set devId to Default Id */
devId = wc_CryptoCb_DefaultDevID();
}
sha512->devId = devId;
sha512->devCtx = NULL;
#endif
Expand Down Expand Up @@ -1756,6 +1759,9 @@ int wc_InitSha384_ex(wc_Sha384* sha384, void* heap, int devId)
sha384->W = NULL;
#endif
#ifdef WOLF_CRYPTO_CB
if (devId == NULL) { /* If NULL is passed set devId to Default Id */
devId = wc_CryptoCb_DefaultDevID();
}
sha384->devId = devId;
sha384->devCtx = NULL;
#endif
Expand Down
3 changes: 0 additions & 3 deletions wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
#ifndef WOLFSSL_MAX3266X_DEVID
#define WOLFSSL_MAX3266X_DEVID 9
#endif
#ifndef MAX_CRYPTO_DEVID_CALLBACKS
#define MAX_CRYPTO_DEVID_CALLBACKS WOLFSSL_MAX3266X_DEVID
#endif
#define WC_USE_DEVID WOLFSSL_MAX3266X_DEVID
#include <wolfssl/wolfcrypt/types.h>
#include <wolfssl/wolfcrypt/cryptocb.h>
Expand Down

0 comments on commit f2ccfb3

Please sign in to comment.