Skip to content

Commit b324061

Browse files
committed
[Core] Implement SIMD for AesGcm in ARMv8
1 parent 9a8bcd2 commit b324061

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

Lagrange.Core/Utility/Cryptography/AesGcmProvider.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Buffers.Binary;
22
using System.Runtime.CompilerServices;
3+
using System.Runtime.Intrinsics.Arm;
34
using System.Runtime.Intrinsics.X86;
45
using System.Security.Cryptography;
56

@@ -152,23 +153,22 @@ private unsafe void TransformBlockHardware(ReadOnlySpan<byte> input, Span<byte>
152153
}
153154
else if (System.Runtime.Intrinsics.Arm.Aes.IsSupported)
154155
{
155-
/*var block = AdvSimd.LoadVector128(pInput);
156-
var state = AdvSimd.LoadVector128(pRoundKey);
156+
var state = AdvSimd.LoadVector128(pInput);
157157

158-
state = AdvSimd.Xor(block, state);
159-
160-
for (int round = 1; round < Nr; round++)
158+
for (int round = 0; round < Nr - 1; round++)
161159
{
162160
var roundKey = AdvSimd.LoadVector128(pRoundKey + round * BlockSize);
163161
state = System.Runtime.Intrinsics.Arm.Aes.Encrypt(state, roundKey);
164162
state = System.Runtime.Intrinsics.Arm.Aes.MixColumns(state);
165163
}
166164

167-
var lastRoundKey = AdvSimd.LoadVector128(pRoundKey + Nr * BlockSize);
168-
state = System.Runtime.Intrinsics.Arm.Aes.Encrypt(state, lastRoundKey);
165+
var penultimateKey = AdvSimd.LoadVector128(pRoundKey + (Nr - 1) * BlockSize);
166+
state = System.Runtime.Intrinsics.Arm.Aes.Encrypt(state, penultimateKey);
167+
168+
var lastKey = AdvSimd.LoadVector128(pRoundKey + Nr * BlockSize);
169+
state = AdvSimd.Xor(state, lastKey);
169170

170-
AdvSimd.Store(pOutput, state);*/
171-
TransformBlockSoftware(input, output); // Fallback to software implementation if ARM AES is not supported
171+
AdvSimd.Store(pOutput, state);
172172
}
173173
else
174174
{

0 commit comments

Comments
 (0)