'Performs AES key expansion on self.key and stores in self.exkey'

def expand_key(self):

    exkey = array('B', self.key)
    if (self.key_size == 16):
        extra_cnt = 0
    elif (self.key_size == 24):
        extra_cnt = 2
    else:
        extra_cnt = 3
    word = exkey[(-4):]
    for i in xrange(1, 11):
        word = (word[1:4] + word[0:1])
        for j in xrange(4):
            word[j] = aes_sbox[word[j]]
        word[0] = (word[0] ^ aes_Rcon[i])
        for z in xrange(4):
            for j in xrange(4):
                word[j] ^= exkey[((- self.key_size) + j)]
            exkey.extend(word)
        if (len(exkey) >= ((self.rounds + 1) * self.block_size)):
            break
        if (self.key_size == 32):
            for j in xrange(4):
                word[j] = (aes_sbox[word[j]] ^ exkey[((- self.key_size) + j)])
            exkey.extend(word)
        for z in xrange(extra_cnt):
            for j in xrange(4):
                word[j] ^= exkey[((- self.key_size) + j)]
            exkey.extend(word)
    self.exkey = exkey
