AES์๋ 3๊ฐ์ง ์ข ๋ฅ๊ฐ ์์ผ๋ฉฐ ๊ฐ๊ฐ AES-128, AES-192, AES-256์ผ๋ก ๋ถ๋ฆฌ๋ฉฐ ์ด๋ฆ ๊ทธ๋๋ก ํค ํฌ๊ธฐ๊ฐ 128, 192, 256 bit์ด๋ค.
DES๋ Feistel ๋คํธ์ํฌ๋ผ๋ ๊ธฐ๋ณธ ๊ตฌ์กฐ๋ฅผ ์ฌ์ฉํ์ง๋ง AES์์๋ SPN ์ด๋ผ๋ ๊ตฌ์กฐ๋ฅผ ์ฌ์ฉํ๊ณ ์๋ค.
spn: Subsititution Layer๊ณผ Pernutation์ ์ด์ฉํ์ฌ Confusion๊ณผ Diffusion์ ๋ง์กฑ์์ผ์ฃผ๋ ๊ตฌ์กฐ์ด๋ค. ์ด ๊ตฌ์กฐ์ ์ฅ์ ์ Feistal ๊ตฌ์กฐ์ ๋ฐ๋๋ก ๋ณ๋ ฌ์ฐ์ฐ์ด ๊ฐ๋ฅํ์ฌ ์๋๊ฐ ๋น ๋ฅด๊ณ ๋จ์ ์ ๋ณตํธํ์ ๋ณ๋์ ๋ณตํธํ ๋ชจ๋์ ๊ตฌํํด์ค์ผ ํ๋ค๋ ๊ฒ์ด๋ค.
: ์ํธ๋ฌธ์ด ๋น ์ ํ์ฑ์ ๊ฐ๋๋ก ํ๊ธฐ ์ํด ๋ฐ์ดํธ ๋จ์๋ก ์ญ ๋ณํ์ด ๊ฐ๋ฅํ S-box๋ผ๋ ํ๋ฅผ ์ด์ฉํ์ฌ ๋ธ๋ก์ ๊ตํํ๋ค.
: Shift ์ฐ์ฐ์ ํ์ฌ ๋จ์ํ ํ๊ณผ ํ์ ์นํํ๋๋ฐ 4๊ฐ์ ํ์ ๊ฐ๊ฐ ์ผ์ชฝ์ผ๋ก Shift๋์ง๋ง ์ฒซ๋ฒ์งธ ํ์ ๊ทธ ํ์ ๋งจ ์ค๋ฅธ์ชฝ ๊ฐ์ผ๋ก ์ด๋ํ๋ค.
void ShiftRows()
{
unsigned char temp;
// Rotate first row 1 columns to left
temp = state[1][0];
state[1][0] = state[1][1];
state[1][1] = state[1][2];
state[1][2] = state[1][3];
state[1][3] = temp;
// Rotate second row 2 columns to left
temp = state[2][0];
state[2][0] = state[2][2];
state[2][2] = temp;
temp = state[2][1];
state[2][1] = state[2][3];
state[2][3] = temp;
// Rotate third row 3 columns to left
temp = state[3][0];
state[3][0] = state[3][3];
state[3][3] = state[3][2];
state[3][2] = state[3][1];
state[3][1] = temp;
}
: ์ด ๋จ์ ์ฐ์ฐ์ ์ํํ๋ค. ์ด์ ์ํ ๋ชจ๋ ๋ฐ์ดํธ๋ฅผ ์ํ ํ๋ ฌ์ ์ฌ์ฉํด ํจ์๋ก ์ด์ ์๋ ๊ฐ ๋ฐ์ดํธ๋ฅผ ๋์ฒดํ์ฌ ๋ณํ์ํจ๋ค. ์ฐธ๊ณ ๋ก ๋ง์ง๋ง ๋ผ์ด๋๋ MixColumn์ ํ์ง ์๋๋ค
// xtime is a macro that finds the product of {02} and the argument to xtime modulo {1b}
#define xtime(x) ((x<<1) ^ (((x>>7) & 1) * 0x1b))
// MixColumns function mixes the columns of the state matrix
// The method used may look complicated, but it is easy if you know the underlying theory.
// Refer the documents specified above.
void MixColumns()
{
int i;
unsigned char Tmp, Tm, t;
for (i = 0; i<4; i++)
{
t = state[0][i];
Tmp = state[0][i] ^ state[1][i] ^ state[2][i] ^ state[3][i];
Tm = state[0][i] ^ state[1][i]; Tm = xtime(Tm); state[0][i] ^= Tm ^ Tmp;
Tm = state[1][i] ^ state[2][i]; Tm = xtime(Tm); state[1][i] ^= Tm ^ Tmp;
Tm = state[2][i] ^ state[3][i]; Tm = xtime(Tm); state[2][i] ^= Tm ^ Tmp;
Tm = state[3][i] ^ t; Tm = xtime(Tm); state[3][i] ^= Tm ^ Tmp;
}
}
: ๋ผ์ด๋ ํค์ ํ์ฌ state ๋ธ๋ก์ ๋นํธ๋ณ๋ก XOR ํ๋ค.RoundKey๋ key expansion schedule์ ๋ฐ๋ผ key๋ก๋ถํฐ ์ ๋๋์ด์ง๋ค.
// This function adds the round key to state.
// The round key is added to the state by an XOR function.
void AddRoundKey(int round)
{
int i, j;
for (i = 0; i<4; i++)
for (j = 0; j<4; j++)
state[j][i] ^= RoundKey[round * Nb * 4 + i * Nb + j];
}
์์ ์ ํค๋ก ๋ฉ์ธ์ง๋ฅผ ์ํธํ๋ผ๊ณ ํค๋ฅผ ์์ ์์๊ฒ ๋ณด๋ด๋ฉด ํค๋ฅผ ์ด์ฉํด ๋ณตํธํํ๋ ๋ฐฉ์์ด๋ค. ํค๋ฅผ ๊ณต์ ํด์ผํ๊ธฐ ๋๋ฌธ์ ํค๊ฐ ๊ณต๊ฒฉ์์๊ฒ ๋ ธ์ถ๋๋ฉด ๋ณด์์ ์ทจ์ฝํด์ง์ง๋ง ๋น๋์นญ ์ํธํ ๋ฐฉ์์ ๋นํด ํค ์ฌ์ด์ฆ๊ฐ ์๊ณ ์๊ณ ๋ฆฌ์ฆ ๊ตฌ์กฐ๊ฐ ๊ฐ๋จํด์ ์๋๊ฐ ๋นจ๋ผ ํจ์จ์ ์ด๋ค.
Reference
https://developer-mac.tistory.com/59
https://www.crocus.co.kr/1230
https://gaeko-security-hack.tistory.com/106