This file contains the code for implementing the key schedule for AES (Rijndael) for block and key sizes of 16, 24, and 32 bytes. See aesopt.h for further details including optimisation. More...
#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]) |
This file contains the code for implementing the key schedule for AES (Rijndael) for block and key sizes of 16, 24, and 32 bytes. See aesopt.h for further details including optimisation.
Definition in file aeskey.c.
| #define kd4 | ( | k, | ||
| i | ||||
| ) |
{ 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 | ||||
| ) |
{ 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 | ||||
| ) |
{ 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 | ||||
| ) |
{ 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 | ||||
| ) |
{ 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 | ||||
| ) |
{ 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 inv_mcol, kd4, kdf4, kdl4, ke4, aes_decrypt_ctx::ks, N_COLS, and word_in.
{ aes_32t ss[5];
#ifdef d_vars
d_vars;
#endif
cx->ks[0] = ss[0] = word_in(in_key, 0);
cx->ks[1] = ss[1] = word_in(in_key, 1);
cx->ks[2] = ss[2] = word_in(in_key, 2);
cx->ks[3] = ss[3] = word_in(in_key, 3);
#if DEC_UNROLL == NONE
{ aes_32t i;
for(i = 0; i < (11 * N_COLS - 1) / 4; ++i)
ke4(cx->ks, i);
#if !(DEC_ROUND == NO_TABLES)
for(i = N_COLS; i < 10 * N_COLS; ++i)
cx->ks[i] = inv_mcol(cx->ks[i]);
#endif
}
#else
kdf4(cx->ks, 0); kd4(cx->ks, 1);
kd4(cx->ks, 2); kd4(cx->ks, 3);
kd4(cx->ks, 4); kd4(cx->ks, 5);
kd4(cx->ks, 6); kd4(cx->ks, 7);
kd4(cx->ks, 8); kdl4(cx->ks, 9);
#endif
/* cx->ks[45] ^ cx->ks[52] ^ cx->ks[53] is zero for a 256 bit */
/* key and must be non-zero for 128 and 192 bits keys */
cx->ks[53] = cx->ks[45] = 0;
cx->ks[52] = 10;
#ifdef AES_ERR_CHK
return aes_good;
#endif
}
| aes_rval aes_encrypt_key128 | ( | const void * | in_key, | |
| aes_encrypt_ctx | cx[1] | |||
| ) |
Definition at line 105 of file aeskey.c.
References ke4, kel4, aes_encrypt_ctx::ks, N_COLS, and word_in.
{ aes_32t ss[4];
cx->ks[0] = ss[0] = word_in(in_key, 0);
cx->ks[1] = ss[1] = word_in(in_key, 1);
cx->ks[2] = ss[2] = word_in(in_key, 2);
cx->ks[3] = ss[3] = word_in(in_key, 3);
#if ENC_UNROLL == NONE
{ aes_32t i;
for(i = 0; i < ((11 * N_COLS - 1) / 4); ++i)
ke4(cx->ks, i);
}
#else
ke4(cx->ks, 0); ke4(cx->ks, 1);
ke4(cx->ks, 2); ke4(cx->ks, 3);
ke4(cx->ks, 4); ke4(cx->ks, 5);
ke4(cx->ks, 6); ke4(cx->ks, 7);
ke4(cx->ks, 8); kel4(cx->ks, 9);
#endif
/* cx->ks[45] ^ cx->ks[52] ^ cx->ks[53] is zero for a 256 bit */
/* key and must be non-zero for 128 and 192 bits keys */
cx->ks[53] = cx->ks[45] = 0;
cx->ks[52] = 10;
#ifdef AES_ERR_CHK
return aes_good;
#endif
}
1.7.1