Re: [kaffe] SHA1PRNG fix

2002-06-04 Thread Timothy Stack

 hi,
 
 I attached a patch for SHA1PRNG.java, it still wasn't quite doing what it
 was supposed to.  Also, i think i forgot to mention that this was based on
 Classpath's (broken) code, so the copyright should probably be gpl'ed.

oops, i whiffed again...

in libraries/javalib/kaffe/security/provider/SHA1PRNG.java:
 @@ -112,6 +110,22 @@
this.data,
SEED_SIZE,

This is supposed to be zero.  So it should look like:

System.arraycopy(this.seed,
 0,
 this.data,
 0,
 SEED_SIZE);

atleast, thats how i think its supposed to work.

thanks,

tim stack

___
kaffe mailing list
[EMAIL PROTECTED]
http://kaffe.org/cgi-bin/mailman/listinfo/kaffe



[kaffe] SHA1PRNG fix

2002-06-03 Thread Timothy Stack


hi,

I attached a patch for SHA1PRNG.java, it still wasn't quite doing what it
was supposed to.  Also, i think i forgot to mention that this was based on
Classpath's (broken) code, so the copyright should probably be gpl'ed.

thanks,

tim stack


Index: SHA1PRNG.java
===
RCS file: /cvs/kaffe/kaffe/libraries/javalib/kaffe/security/provider/SHA1PRNG.java,v
retrieving revision 1.3
diff -u -r1.3 SHA1PRNG.java
--- SHA1PRNG.java   12 May 2002 15:08:46 -  1.3
+++ SHA1PRNG.java   3 Jun 2002 20:36:08 -
 -6,10 +6,6 
  *
  * See the file license.terms for information on usage and redistribution
  * of this file.
- *
- * NB THIS DOES NOT ACTUALLY IMPLEMENT SHA1PRNG - it uses random and
- *is a place holder.
- *
  */
 
 package kaffe.security.provider;
 -25,14 +21,15 
 public class SHA1PRNG
extends SecureRandomSpi
 {
-   private static final int SEED_SIZE = 20;
-   private static final int DATA_SIZE = 40;
+   private static final int SEED_SIZE = 8;
+   private static final int DATA_SIZE = 16;

private MessageDigest md;
private byte seed[] = new byte[SEED_SIZE];
private int seedPos = 0;
private byte data[] = new byte[DATA_SIZE];
private int dataPos = 0;
+   private long counter = 0;

public SHA1PRNG()
{
 -43,7 +40,7 
this.md = MessageDigest.getInstance(SHA-1);
 
new Random().nextBytes(this.seed);
-   digest = this.md.digest(this.data);
+   digest = this.md.digest(this.seed);
System.arraycopy(digest, 0, this.data, 0, SEED_SIZE);
}
catch(NoSuchAlgorithmException e)
 -77,7 +74,8 

protected void engineNextBytes(byte[] bytes)
{
-   if( bytes.length  (20 - this.dataPos) )
+   this.counter += 1;
+   if( bytes.length  (SEED_SIZE - this.dataPos) )
{
System.arraycopy(this.data, this.dataPos,
 bytes, 0,
 -112,6 +110,22 
 this.data,
 SEED_SIZE,
 SEED_SIZE);
+   this.data[SEED_SIZE] =
+   (byte)(this.counter);
+   this.data[SEED_SIZE + 1] =
+   (byte)(this.counter   8);
+   this.data[SEED_SIZE + 2] =
+   (byte)(this.counter  16);
+   this.data[SEED_SIZE + 3] =
+   (byte)(this.counter  24);
+   this.data[SEED_SIZE + 4] =
+   (byte)(this.counter  32);
+   this.data[SEED_SIZE + 5] =
+   (byte)(this.counter  40);
+   this.data[SEED_SIZE + 6] =
+   (byte)(this.counter  48);
+   this.data[SEED_SIZE + 7] =
+   (byte)(this.counter  56);
digest = this.md.digest(this.data);
System.arraycopy(digest,
 0,



Re: [kaffe] SHA1PRNG fix

2002-06-03 Thread Timothy Stack


bah, i forgot a couple of other security fixes:

  Change name of SHA - SHA-1
  Add aliases to the Kaffe provider

tim stack



Index: SHA.java
===
RCS file: /cvs/kaffe/kaffe/libraries/javalib/kaffe/security/provider/SHA.java,v
retrieving revision 1.2
diff -u -r1.2 SHA.java
--- SHA.java22 Nov 2001 06:21:25 -  1.2
+++ SHA.java3 Jun 2002 20:57:57 -
 -17,7 +17,7 
 
 
 public final class SHA extends UpdateDigest {
-   public static final String DIGEST_NAME = SHA;
+   public static final String DIGEST_NAME = SHA-1;
public static final int DIGEST_LENGTH = 20;
 
public SHA() {
Index: Kaffe.java
===
RCS file: /cvs/kaffe/kaffe/libraries/javalib/kaffe/security/provider/Kaffe.java,v
retrieving revision 1.3
diff -u -r1.3 Kaffe.java
--- Kaffe.java  4 Jan 2002 05:12:33 -   1.3
+++ Kaffe.java  3 Jun 2002 20:57:57 -
 -39,8 +39,12 
kaffe.security.provider.MD4);
put(MessageDigest.MD5,
kaffe.security.provider.MD5);
-   put(MessageDigest.SHA,
+   put(MessageDigest.SHA-1,
kaffe.security.provider.SHA);
+   put(Alg.Alias.MessageDigest.SHA1,
+   SHA-1);
+   put(Alg.Alias.MessageDigest.SHA,
+   SHA-1);
put(SecureRandom.SHA1PRNG,
kaffe.security.provider.SHA1PRNG);
return null;