From 1ddea81bf55bbd963852dafc895d7baebaf17dd8 Mon Sep 17 00:00:00 2001 From: Christophe Oosterlynck Date: Tue, 14 Oct 2008 14:56:42 +0200 Subject: [PATCH] IV default is an "all zero" string by default --- src/CryptoPlus/Cipher/AES.py | 2 +- src/CryptoPlus/Cipher/ARC2.py | 2 +- src/CryptoPlus/Cipher/Blowfish.py | 2 +- src/CryptoPlus/Cipher/CAST.py | 2 +- src/CryptoPlus/Cipher/DES.py | 2 +- src/CryptoPlus/Cipher/DES3.py | 2 +- src/CryptoPlus/Cipher/IDEA.py | 2 +- src/CryptoPlus/Cipher/RC5.py | 2 +- src/CryptoPlus/Cipher/blockcipher.py | 23 +++++++++++------------ src/CryptoPlus/Cipher/python_AES.py | 2 +- src/CryptoPlus/Cipher/python_Blowfish.py | 2 +- src/CryptoPlus/Cipher/python_DES.py | 2 +- src/CryptoPlus/Cipher/python_DES3.py | 2 +- src/CryptoPlus/Cipher/python_PRESENT.py | 2 +- src/CryptoPlus/Cipher/python_Rijndael.py | 2 +- src/CryptoPlus/Cipher/python_Serpent.py | 2 +- src/CryptoPlus/Cipher/python_Twofish.py | 2 +- 17 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/CryptoPlus/Cipher/AES.py b/src/CryptoPlus/Cipher/AES.py index 8f8ab7b..d1abe3e 100644 --- a/src/CryptoPlus/Cipher/AES.py +++ b/src/CryptoPlus/Cipher/AES.py @@ -7,7 +7,7 @@ def new(key,mode=MODE_ECB,IV=None,counter=None): key = raw string containing the key, AES-128..256 will be selected according to the key length -> when using XTS mode: the key should be a tuple of the 2 keys needed mode = AES.MODE_ECB/CBC/CFB/OFB/CTR/XTS/CMAC, default is ECB - IV = IV as a raw string + IV = IV as a raw string, default is "all zero" IV -> only needed for CBC mode counter = counter object (CryptoPlus.Util.util.Counter) -> only needed for CTR mode diff --git a/src/CryptoPlus/Cipher/ARC2.py b/src/CryptoPlus/Cipher/ARC2.py index 2c93bdb..c1bef3c 100644 --- a/src/CryptoPlus/Cipher/ARC2.py +++ b/src/CryptoPlus/Cipher/ARC2.py @@ -10,7 +10,7 @@ def new(key,mode=MODE_ECB,IV=None,counter=None,effective_keylen=None): key = raw string containing the keys mode = python_AES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB - IV = IV as a raw string + IV = IV as a raw string, default is "all zero" IV -> only needed for CBC mode counter = counter object (CryptoPlus.Util.util.Counter) -> only needed for CTR mode diff --git a/src/CryptoPlus/Cipher/Blowfish.py b/src/CryptoPlus/Cipher/Blowfish.py index 46f826d..49e5442 100644 --- a/src/CryptoPlus/Cipher/Blowfish.py +++ b/src/CryptoPlus/Cipher/Blowfish.py @@ -8,7 +8,7 @@ def new(key,mode=MODE_ECB,IV=None,counter=None): key = raw string containing the key mode = Blowfish.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB - IV = IV as a raw string + IV = IV as a raw string, default is "all zero" IV -> only needed for CBC mode counter = counter object (CryptoPlus.Util.util.Counter) -> only needed for CTR mode diff --git a/src/CryptoPlus/Cipher/CAST.py b/src/CryptoPlus/Cipher/CAST.py index 8225781..52be6ff 100644 --- a/src/CryptoPlus/Cipher/CAST.py +++ b/src/CryptoPlus/Cipher/CAST.py @@ -8,7 +8,7 @@ def new(key,mode=MODE_ECB,IV=None,counter=None): key = raw string containing the keys mode = python_AES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB - IV = IV as a raw string + IV = IV as a raw string, default is "all zero" IV -> only needed for CBC mode counter = counter object (CryptoPlus.Util.util.Counter) -> only needed for CTR mode diff --git a/src/CryptoPlus/Cipher/DES.py b/src/CryptoPlus/Cipher/DES.py index ad55bd6..033f685 100644 --- a/src/CryptoPlus/Cipher/DES.py +++ b/src/CryptoPlus/Cipher/DES.py @@ -8,7 +8,7 @@ def new(key,mode=MODE_ECB,IV=None,counter=None): key = raw string containing the keys mode = python_AES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB - IV = IV as a raw string + IV = IV as a raw string, default is "all zero" IV -> only needed for CBC mode counter = counter object (CryptoPlus.Util.util.Counter) -> only needed for CTR mode diff --git a/src/CryptoPlus/Cipher/DES3.py b/src/CryptoPlus/Cipher/DES3.py index b5da7b6..1ad6397 100644 --- a/src/CryptoPlus/Cipher/DES3.py +++ b/src/CryptoPlus/Cipher/DES3.py @@ -10,7 +10,7 @@ def new(key,mode=MODE_ECB,IV=None,counter=None): - DES-EDE2: supply 2 keys as 1 single concatenated 16byte key= key1|key2 - DES-EDE3: supply 3 keys as 1 single concatenated 24byte key= key1|key2|key3 mode = python_AES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB - IV = IV as a raw string + IV = IV as a raw string, default is "all zero" IV -> only needed for CBC mode counter = counter object (CryptoPlus.Util.util.Counter) -> only needed for CTR mode diff --git a/src/CryptoPlus/Cipher/IDEA.py b/src/CryptoPlus/Cipher/IDEA.py index 0fd41c7..57e7712 100644 --- a/src/CryptoPlus/Cipher/IDEA.py +++ b/src/CryptoPlus/Cipher/IDEA.py @@ -12,7 +12,7 @@ def new(key,mode=MODE_ECB,IV=None,counter=None): key = raw string containing the keys mode = python_AES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB - IV = IV as a raw string + IV = IV as a raw string, default is "all zero" IV -> only needed for CBC mode counter = counter object (CryptoPlus.Util.util.Counter) -> only needed for CTR mode diff --git a/src/CryptoPlus/Cipher/RC5.py b/src/CryptoPlus/Cipher/RC5.py index 3c0668c..f0267a5 100644 --- a/src/CryptoPlus/Cipher/RC5.py +++ b/src/CryptoPlus/Cipher/RC5.py @@ -13,7 +13,7 @@ def new(key,mode=MODE_ECB,IV=None,counter=None,rounds=12,word_size=32): key = raw string containing the keys multiple of 8 bits between 0 <-> 2040 bits mode = python_AES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB - IV = IV as a raw string + IV = IV as a raw string, default is "all zero" IV -> only needed for CBC mode counter = counter object (CryptoPlus.Util.util.Counter) -> only needed for CTR mode diff --git a/src/CryptoPlus/Cipher/blockcipher.py b/src/CryptoPlus/Cipher/blockcipher.py index 9c18bf6..97a4096 100644 --- a/src/CryptoPlus/Cipher/blockcipher.py +++ b/src/CryptoPlus/Cipher/blockcipher.py @@ -51,28 +51,27 @@ class BlockCipher(): if not self.keylen_valid(key) and type(key) is not tuple: raise ValueError(self.key_error_message) + if IV == None: + self.IV = '\x00'*16 + else: + self.IV = IV + if mode <> MODE_XTS: self.cipher = cipher_module(self.key,**args) if mode == MODE_ECB: self.chain = ECB(self.cipher, self.blocksize) elif mode == MODE_CBC: - if IV == None: - raise Exception,"Provide an IV!" - if len(IV) <> self.blocksize: + if len(self.IV) <> self.blocksize: raise Exception,"the IV length should be %i bytes"%self.blocksize - self.chain = CBC(self.cipher, self.blocksize,IV) + self.chain = CBC(self.cipher, self.blocksize,self.IV) elif mode == MODE_CFB: - if IV == None: - raise Exception,"Provide an IV!" - if len(IV) <> self.blocksize: + if len(self.IV) <> self.blocksize: raise Exception,"the IV length should be %i bytes"%self.blocksize - self.chain = CFB(self.cipher, self.blocksize,IV) + self.chain = CFB(self.cipher, self.blocksize,self.IV) elif mode == MODE_OFB: - if IV == None: - raise Exception,"Provide an IV!" - if len(IV) <> self.blocksize: + if len(self.IV) <> self.blocksize: raise ValueError("the IV length should be %i bytes"%self.blocksize) - self.chain = OFB(self.cipher, self.blocksize,IV) + self.chain = OFB(self.cipher, self.blocksize,self.IV) elif mode == MODE_CTR: if (counter == None) or not callable(counter): raise Exception,"Supply a valid counter object for the CTR mode" diff --git a/src/CryptoPlus/Cipher/python_AES.py b/src/CryptoPlus/Cipher/python_AES.py index 4f7783a..69ec6b9 100644 --- a/src/CryptoPlus/Cipher/python_AES.py +++ b/src/CryptoPlus/Cipher/python_AES.py @@ -10,7 +10,7 @@ def new(key,mode=MODE_ECB,IV=None,counter=None): -> when using XTS mode: the key should be a tuple containing the 2 keys needed mode = python_AES.MODE_ECB/CBC/CFB/OFB/CTR/XTS/CMAC, default is ECB -> for every mode, except ECB and CTR, it is important to construct a seperate cipher for encryption and decryption - IV = IV as a raw string + IV = IV as a raw string, default is "all zero" IV -> needed for CBC, CFB and OFB mode counter = counter object (CryptoPlus.Util.util.Counter) -> only needed for CTR mode diff --git a/src/CryptoPlus/Cipher/python_Blowfish.py b/src/CryptoPlus/Cipher/python_Blowfish.py index 25b5cf3..8ed2dc9 100644 --- a/src/CryptoPlus/Cipher/python_Blowfish.py +++ b/src/CryptoPlus/Cipher/python_Blowfish.py @@ -8,7 +8,7 @@ def new(key,mode=MODE_ECB,IV=None,counter=None): key = raw string containing the key mode = Blowfish.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB - IV = IV as a raw string + IV = IV as a raw string, default is "all zero" IV -> only needed for CBC mode counter = counter object (CryptoPlus.Util.util.Counter) -> only needed for CTR mode diff --git a/src/CryptoPlus/Cipher/python_DES.py b/src/CryptoPlus/Cipher/python_DES.py index 61ac8d8..bf0cef3 100644 --- a/src/CryptoPlus/Cipher/python_DES.py +++ b/src/CryptoPlus/Cipher/python_DES.py @@ -9,7 +9,7 @@ def new(key,mode=MODE_ECB,IV=None,counter=None): key = raw string containing the key mode = python_DES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB -> for every mode, except ECB and CTR, it is important to construct a seperate cipher for encryption and decryption - IV = IV as a raw string + IV = IV as a raw string, default is "all zero" IV -> needed for CBC, CFB and OFB mode counter = counter object (CryptoPlus.Util.util.Counter) -> only needed for CTR mode diff --git a/src/CryptoPlus/Cipher/python_DES3.py b/src/CryptoPlus/Cipher/python_DES3.py index 2251270..5203bcf 100644 --- a/src/CryptoPlus/Cipher/python_DES3.py +++ b/src/CryptoPlus/Cipher/python_DES3.py @@ -10,7 +10,7 @@ def new(key,mode=MODE_ECB,IV=None,counter=None): - DES-EDE2: supply 2 keys as 1 single concatenated 16byte key= key1|key2 - DES-EDE3: supply 3 keys as 1 single concatenated 24byte key= key1|key2|key3 mode = python_AES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB - IV = IV as a raw string + IV = IV as a raw string, default is "all zero" IV -> only needed for CBC mode counter = counter object (CryptoPlus.Util.util.Counter) -> only needed for CTR mode diff --git a/src/CryptoPlus/Cipher/python_PRESENT.py b/src/CryptoPlus/Cipher/python_PRESENT.py index 3260b11..b58a454 100644 --- a/src/CryptoPlus/Cipher/python_PRESENT.py +++ b/src/CryptoPlus/Cipher/python_PRESENT.py @@ -9,7 +9,7 @@ def new(key,mode=MODE_ECB,IV=None,counter=None,rounds=32): key = raw string containing the key, AES-128..256 will be selected according to the key length mode = python_PRESENT.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB -> for every mode, except ECB and CTR, it is important to construct a seperate cipher for encryption and decryption - IV = IV as a raw string + IV = IV as a raw string, default is "all zero" IV -> needed for CBC, CFB and OFB mode counter = counter object (CryptoPlus.Util.util.Counter) -> only needed for CTR mode diff --git a/src/CryptoPlus/Cipher/python_Rijndael.py b/src/CryptoPlus/Cipher/python_Rijndael.py index 4178487..7f78ab8 100644 --- a/src/CryptoPlus/Cipher/python_Rijndael.py +++ b/src/CryptoPlus/Cipher/python_Rijndael.py @@ -10,7 +10,7 @@ def new(key,mode=MODE_ECB,IV=None,counter=None,blocksize=None): -> supported key size are 16, 24 and 32 bytes mode = python_Rijndael.MODE_ECB/CBC/CFB/OFB/CTR/XTS/CMAC, default is ECB -> for every mode, except ECB and CTR, it is important to construct a seperate cipher for encryption and decryption - IV = IV as a raw string + IV = IV as a raw string, default is "all zero" IV -> needed for CBC, CFB and OFB mode counter = counter object (CryptoPlus.Util.util.Counter) -> only needed for CTR mode diff --git a/src/CryptoPlus/Cipher/python_Serpent.py b/src/CryptoPlus/Cipher/python_Serpent.py index 29f9860..75a7355 100644 --- a/src/CryptoPlus/Cipher/python_Serpent.py +++ b/src/CryptoPlus/Cipher/python_Serpent.py @@ -10,7 +10,7 @@ def new(key,mode=MODE_ECB,IV=None,counter=None): -> when using XTS mode: the key should be a tuple containing the 2 keys needed mode = python_Serpent.MODE_ECB/CBC/CFB/OFB/CTR/XTS/CMAC, default is ECB -> for every mode, except ECB and CTR, it is important to construct a seperate cipher for encryption and decryption - IV = IV as a raw string + IV = IV as a raw string, default is "all zero" IV -> needed for CBC, CFB and OFB mode counter = counter object (CryptoPlus.Util.util.Counter) -> only needed for CTR mode diff --git a/src/CryptoPlus/Cipher/python_Twofish.py b/src/CryptoPlus/Cipher/python_Twofish.py index e8175bd..3797e3c 100644 --- a/src/CryptoPlus/Cipher/python_Twofish.py +++ b/src/CryptoPlus/Cipher/python_Twofish.py @@ -10,7 +10,7 @@ def new(key,mode=MODE_ECB,IV=None,counter=None): -> when using XTS mode: the key should be a tuple containing the 2 keys needed mode = python_Twofish.MODE_ECB/CBC/CFB/OFB/CTR/XTS/CMAC, default is ECB -> for every mode, except ECB and CTR, it is important to construct a seperate cipher for encryption and decryption - IV = IV as a raw string + IV = IV as a raw string, default is "all zero" IV -> needed for CBC, CFB and OFB mode counter = counter object (CryptoPlus.Util.util.Counter) -> only needed for CTR mode -- 2.11.4.GIT