Java


JAVA.INSEC.SS : Use of Same Seed (Java)

Summary

The same random seed is used multiple times.

If two random generators are initialized with the same seed, they will produce the same predictable sequence of numbers.

See also Hardcoded Random Seed (Java).

Properties

Class Name Use of Same Seed (Java)
Significance security
Mnemonic JAVA.INSEC.SS
Categories
CWE CWE:336 Same Seed in Pseudo-Random Number Generator (PRNG)
Availability Available for Java only.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Use of Same Seed (Java)"

Example

public class SameSeed {
    public void randomPrint() {
        final byte[] SEED = new byte[] {0x01, 0x02, 0x03, 0x04, 0x05};

        SecureRandom secureRandom1 = new SecureRandom();
        secureRandom1.setSeed(SEED);

        SecureRandom secureRandom2 = new SecureRandom();
        secureRandom2.setSeed(SEED); // 'Use of Same Seed (Java)' warning issued here

        System.out.println("" + secureRandom1.nextInt());
        System.out.println("" + secureRandom2.nextInt());
    }
}

Resolution

Use a less predictable seed, or don't specify a seed at all.

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.