From eb56edefcddd7037f293f0b23097714e0ff65d66 Mon Sep 17 00:00:00 2001 From: tiftof Date: Thu, 25 Sep 2008 13:44:58 +0000 Subject: [PATCH] extended XTS support XTS support for some cipher has been updated to the new key interface(supply key as tuple) and some ciphers have gained XTS support XTS is available now for: AES, Serpent and Twofish git-svn-id: svn+ssh://devel.yobi.be/home/svn/CryptoPlus/trunk@23 49921240-e1b6-4d8d-af3b-5ae6c3d9e7c1 --- .gitignore | 1 + src/Cipher/python_DES3.py | 1 - src/Cipher/python_Rijndael.py | 7 ++++--- src/Cipher/python_Serpent.py | 16 +++++++--------- src/Cipher/python_Twofish.py | 8 +++++++- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 0e01008..4f95877 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.pyc *~ dist/ +build/ diff --git a/src/Cipher/python_DES3.py b/src/Cipher/python_DES3.py index dcb85e4..781cd34 100644 --- a/src/Cipher/python_DES3.py +++ b/src/Cipher/python_DES3.py @@ -7,7 +7,6 @@ MODE_CFB = 3 MODE_OFB = 5 MODE_CTR = 6 MODE_CMAC = 8 -#TODO: XTS nog niet mogelijk -> blocksize des = 8, XTS = 16 def new(key,mode=blockcipher.MODE_ECB,IV=None,counter=None): """Create a DES-EDE3 or DES-EDE2 cipher object diff --git a/src/Cipher/python_Rijndael.py b/src/Cipher/python_Rijndael.py index 7e5e672..567b168 100644 --- a/src/Cipher/python_Rijndael.py +++ b/src/Cipher/python_Rijndael.py @@ -66,9 +66,10 @@ class python_Rijndael(blockcipher.BlockCipher): assert len(key) in (16, 24, 32) assert blocksize in (16, 24, 32) if mode == MODE_XTS: - assert len(key) == 32 - self.cipher = rijndael(key[:16], blocksize) - self.cipher2 = rijndael(key[16:], blocksize) + assert len(blocksize) == 16 + assert type(key) is tuple + self.cipher = rijndael(key[0], blocksize) + self.cipher2 = rijndael(key[1], blocksize) else: self.cipher = rijndael(key, blocksize) self.blocksize = blocksize diff --git a/src/Cipher/python_Serpent.py b/src/Cipher/python_Serpent.py index 239a248..c1e52c5 100644 --- a/src/Cipher/python_Serpent.py +++ b/src/Cipher/python_Serpent.py @@ -1,10 +1,3 @@ -# source of the used python implementation of blowfish -# http://www.michaelgilfix.com/files/blowfish.py -# other possibility: -# http://www.4dsolutions.net/cgi-bin/py2html.cgi?script=/ocn/python/blowfish.py -# => difficulties: doesn't define a class, only functions -# - import blockcipher from pyserpent import Serpent @@ -13,6 +6,7 @@ MODE_CBC = 2 MODE_CFB = 3 MODE_OFB = 5 MODE_CTR = 6 +MODE_XTS = 7 MODE_CMAC = 8 def new(key,mode=blockcipher.MODE_ECB,IV=None,counter=None): @@ -58,9 +52,13 @@ def new(key,mode=blockcipher.MODE_ECB,IV=None,counter=None): return python_Serpent(key,mode,IV,counter) class python_Serpent(blockcipher.BlockCipher): - #need test vectors for other modes than ecb def __init__(self,key,mode,IV,counter): - self.cipher = Serpent(key) + if mode == MODE_XTS: + assert type(key) is tuple + self.cipher = Serpent(key[0]) + self.cipher2 = Serpent(key[1]) + else: + self.cipher = Serpent(key) self.blocksize = self.cipher.get_block_size() blockcipher.BlockCipher.__init__(self,key,mode,IV,counter) diff --git a/src/Cipher/python_Twofish.py b/src/Cipher/python_Twofish.py index 52d04ba..9db3f18 100644 --- a/src/Cipher/python_Twofish.py +++ b/src/Cipher/python_Twofish.py @@ -10,6 +10,7 @@ MODE_CBC = 2 MODE_CFB = 3 MODE_OFB = 5 MODE_CTR = 6 +MODE_XTS = 7 MODE_CMAC = 8 def new(key,mode=blockcipher.MODE_ECB,IV=None,counter=None): @@ -42,7 +43,12 @@ def new(key,mode=blockcipher.MODE_ECB,IV=None,counter=None): class python_Twofish(blockcipher.BlockCipher): def __init__(self,key,mode,IV,counter): - self.cipher = Twofish(key) + if mode == MODE_XTS: + assert type(key) is tuple + self.cipher = Twofish(key[1]) + self.cipher2 = Twofish(key[2]) + else: + self.cipher = Twofish(key) self.blocksize = self.cipher.get_block_size() blockcipher.BlockCipher.__init__(self,key,mode,IV,counter) -- 2.11.4.GIT