aes python 3 compiles (but does work well?)
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.2.1 (2012-10-23 09:44:29) stable
|
Version 2.2.1 (2012-10-23 09:54:01) stable
|
||||||
|
|||||||
+63
-52
@@ -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,67 +444,70 @@ 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',
|
||||||
'ca82c97dfa5947f0add4a2af9ca472c0'
|
str2hex('637c777bf26b6fc53001672bfed7ab76'
|
||||||
'b7fd9326363ff7cc34a5e5f171d83115'
|
'ca82c97dfa5947f0add4a2af9ca472c0'
|
||||||
'04c723c31896059a071280e2eb27b275'
|
'b7fd9326363ff7cc34a5e5f171d83115'
|
||||||
'09832c1a1b6e5aa0523bd6b329e32f84'
|
'04c723c31896059a071280e2eb27b275'
|
||||||
'53d100ed20fcb15b6acbbe394a4c58cf'
|
'09832c1a1b6e5aa0523bd6b329e32f84'
|
||||||
'd0efaafb434d338545f9027f503c9fa8'
|
'53d100ed20fcb15b6acbbe394a4c58cf'
|
||||||
'51a3408f929d38f5bcb6da2110fff3d2'
|
'd0efaafb434d338545f9027f503c9fa8'
|
||||||
'cd0c13ec5f974417c4a77e3d645d1973'
|
'51a3408f929d38f5bcb6da2110fff3d2'
|
||||||
'60814fdc222a908846eeb814de5e0bdb'
|
'cd0c13ec5f974417c4a77e3d645d1973'
|
||||||
'e0323a0a4906245cc2d3ac629195e479'
|
'60814fdc222a908846eeb814de5e0bdb'
|
||||||
'e7c8376d8dd54ea96c56f4ea657aae08'
|
'e0323a0a4906245cc2d3ac629195e479'
|
||||||
'ba78252e1ca6b4c6e8dd741f4bbd8b8a'
|
'e7c8376d8dd54ea96c56f4ea657aae08'
|
||||||
'703eb5664803f60e613557b986c11d9e'
|
'ba78252e1ca6b4c6e8dd741f4bbd8b8a'
|
||||||
'e1f8981169d98e949b1e87e9ce5528df'
|
'703eb5664803f60e613557b986c11d9e'
|
||||||
'8ca1890dbfe6426841992d0fb054bb16'.decode('hex')
|
'e1f8981169d98e949b1e87e9ce5528df'
|
||||||
|
'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',
|
||||||
'7ce339829b2fff87348e4344c4dee9cb'
|
str2hex('52096ad53036a538bf40a39e81f3d7fb'
|
||||||
'547b9432a6c2233dee4c950b42fac34e'
|
'7ce339829b2fff87348e4344c4dee9cb'
|
||||||
'082ea16628d924b2765ba2496d8bd125'
|
'547b9432a6c2233dee4c950b42fac34e'
|
||||||
'72f8f66486689816d4a45ccc5d65b692'
|
'082ea16628d924b2765ba2496d8bd125'
|
||||||
'6c704850fdedb9da5e154657a78d9d84'
|
'72f8f66486689816d4a45ccc5d65b692'
|
||||||
'90d8ab008cbcd30af7e45805b8b34506'
|
'6c704850fdedb9da5e154657a78d9d84'
|
||||||
'd02c1e8fca3f0f02c1afbd0301138a6b'
|
'90d8ab008cbcd30af7e45805b8b34506'
|
||||||
'3a9111414f67dcea97f2cfcef0b4e673'
|
'd02c1e8fca3f0f02c1afbd0301138a6b'
|
||||||
'96ac7422e7ad3585e2f937e81c75df6e'
|
'3a9111414f67dcea97f2cfcef0b4e673'
|
||||||
'47f11a711d29c5896fb7620eaa18be1b'
|
'96ac7422e7ad3585e2f937e81c75df6e'
|
||||||
'fc563e4bc6d279209adbc0fe78cd5af4'
|
'47f11a711d29c5896fb7620eaa18be1b'
|
||||||
'1fdda8338807c731b11210592780ec5f'
|
'fc563e4bc6d279209adbc0fe78cd5af4'
|
||||||
'60517fa919b54a0d2de57a9f93c99cef'
|
'1fdda8338807c731b11210592780ec5f'
|
||||||
'a0e03b4dae2af5b0c8ebbb3c83539961'
|
'60517fa919b54a0d2de57a9f93c99cef'
|
||||||
'172b047eba77d626e169146355210c7d'.decode('hex')
|
'a0e03b4dae2af5b0c8ebbb3c83539961'
|
||||||
)
|
'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)
|
||||||
# It's a pre-computed table of exponentation of 2 in AES's finite field
|
# It's a pre-computed table of exponentation of 2 in AES's finite field
|
||||||
#
|
#
|
||||||
# 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',
|
||||||
'2f5ebc63c697356ad4b37dfaefc59139'
|
str2hex('8d01020408102040801b366cd8ab4d9a'
|
||||||
'72e4d3bd61c29f254a943366cc831d3a'
|
'2f5ebc63c697356ad4b37dfaefc59139'
|
||||||
'74e8cb8d01020408102040801b366cd8'
|
'72e4d3bd61c29f254a943366cc831d3a'
|
||||||
'ab4d9a2f5ebc63c697356ad4b37dfaef'
|
'74e8cb8d01020408102040801b366cd8'
|
||||||
'c5913972e4d3bd61c29f254a943366cc'
|
'ab4d9a2f5ebc63c697356ad4b37dfaef'
|
||||||
'831d3a74e8cb8d01020408102040801b'
|
'c5913972e4d3bd61c29f254a943366cc'
|
||||||
'366cd8ab4d9a2f5ebc63c697356ad4b3'
|
'831d3a74e8cb8d01020408102040801b'
|
||||||
'7dfaefc5913972e4d3bd61c29f254a94'
|
'366cd8ab4d9a2f5ebc63c697356ad4b3'
|
||||||
'3366cc831d3a74e8cb8d010204081020'
|
'7dfaefc5913972e4d3bd61c29f254a94'
|
||||||
'40801b366cd8ab4d9a2f5ebc63c69735'
|
'3366cc831d3a74e8cb8d010204081020'
|
||||||
'6ad4b37dfaefc5913972e4d3bd61c29f'
|
'40801b366cd8ab4d9a2f5ebc63c69735'
|
||||||
'254a943366cc831d3a74e8cb8d010204'
|
'6ad4b37dfaefc5913972e4d3bd61c29f'
|
||||||
'08102040801b366cd8ab4d9a2f5ebc63'
|
'254a943366cc831d3a74e8cb8d010204'
|
||||||
'c697356ad4b37dfaefc5913972e4d3bd'
|
'08102040801b366cd8ab4d9a2f5ebc63'
|
||||||
'61c29f254a943366cc831d3a74e8cb'.decode('hex')
|
'c697356ad4b37dfaefc5913972e4d3bd'
|
||||||
|
'61c29f254a943366cc831d3a74e8cb')
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user