java.security.SecureRandom in GCJ 4.0.2 has no impact, so SecureRandom always
uses the same weak seed.  This has obvious security issues, though they'd take
a targetted attack to mount (e.g. force a JVM restart so the SecureRandom
reverts to the default seed - "new java.util.Random(0l).nextBytes(new
byte[20])", per gnu.java.security.provider.SHA1PRNG.ensureIsSeeded()).

[EMAIL PROTECTED] ~/dev/i2p/native $ gcj -o seed --main=seed seed.java
[EMAIL PROTECTED] ~/dev/i2p/native $ ./seed
Byte difference in a seeded PRNG: 0
Seed data:
8bc7ec2ec7c4f87a13ec6120616ead831baeaf40dfd0804c534145ddbd12c580926578f8e0fea3b8b69287e26841a91cfca9a63fa95e453494f495ff14c82
[EMAIL PROTECTED] ~/dev/i2p/native $ cat seed.java
import java.security.SecureRandom;

public class seed {
  public static void main(String args[]) {
    SecureRandom r = new SecureRandom();
    byte unseededBuf[] = new byte[64];
    r.nextBytes(unseededBuf);

    r = new SecureRandom();
    byte seededBuf[] = new byte[64];
    r.setSeed(unseededBuf);
    r.nextBytes(seededBuf);

    int diffs = 0;
    for (int i = 0; i < 64; i++) {
      if (seededBuf[i] != unseededBuf[i])
        diffs++;
    }
    System.out.println("Byte difference in a seeded PRNG: " + diffs);
    System.out.print("Seed data: ");
    for (int i = 0; i < 64; i++)
      System.out.print(Integer.toHexString((int)(unseededBuf[i]&0xFF)));
    System.out.println();
  }
}

The secureRandom.getProvider().toString() returns
"gnu.java.security.provider.Gnu: name=GNU version=1.0", which in turn uses the
SHA1PRNG (in the 4.0.2 release, at least).  The odd part is that the provider
should be taking into account the seed - engineSetSeed *looks* right, and
java.security.SecureRandom.java's setSeed just calls the spi.engineSetSeed, so
I'm not sure whats going on here.

=jr


-- 
           Summary: SecureRandom.setSeed has no impact
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: java
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jrandom-gcc at i2p dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24481

Reply via email to