summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2019-07-29 22:29:43 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2019-07-29 22:29:43 +0700
commit3d27c78a8822120ce09328304b98895845ee4f88 (patch)
tree22c2b6d5c44da829facbdb723929e66e3e99871a
parentRemove unused imports (diff)
downloadBouncyCastle.NET-ed25519-3d27c78a8822120ce09328304b98895845ee4f88.tar.xz
Make main SMix array 1-dimensional
-rw-r--r--crypto/src/crypto/generators/SCrypt.cs28
1 files changed, 16 insertions, 12 deletions
diff --git a/crypto/src/crypto/generators/SCrypt.cs b/crypto/src/crypto/generators/SCrypt.cs
index 4d15bb3d7..51dc50b81 100644
--- a/crypto/src/crypto/generators/SCrypt.cs
+++ b/crypto/src/crypto/generators/SCrypt.cs
@@ -98,31 +98,37 @@ namespace Org.BouncyCastle.Crypto.Generators
 			uint[] blockY = new uint[BCount];
 
 			uint[] X = new uint[BCount];
-			uint[][] V = new uint[N][];
+            uint[] V = new uint[N * BCount];
 
 			try
 			{
 				Array.Copy(B, BOff, X, 0, BCount);
 
-				for (int i = 0; i < N; ++i)
-				{
-					V[i] = (uint[])X.Clone();
-					BlockMix(X, blockX1, blockX2, blockY, r);
-				}
+                int off = 0;
+                for (int i = 0; i < N; i += 2)
+                {
+                    Array.Copy(X, 0, V, off, BCount);
+                    off += BCount;
+                    BlockMix(X, blockX1, blockX2, blockY, r);
+                    Array.Copy(blockY, 0, V, off, BCount);
+                    off += BCount;
+                    BlockMix(blockY, blockX1, blockX2, X, r);
+                }
 
 				uint mask = (uint)N - 1;
 				for (int i = 0; i < N; ++i)
 				{
 					uint j = X[BCount - 16] & mask;
-					Xor(X, V[j], 0, X);
-					BlockMix(X, blockX1, blockX2, blockY, r);
-				}
+                    Array.Copy(V, j * BCount, blockY, 0, BCount);
+                    Xor(blockY, X, 0, blockY);
+                    BlockMix(blockY, blockX1, blockX2, X, r);
+                }
 
 				Array.Copy(X, 0, B, BOff, BCount);
 			}
 			finally
 			{
-				ClearAll(V);
+				Clear(V);
 				ClearAll(X, blockX1, blockX2, blockY);
 			}
 		}
@@ -143,8 +149,6 @@ namespace Org.BouncyCastle.Crypto.Generators
 				YOff = halfLen + BOff - YOff;
 				BOff += 16;
 			}
-
-			Array.Copy(Y, 0, B, 0, Y.Length);
 		}
 
 		private static void Xor(uint[] a, uint[] b, int bOff, uint[] output)