Пример #1
0
        def CBCtestVector(key, iv, pt, kct):
            """ CBC test vectors using AES algorithm """
            key, iv, pt, kct = a2b_p(key), a2b_p(iv), a2b_p(pt), a2b_p(kct)
            alg = CBC(AES(key), padding=noPadding())

            self.assertEqual(alg.encrypt(pt, iv=iv), kct)
            self.assertEqual(alg.decrypt(iv + kct), pt)
Пример #2
0
        def CBCtestVector(key,iv,pt,kct):
            """ CBC test vectors using AES algorithm """
            key,iv,pt,kct = a2b_p(key),a2b_p(iv),a2b_p(pt),a2b_p(kct)
            alg = CBC(AES(key), padding=noPadding())

            self.assertEqual( alg.encrypt(pt,iv=iv), kct )
            self.assertEqual( alg.decrypt(iv+kct),   pt )
Пример #3
0
 def testIVuniqueness(self):
     """  Test that two different instances have different IVs """
     key =   a2b_p('2b7e151628aed2a6abf7158809cf4f3c')
     pt  = "This is a test case"
     alg1 = CBC(Rijndael(key, blockSize=32))
     alg2 = CBC(Rijndael(key, blockSize=32))
     ct1 = alg1.encrypt(pt)
     ct2 = alg2.encrypt(pt)
     self.assertNotEqual( ct1,ct2 )
Пример #4
0
 def testIVmultencryptUnique(self):
     """  Test that two different encrypts have different IVs """
     key =   a2b_p('2b7e151628aed2a6abf7158809cf4f3c')
     pt  = "This is yet another test case"
     alg1 = CBC(Rijndael(key, blockSize=32))
     ct1 = alg1.encrypt(pt)
     ct2 = alg1.encrypt(pt)
     self.assertNotEqual( ct1, ct2 )
     self.assertEqual( alg1.decrypt(ct1), pt )
     self.assertEqual( alg1.decrypt(ct1), alg1.decrypt(ct2) )
Пример #5
0
 def testCBC_Rijndael_variable_data(self):
     """  Rijndael CBC 256 """
     key =   '2b7e151628aed2a6abf7158809cf4f3c'
     iv  =   '000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f'
     key,iv = a2b_p(key),a2b_p(iv)
     alg = CBC(Rijndael(key, blockSize=32))
     for i in range(100):
         pt = i*'a'
         ct = alg.encrypt(pt,iv=iv)
         self.assertEqual( alg.decrypt(iv+ct), pt )
Пример #6
0
 def testCBC_Rijndael_256(self):
     """  Rijndael CBC 256 """
     key =   '2b7e151628aed2a6abf7158809cf4f3c'
     iv  =   '000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f'
     pt  = """6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e51
              30c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"""
     key,iv,pt = a2b_p(key),a2b_p(iv),a2b_p(pt)
     alg = CBC(Rijndael(key, blockSize=32))
     ct = alg.encrypt(pt,iv=iv)
     self.assertEqual( alg.decrypt(iv+ct), pt )
Пример #7
0
 def testIVmultencryptUnique(self):
     """  Test that two different encrypts have different IVs """
     key = a2b_p('2b7e151628aed2a6abf7158809cf4f3c')
     pt = "This is yet another test case"
     alg1 = CBC(Rijndael(key, blockSize=32))
     ct1 = alg1.encrypt(pt)
     ct2 = alg1.encrypt(pt)
     self.assertNotEqual(ct1, ct2)
     self.assertEqual(alg1.decrypt(ct1), pt)
     self.assertEqual(alg1.decrypt(ct1), alg1.decrypt(ct2))
Пример #8
0
 def testCBC_Rijndael_variable_data(self):
     """  Rijndael CBC 256 """
     key = '2b7e151628aed2a6abf7158809cf4f3c'
     iv = '000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f'
     key, iv = a2b_p(key), a2b_p(iv)
     alg = CBC(Rijndael(key, blockSize=32))
     for i in range(100):
         pt = i * 'a'
         ct = alg.encrypt(pt, iv=iv)
         self.assertEqual(alg.decrypt(iv + ct), pt)
Пример #9
0
 def testCBC_Rijndael_256(self):
     """  Rijndael CBC 256 """
     key = '2b7e151628aed2a6abf7158809cf4f3c'
     iv = '000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f'
     pt = """6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e51
              30c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"""
     key, iv, pt = a2b_p(key), a2b_p(iv), a2b_p(pt)
     alg = CBC(Rijndael(key, blockSize=32))
     ct = alg.encrypt(pt, iv=iv)
     self.assertEqual(alg.decrypt(iv + ct), pt)
Пример #10
0
    def testMultipassEncrypt(self):
        """ Test moreData usage """
        alg = CBC(Rijndael(16 * chr(0), blockSize=32))
        ct1 = ''
        for i in range(129):
            ct1 += alg.encrypt('a', more=1)
        ct1 += alg.encrypt('')  # flush any remaining
        ct2 = alg.encrypt(129 * 'a')
        self.assertNotEqual(ct1, ct2)
        pt1 = alg.decrypt(ct1)
        pt2 = alg.decrypt(ct2)
        self.assertEqual(pt1, pt2)

        pt3 = alg.decrypt('', more=1)
        for i in range(len(ct2)):
            pt3 += alg.decrypt(ct2[i], more=1)
        pt3 += alg.decrypt('')
Пример #11
0
 def testIVuniqueness(self):
     """  Test that two different instances have different IVs """
     key = a2b_p('2b7e151628aed2a6abf7158809cf4f3c')
     pt = "This is a test case"
     alg1 = CBC(Rijndael(key, blockSize=32))
     alg2 = CBC(Rijndael(key, blockSize=32))
     ct1 = alg1.encrypt(pt)
     ct2 = alg2.encrypt(pt)
     self.assertNotEqual(ct1, ct2)
Пример #12
0
    def testMultipassEncrypt(self):
        """ Test moreData usage """
        alg = CBC(Rijndael(16*chr(0), blockSize=32))
        ct1 = ''
        for i in range(129):
            ct1 += alg.encrypt('a',more=1)
        ct1 += alg.encrypt('')      # flush any remaining
        ct2 = alg.encrypt(129*'a')
        self.assertNotEqual( ct1, ct2 )
        pt1 = alg.decrypt(ct1)
        pt2 = alg.decrypt(ct2)
        self.assertEqual(pt1,pt2)

        pt3 = alg.decrypt('',more=1)
        for i in range(len(ct2)):
            pt3 += alg.decrypt(ct2[i], more=1)
        pt3 += alg.decrypt('')
Пример #13
0
 def test(self):
     aes_cbc = CBC(AES())
     aes_cbc.setKey('aaaaaaaaaaaaaaaa')
     ct1 = aes_cbc.encrypt('test')
     ct2 = aes_cbc.encrypt('test') # note - auto iv, reslt is different ths time
Пример #14
0
 def __init__(self, key=None, padding=padWithPadLen(), keySize=16):
     CBC.__init__(self, AES(key, noPadding(), keySize), padding)
     self.name = 'AES_CBC'
Пример #15
0
 def test(self):
     aes_cbc = CBC(AES())
     aes_cbc.setKey('aaaaaaaaaaaaaaaa')
     ct1 = aes_cbc.encrypt('test')
     ct2 = aes_cbc.encrypt(
         'test')  # note - auto iv, reslt is different ths time
Пример #16
0
 def __init__(self, key=None, padding=padWithPadLen(), keySize=16):
     CBC.__init__( self, AES(key, noPadding(), keySize), padding)
     self.name       = 'AES_CBC'