src/eric7/Utilities/crypto/py3AES.py

branch
eric7
changeset 10433
328f3ec4b77a
parent 10180
3a595df36c9a
child 10439
21c28b0f9e41
diff -r 2fe91fe443dd -r 328f3ec4b77a src/eric7/Utilities/crypto/py3AES.py
--- a/src/eric7/Utilities/crypto/py3AES.py	Thu Dec 21 15:46:22 2023 +0100
+++ b/src/eric7/Utilities/crypto/py3AES.py	Thu Dec 21 19:50:01 2023 +0100
@@ -33,8 +33,10 @@
     """
     Function to pad the given data to a multiple of 16-bytes by PKCS7 padding.
 
-    @param b data to be padded (bytes)
-    @return padded data (bytes)
+    @param b data to be padded
+    @type bytes
+    @return padded data
+    @rtype bytes
     """
     numpads = 16 - (len(b) % 16)
     return b + numpads * bytes(chr(numpads), encoding="ascii")
@@ -44,8 +46,10 @@
     """
     Function to strip off PKCS7 padding.
 
-    @param b data to be stripped (bytes)
-    @return stripped data (bytes)
+    @param b data to be stripped
+    @type bytes
+    @return stripped data
+    @rtype bytes
     @exception ValueError data padding is invalid
     """
     if len(b) % 16 or not b:
@@ -851,8 +855,10 @@
         """
         Private method to retrieve a given S-Box value.
 
-        @param num position of the value (integer)
-        @return value of the S-Box (integer)
+        @param num position of the value
+        @type int
+        @return value of the S-Box
+        @rtype int
         """
         return self.sbox[num]
 
@@ -860,8 +866,10 @@
         """
         Private method to retrieve a given Inverted S-Box value.
 
-        @param num position of the value (integer)
-        @return value of the Inverted S-Box (integer)
+        @param num position of the value
+        @type int
+        @return value of the Inverted S-Box
+        @rtype int
         """
         return self.rsbox[num]
 
@@ -872,8 +880,10 @@
         Rotate the data word eight bits to the left: eg,
         rotate(1d2c3a4f) == 2c3a4f1d.
 
-        @param data data of size 4 (bytearray)
-        @return rotated data (bytearray)
+        @param data data of size 4
+        @type bytearray
+        @return rotated data
+        @rtype bytearray
         """
         return data[1:] + data[:1]
 
@@ -881,8 +891,10 @@
         """
         Private method to retrieve a given Rcon value.
 
-        @param num position of the value (integer)
-        @return Rcon value (integer)
+        @param num position of the value
+        @type int
+        @return Rcon value
+        @rtype int
         """
         return self.Rcon[num]
 
@@ -890,9 +902,12 @@
         """
         Private method performing the key schedule core operation.
 
-        @param data data to operate on (bytearray)
-        @param iteration iteration counter (integer)
-        @return modified data (bytearray)
+        @param data data to operate on
+        @type bytearray
+        @param iteration iteration counter
+        @type int
+        @return modified data
+        @rtype bytearray
         """
         # rotate the 32-bit word 8 bits to the left
         data = self.__rotate(data)
@@ -910,10 +925,14 @@
 
         Expands a 128, 192 or 256 bit key into a 176, 208 or 240 bit key.
 
-        @param key key to be expanded (bytes or bytearray)
+        @param key key to be expanded
+        @type bytes or bytearray
         @param size size of the key in bytes (16, 24 or 32)
-        @param expandedKeySize size of the expanded key (integer)
-        @return expanded key (bytearray)
+        @type int
+        @param expandedKeySize size of the expanded key
+        @type int
+        @return expanded key
+        @rtype bytearray
         """
         # current expanded keySize, in bytes
         currentSize = 0
@@ -952,9 +971,12 @@
         """
         Private method to add (XORs) the round key to the state.
 
-        @param state state to be changed (bytearray)
-        @param roundKey key to be used for the modification (bytearray)
-        @return modified state (bytearray)
+        @param state state to be changed
+        @type bytearray
+        @param roundKey key to be used for the modification
+        @type bytearray
+        @return modified state
+        @rtype bytearray
         """
         buf = state[:]
         for i in range(16):
@@ -965,9 +987,12 @@
         """
         Private method to create a round key.
 
-        @param expandedKey expanded key to be used (bytearray)
-        @param roundKeyPointer position within the expanded key (integer)
-        @return round key (bytearray)
+        @param expandedKey expanded key to be used
+        @type bytearray
+        @param roundKeyPointer position within the expanded key
+        @type int
+        @return round key
+        @rtype bytearray
         """
         roundKey = bytearray(16)
         for i in range(4):
@@ -980,9 +1005,12 @@
         Private method to perform a Galois multiplication of 8 bit characters
         a and b.
 
