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.
This commit is contained in:
Dag-Erling Smørgrav 2017-03-03 23:34:49 +01:00
parent 95b2518eed
commit d419d7388a
2 changed files with 5 additions and 7 deletions

View file

@ -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);

View file

@ -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++;