CFB: added segment_size to docstring of the cipher wrappers
[python-cryptoplus.git] / src / CryptoPlus / Cipher / CAST.py
blob7814f4ab14736d60474173d48dc7268e7dbf5b03
1 from blockcipher import *
2 import Crypto.Cipher.CAST
4 def new(key,mode=MODE_ECB,IV=None,counter=None,segment_size=None):
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
15 segment_size = amount of bits to use from the keystream in each chain part
16 -> supported values: multiple of 8 between 8 and the blocksize
17 of the cipher (only per byte access possible), default is 8
18 -> only needed for CFB mode
20 EXAMPLES:
21 **********
22 IMPORTING:
23 -----------
24 >>> from CryptoPlus.Cipher import CAST
26 ECB example: http://www.rfc-editor.org/rfc/rfc2144.txt
27 -------------
28 128 bit key
30 >>> key = "0123456712345678234567893456789A".decode('hex')
31 >>> plaintext = "0123456789ABCDEF".decode('hex')
32 >>> cipher = CAST.new(key,CAST.MODE_ECB,)
33 >>> cipher.encrypt(plaintext).encode('hex')
34 '238b4fe5847e44b2'
36 40 bit key
37 >>> from CryptoPlus.Cipher import CAST
38 >>> key = "0123456712".decode('hex')
39 >>> plaintext = "0123456789ABCDEF".decode('hex')
40 >>> cipher = CAST.new(key,CAST.MODE_ECB,)
41 >>> cipher.encrypt(plaintext).encode('hex').upper()
42 '7AC816D16E9B302E'
43 """
44 return CAST(key,mode,IV,counter,segment_size)
46 class CAST(BlockCipher):
47 def __init__(self,key,mode,IV,counter,segment_size):
48 cipher_module = Crypto.Cipher.CAST.new
49 self.blocksize = 8
50 BlockCipher.__init__(self,key,mode,IV,counter,cipher_module,segment_size)
52 def _test():
53 import doctest
54 doctest.testmod()
56 if __name__ == "__main__":
57 _test()