comparison test.py @ 13:19d8314d9fe4

update for new data padding scheme
author Matt Johnston <matt@ucc.asn.au>
date Wed, 12 Jun 2013 23:49:19 +0800
parents 3aa92c7f379c
children 735c406b4c57
comparison
equal deleted inserted replaced
11:e83b35e864d7 13:19d8314d9fe4
1 #!./bin/python 1 #!/Users/matt/tmp/crypto/bin/python
2 2
3 from Crypto.Cipher import AES 3 from Crypto.Cipher import AES
4 import hashlib 4 import hashlib
5 import hmac 5 import hmac
6 from binascii import hexlify, unhexlify 6 from binascii import hexlify, unhexlify
15 #enc hex 0ba302059bfc650d4491268448102119 15 #enc hex 0ba302059bfc650d4491268448102119
16 #hmac hex ecd858ee07a8e16575723513d2d072a7565865e4 16 #hmac hex ecd858ee07a8e16575723513d2d072a7565865e4
17 17
18 18
19 cli_key = 'yyuuiiooddeeffqqddii' 19 cli_key = 'yyuuiiooddeeffqqddii'
20 enc_key = 'aabbccddeeffgghh' 20 enc_key = 'aabbccddeeffgghh\0\0\0\0'
21 indata = '1234567890123456' 21 indata = '1234567890123456'
22 22
23 print "cli_key %s, hex %s" % (cli_key, hexlify(cli_key)) 23 print "cli_key %s, hex %s" % (cli_key, hexlify(cli_key))
24 print "enc_key %s, hex %s" % (enc_key, hexlify(enc_key)) 24 print "enc_key %s, hex %s" % (enc_key, hexlify(enc_key))
25 print "data %s, hex %s" % (indata, hexlify(indata)) 25 print "data %s, hex %s" % (indata, hexlify(indata))
26 26
27 print "data %s, hex %s" % (indata, hexlify(indata)) 27 print "data %s, hex %s" % (indata, hexlify(indata))
28 28
29 a = AES.new(enc_key) 29 a = AES.new(enc_key[:16])
30 enc = a.encrypt(indata) 30 enc = a.encrypt(indata)
31 31
32 print "enc hex %s" % hexlify(enc) 32 print "enc hex %s" % hexlify(enc)
33 33
34 h = hmac.new(cli_key, enc, hashlib.sha1).digest() 34 h = hmac.new(enc_key, 'D:' + enc, hashlib.sha1).digest()
35 print "hmac hex %s" % hexlify(h) 35 print "enc hmac hex %s" % hexlify(h)
36 36
37 h = hmac.new(cli_key, 'H:' + cli_key, hashlib.sha1).digest()
38 print "hmac test hex %s" % hexlify(h)
39
40