diff --git a/src/LibHac/Crypto2/Aes.cs b/src/LibHac/Crypto2/Aes.cs index 5f2a5f44..455b345d 100644 --- a/src/LibHac/Crypto2/Aes.cs +++ b/src/LibHac/Crypto2/Aes.cs @@ -2,13 +2,14 @@ using System; #if HAS_INTRINSICS -using System.Runtime.Intrinsics.X86; using LibHac.Crypto2.Detail; + +using AesNi = System.Runtime.Intrinsics.X86.Aes; #endif namespace LibHac.Crypto2 { - public static class AesCrypto + public static class Aes { public const int KeySize128 = 0x10; public const int BlockSize = 0x10; @@ -16,7 +17,7 @@ namespace LibHac.Crypto2 public static bool IsAesNiSupported() { #if HAS_INTRINSICS - return Aes.IsSupported; + return AesNi.IsSupported; #else return false; #endif diff --git a/src/LibHac/Crypto2/Detail/AesCbcModeNi.cs b/src/LibHac/Crypto2/Detail/AesCbcModeNi.cs index 6f9c0bf7..f69bd8f9 100644 --- a/src/LibHac/Crypto2/Detail/AesCbcModeNi.cs +++ b/src/LibHac/Crypto2/Detail/AesCbcModeNi.cs @@ -1,5 +1,6 @@ #if HAS_INTRINSICS using System; +using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; @@ -17,6 +18,8 @@ namespace LibHac.Crypto2.Detail public void Initialize(ReadOnlySpan key, ReadOnlySpan iv, bool isDecrypting) { + Debug.Assert(iv.Length == Aes.BlockSize); + _aesCore.Initialize(key, isDecrypting); _iv = Unsafe.ReadUnaligned>(ref MemoryMarshal.GetReference(iv)); diff --git a/src/LibHac/Crypto2/Detail/AesCore.cs b/src/LibHac/Crypto2/Detail/AesCore.cs index 9f1bc2f0..4df0e3f2 100644 --- a/src/LibHac/Crypto2/Detail/AesCore.cs +++ b/src/LibHac/Crypto2/Detail/AesCore.cs @@ -12,10 +12,10 @@ namespace LibHac.Crypto2.Detail public void Initialize(ReadOnlySpan key, ReadOnlySpan iv, CipherMode mode, bool isDecrypting) { - Debug.Assert(key.Length == AesCrypto.KeySize128); - Debug.Assert(iv.IsEmpty || iv.Length == AesCrypto.BlockSize); + Debug.Assert(key.Length == Aes.KeySize128); + Debug.Assert(iv.IsEmpty || iv.Length == Aes.BlockSize); - Aes aes = Aes.Create(); + System.Security.Cryptography.Aes aes = System.Security.Cryptography.Aes.Create(); if (aes == null) throw new CryptographicException("Unable to create AES object"); aes.Key = key.ToArray(); diff --git a/src/LibHac/Crypto2/Detail/AesCoreNi.cs b/src/LibHac/Crypto2/Detail/AesCoreNi.cs index 2d2a82ae..28dfef6f 100644 --- a/src/LibHac/Crypto2/Detail/AesCoreNi.cs +++ b/src/LibHac/Crypto2/Detail/AesCoreNi.cs @@ -1,9 +1,12 @@ #if NETCOREAPP +using System; +using System.Diagnostics; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; -using System; -using System.Runtime.CompilerServices; + +using AesNi = System.Runtime.Intrinsics.X86.Aes; namespace LibHac.Crypto2.Detail { @@ -17,6 +20,8 @@ namespace LibHac.Crypto2.Detail public void Initialize(ReadOnlySpan key, bool isDecrypting) { + Debug.Assert(key.Length == Aes.KeySize128); + KeyExpansion(key, MemoryMarshal.CreateSpan(ref _roundKeys, RoundKeyCount), isDecrypting); } @@ -63,16 +68,16 @@ namespace LibHac.Crypto2.Detail ReadOnlySpan> keys = RoundKeys; Vector128 b = Sse2.Xor(input, keys[0]); - b = Aes.Encrypt(b, keys[1]); - b = Aes.Encrypt(b, keys[2]); - b = Aes.Encrypt(b, keys[3]); - b = Aes.Encrypt(b, keys[4]); - b = Aes.Encrypt(b, keys[5]); - b = Aes.Encrypt(b, keys[6]); - b = Aes.Encrypt(b, keys[7]); - b = Aes.Encrypt(b, keys[8]); - b = Aes.Encrypt(b, keys[9]); - return Aes.EncryptLast(b, keys[10]); + b = AesNi.Encrypt(b, keys[1]); + b = AesNi.Encrypt(b, keys[2]); + b = AesNi.Encrypt(b, keys[3]); + b = AesNi.Encrypt(b, keys[4]); + b = AesNi.Encrypt(b, keys[5]); + b = AesNi.Encrypt(b, keys[6]); + b = AesNi.Encrypt(b, keys[7]); + b = AesNi.Encrypt(b, keys[8]); + b = AesNi.Encrypt(b, keys[9]); + return AesNi.EncryptLast(b, keys[10]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -81,16 +86,16 @@ namespace LibHac.Crypto2.Detail ReadOnlySpan> keys = RoundKeys; Vector128 b = Sse2.Xor(input, keys[10]); - b = Aes.Decrypt(b, keys[9]); - b = Aes.Decrypt(b, keys[8]); - b = Aes.Decrypt(b, keys[7]); - b = Aes.Decrypt(b, keys[6]); - b = Aes.Decrypt(b, keys[5]); - b = Aes.Decrypt(b, keys[4]); - b = Aes.Decrypt(b, keys[3]); - b = Aes.Decrypt(b, keys[2]); - b = Aes.Decrypt(b, keys[1]); - return Aes.DecryptLast(b, keys[0]); + b = AesNi.Decrypt(b, keys[9]); + b = AesNi.Decrypt(b, keys[8]); + b = AesNi.Decrypt(b, keys[7]); + b = AesNi.Decrypt(b, keys[6]); + b = AesNi.Decrypt(b, keys[5]); + b = AesNi.Decrypt(b, keys[4]); + b = AesNi.Decrypt(b, keys[3]); + b = AesNi.Decrypt(b, keys[2]); + b = AesNi.Decrypt(b, keys[1]); + return AesNi.DecryptLast(b, keys[0]); } [MethodImpl(MethodImplOptions.AggressiveOptimization)] @@ -99,41 +104,41 @@ namespace LibHac.Crypto2.Detail var curKey = Unsafe.ReadUnaligned>(ref MemoryMarshal.GetReference(key)); roundKeys[0] = curKey; - curKey = KeyExpansion(curKey, Aes.KeygenAssist(curKey, 0x01)); + curKey = KeyExpansion(curKey, AesNi.KeygenAssist(curKey, 0x01)); roundKeys[1] = curKey; - curKey = KeyExpansion(curKey, Aes.KeygenAssist(curKey, 0x02)); + curKey = KeyExpansion(curKey, AesNi.KeygenAssist(curKey, 0x02)); roundKeys[2] = curKey; - curKey = KeyExpansion(curKey, Aes.KeygenAssist(curKey, 0x04)); + curKey = KeyExpansion(curKey, AesNi.KeygenAssist(curKey, 0x04)); roundKeys[3] = curKey; - curKey = KeyExpansion(curKey, Aes.KeygenAssist(curKey, 0x08)); + curKey = KeyExpansion(curKey, AesNi.KeygenAssist(curKey, 0x08)); roundKeys[4] = curKey; - curKey = KeyExpansion(curKey, Aes.KeygenAssist(curKey, 0x10)); + curKey = KeyExpansion(curKey, AesNi.KeygenAssist(curKey, 0x10)); roundKeys[5] = curKey; - curKey = KeyExpansion(curKey, Aes.KeygenAssist(curKey, 0x20)); + curKey = KeyExpansion(curKey, AesNi.KeygenAssist(curKey, 0x20)); roundKeys[6] = curKey; - curKey = KeyExpansion(curKey, Aes.KeygenAssist(curKey, 0x40)); + curKey = KeyExpansion(curKey, AesNi.KeygenAssist(curKey, 0x40)); roundKeys[7] = curKey; - curKey = KeyExpansion(curKey, Aes.KeygenAssist(curKey, 0x80)); + curKey = KeyExpansion(curKey, AesNi.KeygenAssist(curKey, 0x80)); roundKeys[8] = curKey; - curKey = KeyExpansion(curKey, Aes.KeygenAssist(curKey, 0x1b)); + curKey = KeyExpansion(curKey, AesNi.KeygenAssist(curKey, 0x1b)); roundKeys[9] = curKey; - curKey = KeyExpansion(curKey, Aes.KeygenAssist(curKey, 0x36)); + curKey = KeyExpansion(curKey, AesNi.KeygenAssist(curKey, 0x36)); roundKeys[10] = curKey; if (isDecrypting) { for (int i = 1; i < 10; i++) { - roundKeys[i] = Aes.InverseMixColumns(roundKeys[i]); + roundKeys[i] = AesNi.InverseMixColumns(roundKeys[i]); } } } diff --git a/src/LibHac/Crypto2/Detail/AesCtrMode.cs b/src/LibHac/Crypto2/Detail/AesCtrMode.cs index fc4943ba..300cc80d 100644 --- a/src/LibHac/Crypto2/Detail/AesCtrMode.cs +++ b/src/LibHac/Crypto2/Detail/AesCtrMode.cs @@ -14,7 +14,7 @@ namespace LibHac.Crypto2.Detail public void Initialize(ReadOnlySpan key, ReadOnlySpan iv) { - Debug.Assert(iv.Length == AesCrypto.BlockSize); + Debug.Assert(iv.Length == Aes.BlockSize); _aesCore = new AesCore(); _aesCore.Initialize(key, ReadOnlySpan.Empty, CipherMode.ECB, false); @@ -24,8 +24,8 @@ namespace LibHac.Crypto2.Detail public void Transform(ReadOnlySpan input, Span output) { - int blockCount = Util.DivideByRoundUp(input.Length, AesCrypto.BlockSize); - int length = blockCount * AesCrypto.BlockSize; + int blockCount = Util.DivideByRoundUp(input.Length, Aes.BlockSize); + int length = blockCount * Aes.BlockSize; using var counterBuffer = new RentedArray(length); FillDecryptedCounter(_counter, counterBuffer.Span); diff --git a/src/LibHac/Crypto2/Detail/AesCtrModeNi.cs b/src/LibHac/Crypto2/Detail/AesCtrModeNi.cs index b7638698..35624ae7 100644 --- a/src/LibHac/Crypto2/Detail/AesCtrModeNi.cs +++ b/src/LibHac/Crypto2/Detail/AesCtrModeNi.cs @@ -1,5 +1,6 @@ #if HAS_INTRINSICS using System; +using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; @@ -17,6 +18,8 @@ namespace LibHac.Crypto2.Detail public void Initialize(ReadOnlySpan key, ReadOnlySpan iv) { + Debug.Assert(iv.Length == Aes.BlockSize); + _aesCore.Initialize(key, false); _iv = Unsafe.ReadUnaligned>(ref MemoryMarshal.GetReference(iv)); diff --git a/src/LibHac/Crypto2/Detail/AesXtsMode.cs b/src/LibHac/Crypto2/Detail/AesXtsMode.cs index ca8805bb..d0c0ab13 100644 --- a/src/LibHac/Crypto2/Detail/AesXtsMode.cs +++ b/src/LibHac/Crypto2/Detail/AesXtsMode.cs @@ -15,7 +15,7 @@ namespace LibHac.Crypto2.Detail public void Initialize(ReadOnlySpan key1, ReadOnlySpan key2, ReadOnlySpan iv, bool isDecrypting) { - Debug.Assert(iv.Length == AesCrypto.BlockSize); + Debug.Assert(iv.Length == Aes.BlockSize); _dataAesCore = new AesCore(); _tweakAesCore = new AesCore(); @@ -33,18 +33,18 @@ namespace LibHac.Crypto2.Detail int leftover = length & 0xF; // Data units must be at least 1 block long. - if (length < AesCrypto.BlockSize) + if (length < Aes.BlockSize) throw new ArgumentException(); var tweak = new Buffer16(); _tweakAesCore.Encrypt(_iv, tweak); - using var tweakBuffer = new RentedArray(blockCount * AesCrypto.BlockSize); + using var tweakBuffer = new RentedArray(blockCount * Aes.BlockSize); tweak = FillTweakBuffer(tweak, MemoryMarshal.Cast(tweakBuffer.Span)); Util.XorArrays(output, input, tweakBuffer.Span); - _dataAesCore.Encrypt(output.Slice(0, blockCount * AesCrypto.BlockSize), output); + _dataAesCore.Encrypt(output.Slice(0, blockCount * Aes.BlockSize), output); Util.XorArrays(output, output, tweakBuffer.Array); if (leftover != 0) @@ -65,7 +65,7 @@ namespace LibHac.Crypto2.Detail tmp[i] = inBlock[i]; } - for (int i = leftover; i < AesCrypto.BlockSize; i++) + for (int i = leftover; i < Aes.BlockSize; i++) { tmp[i] = prevOutBlock[i]; } @@ -83,7 +83,7 @@ namespace LibHac.Crypto2.Detail int leftover = length & 0xF; // Data units must be at least 1 block long. - if (length < AesCrypto.BlockSize) + if (length < Aes.BlockSize) throw new ArgumentException(); if (leftover != 0) blockCount--; @@ -94,11 +94,11 @@ namespace LibHac.Crypto2.Detail if (blockCount > 0) { - using var tweakBuffer = new RentedArray(blockCount * AesCrypto.BlockSize); + using var tweakBuffer = new RentedArray(blockCount * Aes.BlockSize); tweak = FillTweakBuffer(tweak, MemoryMarshal.Cast(tweakBuffer.Span)); Util.XorArrays(output, input, tweakBuffer.Span); - _dataAesCore.Decrypt(output.Slice(0, blockCount * AesCrypto.BlockSize), output); + _dataAesCore.Decrypt(output.Slice(0, blockCount * Aes.BlockSize), output); Util.XorArrays(output, output, tweakBuffer.Span); } @@ -128,7 +128,7 @@ namespace LibHac.Crypto2.Detail tmp[i] = finalInBlock[i]; } - for (int i = leftover; i < AesCrypto.BlockSize; i++) + for (int i = leftover; i < Aes.BlockSize; i++) { tmp[i] = outBlock[i]; } diff --git a/src/LibHac/Crypto2/Detail/AesXtsModeNi.cs b/src/LibHac/Crypto2/Detail/AesXtsModeNi.cs index 479c46a9..1b62d53c 100644 --- a/src/LibHac/Crypto2/Detail/AesXtsModeNi.cs +++ b/src/LibHac/Crypto2/Detail/AesXtsModeNi.cs @@ -20,9 +20,7 @@ namespace LibHac.Crypto2.Detail public void Initialize(ReadOnlySpan key1, ReadOnlySpan key2, ReadOnlySpan iv, bool decrypting) { - Debug.Assert(key1.Length == AesCrypto.KeySize128); - Debug.Assert(key2.Length == AesCrypto.KeySize128); - Debug.Assert(iv.Length == AesCrypto.KeySize128); + Debug.Assert(iv.Length == Aes.KeySize128); _dataAesCore.Initialize(key1, decrypting); _tweakAesCore.Initialize(key2, false); diff --git a/src/hactoolnet/ProcessBench.cs b/src/hactoolnet/ProcessBench.cs index db64776b..47510d4d 100644 --- a/src/hactoolnet/ProcessBench.cs +++ b/src/hactoolnet/ProcessBench.cs @@ -186,13 +186,13 @@ namespace hactoolnet logger.LogMessage(string.Empty); logger.LogMessage(label); - if (AesCrypto.IsAesNiSupported()) + if (Aes.IsAesNiSupported()) CipherBenchmark(srcData, dstDataLh, cipherLibHac, Iterations, "LibHac impl: ", logger); CipherBenchmark(srcData, dstDataNet, cipherNet, Iterations, ".NET impl: ", logger); if (benchBlocked) { - if (AesCrypto.IsAesNiSupported()) + if (Aes.IsAesNiSupported()) CipherBenchmarkBlocked(srcData, dstDataBlockedLh, cipherLibHac, Iterations / 5, "LibHac impl (blocked): ", logger); @@ -202,7 +202,7 @@ namespace hactoolnet if (function != null) { - if (AesCrypto.IsAesNiSupported()) + if (Aes.IsAesNiSupported()) CipherBenchmarkSeparate(srcData, dstDataSeparateLh, function, Iterations / 5, "LibHac impl (separate): ", false, logger); @@ -210,7 +210,7 @@ namespace hactoolnet ".NET impl (separate): ", true, logger); } - if (AesCrypto.IsAesNiSupported()) + if (Aes.IsAesNiSupported()) { logger.LogMessage($"{dstDataLh.SequenceEqual(dstDataNet)}"); @@ -279,17 +279,17 @@ namespace hactoolnet case "aesecbnew": { - Func encryptorNet = () => AesCrypto.CreateEcbEncryptor(new byte[0x10], true); - Func encryptorLh = () => AesCrypto.CreateEcbEncryptor(new byte[0x10]); + Func encryptorNet = () => Aes.CreateEcbEncryptor(new byte[0x10], true); + Func encryptorLh = () => Aes.CreateEcbEncryptor(new byte[0x10]); CipherTaskSeparate encrypt = (input, output, key1, key2, iv, crypto) => - AesCrypto.EncryptEcb128(input, output, key1, crypto); + Aes.EncryptEcb128(input, output, key1, crypto); RunCipherBenchmark(encryptorNet, encryptorLh, encrypt, true, "AES-ECB encrypt", ctx.Logger); - Func decryptorNet = () => AesCrypto.CreateEcbDecryptor(new byte[0x10], true); - Func decryptorLh = () => AesCrypto.CreateEcbDecryptor(new byte[0x10]); + Func decryptorNet = () => Aes.CreateEcbDecryptor(new byte[0x10], true); + Func decryptorLh = () => Aes.CreateEcbDecryptor(new byte[0x10]); CipherTaskSeparate decrypt = (input, output, key1, key2, iv, crypto) => - AesCrypto.DecryptEcb128(input, output, key1, crypto); + Aes.DecryptEcb128(input, output, key1, crypto); RunCipherBenchmark(decryptorNet, decryptorLh, decrypt, true, "AES-ECB decrypt", ctx.Logger); @@ -297,17 +297,17 @@ namespace hactoolnet } case "aescbcnew": { - Func encryptorNet = () => AesCrypto.CreateCbcEncryptor(new byte[0x10], new byte[0x10], true); - Func encryptorLh = () => AesCrypto.CreateCbcEncryptor(new byte[0x10], new byte[0x10]); + Func encryptorNet = () => Aes.CreateCbcEncryptor(new byte[0x10], new byte[0x10], true); + Func encryptorLh = () => Aes.CreateCbcEncryptor(new byte[0x10], new byte[0x10]); CipherTaskSeparate encrypt = (input, output, key1, key2, iv, crypto) => - AesCrypto.EncryptCbc128(input, output, key1, iv, crypto); + Aes.EncryptCbc128(input, output, key1, iv, crypto); RunCipherBenchmark(encryptorNet, encryptorLh, encrypt, true, "AES-CBC encrypt", ctx.Logger); - Func decryptorNet = () => AesCrypto.CreateCbcDecryptor(new byte[0x10], new byte[0x10], true); - Func decryptorLh = () => AesCrypto.CreateCbcDecryptor(new byte[0x10], new byte[0x10]); + Func decryptorNet = () => Aes.CreateCbcDecryptor(new byte[0x10], new byte[0x10], true); + Func decryptorLh = () => Aes.CreateCbcDecryptor(new byte[0x10], new byte[0x10]); CipherTaskSeparate decrypt = (input, output, key1, key2, iv, crypto) => - AesCrypto.DecryptCbc128(input, output, key1, iv, crypto); + Aes.DecryptCbc128(input, output, key1, iv, crypto); RunCipherBenchmark(decryptorNet, decryptorLh, decrypt, true, "AES-CBC decrypt", ctx.Logger); @@ -316,10 +316,10 @@ namespace hactoolnet case "aesctrnew": { - Func encryptorNet = () => AesCrypto.CreateCtrEncryptor(new byte[0x10], new byte[0x10], true); - Func encryptorLh = () => AesCrypto.CreateCtrEncryptor(new byte[0x10], new byte[0x10]); + Func encryptorNet = () => Aes.CreateCtrEncryptor(new byte[0x10], new byte[0x10], true); + Func encryptorLh = () => Aes.CreateCtrEncryptor(new byte[0x10], new byte[0x10]); CipherTaskSeparate encrypt = (input, output, key1, key2, iv, crypto) => - AesCrypto.EncryptCtr128(input, output, key1, iv, crypto); + Aes.EncryptCtr128(input, output, key1, iv, crypto); RunCipherBenchmark(encryptorNet, encryptorLh, encrypt, true, "AES-CTR", ctx.Logger); @@ -327,17 +327,17 @@ namespace hactoolnet } case "aesxtsnew": { - Func encryptorNet = () => AesCrypto.CreateXtsEncryptor(new byte[0x10], new byte[0x10], new byte[0x10], true); - Func encryptorLh = () => AesCrypto.CreateXtsEncryptor(new byte[0x10], new byte[0x10], new byte[0x10]); + Func encryptorNet = () => Aes.CreateXtsEncryptor(new byte[0x10], new byte[0x10], new byte[0x10], true); + Func encryptorLh = () => Aes.CreateXtsEncryptor(new byte[0x10], new byte[0x10], new byte[0x10]); CipherTaskSeparate encrypt = (input, output, key1, key2, iv, crypto) => - AesCrypto.EncryptXts128(input, output, key1, key2, iv, crypto); + Aes.EncryptXts128(input, output, key1, key2, iv, crypto); RunCipherBenchmark(encryptorNet, encryptorLh, encrypt, false, "AES-XTS encrypt", ctx.Logger); - Func decryptorNet = () => AesCrypto.CreateXtsDecryptor(new byte[0x10], new byte[0x10], new byte[0x10], true); - Func decryptorLh = () => AesCrypto.CreateXtsDecryptor(new byte[0x10], new byte[0x10], new byte[0x10]); + Func decryptorNet = () => Aes.CreateXtsDecryptor(new byte[0x10], new byte[0x10], new byte[0x10], true); + Func decryptorLh = () => Aes.CreateXtsDecryptor(new byte[0x10], new byte[0x10], new byte[0x10]); CipherTaskSeparate decrypt = (input, output, key1, key2, iv, crypto) => - AesCrypto.DecryptXts128(input, output, key1, key2, iv, crypto); + Aes.DecryptXts128(input, output, key1, key2, iv, crypto); RunCipherBenchmark(decryptorNet, decryptorLh, decrypt, false, "AES-XTS decrypt", ctx.Logger); diff --git a/tests/LibHac.Tests/CryptoTests/AesCbcTests.cs b/tests/LibHac.Tests/CryptoTests/AesCbcTests.cs index ff78cc23..9fa026a3 100644 --- a/tests/LibHac.Tests/CryptoTests/AesCbcTests.cs +++ b/tests/LibHac.Tests/CryptoTests/AesCbcTests.cs @@ -21,56 +21,56 @@ namespace LibHac.Tests.CryptoTests [MemberData(nameof(EncryptTestVectors))] public static void Encrypt(EncryptionTestVector tv) { - Common.CipherTestCore(tv.PlainText, tv.CipherText, AesCrypto.CreateCbcEncryptor(tv.Key, tv.Iv, true)); + Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateCbcEncryptor(tv.Key, tv.Iv, true)); } [Theory] [MemberData(nameof(DecryptTestVectors))] public static void Decrypt(EncryptionTestVector tv) { - Common.CipherTestCore(tv.CipherText, tv.PlainText, AesCrypto.CreateCbcDecryptor(tv.Key, tv.Iv, true)); + Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateCbcDecryptor(tv.Key, tv.Iv, true)); } [Theory] [MemberData(nameof(EncryptMultiTestVectors))] public static void EncryptMulti(EncryptionTestVector tv) { - Common.CipherTestCore(tv.PlainText, tv.CipherText, AesCrypto.CreateCbcEncryptor(tv.Key, tv.Iv, true)); + Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateCbcEncryptor(tv.Key, tv.Iv, true)); } [Theory] [MemberData(nameof(DecryptMultiTestVectors))] public static void DecryptMulti(EncryptionTestVector tv) { - Common.CipherTestCore(tv.CipherText, tv.PlainText, AesCrypto.CreateCbcDecryptor(tv.Key, tv.Iv, true)); + Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateCbcDecryptor(tv.Key, tv.Iv, true)); } [AesIntrinsicsRequiredTheory] [MemberData(nameof(EncryptTestVectors))] public static void EncryptIntrinsics(EncryptionTestVector tv) { - Common.CipherTestCore(tv.PlainText, tv.CipherText, AesCrypto.CreateCbcEncryptor(tv.Key, tv.Iv)); + Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateCbcEncryptor(tv.Key, tv.Iv)); } [AesIntrinsicsRequiredTheory] [MemberData(nameof(DecryptTestVectors))] public static void DecryptIntrinsics(EncryptionTestVector tv) { - Common.CipherTestCore(tv.CipherText, tv.PlainText, AesCrypto.CreateCbcDecryptor(tv.Key, tv.Iv)); + Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateCbcDecryptor(tv.Key, tv.Iv)); } [AesIntrinsicsRequiredTheory] [MemberData(nameof(EncryptMultiTestVectors))] public static void EncryptMultiIntrinsics(EncryptionTestVector tv) { - Common.CipherTestCore(tv.PlainText, tv.CipherText, AesCrypto.CreateCbcEncryptor(tv.Key, tv.Iv)); + Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateCbcEncryptor(tv.Key, tv.Iv)); } [AesIntrinsicsRequiredTheory] [MemberData(nameof(DecryptMultiTestVectors))] public static void DecryptMultiIntrinsics(EncryptionTestVector tv) { - Common.CipherTestCore(tv.CipherText, tv.PlainText, AesCrypto.CreateCbcDecryptor(tv.Key, tv.Iv)); + Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateCbcDecryptor(tv.Key, tv.Iv)); } } } diff --git a/tests/LibHac.Tests/CryptoTests/AesCtrTests.cs b/tests/LibHac.Tests/CryptoTests/AesCtrTests.cs index 6c6b347a..697bb208 100644 --- a/tests/LibHac.Tests/CryptoTests/AesCtrTests.cs +++ b/tests/LibHac.Tests/CryptoTests/AesCtrTests.cs @@ -11,14 +11,14 @@ namespace LibHac.Tests.CryptoTests [MemberData(nameof(TestVectors))] public static void Transform(EncryptionTestVector tv) { - Common.CipherTestCore(tv.PlainText, tv.CipherText, AesCrypto.CreateCtrEncryptor(tv.Key, tv.Iv, true)); + Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateCtrEncryptor(tv.Key, tv.Iv, true)); } [AesIntrinsicsRequiredTheory] [MemberData(nameof(TestVectors))] public static void TransformIntrinsics(EncryptionTestVector tv) { - Common.CipherTestCore(tv.PlainText, tv.CipherText, AesCrypto.CreateCtrEncryptor(tv.Key, tv.Iv)); + Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateCtrEncryptor(tv.Key, tv.Iv)); } } } diff --git a/tests/LibHac.Tests/CryptoTests/AesEcbTests.cs b/tests/LibHac.Tests/CryptoTests/AesEcbTests.cs index 1fdd1962..79102ce1 100644 --- a/tests/LibHac.Tests/CryptoTests/AesEcbTests.cs +++ b/tests/LibHac.Tests/CryptoTests/AesEcbTests.cs @@ -21,56 +21,56 @@ namespace LibHac.Tests.CryptoTests [MemberData(nameof(EncryptTestVectors))] public static void Encrypt(EncryptionTestVector tv) { - Common.CipherTestCore(tv.PlainText, tv.CipherText, AesCrypto.CreateEcbEncryptor(tv.Key, true)); + Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateEcbEncryptor(tv.Key, true)); } [Theory] [MemberData(nameof(DecryptTestVectors))] public static void Decrypt(EncryptionTestVector tv) { - Common.CipherTestCore(tv.CipherText, tv.PlainText, AesCrypto.CreateEcbDecryptor(tv.Key, true)); + Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateEcbDecryptor(tv.Key, true)); } [Theory] [MemberData(nameof(EncryptMultiTestVectors))] public static void EncryptMulti(EncryptionTestVector tv) { - Common.CipherTestCore(tv.PlainText, tv.CipherText, AesCrypto.CreateEcbEncryptor(tv.Key, true)); + Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateEcbEncryptor(tv.Key, true)); } [Theory] [MemberData(nameof(DecryptMultiTestVectors))] public static void DecryptMulti(EncryptionTestVector tv) { - Common.CipherTestCore(tv.CipherText, tv.PlainText, AesCrypto.CreateEcbDecryptor(tv.Key, true)); + Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateEcbDecryptor(tv.Key, true)); } [AesIntrinsicsRequiredTheory] [MemberData(nameof(EncryptTestVectors))] public static void EncryptIntrinsics(EncryptionTestVector tv) { - Common.CipherTestCore(tv.PlainText, tv.CipherText, AesCrypto.CreateEcbEncryptor(tv.Key)); + Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateEcbEncryptor(tv.Key)); } [AesIntrinsicsRequiredTheory] [MemberData(nameof(DecryptTestVectors))] public static void DecryptIntrinsics(EncryptionTestVector tv) { - Common.CipherTestCore(tv.CipherText, tv.PlainText, AesCrypto.CreateEcbDecryptor(tv.Key)); + Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateEcbDecryptor(tv.Key)); } [AesIntrinsicsRequiredTheory] [MemberData(nameof(EncryptMultiTestVectors))] public static void EncryptMultiIntrinsics(EncryptionTestVector tv) { - Common.CipherTestCore(tv.PlainText, tv.CipherText, AesCrypto.CreateEcbEncryptor(tv.Key)); + Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateEcbEncryptor(tv.Key)); } [AesIntrinsicsRequiredTheory] [MemberData(nameof(DecryptMultiTestVectors))] public static void DecryptMultiIntrinsics(EncryptionTestVector tv) { - Common.CipherTestCore(tv.CipherText, tv.PlainText, AesCrypto.CreateEcbDecryptor(tv.Key)); + Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateEcbDecryptor(tv.Key)); } } } diff --git a/tests/LibHac.Tests/CryptoTests/AesIntrinsicsRequiredTheory.cs b/tests/LibHac.Tests/CryptoTests/AesIntrinsicsRequiredTheory.cs index 1abcbc8e..d84ee178 100644 --- a/tests/LibHac.Tests/CryptoTests/AesIntrinsicsRequiredTheory.cs +++ b/tests/LibHac.Tests/CryptoTests/AesIntrinsicsRequiredTheory.cs @@ -7,7 +7,7 @@ namespace LibHac.Tests.CryptoTests { public AesIntrinsicsRequiredTheoryAttribute() { - if (!AesCrypto.IsAesNiSupported()) + if (!Aes.IsAesNiSupported()) { Skip = "AES intrinsics required"; } diff --git a/tests/LibHac.Tests/CryptoTests/AesXtsTests.cs b/tests/LibHac.Tests/CryptoTests/AesXtsTests.cs index 60bf5ac2..818b0394 100644 --- a/tests/LibHac.Tests/CryptoTests/AesXtsTests.cs +++ b/tests/LibHac.Tests/CryptoTests/AesXtsTests.cs @@ -39,7 +39,7 @@ namespace LibHac.Tests.CryptoTests Span key1 = tv.Key.AsSpan(0, 0x10); Span key2 = tv.Key.AsSpan(0x10, 0x10); - Common.CipherTestCore(tv.PlainText, tv.CipherText, AesCrypto.CreateXtsEncryptor(key1, key2, tv.Iv, true)); + Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateXtsEncryptor(key1, key2, tv.Iv, true)); } [Theory] @@ -49,7 +49,7 @@ namespace LibHac.Tests.CryptoTests Span key1 = tv.Key.AsSpan(0, 0x10); Span key2 = tv.Key.AsSpan(0x10, 0x10); - Common.CipherTestCore(tv.CipherText, tv.PlainText, AesCrypto.CreateXtsDecryptor(key1, key2, tv.Iv, true)); + Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateXtsDecryptor(key1, key2, tv.Iv, true)); } [AesIntrinsicsRequiredTheory] @@ -59,7 +59,7 @@ namespace LibHac.Tests.CryptoTests Span key1 = tv.Key.AsSpan(0, 0x10); Span key2 = tv.Key.AsSpan(0x10, 0x10); - Common.CipherTestCore(tv.PlainText, tv.CipherText, AesCrypto.CreateXtsEncryptor(key1, key2, tv.Iv)); + Common.CipherTestCore(tv.PlainText, tv.CipherText, Aes.CreateXtsEncryptor(key1, key2, tv.Iv)); } [AesIntrinsicsRequiredTheory] @@ -69,7 +69,7 @@ namespace LibHac.Tests.CryptoTests Span key1 = tv.Key.AsSpan(0, 0x10); Span key2 = tv.Key.AsSpan(0x10, 0x10); - Common.CipherTestCore(tv.CipherText, tv.PlainText, AesCrypto.CreateXtsDecryptor(key1, key2, tv.Iv)); + Common.CipherTestCore(tv.CipherText, tv.PlainText, Aes.CreateXtsDecryptor(key1, key2, tv.Iv)); } } }