aboutsummaryrefslogtreecommitdiff
path: root/aes_keywrap.c
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2018-09-11 19:01:19 -0400
committerPaul Selkirk <paul@psgd.org>2018-09-11 19:01:19 -0400
commite4fa00258cd920d4ea91b024ee007f5b44bac196 (patch)
treef86dfdf941cb16891ef48f6681363dcd1ac5a31b /aes_keywrap.c
parentef175c10a47afba83935918e26900d38eec565cb (diff)
Track Joachim's latest keywrap core - unroll bank-switched memory into a number of core register blocks.
Diffstat (limited to 'aes_keywrap.c')
-rw-r--r--aes_keywrap.c27
1 files changed, 8 insertions, 19 deletions
diff --git a/aes_keywrap.c b/aes_keywrap.c
index 8ef018b..a3e223f 100644
--- a/aes_keywrap.c
+++ b/aes_keywrap.c
@@ -144,8 +144,10 @@ static hal_error_t do_keywrap_core(const hal_core_t *core, uint8_t * const C, co
hal_assert(core != NULL && C != NULL && n > 0);
- /* The core is limited to 128 banks of 512 bytes/64 blocks */
- if (n == 0 || n > 128 * 64)
+ /* n is the number of 64-bit (8-byte) blocks in the input.
+ * KEYWRAP_LEN_R_DATA is the number of 4-byte data registers in the core.
+ */
+ if (n == 0 || n > KEYWRAP_LEN_R_DATA * 2)
return HAL_ERROR_BAD_ARGUMENTS;
/* write the AIV to A */
@@ -157,16 +159,9 @@ static hal_error_t do_keywrap_core(const hal_core_t *core, uint8_t * const C, co
if ((err = hal_io_write(core, KEYWRAP_ADDR_RLEN, (const uint8_t *)&nn, 4)) != HAL_OK)
return err;
- /* write the data to R_DATA, with bank-switching as necessary */
- for (size_t bank = 0; 64 * bank < n; ++bank) {
- uint32_t bb = htonl(bank);
- if ((err = hal_io_write(core, KEYWRAP_ADDR_R_BANK, (const uint8_t *)&bb, 4)) != HAL_OK)
- return err;
- /* R_DATA is 128 32-bit registers, so 64 64-bit blocks or 512 bytes. */
- size_t len = min(n - 64 * bank, 64) * 8;
- if ((err = hal_io_write(core, KEYWRAP_ADDR_R_DATA0, (C + 512 * bank + 8), len)) != HAL_OK)
+ /* write the data to R_DATA */
+ if ((err = hal_io_write(core, KEYWRAP_ADDR_R_DATA, C + 8, 8 * n)) != HAL_OK)
return err;
- }
/* start the wrap/unwrap operation, and wait for it to complete */
if ((err = hal_io_next(core)) != HAL_OK ||
@@ -177,15 +172,9 @@ static hal_error_t do_keywrap_core(const hal_core_t *core, uint8_t * const C, co
if ((err = hal_io_read(core, KEYWRAP_ADDR_A0, C, 8)) != HAL_OK)
return err;
- /* read the data from R_DATA, with bank-switching as necessary */
- for (size_t bank = 0; 64 * bank < n; ++bank) {
- uint32_t bb = htonl(bank);
- if ((err = hal_io_write(core, KEYWRAP_ADDR_R_BANK, (const uint8_t *)&bb, 4)) != HAL_OK)
+ /* read the data to R_DATA */
+ if ((err = hal_io_read(core, KEYWRAP_ADDR_R_DATA, C + 8, 8 * n)) != HAL_OK)
return err;
- size_t len = min(n - 64 * bank, 64) * 8;
- if ((err = hal_io_read(core, KEYWRAP_ADDR_R_DATA0, (C + 512 * bank + 8), len)) != HAL_OK)
- return err;
- }
return HAL_OK;
}