Author: toad
Date: 2007-02-09 18:14:57 +0000 (Fri, 09 Feb 2007)
New Revision: 11711

Modified:
   trunk/freenet/src/freenet/crypt/DSA.java
   trunk/freenet/src/freenet/crypt/DSAGroup.java
   trunk/freenet/src/freenet/crypt/DSAPrivateKey.java
   trunk/freenet/src/freenet/crypt/DSAPublicKey.java
   trunk/freenet/src/freenet/crypt/DSASignature.java
Log:
Throw if passed an illegal (negative or zero) BigInteger in asymmetric crypto

Modified: trunk/freenet/src/freenet/crypt/DSA.java
===================================================================
--- trunk/freenet/src/freenet/crypt/DSA.java    2007-02-09 17:50:09 UTC (rev 
11710)
+++ trunk/freenet/src/freenet/crypt/DSA.java    2007-02-09 18:14:57 UTC (rev 
11711)
@@ -24,6 +24,8 @@
                        BigInteger k, 
                        BigInteger m,
                        RandomSource random) {
+               if(k.signum() == -1) throw new IllegalArgumentException();
+               if(m.signum() == -1) throw new IllegalArgumentException();
                BigInteger r=g.getG().modPow(k, g.getP()).mod(g.getQ());

                BigInteger kInv=k.modInverse(g.getQ());
@@ -84,6 +86,7 @@
        public static boolean verify(DSAPublicKey kp,
                        DSASignature sig,
                        BigInteger m) {
+               if(m.signum() == -1) throw new IllegalArgumentException();
                try {
                        // 0<r<q has to be true
                        if((sig.getR().compareTo(BigInteger.ZERO) < 1) || 
(kp.getQ().compareTo(sig.getR()) < 1)) return false;

Modified: trunk/freenet/src/freenet/crypt/DSAGroup.java
===================================================================
--- trunk/freenet/src/freenet/crypt/DSAGroup.java       2007-02-09 17:50:09 UTC 
(rev 11710)
+++ trunk/freenet/src/freenet/crypt/DSAGroup.java       2007-02-09 18:14:57 UTC 
(rev 11711)
@@ -41,6 +41,8 @@
         this.p = p;
         this.q = q;
         this.g = g;
+        if(p.signum() != 1 || q.signum() != 1 || g.signum() != 1)
+               throw new IllegalArgumentException();
         updateCachedHexStrings();
     }

@@ -66,6 +68,8 @@
                     + pAsHexString + ',' + qAsHexString + " and "
                     + gAsHexString + " to integers");
         }
+        if(p.signum() != 1 || q.signum() != 1 || g.signum() != 1)
+               throw new IllegalArgumentException();
     }

     private void updateCachedHexStrings() {

Modified: trunk/freenet/src/freenet/crypt/DSAPrivateKey.java
===================================================================
--- trunk/freenet/src/freenet/crypt/DSAPrivateKey.java  2007-02-09 17:50:09 UTC 
(rev 11710)
+++ trunk/freenet/src/freenet/crypt/DSAPrivateKey.java  2007-02-09 18:14:57 UTC 
(rev 11711)
@@ -21,6 +21,8 @@

     public DSAPrivateKey(BigInteger x) {
         this.x = x;
+        if(x.signum() != 1)
+               throw new IllegalArgumentException();
     }

     // this is dangerous...  better to force people to construct the

Modified: trunk/freenet/src/freenet/crypt/DSAPublicKey.java
===================================================================
--- trunk/freenet/src/freenet/crypt/DSAPublicKey.java   2007-02-09 17:50:09 UTC 
(rev 11710)
+++ trunk/freenet/src/freenet/crypt/DSAPublicKey.java   2007-02-09 18:14:57 UTC 
(rev 11711)
@@ -26,6 +26,7 @@
        private byte[] fingerprint = null;

     public DSAPublicKey(DSAGroup g, BigInteger y) {
+       if(y.signum() != 1) throw new IllegalArgumentException();
                this.y=y;
                this.group=g;
                if(g == null) throw new NullPointerException();
@@ -37,6 +38,7 @@
         */
        public DSAPublicKey(DSAGroup g, String yAsHexString) throws 
NumberFormatException {
                this.y=new NativeBigInteger(yAsHexString,16);
+       if(y.signum() != 1) throw new IllegalArgumentException();
                this.yAsHexString = yAsHexString;
                this.group=g;
                if(g == null) throw new NullPointerException();

Modified: trunk/freenet/src/freenet/crypt/DSASignature.java
===================================================================
--- trunk/freenet/src/freenet/crypt/DSASignature.java   2007-02-09 17:50:09 UTC 
(rev 11710)
+++ trunk/freenet/src/freenet/crypt/DSASignature.java   2007-02-09 18:14:57 UTC 
(rev 11711)
@@ -33,6 +33,7 @@
                throw new NumberFormatException("DSA Signatures have two 
values");
                r = new NativeBigInteger(sig.substring(0,x), 16);
                s = new NativeBigInteger(sig.substring(x+1), 16);
+               if(r.signum() != 1 || s.signum() != 1) throw new 
IllegalArgumentException();
     }

     public static DSASignature read(InputStream in) throws IOException {
@@ -59,6 +60,7 @@
                this.s=s;
                if((r == null) || (s == null)) //Do not allow this sice we wont 
do any sanity checking beyond this place
                        throw new NullPointerException();
+               if(r.signum() != 1 || s.signum() != 1) throw new 
IllegalArgumentException();
     }

     public BigInteger getR() {


Reply via email to