#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 246 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 240 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 251 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 69 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 73 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 318 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.
Referenced by build_ecx_key(), build_encryption_keys(), check_key(), and update_key().
00319 { aes_32t ss[5]; 00320 #ifdef d_vars 00321 d_vars; 00322 #endif 00323 cx->ks[0] = ss[0] = word_in(in_key, 0); 00324 cx->ks[1] = ss[1] = word_in(in_key, 1); 00325 cx->ks[2] = ss[2] = word_in(in_key, 2); 00326 cx->ks[3] = ss[3] = word_in(in_key, 3); 00327 00328 #if DEC_UNROLL == NONE 00329 { aes_32t i; 00330 00331 for(i = 0; i < (11 * N_COLS - 1) / 4; ++i) 00332 ke4(cx->ks, i); 00333 #if !(DEC_ROUND == NO_TABLES) 00334 for(i = N_COLS; i < 10 * N_COLS; ++i) 00335 cx->ks[i] = inv_mcol(cx->ks[i]); 00336 #endif 00337 } 00338 #else 00339 kdf4(cx->ks, 0); kd4(cx->ks, 1); 00340 kd4(cx->ks, 2); kd4(cx->ks, 3); 00341 kd4(cx->ks, 4); kd4(cx->ks, 5); 00342 kd4(cx->ks, 6); kd4(cx->ks, 7); 00343 kd4(cx->ks, 8); kdl4(cx->ks, 9); 00344 #endif 00345 00346 /* cx->ks[45] ^ cx->ks[52] ^ cx->ks[53] is zero for a 256 bit */ 00347 /* key and must be non-zero for 128 and 192 bits keys */ 00348 cx->ks[53] = cx->ks[45] = 0; 00349 cx->ks[52] = 10; 00350 #ifdef AES_ERR_CHK 00351 return aes_good; 00352 #endif 00353 }
aes_rval aes_encrypt_key128 | ( | const void * | in_key, | |
aes_encrypt_ctx | cx[1] | |||
) |
Definition at line 103 of file aeskey.c.
References aes_good, ke4, kel4, aes_encrypt_ctx::ks, N_COLS, and word_in.
Referenced by build_ecx_key(), check_key(), and update_key().
00104 { aes_32t ss[4]; 00105 00106 cx->ks[0] = ss[0] = word_in(in_key, 0); 00107 cx->ks[1] = ss[1] = word_in(in_key, 1); 00108 cx->ks[2] = ss[2] = word_in(in_key, 2); 00109 cx->ks[3] = ss[3] = word_in(in_key, 3); 00110 00111 #if ENC_UNROLL == NONE 00112 { aes_32t i; 00113 00114 for(i = 0; i < ((11 * N_COLS - 1) / 4); ++i) 00115 ke4(cx->ks, i); 00116 } 00117 #else 00118 ke4(cx->ks, 0); ke4(cx->ks, 1); 00119 ke4(cx->ks, 2); ke4(cx->ks, 3); 00120 ke4(cx->ks, 4); ke4(cx->ks, 5); 00121 ke4(cx->ks, 6); ke4(cx->ks, 7); 00122 ke4(cx->ks, 8); kel4(cx->ks, 9); 00123 #endif 00124 00125 /* cx->ks[45] ^ cx->ks[52] ^ cx->ks[53] is zero for a 256 bit */ 00126 /* key and must be non-zero for 128 and 192 bits keys */ 00127 cx->ks[53] = cx->ks[45] = 0; 00128 cx->ks[52] = 10; 00129 #ifdef AES_ERR_CHK 00130 return aes_good; 00131 #endif 00132 }