Pseudocode for CIPHER()
procedure CIPHER( in , Nr , w)
state <- in # state에 input block을 copy
state <- addRoundKey( state , w[0..3] ) # 0라운드에서는 addRoundKey()만 수행
for round frim 1 to Nr-1 do # key length에 따라 Nr-1번 만큼 수행한다.
state <- subBytes( state )
state <- shiftRows( state )
state <- mixColumns( state )
state <- addRoundKey( state , w[ 4*roundKey..4*roundKey+3 ] )
end for # 마지막 라운드이며 mixColumns를 제외하고 수행한다.
state <- subBytes( state )
state <- shift( state )
state <- addRoundKey( state , w[ 4*roundKey..4*roundKey+3 ] )
return state
end procedure
pseudocode for KEYEXPANSION()
procedure KEYEXPANSION( key )
i <- 0
while i <= Nk - 1 do # nk는 키의 길이.
w[i] <- key[ 4*i..4*i+3 ] # 키에 대해서 4*1부터 4*i+3까지의 할당
i <- i+1
end while
while i <= 4*Nr+3 do # 키의 길이에 따른 라운드 수만큼 반복
temp <- w[i-1]
if i mod Nk = 0 then # 새로운 sub key의 시작 부분일때....
temp <- SUBWORD ( ROTWORD( temp ) ) ⊕ Rcon[i/Nk]
else if Nk > 6 and i mod Nk = 4 then # 256에서만 실행됨
temp <- SUBWORD(temp)
end if
w[i] <- w[i-Nk] ⊕ temp
i <- i+1
end while
return w
end procedure