[pycrypto] AES, MODE_CTR
Legrandin
helderijs at gmail.com
Thu Dec 5 11:41:05 PST 2013
>Thanks Richard. Now working
> def test_AES5(self):
> pt=b' '*10
> ctr=Counter.new(128)
> iv = Random.new().read(AES.block_size)
> cipher = AES.new(b' '*16, AES.MODE_CTR, IV=iv, counter=ctr)
> ct = cipher.encrypt(pt)
> ctrr=Counter.new(128)
> decipher = AES.new(b' '*16, AES.MODE_CTR, IV=iv, counter=ctrr)
> ptr = decipher.decrypt(ct)
> self.assertEqual(pt,ptr)
> iv added as suggested.
Actually, the IV parameter is ignored in Counter mode.
If you want to add a nonce to the counter block you must pass it to
the Counter class:
nonce = Random.new().read(8)
ctr = Counter.new(64, nonce)
cipher = AES.new(b' '*16, AES.MODE_CTR, counter=ctr)
The counter block is then made up by 64 bits of nonce and 64 bits of counter.
PS: I think I get 1 out of 3 messages out of this mailing list.
More information about the pycrypto
mailing list