-        @param a first factor (byte)
-        @param b second factor (byte)
-        @return result (byte)
+        @param a first factor
+        @type bytes
+        @param b second factor
+        @type bytes
+        @return result
+        @rtype bytes
         """
         p = 0
         for _counter in range(8):
@@ -1002,9 +1030,12 @@
         Private method to substitute all the values from the state with the
         value in the SBox using the state value as index for the SBox.
 
-        @param state state to be worked on (bytearray)
-        @param isInv flag indicating an inverse operation (boolean)
-        @return modified state (bytearray)
+        @param state state to be worked on
+        @type bytearray
+        @param isInv flag indicating an inverse operation
+        @type bool
+        @return modified state
+        @rtype bytearray
         """
         state = state[:]
         getter = self.__getSBoxInvert if isInv else self.__getSBoxValue
@@ -1017,9 +1048,12 @@
         Private method to iterate over the 4 rows and call __shiftRow() with
         that row.
 
-        @param state state to be worked on (bytearray)
-        @param isInv flag indicating an inverse operation (boolean)
-        @return modified state (bytearray)
+        @param state state to be worked on
+        @type bytearray
+        @param isInv flag indicating an inverse operation
+        @type bool
+        @return modified state
+        @rtype bytearray
         """
         state = state[:]
         for i in range(4):
@@ -1030,11 +1064,16 @@
         """
         Private method to shift the bytes of a row to the left.
 
-        @param state state to be worked on (bytearray)
-        @param statePointer index into the state (integer)
-        @param nbr number of positions to shift (integer)
-        @param isInv flag indicating an inverse operation (boolean)
-        @return modified state (bytearray)
+        @param state state to be worked on
+        @type bytearray
+        @param statePointer index into the state
+        @type int
+        @param nbr number of positions to shift
+        @type int
+        @param isInv flag indicating an inverse operation
+        @type bool
+        @return modified state
+        @rtype bytearray
         """
         state = state[:]
         for _ in range(nbr):
@@ -1054,9 +1093,12 @@
         """
         Private method to perform a galois multiplication of the 4x4 matrix.
 
-        @param state state to be worked on (bytearray)
-        @param isInv flag indicating an inverse operation (boolean)
-        @return modified state (bytearray)
+        @param state state to be worked on
+        @type bytearray
+        @param isInv flag indicating an inverse operation
+        @type bool
+        @return modified state
+        @rtype bytearray
         """
         state = state[:]
         # iterate over the 4 columns
@@ -1076,9 +1118,12 @@
         Private method to perform a galois multiplication of 1 column the
         4x4 matrix.
 
-        @param column column to be worked on (bytearray)
-        @param isInv flag indicating an inverse operation (boolean)
-        @return modified column (bytearray)
+        @param column column to be worked on
+        @type bytearray
+        @param isInv flag indicating an inverse operation
+        @type bool
+        @return modified column
+        @rtype bytearray
         """
         column = column[:]
         mult = [14, 9, 13, 11] if isInv else [2, 1, 1, 3]
@@ -1116,9 +1161,12 @@
         Private method to apply the 4 operations of the forward round in
         sequence.
 
-        @param state state to be worked on (bytearray)
-        @param roundKey round key to be used (bytearray)
-        @return modified state (bytearray)
+        @param state state to be worked on
+        @type bytearray
+        @param roundKey round key to be used
+        @type bytearray
+        @return modified state
+        @rtype bytearray
         """
         state = self.__subBytes(state, False)
         state = self.__shiftRows(state, False)
@@ -1131,9 +1179,12 @@
         Private method to apply the 4 operations of the inverse round in
         sequence.
 
-        @param state state to be worked on (bytearray)
-        @param roundKey round key to be used (bytearray)
-        @return modified state (bytearray)
+        @param state state to be worked on
+        @type bytearray
+        @param roundKey round key to be used
+        @type bytearray
+        @return modified state
+        @rtype bytearray
         """
         state = self.__shiftRows(state, True)
         state = self.__subBytes(state, True)
@@ -1149,10 +1200,14 @@
         final operations of the forward AES, creating a round key for
         each round.
 
