diff options
author | lloyd <[email protected]> | 2015-05-30 12:19:06 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-05-30 12:19:06 +0000 |
commit | e6709f71bcb27485b241dd9fb65b3ac76944bee7 (patch) | |
tree | bbcd06eee84f7bfe5fc676a7694f7dd1b9ce3a52 /src/python/botan.py | |
parent | a62c643442d232885dc27accb9b61153cb874a02 (diff) |
Fix Python MAC wrapper, add an example/test
Diffstat (limited to 'src/python/botan.py')
-rwxr-xr-x | src/python/botan.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/python/botan.py b/src/python/botan.py index 94887870b..10b7d0fec 100755 --- a/src/python/botan.py +++ b/src/python/botan.py @@ -111,7 +111,7 @@ class message_authentication_code(object): flags = c_uint32(0) # always zero in this API version self.mac = c_void_p(0) rc = botan.botan_mac_init(byref(self.mac), algo, flags) - if rc != 0 or self.hash is None: + if rc != 0 or self.mac is None: raise Exception("No mac " + algo + " for you!") def __del__(self): @@ -130,7 +130,7 @@ class message_authentication_code(object): def set_key(self, key): botan.botan_mac_set_key.argtypes = [c_void_p, POINTER(c_char), c_size_t] - return botan.botan_mac_set_key(self.mac, k, len(k)) + return botan.botan_mac_set_key(self.mac, key, len(key)) def update(self, x): botan.botan_mac_update.argtypes = [c_void_p, POINTER(c_char), c_size_t] @@ -508,6 +508,16 @@ def test(): print 'x', psk.encode('hex') print 'y', pbkdf('PBKDF2(SHA-256)', 'xyz', 32, iterations, salt)[2].encode('hex') + hmac = message_authentication_code('HMAC(SHA-256)') + hmac.set_key('0102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F20'.decode('hex')) + hmac.update('616263'.decode('hex')) + + hmac_output = hmac.final() + + print hmac_output.encode('hex') + if hmac_output != 'A21B1F5D4CF4F73A4DD939750F7A066A7F98CC131CB16A6692759021CFAB8181'.decode('hex'): + print 'Bad HMAC' + print r.get(42).encode('hex'), r.get(13).encode('hex'), r.get(9).encode('hex') h = hash_function('MD5') |