summary refs log tree commit diff
path: root/crypto/src/security
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-09-12 13:37:38 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-09-12 13:37:38 +0700
commit1298385506df2df9f8fd9c1ceacfaf952e02fd5d (patch)
tree5725137d5bdd744127a7cb91f7822949f85cbf7d /crypto/src/security
parentAdd basic support for JKS keystores (diff)
downloadBouncyCastle.NET-ed25519-1298385506df2df9f8fd9c1ceacfaf952e02fd5d.tar.xz
Separate out new IBlockCipherMode from IBlockCipher
Diffstat (limited to 'crypto/src/security')
-rw-r--r--crypto/src/security/CipherUtilities.cs32
1 files changed, 19 insertions, 13 deletions
diff --git a/crypto/src/security/CipherUtilities.cs b/crypto/src/security/CipherUtilities.cs
index 8ed5d8d41..929040e2c 100644
--- a/crypto/src/security/CipherUtilities.cs
+++ b/crypto/src/security/CipherUtilities.cs
@@ -620,6 +620,7 @@ namespace Org.BouncyCastle.Security
             }
 
             string mode = "";
+            IBlockCipherMode blockCipherMode = null;
             if (parts.Length > 1)
             {
                 mode = parts[1];
@@ -639,7 +640,7 @@ namespace Org.BouncyCastle.Security
                     case CipherMode.NONE:
                         break;
                     case CipherMode.CBC:
-                        blockCipher = new CbcBlockCipher(blockCipher);
+                        blockCipherMode = new CbcBlockCipher(blockCipher);
                         break;
                     case CipherMode.CCM:
                         aeadBlockCipher = new CcmBlockCipher(blockCipher);
@@ -650,15 +651,15 @@ namespace Org.BouncyCastle.Security
                             ?	8 * blockCipher.GetBlockSize()
                             :	int.Parse(mode.Substring(di));
     
-                        blockCipher = new CfbBlockCipher(blockCipher, bits);
+                        blockCipherMode = new CfbBlockCipher(blockCipher, bits);
                         break;
                     }
                     case CipherMode.CTR:
-                        blockCipher = new SicBlockCipher(blockCipher);
+                        blockCipherMode = new SicBlockCipher(blockCipher);
                         break;
                     case CipherMode.CTS:
                         cts = true;
-                        blockCipher = new CbcBlockCipher(blockCipher);
+                        blockCipherMode = new CbcBlockCipher(blockCipher);
                         break;
                     case CipherMode.EAX:
                         aeadBlockCipher = new EaxBlockCipher(blockCipher);
@@ -667,7 +668,7 @@ namespace Org.BouncyCastle.Security
                         aeadBlockCipher = new GcmBlockCipher(blockCipher);
                         break;
                     case CipherMode.GOFB:
-                        blockCipher = new GOfbBlockCipher(blockCipher);
+                        blockCipherMode = new GOfbBlockCipher(blockCipher);
                         break;
                     case CipherMode.OCB:
                         aeadBlockCipher = new OcbBlockCipher(blockCipher, CreateBlockCipher(cipherAlgorithm));
@@ -678,18 +679,18 @@ namespace Org.BouncyCastle.Security
                             ?	8 * blockCipher.GetBlockSize()
                             :	int.Parse(mode.Substring(di));
     
-                        blockCipher = new OfbBlockCipher(blockCipher, bits);
+                        blockCipherMode = new OfbBlockCipher(blockCipher, bits);
                         break;
                     }
                     case CipherMode.OPENPGPCFB:
-                        blockCipher = new OpenPgpCfbBlockCipher(blockCipher);
+                        blockCipherMode = new OpenPgpCfbBlockCipher(blockCipher);
                         break;
                     case CipherMode.SIC:
                         if (blockCipher.GetBlockSize() < 16)
                         {
                             throw new ArgumentException("Warning: SIC-Mode can become a twotime-pad if the blocksize of the cipher is too small. Use a cipher with a block size of at least 128 bits (e.g. AES)");
                         }
-                        blockCipher = new SicBlockCipher(blockCipher);
+                        blockCipherMode = new SicBlockCipher(blockCipher);
                         break;
                     default:
                         throw new SecurityUtilityException("Cipher " + algorithm + " not recognised.");
@@ -713,22 +714,27 @@ namespace Org.BouncyCastle.Security
 
             if (blockCipher != null)
             {
+                if (blockCipherMode == null)
+                {
+                    blockCipherMode = EcbBlockCipher.GetBlockCipherMode(blockCipher);
+                }
+
                 if (cts)
                 {
-                    return new CtsBlockCipher(blockCipher);
+                    return new CtsBlockCipher(blockCipherMode);
                 }
 
                 if (padding != null)
                 {
-                    return new PaddedBufferedBlockCipher(blockCipher, padding);
+                    return new PaddedBufferedBlockCipher(blockCipherMode, padding);
                 }
 
-                if (!padded || blockCipher.IsPartialBlockOkay)
+                if (!padded || blockCipherMode.IsPartialBlockOkay)
                 {
-                    return new BufferedBlockCipher(blockCipher);
+                    return new BufferedBlockCipher(blockCipherMode);
                 }
 
-                return new PaddedBufferedBlockCipher(blockCipher);
+                return new PaddedBufferedBlockCipher(blockCipherMode);
             }
 
             if (asymBlockCipher != null)