diff --git a/crypto/src/crypto/engines/ChaChaEngine.cs b/crypto/src/crypto/engines/ChaChaEngine.cs
index 8720504cd..a97c04e08 100644
--- a/crypto/src/crypto/engines/ChaChaEngine.cs
+++ b/crypto/src/crypto/engines/ChaChaEngine.cs
@@ -1,6 +1,7 @@
using System;
using Org.BouncyCastle.Crypto.Utilities;
+using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Crypto.Engines
{
@@ -102,38 +103,38 @@ namespace Org.BouncyCastle.Crypto.Engines
for (int i = rounds; i > 0; i -= 2)
{
- x00 += x04; x12 = R(x12 ^ x00, 16);
- x08 += x12; x04 = R(x04 ^ x08, 12);
- x00 += x04; x12 = R(x12 ^ x00, 8);
- x08 += x12; x04 = R(x04 ^ x08, 7);
- x01 += x05; x13 = R(x13 ^ x01, 16);
- x09 += x13; x05 = R(x05 ^ x09, 12);
- x01 += x05; x13 = R(x13 ^ x01, 8);
- x09 += x13; x05 = R(x05 ^ x09, 7);
- x02 += x06; x14 = R(x14 ^ x02, 16);
- x10 += x14; x06 = R(x06 ^ x10, 12);
- x02 += x06; x14 = R(x14 ^ x02, 8);
- x10 += x14; x06 = R(x06 ^ x10, 7);
- x03 += x07; x15 = R(x15 ^ x03, 16);
- x11 += x15; x07 = R(x07 ^ x11, 12);
- x03 += x07; x15 = R(x15 ^ x03, 8);
- x11 += x15; x07 = R(x07 ^ x11, 7);
- x00 += x05; x15 = R(x15 ^ x00, 16);
- x10 += x15; x05 = R(x05 ^ x10, 12);
- x00 += x05; x15 = R(x15 ^ x00, 8);
- x10 += x15; x05 = R(x05 ^ x10, 7);
- x01 += x06; x12 = R(x12 ^ x01, 16);
- x11 += x12; x06 = R(x06 ^ x11, 12);
- x01 += x06; x12 = R(x12 ^ x01, 8);
- x11 += x12; x06 = R(x06 ^ x11, 7);
- x02 += x07; x13 = R(x13 ^ x02, 16);
- x08 += x13; x07 = R(x07 ^ x08, 12);
- x02 += x07; x13 = R(x13 ^ x02, 8);
- x08 += x13; x07 = R(x07 ^ x08, 7);
- x03 += x04; x14 = R(x14 ^ x03, 16);
- x09 += x14; x04 = R(x04 ^ x09, 12);
- x03 += x04; x14 = R(x14 ^ x03, 8);
- x09 += x14; x04 = R(x04 ^ x09, 7);
+ x00 += x04; x12 = Integers.RotateLeft(x12 ^ x00, 16);
+ x08 += x12; x04 = Integers.RotateLeft(x04 ^ x08, 12);
+ x00 += x04; x12 = Integers.RotateLeft(x12 ^ x00, 8);
+ x08 += x12; x04 = Integers.RotateLeft(x04 ^ x08, 7);
+ x01 += x05; x13 = Integers.RotateLeft(x13 ^ x01, 16);
+ x09 += x13; x05 = Integers.RotateLeft(x05 ^ x09, 12);
+ x01 += x05; x13 = Integers.RotateLeft(x13 ^ x01, 8);
+ x09 += x13; x05 = Integers.RotateLeft(x05 ^ x09, 7);
+ x02 += x06; x14 = Integers.RotateLeft(x14 ^ x02, 16);
+ x10 += x14; x06 = Integers.RotateLeft(x06 ^ x10, 12);
+ x02 += x06; x14 = Integers.RotateLeft(x14 ^ x02, 8);
+ x10 += x14; x06 = Integers.RotateLeft(x06 ^ x10, 7);
+ x03 += x07; x15 = Integers.RotateLeft(x15 ^ x03, 16);
+ x11 += x15; x07 = Integers.RotateLeft(x07 ^ x11, 12);
+ x03 += x07; x15 = Integers.RotateLeft(x15 ^ x03, 8);
+ x11 += x15; x07 = Integers.RotateLeft(x07 ^ x11, 7);
+ x00 += x05; x15 = Integers.RotateLeft(x15 ^ x00, 16);
+ x10 += x15; x05 = Integers.RotateLeft(x05 ^ x10, 12);
+ x00 += x05; x15 = Integers.RotateLeft(x15 ^ x00, 8);
+ x10 += x15; x05 = Integers.RotateLeft(x05 ^ x10, 7);
+ x01 += x06; x12 = Integers.RotateLeft(x12 ^ x01, 16);
+ x11 += x12; x06 = Integers.RotateLeft(x06 ^ x11, 12);
+ x01 += x06; x12 = Integers.RotateLeft(x12 ^ x01, 8);
+ x11 += x12; x06 = Integers.RotateLeft(x06 ^ x11, 7);
+ x02 += x07; x13 = Integers.RotateLeft(x13 ^ x02, 16);
+ x08 += x13; x07 = Integers.RotateLeft(x07 ^ x08, 12);
+ x02 += x07; x13 = Integers.RotateLeft(x13 ^ x02, 8);
+ x08 += x13; x07 = Integers.RotateLeft(x07 ^ x08, 7);
+ x03 += x04; x14 = Integers.RotateLeft(x14 ^ x03, 16);
+ x09 += x14; x04 = Integers.RotateLeft(x04 ^ x09, 12);
+ x03 += x04; x14 = Integers.RotateLeft(x14 ^ x03, 8);
+ x09 += x14; x04 = Integers.RotateLeft(x04 ^ x09, 7);
}
x[ 0] = x00 + input[ 0];
diff --git a/crypto/src/crypto/engines/Salsa20Engine.cs b/crypto/src/crypto/engines/Salsa20Engine.cs
index 182eacd71..056fc09eb 100644
--- a/crypto/src/crypto/engines/Salsa20Engine.cs
+++ b/crypto/src/crypto/engines/Salsa20Engine.cs
@@ -254,39 +254,39 @@ namespace Org.BouncyCastle.Crypto.Engines
for (int i = rounds; i > 0; i -= 2)
{
- x04 ^= R((x00+x12), 7);
- x08 ^= R((x04+x00), 9);
- x12 ^= R((x08+x04),13);
- x00 ^= R((x12+x08),18);
- x09 ^= R((x05+x01), 7);
- x13 ^= R((x09+x05), 9);
- x01 ^= R((x13+x09),13);
- x05 ^= R((x01+x13),18);
- x14 ^= R((x10+x06), 7);
- x02 ^= R((x14+x10), 9);
- x06 ^= R((x02+x14),13);
- x10 ^= R((x06+x02),18);
- x03 ^= R((x15+x11), 7);
- x07 ^= R((x03+x15), 9);
- x11 ^= R((x07+x03),13);
- x15 ^= R((x11+x07),18);
-
- x01 ^= R((x00+x03), 7);
- x02 ^= R((x01+x00), 9);
- x03 ^= R((x02+x01),13);
- x00 ^= R((x03+x02),18);
- x06 ^= R((x05+x04), 7);
- x07 ^= R((x06+x05), 9);
- x04 ^= R((x07+x06),13);
- x05 ^= R((x04+x07),18);
- x11 ^= R((x10+x09), 7);
- x08 ^= R((x11+x10), 9);
- x09 ^= R((x08+x11),13);
- x10 ^= R((x09+x08),18);
- x12 ^= R((x15+x14), 7);
- x13 ^= R((x12+x15), 9);
- x14 ^= R((x13+x12),13);
- x15 ^= R((x14+x13),18);
+ x04 ^= Integers.RotateLeft((x00+x12), 7);
+ x08 ^= Integers.RotateLeft((x04+x00), 9);
+ x12 ^= Integers.RotateLeft((x08+x04),13);
+ x00 ^= Integers.RotateLeft((x12+x08),18);
+ x09 ^= Integers.RotateLeft((x05+x01), 7);
+ x13 ^= Integers.RotateLeft((x09+x05), 9);
+ x01 ^= Integers.RotateLeft((x13+x09),13);
+ x05 ^= Integers.RotateLeft((x01+x13),18);
+ x14 ^= Integers.RotateLeft((x10+x06), 7);
+ x02 ^= Integers.RotateLeft((x14+x10), 9);
+ x06 ^= Integers.RotateLeft((x02+x14),13);
+ x10 ^= Integers.RotateLeft((x06+x02),18);
+ x03 ^= Integers.RotateLeft((x15+x11), 7);
+ x07 ^= Integers.RotateLeft((x03+x15), 9);
+ x11 ^= Integers.RotateLeft((x07+x03),13);
+ x15 ^= Integers.RotateLeft((x11+x07),18);
+
+ x01 ^= Integers.RotateLeft((x00+x03), 7);
+ x02 ^= Integers.RotateLeft((x01+x00), 9);
+ x03 ^= Integers.RotateLeft((x02+x01),13);
+ x00 ^= Integers.RotateLeft((x03+x02),18);
+ x06 ^= Integers.RotateLeft((x05+x04), 7);
+ x07 ^= Integers.RotateLeft((x06+x05), 9);
+ x04 ^= Integers.RotateLeft((x07+x06),13);
+ x05 ^= Integers.RotateLeft((x04+x07),18);
+ x11 ^= Integers.RotateLeft((x10+x09), 7);
+ x08 ^= Integers.RotateLeft((x11+x10), 9);
+ x09 ^= Integers.RotateLeft((x08+x11),13);
+ x10 ^= Integers.RotateLeft((x09+x08),18);
+ x12 ^= Integers.RotateLeft((x15+x14), 7);
+ x13 ^= Integers.RotateLeft((x12+x15), 9);
+ x14 ^= Integers.RotateLeft((x13+x12),13);
+ x15 ^= Integers.RotateLeft((x14+x13),18);
}
x[ 0] = x00 + input[ 0];
@@ -307,19 +307,6 @@ namespace Org.BouncyCastle.Crypto.Engines
x[15] = x15 + input[15];
}
- /**
- * Rotate left
- *
- * @param x value to rotate
- * @param y amount to rotate x
- *
- * @return rotated x
- */
- internal static uint R(uint x, int y)
- {
- return (x << y) | (x >> (32 - y));
- }
-
private void ResetLimitCounter()
{
cW0 = 0;
|