|
1 | 1 | using System.Buffers.Binary; |
2 | 2 | using System.Runtime.CompilerServices; |
| 3 | +using System.Runtime.Intrinsics.Arm; |
3 | 4 | using System.Runtime.Intrinsics.X86; |
4 | 5 | using System.Security.Cryptography; |
5 | 6 |
|
@@ -152,23 +153,22 @@ private unsafe void TransformBlockHardware(ReadOnlySpan<byte> input, Span<byte> |
152 | 153 | } |
153 | 154 | else if (System.Runtime.Intrinsics.Arm.Aes.IsSupported) |
154 | 155 | { |
155 | | - /*var block = AdvSimd.LoadVector128(pInput); |
156 | | - var state = AdvSimd.LoadVector128(pRoundKey); |
| 156 | + var state = AdvSimd.LoadVector128(pInput); |
157 | 157 |
|
158 | | - state = AdvSimd.Xor(block, state); |
159 | | -
|
160 | | - for (int round = 1; round < Nr; round++) |
| 158 | + for (int round = 0; round < Nr - 1; round++) |
161 | 159 | { |
162 | 160 | var roundKey = AdvSimd.LoadVector128(pRoundKey + round * BlockSize); |
163 | 161 | state = System.Runtime.Intrinsics.Arm.Aes.Encrypt(state, roundKey); |
164 | 162 | state = System.Runtime.Intrinsics.Arm.Aes.MixColumns(state); |
165 | 163 | } |
166 | 164 |
|
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); |
169 | 170 |
|
170 | | - AdvSimd.Store(pOutput, state);*/ |
171 | | - TransformBlockSoftware(input, output); // Fallback to software implementation if ARM AES is not supported |
| 171 | + AdvSimd.Store(pOutput, state); |
172 | 172 | } |
173 | 173 | else |
174 | 174 | { |
|
0 commit comments