Skip to content

Commit 70f3968

Browse files
committed
Use intrinsic to rotate left in Magma
1 parent 9009e39 commit 70f3968

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/OpenGost.Security.Cryptography/MagmaManagedTransform.cs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.CompilerServices;
1+
using System.Numerics;
2+
using System.Runtime.CompilerServices;
23
using System.Security;
34

45
namespace OpenGost.Security.Cryptography;
@@ -134,11 +135,6 @@ private static unsafe void ComputeEightRoundsBackwardKeyOrder(uint* k, uint* loo
134135
a0 ^= SubstituteAndRotateElevenBits(a1 + k[0], lookup0, lookup1, lookup2, lookup3);
135136
}
136137

137-
private static uint RotateElevenBitsLeft(uint input)
138-
{
139-
return input << 11 | input >> 21;
140-
}
141-
142138
[SecurityCritical]
143139
[MethodImpl(MethodImplOptions.AggressiveInlining)]
144140
private static unsafe uint SubstituteAndRotateElevenBits(uint data, uint* lookup0, uint* lookup1, uint* lookup2, uint* lookup3)
@@ -198,6 +194,8 @@ private static unsafe void InitializeSubstituteAndRotateElevenBits(
198194
int b,
199195
int shift)
200196
{
201-
lookup[b] = RotateElevenBitsLeft((sbox1[b & 0x0f] ^ (uint)sbox2[b >> 4] << 4) << shift);
197+
lookup[b] = BitOperations.RotateLeft(
198+
offset: 11,
199+
value: (sbox1[b & 0x0f] ^ (uint)sbox2[b >> 4] << 4) << shift);
202200
}
203201
}

0 commit comments

Comments
 (0)