|
10 | 10 | #include <stddef.h> |
11 | 11 | #include <stdint.h> |
12 | 12 | #include "internal.h" |
| 13 | +#include "nrf-psa-crypto-user-config.h" |
13 | 14 |
|
14 | | -#ifndef SX_HASH_PRIV_SZ |
| 15 | +/* These are not magic numbers, the number here is the size in bytes of the |
| 16 | + * extramem field of sxhash. The extra memory holds the data for saving/resuming |
| 17 | + * the state and should have the size of statesz + maxpadsz. |
| 18 | + * The size here is the MAX of this sum from the enabled algorithms. |
| 19 | + * |
| 20 | + * !!! ORDER MATTERS !!! |
| 21 | + */ |
| 22 | +#if defined(PSA_NEED_CRACEN_SHA3_224) |
15 | 23 | #define SX_HASH_PRIV_SZ 344 |
| 24 | +#elif defined(PSA_NEED_CRACEN_SHA3_256) |
| 25 | +/* SHAKE256 has the same size but doesn't have a PSA_NEED yet */ |
| 26 | +#define SX_HASH_PRIV_SZ 336 |
| 27 | +#elif defined(PSA_NEED_CRACEN_SHA3_384) |
| 28 | +#define SX_HASH_PRIV_SZ 304 |
| 29 | +#elif defined(PSA_NEED_CRACEN_SHA3_512) |
| 30 | +#define SX_HASH_PRIV_SZ 272 |
| 31 | +#elif defined(PSA_NEED_CRACEN_SHA_512) || defined(PSA_NEED_CRACEN_SHA_384) |
| 32 | +#define SX_HASH_PRIV_SZ 208 |
| 33 | +#elif defined(PSA_NEED_CRACEN_SHA_256) || defined(PSA_NEED_CRACEN_SHA_224) |
| 34 | +/* SM3 has the same size but doesn't have a PSA_NEED yet */ |
| 35 | +#define SX_HASH_PRIV_SZ 104 |
| 36 | +#elif defined(PSA_NEED_CRACEN_SHA_1) |
| 37 | +#define SX_HASH_PRIV_SZ 92 |
| 38 | +#else |
| 39 | +/* A default value is needed to avoid building failures when no hash is |
| 40 | + * enabled. A small number is used because it will enforce a runtime failure |
| 41 | + * if the sx_hash APIs are called while no algorithm is enabled. |
| 42 | + */ |
| 43 | +#define SX_HASH_PRIV_SZ 1 |
16 | 44 | #endif |
17 | 45 |
|
18 | 46 | struct sx_digesttags { |
|
0 commit comments