-        @param state state to be worked on (bytearray)
-        @param expandedKey expanded key to be used (bytearray)
-        @param nbrRounds number of rounds to be done (integer)
-        @return modified state (bytearray)
+        @param state state to be worked on
+        @type bytearray
+        @param expandedKey expanded key to be used
+        @type bytearray
+        @param nbrRounds number of rounds to be done
+        @type int
+        @return modified state
+        @rtype bytearray
         """
         state = self.__addRoundKey(state, self.__createRoundKey(expandedKey, 0))
         i = 1
@@ -1174,10 +1229,14 @@
         final operations of the inverse AES, creating a round key for
         each round.
 
-        @param state state to be worked on (bytearray)
-        @param expandedKey expanded key to be used (bytearray)
-        @param nbrRounds number of rounds to be done (integer)
-        @return modified state (bytearray)
+        @param state state to be worked on
+        @type bytearray
+        @param expandedKey expanded key to be used
+        @type bytearray
+        @param nbrRounds number of rounds to be done
+        @type int
+        @return modified state
+        @rtype bytearray
         """
         state = self.__addRoundKey(
             state, self.__createRoundKey(expandedKey, 16 * nbrRounds)
@@ -1198,10 +1257,14 @@
         Public method to encrypt a 128 bit input block against the given key
         of size specified.
 
-        @param iput input data (bytearray)
-        @param key key to be used (bytes or bytearray)
+        @param iput input data
+        @type bytearray
+        @param key key to be used
+        @type bytes or bytearray
         @param size key size (16, 24 or 32)
-        @return encrypted data (bytes)
+        @type int
+        @return encrypted data
+        @rtype bytes
         @exception ValueError key size is invalid
         """
         if size not in self.KeySize.values():
@@ -1256,10 +1319,14 @@
         Public method to decrypt a 128 bit input block against the given key
         of size specified.
 
-        @param iput input data (bytearray)
-        @param key key to be used (bytes or bytearray)
+        @param iput input data
+        @type bytearray
+        @param key key to be used
+        @type bytes or bytearray
         @param size key size (16, 24 or 32)
-        @return decrypted data (bytes)
+        @type int
+        @return decrypted data
+        @rtype bytes
         @exception ValueError key size is invalid
         """
         if size not in self.KeySize.values():
@@ -1324,11 +1391,16 @@
         """
         Private method to extract a range of bytes from the input.
 
-        @param inputData input data (bytes)
-        @param start start index (integer)
-        @param end end index (integer)
+        @param inputData input data
+        @type bytes
+        @param start start index
+        @type int
+        @param end end index
+        @type int
         @param mode mode of operation (0, 1, 2)
-        @return extracted bytes (bytearray)
+        @type int
+        @return extracted bytes
+        @rtype bytearray
         """
         if end - start > 16:
             end = start + 16
@@ -1348,13 +1420,19 @@
         """
         Public method to perform the encryption operation.
 
-        @param inputData data to be encrypted (bytes)
+        @param inputData data to be encrypted
+        @type bytes
         @param mode mode of operation (0, 1 or 2)
-        @param key key to be used (bytes)
+        @type int
+        @param key key to be used
+        @type bytes
         @param size length of the key (16, 24 or 32)
-        @param IV initialisation vector (bytearray)
+        @type int
+        @param IV initialisation vector
+        @type bytearray
         @return tuple with mode of operation, length of the input data and
-            the encrypted data (integer, integer, bytes)
+            the encrypted data
+        @rtype tuple of (int, int, bytes)
         @exception ValueError key size is invalid or decrypted data is invalid
         """
         if len(key) % size:
@@ -1436,14 +1514,20 @@
         """
         Public method to perform the decryption operation.
 
-        @param cipherIn data to be decrypted (bytes)
+        @param cipherIn data to be decrypted
+        @type bytes
         @param originalsize unencrypted string length (required for CBC)
-            (integer)
+        @type int
         @param mode mode of operation (0, 1 or 2)
-        @param key key to be used (bytes)
+        @type int
+        @param key key to be used
+        @type bytes
         @param size length of the key (16, 24 or 32)
-        @param IV initialisation vector (bytearray)
-        @return decrypted data (bytes)
+        @type int
+        @param IV initialisation vector
+        @type bytearray
+        @return decrypted data
+        @rtype bytes
         @exception ValueError key size is invalid or decrypted data is invalid
         """
         if len(key) % size:
@@ -1524,10 +1608,14 @@
     """
     Module function to encrypt the given data with the given key.
 
-    @param key key to be used for encryption (bytes)
-    @param data data to be encrypted (bytes)
+    @param key key to be used for encryption
+    @type bytes
+    @param data data to be encrypted
+    @type bytes
     @param mode mode of operations (0, 1 or 2)
-    @return encrypted data prepended with the initialization vector (bytes)
+    @type int
+    @return encrypted data prepended with the initialization vector
+    @rtype bytes
     @exception ValueError raised to indicate an invalid key size
     """
     key = bytearray(key)
@@ -1550,11 +1638,14 @@
     """
     Module function to decrypt the given data with the given key.
 
-    @param key key to be used for decryption (bytes)
+    @param key key to be used for decryption
+    @type bytes
     @param data data to be decrypted (with initialization vector prepended)
-        (bytes)
+    @type bytes
     @param mode mode of operations (0, 1 or 2)
-    @return decrypted data (bytes)
+    @type int
+    @return decrypted data
+    @rtype bytes
     @exception ValueError raised to indicate an invalid key size
     """
     key = bytearray(key)

eric ide

mercurial