Eliminate byte[] allocation in RC4

This commit is contained in:
Jason Nelson 2024-04-01 21:46:06 -07:00 committed by BobLd
parent fba5b60718
commit ce5dc7c1a1

View File

@ -7,7 +7,7 @@
public static byte[] Encrypt(ReadOnlySpan<byte> key, ReadOnlySpan<byte> data) public static byte[] Encrypt(ReadOnlySpan<byte> key, ReadOnlySpan<byte> data)
{ {
// Key-scheduling algorithm // Key-scheduling algorithm
var s = new byte[256]; Span<byte> s = stackalloc byte[256];
for (var i = 0; i < 256; i++) for (var i = 0; i < 256; i++)
{ {
s[i] = (byte)i; s[i] = (byte)i;