CFB: added support for "segmentsize"
[python-cryptoplus.git] / src / CryptoPlus / Cipher / CAST.py
blob6259a82b95075bd2bee4f62f7bb01d7b76c70f1a
1 from blockcipher import *
2 import Crypto.Cipher.CAST
4 def new(key,mode=MODE_ECB,IV=None,counter=None,segment_size=8):
5 """Create a new cipher object
7 CAST using pycrypto for algo and pycryptoplus for ciphermode
9 key = raw string containing the keys
10 mode = python_AES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB
11 IV = IV as a raw string, default is "all zero" IV
12 -> only needed for CBC mode
13 counter = counter object (CryptoPlus.Util.util.Counter)
14 -> only needed for CTR mode
16 EXAMPLES:
17 **********
18 IMPORTING:
19 -----------
20 >>> from CryptoPlus.Cipher import CAST
22 ECB example: http://www.rfc-editor.org/rfc/rfc2144.txt
23 -------------
24 128 bit key
26 >>> key = "0123456712345678234567893456789A".decode('hex')
27 >>> plaintext = "0123456789ABCDEF".decode('hex')
28 >>> cipher = CAST.new(key,CAST.MODE_ECB,)
29 >>> cipher.encrypt(plaintext).encode('hex')
30 '238b4fe5847e44b2'
32 40 bit key
33 >>> from CryptoPlus.Cipher import CAST
34 >>> key = "0123456712".decode('hex')
35 >>> plaintext = "0123456789ABCDEF".decode('hex')
36 >>> cipher = CAST.new(key,CAST.MODE_ECB,)
37 >>> cipher.encrypt(plaintext).encode('hex').upper()
38 '7AC816D16E9B302E'
39 """
40 return CAST(key,mode,IV,counter,segment_size)
42 class CAST(BlockCipher):
43 def __init__(self,key,mode,IV,counter,segment_size):
44 cipher_module = Crypto.Cipher.CAST.new
45 self.blocksize = 8
46 BlockCipher.__init__(self,key,mode,IV,counter,cipher_module,segment_size)
48 def _test():
49 import doctest
50 doctest.testmod()
52 if __name__ == "__main__":
53 _test()