From d419d7388a1c4281b712a7b8adca00f2a06078e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Fri, 3 Mar 2017 23:34:49 +0100 Subject: [PATCH] Remove an unnecessary pointer from struct aes_ctx. The rk pointer in struct aes_ctx always pointed to the context's buffer and served no purpose whatsoever, but the compiler had no way of knowing that and could therefore not optimize away assignments to and from it. Note that the removal of rk breaks the ABI, since it changes the size of struct aes_ctx, but we allow ourselves that because neither the API nor the ABI have been fixed yet. --- include/cryb/aes.h | 8 +++----- lib/cipher/cryb_aes.c | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/cryb/aes.h b/include/cryb/aes.h index f2480e4..0804c22 100644 --- a/include/cryb/aes.h +++ b/include/cryb/aes.h @@ -40,7 +40,6 @@ CRYB_BEGIN #define AES_BLOCK_LEN 16 -#define aes_digest cryb_aes_digest #define aes_ctx cryb_aes_ctx #define aes_init cryb_aes_init #define aes_update cryb_aes_update @@ -51,10 +50,9 @@ extern cipher_algorithm aes192_cipher; extern cipher_algorithm aes256_cipher; typedef struct { - int mode; - int nr; - uint32_t *rk; - uint32_t buf[68]; + int mode; + int nr; + uint32_t rk[68]; } aes_ctx; void aes_init(aes_ctx *, cipher_mode, const uint8_t *, size_t); diff --git a/lib/cipher/cryb_aes.c b/lib/cipher/cryb_aes.c index 99c114e..c8511b3 100644 --- a/lib/cipher/cryb_aes.c +++ b/lib/cipher/cryb_aes.c @@ -321,7 +321,7 @@ CRYB_DISABLE_COVERAGE return; CRYB_RESTORE_COVERAGE } - ctx->rk = RK = ctx->buf; + RK = ctx->rk; for (i = 0; i < (keysize >> 2); i++) RK[i] = le32dec(key + (i << 2)); switch (ctx->nr) { @@ -406,7 +406,7 @@ CRYB_DISABLE_COVERAGE return; CRYB_RESTORE_COVERAGE } - ctx->rk = RK = ctx->buf; + RK = ctx->rk; aes_setkey_enc(&cty, key, keysize); SK = cty.rk + cty.nr * 4; *RK++ = *SK++;