Beispiel #1
0
 def testEncrcptDecryptMultiSizesPt(self):
     """ Encrypt decrypt multiple sizes """
     alg = Icedoll( 16*chr(0))
     for size in range(100):
         pt = size*'a'
         ct = alg.encrypt(pt)
         #print 'ct  = ',b2a_p(ct)
         dct = alg.decrypt(ct)
         #print 'dct = ',b2a_p(dct)
         assert(pt == dct), 'pt != dct'
 def testEncrcptDecryptMultiSizesPt(self):
     """ Encrypt decrypt multiple sizes """
     alg = Icedoll(16 * chr(0))
     for size in range(100):
         pt = size * 'a'
         ct = alg.encrypt(pt)
         #print 'ct  = ',b2a_p(ct)
         dct = alg.decrypt(ct)
         #print 'dct = ',b2a_p(dct)
         assert (pt == dct), 'pt != dct'
Beispiel #3
0
 def __init__(self,key=None,keySize=32,blockSize=32,tapRound=6,extraRounds=6,micSize=16,ivSize=16):
     """  """
     Icedoll.__init__(self,key=None,keySize=32,blockSize=32,tapRound=6,extraRounds=6)
     self.name    = 'TROLLDOLL'
     self.micSize = micSize
     self.ivSize  = ivSize
     self.r       = Random()            # for IV generation
     import time
     newSeed = time.ctime()+str(self.r)    # seed with instance location
     self.r.seed(newSeed)                  # to make unique
     self.reset()
Beispiel #4
0
 def __init__(self,key=None,keySize=32,blockSize=32,tapRound=6,extraRounds=6,micSize=16,ivSize=16):
     """  """
     Icedoll.__init__(self,key=None,keySize=32,blockSize=32,tapRound=6,extraRounds=6)
     self.name    = 'TROLLDOLL'
     self.micSize = micSize
     self.ivSize  = ivSize
     self.r       = Random()            # for IV generation
     import time
     newSeed = time.ctime()+str(self.r)    # seed with instance location
     self.r.seed(newSeed)                  # to make unique
     self.reset()
Beispiel #5
0
 def encrypt(self, plainText, more=None):
     """ """
     if not(self.hasIV):  # On first call to encrypt put in an IV
         plainText = self._makeIV() + plainText # add the 'IV'
         self.hasIV = 1
     if more == None:    # on last call to encrypt append integrity check
         plainText = plainText + self._makeIC()
     return Icedoll.encrypt(self, plainText, more=more)
Beispiel #6
0
 def encrypt(self, plainText, more=None):
     """ """
     if not (self.hasIV):  # On first call to encrypt put in an IV
         plainText = self._makeIV() + plainText  # add the 'IV'
         self.hasIV = 1
     if more == None:  # on last call to encrypt append integrity check
         plainText = plainText + self._makeIC()
     return Icedoll.encrypt(self, plainText, more=more)
    def testDctEqPt(self):
        """ test of plaintext = decrypt(encrypt(plaintext)) """
        alg = Icedoll(16 * chr(0), padding=noPadding())
        pt = 16 * 4 * 'a'  # block aligned
        ct = alg.encrypt(pt)
        print('ct  = ', b2a_p(ct))
        dct = alg.decrypt(ct)
        print('dct = ', b2a_p(dct))
        assert (pt == dct), 'pt != dct'

        alg = Icedoll(16 * chr(0))  # autoPad
        pt = 17 * 4 * 'a'  # non-block aligned
        ct = alg.encrypt(pt)
        print('ct  = ', b2a_p(ct))
        dct = alg.decrypt(ct)
        print('dct = ', b2a_p(dct))
        assert (pt == dct), 'pt != dct'
Beispiel #8
0
 def decrypt(self, cipherText, more=None):
     """ Decrypt cipher text, Icedoll automatically removes
         prepended random bits used as IV.
         Note - typically IV is directly used as the first
         cipher text.  Here the IV is prepended to the plaintext
         prior to encryption and removed on decryption.
     """
     plainText = Icedoll.decrypt(self, cipherText, more=more)
     if not(self.hasIV):  # on first call to decrypt remove IV
         plainText = plainText[self.ivSize:] # remove the IV
         self.hasIV = 1
     if more == None:    # on last call to encrypt append integrity check
         if not(self._verifyIC(plainText[-self.micSize:])) :
             raise IntegrityCheckError, 'Trolldoll MIC Failure, bad key or modified data'
         plainText = plainText[:-self.micSize]  # trim off the integrity check
     return plainText
Beispiel #9
0
 def decrypt(self, cipherText, more=None):
     """ Decrypt cipher text, Icedoll automatically removes
         prepended random bits used as IV.
         Note - typically IV is directly used as the first
         cipher text.  Here the IV is prepended to the plaintext
         prior to encryption and removed on decryption.
     """
     plainText = Icedoll.decrypt(self, cipherText, more=more)
     if not(self.hasIV):  # on first call to decrypt remove IV
         plainText = plainText[self.ivSize:] # remove the IV
         self.hasIV = 1
     if more == None:    # on last call to encrypt append integrity check
         if not(self._verifyIC(plainText[-self.micSize:])) :
             raise IntegrityCheckError, 'Trolldoll MIC Failure, bad key or modified data'
         plainText = plainText[:-self.micSize]  # trim off the integrity check
     return plainText
Beispiel #10
0
 def IcedollTestVec(i, key, pt, ct):
     """ Run single AES test vector with any legal blockSize
         and any legal key size. """
     bkey, plainText, cipherText = a2b_hex(key), a2b_hex(pt), a2b_hex(ct)
     kSize = len(bkey)
     bSize = len(cipherText) # set block size to length of block
     alg = Icedoll(bkey, keySize=kSize, blockSize=bSize, padding=noPadding())
     cct = alg.encrypt(plainText)
     print 'pt    =',b2a_p(plainText)
     print 'ct    =',b2a_p(cct)
     dcct = alg.decrypt(cct)
     #print '_dcct',b2a_p(dcct)
     self.assertEqual( dcct, plainText )
     self.assertEqual( alg.encrypt(plainText),  cipherText )
     self.assertEqual( alg.decrypt(cipherText), plainText )
Beispiel #11
0
    def testDctEqPt(self):
        """ test of plaintext = decrypt(encrypt(plaintext)) """
        alg = Icedoll( 16*chr(0), padding=noPadding())
        pt  = 16*4*'a'             # block aligned
        ct  = alg.encrypt(pt)
        print 'ct  = ',b2a_p(ct)
        dct = alg.decrypt(ct)
        print 'dct = ',b2a_p(dct)
        assert(pt == dct), 'pt != dct'

        alg = Icedoll( 16*chr(0))  # autoPad
        pt  = 17*4*'a'             # non-block aligned
        ct  = alg.encrypt(pt)
        print 'ct  = ',b2a_p(ct)
        dct = alg.decrypt(ct)
        print 'dct = ',b2a_p(dct)
        assert(pt == dct), 'pt != dct'
Beispiel #12
0
 def reset(self):
     Icedoll.reset(self)
     self.hasIV = None
Beispiel #13
0
 def reset(self):
     Icedoll.reset(self)
     self.hasIV = None