#include "aesopt.h"
Go to the source code of this file.
Defines | |
#define | ff(x) inv_mcol(x) |
#define | kd4(k, i) |
#define | kd6(k, i) |
#define | kd8(k, i) |
#define | kdf4(k, i) |
#define | kdf6(k, i) |
#define | kdf8(k, i) |
#define | kdl4(k, i) |
#define | kdl6(k, i) |
#define | kdl8(k, i) |
#define | ke4(k, i) |
#define | ke6(k, i) |
#define | ke8(k, i) |
#define | kel4(k, i) |
#define | kel6(k, i) |
#define | kel8(k, i) |
Functions | |
aes_rval | aes_decrypt_key128 (const void *in_key, aes_decrypt_ctx cx[1]) |
aes_rval | aes_encrypt_key128 (const void *in_key, aes_encrypt_ctx cx[1]) |
Definition in file aeskey.c.
#define kd4 | ( | k, | |||
i | ) |
Value:
{ ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; ss[i % 4] ^= ss[4]; ss[4] = ff(ss[4]); \ k[4*(i)+4] = ss[4] ^= k[4*(i)]; k[4*(i)+5] = ss[4] ^= k[4*(i)+1]; \ k[4*(i)+6] = ss[4] ^= k[4*(i)+2]; k[4*(i)+7] = ss[4] ^= k[4*(i)+3]; \ }
Definition at line 248 of file aeskey.c.
Referenced by aes_decrypt_key128().
#define kdf4 | ( | k, | |||
i | ) |
Value:
{ ss[0] = ss[0] ^ ss[2] ^ ss[1] ^ ss[3]; ss[1] = ss[1] ^ ss[3]; ss[2] = ss[2] ^ ss[3]; ss[3] = ss[3]; \ ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; ss[i % 4] ^= ss[4]; \ ss[4] ^= k[4*(i)]; k[4*(i)+4] = ff(ss[4]); ss[4] ^= k[4*(i)+1]; k[4*(i)+5] = ff(ss[4]); \ ss[4] ^= k[4*(i)+2]; k[4*(i)+6] = ff(ss[4]); ss[4] ^= k[4*(i)+3]; k[4*(i)+7] = ff(ss[4]); \ }
Definition at line 242 of file aeskey.c.
Referenced by aes_decrypt_key128().
#define kdf6 | ( | k, | |||
i | ) |
#define kdf8 | ( | k, | |||
i | ) |
Value:
{ ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[8*(i)+ 8] = ff(ss[0]); ss[1] ^= ss[0]; k[8*(i)+ 9] = ff(ss[1]); \ ss[2] ^= ss[1]; k[8*(i)+10] = ff(ss[2]); ss[3] ^= ss[2]; k[8*(i)+11] = ff(ss[3]); \ ss[4] ^= ls_box(ss[3],0); k[8*(i)+12] = ff(ss[4]); ss[5] ^= ss[4]; k[8*(i)+13] = ff(ss[5]); \ ss[6] ^= ss[5]; k[8*(i)+14] = ff(ss[6]); ss[7] ^= ss[6]; k[8*(i)+15] = ff(ss[7]); \ }
#define kdl4 | ( | k, | |||
i | ) |
Value:
{ ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; ss[i % 4] ^= ss[4]; \ k[4*(i)+4] = (ss[0] ^= ss[1]) ^ ss[2] ^ ss[3]; k[4*(i)+5] = ss[1] ^ ss[3]; \ k[4*(i)+6] = ss[0]; k[4*(i)+7] = ss[1]; \ }
Definition at line 253 of file aeskey.c.
Referenced by aes_decrypt_key128().
#define kdl6 | ( | k, | |||
i | ) |
#define kdl8 | ( | k, | |||
i | ) |
#define ke4 | ( | k, | |||
i | ) |
Value:
{ k[4*(i)+4] = ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+5] = ss[1] ^= ss[0]; \ k[4*(i)+6] = ss[2] ^= ss[1]; k[4*(i)+7] = ss[3] ^= ss[2]; \ }
Definition at line 71 of file aeskey.c.
Referenced by aes_decrypt_key128(), and aes_encrypt_key128().
#define ke6 | ( | k, | |||
i | ) |
#define ke8 | ( | k, | |||
i | ) |
#define kel4 | ( | k, | |||
i | ) |
Value:
{ k[4*(i)+4] = ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+5] = ss[1] ^= ss[0]; \ k[4*(i)+6] = ss[2] ^= ss[1]; k[4*(i)+7] = ss[3] ^= ss[2]; \ }
Definition at line 75 of file aeskey.c.
Referenced by aes_encrypt_key128().
#define kel6 | ( | k, | |||
i | ) |
#define kel8 | ( | k, | |||
i | ) |
aes_rval aes_decrypt_key128 | ( | const void * | in_key, | |
aes_decrypt_ctx | cx[1] | |||
) |
Definition at line 320 of file aeskey.c.
References aes_good, DEC_ROUND, inv_mcol, kd4, kdf4, kdl4, ke4, aes_decrypt_ctx::ks, N_COLS, NO_TABLES, and word_in.
00321 { aes_32t ss[5]; 00322 #ifdef d_vars 00323 d_vars; 00324 #endif 00325 cx->ks[0] = ss[0] = word_in(in_key, 0); 00326 cx->ks[1] = ss[1] = word_in(in_key, 1); 00327 cx->ks[2] = ss[2] = word_in(in_key, 2); 00328 cx->ks[3] = ss[3] = word_in(in_key, 3); 00329 00330 #if DEC_UNROLL == NONE 00331 { aes_32t i; 00332 00333 for(i = 0; i < (11 * N_COLS - 1) / 4; ++i) 00334 ke4(cx->ks, i); 00335 #if !(DEC_ROUND == NO_TABLES) 00336 for(i = N_COLS; i < 10 * N_COLS; ++i) 00337 cx->ks[i] = inv_mcol(cx->ks[i]); 00338 #endif 00339 } 00340 #else 00341 kdf4(cx->ks, 0); kd4(cx->ks, 1); 00342 kd4(cx->ks, 2); kd4(cx->ks, 3); 00343 kd4(cx->ks, 4); kd4(cx->ks, 5); 00344 kd4(cx->ks, 6); kd4(cx->ks, 7); 00345 kd4(cx->ks, 8); kdl4(cx->ks, 9); 00346 #endif 00347 00348 /* cx->ks[45] ^ cx->ks[52] ^ cx->ks[53] is zero for a 256 bit */ 00349 /* key and must be non-zero for 128 and 192 bits keys */ 00350 cx->ks[53] = cx->ks[45] = 0; 00351 cx->ks[52] = 10; 00352 #ifdef AES_ERR_CHK 00353 return aes_good; 00354 #endif 00355 }
aes_rval aes_encrypt_key128 | ( | const void * | in_key, | |
aes_encrypt_ctx | cx[1] | |||
) |
Definition at line 105 of file aeskey.c.
References aes_good, ke4, kel4, aes_encrypt_ctx::ks, N_COLS, and word_in.
00106 { aes_32t ss[4]; 00107 00108 cx->ks[0] = ss[0] = word_in(in_key, 0); 00109 cx->ks[1] = ss[1] = word_in(in_key, 1); 00110 cx->ks[2] = ss[2] = word_in(in_key, 2); 00111 cx->ks[3] = ss[3] = word_in(in_key, 3); 00112 00113 #if ENC_UNROLL == NONE 00114 { aes_32t i; 00115 00116 for(i = 0; i < ((11 * N_COLS - 1) / 4); ++i) 00117 ke4(cx->ks, i); 00118 } 00119 #else 00120 ke4(cx->ks, 0); ke4(cx->ks, 1); 00121 ke4(cx->ks, 2); ke4(cx->ks, 3); 00122 ke4(cx->ks, 4); ke4(cx->ks, 5); 00123 ke4(cx->ks, 6); ke4(cx->ks, 7); 00124 ke4(cx->ks, 8); kel4(cx->ks, 9); 00125 #endif 00126 00127 /* cx->ks[45] ^ cx->ks[52] ^ cx->ks[53] is zero for a 256 bit */ 00128 /* key and must be non-zero for 128 and 192 bits keys */ 00129 cx->ks[53] = cx->ks[45] = 0; 00130 cx->ks[52] = 10; 00131 #ifdef AES_ERR_CHK 00132 return aes_good; 00133 #endif 00134 }