This commit is contained in:
BruceChen 2022-08-28 13:18:07 +08:00
parent 842c968220
commit 4757c4be53
8 changed files with 97 additions and 189 deletions

View file

@ -8,17 +8,24 @@ namespace MinecraftClient.Crypto
{
// Using the AES-NI instruction set
// https://gist.github.com/Thealexbarney/9f75883786a9f3100408ff795fb95d85
public class AesContext
public class FastAes
{
private Vector128<byte>[] RoundKeys { get; }
public byte[] Iv { get; } = new byte[0x10];
public AesContext(Span<byte> key)
public FastAes(Span<byte> key)
{
RoundKeys = KeyExpansion(key);
}
/// <summary>
/// Detects if the required instruction set is supported
/// </summary>
/// <returns>Is it supported</returns>
public static bool IsSupport()
{
return Sse2.IsSupported && Aes.IsSupported;
}
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public void EncryptEcb(ReadOnlySpan<byte> plaintext, Span<byte> destination)
{
@ -88,10 +95,5 @@ namespace MinecraftClient.Crypto
keys[i] = Sse2.Xor(s, t);
}
public void SetIv(Span<byte> iv)
{
iv.Slice(0, 0x10).CopyTo(Iv);
}
}
}
}