summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-11-23 21:13:36 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-11-23 21:13:36 +0700
commit91424cfd47d68b7a1c76ac6109e332b8085bdc12 (patch)
tree6e7dee01406efb9ce62bdcca31ccaae557a16fd5
parentUse FixedTimeEquals (diff)
downloadBouncyCastle.NET-ed25519-91424cfd47d68b7a1c76ac6109e332b8085bdc12.tar.xz
Refactoring DesEdeWrapEngine
-rw-r--r--crypto/src/crypto/engines/DesEdeWrapEngine.cs33
1 files changed, 10 insertions, 23 deletions
diff --git a/crypto/src/crypto/engines/DesEdeWrapEngine.cs b/crypto/src/crypto/engines/DesEdeWrapEngine.cs
index c1f93eef9..6832ab9d6 100644
--- a/crypto/src/crypto/engines/DesEdeWrapEngine.cs
+++ b/crypto/src/crypto/engines/DesEdeWrapEngine.cs
@@ -159,7 +159,7 @@ namespace Org.BouncyCastle.Crypto.Engines
             Array.Copy(TEMP1, 0, TEMP2, this.iv.Length, TEMP1.Length);
 
             // Reverse the order of the octets in TEMP2 and call the result TEMP3.
-            byte[] TEMP3 = reverse(TEMP2);
+            Array.Reverse(TEMP2);
 
 			// Encrypt TEMP3 in CBC mode using the KEK and an initialization vector
             // of 0x 4a dd a2 2c 79 e8 21 05. The resulting cipher text is the desired
@@ -167,12 +167,12 @@ namespace Org.BouncyCastle.Crypto.Engines
             ParametersWithIV param2 = new ParametersWithIV(this.param, IV2);
             this.engine.Init(true, param2);
 
-            for (int currentBytePos = 0; currentBytePos != TEMP3.Length; currentBytePos += blockSize)
+            for (int currentBytePos = 0; currentBytePos != TEMP2.Length; currentBytePos += blockSize)
 			{
-                engine.ProcessBlock(TEMP3, currentBytePos, TEMP3, currentBytePos);
+                engine.ProcessBlock(TEMP2, currentBytePos, TEMP2, currentBytePos);
             }
 
-            return TEMP3;
+            return TEMP2;
         }
 
 		/**
@@ -225,15 +225,15 @@ namespace Org.BouncyCastle.Crypto.Engines
             ParametersWithIV param2 = new ParametersWithIV(this.param, IV2);
             this.engine.Init(false, param2);
 
-            byte [] TEMP3 = new byte[length];
+            byte [] TEMP2 = new byte[length];
 
-			for (int currentBytePos = 0; currentBytePos != TEMP3.Length; currentBytePos += blockSize)
+			for (int currentBytePos = 0; currentBytePos != TEMP2.Length; currentBytePos += blockSize)
 			{
-				engine.ProcessBlock(input, inOff + currentBytePos, TEMP3, currentBytePos);
+				engine.ProcessBlock(input, inOff + currentBytePos, TEMP2, currentBytePos);
             }
 
             // Reverse the order of the octets in TEMP3 and call the result TEMP2.
-            byte[] TEMP2 = reverse(TEMP3);
+            Array.Reverse(TEMP2);
 
 			// Decompose TEMP2 into IV, the first 8 octets, and TEMP1, the remaining octets.
             this.iv = new byte[8];
@@ -284,8 +284,7 @@ namespace Org.BouncyCastle.Crypto.Engines
         * @throws Exception
         * @see http://www.w3.org/TR/xmlenc-core/#sec-CMSKeyChecksum
         */
-        private byte[] CalculateCmsKeyChecksum(
-            byte[] key)
+        private byte[] CalculateCmsKeyChecksum(byte[] key)
         {
 			sha1.BlockUpdate(key, 0, key.Length);
             sha1.DoFinal(digest, 0);
@@ -301,21 +300,9 @@ namespace Org.BouncyCastle.Crypto.Engines
         * @return
         * @see http://www.w3.org/TR/xmlenc-core/#sec-CMSKeyChecksum
         */
-        private bool CheckCmsKeyChecksum(
-            byte[]	key,
-            byte[]	checksum)
+        private bool CheckCmsKeyChecksum(byte[]	key, byte[]	checksum)
         {
 			return Arrays.FixedTimeEquals(CalculateCmsKeyChecksum(key), checksum);
         }
-
-		private static byte[] reverse(byte[] bs)
-		{
-			byte[] result = new byte[bs.Length];
-			for (int i = 0; i < bs.Length; i++) 
-			{
-				result[i] = bs[bs.Length - (i + 1)];
-			}
-			return result;
-		}
     }
 }