diff options
Diffstat (limited to 'gnu/java/security/sig/rsa')
-rw-r--r-- | gnu/java/security/sig/rsa/EMSA_PSS.java | 84 | ||||
-rw-r--r-- | gnu/java/security/sig/rsa/RSAPSSSignature.java | 36 |
2 files changed, 34 insertions, 86 deletions
diff --git a/gnu/java/security/sig/rsa/EMSA_PSS.java b/gnu/java/security/sig/rsa/EMSA_PSS.java index c1c9760ed..0b93abab7 100644 --- a/gnu/java/security/sig/rsa/EMSA_PSS.java +++ b/gnu/java/security/sig/rsa/EMSA_PSS.java @@ -38,12 +38,13 @@ exception statement from your version. */ package gnu.java.security.sig.rsa; +import gnu.classpath.Configuration; import gnu.java.security.hash.HashFactory; import gnu.java.security.hash.IMessageDigest; import gnu.java.security.util.Util; -import java.io.PrintWriter; import java.util.Arrays; +import java.util.logging.Logger; /** * <p>An implementation of the EMSA-PSS encoding/decoding scheme.</p> @@ -70,26 +71,7 @@ import java.util.Arrays; */ public class EMSA_PSS implements Cloneable { - - // Debugging methods and variables - // ------------------------------------------------------------------------- - - private static final String NAME = "emsa-pss"; - - private static final boolean DEBUG = false; - - private static final int debuglevel = 5; - - private static final PrintWriter err = new PrintWriter(System.out, true); - - private static void debug(String s) - { - err.println(">>> " + NAME + ": " + s); - } - - // Constants and variables - // ------------------------------------------------------------------------- - + private static final Logger log = Logger.getLogger(EMSA_PSS.class.getName()); /** The underlying hash function to use with this instance. */ private IMessageDigest hash; @@ -202,10 +184,10 @@ public class EMSA_PSS implements Cloneable System.arraycopy(salt, 0, DB, emLen - sLen - hLen - 1, sLen); // 9. Let dbMask = MGF(H, emLen - hLen - 1). byte[] dbMask = MGF(H, emLen - hLen - 1); - if (DEBUG && debuglevel > 8) + if (Configuration.DEBUG) { - debug("dbMask (encode): " + Util.toString(dbMask)); - debug("DB (encode): " + Util.toString(DB)); + log.fine("dbMask (encode): " + Util.toString(dbMask)); + log.fine("DB (encode): " + Util.toString(DB)); } // 10. Let maskedDB = DB XOR dbMask. for (i = 0; i < DB.length; i++) @@ -244,12 +226,12 @@ public class EMSA_PSS implements Cloneable */ public boolean decode(byte[] mHash, byte[] EM, int emBits, int sLen) { - if (DEBUG && debuglevel > 8) + if (Configuration.DEBUG) { - debug("mHash: " + Util.toString(mHash)); - debug("EM: " + Util.toString(EM)); - debug("emBits: " + String.valueOf(emBits)); - debug("sLen: " + String.valueOf(sLen)); + log.fine("mHash: " + Util.toString(mHash)); + log.fine("EM: " + Util.toString(EM)); + log.fine("emBits: " + String.valueOf(emBits)); + log.fine("sLen: " + String.valueOf(sLen)); } if (sLen < 0) { @@ -262,19 +244,15 @@ public class EMSA_PSS implements Cloneable // 2. Let mHash = Hash(M), an octet string of length hLen. if (hLen != mHash.length) { - if (DEBUG && debuglevel > 8) - { - debug("hLen != mHash.length; hLen: " + String.valueOf(hLen)); - } + if (Configuration.DEBUG) + log.fine("hLen != mHash.length; hLen: " + String.valueOf(hLen)); throw new IllegalArgumentException("wrong hash"); } // 3. If emBits < 8.hLen + 8.sLen + 9, output 'decoding error' and stop. if (emBits < (8 * hLen + 8 * sLen + 9)) { - if (DEBUG && debuglevel > 8) - { - debug("emBits < (8hLen + 8sLen + 9); sLen: " + String.valueOf(sLen)); - } + if (Configuration.DEBUG) + log.fine("emBits < (8hLen + 8sLen + 9); sLen: " + String.valueOf(sLen)); throw new IllegalArgumentException("decoding error"); } int emLen = (emBits + 7) / 8; @@ -282,10 +260,8 @@ public class EMSA_PSS implements Cloneable // output 'inconsistent' and stop. if ((EM[EM.length - 1] & 0xFF) != 0xBC) { - if (DEBUG && debuglevel > 8) - { - debug("EM does not end with 0xBC"); - } + if (Configuration.DEBUG) + log.fine("EM does not end with 0xBC"); return false; } // 5. Let maskedDB be the leftmost emLen ? hLen ? 1 octets of EM, and let @@ -294,10 +270,8 @@ public class EMSA_PSS implements Cloneable // maskedDB are not all equal to zero, output 'inconsistent' and stop. if ((EM[0] & (0xFF << (8 - (8 * emLen - emBits)))) != 0) { - if (DEBUG && debuglevel > 8) - { - debug("Leftmost 8emLen - emBits bits of EM are not 0s"); - } + if (Configuration.DEBUG) + log.fine("Leftmost 8emLen - emBits bits of EM are not 0s"); return false; } byte[] DB = new byte[emLen - hLen - 1]; @@ -314,10 +288,10 @@ public class EMSA_PSS implements Cloneable } // 9. Set the leftmost 8.emLen ? emBits bits of DB to zero. DB[0] &= (0xFF >>> (8 * emLen - emBits)); - if (DEBUG && debuglevel > 8) + if (Configuration.DEBUG) { - debug("dbMask (decode): " + Util.toString(dbMask)); - debug("DB (decode): " + Util.toString(DB)); + log.fine("dbMask (decode): " + Util.toString(dbMask)); + log.fine("DB (decode): " + Util.toString(DB)); } // 10. If the emLen -hLen -sLen -2 leftmost octets of DB are not zero or // if the octet at position emLen -hLen -sLen -1 is not equal to 0x01, @@ -329,20 +303,16 @@ public class EMSA_PSS implements Cloneable { if (DB[i] != 0) { - if (DEBUG && debuglevel > 8) - { - debug("DB[" + String.valueOf(i) + "] != 0x00"); - } + if (Configuration.DEBUG) + log.fine("DB[" + String.valueOf(i) + "] != 0x00"); return false; } } if (DB[i] != 0x01) { // i == emLen -hLen -sLen -2 - if (DEBUG && debuglevel > 8) - { - debug("DB's byte at position (emLen -hLen -sLen -2); i.e. " - + String.valueOf(i) + " is not 0x01"); - } + if (Configuration.DEBUG) + log.fine("DB's byte at position (emLen -hLen -sLen -2); i.e. " + + String.valueOf(i) + " is not 0x01"); return false; } // 11. Let salt be the last sLen octets of DB. diff --git a/gnu/java/security/sig/rsa/RSAPSSSignature.java b/gnu/java/security/sig/rsa/RSAPSSSignature.java index 7ec62568a..3e9cad452 100644 --- a/gnu/java/security/sig/rsa/RSAPSSSignature.java +++ b/gnu/java/security/sig/rsa/RSAPSSSignature.java @@ -38,18 +38,19 @@ exception statement from your version. */ package gnu.java.security.sig.rsa; +import gnu.classpath.Configuration; import gnu.java.security.Registry; import gnu.java.security.hash.HashFactory; import gnu.java.security.hash.IMessageDigest; import gnu.java.security.sig.BaseSignature; import gnu.java.security.util.Util; -import java.io.PrintWriter; import java.math.BigInteger; import java.security.PrivateKey; import java.security.PublicKey; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; +import java.util.logging.Logger; /** * <p>The RSA-PSS signature scheme is a public-key encryption scheme combining @@ -73,26 +74,7 @@ import java.security.interfaces.RSAPublicKey; */ public class RSAPSSSignature extends BaseSignature { - - // Debugging methods and variables - // ------------------------------------------------------------------------- - - private static final String NAME = "rsa-pss"; - - private static final boolean DEBUG = false; - - private static final int debuglevel = 1; - - private static final PrintWriter err = new PrintWriter(System.out, true); - - private static void debug(String s) - { - err.println(">>> " + NAME + ": " + s); - } - - // Constants and variables - // ------------------------------------------------------------------------- - + private static final Logger log = Logger.getLogger(RSAPSSSignature.class.getName()); /** The underlying EMSA-PSS instance for this object. */ private EMSA_PSS pss; @@ -201,10 +183,8 @@ public class RSAPSSSignature extends BaseSignature byte[] salt = new byte[sLen]; this.nextRandomBytes(salt); byte[] EM = pss.encode(md.digest(), modBits - 1, salt); - if (DEBUG && debuglevel > 8) - { - debug("EM (sign): " + Util.toString(EM)); - } + if (Configuration.DEBUG) + log.fine("EM (sign): " + Util.toString(EM)); // 2. Convert the encoded message EM to an integer message representative // m (see Section 1.2.2): m = OS2IP(EM). BigInteger m = new BigInteger(1, EM); @@ -262,10 +242,8 @@ public class RSAPSSSignature extends BaseSignature int emBits = modBits - 1; int emLen = (emBits + 7) / 8; byte[] EM = m.toByteArray(); - if (DEBUG && debuglevel > 8) - { - debug("EM (verify): " + Util.toString(EM)); - } + if (Configuration.DEBUG) + log.fine("EM (verify): " + Util.toString(EM)); if (EM.length > emLen) { return false; |