コード例 #1
0
 def __Rcon(self, i):
     rc = [0]*self.__nRows
     rc[0] = _RC[i/self.__nKeyWords]
     Rcon = _Word(self.__nRows, self.__wordSize).fromList(rc)
     self._debug_stream("\tRcon[%d]" % (i), Rcon,
                        operation='keyExpansion()\t')
     return Rcon
コード例 #2
0
 def __init__(self, key,
              nRounds=10, nRows=4, nColumns=4, wordSize=8,  # stardard aes
              nKeyWords=None, loglevel=_Logger._info, *args, **kwargs):
     super(KeyExpansion, self).__init__(loglevel, *args, **kwargs)
     self.__key = key
     self.__nRounds = nRounds
     self.__nRows = nRows
     self.__nColumns = nColumns
     self.__wordSize = wordSize
     if nKeyWords:
         self.__nKeyWords = nKeyWords
     else:
         self.__nKeyWords = nColumns
     self.__sbox = _SBox(self.__wordSize, loglevel=loglevel)
     self.includeInstance(self.__sbox)
     self.__word = _Word(self.__nRows, self.__wordSize)
     self.__keyExpanded = [None]*self.__nKeyWords
     self._debug_stream("key", key, operation="keyExpansion()\t")
     try:
         key = _Long(self.__wordSize).toArray(key,
                                              self.__nKeyWords *
                                              self.__nRows *
                                              self.__wordSize)
     except:
         raise Exception("Key length doesn't fit with the matrix size")
     self._debug_stream("key array", key, operation="keyExpansion()\t")
     self.__initialize(key)
     #self.__expand(self.__nKeyWords*(self.__nRounds+1))
     self._debug_stream("keyExpanded", self.__keyExpanded,
                        operation="keyExpansion()\t")
     self._debug_stream("size of key expanded %d"
                        % (len(self.__keyExpanded)))
コード例 #3
0
 def __initialize(self, key):
     for i in range(self.__nKeyWords):
         subkey = key[(self.__nRows*i):(self.__nRows*i)+self.__nRows]
         self.__keyExpanded[i] = \
             _Word(self.__nRows, self.__wordSize).fromList(subkey)
コード例 #4
0
ファイル: AddRoundKey.py プロジェクト: srgblnch/Rijndael
 def __init__(self, nRows, nColumns, wordSize, *args, **kwargs):
     super(AddRoundKey, self).__init__(*args, **kwargs)
     self.__nRows = nRows
     self.__nColumns = nColumns
     self.__word = _Word(nRows, wordSize)