public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug java/24481]  New: SecureRandom.setSeed has no impact
@ 2005-10-22  0:52 jrandom-gcc at i2p dot net
  2005-10-22  2:28 ` [Bug classpath/24481] " pinskia at gcc dot gnu dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: jrandom-gcc at i2p dot net @ 2005-10-22  0:52 UTC (permalink / raw)
  To: java-prs

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()).

jrandom@betty ~/dev/i2p/native $ gcj -o seed --main=seed seed.java
jrandom@betty ~/dev/i2p/native $ ./seed
Byte difference in a seeded PRNG: 0
Seed data:
8bc7ec2ec7c4f87a13ec6120616ead831baeaf40dfd0804c534145ddbd12c580926578f8e0fea3b8b69287e26841a91cfca9a63fa95e453494f495ff14c82
jrandom@betty ~/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


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2006-04-12 18:19 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-22  0:52 [Bug java/24481] New: SecureRandom.setSeed has no impact jrandom-gcc at i2p dot net
2005-10-22  2:28 ` [Bug classpath/24481] " pinskia at gcc dot gnu dot org
2005-10-22  2:36 ` pinskia at gcc dot gnu dot org
2005-10-24 18:47 ` tromey at gcc dot gnu dot org
2006-04-07 11:07 ` david at jpackage dot org
2006-04-11  4:21 ` csm at gnu dot org
2006-04-11  4:34 ` david at jpackage dot org
2006-04-11 20:58 ` csm at gnu dot org
2006-04-12  0:11 ` david at jpackage dot org
2006-04-12  4:46 ` csm at gnu dot org
2006-04-12 16:39 ` cvs-commit at developer dot classpath dot org
2006-04-12 18:19 ` csm at gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).