From 3395ebff44e99f9a31ce56c102008f16f70fd178 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sat, 23 Nov 2019 20:05:05 -0600 Subject: [PATCH] Improve AES key expansion performance --- src/LibHac/Crypto/Detail/AesCoreNi.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/LibHac/Crypto/Detail/AesCoreNi.cs b/src/LibHac/Crypto/Detail/AesCoreNi.cs index 554d2681..f1b65481 100644 --- a/src/LibHac/Crypto/Detail/AesCoreNi.cs +++ b/src/LibHac/Crypto/Detail/AesCoreNi.cs @@ -22,7 +22,7 @@ namespace LibHac.Crypto.Detail { Debug.Assert(key.Length == Aes.KeySize128); - KeyExpansion(key, MemoryMarshal.CreateSpan(ref _roundKeys, RoundKeyCount), isDecrypting); + KeyExpansion(key, isDecrypting); } public readonly ReadOnlySpan> RoundKeys => @@ -447,8 +447,10 @@ namespace LibHac.Crypto.Detail out7 = AesNi.DecryptLast(b7, key); } - private static void KeyExpansion(ReadOnlySpan key, Span> roundKeys, bool isDecrypting) + private void KeyExpansion(ReadOnlySpan key, bool isDecrypting) { + Span> roundKeys = MemoryMarshal.CreateSpan(ref _roundKeys, RoundKeyCount); + var curKey = Unsafe.ReadUnaligned>(ref MemoryMarshal.GetReference(key)); roundKeys[0] = curKey;