diff --git a/src/LibHac/Compatibility/Rsa.cs b/src/LibHac/Compatibility/Rsa.cs index b95b1075..9f53bb35 100644 --- a/src/LibHac/Compatibility/Rsa.cs +++ b/src/LibHac/Compatibility/Rsa.cs @@ -20,7 +20,7 @@ namespace LibHac.Compatibility SHA256 sha = SHA256.Create(); var message = new byte[rsaLen]; - BigInteger decInt = BigInteger.ModPow(Crypto.GetBigInteger(signature), new BigInteger(65537), Crypto.GetBigInteger(modulus)); + BigInteger decInt = BigInteger.ModPow(CryptoOld.GetBigInteger(signature), new BigInteger(65537), CryptoOld.GetBigInteger(modulus)); byte[] decBytes = decInt.ToByteArray(); if (decBytes[0] != 0xBC) return false; diff --git a/src/LibHac/Crypto2/Aes.cs b/src/LibHac/Crypto/Aes.cs similarity index 99% rename from src/LibHac/Crypto2/Aes.cs rename to src/LibHac/Crypto/Aes.cs index 455b345d..8286f255 100644 --- a/src/LibHac/Crypto2/Aes.cs +++ b/src/LibHac/Crypto/Aes.cs @@ -1,13 +1,11 @@ // ReSharper disable AssignmentIsFullyDiscarded using System; - +using LibHac.Crypto.Detail; #if HAS_INTRINSICS -using LibHac.Crypto2.Detail; - using AesNi = System.Runtime.Intrinsics.X86.Aes; #endif -namespace LibHac.Crypto2 +namespace LibHac.Crypto { public static class Aes { diff --git a/src/LibHac/Crypto2/AesCbcCipher.cs b/src/LibHac/Crypto/AesCbcCipher.cs similarity index 94% rename from src/LibHac/Crypto2/AesCbcCipher.cs rename to src/LibHac/Crypto/AesCbcCipher.cs index 03a1ef16..deeeb673 100644 --- a/src/LibHac/Crypto2/AesCbcCipher.cs +++ b/src/LibHac/Crypto/AesCbcCipher.cs @@ -1,7 +1,7 @@ using System; -using LibHac.Crypto2.Detail; +using LibHac.Crypto.Detail; -namespace LibHac.Crypto2 +namespace LibHac.Crypto { public class AesCbcEncryptor : ICipher { diff --git a/src/LibHac/Crypto2/AesCbcCipherNi.cs b/src/LibHac/Crypto/AesCbcCipherNi.cs similarity index 94% rename from src/LibHac/Crypto2/AesCbcCipherNi.cs rename to src/LibHac/Crypto/AesCbcCipherNi.cs index 9166329e..618549e8 100644 --- a/src/LibHac/Crypto2/AesCbcCipherNi.cs +++ b/src/LibHac/Crypto/AesCbcCipherNi.cs @@ -1,8 +1,8 @@ #if HAS_INTRINSICS using System; -using LibHac.Crypto2.Detail; +using LibHac.Crypto.Detail; -namespace LibHac.Crypto2 +namespace LibHac.Crypto { public struct AesCbcEncryptorNi : ICipher { diff --git a/src/LibHac/Crypto2/AesCtrCipher.cs b/src/LibHac/Crypto/AesCtrCipher.cs similarity index 89% rename from src/LibHac/Crypto2/AesCtrCipher.cs rename to src/LibHac/Crypto/AesCtrCipher.cs index f0e792c9..4057c113 100644 --- a/src/LibHac/Crypto2/AesCtrCipher.cs +++ b/src/LibHac/Crypto/AesCtrCipher.cs @@ -1,7 +1,7 @@ using System; -using LibHac.Crypto2.Detail; +using LibHac.Crypto.Detail; -namespace LibHac.Crypto2 +namespace LibHac.Crypto { public class AesCtrCipher : ICipher { diff --git a/src/LibHac/Crypto2/AesCtrCipherNi.cs b/src/LibHac/Crypto/AesCtrCipherNi.cs similarity index 89% rename from src/LibHac/Crypto2/AesCtrCipherNi.cs rename to src/LibHac/Crypto/AesCtrCipherNi.cs index 99a0c17d..ba177ca6 100644 --- a/src/LibHac/Crypto2/AesCtrCipherNi.cs +++ b/src/LibHac/Crypto/AesCtrCipherNi.cs @@ -1,8 +1,8 @@ #if HAS_INTRINSICS using System; -using LibHac.Crypto2.Detail; +using LibHac.Crypto.Detail; -namespace LibHac.Crypto2 +namespace LibHac.Crypto { public class AesCtrCipherNi : ICipher { diff --git a/src/LibHac/Crypto2/AesEcbCipher.cs b/src/LibHac/Crypto/AesEcbCipher.cs similarity index 93% rename from src/LibHac/Crypto2/AesEcbCipher.cs rename to src/LibHac/Crypto/AesEcbCipher.cs index 179a0cd4..fcc6c698 100644 --- a/src/LibHac/Crypto2/AesEcbCipher.cs +++ b/src/LibHac/Crypto/AesEcbCipher.cs @@ -1,7 +1,7 @@ using System; -using LibHac.Crypto2.Detail; +using LibHac.Crypto.Detail; -namespace LibHac.Crypto2 +namespace LibHac.Crypto { public class AesEcbEncryptor : ICipher { diff --git a/src/LibHac/Crypto2/AesEcbCipherNi.cs b/src/LibHac/Crypto/AesEcbCipherNi.cs similarity index 94% rename from src/LibHac/Crypto2/AesEcbCipherNi.cs rename to src/LibHac/Crypto/AesEcbCipherNi.cs index 16e5ff16..234331dc 100644 --- a/src/LibHac/Crypto2/AesEcbCipherNi.cs +++ b/src/LibHac/Crypto/AesEcbCipherNi.cs @@ -1,8 +1,8 @@ #if HAS_INTRINSICS using System; -using LibHac.Crypto2.Detail; +using LibHac.Crypto.Detail; -namespace LibHac.Crypto2 +namespace LibHac.Crypto { public class AesEcbEncryptorNi : ICipher { diff --git a/src/LibHac/Crypto2/AesXtsCipher.cs b/src/LibHac/Crypto/AesXtsCipher.cs similarity index 94% rename from src/LibHac/Crypto2/AesXtsCipher.cs rename to src/LibHac/Crypto/AesXtsCipher.cs index f7cd4cd4..152e3d5b 100644 --- a/src/LibHac/Crypto2/AesXtsCipher.cs +++ b/src/LibHac/Crypto/AesXtsCipher.cs @@ -1,7 +1,7 @@ using System; -using LibHac.Crypto2.Detail; +using LibHac.Crypto.Detail; -namespace LibHac.Crypto2 +namespace LibHac.Crypto { public class AesXtsEncryptor : ICipher { diff --git a/src/LibHac/Crypto2/AesXtsCipherNi.cs b/src/LibHac/Crypto/AesXtsCipherNi.cs similarity index 94% rename from src/LibHac/Crypto2/AesXtsCipherNi.cs rename to src/LibHac/Crypto/AesXtsCipherNi.cs index b53a8b1f..a4b13730 100644 --- a/src/LibHac/Crypto2/AesXtsCipherNi.cs +++ b/src/LibHac/Crypto/AesXtsCipherNi.cs @@ -1,8 +1,8 @@ #if HAS_INTRINSICS using System; -using LibHac.Crypto2.Detail; +using LibHac.Crypto.Detail; -namespace LibHac.Crypto2 +namespace LibHac.Crypto { public class AesXtsEncryptorNi : ICipher { diff --git a/src/LibHac/Crypto2/Detail/AesCbcMode.cs b/src/LibHac/Crypto/Detail/AesCbcMode.cs similarity index 95% rename from src/LibHac/Crypto2/Detail/AesCbcMode.cs rename to src/LibHac/Crypto/Detail/AesCbcMode.cs index 302c4ff1..86361cd0 100644 --- a/src/LibHac/Crypto2/Detail/AesCbcMode.cs +++ b/src/LibHac/Crypto/Detail/AesCbcMode.cs @@ -1,7 +1,7 @@ using System; using System.Security.Cryptography; -namespace LibHac.Crypto2.Detail +namespace LibHac.Crypto.Detail { public struct AesCbcMode { diff --git a/src/LibHac/Crypto2/Detail/AesCbcModeNi.cs b/src/LibHac/Crypto/Detail/AesCbcModeNi.cs similarity index 98% rename from src/LibHac/Crypto2/Detail/AesCbcModeNi.cs rename to src/LibHac/Crypto/Detail/AesCbcModeNi.cs index f69bd8f9..fd997d0f 100644 --- a/src/LibHac/Crypto2/Detail/AesCbcModeNi.cs +++ b/src/LibHac/Crypto/Detail/AesCbcModeNi.cs @@ -6,7 +6,7 @@ using System.Runtime.InteropServices; using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; -namespace LibHac.Crypto2.Detail +namespace LibHac.Crypto.Detail { public struct AesCbcModeNi { diff --git a/src/LibHac/Crypto2/Detail/AesCore.cs b/src/LibHac/Crypto/Detail/AesCore.cs similarity index 98% rename from src/LibHac/Crypto2/Detail/AesCore.cs rename to src/LibHac/Crypto/Detail/AesCore.cs index 4df0e3f2..fccf1001 100644 --- a/src/LibHac/Crypto2/Detail/AesCore.cs +++ b/src/LibHac/Crypto/Detail/AesCore.cs @@ -3,7 +3,7 @@ using System.Diagnostics; using System.Security.Cryptography; using LibHac.Common; -namespace LibHac.Crypto2.Detail +namespace LibHac.Crypto.Detail { public struct AesCore { diff --git a/src/LibHac/Crypto2/Detail/AesCoreNi.cs b/src/LibHac/Crypto/Detail/AesCoreNi.cs similarity index 99% rename from src/LibHac/Crypto2/Detail/AesCoreNi.cs rename to src/LibHac/Crypto/Detail/AesCoreNi.cs index 28dfef6f..3cdb4fef 100644 --- a/src/LibHac/Crypto2/Detail/AesCoreNi.cs +++ b/src/LibHac/Crypto/Detail/AesCoreNi.cs @@ -8,7 +8,7 @@ using System.Runtime.Intrinsics.X86; using AesNi = System.Runtime.Intrinsics.X86.Aes; -namespace LibHac.Crypto2.Detail +namespace LibHac.Crypto.Detail { [StructLayout(LayoutKind.Sequential, Size = RoundKeyCount * RoundKeySize)] public struct AesCoreNi diff --git a/src/LibHac/Crypto2/Detail/AesCtrMode.cs b/src/LibHac/Crypto/Detail/AesCtrMode.cs similarity index 98% rename from src/LibHac/Crypto2/Detail/AesCtrMode.cs rename to src/LibHac/Crypto/Detail/AesCtrMode.cs index 300cc80d..7ed80a93 100644 --- a/src/LibHac/Crypto2/Detail/AesCtrMode.cs +++ b/src/LibHac/Crypto/Detail/AesCtrMode.cs @@ -5,7 +5,7 @@ using System.Runtime.InteropServices; using System.Security.Cryptography; using LibHac.Common; -namespace LibHac.Crypto2.Detail +namespace LibHac.Crypto.Detail { public struct AesCtrMode { diff --git a/src/LibHac/Crypto2/Detail/AesCtrModeNi.cs b/src/LibHac/Crypto/Detail/AesCtrModeNi.cs similarity index 98% rename from src/LibHac/Crypto2/Detail/AesCtrModeNi.cs rename to src/LibHac/Crypto/Detail/AesCtrModeNi.cs index 35624ae7..244ca672 100644 --- a/src/LibHac/Crypto2/Detail/AesCtrModeNi.cs +++ b/src/LibHac/Crypto/Detail/AesCtrModeNi.cs @@ -6,7 +6,7 @@ using System.Runtime.InteropServices; using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; -namespace LibHac.Crypto2.Detail +namespace LibHac.Crypto.Detail { public struct AesCtrModeNi { diff --git a/src/LibHac/Crypto2/Detail/AesEcbMode.cs b/src/LibHac/Crypto/Detail/AesEcbMode.cs similarity index 95% rename from src/LibHac/Crypto2/Detail/AesEcbMode.cs rename to src/LibHac/Crypto/Detail/AesEcbMode.cs index 8365be0c..8a90322d 100644 --- a/src/LibHac/Crypto2/Detail/AesEcbMode.cs +++ b/src/LibHac/Crypto/Detail/AesEcbMode.cs @@ -1,7 +1,7 @@ using System; using System.Security.Cryptography; -namespace LibHac.Crypto2.Detail +namespace LibHac.Crypto.Detail { public struct AesEcbMode { diff --git a/src/LibHac/Crypto2/Detail/AesEcbModeNi.cs b/src/LibHac/Crypto/Detail/AesEcbModeNi.cs similarity index 95% rename from src/LibHac/Crypto2/Detail/AesEcbModeNi.cs rename to src/LibHac/Crypto/Detail/AesEcbModeNi.cs index 90b066ac..17c24f78 100644 --- a/src/LibHac/Crypto2/Detail/AesEcbModeNi.cs +++ b/src/LibHac/Crypto/Detail/AesEcbModeNi.cs @@ -1,7 +1,7 @@ #if HAS_INTRINSICS using System; -namespace LibHac.Crypto2.Detail +namespace LibHac.Crypto.Detail { public struct AesEcbModeNi { diff --git a/src/LibHac/Crypto2/Detail/AesXtsMode.cs b/src/LibHac/Crypto/Detail/AesXtsMode.cs similarity index 99% rename from src/LibHac/Crypto2/Detail/AesXtsMode.cs rename to src/LibHac/Crypto/Detail/AesXtsMode.cs index d0c0ab13..ccfd37db 100644 --- a/src/LibHac/Crypto2/Detail/AesXtsMode.cs +++ b/src/LibHac/Crypto/Detail/AesXtsMode.cs @@ -5,7 +5,7 @@ using System.Runtime.InteropServices; using System.Security.Cryptography; using LibHac.Common; -namespace LibHac.Crypto2.Detail +namespace LibHac.Crypto.Detail { public struct AesXtsMode { diff --git a/src/LibHac/Crypto2/Detail/AesXtsModeNi.cs b/src/LibHac/Crypto/Detail/AesXtsModeNi.cs similarity index 99% rename from src/LibHac/Crypto2/Detail/AesXtsModeNi.cs rename to src/LibHac/Crypto/Detail/AesXtsModeNi.cs index 1b62d53c..914d9d56 100644 --- a/src/LibHac/Crypto2/Detail/AesXtsModeNi.cs +++ b/src/LibHac/Crypto/Detail/AesXtsModeNi.cs @@ -7,7 +7,7 @@ using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; using LibHac.Common; -namespace LibHac.Crypto2.Detail +namespace LibHac.Crypto.Detail { public struct AesXtsModeNi { diff --git a/src/LibHac/Crypto2/ICipher.cs b/src/LibHac/Crypto/ICipher.cs similarity index 83% rename from src/LibHac/Crypto2/ICipher.cs rename to src/LibHac/Crypto/ICipher.cs index 9ad0647d..9973d7f8 100644 --- a/src/LibHac/Crypto2/ICipher.cs +++ b/src/LibHac/Crypto/ICipher.cs @@ -1,6 +1,6 @@ using System; -namespace LibHac.Crypto2 +namespace LibHac.Crypto { public interface ICipher { diff --git a/src/LibHac/Crypto.cs b/src/LibHac/CryptoOld.cs similarity index 99% rename from src/LibHac/Crypto.cs rename to src/LibHac/CryptoOld.cs index 62c859ba..0b05c4f1 100644 --- a/src/LibHac/Crypto.cs +++ b/src/LibHac/CryptoOld.cs @@ -6,7 +6,7 @@ using LibHac.FsSystem; namespace LibHac { - public static class Crypto + public static class CryptoOld { internal const int Aes128Size = 0x10; internal const int Sha256DigestSize = 0x20; diff --git a/src/LibHac/FsSystem/AesXtsFileHeader.cs b/src/LibHac/FsSystem/AesXtsFileHeader.cs index 89233eab..86f1bdd4 100644 --- a/src/LibHac/FsSystem/AesXtsFileHeader.cs +++ b/src/LibHac/FsSystem/AesXtsFileHeader.cs @@ -78,14 +78,14 @@ namespace LibHac.FsSystem private void DecryptKeys() { - Crypto.DecryptEcb(Kek1, EncryptedKey1, DecryptedKey1, 0x10); - Crypto.DecryptEcb(Kek2, EncryptedKey2, DecryptedKey2, 0x10); + CryptoOld.DecryptEcb(Kek1, EncryptedKey1, DecryptedKey1, 0x10); + CryptoOld.DecryptEcb(Kek2, EncryptedKey2, DecryptedKey2, 0x10); } private void EncryptKeys() { - Crypto.EncryptEcb(Kek1, DecryptedKey1, EncryptedKey1, 0x10); - Crypto.EncryptEcb(Kek2, DecryptedKey2, EncryptedKey2, 0x10); + CryptoOld.EncryptEcb(Kek1, DecryptedKey1, EncryptedKey1, 0x10); + CryptoOld.EncryptEcb(Kek2, DecryptedKey2, EncryptedKey2, 0x10); } private void GenerateKek(byte[] kekSeed, string path) diff --git a/src/LibHac/FsSystem/NcaUtils/Nca.cs b/src/LibHac/FsSystem/NcaUtils/Nca.cs index df7af1e8..573f6bf9 100644 --- a/src/LibHac/FsSystem/NcaUtils/Nca.cs +++ b/src/LibHac/FsSystem/NcaUtils/Nca.cs @@ -36,9 +36,9 @@ namespace LibHac.FsSystem.NcaUtils } byte[] encryptedKey = Header.GetEncryptedKey(index).ToArray(); - var decryptedKey = new byte[Crypto.Aes128Size]; + var decryptedKey = new byte[CryptoOld.Aes128Size]; - Crypto.DecryptEcb(keyAreaKey, encryptedKey, decryptedKey, Crypto.Aes128Size); + CryptoOld.DecryptEcb(keyAreaKey, encryptedKey, decryptedKey, CryptoOld.Aes128Size); return decryptedKey; } @@ -60,9 +60,9 @@ namespace LibHac.FsSystem.NcaUtils } byte[] encryptedKey = accessKey.Value.ToArray(); - var decryptedKey = new byte[Crypto.Aes128Size]; + var decryptedKey = new byte[CryptoOld.Aes128Size]; - Crypto.DecryptEcb(titleKek, encryptedKey, decryptedKey, Crypto.Aes128Size); + CryptoOld.DecryptEcb(titleKek, encryptedKey, decryptedKey, CryptoOld.Aes128Size); return decryptedKey; } diff --git a/src/LibHac/FsSystem/NcaUtils/NcaExtensions.cs b/src/LibHac/FsSystem/NcaUtils/NcaExtensions.cs index b9ddfc7f..0f0e4e36 100644 --- a/src/LibHac/FsSystem/NcaUtils/NcaExtensions.cs +++ b/src/LibHac/FsSystem/NcaUtils/NcaExtensions.cs @@ -98,7 +98,7 @@ namespace LibHac.FsSystem.NcaUtils var data = new byte[size]; storage.Read(offset, data).ThrowIfFailure(); - byte[] actualHash = Crypto.ComputeSha256(data, 0, data.Length); + byte[] actualHash = CryptoOld.ComputeSha256(data, 0, data.Length); if (Util.ArraysEqual(expectedHash, actualHash)) return Validity.Valid; diff --git a/src/LibHac/FsSystem/NcaUtils/NcaHeader.cs b/src/LibHac/FsSystem/NcaUtils/NcaHeader.cs index 7445129b..63284e69 100644 --- a/src/LibHac/FsSystem/NcaUtils/NcaHeader.cs +++ b/src/LibHac/FsSystem/NcaUtils/NcaHeader.cs @@ -151,8 +151,8 @@ namespace LibHac.FsSystem.NcaUtils throw new ArgumentOutOfRangeException($"Key index must be between 0 and 3. Actual: {index}"); } - int offset = NcaHeaderStruct.KeyAreaOffset + Crypto.Aes128Size * index; - return _header.Span.Slice(offset, Crypto.Aes128Size); + int offset = NcaHeaderStruct.KeyAreaOffset + CryptoOld.Aes128Size * index; + return _header.Span.Slice(offset, CryptoOld.Aes128Size); } public NcaFsHeader GetFsHeader(int index) @@ -163,7 +163,7 @@ namespace LibHac.FsSystem.NcaUtils // ReSharper disable once ImpureMethodCallOnReadonlyValueField Memory headerData = _header.Slice(offset, NcaHeaderStruct.FsHeaderSize); - byte[] actualHash = Crypto.ComputeSha256(headerData.ToArray(), 0, NcaHeaderStruct.FsHeaderSize); + byte[] actualHash = CryptoOld.ComputeSha256(headerData.ToArray(), 0, NcaHeaderStruct.FsHeaderSize); if (!Util.SpansEqual(expectedHash, actualHash)) { @@ -231,12 +231,12 @@ namespace LibHac.FsSystem.NcaUtils public Validity VerifySignature1(byte[] modulus) { - return Crypto.Rsa2048PssVerify(_header.Span.Slice(0x200, 0x200).ToArray(), Signature1.ToArray(), modulus); + return CryptoOld.Rsa2048PssVerify(_header.Span.Slice(0x200, 0x200).ToArray(), Signature1.ToArray(), modulus); } public Validity VerifySignature2(byte[] modulus) { - return Crypto.Rsa2048PssVerify(_header.Span.Slice(0x200, 0x200).ToArray(), Signature2.ToArray(), modulus); + return CryptoOld.Rsa2048PssVerify(_header.Span.Slice(0x200, 0x200).ToArray(), Signature2.ToArray(), modulus); } [StructLayout(LayoutKind.Explicit, Size = 0xC00)] diff --git a/src/LibHac/FsSystem/PartitionFileSystem.cs b/src/LibHac/FsSystem/PartitionFileSystem.cs index a3b8e8d1..5cee34c3 100644 --- a/src/LibHac/FsSystem/PartitionFileSystem.cs +++ b/src/LibHac/FsSystem/PartitionFileSystem.cs @@ -164,7 +164,7 @@ namespace LibHac.FsSystem { HashedRegionSize = reader.ReadInt32(); HashedRegionOffset = reader.ReadInt64(); - Hash = reader.ReadBytes(Crypto.Sha256DigestSize); + Hash = reader.ReadBytes(CryptoOld.Sha256DigestSize); } else { diff --git a/src/LibHac/FsSystem/Save/Header.cs b/src/LibHac/FsSystem/Save/Header.cs index 39fb32cb..47d9f927 100644 --- a/src/LibHac/FsSystem/Save/Header.cs +++ b/src/LibHac/FsSystem/Save/Header.cs @@ -81,7 +81,7 @@ namespace LibHac.FsSystem.Save MasterHash = storage.Slice(Layout.IvfcMasterHashOffsetA, Layout.IvfcMasterHashSize); - HeaderHashValidity = Crypto.CheckMemoryHashTable(Data, Layout.Hash, 0x300, 0x3d00); + HeaderHashValidity = CryptoOld.CheckMemoryHashTable(Data, Layout.Hash, 0x300, 0x3d00); SignatureValidity = ValidateSignature(keyset); } @@ -89,7 +89,7 @@ namespace LibHac.FsSystem.Save { var calculatedCmac = new byte[0x10]; - Crypto.CalculateAesCmac(keyset.SaveMacKey, Data, 0x100, calculatedCmac, 0, 0x200); + CryptoOld.CalculateAesCmac(keyset.SaveMacKey, Data, 0x100, calculatedCmac, 0, 0x200); return Util.ArraysEqual(calculatedCmac, Cmac) ? Validity.Valid : Validity.Invalid; } diff --git a/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs b/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs index 51e8a827..851ac3a7 100644 --- a/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs +++ b/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs @@ -252,7 +252,7 @@ namespace LibHac.FsSystem.Save headerStream.Position = 0x300; headerStream.Read(hashData, 0, hashData.Length); - byte[] hash = Crypto.ComputeSha256(hashData, 0, hashData.Length); + byte[] hash = CryptoOld.ComputeSha256(hashData, 0, hashData.Length); headerStream.Position = 0x108; headerStream.Write(hash, 0, hash.Length); @@ -264,7 +264,7 @@ namespace LibHac.FsSystem.Save headerStream.Position = 0x100; headerStream.Read(cmacData, 0, 0x200); - Crypto.CalculateAesCmac(keyset.SaveMacKey, cmacData, 0, cmac, 0, 0x200); + CryptoOld.CalculateAesCmac(keyset.SaveMacKey, cmacData, 0, cmac, 0, 0x200); headerStream.Position = 0; headerStream.Write(cmac, 0, 0x10); diff --git a/src/LibHac/Keyset.cs b/src/LibHac/Keyset.cs index 724daf8a..07d05164 100644 --- a/src/LibHac/Keyset.cs +++ b/src/LibHac/Keyset.cs @@ -272,12 +272,12 @@ namespace LibHac { if (KeyblobKeySources[i].IsEmpty()) continue; - Crypto.DecryptEcb(TsecKey, KeyblobKeySources[i], temp, 0x10); - Crypto.DecryptEcb(SecureBootKey, temp, KeyblobKeys[i], 0x10); + CryptoOld.DecryptEcb(TsecKey, KeyblobKeySources[i], temp, 0x10); + CryptoOld.DecryptEcb(SecureBootKey, temp, KeyblobKeys[i], 0x10); if (!haveKeyblobMacKeySource) continue; - Crypto.DecryptEcb(KeyblobKeys[i], KeyblobMacKeySource, KeyblobMacKeys[i], 0x10); + CryptoOld.DecryptEcb(KeyblobKeys[i], KeyblobMacKeySource, KeyblobMacKeys[i], 0x10); } } @@ -295,7 +295,7 @@ namespace LibHac } Array.Copy(EncryptedKeyblobs[i], expectedCmac, 0x10); - Crypto.CalculateAesCmac(KeyblobMacKeys[i], EncryptedKeyblobs[i], 0x10, cmac, 0, 0xa0); + CryptoOld.CalculateAesCmac(KeyblobMacKeys[i], EncryptedKeyblobs[i], 0x10, cmac, 0, 0xa0); if (!Util.ArraysEqual(cmac, expectedCmac)) { @@ -329,7 +329,7 @@ namespace LibHac { if (TsecRootKeys[i - UsedKeyblobCount].IsEmpty() || MasterKekSources[i].IsEmpty()) continue; - Crypto.DecryptEcb(TsecRootKeys[i - UsedKeyblobCount], MasterKekSources[i], MasterKeks[i], 0x10); + CryptoOld.DecryptEcb(TsecRootKeys[i - UsedKeyblobCount], MasterKekSources[i], MasterKeks[i], 0x10); } } @@ -341,7 +341,7 @@ namespace LibHac { if (MasterKeks[i].IsEmpty()) continue; - Crypto.DecryptEcb(MasterKeks[i], MasterKeySource, MasterKeys[i], 0x10); + CryptoOld.DecryptEcb(MasterKeks[i], MasterKeySource, MasterKeys[i], 0x10); } } @@ -352,14 +352,14 @@ namespace LibHac // Derive the device key if (!PerConsoleKeySource.IsEmpty() && !KeyblobKeys[0].IsEmpty()) { - Crypto.DecryptEcb(KeyblobKeys[0], PerConsoleKeySource, DeviceKey, 0x10); + CryptoOld.DecryptEcb(KeyblobKeys[0], PerConsoleKeySource, DeviceKey, 0x10); } // Derive save key if (!SaveMacKekSource.IsEmpty() && !SaveMacKeySource.IsEmpty() && !DeviceKey.IsEmpty()) { - Crypto.GenerateKek(DeviceKey, SaveMacKekSource, kek, AesKekGenerationSource, null); - Crypto.DecryptEcb(kek, SaveMacKeySource, SaveMacKey, 0x10); + CryptoOld.GenerateKek(DeviceKey, SaveMacKekSource, kek, AesKekGenerationSource, null); + CryptoOld.DecryptEcb(kek, SaveMacKeySource, SaveMacKey, 0x10); } // Derive BIS keys @@ -378,14 +378,14 @@ namespace LibHac Array.Copy(BisKeySource[2], BisKeySource[3], 0x20); } - Crypto.DecryptEcb(DeviceKey, RetailSpecificAesKeySource, kek, 0x10); - if (!BisKeySource[0].IsEmpty()) Crypto.DecryptEcb(kek, BisKeySource[0], BisKeys[0], 0x20); + CryptoOld.DecryptEcb(DeviceKey, RetailSpecificAesKeySource, kek, 0x10); + if (!BisKeySource[0].IsEmpty()) CryptoOld.DecryptEcb(kek, BisKeySource[0], BisKeys[0], 0x20); - Crypto.GenerateKek(DeviceKey, BisKekSource, kek, AesKekGenerationSource, AesKeyGenerationSource); + CryptoOld.GenerateKek(DeviceKey, BisKekSource, kek, AesKekGenerationSource, AesKeyGenerationSource); for (int i = 1; i < 4; i++) { - if (!BisKeySource[i].IsEmpty()) Crypto.DecryptEcb(kek, BisKeySource[i], BisKeys[i], 0x20); + if (!BisKeySource[i].IsEmpty()) CryptoOld.DecryptEcb(kek, BisKeySource[i], BisKeys[i], 0x20); } } @@ -406,30 +406,30 @@ namespace LibHac if (haveKakSource0) { - Crypto.GenerateKek(MasterKeys[i], KeyAreaKeyApplicationSource, KeyAreaKeys[i][0], + CryptoOld.GenerateKek(MasterKeys[i], KeyAreaKeyApplicationSource, KeyAreaKeys[i][0], AesKekGenerationSource, AesKeyGenerationSource); } if (haveKakSource1) { - Crypto.GenerateKek(MasterKeys[i], KeyAreaKeyOceanSource, KeyAreaKeys[i][1], + CryptoOld.GenerateKek(MasterKeys[i], KeyAreaKeyOceanSource, KeyAreaKeys[i][1], AesKekGenerationSource, AesKeyGenerationSource); } if (haveKakSource2) { - Crypto.GenerateKek(MasterKeys[i], KeyAreaKeySystemSource, KeyAreaKeys[i][2], + CryptoOld.GenerateKek(MasterKeys[i], KeyAreaKeySystemSource, KeyAreaKeys[i][2], AesKekGenerationSource, AesKeyGenerationSource); } if (haveTitleKekSource) { - Crypto.DecryptEcb(MasterKeys[i], TitleKekSource, TitleKeks[i], 0x10); + CryptoOld.DecryptEcb(MasterKeys[i], TitleKekSource, TitleKeks[i], 0x10); } if (havePackage2KeySource) { - Crypto.DecryptEcb(MasterKeys[i], Package2KeySource, Package2Keys[i], 0x10); + CryptoOld.DecryptEcb(MasterKeys[i], Package2KeySource, Package2Keys[i], 0x10); } } } @@ -440,15 +440,15 @@ namespace LibHac var headerKek = new byte[0x10]; - Crypto.GenerateKek(MasterKeys[0], HeaderKekSource, headerKek, AesKekGenerationSource, + CryptoOld.GenerateKek(MasterKeys[0], HeaderKekSource, headerKek, AesKekGenerationSource, AesKeyGenerationSource); - Crypto.DecryptEcb(headerKek, HeaderKeySource, HeaderKey, 0x20); + CryptoOld.DecryptEcb(headerKek, HeaderKeySource, HeaderKey, 0x20); } public void DeriveSdCardKeys() { var sdKek = new byte[0x10]; - Crypto.GenerateKek(MasterKeys[0], SdCardKekSource, sdKek, AesKekGenerationSource, AesKeyGenerationSource); + CryptoOld.GenerateKek(MasterKeys[0], SdCardKekSource, sdKek, AesKekGenerationSource, AesKeyGenerationSource); for (int k = 0; k < SdCardKeyIdCount; k++) { @@ -460,7 +460,7 @@ namespace LibHac for (int k = 0; k < SdCardKeyIdCount; k++) { - Crypto.DecryptEcb(sdKek, SdCardKeySourcesSpecific[k], SdCardKeys[k], 0x20); + CryptoOld.DecryptEcb(sdKek, SdCardKeySourcesSpecific[k], SdCardKeys[k], 0x20); } // Derive sd card save key @@ -473,8 +473,8 @@ namespace LibHac keySource[i] = (byte)(SaveMacSdCardKeySource[i] ^ SdSeed[i]); } - Crypto.GenerateKek(MasterKeys[0], SaveMacSdCardKekSource, sdKek, AesKekGenerationSource, null); - Crypto.DecryptEcb(sdKek, keySource, SaveMacSdCardKey, 0x10); + CryptoOld.GenerateKek(MasterKeys[0], SaveMacSdCardKekSource, sdKek, AesKekGenerationSource, null); + CryptoOld.DecryptEcb(sdKek, keySource, SaveMacSdCardKey, 0x10); } } diff --git a/src/LibHac/Npdm/Acid.cs b/src/LibHac/Npdm/Acid.cs index 2e575031..f332781b 100644 --- a/src/LibHac/Npdm/Acid.cs +++ b/src/LibHac/Npdm/Acid.cs @@ -44,7 +44,7 @@ namespace LibHac.Npdm { reader.BaseStream.Position = offset + 0x100; byte[] signatureData = reader.ReadBytes(Size); - SignatureValidity = Crypto.Rsa2048PssVerify(signatureData, Rsa2048Signature, keyset.AcidFixedKeyModulus); + SignatureValidity = CryptoOld.Rsa2048PssVerify(signatureData, Rsa2048Signature, keyset.AcidFixedKeyModulus); } reader.BaseStream.Position = offset + 0x208; diff --git a/src/LibHac/Package2.cs b/src/LibHac/Package2.cs index 9e9cf4c6..24e7903a 100644 --- a/src/LibHac/Package2.cs +++ b/src/LibHac/Package2.cs @@ -151,7 +151,7 @@ namespace LibHac Signature = reader.ReadBytes(0x100); byte[] sigData = reader.ReadBytes(0x100); - SignatureValidity = Crypto.Rsa2048PssVerify(sigData, Signature, keyset.Package2FixedKeyModulus); + SignatureValidity = CryptoOld.Rsa2048PssVerify(sigData, Signature, keyset.Package2FixedKeyModulus); reader.BaseStream.Position -= 0x100; Counter = reader.ReadBytes(0x10); diff --git a/src/LibHac/Ticket.cs b/src/LibHac/Ticket.cs index ad81becd..89156684 100644 --- a/src/LibHac/Ticket.cs +++ b/src/LibHac/Ticket.cs @@ -153,7 +153,7 @@ namespace LibHac return commonKey; } - return Crypto.DecryptTitleKey(TitleKeyBlock, keyset.EticketExtKeyRsa); + return CryptoOld.DecryptTitleKey(TitleKeyBlock, keyset.EticketExtKeyRsa); } } diff --git a/src/LibHac/XciHeader.cs b/src/LibHac/XciHeader.cs index 361dcad8..899edac6 100644 --- a/src/LibHac/XciHeader.cs +++ b/src/LibHac/XciHeader.cs @@ -83,7 +83,7 @@ namespace LibHac byte[] sigData = reader.ReadBytes(SignatureSize); reader.BaseStream.Position = SignatureSize + 4; - SignatureValidity = Crypto.Rsa2048Pkcs1Verify(sigData, Signature, _xciHeaderPubk); + SignatureValidity = CryptoOld.Rsa2048Pkcs1Verify(sigData, Signature, _xciHeaderPubk); RomAreaStartPage = reader.ReadInt32(); BackupAreaStartPage = reader.ReadInt32(); @@ -95,12 +95,12 @@ namespace LibHac Flags = (GameCardAttribute)reader.ReadByte(); PackageId = reader.ReadUInt64(); ValidDataEndPage = reader.ReadInt64(); - AesCbcIv = reader.ReadBytes(Crypto.Aes128Size); + AesCbcIv = reader.ReadBytes(CryptoOld.Aes128Size); Array.Reverse(AesCbcIv); RootPartitionOffset = reader.ReadInt64(); RootPartitionHeaderSize = reader.ReadInt64(); - RootPartitionHeaderHash = reader.ReadBytes(Crypto.Sha256DigestSize); - InitialDataHash = reader.ReadBytes(Crypto.Sha256DigestSize); + RootPartitionHeaderHash = reader.ReadBytes(CryptoOld.Sha256DigestSize); + InitialDataHash = reader.ReadBytes(CryptoOld.Sha256DigestSize); SelSec = reader.ReadInt32(); SelT1Key = reader.ReadInt32(); SelKey = reader.ReadInt32(); @@ -110,7 +110,7 @@ namespace LibHac { byte[] encHeader = reader.ReadBytes(EncryptedHeaderSize); var decHeader = new byte[EncryptedHeaderSize]; - Crypto.DecryptCbc(keyset.XciHeaderKey, AesCbcIv, encHeader, decHeader, EncryptedHeaderSize); + CryptoOld.DecryptCbc(keyset.XciHeaderKey, AesCbcIv, encHeader, decHeader, EncryptedHeaderSize); using (var decreader = new BinaryReader(new MemoryStream(decHeader))) { @@ -128,10 +128,10 @@ namespace LibHac } } - ImageHash = Crypto.ComputeSha256(sigData, 0, sigData.Length); + ImageHash = CryptoOld.ComputeSha256(sigData, 0, sigData.Length); reader.BaseStream.Position = RootPartitionOffset; - PartitionFsHeaderValidity = Crypto.CheckMemoryHashTable(reader.ReadBytes((int)RootPartitionHeaderSize), RootPartitionHeaderHash, 0, (int)RootPartitionHeaderSize); + PartitionFsHeaderValidity = CryptoOld.CheckMemoryHashTable(reader.ReadBytes((int)RootPartitionHeaderSize), RootPartitionHeaderHash, 0, (int)RootPartitionHeaderSize); } } } diff --git a/src/hactoolnet/ProcessBench.cs b/src/hactoolnet/ProcessBench.cs index 47510d4d..9ab0228c 100644 --- a/src/hactoolnet/ProcessBench.cs +++ b/src/hactoolnet/ProcessBench.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using System.Linq; using LibHac; -using LibHac.Crypto2; +using LibHac.Crypto; using LibHac.Fs; using LibHac.FsSystem; diff --git a/tests/LibHac.Tests/AesCmac.cs b/tests/LibHac.Tests/AesCmac.cs index c51f9a95..9caf2315 100644 --- a/tests/LibHac.Tests/AesCmac.cs +++ b/tests/LibHac.Tests/AesCmac.cs @@ -57,7 +57,7 @@ namespace LibHac.Tests { var actual = new byte[0x10]; - Crypto.CalculateAesCmac(data.Key, data.Message, data.Start, actual, 0, data.Length); + CryptoOld.CalculateAesCmac(data.Key, data.Message, data.Start, actual, 0, data.Length); Assert.Equal(data.Expected, actual); } diff --git a/tests/LibHac.Tests/CryptoTests/AesCbcTests.cs b/tests/LibHac.Tests/CryptoTests/AesCbcTests.cs index 9fa026a3..86645f56 100644 --- a/tests/LibHac.Tests/CryptoTests/AesCbcTests.cs +++ b/tests/LibHac.Tests/CryptoTests/AesCbcTests.cs @@ -1,4 +1,4 @@ -using LibHac.Crypto2; +using LibHac.Crypto; using Xunit; namespace LibHac.Tests.CryptoTests diff --git a/tests/LibHac.Tests/CryptoTests/AesCtrTests.cs b/tests/LibHac.Tests/CryptoTests/AesCtrTests.cs index 697bb208..d2563155 100644 --- a/tests/LibHac.Tests/CryptoTests/AesCtrTests.cs +++ b/tests/LibHac.Tests/CryptoTests/AesCtrTests.cs @@ -1,4 +1,4 @@ -using LibHac.Crypto2; +using LibHac.Crypto; using Xunit; namespace LibHac.Tests.CryptoTests diff --git a/tests/LibHac.Tests/CryptoTests/AesEcbTests.cs b/tests/LibHac.Tests/CryptoTests/AesEcbTests.cs index 79102ce1..c424639c 100644 --- a/tests/LibHac.Tests/CryptoTests/AesEcbTests.cs +++ b/tests/LibHac.Tests/CryptoTests/AesEcbTests.cs @@ -1,4 +1,4 @@ -using LibHac.Crypto2; +using LibHac.Crypto; using Xunit; namespace LibHac.Tests.CryptoTests diff --git a/tests/LibHac.Tests/CryptoTests/AesIntrinsicsRequiredTheory.cs b/tests/LibHac.Tests/CryptoTests/AesIntrinsicsRequiredTheory.cs index d84ee178..857e827d 100644 --- a/tests/LibHac.Tests/CryptoTests/AesIntrinsicsRequiredTheory.cs +++ b/tests/LibHac.Tests/CryptoTests/AesIntrinsicsRequiredTheory.cs @@ -1,4 +1,4 @@ -using LibHac.Crypto2; +using LibHac.Crypto; using Xunit; namespace LibHac.Tests.CryptoTests diff --git a/tests/LibHac.Tests/CryptoTests/AesXtsTests.cs b/tests/LibHac.Tests/CryptoTests/AesXtsTests.cs index 818b0394..489fc9d1 100644 --- a/tests/LibHac.Tests/CryptoTests/AesXtsTests.cs +++ b/tests/LibHac.Tests/CryptoTests/AesXtsTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; -using LibHac.Crypto2; +using LibHac.Crypto; using Xunit; namespace LibHac.Tests.CryptoTests diff --git a/tests/LibHac.Tests/CryptoTests/Common.cs b/tests/LibHac.Tests/CryptoTests/Common.cs index a4a9b833..3c7f915c 100644 --- a/tests/LibHac.Tests/CryptoTests/Common.cs +++ b/tests/LibHac.Tests/CryptoTests/Common.cs @@ -1,4 +1,4 @@ -using LibHac.Crypto2; +using LibHac.Crypto; using Xunit; namespace LibHac.Tests.CryptoTests