During my research on a java application, I discovered that the nextInt(64)
function of the java.Random()
class is used to generate the encryption key.
The key size is 16 bytes. I know that this generator is not recommended because it is vulnerable. Especially in this case, the value of each byte of the key is selected from a short range from 0x0 to 0x40.
I already got acquainted with the fact that it is possible to predict the next values of the generator using the previous values. But in my case meyan has no data about the previous values (The key is encrypted and I don't have access to its values), so here we are talking about iterating over the key values. I don't understand how can I use the data that each next value depends on the previous one (oldseed parameter)?
protected int next(int bits) {
long oldseed, nextseed;
AtomicLong seed = this.seed;
do {
oldseed = seed.get();
nextseed = (oldseed * multiplier + addend) & mask;
} while (!seed.compareAndSet(oldseed, nextseed));
return (int)(nextseed >>> (48 - bits));
}
How to reduce the number of enumeration for such a 16-byte key?
nextInt(64)
usesnext(31)
, and whynextInt(64)
is precisely equivalent tonext(6)
. Then assume a single thread during key generation, and simplify the question's code accordingly. Find which bits of the seed have an influence on the 16-byte key. Conclude how many such 16-byte keys there can be, and how to enumerate all of them at feasible cost. Perhaps, investigate how the seed is chosen, which may allow to enumerate the actual key much faster. – fgrieu Apr 11 '22 at 08:42