def testRFC2104_1(self): """ RFC2104 test 1 and various calling methods """ key = chr(0x0b) * 20 keyedHashAlg = HMAC(SHA1, key) data = "Hi There" digest = a2b_hex('b617318655057264e28bc0b6fb378c8ef146be00') cd = keyedHashAlg(data) assert (cd == digest), 'RFC2104 test 1 failed' hmac_sha1 = HMAC_SHA1(key) cd = hmac_sha1.hash(data) assert (cd == digest), 'RFC2104 test 1 failed, HMAC_SHA1 called' cd = hmac_sha1.hash(data[:3], more=1) cd = hmac_sha1.hash(data[3:]) assert (cd == digest), 'RFC2104 test 1 failed, HMAC_SHA1 called twice' hmac_sha1.update(data[:3]) hmac_sha1.update(data[3:]) cd = hmac_sha1.digest() print b2a_hex(cd) assert (cd == digest ), 'RFC2104 test 1 failed, HMAC_SHA1 called with update' hmac_sha1.reset(data) cd1 = hmac_sha1.hash(data) cd2 = hmac_sha1.hash(data) print b2a_hex(cd1) print b2a_hex(cd2) assert (cd1 == cd2), 'hash method should default to reseting state'
def testRFC2104_3(self): """ RFC2104 test 3 """ key = a2b_hex('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') keyedHashAlg = HMAC_SHA1(key) data = 50 * chr(0xdd) digest = a2b_hex('125d7342b9ac11cd91a39af48aa17b4f63f175d3') cd = keyedHashAlg(data) assert (cd == digest), 'RFC2104 test 3 failed'