[pycrypto] AES, MODE_CTR

Dave Pawson dave.pawson at gmail.com
Thu Dec 5 23:24:42 PST 2013


On 5 December 2013 19:41, Legrandin <helderijs at gmail.com> wrote:
>>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.

Another undocumented feature?
Sigh.




>
> PS: I think I get 1 out of 3 messages out of this mailing list.

Your email system or the server?
It seems that the repo owner and the mailing list are both
somewhat lax.

regards


-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk


More information about the pycrypto mailing list