예제 #1
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)))
예제 #2
0
 def __convertState2output(self):
     anArray = _State(self.__nRows, self.__nColumns,
                      self._logLevel).toArray(self.__state)
     argout = _Long(self.__wordSize).fromArray(anArray,
                                               self.__nColumns *
                                               self.__nRows *
                                               self.__wordSize)
     self._debug_stream("argout: %s" % argout)
     return argout
예제 #3
0
 def __convertInput2State(self, argin):
     self._debug_stream("argin: %s" % (argin))
     # TODO: check the argin have the size to be ciphered/deciphered
     anArray = _Long(self.__wordSize).toArray(argin,
                                              self.__nColumns *
                                              self.__nRows *
                                              self.__wordSize)
     self.__state = _State(self.__nRows, self.__nColumns, self._logLevel).\
         fromArray(anArray)