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 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'