Skip to content

Commit 77da492

Browse files
Vge0rgerlubos
authored andcommitted
nrf_security: Use static variables in sx_blkcipher_ecb_simple
The in and out dma descriptors variables in sx_blkcipher_ecb_simple takes up around 80 bytes of space in the stack. To optimize the stack usage these variables are now static, the mutex locking was moved before there variables are set so that accessing these from multiple threads is not an issue. Signed-off-by: Georgios Vasilakis <[email protected]>
1 parent b543f8f commit 77da492

File tree

1 file changed

+8
-5
lines changed
  • subsys/nrf_security/src/drivers/cracen/sxsymcrypt/src

1 file changed

+8
-5
lines changed

subsys/nrf_security/src/drivers/cracen/sxsymcrypt/src/blkcipher.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,14 @@ int sx_blkcipher_ecb_simple(uint8_t *key, size_t key_size, uint8_t *input, size_
408408
int status = SX_ERR_HW_PROCESSING;
409409

410410
uint32_t cmd = CMDMA_BLKCIPHER_MODE_SET(BLKCIPHER_MODEID_ECB);
411-
struct sxdesc in_descs[3] = {};
411+
/* Both out_desc and in_descs are used after sx_hw_reserve which locks
412+
* the symmetric mutex, so it is safe to have them as static.
413+
*/
414+
static struct sxdesc out_desc;
415+
static struct sxdesc in_descs[3];
416+
417+
/* This guards the static variables out_desc and in_descs */
418+
sx_hw_reserve(NULL);
412419

413420
in_descs[0].addr = (char *)&cmd;
414421
in_descs[0].sz = DMA_REALIGN | sizeof(cmd);
@@ -425,15 +432,11 @@ int sx_blkcipher_ecb_simple(uint8_t *key, size_t key_size, uint8_t *input, size_
425432
in_descs[2].dmatag = DMATAG_LAST | ba411tags.data;
426433
in_descs[2].next = (void *)1;
427434

428-
struct sxdesc out_desc = {};
429-
430435
out_desc.addr = output;
431436
out_desc.sz = DMA_REALIGN | output_size;
432437
out_desc.next = (void *)1;
433438
out_desc.dmatag = DMATAG_LAST;
434439

435-
sx_hw_reserve(NULL);
436-
437440
#if CONFIG_DCACHE
438441
sys_cache_data_flush_range(in_descs, sizeof(in_descs));
439442
sys_cache_data_flush_range(&out_desc, sizeof(out_desc));

0 commit comments

Comments
 (0)