2003/02/12 06:21:04
[org.ibex.core.git] / src / org / bouncycastle / crypto / engines / RSAEngine.java
index 2cbac54..c02e20a 100644 (file)
@@ -21,7 +21,7 @@ public class RSAEngine
     /**
      * initialise the RSA engine.
      *
-     * @param forEncryption treu if we are encrypting, false otherwise.
+     * @param forEncryption true if we are encrypting, false otherwise.
      * @param param the necessary RSA key parameters.
      */
     public void init(
@@ -45,12 +45,7 @@ public class RSAEngine
 
         if (forEncryption)
         {
-            if ((bitSize % 8) == 0)
-            {
-                return bitSize / 8 - 1;
-            }
-
-            return bitSize / 8;
+            return (bitSize + 7) / 8 - 1;
         }
         else
         {
@@ -63,7 +58,7 @@ public class RSAEngine
      * For RSA this is always one byte less than the key size on
      * decryption, and the same length as the key size on encryption.
      *
-     * @return maximum size for an input block.
+     * @return maximum size for an output block.
      */
     public int getOutputBlockSize()
     {
@@ -71,11 +66,11 @@ public class RSAEngine
 
         if (forEncryption)
         {
-            return ((bitSize - 1) + 7) / 8;
+            return (bitSize + 7) / 8;
         }
         else
         {
-            return (bitSize - 7) / 8;
+            return (bitSize + 7) / 8 - 1;
         }
     }