505 @param key key to be used (bytes or bytearray) |
505 @param key key to be used (bytes or bytearray) |
506 @param size key size (16, 24 or 32) |
506 @param size key size (16, 24 or 32) |
507 @return encrypted data (bytes) |
507 @return encrypted data (bytes) |
508 @exception ValueError key size is invalid |
508 @exception ValueError key size is invalid |
509 """ |
509 """ |
|
510 if size not in self.KeySize.values(): |
|
511 raise ValueError("Wrong key size given ({0}).".format(size)) |
|
512 |
510 output = bytearray(16) |
513 output = bytearray(16) |
511 # the number of rounds |
514 # the number of rounds |
512 nbrRounds = 0 |
515 nbrRounds = 0 |
513 # the 128 bit block to encode |
516 # the 128 bit block to encode |
514 block = bytearray(16) |
517 block = bytearray(16) |
515 # set the number of rounds |
518 # set the number of rounds |
516 if size == self.KeySize["SIZE_128"]: |
519 if size == self.KeySize["SIZE_128"]: |
517 nbrRounds = 10 |
520 nbrRounds = 10 |
518 elif size == self.KeySize["SIZE_192"]: |
521 elif size == self.KeySize["SIZE_192"]: |
519 nbrRounds = 12 |
522 nbrRounds = 12 |
520 elif size == self.KeySize["SIZE_256"]: |
523 else: |
521 nbrRounds = 14 |
524 nbrRounds = 14 |
522 else: |
|
523 raise ValueError("Wrong key size given ({0}).".format(size)) |
|
524 |
525 |
525 # the expanded keySize |
526 # the expanded keySize |
526 expandedKeySize = 16 * (nbrRounds + 1) |
527 expandedKeySize = 16 * (nbrRounds + 1) |
527 |
528 |
528 # Set the block values, for the block: |
529 # Set the block values, for the block: |
562 @param key key to be used (bytes or bytearray) |
563 @param key key to be used (bytes or bytearray) |
563 @param size key size (16, 24 or 32) |
564 @param size key size (16, 24 or 32) |
564 @return decrypted data (bytes) |
565 @return decrypted data (bytes) |
565 @exception ValueError key size is invalid |
566 @exception ValueError key size is invalid |
566 """ |
567 """ |
|
568 if size not in self.KeySize.values(): |
|
569 raise ValueError("Wrong key size given ({0}).".format(size)) |
|
570 |
567 output = bytearray(16) |
571 output = bytearray(16) |
568 # the number of rounds |
572 # the number of rounds |
569 nbrRounds = 0 |
573 nbrRounds = 0 |
570 # the 128 bit block to decode |
574 # the 128 bit block to decode |
571 block = bytearray(16) |
575 block = bytearray(16) |
572 # set the number of rounds |
576 # set the number of rounds |
|
577 |
573 if size == self.KeySize["SIZE_128"]: |
578 if size == self.KeySize["SIZE_128"]: |
574 nbrRounds = 10 |
579 nbrRounds = 10 |
575 elif size == self.KeySize["SIZE_192"]: |
580 elif size == self.KeySize["SIZE_192"]: |
576 nbrRounds = 12 |
581 nbrRounds = 12 |
577 elif size == self.KeySize["SIZE_256"]: |
582 else: |
578 nbrRounds = 14 |
583 nbrRounds = 14 |
579 else: |
|
580 raise ValueError("Wrong key size given ({0}).".format(size)) |
|
581 |
584 |
582 # the expanded keySize |
585 # the expanded keySize |
583 expandedKeySize = 16 * (nbrRounds + 1) |
586 expandedKeySize = 16 * (nbrRounds + 1) |
584 |
587 |
585 # Set the block values, for the block: |
588 # Set the block values, for the block: |