Skip to content

Commit

Permalink
Revert "Do not allocate arrays of _m128i on the stack"
Browse files Browse the repository at this point in the history
This reverts commit f7e0f9d.
  • Loading branch information
Legrandin committed Nov 11, 2019
1 parent a730de0 commit 31c23ca
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions src/AESNI.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ FAKE_INIT(raw_aesni)
#define BLOCK_SIZE 16

struct block_state {
__m128i *erk; /** Round keys for encryption (11, 13 or 15 elements) **/
__m128i *drk; /** Round keys for decryption **/
__m128i *tmp_rk;
__m128i *erk; /** Round keys for encryption (11, 13 or 15 elements) **/
__m128i *drk; /** Round keys for decryption **/
unsigned rounds;
};

Expand Down Expand Up @@ -141,18 +140,16 @@ static FUNC_SSE2 int expand_key(__m128i *erk, __m128i *drk, const uint8_t *key,
static FUNC_SSE2 int AESNI_encrypt(const BlockBase *bb, const uint8_t *in, uint8_t *out, size_t data_len)
{
unsigned rounds;
__m128i r[14+1];
const struct block_state *state;
unsigned k;
__m128i *r;

if ((bb == NULL) || (in == NULL) || (out == NULL))
return ERR_NULL;

state = &((AESNI_State*)bb)->algo_state;
rounds = state->rounds;

r = state->tmp_rk;

if (rounds > 14)
return ERR_NR_ROUNDS;

Expand Down Expand Up @@ -252,9 +249,9 @@ static FUNC_SSE2 int AESNI_encrypt(const BlockBase *bb, const uint8_t *in, uint8
static FUNC_SSE2 int AESNI_decrypt(const BlockBase *bb, const uint8_t *in, uint8_t *out, size_t data_len)
{
unsigned rounds;
__m128i r[14+1];
const struct block_state *state;
unsigned k;
__m128i *r;

if ((bb == NULL) || (in == NULL) || (out == NULL))
return ERR_NULL;
Expand All @@ -265,8 +262,6 @@ static FUNC_SSE2 int AESNI_decrypt(const BlockBase *bb, const uint8_t *in, uint8
if (rounds > 14)
return ERR_NR_ROUNDS;

r = state->tmp_rk;

for (k=0; k<=rounds; k++) {
r[k] = state->drk[k];
}
Expand Down Expand Up @@ -416,12 +411,6 @@ EXPORT_SYM int AESNI_start_operation(const uint8_t key[], size_t key_len, AESNI_
goto error;
}

state->tmp_rk = align_alloc(Nb*(Nr+1)*sizeof(uint32_t), 16);
if (state->tmp_rk == NULL) {
result = ERR_MEMORY;
goto error;
}

result = expand_key(state->erk, state->drk, key, (unsigned)key_len/4, Nr);
if (result) {
goto error;
Expand All @@ -431,7 +420,6 @@ EXPORT_SYM int AESNI_start_operation(const uint8_t key[], size_t key_len, AESNI_
error:
align_free(state->erk);
align_free(state->drk);
align_free(state->tmp_rk);
free(*pResult);
return result;
}
Expand Down

0 comments on commit 31c23ca

Please sign in to comment.