Index: ../../new/gcrypt/cipher/rijndael.c =================================================================== --- ../../new/gcrypt/cipher/rijndael.c +++ ../../new/gcrypt/cipher/rijndael.c @@ -51,8 +51,8 @@ typedef struct { int ROUNDS; /* key-length-dependent number of rounds */ int decryption_prepared; - byte keySched[MAXROUNDS+1][4][4]; /* key schedule */ - byte keySched2[MAXROUNDS+1][4][4]; /* key schedule */ + byte __attribute__((aligned(4))) keySched[MAXROUNDS+1][4][4]; /* key schedule */ + byte __attribute__((aligned(4))) keySched2[MAXROUNDS+1][4][4]; /* key schedule */ } RIJNDAEL_context; @@ -1881,7 +1881,7 @@ /* Encrypt one block. A and B may be the same. */ static void -do_encrypt (const RIJNDAEL_context *ctx, byte *b, const byte *a) +do_encrypt (const RIJNDAEL_context *ctx, byte *bx, const byte *ax) { /* FIXME: Ugly code, replace by straighter implementaion and use optimized assembler for common CPUs. */ @@ -1891,9 +1891,14 @@ u32 tempu32[4]; /* Force correct alignment. */ byte temp[4][4]; } u; + byte __attribute__((aligned(4))) a[16]; + byte __attribute__((aligned(4))) b[16]; + int ROUNDS = ctx->ROUNDS; #define rk (ctx->keySched) + memcpy(a,ax,16); + *((u32*)u.temp[0]) = *((u32*)(a )) ^ *((u32*)rk[0][0]); *((u32*)u.temp[1]) = *((u32*)(a+ 4)) ^ *((u32*)rk[0][1]); *((u32*)u.temp[2]) = *((u32*)(a+ 8)) ^ *((u32*)rk[0][2]); @@ -1966,6 +1971,7 @@ *((u32*)(b+ 8)) ^= *((u32*)rk[ROUNDS][2]); *((u32*)(b+12)) ^= *((u32*)rk[ROUNDS][3]); #undef rk + memcpy(bx,b,16); } static void @@ -1974,14 +1980,14 @@ RIJNDAEL_context *ctx = context; do_encrypt (ctx, b, a); - _gcry_burn_stack (16 + 2*sizeof(int)); + _gcry_burn_stack (48 + 2*sizeof(int)); } /* Decrypt one block. a and b may be the same. */ static void -do_decrypt (RIJNDAEL_context *ctx, byte *b, const byte *a) +do_decrypt (RIJNDAEL_context *ctx, byte *bx, const byte *ax) { #define rk (ctx->keySched2) int ROUNDS = ctx->ROUNDS; @@ -1990,6 +1996,10 @@ u32 tempu32[4]; /* Force correct alignment. */ byte temp[4][4]; } u; + byte __attribute__((aligned(4))) a[16]; + byte __attribute__((aligned(4))) b[16]; + + memcpy(a,ax,16); if ( !ctx->decryption_prepared ) { @@ -2070,6 +2080,7 @@ *((u32*)(b+ 8)) ^= *((u32*)rk[0][2]); *((u32*)(b+12)) ^= *((u32*)rk[0][3]); #undef rk + memcpy(bx,b,16); } static void @@ -2078,7 +2089,7 @@ RIJNDAEL_context *ctx = context; do_decrypt (ctx, b, a); - _gcry_burn_stack (16+2*sizeof(int)); + _gcry_burn_stack (48+2*sizeof(int)); }