Changeset View
Changeset View
Standalone View
Standalone View
../../new/gcrypt/cipher/rijndael.c
Context not available. | |||||
typedef struct { | typedef struct { | ||||
int ROUNDS; /* key-length-dependent number of rounds */ | int ROUNDS; /* key-length-dependent number of rounds */ | ||||
int decryption_prepared; | int decryption_prepared; | ||||
byte keySched[MAXROUNDS+1][4][4]; /* key schedule */ | byte __attribute__((aligned(4))) keySched[MAXROUNDS+1][4][4]; /* key schedule */ | ||||
byte keySched2[MAXROUNDS+1][4][4]; /* key schedule */ | byte __attribute__((aligned(4))) keySched2[MAXROUNDS+1][4][4]; /* key schedule */ | ||||
} RIJNDAEL_context; | } RIJNDAEL_context; | ||||
Context not available. | |||||
␌ | ␌ | ||||
/* Encrypt one block. A and B may be the same. */ | /* Encrypt one block. A and B may be the same. */ | ||||
static void | 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 | /* FIXME: Ugly code, replace by straighter implementaion and use | ||||
optimized assembler for common CPUs. */ | optimized assembler for common CPUs. */ | ||||
Context not available. | |||||
u32 tempu32[4]; /* Force correct alignment. */ | u32 tempu32[4]; /* Force correct alignment. */ | ||||
byte temp[4][4]; | byte temp[4][4]; | ||||
} u; | } u; | ||||
byte __attribute__((aligned(4))) a[16]; | |||||
byte __attribute__((aligned(4))) b[16]; | |||||
int ROUNDS = ctx->ROUNDS; | int ROUNDS = ctx->ROUNDS; | ||||
#define rk (ctx->keySched) | #define rk (ctx->keySched) | ||||
memcpy(a,ax,16); | |||||
*((u32*)u.temp[0]) = *((u32*)(a )) ^ *((u32*)rk[0][0]); | *((u32*)u.temp[0]) = *((u32*)(a )) ^ *((u32*)rk[0][0]); | ||||
*((u32*)u.temp[1]) = *((u32*)(a+ 4)) ^ *((u32*)rk[0][1]); | *((u32*)u.temp[1]) = *((u32*)(a+ 4)) ^ *((u32*)rk[0][1]); | ||||
*((u32*)u.temp[2]) = *((u32*)(a+ 8)) ^ *((u32*)rk[0][2]); | *((u32*)u.temp[2]) = *((u32*)(a+ 8)) ^ *((u32*)rk[0][2]); | ||||
Context not available. | |||||
*((u32*)(b+ 8)) ^= *((u32*)rk[ROUNDS][2]); | *((u32*)(b+ 8)) ^= *((u32*)rk[ROUNDS][2]); | ||||
*((u32*)(b+12)) ^= *((u32*)rk[ROUNDS][3]); | *((u32*)(b+12)) ^= *((u32*)rk[ROUNDS][3]); | ||||
#undef rk | #undef rk | ||||
memcpy(bx,b,16); | |||||
} | } | ||||
static void | static void | ||||
Context not available. | |||||
RIJNDAEL_context *ctx = context; | RIJNDAEL_context *ctx = context; | ||||
do_encrypt (ctx, b, a); | 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. */ | /* Decrypt one block. a and b may be the same. */ | ||||
static void | 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) | #define rk (ctx->keySched2) | ||||
int ROUNDS = ctx->ROUNDS; | int ROUNDS = ctx->ROUNDS; | ||||
Context not available. | |||||
u32 tempu32[4]; /* Force correct alignment. */ | u32 tempu32[4]; /* Force correct alignment. */ | ||||
byte temp[4][4]; | byte temp[4][4]; | ||||
} u; | } u; | ||||
byte __attribute__((aligned(4))) a[16]; | |||||
byte __attribute__((aligned(4))) b[16]; | |||||
memcpy(a,ax,16); | |||||
if ( !ctx->decryption_prepared ) | if ( !ctx->decryption_prepared ) | ||||
{ | { | ||||
Context not available. | |||||
*((u32*)(b+ 8)) ^= *((u32*)rk[0][2]); | *((u32*)(b+ 8)) ^= *((u32*)rk[0][2]); | ||||
*((u32*)(b+12)) ^= *((u32*)rk[0][3]); | *((u32*)(b+12)) ^= *((u32*)rk[0][3]); | ||||
#undef rk | #undef rk | ||||
memcpy(bx,b,16); | |||||
} | } | ||||
static void | static void | ||||
Context not available. | |||||
RIJNDAEL_context *ctx = context; | RIJNDAEL_context *ctx = context; | ||||
do_decrypt (ctx, b, a); | do_decrypt (ctx, b, a); | ||||
_gcry_burn_stack (16+2*sizeof(int)); | _gcry_burn_stack (48+2*sizeof(int)); | ||||
} | } | ||||
␌ | ␌ | ||||
Context not available. |