The doc of pycrypto gives an example of using AES in CTR mode:
>>> from Crypto.Cipher import AES
>>> from Crypto.Util import Counter
>>>
>>> pt = b''*1000000
>>> ctr = Counter.new(128)
>>> cipher = AES.new(b''*16, AES.MODE_CTR, counter=ctr)
>>> ct = cipher.encrypt(pt)
I think this isn't safe for encryption of multiple messages with the same key because the counter value defaults to 1. Would it be safe if I do:
iv = os.urandom(16)
ctr = Counter.new(128, initial_value=int.from_bytes(iv, 'big'))
Some articles recommend a timestamp-based nonce (e.g. 64-bit timestamp + 64-bit random value). I was wondering if it's OK to simply draw a 128-bit random value with urandom
, and if this implementation is flawless.
urandom
vsrandom
and whether there are pycrypto-specific issues. $\endgroup$