|
57 | 57 | #endif |
58 | 58 | #endif |
59 | 59 |
|
| 60 | +/* Enable copy/free callbacks when using callback mode */ |
| 61 | +#if defined(MAX3266X_SHA_CB) |
| 62 | + #ifndef WOLF_CRYPTO_CB_COPY |
| 63 | + #define WOLF_CRYPTO_CB_COPY |
| 64 | + #endif |
| 65 | + #ifndef WOLF_CRYPTO_CB_FREE |
| 66 | + #define WOLF_CRYPTO_CB_FREE |
| 67 | + #endif |
| 68 | +#endif |
| 69 | + |
60 | 70 | /* Crypto HW can be used in parallel on this device */ |
61 | 71 | /* Sets up new Mutexing if desired */ |
62 | 72 | #ifdef WOLFSSL_ALGO_HW_MUTEX |
|
236 | 246 |
|
237 | 247 | #if defined(MAX3266X_SHA) || defined(MAX3266X_SHA_CB) |
238 | 248 |
|
239 | | - /* Need to update this struct accordingly if other SHA Structs change */ |
240 | | - /* This is a generic struct to use so only this is needed */ |
241 | | - |
242 | | - typedef struct { |
243 | | - unsigned char *msg; |
244 | | - unsigned int used; |
245 | | - unsigned int size; |
246 | | - } wc_MXC_Sha; |
| 249 | + /* Use HASH_KEEP to accumulate message data for one-shot TPU hardware */ |
| 250 | + #ifndef WOLFSSL_HASH_KEEP |
| 251 | + #define WOLFSSL_HASH_KEEP |
| 252 | + #endif |
247 | 253 |
|
248 | 254 | #if !defined(NO_SHA) |
249 | 255 | /* Define the SHA digest for an empty string */ |
|
311 | 317 | #endif /* WOLFSSL_SHA512 */ |
312 | 318 |
|
313 | 319 |
|
314 | | - WOLFSSL_LOCAL int wc_MXC_TPU_SHA_Init(wc_MXC_Sha *hash); |
315 | | - WOLFSSL_LOCAL int wc_MXC_TPU_SHA_Update(wc_MXC_Sha *hash, |
316 | | - const unsigned char* data, |
317 | | - unsigned int size); |
318 | | - WOLFSSL_LOCAL int wc_MXC_TPU_SHA_Final(wc_MXC_Sha *hash, |
| 320 | + /* Check for empty message and provide pre-computed digest if so */ |
| 321 | + WOLFSSL_LOCAL int wc_MXC_TPU_SHA_GetDigest(const unsigned char* msg, |
| 322 | + unsigned int msgSz, |
319 | 323 | unsigned char* digest, |
320 | 324 | MXC_TPU_HASH_TYPE algo); |
321 | | - WOLFSSL_LOCAL int wc_MXC_TPU_SHA_GetHash(wc_MXC_Sha *hash, |
| 325 | + /* Compute hash from accumulated message using TPU hardware */ |
| 326 | + WOLFSSL_LOCAL int wc_MXC_TPU_SHA_GetHash(const unsigned char* msg, |
| 327 | + unsigned int msgSz, |
322 | 328 | unsigned char* digest, |
323 | 329 | MXC_TPU_HASH_TYPE algo); |
324 | | - WOLFSSL_LOCAL int wc_MXC_TPU_SHA_Copy(wc_MXC_Sha* src, wc_MXC_Sha* dst); |
325 | | - WOLFSSL_LOCAL void wc_MXC_TPU_SHA_Free(wc_MXC_Sha* hash); |
326 | | - WOLFSSL_LOCAL int wc_MXC_TPU_SHA_GetDigest(wc_MXC_Sha *hash, |
| 330 | + /* Free HASH_KEEP message buffer and reset fields */ |
| 331 | + WOLFSSL_LOCAL void wc_MXC_TPU_SHA_Free(unsigned char** msg, |
| 332 | + unsigned int* used, |
| 333 | + unsigned int* len, |
| 334 | + void* heap); |
| 335 | + /* Free HASH_KEEP message buffer and zero the full SHA context */ |
| 336 | + WOLFSSL_LOCAL void wc_MXC_TPU_SHA_FreeCtx(void* ctx, |
| 337 | + unsigned int ctxSz, |
| 338 | + unsigned char** msg, |
| 339 | + unsigned int* used, |
| 340 | + unsigned int* len, |
| 341 | + void* heap); |
| 342 | + /* Copy SHA context and deep copy HASH_KEEP message buffer */ |
| 343 | + WOLFSSL_LOCAL int wc_MXC_TPU_SHA_Copy(void* src, void* dst, |
| 344 | + unsigned int ctxSz, |
| 345 | + unsigned char** dstMsg, |
| 346 | + unsigned int* dstUsed, |
| 347 | + unsigned int* dstLen, |
| 348 | + void* dstHeap, void* srcHeap); |
| 349 | + /* Compute hash, free message buffer, and reset fields */ |
| 350 | + WOLFSSL_LOCAL int wc_MXC_TPU_SHA_Final(unsigned char** msg, |
| 351 | + unsigned int* used, |
| 352 | + unsigned int* len, |
| 353 | + void* heap, |
327 | 354 | unsigned char* digest, |
328 | 355 | MXC_TPU_HASH_TYPE algo); |
329 | 356 |
|
330 | 357 |
|
331 | | -#endif /* defined(MAX3266X_SHA) && !defined(WOLF_CRYPTO_CB) */ |
| 358 | +#endif /* defined(MAX3266X_SHA) || defined(MAX3266X_SHA_CB) */ |
332 | 359 |
|
333 | 360 | #if defined(MAX3266X_MATH) |
334 | 361 | #define WOLFSSL_USE_HW_MP |
|
0 commit comments