aesni: Align all class instances to 16 byte boundaries

While the required members are aligned in the struct as required, on 32-bit
platforms the allocator aligns the structures itself to 8 bytes only. This
results in non-aligned struct members, and invalid memory accesses.
This commit is contained in:
Martin Willi
2015-04-15 13:44:40 +02:00
parent 0c83225883
commit 93f0080265
7 changed files with 14 additions and 14 deletions
+2 -2
View File
@@ -693,7 +693,7 @@ METHOD(crypter_t, destroy, void,
{ {
DESTROY_IF(this->ekey); DESTROY_IF(this->ekey);
DESTROY_IF(this->dkey); DESTROY_IF(this->dkey);
free(this); free_align(this);
} }
/** /**
@@ -720,7 +720,7 @@ aesni_cbc_t *aesni_cbc_create(encryption_algorithm_t algo, size_t key_size)
return NULL; return NULL;
} }
INIT(this, INIT_ALIGN(this, sizeof(__m128i),
.public = { .public = {
.crypter = { .crypter = {
.encrypt = _encrypt, .encrypt = _encrypt,
+2 -2
View File
@@ -902,7 +902,7 @@ METHOD(aead_t, destroy, void,
{ {
DESTROY_IF(this->key); DESTROY_IF(this->key);
this->iv_gen->destroy(this->iv_gen); this->iv_gen->destroy(this->iv_gen);
free(this); free_align(this);
} }
/** /**
@@ -949,7 +949,7 @@ aesni_ccm_t *aesni_ccm_create(encryption_algorithm_t algo,
return NULL; return NULL;
} }
INIT(this, INIT_ALIGN(this, sizeof(__m128i),
.public = { .public = {
.aead = { .aead = {
.encrypt = _encrypt, .encrypt = _encrypt,
+2 -2
View File
@@ -314,7 +314,7 @@ METHOD(mac_t, destroy, void,
DESTROY_IF(this->k); DESTROY_IF(this->k);
memwipe(&this->k1, sizeof(this->k1)); memwipe(&this->k1, sizeof(this->k1));
memwipe(&this->k2, sizeof(this->k2)); memwipe(&this->k2, sizeof(this->k2));
free(this); free_align(this);
} }
/* /*
@@ -324,7 +324,7 @@ mac_t *aesni_cmac_create(encryption_algorithm_t algo, size_t key_size)
{ {
private_mac_t *this; private_mac_t *this;
INIT(this, INIT_ALIGN(this, sizeof(__m128i),
.public = { .public = {
.get_mac = _get_mac, .get_mac = _get_mac,
.get_mac_size = _get_mac_size, .get_mac_size = _get_mac_size,
+2 -2
View File
@@ -623,7 +623,7 @@ METHOD(crypter_t, destroy, void,
private_aesni_ctr_t *this) private_aesni_ctr_t *this)
{ {
DESTROY_IF(this->key); DESTROY_IF(this->key);
free(this); free_align(this);
} }
/** /**
@@ -650,7 +650,7 @@ aesni_ctr_t *aesni_ctr_create(encryption_algorithm_t algo, size_t key_size)
return NULL; return NULL;
} }
INIT(this, INIT_ALIGN(this, sizeof(__m128i),
.public = { .public = {
.crypter = { .crypter = {
.encrypt = _crypt, .encrypt = _crypt,
+2 -2
View File
@@ -1465,7 +1465,7 @@ METHOD(aead_t, destroy, void,
memwipe(&this->hhh, sizeof(this->hhh)); memwipe(&this->hhh, sizeof(this->hhh));
memwipe(&this->hhhh, sizeof(this->hhhh)); memwipe(&this->hhhh, sizeof(this->hhhh));
this->iv_gen->destroy(this->iv_gen); this->iv_gen->destroy(this->iv_gen);
free(this); free_align(this);
} }
/** /**
@@ -1512,7 +1512,7 @@ aesni_gcm_t *aesni_gcm_create(encryption_algorithm_t algo,
return NULL; return NULL;
} }
INIT(this, INIT_ALIGN(this, sizeof(__m128i),
.public = { .public = {
.aead = { .aead = {
.encrypt = _encrypt, .encrypt = _encrypt,
+2 -2
View File
@@ -244,7 +244,7 @@ METHOD(aesni_key_t, destroy, void,
private_aesni_key_t *this) private_aesni_key_t *this)
{ {
memwipe(this, sizeof(*this) + (this->public.rounds + 1) * AES_BLOCK_SIZE); memwipe(this, sizeof(*this) + (this->public.rounds + 1) * AES_BLOCK_SIZE);
free(this); free_align(this);
} }
/** /**
@@ -270,7 +270,7 @@ aesni_key_t *aesni_key_create(bool encrypt, chunk_t key)
return NULL; return NULL;
} }
INIT_EXTRA(this, (rounds + 1) * AES_BLOCK_SIZE, INIT_EXTRA_ALIGN(this, (rounds + 1) * AES_BLOCK_SIZE, sizeof(__m128i),
.public = { .public = {
.destroy = _destroy, .destroy = _destroy,
.rounds = rounds, .rounds = rounds,
+2 -2
View File
@@ -309,7 +309,7 @@ METHOD(mac_t, destroy, void,
DESTROY_IF(this->k1); DESTROY_IF(this->k1);
memwipe(&this->k2, sizeof(this->k2)); memwipe(&this->k2, sizeof(this->k2));
memwipe(&this->k3, sizeof(this->k3)); memwipe(&this->k3, sizeof(this->k3));
free(this); free_align(this);
} }
/* /*
@@ -319,7 +319,7 @@ mac_t *aesni_xcbc_create(encryption_algorithm_t algo, size_t key_size)
{ {
private_aesni_mac_t *this; private_aesni_mac_t *this;
INIT(this, INIT_ALIGN(this, sizeof(__m128i),
.public = { .public = {
.get_mac = _get_mac, .get_mac = _get_mac,
.get_mac_size = _get_mac_size, .get_mac_size = _get_mac_size,