eric6/Documentation/Source/eric6.Utilities.crypto.py3AES.html

changeset 7273
391d6b7b1eff
parent 6942
2602857055c5
child 7631
2c7ccb4484bf
equal deleted inserted replaced
7272:1779dc278077 7273:391d6b7b1eff
16 16
17 a { color: #BA6D36; } 17 a { color: #BA6D36; }
18 18
19 </style> 19 </style>
20 </head> 20 </head>
21 <body><a NAME="top" ID="top"></a> 21 <body>
22 <a NAME="top" ID="top"></a>
22 <h1>eric6.Utilities.crypto.py3AES</h1> 23 <h1>eric6.Utilities.crypto.py3AES</h1>
24
23 <p> 25 <p>
24 Module implementing classes for encryption according 26 Module implementing classes for encryption according
25 Advanced Encryption Standard. 27 Advanced Encryption Standard.
26 </p> 28 </p>
27 <h3>Global Attributes</h3> 29 <h3>Global Attributes</h3>
30
28 <table> 31 <table>
29 <tr><td>None</td></tr> 32 <tr><td>None</td></tr>
30 </table> 33 </table>
31 <h3>Classes</h3> 34 <h3>Classes</h3>
32 <table> 35
36 <table>
37
33 <tr> 38 <tr>
34 <td><a href="#AES">AES</a></td> 39 <td><a href="#AES">AES</a></td>
35 <td>Class implementing the Advanced Encryption Standard algorithm.</td> 40 <td>Class implementing the Advanced Encryption Standard algorithm.</td>
36 </tr><tr> 41 </tr>
42 <tr>
37 <td><a href="#AESModeOfOperation">AESModeOfOperation</a></td> 43 <td><a href="#AESModeOfOperation">AESModeOfOperation</a></td>
38 <td>Class implementing the different AES mode of operations.</td> 44 <td>Class implementing the different AES mode of operations.</td>
39 </tr> 45 </tr>
40 </table> 46 </table>
41 <h3>Functions</h3> 47 <h3>Functions</h3>
42 <table> 48
49 <table>
50
43 <tr> 51 <tr>
44 <td><a href="#append_PKCS7_padding">append_PKCS7_padding</a></td> 52 <td><a href="#append_PKCS7_padding">append_PKCS7_padding</a></td>
45 <td>Function to pad the given data to a multiple of 16-bytes by PKCS7 padding.</td> 53 <td>Function to pad the given data to a multiple of 16-bytes by PKCS7 padding.</td>
46 </tr><tr> 54 </tr>
55 <tr>
47 <td><a href="#decryptData">decryptData</a></td> 56 <td><a href="#decryptData">decryptData</a></td>
48 <td>Module function to decrypt the given data with the given key.</td> 57 <td>Module function to decrypt the given data with the given key.</td>
49 </tr><tr> 58 </tr>
59 <tr>
50 <td><a href="#encryptData">encryptData</a></td> 60 <td><a href="#encryptData">encryptData</a></td>
51 <td>Module function to encrypt the given data with the given key.</td> 61 <td>Module function to encrypt the given data with the given key.</td>
52 </tr><tr> 62 </tr>
63 <tr>
53 <td><a href="#strip_PKCS7_padding">strip_PKCS7_padding</a></td> 64 <td><a href="#strip_PKCS7_padding">strip_PKCS7_padding</a></td>
54 <td>Function to strip off PKCS7 padding.</td> 65 <td>Function to strip off PKCS7 padding.</td>
55 </tr> 66 </tr>
56 </table> 67 </table>
57 <hr /><hr /> 68 <hr />
69 <hr />
58 <a NAME="AES" ID="AES"></a> 70 <a NAME="AES" ID="AES"></a>
59 <h2>AES</h2> 71 <h2>AES</h2>
72
60 <p> 73 <p>
61 Class implementing the Advanced Encryption Standard algorithm. 74 Class implementing the Advanced Encryption Standard algorithm.
62 </p> 75 </p>
63 <h3>Derived from</h3> 76 <h3>Derived from</h3>
64 object 77 object
65 <h3>Class Attributes</h3> 78 <h3>Class Attributes</h3>
79
66 <table> 80 <table>
67 <tr><td>KeySize</td></tr><tr><td>Rcon</td></tr><tr><td>rsbox</td></tr><tr><td>sbox</td></tr> 81 <tr><td>KeySize</td></tr><tr><td>Rcon</td></tr><tr><td>rsbox</td></tr><tr><td>sbox</td></tr>
68 </table> 82 </table>
69 <h3>Class Methods</h3> 83 <h3>Class Methods</h3>
84
70 <table> 85 <table>
71 <tr><td>None</td></tr> 86 <tr><td>None</td></tr>
72 </table> 87 </table>
73 <h3>Methods</h3> 88 <h3>Methods</h3>
74 <table> 89
90 <table>
91
75 <tr> 92 <tr>
76 <td><a href="#AES.__addRoundKey">__addRoundKey</a></td> 93 <td><a href="#AES.__addRoundKey">__addRoundKey</a></td>
77 <td>Private method to add (XORs) the round key to the state.</td> 94 <td>Private method to add (XORs) the round key to the state.</td>
78 </tr><tr> 95 </tr>
96 <tr>
79 <td><a href="#AES.__aes_invMain">__aes_invMain</a></td> 97 <td><a href="#AES.__aes_invMain">__aes_invMain</a></td>
80 <td>Private method to do the inverse AES encryption for one round.</td> 98 <td>Private method to do the inverse AES encryption for one round.</td>
81 </tr><tr> 99 </tr>
100 <tr>
82 <td><a href="#AES.__aes_invRound">__aes_invRound</a></td> 101 <td><a href="#AES.__aes_invRound">__aes_invRound</a></td>
83 <td>Private method to apply the 4 operations of the inverse round in sequence.</td> 102 <td>Private method to apply the 4 operations of the inverse round in sequence.</td>
84 </tr><tr> 103 </tr>
104 <tr>
85 <td><a href="#AES.__aes_main">__aes_main</a></td> 105 <td><a href="#AES.__aes_main">__aes_main</a></td>
86 <td>Private method to do the AES encryption for one round.</td> 106 <td>Private method to do the AES encryption for one round.</td>
87 </tr><tr> 107 </tr>
108 <tr>
88 <td><a href="#AES.__aes_round">__aes_round</a></td> 109 <td><a href="#AES.__aes_round">__aes_round</a></td>
89 <td>Private method to apply the 4 operations of the forward round in sequence.</td> 110 <td>Private method to apply the 4 operations of the forward round in sequence.</td>
90 </tr><tr> 111 </tr>
112 <tr>
91 <td><a href="#AES.__core">__core</a></td> 113 <td><a href="#AES.__core">__core</a></td>
92 <td>Private method performing the key schedule core operation.</td> 114 <td>Private method performing the key schedule core operation.</td>
93 </tr><tr> 115 </tr>
116 <tr>
94 <td><a href="#AES.__createRoundKey">__createRoundKey</a></td> 117 <td><a href="#AES.__createRoundKey">__createRoundKey</a></td>
95 <td>Private method to create a round key.</td> 118 <td>Private method to create a round key.</td>
96 </tr><tr> 119 </tr>
120 <tr>
97 <td><a href="#AES.__expandKey">__expandKey</a></td> 121 <td><a href="#AES.__expandKey">__expandKey</a></td>
98 <td>Private method performing Rijndael's key expansion.</td> 122 <td>Private method performing Rijndael's key expansion.</td>
99 </tr><tr> 123 </tr>
124 <tr>
100 <td><a href="#AES.__galois_multiplication">__galois_multiplication</a></td> 125 <td><a href="#AES.__galois_multiplication">__galois_multiplication</a></td>
101 <td>Private method to perform a Galois multiplication of 8 bit characters a and b.</td> 126 <td>Private method to perform a Galois multiplication of 8 bit characters a and b.</td>
102 </tr><tr> 127 </tr>
128 <tr>
103 <td><a href="#AES.__getRconValue">__getRconValue</a></td> 129 <td><a href="#AES.__getRconValue">__getRconValue</a></td>
104 <td>Private method to retrieve a given Rcon value.</td> 130 <td>Private method to retrieve a given Rcon value.</td>
105 </tr><tr> 131 </tr>
132 <tr>
106 <td><a href="#AES.__getSBoxInvert">__getSBoxInvert</a></td> 133 <td><a href="#AES.__getSBoxInvert">__getSBoxInvert</a></td>
107 <td>Private method to retrieve a given Inverted S-Box value.</td> 134 <td>Private method to retrieve a given Inverted S-Box value.</td>
108 </tr><tr> 135 </tr>
136 <tr>
109 <td><a href="#AES.__getSBoxValue">__getSBoxValue</a></td> 137 <td><a href="#AES.__getSBoxValue">__getSBoxValue</a></td>
110 <td>Private method to retrieve a given S-Box value.</td> 138 <td>Private method to retrieve a given S-Box value.</td>
111 </tr><tr> 139 </tr>
140 <tr>
112 <td><a href="#AES.__mixColumn">__mixColumn</a></td> 141 <td><a href="#AES.__mixColumn">__mixColumn</a></td>
113 <td>Private method to perform a galois multiplication of 1 column the 4x4 matrix.</td> 142 <td>Private method to perform a galois multiplication of 1 column the 4x4 matrix.</td>
114 </tr><tr> 143 </tr>
144 <tr>
115 <td><a href="#AES.__mixColumns">__mixColumns</a></td> 145 <td><a href="#AES.__mixColumns">__mixColumns</a></td>
116 <td>Private method to perform a galois multiplication of the 4x4 matrix.</td> 146 <td>Private method to perform a galois multiplication of the 4x4 matrix.</td>
117 </tr><tr> 147 </tr>
148 <tr>
118 <td><a href="#AES.__rotate">__rotate</a></td> 149 <td><a href="#AES.__rotate">__rotate</a></td>
119 <td>Private method performing Rijndael's key schedule rotate operation.</td> 150 <td>Private method performing Rijndael's key schedule rotate operation.</td>
120 </tr><tr> 151 </tr>
152 <tr>
121 <td><a href="#AES.__shiftRow">__shiftRow</a></td> 153 <td><a href="#AES.__shiftRow">__shiftRow</a></td>
122 <td>Private method to shift the bytes of a row to the left.</td> 154 <td>Private method to shift the bytes of a row to the left.</td>
123 </tr><tr> 155 </tr>
156 <tr>
124 <td><a href="#AES.__shiftRows">__shiftRows</a></td> 157 <td><a href="#AES.__shiftRows">__shiftRows</a></td>
125 <td>Private method to iterate over the 4 rows and call __shiftRow() with that row.</td> 158 <td>Private method to iterate over the 4 rows and call __shiftRow() with that row.</td>
126 </tr><tr> 159 </tr>
160 <tr>
127 <td><a href="#AES.__subBytes">__subBytes</a></td> 161 <td><a href="#AES.__subBytes">__subBytes</a></td>
128 <td>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.</td> 162 <td>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.</td>
129 </tr><tr> 163 </tr>
164 <tr>
130 <td><a href="#AES.decrypt">decrypt</a></td> 165 <td><a href="#AES.decrypt">decrypt</a></td>
131 <td>Public method to decrypt a 128 bit input block against the given key of size specified.</td> 166 <td>Public method to decrypt a 128 bit input block against the given key of size specified.</td>
132 </tr><tr> 167 </tr>
168 <tr>
133 <td><a href="#AES.encrypt">encrypt</a></td> 169 <td><a href="#AES.encrypt">encrypt</a></td>
134 <td>Public method to encrypt a 128 bit input block against the given key of size specified.</td> 170 <td>Public method to encrypt a 128 bit input block against the given key of size specified.</td>
135 </tr> 171 </tr>
136 </table> 172 </table>
137 <h3>Static Methods</h3> 173 <h3>Static Methods</h3>
174
138 <table> 175 <table>
139 <tr><td>None</td></tr> 176 <tr><td>None</td></tr>
140 </table> 177 </table>
178
141 <a NAME="AES.__addRoundKey" ID="AES.__addRoundKey"></a> 179 <a NAME="AES.__addRoundKey" ID="AES.__addRoundKey"></a>
142 <h4>AES.__addRoundKey</h4> 180 <h4>AES.__addRoundKey</h4>
143 <b>__addRoundKey</b>(<i>state, roundKey</i>) 181 <b>__addRoundKey</b>(<i>state, roundKey</i>)
182
144 <p> 183 <p>
145 Private method to add (XORs) the round key to the state. 184 Private method to add (XORs) the round key to the state.
146 </p><dl> 185 </p>
186 <dl>
187
147 <dt><i>state</i></dt> 188 <dt><i>state</i></dt>
148 <dd> 189 <dd>
149 state to be changed (bytearray) 190 state to be changed (bytearray)
150 </dd><dt><i>roundKey</i></dt> 191 </dd>
192 <dt><i>roundKey</i></dt>
151 <dd> 193 <dd>
152 key to be used for the modification (bytearray) 194 key to be used for the modification (bytearray)
153 </dd> 195 </dd>
154 </dl><dl> 196 </dl>
197 <dl>
155 <dt>Returns:</dt> 198 <dt>Returns:</dt>
156 <dd> 199 <dd>
157 modified state (bytearray) 200 modified state (bytearray)
158 </dd> 201 </dd>
159 </dl><a NAME="AES.__aes_invMain" ID="AES.__aes_invMain"></a> 202 </dl>
203 <a NAME="AES.__aes_invMain" ID="AES.__aes_invMain"></a>
160 <h4>AES.__aes_invMain</h4> 204 <h4>AES.__aes_invMain</h4>
161 <b>__aes_invMain</b>(<i>state, expandedKey, nbrRounds</i>) 205 <b>__aes_invMain</b>(<i>state, expandedKey, nbrRounds</i>)
206
162 <p> 207 <p>
163 Private method to do the inverse AES encryption for one round. 208 Private method to do the inverse AES encryption for one round.
164 </p><p> 209 </p>
210 <p>
165 Perform the initial operations, the standard round, and the 211 Perform the initial operations, the standard round, and the
166 final operations of the inverse AES, creating a round key for 212 final operations of the inverse AES, creating a round key for
167 each round. 213 each round.
168 </p><dl> 214 </p>
215 <dl>
216
169 <dt><i>state</i></dt> 217 <dt><i>state</i></dt>
170 <dd> 218 <dd>
171 state to be worked on (bytearray) 219 state to be worked on (bytearray)
172 </dd><dt><i>expandedKey</i></dt> 220 </dd>
221 <dt><i>expandedKey</i></dt>
173 <dd> 222 <dd>
174 expanded key to be used (bytearray) 223 expanded key to be used (bytearray)
175 </dd><dt><i>nbrRounds</i></dt> 224 </dd>
225 <dt><i>nbrRounds</i></dt>
176 <dd> 226 <dd>
177 number of rounds to be done (integer) 227 number of rounds to be done (integer)
178 </dd> 228 </dd>
179 </dl><dl> 229 </dl>
230 <dl>
180 <dt>Returns:</dt> 231 <dt>Returns:</dt>
181 <dd> 232 <dd>
182 modified state (bytearray) 233 modified state (bytearray)
183 </dd> 234 </dd>
184 </dl><a NAME="AES.__aes_invRound" ID="AES.__aes_invRound"></a> 235 </dl>
236 <a NAME="AES.__aes_invRound" ID="AES.__aes_invRound"></a>
185 <h4>AES.__aes_invRound</h4> 237 <h4>AES.__aes_invRound</h4>
186 <b>__aes_invRound</b>(<i>state, roundKey</i>) 238 <b>__aes_invRound</b>(<i>state, roundKey</i>)
239
187 <p> 240 <p>
188 Private method to apply the 4 operations of the inverse round in 241 Private method to apply the 4 operations of the inverse round in
189 sequence. 242 sequence.
190 </p><dl> 243 </p>
244 <dl>
245
191 <dt><i>state</i></dt> 246 <dt><i>state</i></dt>
192 <dd> 247 <dd>
193 state to be worked on (bytearray) 248 state to be worked on (bytearray)
194 </dd><dt><i>roundKey</i></dt> 249 </dd>
250 <dt><i>roundKey</i></dt>
195 <dd> 251 <dd>
196 round key to be used (bytearray) 252 round key to be used (bytearray)
197 </dd> 253 </dd>
198 </dl><dl> 254 </dl>
255 <dl>
199 <dt>Returns:</dt> 256 <dt>Returns:</dt>
200 <dd> 257 <dd>
201 modified state (bytearray) 258 modified state (bytearray)
202 </dd> 259 </dd>
203 </dl><a NAME="AES.__aes_main" ID="AES.__aes_main"></a> 260 </dl>
261 <a NAME="AES.__aes_main" ID="AES.__aes_main"></a>
204 <h4>AES.__aes_main</h4> 262 <h4>AES.__aes_main</h4>
205 <b>__aes_main</b>(<i>state, expandedKey, nbrRounds</i>) 263 <b>__aes_main</b>(<i>state, expandedKey, nbrRounds</i>)
264
206 <p> 265 <p>
207 Private method to do the AES encryption for one round. 266 Private method to do the AES encryption for one round.
208 </p><p> 267 </p>
268 <p>
209 Perform the initial operations, the standard round, and the 269 Perform the initial operations, the standard round, and the
210 final operations of the forward AES, creating a round key for 270 final operations of the forward AES, creating a round key for
211 each round. 271 each round.
212 </p><dl> 272 </p>
273 <dl>
274
213 <dt><i>state</i></dt> 275 <dt><i>state</i></dt>
214 <dd> 276 <dd>
215 state to be worked on (bytearray) 277 state to be worked on (bytearray)
216 </dd><dt><i>expandedKey</i></dt> 278 </dd>
279 <dt><i>expandedKey</i></dt>
217 <dd> 280 <dd>
218 expanded key to be used (bytearray) 281 expanded key to be used (bytearray)
219 </dd><dt><i>nbrRounds</i></dt> 282 </dd>
283 <dt><i>nbrRounds</i></dt>
220 <dd> 284 <dd>
221 number of rounds to be done (integer) 285 number of rounds to be done (integer)
222 </dd> 286 </dd>
223 </dl><dl> 287 </dl>
288 <dl>
224 <dt>Returns:</dt> 289 <dt>Returns:</dt>
225 <dd> 290 <dd>
226 modified state (bytearray) 291 modified state (bytearray)
227 </dd> 292 </dd>
228 </dl><a NAME="AES.__aes_round" ID="AES.__aes_round"></a> 293 </dl>
294 <a NAME="AES.__aes_round" ID="AES.__aes_round"></a>
229 <h4>AES.__aes_round</h4> 295 <h4>AES.__aes_round</h4>
230 <b>__aes_round</b>(<i>state, roundKey</i>) 296 <b>__aes_round</b>(<i>state, roundKey</i>)
297
231 <p> 298 <p>
232 Private method to apply the 4 operations of the forward round in 299 Private method to apply the 4 operations of the forward round in
233 sequence. 300 sequence.
234 </p><dl> 301 </p>
302 <dl>
303
235 <dt><i>state</i></dt> 304 <dt><i>state</i></dt>
236 <dd> 305 <dd>
237 state to be worked on (bytearray) 306 state to be worked on (bytearray)
238 </dd><dt><i>roundKey</i></dt> 307 </dd>
308 <dt><i>roundKey</i></dt>
239 <dd> 309 <dd>
240 round key to be used (bytearray) 310 round key to be used (bytearray)
241 </dd> 311 </dd>
242 </dl><dl> 312 </dl>
313 <dl>
243 <dt>Returns:</dt> 314 <dt>Returns:</dt>
244 <dd> 315 <dd>
245 modified state (bytearray) 316 modified state (bytearray)
246 </dd> 317 </dd>
247 </dl><a NAME="AES.__core" ID="AES.__core"></a> 318 </dl>
319 <a NAME="AES.__core" ID="AES.__core"></a>
248 <h4>AES.__core</h4> 320 <h4>AES.__core</h4>
249 <b>__core</b>(<i>data, iteration</i>) 321 <b>__core</b>(<i>data, iteration</i>)
322
250 <p> 323 <p>
251 Private method performing the key schedule core operation. 324 Private method performing the key schedule core operation.
252 </p><dl> 325 </p>
326 <dl>
327
253 <dt><i>data</i></dt> 328 <dt><i>data</i></dt>
254 <dd> 329 <dd>
255 data to operate on (bytearray) 330 data to operate on (bytearray)
256 </dd><dt><i>iteration</i></dt> 331 </dd>
332 <dt><i>iteration</i></dt>
257 <dd> 333 <dd>
258 iteration counter (integer) 334 iteration counter (integer)
259 </dd> 335 </dd>
260 </dl><dl> 336 </dl>
337 <dl>
261 <dt>Returns:</dt> 338 <dt>Returns:</dt>
262 <dd> 339 <dd>
263 modified data (bytearray) 340 modified data (bytearray)
264 </dd> 341 </dd>
265 </dl><a NAME="AES.__createRoundKey" ID="AES.__createRoundKey"></a> 342 </dl>
343 <a NAME="AES.__createRoundKey" ID="AES.__createRoundKey"></a>
266 <h4>AES.__createRoundKey</h4> 344 <h4>AES.__createRoundKey</h4>
267 <b>__createRoundKey</b>(<i>expandedKey, roundKeyPointer</i>) 345 <b>__createRoundKey</b>(<i>expandedKey, roundKeyPointer</i>)
346
268 <p> 347 <p>
269 Private method to create a round key. 348 Private method to create a round key.
270 </p><dl> 349 </p>
350 <dl>
351
271 <dt><i>expandedKey</i></dt> 352 <dt><i>expandedKey</i></dt>
272 <dd> 353 <dd>
273 expanded key to be used (bytearray) 354 expanded key to be used (bytearray)
274 </dd><dt><i>roundKeyPointer</i></dt> 355 </dd>
356 <dt><i>roundKeyPointer</i></dt>
275 <dd> 357 <dd>
276 position within the expanded key (integer) 358 position within the expanded key (integer)
277 </dd> 359 </dd>
278 </dl><dl> 360 </dl>
361 <dl>
279 <dt>Returns:</dt> 362 <dt>Returns:</dt>
280 <dd> 363 <dd>
281 round key (bytearray) 364 round key (bytearray)
282 </dd> 365 </dd>
283 </dl><a NAME="AES.__expandKey" ID="AES.__expandKey"></a> 366 </dl>
367 <a NAME="AES.__expandKey" ID="AES.__expandKey"></a>
284 <h4>AES.__expandKey</h4> 368 <h4>AES.__expandKey</h4>
285 <b>__expandKey</b>(<i>key, size, expandedKeySize</i>) 369 <b>__expandKey</b>(<i>key, size, expandedKeySize</i>)
370
286 <p> 371 <p>
287 Private method performing Rijndael's key expansion. 372 Private method performing Rijndael's key expansion.
288 </p><p> 373 </p>
374 <p>
289 Expands a 128, 192 or 256 bit key into a 176, 208 or 240 bit key. 375 Expands a 128, 192 or 256 bit key into a 176, 208 or 240 bit key.
290 </p><dl> 376 </p>
377 <dl>
378
291 <dt><i>key</i></dt> 379 <dt><i>key</i></dt>
292 <dd> 380 <dd>
293 key to be expanded (bytes or bytearray) 381 key to be expanded (bytes or bytearray)
294 </dd><dt><i>size</i></dt> 382 </dd>
383 <dt><i>size</i></dt>
295 <dd> 384 <dd>
296 size of the key in bytes (16, 24 or 32) 385 size of the key in bytes (16, 24 or 32)
297 </dd><dt><i>expandedKeySize</i></dt> 386 </dd>
387 <dt><i>expandedKeySize</i></dt>
298 <dd> 388 <dd>
299 size of the expanded key (integer) 389 size of the expanded key (integer)
300 </dd> 390 </dd>
301 </dl><dl> 391 </dl>
392 <dl>
302 <dt>Returns:</dt> 393 <dt>Returns:</dt>
303 <dd> 394 <dd>
304 expanded key (bytearray) 395 expanded key (bytearray)
305 </dd> 396 </dd>
306 </dl><a NAME="AES.__galois_multiplication" ID="AES.__galois_multiplication"></a> 397 </dl>
398 <a NAME="AES.__galois_multiplication" ID="AES.__galois_multiplication"></a>
307 <h4>AES.__galois_multiplication</h4> 399 <h4>AES.__galois_multiplication</h4>
308 <b>__galois_multiplication</b>(<i>a, b</i>) 400 <b>__galois_multiplication</b>(<i>a, b</i>)
401
309 <p> 402 <p>
310 Private method to perform a Galois multiplication of 8 bit characters 403 Private method to perform a Galois multiplication of 8 bit characters
311 a and b. 404 a and b.
312 </p><dl> 405 </p>
406 <dl>
407
313 <dt><i>a</i></dt> 408 <dt><i>a</i></dt>
314 <dd> 409 <dd>
315 first factor (byte) 410 first factor (byte)
316 </dd><dt><i>b</i></dt> 411 </dd>
412 <dt><i>b</i></dt>
317 <dd> 413 <dd>
318 second factor (byte) 414 second factor (byte)
319 </dd> 415 </dd>
320 </dl><dl> 416 </dl>
417 <dl>
321 <dt>Returns:</dt> 418 <dt>Returns:</dt>
322 <dd> 419 <dd>
323 result (byte) 420 result (byte)
324 </dd> 421 </dd>
325 </dl><a NAME="AES.__getRconValue" ID="AES.__getRconValue"></a> 422 </dl>
423 <a NAME="AES.__getRconValue" ID="AES.__getRconValue"></a>
326 <h4>AES.__getRconValue</h4> 424 <h4>AES.__getRconValue</h4>
327 <b>__getRconValue</b>(<i>num</i>) 425 <b>__getRconValue</b>(<i>num</i>)
426
328 <p> 427 <p>
329 Private method to retrieve a given Rcon value. 428 Private method to retrieve a given Rcon value.
330 </p><dl> 429 </p>
430 <dl>
431
331 <dt><i>num</i></dt> 432 <dt><i>num</i></dt>
332 <dd> 433 <dd>
333 position of the value (integer) 434 position of the value (integer)
334 </dd> 435 </dd>
335 </dl><dl> 436 </dl>
437 <dl>
336 <dt>Returns:</dt> 438 <dt>Returns:</dt>
337 <dd> 439 <dd>
338 Rcon value (integer) 440 Rcon value (integer)
339 </dd> 441 </dd>
340 </dl><a NAME="AES.__getSBoxInvert" ID="AES.__getSBoxInvert"></a> 442 </dl>
443 <a NAME="AES.__getSBoxInvert" ID="AES.__getSBoxInvert"></a>
341 <h4>AES.__getSBoxInvert</h4> 444 <h4>AES.__getSBoxInvert</h4>
342 <b>__getSBoxInvert</b>(<i>num</i>) 445 <b>__getSBoxInvert</b>(<i>num</i>)
446
343 <p> 447 <p>
344 Private method to retrieve a given Inverted S-Box value. 448 Private method to retrieve a given Inverted S-Box value.
345 </p><dl> 449 </p>
450 <dl>
451
346 <dt><i>num</i></dt> 452 <dt><i>num</i></dt>
347 <dd> 453 <dd>
348 position of the value (integer) 454 position of the value (integer)
349 </dd> 455 </dd>
350 </dl><dl> 456 </dl>
457 <dl>
351 <dt>Returns:</dt> 458 <dt>Returns:</dt>
352 <dd> 459 <dd>
353 value of the Inverted S-Box (integer) 460 value of the Inverted S-Box (integer)
354 </dd> 461 </dd>
355 </dl><a NAME="AES.__getSBoxValue" ID="AES.__getSBoxValue"></a> 462 </dl>
463 <a NAME="AES.__getSBoxValue" ID="AES.__getSBoxValue"></a>
356 <h4>AES.__getSBoxValue</h4> 464 <h4>AES.__getSBoxValue</h4>
357 <b>__getSBoxValue</b>(<i>num</i>) 465 <b>__getSBoxValue</b>(<i>num</i>)
466
358 <p> 467 <p>
359 Private method to retrieve a given S-Box value. 468 Private method to retrieve a given S-Box value.
360 </p><dl> 469 </p>
470 <dl>
471
361 <dt><i>num</i></dt> 472 <dt><i>num</i></dt>
362 <dd> 473 <dd>
363 position of the value (integer) 474 position of the value (integer)
364 </dd> 475 </dd>
365 </dl><dl> 476 </dl>
477 <dl>
366 <dt>Returns:</dt> 478 <dt>Returns:</dt>
367 <dd> 479 <dd>
368 value of the S-Box (integer) 480 value of the S-Box (integer)
369 </dd> 481 </dd>
370 </dl><a NAME="AES.__mixColumn" ID="AES.__mixColumn"></a> 482 </dl>
483 <a NAME="AES.__mixColumn" ID="AES.__mixColumn"></a>
371 <h4>AES.__mixColumn</h4> 484 <h4>AES.__mixColumn</h4>
372 <b>__mixColumn</b>(<i>column, isInv</i>) 485 <b>__mixColumn</b>(<i>column, isInv</i>)
486
373 <p> 487 <p>
374 Private method to perform a galois multiplication of 1 column the 488 Private method to perform a galois multiplication of 1 column the
375 4x4 matrix. 489 4x4 matrix.
376 </p><dl> 490 </p>
491 <dl>
492
377 <dt><i>column</i></dt> 493 <dt><i>column</i></dt>
378 <dd> 494 <dd>
379 column to be worked on (bytearray) 495 column to be worked on (bytearray)
380 </dd><dt><i>isInv</i></dt> 496 </dd>
497 <dt><i>isInv</i></dt>
381 <dd> 498 <dd>
382 flag indicating an inverse operation (boolean) 499 flag indicating an inverse operation (boolean)
383 </dd> 500 </dd>
384 </dl><dl> 501 </dl>
502 <dl>
385 <dt>Returns:</dt> 503 <dt>Returns:</dt>
386 <dd> 504 <dd>
387 modified column (bytearray) 505 modified column (bytearray)
388 </dd> 506 </dd>
389 </dl><a NAME="AES.__mixColumns" ID="AES.__mixColumns"></a> 507 </dl>
508 <a NAME="AES.__mixColumns" ID="AES.__mixColumns"></a>
390 <h4>AES.__mixColumns</h4> 509 <h4>AES.__mixColumns</h4>
391 <b>__mixColumns</b>(<i>state, isInv</i>) 510 <b>__mixColumns</b>(<i>state, isInv</i>)
511
392 <p> 512 <p>
393 Private method to perform a galois multiplication of the 4x4 matrix. 513 Private method to perform a galois multiplication of the 4x4 matrix.
394 </p><dl> 514 </p>
515 <dl>
516
395 <dt><i>state</i></dt> 517 <dt><i>state</i></dt>
396 <dd> 518 <dd>
397 state to be worked on (bytearray) 519 state to be worked on (bytearray)
398 </dd><dt><i>isInv</i></dt> 520 </dd>
521 <dt><i>isInv</i></dt>
399 <dd> 522 <dd>
400 flag indicating an inverse operation (boolean) 523 flag indicating an inverse operation (boolean)
401 </dd> 524 </dd>
402 </dl><dl> 525 </dl>
526 <dl>
403 <dt>Returns:</dt> 527 <dt>Returns:</dt>
404 <dd> 528 <dd>
405 modified state (bytearray) 529 modified state (bytearray)
406 </dd> 530 </dd>
407 </dl><a NAME="AES.__rotate" ID="AES.__rotate"></a> 531 </dl>
532 <a NAME="AES.__rotate" ID="AES.__rotate"></a>
408 <h4>AES.__rotate</h4> 533 <h4>AES.__rotate</h4>
409 <b>__rotate</b>(<i>data</i>) 534 <b>__rotate</b>(<i>data</i>)
535
410 <p> 536 <p>
411 Private method performing Rijndael's key schedule rotate operation. 537 Private method performing Rijndael's key schedule rotate operation.
412 </p><p> 538 </p>
539 <p>
413 Rotate the data word eight bits to the left: eg, 540 Rotate the data word eight bits to the left: eg,
414 rotate(1d2c3a4f) == 2c3a4f1d. 541 rotate(1d2c3a4f) == 2c3a4f1d.
415 </p><dl> 542 </p>
543 <dl>
544
416 <dt><i>data</i></dt> 545 <dt><i>data</i></dt>
417 <dd> 546 <dd>
418 data of size 4 (bytearray) 547 data of size 4 (bytearray)
419 </dd> 548 </dd>
420 </dl><dl> 549 </dl>
550 <dl>
421 <dt>Returns:</dt> 551 <dt>Returns:</dt>
422 <dd> 552 <dd>
423 rotated data (bytearray) 553 rotated data (bytearray)
424 </dd> 554 </dd>
425 </dl><a NAME="AES.__shiftRow" ID="AES.__shiftRow"></a> 555 </dl>
556 <a NAME="AES.__shiftRow" ID="AES.__shiftRow"></a>
426 <h4>AES.__shiftRow</h4> 557 <h4>AES.__shiftRow</h4>
427 <b>__shiftRow</b>(<i>state, statePointer, nbr, isInv</i>) 558 <b>__shiftRow</b>(<i>state, statePointer, nbr, isInv</i>)
559
428 <p> 560 <p>
429 Private method to shift the bytes of a row to the left. 561 Private method to shift the bytes of a row to the left.
430 </p><dl> 562 </p>
563 <dl>
564
431 <dt><i>state</i></dt> 565 <dt><i>state</i></dt>
432 <dd> 566 <dd>
433 state to be worked on (bytearray) 567 state to be worked on (bytearray)
434 </dd><dt><i>statePointer</i></dt> 568 </dd>
569 <dt><i>statePointer</i></dt>
435 <dd> 570 <dd>
436 index into the state (integer) 571 index into the state (integer)
437 </dd><dt><i>nbr</i></dt> 572 </dd>
573 <dt><i>nbr</i></dt>
438 <dd> 574 <dd>
439 number of positions to shift (integer) 575 number of positions to shift (integer)
440 </dd><dt><i>isInv</i></dt> 576 </dd>
577 <dt><i>isInv</i></dt>
441 <dd> 578 <dd>
442 flag indicating an inverse operation (boolean) 579 flag indicating an inverse operation (boolean)
443 </dd> 580 </dd>
444 </dl><dl> 581 </dl>
582 <dl>
445 <dt>Returns:</dt> 583 <dt>Returns:</dt>
446 <dd> 584 <dd>
447 modified state (bytearray) 585 modified state (bytearray)
448 </dd> 586 </dd>
449 </dl><a NAME="AES.__shiftRows" ID="AES.__shiftRows"></a> 587 </dl>
588 <a NAME="AES.__shiftRows" ID="AES.__shiftRows"></a>
450 <h4>AES.__shiftRows</h4> 589 <h4>AES.__shiftRows</h4>
451 <b>__shiftRows</b>(<i>state, isInv</i>) 590 <b>__shiftRows</b>(<i>state, isInv</i>)
591
452 <p> 592 <p>
453 Private method to iterate over the 4 rows and call __shiftRow() with 593 Private method to iterate over the 4 rows and call __shiftRow() with
454 that row. 594 that row.
455 </p><dl> 595 </p>
596 <dl>
597
456 <dt><i>state</i></dt> 598 <dt><i>state</i></dt>
457 <dd> 599 <dd>
458 state to be worked on (bytearray) 600 state to be worked on (bytearray)
459 </dd><dt><i>isInv</i></dt> 601 </dd>
602 <dt><i>isInv</i></dt>
460 <dd> 603 <dd>
461 flag indicating an inverse operation (boolean) 604 flag indicating an inverse operation (boolean)
462 </dd> 605 </dd>
463 </dl><dl> 606 </dl>
607 <dl>
464 <dt>Returns:</dt> 608 <dt>Returns:</dt>
465 <dd> 609 <dd>
466 modified state (bytearray) 610 modified state (bytearray)
467 </dd> 611 </dd>
468 </dl><a NAME="AES.__subBytes" ID="AES.__subBytes"></a> 612 </dl>
613 <a NAME="AES.__subBytes" ID="AES.__subBytes"></a>
469 <h4>AES.__subBytes</h4> 614 <h4>AES.__subBytes</h4>
470 <b>__subBytes</b>(<i>state, isInv</i>) 615 <b>__subBytes</b>(<i>state, isInv</i>)
616
471 <p> 617 <p>
472 Private method to substitute all the values from the state with the 618 Private method to substitute all the values from the state with the
473 value in the SBox using the state value as index for the SBox. 619 value in the SBox using the state value as index for the SBox.
474 </p><dl> 620 </p>
621 <dl>
622
475 <dt><i>state</i></dt> 623 <dt><i>state</i></dt>
476 <dd> 624 <dd>
477 state to be worked on (bytearray) 625 state to be worked on (bytearray)
478 </dd><dt><i>isInv</i></dt> 626 </dd>
627 <dt><i>isInv</i></dt>
479 <dd> 628 <dd>
480 flag indicating an inverse operation (boolean) 629 flag indicating an inverse operation (boolean)
481 </dd> 630 </dd>
482 </dl><dl> 631 </dl>
632 <dl>
483 <dt>Returns:</dt> 633 <dt>Returns:</dt>
484 <dd> 634 <dd>
485 modified state (bytearray) 635 modified state (bytearray)
486 </dd> 636 </dd>
487 </dl><a NAME="AES.decrypt" ID="AES.decrypt"></a> 637 </dl>
638 <a NAME="AES.decrypt" ID="AES.decrypt"></a>
488 <h4>AES.decrypt</h4> 639 <h4>AES.decrypt</h4>
489 <b>decrypt</b>(<i>iput, key, size</i>) 640 <b>decrypt</b>(<i>iput, key, size</i>)
641
490 <p> 642 <p>
491 Public method to decrypt a 128 bit input block against the given key 643 Public method to decrypt a 128 bit input block against the given key
492 of size specified. 644 of size specified.
493 </p><dl> 645 </p>
646 <dl>
647
494 <dt><i>iput</i></dt> 648 <dt><i>iput</i></dt>
495 <dd> 649 <dd>
496 input data (bytearray) 650 input data (bytearray)
497 </dd><dt><i>key</i></dt> 651 </dd>
652 <dt><i>key</i></dt>
498 <dd> 653 <dd>
499 key to be used (bytes or bytearray) 654 key to be used (bytes or bytearray)
500 </dd><dt><i>size</i></dt> 655 </dd>
656 <dt><i>size</i></dt>
501 <dd> 657 <dd>
502 key size (16, 24 or 32) 658 key size (16, 24 or 32)
503 </dd> 659 </dd>
504 </dl><dl> 660 </dl>
661 <dl>
505 <dt>Returns:</dt> 662 <dt>Returns:</dt>
506 <dd> 663 <dd>
507 decrypted data (bytes) 664 decrypted data (bytes)
508 </dd> 665 </dd>
509 </dl><dl> 666 </dl>
667 <dl>
668
510 <dt>Raises <b>ValueError</b>:</dt> 669 <dt>Raises <b>ValueError</b>:</dt>
511 <dd> 670 <dd>
512 key size is invalid 671 key size is invalid
513 </dd> 672 </dd>
514 </dl><a NAME="AES.encrypt" ID="AES.encrypt"></a> 673 </dl>
674 <a NAME="AES.encrypt" ID="AES.encrypt"></a>
515 <h4>AES.encrypt</h4> 675 <h4>AES.encrypt</h4>
516 <b>encrypt</b>(<i>iput, key, size</i>) 676 <b>encrypt</b>(<i>iput, key, size</i>)
677
517 <p> 678 <p>
518 Public method to encrypt a 128 bit input block against the given key 679 Public method to encrypt a 128 bit input block against the given key
519 of size specified. 680 of size specified.
520 </p><dl> 681 </p>
682 <dl>
683
521 <dt><i>iput</i></dt> 684 <dt><i>iput</i></dt>
522 <dd> 685 <dd>
523 input data (bytearray) 686 input data (bytearray)
524 </dd><dt><i>key</i></dt> 687 </dd>
688 <dt><i>key</i></dt>
525 <dd> 689 <dd>
526 key to be used (bytes or bytearray) 690 key to be used (bytes or bytearray)
527 </dd><dt><i>size</i></dt> 691 </dd>
692 <dt><i>size</i></dt>
528 <dd> 693 <dd>
529 key size (16, 24 or 32) 694 key size (16, 24 or 32)
530 </dd> 695 </dd>
531 </dl><dl> 696 </dl>
697 <dl>
532 <dt>Returns:</dt> 698 <dt>Returns:</dt>
533 <dd> 699 <dd>
534 encrypted data (bytes) 700 encrypted data (bytes)
535 </dd> 701 </dd>
536 </dl><dl> 702 </dl>
703 <dl>
704
537 <dt>Raises <b>ValueError</b>:</dt> 705 <dt>Raises <b>ValueError</b>:</dt>
538 <dd> 706 <dd>
539 key size is invalid 707 key size is invalid
540 </dd> 708 </dd>
541 </dl> 709 </dl>
542 <div align="right"><a href="#top">Up</a></div> 710 <div align="right"><a href="#top">Up</a></div>
543 <hr /><hr /> 711 <hr />
712 <hr />
544 <a NAME="AESModeOfOperation" ID="AESModeOfOperation"></a> 713 <a NAME="AESModeOfOperation" ID="AESModeOfOperation"></a>
545 <h2>AESModeOfOperation</h2> 714 <h2>AESModeOfOperation</h2>
715
546 <p> 716 <p>
547 Class implementing the different AES mode of operations. 717 Class implementing the different AES mode of operations.
548 </p> 718 </p>
549 <h3>Derived from</h3> 719 <h3>Derived from</h3>
550 object 720 object
551 <h3>Class Attributes</h3> 721 <h3>Class Attributes</h3>
722
552 <table> 723 <table>
553 <tr><td>ModeOfOperation</td></tr><tr><td>aes</td></tr> 724 <tr><td>ModeOfOperation</td></tr><tr><td>aes</td></tr>
554 </table> 725 </table>
555 <h3>Class Methods</h3> 726 <h3>Class Methods</h3>
727
556 <table> 728 <table>
557 <tr><td>None</td></tr> 729 <tr><td>None</td></tr>
558 </table> 730 </table>
559 <h3>Methods</h3> 731 <h3>Methods</h3>
560 <table> 732
733 <table>
734
561 <tr> 735 <tr>
562 <td><a href="#AESModeOfOperation.__extractBytes">__extractBytes</a></td> 736 <td><a href="#AESModeOfOperation.__extractBytes">__extractBytes</a></td>
563 <td>Private method to extract a range of bytes from the input.</td> 737 <td>Private method to extract a range of bytes from the input.</td>
564 </tr><tr> 738 </tr>
739 <tr>
565 <td><a href="#AESModeOfOperation.decrypt">decrypt</a></td> 740 <td><a href="#AESModeOfOperation.decrypt">decrypt</a></td>
566 <td>Public method to perform the decryption operation.</td> 741 <td>Public method to perform the decryption operation.</td>
567 </tr><tr> 742 </tr>
743 <tr>
568 <td><a href="#AESModeOfOperation.encrypt">encrypt</a></td> 744 <td><a href="#AESModeOfOperation.encrypt">encrypt</a></td>
569 <td>Public method to perform the encryption operation.</td> 745 <td>Public method to perform the encryption operation.</td>
570 </tr> 746 </tr>
571 </table> 747 </table>
572 <h3>Static Methods</h3> 748 <h3>Static Methods</h3>
749
573 <table> 750 <table>
574 <tr><td>None</td></tr> 751 <tr><td>None</td></tr>
575 </table> 752 </table>
753
576 <a NAME="AESModeOfOperation.__extractBytes" ID="AESModeOfOperation.__extractBytes"></a> 754 <a NAME="AESModeOfOperation.__extractBytes" ID="AESModeOfOperation.__extractBytes"></a>
577 <h4>AESModeOfOperation.__extractBytes</h4> 755 <h4>AESModeOfOperation.__extractBytes</h4>
578 <b>__extractBytes</b>(<i>inputData, start, end, mode</i>) 756 <b>__extractBytes</b>(<i>inputData, start, end, mode</i>)
757
579 <p> 758 <p>
580 Private method to extract a range of bytes from the input. 759 Private method to extract a range of bytes from the input.
581 </p><dl> 760 </p>
761 <dl>
762
582 <dt><i>inputData</i></dt> 763 <dt><i>inputData</i></dt>
583 <dd> 764 <dd>
584 input data (bytes) 765 input data (bytes)
585 </dd><dt><i>start</i></dt> 766 </dd>
767 <dt><i>start</i></dt>
586 <dd> 768 <dd>
587 start index (integer) 769 start index (integer)
588 </dd><dt><i>end</i></dt> 770 </dd>
771 <dt><i>end</i></dt>
589 <dd> 772 <dd>
590 end index (integer) 773 end index (integer)
591 </dd><dt><i>mode</i></dt> 774 </dd>
775 <dt><i>mode</i></dt>
592 <dd> 776 <dd>
593 mode of operation (0, 1, 2) 777 mode of operation (0, 1, 2)
594 </dd> 778 </dd>
595 </dl><dl> 779 </dl>
780 <dl>
596 <dt>Returns:</dt> 781 <dt>Returns:</dt>
597 <dd> 782 <dd>
598 extracted bytes (bytearray) 783 extracted bytes (bytearray)
599 </dd> 784 </dd>
600 </dl><a NAME="AESModeOfOperation.decrypt" ID="AESModeOfOperation.decrypt"></a> 785 </dl>
786 <a NAME="AESModeOfOperation.decrypt" ID="AESModeOfOperation.decrypt"></a>
601 <h4>AESModeOfOperation.decrypt</h4> 787 <h4>AESModeOfOperation.decrypt</h4>
602 <b>decrypt</b>(<i>cipherIn, originalsize, mode, key, size, IV</i>) 788 <b>decrypt</b>(<i>cipherIn, originalsize, mode, key, size, IV</i>)
789
603 <p> 790 <p>
604 Public method to perform the decryption operation. 791 Public method to perform the decryption operation.
605 </p><dl> 792 </p>
793 <dl>
794
606 <dt><i>cipherIn</i></dt> 795 <dt><i>cipherIn</i></dt>
607 <dd> 796 <dd>
608 data to be decrypted (bytes) 797 data to be decrypted (bytes)
609 </dd><dt><i>originalsize</i></dt> 798 </dd>
799 <dt><i>originalsize</i></dt>
610 <dd> 800 <dd>
611 unencrypted string length (required for CBC) 801 unencrypted string length (required for CBC)
612 (integer) 802 (integer)
613 </dd><dt><i>mode</i></dt> 803 </dd>
804 <dt><i>mode</i></dt>
614 <dd> 805 <dd>
615 mode of operation (0, 1 or 2) 806 mode of operation (0, 1 or 2)
616 </dd><dt><i>key</i></dt> 807 </dd>
808 <dt><i>key</i></dt>
617 <dd> 809 <dd>
618 key to be used (bytes) 810 key to be used (bytes)
619 </dd><dt><i>size</i></dt> 811 </dd>
812 <dt><i>size</i></dt>
620 <dd> 813 <dd>
621 length of the key (16, 24 or 32) 814 length of the key (16, 24 or 32)
622 </dd><dt><i>IV</i></dt> 815 </dd>
816 <dt><i>IV</i></dt>
623 <dd> 817 <dd>
624 initialisation vector (bytearray) 818 initialisation vector (bytearray)
625 </dd> 819 </dd>
626 </dl><dl> 820 </dl>
821 <dl>
627 <dt>Returns:</dt> 822 <dt>Returns:</dt>
628 <dd> 823 <dd>
629 decrypted data (bytes) 824 decrypted data (bytes)
630 </dd> 825 </dd>
631 </dl><dl> 826 </dl>
827 <dl>
828
632 <dt>Raises <b>ValueError</b>:</dt> 829 <dt>Raises <b>ValueError</b>:</dt>
633 <dd> 830 <dd>
634 key size is invalid or decrypted data is invalid 831 key size is invalid or decrypted data is invalid
635 </dd> 832 </dd>
636 </dl><a NAME="AESModeOfOperation.encrypt" ID="AESModeOfOperation.encrypt"></a> 833 </dl>
834 <a NAME="AESModeOfOperation.encrypt" ID="AESModeOfOperation.encrypt"></a>
637 <h4>AESModeOfOperation.encrypt</h4> 835 <h4>AESModeOfOperation.encrypt</h4>
638 <b>encrypt</b>(<i>inputData, mode, key, size, IV</i>) 836 <b>encrypt</b>(<i>inputData, mode, key, size, IV</i>)
837
639 <p> 838 <p>
640 Public method to perform the encryption operation. 839 Public method to perform the encryption operation.
641 </p><dl> 840 </p>
841 <dl>
842
642 <dt><i>inputData</i></dt> 843 <dt><i>inputData</i></dt>
643 <dd> 844 <dd>
644 data to be encrypted (bytes) 845 data to be encrypted (bytes)
645 </dd><dt><i>mode</i></dt> 846 </dd>
847 <dt><i>mode</i></dt>
646 <dd> 848 <dd>
647 mode of operation (0, 1 or 2) 849 mode of operation (0, 1 or 2)
648 </dd><dt><i>key</i></dt> 850 </dd>
851 <dt><i>key</i></dt>
649 <dd> 852 <dd>
650 key to be used (bytes) 853 key to be used (bytes)
651 </dd><dt><i>size</i></dt> 854 </dd>
855 <dt><i>size</i></dt>
652 <dd> 856 <dd>
653 length of the key (16, 24 or 32) 857 length of the key (16, 24 or 32)
654 </dd><dt><i>IV</i></dt> 858 </dd>
859 <dt><i>IV</i></dt>
655 <dd> 860 <dd>
656 initialisation vector (bytearray) 861 initialisation vector (bytearray)
657 </dd> 862 </dd>
658 </dl><dl> 863 </dl>
864 <dl>
659 <dt>Returns:</dt> 865 <dt>Returns:</dt>
660 <dd> 866 <dd>
661 tuple with mode of operation, length of the input data and 867 tuple with mode of operation, length of the input data and
662 the encrypted data (integer, integer, bytes) 868 the encrypted data (integer, integer, bytes)
663 </dd> 869 </dd>
664 </dl><dl> 870 </dl>
871 <dl>
872
665 <dt>Raises <b>ValueError</b>:</dt> 873 <dt>Raises <b>ValueError</b>:</dt>
666 <dd> 874 <dd>
667 key size is invalid or decrypted data is invalid 875 key size is invalid or decrypted data is invalid
668 </dd> 876 </dd>
669 </dl> 877 </dl>
670 <div align="right"><a href="#top">Up</a></div> 878 <div align="right"><a href="#top">Up</a></div>
671 <hr /><hr /> 879 <hr />
880 <hr />
672 <a NAME="append_PKCS7_padding" ID="append_PKCS7_padding"></a> 881 <a NAME="append_PKCS7_padding" ID="append_PKCS7_padding"></a>
673 <h2>append_PKCS7_padding</h2> 882 <h2>append_PKCS7_padding</h2>
674 <b>append_PKCS7_padding</b>(<i>b</i>) 883 <b>append_PKCS7_padding</b>(<i>b</i>)
884
675 <p> 885 <p>
676 Function to pad the given data to a multiple of 16-bytes by PKCS7 padding. 886 Function to pad the given data to a multiple of 16-bytes by PKCS7 padding.
677 </p><dl> 887 </p>
888 <dl>
889
678 <dt><i>b</i></dt> 890 <dt><i>b</i></dt>
679 <dd> 891 <dd>
680 data to be padded (bytes) 892 data to be padded (bytes)
681 </dd> 893 </dd>
682 </dl><dl> 894 </dl>
895 <dl>
683 <dt>Returns:</dt> 896 <dt>Returns:</dt>
684 <dd> 897 <dd>
685 padded data (bytes) 898 padded data (bytes)
686 </dd> 899 </dd>
687 </dl> 900 </dl>
688 <div align="right"><a href="#top">Up</a></div> 901 <div align="right"><a href="#top">Up</a></div>
689 <hr /><hr /> 902 <hr />
903 <hr />
690 <a NAME="decryptData" ID="decryptData"></a> 904 <a NAME="decryptData" ID="decryptData"></a>
691 <h2>decryptData</h2> 905 <h2>decryptData</h2>
692 <b>decryptData</b>(<i>key, data, mode=AESModeOfOperation.ModeOfOperation["CBC"]</i>) 906 <b>decryptData</b>(<i>key, data, mode=AESModeOfOperation.ModeOfOperation["CBC"]</i>)
907
693 <p> 908 <p>
694 Module function to decrypt the given data with the given key. 909 Module function to decrypt the given data with the given key.
695 </p><dl> 910 </p>
911 <dl>
912
696 <dt><i>key</i></dt> 913 <dt><i>key</i></dt>
697 <dd> 914 <dd>
698 key to be used for decryption (bytes) 915 key to be used for decryption (bytes)
699 </dd><dt><i>data</i></dt> 916 </dd>
917 <dt><i>data</i></dt>
700 <dd> 918 <dd>
701 data to be decrypted (with initialization vector prepended) 919 data to be decrypted (with initialization vector prepended)
702 (bytes) 920 (bytes)
703 </dd><dt><i>mode</i></dt> 921 </dd>
922 <dt><i>mode</i></dt>
704 <dd> 923 <dd>
705 mode of operations (0, 1 or 2) 924 mode of operations (0, 1 or 2)
706 </dd> 925 </dd>
707 </dl><dl> 926 </dl>
927 <dl>
708 <dt>Returns:</dt> 928 <dt>Returns:</dt>
709 <dd> 929 <dd>
710 decrypted data (bytes) 930 decrypted data (bytes)
711 </dd> 931 </dd>
712 </dl> 932 </dl>
713 <div align="right"><a href="#top">Up</a></div> 933 <div align="right"><a href="#top">Up</a></div>
714 <hr /><hr /> 934 <hr />
935 <hr />
715 <a NAME="encryptData" ID="encryptData"></a> 936 <a NAME="encryptData" ID="encryptData"></a>
716 <h2>encryptData</h2> 937 <h2>encryptData</h2>
717 <b>encryptData</b>(<i>key, data, mode=AESModeOfOperation.ModeOfOperation["CBC"]</i>) 938 <b>encryptData</b>(<i>key, data, mode=AESModeOfOperation.ModeOfOperation["CBC"]</i>)
939
718 <p> 940 <p>
719 Module function to encrypt the given data with the given key. 941 Module function to encrypt the given data with the given key.
720 </p><dl> 942 </p>
943 <dl>
944
721 <dt><i>key</i></dt> 945 <dt><i>key</i></dt>
722 <dd> 946 <dd>
723 key to be used for encryption (bytes) 947 key to be used for encryption (bytes)
724 </dd><dt><i>data</i></dt> 948 </dd>
949 <dt><i>data</i></dt>
725 <dd> 950 <dd>
726 data to be encrypted (bytes) 951 data to be encrypted (bytes)
727 </dd><dt><i>mode</i></dt> 952 </dd>
953 <dt><i>mode</i></dt>
728 <dd> 954 <dd>
729 mode of operations (0, 1 or 2) 955 mode of operations (0, 1 or 2)
730 </dd> 956 </dd>
731 </dl><dl> 957 </dl>
958 <dl>
732 <dt>Returns:</dt> 959 <dt>Returns:</dt>
733 <dd> 960 <dd>
734 encrypted data prepended with the initialization vector (bytes) 961 encrypted data prepended with the initialization vector (bytes)
735 </dd> 962 </dd>
736 </dl> 963 </dl>
737 <div align="right"><a href="#top">Up</a></div> 964 <div align="right"><a href="#top">Up</a></div>
738 <hr /><hr /> 965 <hr />
966 <hr />
739 <a NAME="strip_PKCS7_padding" ID="strip_PKCS7_padding"></a> 967 <a NAME="strip_PKCS7_padding" ID="strip_PKCS7_padding"></a>
740 <h2>strip_PKCS7_padding</h2> 968 <h2>strip_PKCS7_padding</h2>
741 <b>strip_PKCS7_padding</b>(<i>b</i>) 969 <b>strip_PKCS7_padding</b>(<i>b</i>)
970
742 <p> 971 <p>
743 Function to strip off PKCS7 padding. 972 Function to strip off PKCS7 padding.
744 </p><dl> 973 </p>
974 <dl>
975
745 <dt><i>b</i></dt> 976 <dt><i>b</i></dt>
746 <dd> 977 <dd>
747 data to be stripped (bytes) 978 data to be stripped (bytes)
748 </dd> 979 </dd>
749 </dl><dl> 980 </dl>
981 <dl>
750 <dt>Returns:</dt> 982 <dt>Returns:</dt>
751 <dd> 983 <dd>
752 stripped data (bytes) 984 stripped data (bytes)
753 </dd> 985 </dd>
754 </dl><dl> 986 </dl>
987 <dl>
988
755 <dt>Raises <b>ValueError</b>:</dt> 989 <dt>Raises <b>ValueError</b>:</dt>
756 <dd> 990 <dd>
757 data padding is invalid 991 data padding is invalid
758 </dd> 992 </dd>
759 </dl> 993 </dl>

eric ide

mercurial