Created
September 26, 2014 14:28
-
-
Save tlamer/3fa83ef2e29e54d51a52 to your computer and use it in GitHub Desktop.
aes test vectors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/env python3 | |
| from Crypto.Cipher import AES | |
| from binascii import hexlify, unhexlify | |
| # test vectors | |
| tv = [ | |
| {'src':'http://www.inconteam.com/software-development/41-encryption/55-aes-test-vectors#aes-cbc-128', | |
| 'key':b'2b7e151628aed2a6abf7158809cf4f3c', | |
| 'iv': b'000102030405060708090A0B0C0D0E0F', | |
| 'pt': b'6bc1bee22e409f96e93d7e117393172a', | |
| 'ct': b'7649abac8119b246cee98e9b12e9197d'}, | |
| {'src':'http://tools.ietf.org/html/rfc3602#section-4', | |
| 'key':b'06a9214036b8a15b512e03d534120006', | |
| 'iv': b'3dafba429d9eb430b422da802c9fac41', | |
| 'pt': "Single block msg", | |
| 'ct': b'e353779c1079aeb82708942dbe77181a'}, | |
| {'src':'http://csrc.nist.gov/archive/aes/rijndael/wsdindex.html', | |
| 'key':b'00000000000000000000000000000000', | |
| 'iv': b'00000000000000000000000000000000', | |
| 'pt': b'00000000000000000000000000000000', | |
| 'ct': b'8A05FC5E095AF4848A08D328D3688E3D'} | |
| ] | |
| for i in tv: | |
| # convert vectors from hex notation to binary data | |
| bkey = unhexlify(i['key']) | |
| biv = unhexlify(i['iv']) | |
| if type(i['pt']) == str: | |
| bpt = i['pt'] | |
| else: | |
| bpt = unhexlify(i['pt']) | |
| # encrypt | |
| cipher = AES.new(bkey, AES.MODE_CBC, biv) | |
| ct = hexlify(cipher.encrypt(bpt)) | |
| # compare with provided data and report results | |
| print(i['src']) | |
| print('reference: {}'.format(i['ct'])) | |
| print('encrypted: {}'.format(ct)) | |
| if ct == i['ct']: | |
| print('PASS') | |
| else: | |
| print('FAIL') | |
| print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment