Ensure that AES key is always correctly aligned
Aligning a `struct` member via `attribute(align(<n>))` is not guaranteed to work. Change the approach to use an opaque buffer and always manually align the start pointers of the keys. c.f. https://github.com/DCIT/perl-CryptX/issues/95 Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
parent
62add4d0ce
commit
2f6282919f
@ -96,7 +96,7 @@ static ulong32 setup_mix2(ulong32 temp)
|
||||
int SETUP(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
|
||||
{
|
||||
int i;
|
||||
ulong32 temp, *rk;
|
||||
ulong32 temp, *rk, *K;
|
||||
#ifndef ENCRYPT_ONLY
|
||||
ulong32 *rrk;
|
||||
#endif
|
||||
@ -112,6 +112,10 @@ int SETUP(const unsigned char *key, int keylen, int num_rounds, symmetric_key *s
|
||||
}
|
||||
|
||||
skey->rijndael.Nr = 10 + ((keylen/8)-2)*2;
|
||||
K = LTC_ALIGN_BUF(skey->rijndael.K, 16);
|
||||
skey->rijndael.eK = K;
|
||||
K += 60;
|
||||
skey->rijndael.dK = K;
|
||||
|
||||
/* setup the forward key */
|
||||
i = 0;
|
||||
|
@ -46,7 +46,7 @@ int aesni_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_
|
||||
{
|
||||
int i;
|
||||
__m128i temp;
|
||||
ulong32 *rk;
|
||||
ulong32 *rk, *K;
|
||||
ulong32 *rrk;
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(skey != NULL);
|
||||
@ -60,6 +60,10 @@ int aesni_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_
|
||||
}
|
||||
|
||||
skey->rijndael.Nr = keylen / 4 + 6;
|
||||
K = LTC_ALIGN_BUF(skey->rijndael.K, 16);
|
||||
skey->rijndael.eK = K;
|
||||
K += 60;
|
||||
skey->rijndael.dK = K;
|
||||
|
||||
/* setup the forward key */
|
||||
i = 0;
|
||||
|
@ -35,9 +35,10 @@ struct saferp_key {
|
||||
|
||||
#ifdef LTC_RIJNDAEL
|
||||
struct rijndael_key {
|
||||
ulong32 eK[60] LTC_ALIGN(16);
|
||||
ulong32 dK[60] LTC_ALIGN(16);
|
||||
ulong32 *eK;
|
||||
ulong32 *dK;
|
||||
int Nr;
|
||||
unsigned char K[(60 + 60 + 4) * sizeof(ulong32)];
|
||||
};
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user