On Thu, 2006-06-01 at 02:47 -0400, Vivek Lakshmanan wrote:
> - Add support for KeyPairGenerator for RSA.

Chalk this one up to a nOOb error... I was under the impression that all
JCE related providers were merged into one class
(gnu.javax.crypto.jce.GnuCrypto) and since I could not find
KeyPairGenerator provider for RSA there, assumed it was missing. There
is already an RSA KeyPairGenerator in the gnu.java.security.provider.Gnu
JCE provider instead.

Please ignore the earlier patch I sent and consider this instead...

Thanks,
Vivek

Index: gnu/java/security/Registry.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/security/Registry.java,v
retrieving revision 1.5
diff -u -r1.5 Registry.java
--- gnu/java/security/Registry.java	22 Mar 2006 22:49:24 -0000	1.5
+++ gnu/java/security/Registry.java	1 Jun 2006 05:43:12 -0000
@@ -136,6 +136,9 @@
 
   // Symmetric block cipher modes of operations...............................
 
+  /** For compatibility with alternative JCE implementations. */
+  String NONE_MODE = "none";
+  
   /** Electronic CodeBook mode. */
   String ECB_MODE = "ecb";
 
@@ -157,8 +160,14 @@
   /** Authenticated-Encrypted mode. */
   String EAX_MODE = "eax";
 
+  /** Suffix used in transformation for various paddings */
+  String PADDING_SUFFIX = "padding";
+  
+  
   // Padding scheme names and synonyms........................................
-
+  /** PKCS#1 padding scheme for RSA. */
+  String PKCS1_PAD = "pkcs1";
+  
   /** PKCS#5 padding scheme. */
   String PKCS5_PAD = "pkcs5";

 Index: gnu/javax/crypto/RSACipherImpl.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/javax/crypto/RSACipherImpl.java,v
retrieving revision 1.2
diff -u -r1.2 RSACipherImpl.java
--- gnu/javax/crypto/RSACipherImpl.java	21 Sep 2005 20:55:40 -0000	1.2
+++ gnu/javax/crypto/RSACipherImpl.java	3 Jun 2006 03:16:13 -0000
@@ -1,5 +1,5 @@
-/* DiffieHellmanImpl.java -- implementation of the Diffie-Hellman key agreement.
-   Copyright (C) 2005  Free Software Foundation, Inc.
+/* RSACipherImpl.java -- implementation of the RSA shared cipher.
+ Copyright (C) 2005, 2006  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -41,6 +41,7 @@
 import gnu.classpath.ByteArray;
 import gnu.classpath.debug.Component;
 import gnu.classpath.debug.SystemLogger;
+import gnu.java.security.Registry;
 
 import java.math.BigInteger;
 
@@ -79,20 +80,36 @@
   private SecureRandom random = null;
   private byte[] dataBuffer = null;
   private int pos = 0;
-
-  protected void engineSetMode (String mode) throws NoSuchAlgorithmException
+  
+  protected void engineSetMode(String mode) throws NoSuchAlgorithmException
   {
-    throw new NoSuchAlgorithmException ("only one mode available");
+    // RSA can not have any modes, except the "NONE" mode...
+    if (! mode.equalsIgnoreCase(Registry.NONE_MODE))
+      {
+        throw new NoSuchAlgorithmException("only one mode available");
+      }
   }
 
-  protected void engineSetPadding (String pad) throws NoSuchPaddingException
+  protected void engineSetPadding(String pad) throws NoSuchPaddingException
   {
-    throw new NoSuchPaddingException ("only one padding available");
-  }
+    // RSA can only have PKCS1 padding
+    pad = pad.trim().toLowerCase();
+    if (pad.endsWith(Registry.PADDING_SUFFIX))
+      pad = pad.substring(0, pad.length() - Registry.PADDING_SUFFIX.length());
+    if (! pad.equals(Registry.PKCS1_PAD))
+      {
+        throw new NoSuchPaddingException("only one padding available");
+      }
 
-  protected int engineGetBlockSize ()
+  }
+  
+  protected int engineGetBlockSize()
   {
-    return 1;
+    if (dataBuffer == null)
+      throw new IllegalStateException("RSA cipher not initialized!");
+    else
+      return dataBuffer.length;
+    
   }
 
   protected int engineGetOutputSize (int inputLen)
Index: gnu/javax/crypto/pad/PadFactory.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/javax/crypto/pad/PadFactory.java,v
retrieving revision 1.2
diff -u -r1.2 PadFactory.java
--- gnu/javax/crypto/pad/PadFactory.java	22 Mar 2006 22:49:24 -0000	1.2
+++ gnu/javax/crypto/pad/PadFactory.java	3 Jun 2006 03:16:15 -0000
@@ -81,8 +81,8 @@
       }
 
     pad = pad.trim().toLowerCase();
-    if (pad.endsWith("padding"))
-      pad = pad.substring(0, pad.length() - "padding".length());
+    if (pad.endsWith(PADDING_SUFFIX))
+      pad = pad.substring(0, pad.length() - PADDING_SUFFIX.length());
     IPad result = null;
     if (pad.equals(PKCS7_PAD) || pad.equals(PKCS5_PAD))
       {

Reply via email to