src/eric7/Documentation/Source/eric7.Utilities.crypto.py3AES.html

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

eric ide

mercurial