Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a SecureRandom really needed for generating Initialization vectors or is Random enough?

For a stream cipher to be secure against repeated key attacks the IV's should not repeat themselves. But does SecureRandom have a benefit over a simple non-secure Random in that respect (or is it just for generating an unpredictable sequence)?

Assuming I'm using fixed sized messages with AES CBC mode and I generate a new Random for each IV (using the current nano time as seed) does this increase the probability of repeating IV compared to a SecureRandom?

like image 697
user9397757 Avatar asked Sep 03 '12 14:09

user9397757


2 Answers

The biggest problem with using Random to generate your IV is not that it is likely to repeat, but that an attacker can predict future IVs, and this can be used to attack CBC.

Related: https://crypto.stackexchange.com/q/3515/2805

like image 149
finnw Avatar answered Oct 23 '22 09:10

finnw


Random uses 48-bit key so it will repeat approx every 2^48 values. It means not every possible long will be generated. That may or may not be random enough for you. If in doubt use SecureRandom, you can always change it later.

like image 38
Peter Lawrey Avatar answered Oct 23 '22 11:10

Peter Lawrey