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

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

eric ide

mercurial