Skip to content

Commit 1ee8702

Browse files
committed
refactor: Xor
1 parent 8874e26 commit 1ee8702

File tree

1 file changed

+1
-41
lines changed

1 file changed

+1
-41
lines changed

src/CryptoBase/IntrinsicsUtils.cs

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -67,51 +67,11 @@ public static Vector128<T> RotateLeftUInt32_24<T>(this Vector128<T> value) where
6767

6868
/// <summary>
6969
/// destination = source ^ stream
70-
/// TODO: Remove
7170
/// </summary>
7271
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
7372
public static unsafe void Xor(byte* stream, byte* source, byte* destination, int length)
7473
{
75-
while (length >= 64)
76-
{
77-
Vector512<byte> v0 = Vector512.Load(stream);
78-
Vector512<byte> v1 = Vector512.Load(source);
79-
(v0 ^ v1).Store(destination);
80-
81-
stream += 64;
82-
source += 64;
83-
destination += 64;
84-
length -= 64;
85-
}
86-
87-
if (length >= 32)
88-
{
89-
Vector256<byte> v0 = Vector256.Load(stream);
90-
Vector256<byte> v1 = Vector256.Load(source);
91-
(v0 ^ v1).Store(destination);
92-
93-
stream += 32;
94-
source += 32;
95-
destination += 32;
96-
length -= 32;
97-
}
98-
99-
if (length >= 16)
100-
{
101-
Vector128<byte> v0 = Vector128.Load(stream);
102-
Vector128<byte> v1 = Vector128.Load(source);
103-
(v0 ^ v1).Store(destination);
104-
105-
stream += 16;
106-
source += 16;
107-
destination += 16;
108-
length -= 16;
109-
}
110-
111-
for (int i = 0; i < length; ++i)
112-
{
113-
*(destination + i) = (byte)(*(source + i) ^ *(stream + i));
114-
}
74+
FastUtils.Xor(new ReadOnlySpan<byte>(stream, length), new ReadOnlySpan<byte>(source, length), new Span<byte>(destination, length), length);
11575
}
11676

11777
[MethodImpl(MethodImplOptions.AggressiveInlining)]

0 commit comments

Comments
 (0)