Example #1
0
        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 )
Example #2
0
 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'
Example #3
0
 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'
Example #4
0
        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)
Example #5
0
 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'
Example #6
0
 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'
Example #7
0
 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'
Example #8
0
 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'