Skip to content

Commit

Permalink
Use intrinsic to rotate left in Magma
Browse files Browse the repository at this point in the history
  • Loading branch information
sergezhigunov committed Dec 2, 2024
1 parent 9009e39 commit 70f3968
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/OpenGost.Security.Cryptography/MagmaManagedTransform.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.CompilerServices;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Security;

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

private static uint RotateElevenBitsLeft(uint input)
{
return input << 11 | input >> 21;
}

[SecurityCritical]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static unsafe uint SubstituteAndRotateElevenBits(uint data, uint* lookup0, uint* lookup1, uint* lookup2, uint* lookup3)
Expand Down Expand Up @@ -198,6 +194,8 @@ private static unsafe void InitializeSubstituteAndRotateElevenBits(
int b,
int shift)
{
lookup[b] = RotateElevenBitsLeft((sbox1[b & 0x0f] ^ (uint)sbox2[b >> 4] << 4) << shift);
lookup[b] = BitOperations.RotateLeft(
offset: 11,
value: (sbox1[b & 0x0f] ^ (uint)sbox2[b >> 4] << 4) << shift);
}
}

0 comments on commit 70f3968

Please sign in to comment.