CFB: added segment_size to docstring of the cipher wrappers
[python-cryptoplus.git] / src / CryptoPlus / Cipher / ARC2.py
blobc612ce94405aa4170727dc6f0fb85755205684cc
1 from blockcipher import *
2 import Crypto.Cipher.ARC2
3 import Crypto
4 from pkg_resources import parse_version
6 def new(key,mode=MODE_ECB,IV=None,counter=None,segment_size=None,effective_keylen=None):
7 """Create a new cipher object
9 ARC2 using pycrypto for algo and pycryptoplus for ciphermode
11 key = raw string containing the keys
12 mode = python_AES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB
13 IV = IV as a raw string, default is "all zero" IV
14 -> only needed for CBC mode
15 counter = counter object (CryptoPlus.Util.util.Counter)
16 -> only needed for CTR mode
17 segment_size = amount of bits to use from the keystream in each chain part
18 -> supported values: multiple of 8 between 8 and the blocksize
19 of the cipher (only per byte access possible), default is 8
20 -> only needed for CFB mode
21 effective_keylen = how much bits to effectively use from the supplied key
22 -> will only be used when the pycrypto version on your system is >2.0.1
24 EXAMPLES:
25 **********
26 IMPORTING:
27 -----------
28 >>> from CryptoPlus.Cipher import ARC2
30 http://www.ietf.org/rfc/rfc2268.txt
31 Doctest will fail when using pycrypto 2.0.1 and older
32 ------------------------------------
33 >>> key = "0000000000000000".decode('hex')
34 >>> plaintext = "0000000000000000".decode('hex')
35 >>> ek = 63
36 >>> cipher = ARC2.new(key,ARC2.MODE_ECB,effective_keylen=ek)
37 >>> cipher.encrypt(plaintext).encode('hex')
38 'ebb773f993278eff'
39 """
40 return ARC2(key,mode,IV,counter,effective_keylen,segment_size)
42 class ARC2(BlockCipher):
43 def __init__(self,key,mode,IV,counter,effective_keylen,segment_size):
44 # pycrypto versions newer than 2.0.1 will have support for "effective_keylen"
45 if parse_version(Crypto.__version__) <= parse_version("2.0.1"):
46 cipher_module = Crypto.Cipher.ARC2.new
47 args = {}
48 else:
49 cipher_module = Crypto.Cipher.ARC2.new
50 args = {'effective_keylen':effective_keylen}
51 self.blocksize = 8
52 BlockCipher.__init__(self,key,mode,IV,counter,cipher_module,segment_size,args)
54 def _test():
55 import doctest
56 doctest.testmod()
58 if __name__ == "__main__":
59 _test()