annotate test.py @ 49:12236bceb6b0 default tip

snapshot export of the schematic
author Matt Johnston <matt@ucc.asn.au>
date Wed, 25 Jun 2014 21:29:52 +0800
parents 735c406b4c57
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
735c406b4c57 add more tests
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
1 #!/usr/bin/env python
9
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 from Crypto.Cipher import AES
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 import hashlib
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 import hmac
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 from binascii import hexlify, unhexlify
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 # echo -n '1234567890123456' | openssl enc -aes-128-ecb -K '61616262636364646565666667676868' | hexdump -C
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 # output:
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 #cli_key yyuuiiooddeeffqqddii, hex 7979757569696f6f646465656666717164646969
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 #enc_key aabbccddeeffgghh, hex 61616262636364646565666667676868
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 #data 1234567890123456, hex 31323334353637383930313233343536
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 #data 1234567890123456, hex 31323334353637383930313233343536
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 #enc hex 0ba302059bfc650d4491268448102119
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 #hmac hex ecd858ee07a8e16575723513d2d072a7565865e4
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 cli_key = 'yyuuiiooddeeffqqddii'
13
19d8314d9fe4 update for new data padding scheme
Matt Johnston <matt@ucc.asn.au>
parents: 9
diff changeset
20 enc_key = 'aabbccddeeffgghh\0\0\0\0'
9
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 indata = '1234567890123456'
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22
28
735c406b4c57 add more tests
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
23 a_key = unhexlify('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
735c406b4c57 add more tests
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
24 bs = unhexlify('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb')
735c406b4c57 add more tests
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
25 threes = '33333333333333333333'
735c406b4c57 add more tests
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
26 print len(threes)
735c406b4c57 add more tests
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
27
9
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 print "cli_key %s, hex %s" % (cli_key, hexlify(cli_key))
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 print "enc_key %s, hex %s" % (enc_key, hexlify(enc_key))
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 print "data %s, hex %s" % (indata, hexlify(indata))
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 print "data %s, hex %s" % (indata, hexlify(indata))
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33
13
19d8314d9fe4 update for new data padding scheme
Matt Johnston <matt@ucc.asn.au>
parents: 9
diff changeset
34 a = AES.new(enc_key[:16])
9
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 enc = a.encrypt(indata)
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 print "enc hex %s" % hexlify(enc)
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38
13
19d8314d9fe4 update for new data padding scheme
Matt Johnston <matt@ucc.asn.au>
parents: 9
diff changeset
39 h = hmac.new(enc_key, 'D:' + enc, hashlib.sha1).digest()
19d8314d9fe4 update for new data padding scheme
Matt Johnston <matt@ucc.asn.au>
parents: 9
diff changeset
40 print "enc hmac hex %s" % hexlify(h)
9
3aa92c7f379c test python crypto script
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41
28
735c406b4c57 add more tests
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
42 h = hmac.new(a_key, 'H:' + bs, hashlib.sha1).digest()
735c406b4c57 add more tests
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
43 print "hmac test aaaa bbbbhex %s" % hexlify(h)
735c406b4c57 add more tests
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
44
735c406b4c57 add more tests
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
45 h = hmac.new(threes, 'H:' + threes, hashlib.sha1).digest()
735c406b4c57 add more tests
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
46 print "hmac test aaaa bbbbhex %s" % hexlify(h)
13
19d8314d9fe4 update for new data padding scheme
Matt Johnston <matt@ucc.asn.au>
parents: 9
diff changeset
47
19d8314d9fe4 update for new data padding scheme
Matt Johnston <matt@ucc.asn.au>
parents: 9
diff changeset
48