1 from blockcipher
import *
3 import Crypto
.Cipher
.RC5
5 print "Crypto.Cipher.RC5 isn't available. You're probably using the Debian pycrypto version. Install the original pycrypto for RC5."
8 def new(key
,mode
=MODE_ECB
,IV
=None,counter
=None,rounds
=12,word_size
=32):
9 """Create a new cipher object
11 RC5 using pycrypto for algo and pycryptoplus for ciphermode
13 new(key,mode=MODE_ECB,IV=None,counter=None):
14 key = raw string containing the keys
15 mode = python_AES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB
16 IV = IV as a raw string
17 -> only needed for CBC mode
18 counter = counter object (CryptoPlus.Util.util.Counter)
19 -> only needed for CTR mode
21 https://www.cosic.esat.kuleuven.be/nessie/testvectors/
22 -----------------------------------------
23 >>> from CryptoPlus.Cipher import RC5
24 >>> key = "00000000000000000000000000000000".decode('hex')
25 >>> plaintext = "0000000000000000".decode('hex')
27 >>> cipher = RC5.new(key,RC5.MODE_ECB,rounds=rounds)
28 >>> cipher.encrypt(plaintext).encode('hex')
31 return RC5(key
,mode
,IV
,counter
,rounds
,word_size
)
33 class RC5(BlockCipher
):
34 def __init__(self
,key
,mode
,IV
,counter
,rounds
,word_size
):
36 #XTS implementation only works with blocksizes of 16 bytes
37 assert type(key
) is tuple
38 self
.cipher
= Crypto
.Cipher
.RC5
.new(key
[0],rounds
=rounds
,word_size
=word_size
)
39 self
.cipher2
= Crypto
.Cipher
.RC5
.new(key
[1],rounds
=rounds
,word_size
=word_size
)
40 assert self
.cipher
.block_size
== 16
41 elif mode
== MODE_CMAC
:
42 #CMAC implementation only supports blocksizes of 8 and 16 bytes
43 self
.cipher
= Crypto
.Cipher
.RC5
.new(key
,rounds
=rounds
,word_size
=word_size
)
44 assert self
.cipher
.block_size
in (8,16)
46 self
.cipher
= Crypto
.Cipher
.RC5
.new(key
,rounds
=rounds
,word_size
=word_size
)
47 self
.blocksize
= self
.cipher
.block_size
48 BlockCipher
.__init
__(self
,key
,mode
,IV
,counter
)
54 if __name__
== "__main__":