aes python 3 compiles (but does work well?)

This commit is contained in:
mdipierro committed 2012-10-23 09:54:07 -05:00
1 parent ea6714e89b
commit 5247981fa8
2 files changed
+21 -10

No files matched your search

+1 -1
View File
@@ -1 +1 @@
Version 2.2.1 (2012-10-23 09:44:29) stable Version 2.2.1 (2012-10-23 09:54:01) stable
+20 -9
View File
@@ -45,8 +45,16 @@ there clears it up.
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
#
# Ported to python 3 by Massimo Di Pierro
#
#### ####
try:
import binascii # python 3
str2hex = lambda s: binascii.b2a_hex(s.encode('utf8'))
except ImportError: # python 2
str2hex = lambda s: s.decode('hex')
from array import array from array import array
@@ -436,8 +444,9 @@ gf_mul_by_14 = array('B', [galois_multiply(x, 14) for x in range(256)])
# #
# More information: http://en.wikipedia.org/wiki/Rijndael_S-box # More information: http://en.wikipedia.org/wiki/Rijndael_S-box
aes_sbox = array('B', aes_sbox = array(
'637c777bf26b6fc53001672bfed7ab76' 'B',
str2hex('637c777bf26b6fc53001672bfed7ab76'
'ca82c97dfa5947f0add4a2af9ca472c0' 'ca82c97dfa5947f0add4a2af9ca472c0'
'b7fd9326363ff7cc34a5e5f171d83115' 'b7fd9326363ff7cc34a5e5f171d83115'
'04c723c31896059a071280e2eb27b275' '04c723c31896059a071280e2eb27b275'
@@ -452,14 +461,15 @@ aes_sbox = array('B',
'ba78252e1ca6b4c6e8dd741f4bbd8b8a' 'ba78252e1ca6b4c6e8dd741f4bbd8b8a'
'703eb5664803f60e613557b986c11d9e' '703eb5664803f60e613557b986c11d9e'
'e1f8981169d98e949b1e87e9ce5528df' 'e1f8981169d98e949b1e87e9ce5528df'
'8ca1890dbfe6426841992d0fb054bb16'.decode('hex') '8ca1890dbfe6426841992d0fb054bb16')
) )
# This is the inverse of the above. In other words: # This is the inverse of the above. In other words:
# aes_inv_sbox[aes_sbox[val]] == val # aes_inv_sbox[aes_sbox[val]] == val
aes_inv_sbox = array('B', aes_inv_sbox = array(
'52096ad53036a538bf40a39e81f3d7fb' 'B',
str2hex('52096ad53036a538bf40a39e81f3d7fb'
'7ce339829b2fff87348e4344c4dee9cb' '7ce339829b2fff87348e4344c4dee9cb'
'547b9432a6c2233dee4c950b42fac34e' '547b9432a6c2233dee4c950b42fac34e'
'082ea16628d924b2765ba2496d8bd125' '082ea16628d924b2765ba2496d8bd125'
@@ -474,7 +484,7 @@ aes_inv_sbox = array('B',
'1fdda8338807c731b11210592780ec5f' '1fdda8338807c731b11210592780ec5f'
'60517fa919b54a0d2de57a9f93c99cef' '60517fa919b54a0d2de57a9f93c99cef'
'a0e03b4dae2af5b0c8ebbb3c83539961' 'a0e03b4dae2af5b0c8ebbb3c83539961'
'172b047eba77d626e169146355210c7d'.decode('hex') '172b047eba77d626e169146355210c7d')
) )
# The Rcon table is used in AES's key schedule (key expansion) # The Rcon table is used in AES's key schedule (key expansion)
@@ -482,8 +492,9 @@ aes_inv_sbox = array('B',
# #
# More information: http://en.wikipedia.org/wiki/Rijndael_key_schedule # More information: http://en.wikipedia.org/wiki/Rijndael_key_schedule
aes_Rcon = array('B', aes_Rcon = array(
'8d01020408102040801b366cd8ab4d9a' 'B',
str2hex('8d01020408102040801b366cd8ab4d9a'
'2f5ebc63c697356ad4b37dfaefc59139' '2f5ebc63c697356ad4b37dfaefc59139'
'72e4d3bd61c29f254a943366cc831d3a' '72e4d3bd61c29f254a943366cc831d3a'
'74e8cb8d01020408102040801b366cd8' '74e8cb8d01020408102040801b366cd8'
@@ -498,5 +509,5 @@ aes_Rcon = array('B',
'254a943366cc831d3a74e8cb8d010204' '254a943366cc831d3a74e8cb8d010204'
'08102040801b366cd8ab4d9a2f5ebc63' '08102040801b366cd8ab4d9a2f5ebc63'
'c697356ad4b37dfaefc5913972e4d3bd' 'c697356ad4b37dfaefc5913972e4d3bd'
'61c29f254a943366cc831d3a74e8cb'.decode('hex') '61c29f254a943366cc831d3a74e8cb')
) )