Update of /cvsroot/freenet/freenet/src/freenet
In directory sc8-pr-cvs1:/tmp/cvs-serv15619/src/freenet

Modified Files:
        Storables.java 
Log Message:
Some optimizations wrt encryption:
Dont generate pubkey from privkey when we already have it available.
Dont generate hextrings from BigInteger:s when we already have them and the other way 
around.

Index: Storables.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/Storables.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Storables.java      8 Oct 2003 22:02:34 -0000       1.6
+++ Storables.java      8 Oct 2003 22:48:38 -0000       1.7
@@ -73,12 +73,22 @@
       * fields in the Storables.
       */
     public void sign(Random r, DSAPrivateKey sk, DSAGroup g) {
-        setPublicKey(new DSAPublicKey(g, sk));
-        Digest ctx = SHA1.getInstance();
-        hashUpdate(ctx, new String[] {"Signature"});
-        BigInteger k = Util.generateLargeRandom(80, 160, r);
-        BigInteger m = Util.byteArrayToMPI(ctx.digest());
-        setSignature(DSA.sign(g, sk, k, m));
+               sign(r,sk,new DSAPublicKey(g, sk));
+    }
+       /** Calculates the Signature and stores the Public-key and Signature
+                 * fields in the Storables. Make sure that a matching
+                 * private/public pair is supplied. If you cannot do that then
+                 * use the overload above and it will handle that for you.
+                 * Use this method instead of the above one if you have the readily 
pubkey
+                 * available.. saves us some processing
+                 */
+    public void sign(Random r, DSAPrivateKey sk, DSAPublicKey p) {
+               setPublicKey(p);
+               Digest ctx = SHA1.getInstance();
+               hashUpdate(ctx, new String[] {"Signature"});
+               BigInteger k = Util.generateLargeRandom(80, 160, r);
+               BigInteger m = Util.byteArrayToMPI(ctx.digest());
+               setSignature(DSA.sign(p.getGroup(), sk, k, m));
     }
 
     /** Checks the Signature using the Public-key.
@@ -157,12 +167,11 @@
     public DSAPublicKey getPublicKey() {
         FieldSet fs = getSet("Public-key");
         if (fs == null) return null;
-        BigInteger[] ypqg = new BigInteger[4];
+        String[] ypqg = new String[4];
         for (int i = 0 ; i < 4 ; i++) {
             String n = fs.get(ypqgS[i]);
             if (n == null)
                 return null;
-            ypqg[i] = new BigInteger(n, 16);
         }
 
         return new DSAPublicKey(new DSAGroup(ypqg[1], ypqg[2],

_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to