def testAutoIV(self): k = a2b_hex('2b7e151628aed2a6abf7158809cf4f3c') alg = AES_CBC(key=k, padding=noPadding()) pt = a2b_hex('6bc1bee22e409f96e93d7e117393172a') ct = alg.encrypt(pt) dct = alg.decrypt(ct) self.assertEqual( dct, pt ) # 'AES_CBC auto IV error'
def CBCtestVector(key,iv,pt,kct): """ CBC test vectors using AES algorithm """ key,iv,pt,kct = a2b_hex(key),a2b_hex(iv),a2b_p(pt),a2b_p(kct) alg = AES_CBC(key, padding=noPadding()) self.assertEqual( alg.encrypt(pt,iv=iv), kct ) self.assertEqual( alg.decrypt(iv+kct), pt )
def testAutoIVandPadding(self): k = a2b_hex('2b7e151628aed2a6abf7158809cf4f3c') alg = AES_CBC(key=k) # should default to padWithPadLen pt = a2b_hex('6bc1bee22e409f96e93d7e117393172a') ct = alg.encrypt(pt) dct = alg.decrypt(ct) self.assertEqual( dct, pt ) # 'AES_CBC auto IV and pad error'
def CBCtestVector(key, iv, pt, kct): """ CBC test vectors using AES algorithm """ key, iv, pt, kct = a2b_hex(key), a2b_hex(iv), a2b_p(pt), a2b_p(kct) alg = AES_CBC(key, padding=noPadding()) self.assertEqual(alg.encrypt(pt, iv=iv), kct) self.assertEqual(alg.decrypt(iv + kct), pt)
def testAutoIVandPadding(self): k = a2b_hex('2b7e151628aed2a6abf7158809cf4f3c') alg = AES_CBC(key=k) # should default to padWithPadLen pt = a2b_hex('6bc1bee22e409f96e93d7e117393172a') ct = alg.encrypt(pt) dct = alg.decrypt(ct) self.assertEqual(dct, pt) # 'AES_CBC auto IV and pad error'
def testAutoIV(self): k = a2b_hex('2b7e151628aed2a6abf7158809cf4f3c') alg = AES_CBC(key=k, padding=noPadding()) pt = a2b_hex('6bc1bee22e409f96e93d7e117393172a') ct = alg.encrypt(pt) dct = alg.decrypt(ct) self.assertEqual(dct, pt) # 'AES_CBC auto IV error'
def testNonDupIV(self): """ Test to ensure that two instances of CBC don't get duplicate IV """ k = a2b_hex('2b7e151628aed2a6abf7158809cf4f3c') alg1 = AES_CBC(k) alg2 = AES_CBC(k) pt = a2b_hex('6bc1bee22e409f96e93d7e117393172a') ct1 = alg1.encrypt(pt) ct2 = alg2.encrypt(pt) assert( ct1!= ct2 ), 'AES_CBC dup IV error'
def testNonDupIV(self): """ Test to ensure that two instances of CBC don't get duplicate IV """ k = a2b_hex('2b7e151628aed2a6abf7158809cf4f3c') alg1 = AES_CBC(k) alg2 = AES_CBC(k) pt = a2b_hex('6bc1bee22e409f96e93d7e117393172a') ct1 = alg1.encrypt(pt) ct2 = alg2.encrypt(pt) assert (ct1 != ct2), 'AES_CBC dup IV error'
prf_value = a2b_p(prf_know_value) lengthInBits = 8 * len(prf_value) a_prf = PRF(key, prefix, data, lengthInBits) print 'key = ', b2a_p(key) print 'prefix = ', '"' + prefix + '"' print 'data = ', b2a_p(data) print 'PRF = ', b2a_p(a_prf) print 'PRF_v = ', b2a_p(prf_value) print 'len prf= ', len(a_prf) * 8 self.assertEqual(a_prf, prf_value) """ -------------- (key, data, digest, prf_value) ------------------ """ prfTestVectors = ( (a2b_hex('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'), 'Hi There', 'b617318655057264e28bc0b6fb378c8ef146be00', 'bcd4c650b30b9684951829e0d75f9d54'), ('Jefe', 'what do ya want for nothing?', 'effcdf6ae5eb2fa2d27416d5f184df9c259a7c79', """51f4de5b33f249adf81aeb713a3c20f4fe631446fabdfa58 244759ae58ef9009a99abf4eac2ca5fa87e692c440eb40023e 7babb206d61de7b92f41529092b8fc"""), ( 20 * chr(0xaa), 50 * chr(0xdd), #0xdd repeated 50 times '125d7342b9ac11cd91a39af48aa17b4f63f175d3', """e1ac546ec4cb636f9976487be5c86be17a0252ca5d8d8df12c fb0473525249ce9dd8d177ead710bc9b590547239107aef7b4ab d43d87f0a68f1cbd9e2b6f7607"""))
prefix = 'prefix' # remove white spaces and convert to binary string prf_value = a2b_p(prf_know_value) lengthInBits=8*len(prf_value) a_prf = PRF(key,prefix,data,lengthInBits) print 'key = ', b2a_p(key) print 'prefix = ', '"'+prefix+'"' print 'data = ', b2a_p(data) print 'PRF = ', b2a_p(a_prf) print 'PRF_v = ', b2a_p(prf_value) print 'len prf= ', len(a_prf)* 8 self.assertEqual(a_prf, prf_value) """ -------------- (key, data, digest, prf_value) ------------------ """ prfTestVectors =((a2b_hex('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'), 'Hi There', 'b617318655057264e28bc0b6fb378c8ef146be00', 'bcd4c650b30b9684951829e0d75f9d54'), ('Jefe', 'what do ya want for nothing?', 'effcdf6ae5eb2fa2d27416d5f184df9c259a7c79', """51f4de5b33f249adf81aeb713a3c20f4fe631446fabdfa58 244759ae58ef9009a99abf4eac2ca5fa87e692c440eb40023e 7babb206d61de7b92f41529092b8fc"""), (20*chr(0xaa), 50*chr(0xdd), #0xdd repeated 50 times '125d7342b9ac11cd91a39af48aa17b4f63f175d3', """e1ac546ec4cb636f9976487be5c86be17a0252ca5d8d8df12c fb0473525249ce9dd8d177ead710bc9b590547239107aef7b4ab d43d87f0a68f1cbd9e2b6f7607"""))