mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Rename Crypto namespace
This commit is contained in:
parent
488bd8e682
commit
2f4453404f
42 changed files with 92 additions and 94 deletions
|
@ -20,7 +20,7 @@ namespace LibHac.Compatibility
|
||||||
SHA256 sha = SHA256.Create();
|
SHA256 sha = SHA256.Create();
|
||||||
var message = new byte[rsaLen];
|
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();
|
byte[] decBytes = decInt.ToByteArray();
|
||||||
|
|
||||||
if (decBytes[0] != 0xBC) return false;
|
if (decBytes[0] != 0xBC) return false;
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
// ReSharper disable AssignmentIsFullyDiscarded
|
// ReSharper disable AssignmentIsFullyDiscarded
|
||||||
using System;
|
using System;
|
||||||
|
using LibHac.Crypto.Detail;
|
||||||
#if HAS_INTRINSICS
|
#if HAS_INTRINSICS
|
||||||
using LibHac.Crypto2.Detail;
|
|
||||||
|
|
||||||
using AesNi = System.Runtime.Intrinsics.X86.Aes;
|
using AesNi = System.Runtime.Intrinsics.X86.Aes;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace LibHac.Crypto2
|
namespace LibHac.Crypto
|
||||||
{
|
{
|
||||||
public static class Aes
|
public static class Aes
|
||||||
{
|
{
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using LibHac.Crypto2.Detail;
|
using LibHac.Crypto.Detail;
|
||||||
|
|
||||||
namespace LibHac.Crypto2
|
namespace LibHac.Crypto
|
||||||
{
|
{
|
||||||
public class AesCbcEncryptor : ICipher
|
public class AesCbcEncryptor : ICipher
|
||||||
{
|
{
|
|
@ -1,8 +1,8 @@
|
||||||
#if HAS_INTRINSICS
|
#if HAS_INTRINSICS
|
||||||
using System;
|
using System;
|
||||||
using LibHac.Crypto2.Detail;
|
using LibHac.Crypto.Detail;
|
||||||
|
|
||||||
namespace LibHac.Crypto2
|
namespace LibHac.Crypto
|
||||||
{
|
{
|
||||||
public struct AesCbcEncryptorNi : ICipher
|
public struct AesCbcEncryptorNi : ICipher
|
||||||
{
|
{
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using LibHac.Crypto2.Detail;
|
using LibHac.Crypto.Detail;
|
||||||
|
|
||||||
namespace LibHac.Crypto2
|
namespace LibHac.Crypto
|
||||||
{
|
{
|
||||||
public class AesCtrCipher : ICipher
|
public class AesCtrCipher : ICipher
|
||||||
{
|
{
|
|
@ -1,8 +1,8 @@
|
||||||
#if HAS_INTRINSICS
|
#if HAS_INTRINSICS
|
||||||
using System;
|
using System;
|
||||||
using LibHac.Crypto2.Detail;
|
using LibHac.Crypto.Detail;
|
||||||
|
|
||||||
namespace LibHac.Crypto2
|
namespace LibHac.Crypto
|
||||||
{
|
{
|
||||||
public class AesCtrCipherNi : ICipher
|
public class AesCtrCipherNi : ICipher
|
||||||
{
|
{
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using LibHac.Crypto2.Detail;
|
using LibHac.Crypto.Detail;
|
||||||
|
|
||||||
namespace LibHac.Crypto2
|
namespace LibHac.Crypto
|
||||||
{
|
{
|
||||||
public class AesEcbEncryptor : ICipher
|
public class AesEcbEncryptor : ICipher
|
||||||
{
|
{
|
|
@ -1,8 +1,8 @@
|
||||||
#if HAS_INTRINSICS
|
#if HAS_INTRINSICS
|
||||||
using System;
|
using System;
|
||||||
using LibHac.Crypto2.Detail;
|
using LibHac.Crypto.Detail;
|
||||||
|
|
||||||
namespace LibHac.Crypto2
|
namespace LibHac.Crypto
|
||||||
{
|
{
|
||||||
public class AesEcbEncryptorNi : ICipher
|
public class AesEcbEncryptorNi : ICipher
|
||||||
{
|
{
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using LibHac.Crypto2.Detail;
|
using LibHac.Crypto.Detail;
|
||||||
|
|
||||||
namespace LibHac.Crypto2
|
namespace LibHac.Crypto
|
||||||
{
|
{
|
||||||
public class AesXtsEncryptor : ICipher
|
public class AesXtsEncryptor : ICipher
|
||||||
{
|
{
|
|
@ -1,8 +1,8 @@
|
||||||
#if HAS_INTRINSICS
|
#if HAS_INTRINSICS
|
||||||
using System;
|
using System;
|
||||||
using LibHac.Crypto2.Detail;
|
using LibHac.Crypto.Detail;
|
||||||
|
|
||||||
namespace LibHac.Crypto2
|
namespace LibHac.Crypto
|
||||||
{
|
{
|
||||||
public class AesXtsEncryptorNi : ICipher
|
public class AesXtsEncryptorNi : ICipher
|
||||||
{
|
{
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace LibHac.Crypto2.Detail
|
namespace LibHac.Crypto.Detail
|
||||||
{
|
{
|
||||||
public struct AesCbcMode
|
public struct AesCbcMode
|
||||||
{
|
{
|
|
@ -6,7 +6,7 @@ using System.Runtime.InteropServices;
|
||||||
using System.Runtime.Intrinsics;
|
using System.Runtime.Intrinsics;
|
||||||
using System.Runtime.Intrinsics.X86;
|
using System.Runtime.Intrinsics.X86;
|
||||||
|
|
||||||
namespace LibHac.Crypto2.Detail
|
namespace LibHac.Crypto.Detail
|
||||||
{
|
{
|
||||||
public struct AesCbcModeNi
|
public struct AesCbcModeNi
|
||||||
{
|
{
|
|
@ -3,7 +3,7 @@ using System.Diagnostics;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using LibHac.Common;
|
using LibHac.Common;
|
||||||
|
|
||||||
namespace LibHac.Crypto2.Detail
|
namespace LibHac.Crypto.Detail
|
||||||
{
|
{
|
||||||
public struct AesCore
|
public struct AesCore
|
||||||
{
|
{
|
|
@ -8,7 +8,7 @@ using System.Runtime.Intrinsics.X86;
|
||||||
|
|
||||||
using AesNi = System.Runtime.Intrinsics.X86.Aes;
|
using AesNi = System.Runtime.Intrinsics.X86.Aes;
|
||||||
|
|
||||||
namespace LibHac.Crypto2.Detail
|
namespace LibHac.Crypto.Detail
|
||||||
{
|
{
|
||||||
[StructLayout(LayoutKind.Sequential, Size = RoundKeyCount * RoundKeySize)]
|
[StructLayout(LayoutKind.Sequential, Size = RoundKeyCount * RoundKeySize)]
|
||||||
public struct AesCoreNi
|
public struct AesCoreNi
|
|
@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using LibHac.Common;
|
using LibHac.Common;
|
||||||
|
|
||||||
namespace LibHac.Crypto2.Detail
|
namespace LibHac.Crypto.Detail
|
||||||
{
|
{
|
||||||
public struct AesCtrMode
|
public struct AesCtrMode
|
||||||
{
|
{
|
|
@ -6,7 +6,7 @@ using System.Runtime.InteropServices;
|
||||||
using System.Runtime.Intrinsics;
|
using System.Runtime.Intrinsics;
|
||||||
using System.Runtime.Intrinsics.X86;
|
using System.Runtime.Intrinsics.X86;
|
||||||
|
|
||||||
namespace LibHac.Crypto2.Detail
|
namespace LibHac.Crypto.Detail
|
||||||
{
|
{
|
||||||
public struct AesCtrModeNi
|
public struct AesCtrModeNi
|
||||||
{
|
{
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace LibHac.Crypto2.Detail
|
namespace LibHac.Crypto.Detail
|
||||||
{
|
{
|
||||||
public struct AesEcbMode
|
public struct AesEcbMode
|
||||||
{
|
{
|
|
@ -1,7 +1,7 @@
|
||||||
#if HAS_INTRINSICS
|
#if HAS_INTRINSICS
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace LibHac.Crypto2.Detail
|
namespace LibHac.Crypto.Detail
|
||||||
{
|
{
|
||||||
public struct AesEcbModeNi
|
public struct AesEcbModeNi
|
||||||
{
|
{
|
|
@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using LibHac.Common;
|
using LibHac.Common;
|
||||||
|
|
||||||
namespace LibHac.Crypto2.Detail
|
namespace LibHac.Crypto.Detail
|
||||||
{
|
{
|
||||||
public struct AesXtsMode
|
public struct AesXtsMode
|
||||||
{
|
{
|
|
@ -7,7 +7,7 @@ using System.Runtime.Intrinsics;
|
||||||
using System.Runtime.Intrinsics.X86;
|
using System.Runtime.Intrinsics.X86;
|
||||||
using LibHac.Common;
|
using LibHac.Common;
|
||||||
|
|
||||||
namespace LibHac.Crypto2.Detail
|
namespace LibHac.Crypto.Detail
|
||||||
{
|
{
|
||||||
public struct AesXtsModeNi
|
public struct AesXtsModeNi
|
||||||
{
|
{
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace LibHac.Crypto2
|
namespace LibHac.Crypto
|
||||||
{
|
{
|
||||||
public interface ICipher
|
public interface ICipher
|
||||||
{
|
{
|
|
@ -6,7 +6,7 @@ using LibHac.FsSystem;
|
||||||
|
|
||||||
namespace LibHac
|
namespace LibHac
|
||||||
{
|
{
|
||||||
public static class Crypto
|
public static class CryptoOld
|
||||||
{
|
{
|
||||||
internal const int Aes128Size = 0x10;
|
internal const int Aes128Size = 0x10;
|
||||||
internal const int Sha256DigestSize = 0x20;
|
internal const int Sha256DigestSize = 0x20;
|
|
@ -78,14 +78,14 @@ namespace LibHac.FsSystem
|
||||||
|
|
||||||
private void DecryptKeys()
|
private void DecryptKeys()
|
||||||
{
|
{
|
||||||
Crypto.DecryptEcb(Kek1, EncryptedKey1, DecryptedKey1, 0x10);
|
CryptoOld.DecryptEcb(Kek1, EncryptedKey1, DecryptedKey1, 0x10);
|
||||||
Crypto.DecryptEcb(Kek2, EncryptedKey2, DecryptedKey2, 0x10);
|
CryptoOld.DecryptEcb(Kek2, EncryptedKey2, DecryptedKey2, 0x10);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EncryptKeys()
|
private void EncryptKeys()
|
||||||
{
|
{
|
||||||
Crypto.EncryptEcb(Kek1, DecryptedKey1, EncryptedKey1, 0x10);
|
CryptoOld.EncryptEcb(Kek1, DecryptedKey1, EncryptedKey1, 0x10);
|
||||||
Crypto.EncryptEcb(Kek2, DecryptedKey2, EncryptedKey2, 0x10);
|
CryptoOld.EncryptEcb(Kek2, DecryptedKey2, EncryptedKey2, 0x10);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GenerateKek(byte[] kekSeed, string path)
|
private void GenerateKek(byte[] kekSeed, string path)
|
||||||
|
|
|
@ -36,9 +36,9 @@ namespace LibHac.FsSystem.NcaUtils
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] encryptedKey = Header.GetEncryptedKey(index).ToArray();
|
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;
|
return decryptedKey;
|
||||||
}
|
}
|
||||||
|
@ -60,9 +60,9 @@ namespace LibHac.FsSystem.NcaUtils
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] encryptedKey = accessKey.Value.ToArray();
|
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;
|
return decryptedKey;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ namespace LibHac.FsSystem.NcaUtils
|
||||||
var data = new byte[size];
|
var data = new byte[size];
|
||||||
storage.Read(offset, data).ThrowIfFailure();
|
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;
|
if (Util.ArraysEqual(expectedHash, actualHash)) return Validity.Valid;
|
||||||
|
|
||||||
|
|
|
@ -151,8 +151,8 @@ namespace LibHac.FsSystem.NcaUtils
|
||||||
throw new ArgumentOutOfRangeException($"Key index must be between 0 and 3. Actual: {index}");
|
throw new ArgumentOutOfRangeException($"Key index must be between 0 and 3. Actual: {index}");
|
||||||
}
|
}
|
||||||
|
|
||||||
int offset = NcaHeaderStruct.KeyAreaOffset + Crypto.Aes128Size * index;
|
int offset = NcaHeaderStruct.KeyAreaOffset + CryptoOld.Aes128Size * index;
|
||||||
return _header.Span.Slice(offset, Crypto.Aes128Size);
|
return _header.Span.Slice(offset, CryptoOld.Aes128Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NcaFsHeader GetFsHeader(int index)
|
public NcaFsHeader GetFsHeader(int index)
|
||||||
|
@ -163,7 +163,7 @@ namespace LibHac.FsSystem.NcaUtils
|
||||||
// ReSharper disable once ImpureMethodCallOnReadonlyValueField
|
// ReSharper disable once ImpureMethodCallOnReadonlyValueField
|
||||||
Memory<byte> headerData = _header.Slice(offset, NcaHeaderStruct.FsHeaderSize);
|
Memory<byte> 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))
|
if (!Util.SpansEqual(expectedHash, actualHash))
|
||||||
{
|
{
|
||||||
|
@ -231,12 +231,12 @@ namespace LibHac.FsSystem.NcaUtils
|
||||||
|
|
||||||
public Validity VerifySignature1(byte[] modulus)
|
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)
|
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)]
|
[StructLayout(LayoutKind.Explicit, Size = 0xC00)]
|
||||||
|
|
|
@ -164,7 +164,7 @@ namespace LibHac.FsSystem
|
||||||
{
|
{
|
||||||
HashedRegionSize = reader.ReadInt32();
|
HashedRegionSize = reader.ReadInt32();
|
||||||
HashedRegionOffset = reader.ReadInt64();
|
HashedRegionOffset = reader.ReadInt64();
|
||||||
Hash = reader.ReadBytes(Crypto.Sha256DigestSize);
|
Hash = reader.ReadBytes(CryptoOld.Sha256DigestSize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -81,7 +81,7 @@ namespace LibHac.FsSystem.Save
|
||||||
|
|
||||||
MasterHash = storage.Slice(Layout.IvfcMasterHashOffsetA, Layout.IvfcMasterHashSize);
|
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);
|
SignatureValidity = ValidateSignature(keyset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ namespace LibHac.FsSystem.Save
|
||||||
{
|
{
|
||||||
var calculatedCmac = new byte[0x10];
|
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;
|
return Util.ArraysEqual(calculatedCmac, Cmac) ? Validity.Valid : Validity.Invalid;
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,7 +252,7 @@ namespace LibHac.FsSystem.Save
|
||||||
headerStream.Position = 0x300;
|
headerStream.Position = 0x300;
|
||||||
headerStream.Read(hashData, 0, hashData.Length);
|
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.Position = 0x108;
|
||||||
headerStream.Write(hash, 0, hash.Length);
|
headerStream.Write(hash, 0, hash.Length);
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ namespace LibHac.FsSystem.Save
|
||||||
headerStream.Position = 0x100;
|
headerStream.Position = 0x100;
|
||||||
headerStream.Read(cmacData, 0, 0x200);
|
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.Position = 0;
|
||||||
headerStream.Write(cmac, 0, 0x10);
|
headerStream.Write(cmac, 0, 0x10);
|
||||||
|
|
|
@ -272,12 +272,12 @@ namespace LibHac
|
||||||
{
|
{
|
||||||
if (KeyblobKeySources[i].IsEmpty()) continue;
|
if (KeyblobKeySources[i].IsEmpty()) continue;
|
||||||
|
|
||||||
Crypto.DecryptEcb(TsecKey, KeyblobKeySources[i], temp, 0x10);
|
CryptoOld.DecryptEcb(TsecKey, KeyblobKeySources[i], temp, 0x10);
|
||||||
Crypto.DecryptEcb(SecureBootKey, temp, KeyblobKeys[i], 0x10);
|
CryptoOld.DecryptEcb(SecureBootKey, temp, KeyblobKeys[i], 0x10);
|
||||||
|
|
||||||
if (!haveKeyblobMacKeySource) continue;
|
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);
|
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))
|
if (!Util.ArraysEqual(cmac, expectedCmac))
|
||||||
{
|
{
|
||||||
|
@ -329,7 +329,7 @@ namespace LibHac
|
||||||
{
|
{
|
||||||
if (TsecRootKeys[i - UsedKeyblobCount].IsEmpty() || MasterKekSources[i].IsEmpty()) continue;
|
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;
|
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
|
// Derive the device key
|
||||||
if (!PerConsoleKeySource.IsEmpty() && !KeyblobKeys[0].IsEmpty())
|
if (!PerConsoleKeySource.IsEmpty() && !KeyblobKeys[0].IsEmpty())
|
||||||
{
|
{
|
||||||
Crypto.DecryptEcb(KeyblobKeys[0], PerConsoleKeySource, DeviceKey, 0x10);
|
CryptoOld.DecryptEcb(KeyblobKeys[0], PerConsoleKeySource, DeviceKey, 0x10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Derive save key
|
// Derive save key
|
||||||
if (!SaveMacKekSource.IsEmpty() && !SaveMacKeySource.IsEmpty() && !DeviceKey.IsEmpty())
|
if (!SaveMacKekSource.IsEmpty() && !SaveMacKeySource.IsEmpty() && !DeviceKey.IsEmpty())
|
||||||
{
|
{
|
||||||
Crypto.GenerateKek(DeviceKey, SaveMacKekSource, kek, AesKekGenerationSource, null);
|
CryptoOld.GenerateKek(DeviceKey, SaveMacKekSource, kek, AesKekGenerationSource, null);
|
||||||
Crypto.DecryptEcb(kek, SaveMacKeySource, SaveMacKey, 0x10);
|
CryptoOld.DecryptEcb(kek, SaveMacKeySource, SaveMacKey, 0x10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Derive BIS keys
|
// Derive BIS keys
|
||||||
|
@ -378,14 +378,14 @@ namespace LibHac
|
||||||
Array.Copy(BisKeySource[2], BisKeySource[3], 0x20);
|
Array.Copy(BisKeySource[2], BisKeySource[3], 0x20);
|
||||||
}
|
}
|
||||||
|
|
||||||
Crypto.DecryptEcb(DeviceKey, RetailSpecificAesKeySource, kek, 0x10);
|
CryptoOld.DecryptEcb(DeviceKey, RetailSpecificAesKeySource, kek, 0x10);
|
||||||
if (!BisKeySource[0].IsEmpty()) Crypto.DecryptEcb(kek, BisKeySource[0], BisKeys[0], 0x20);
|
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++)
|
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)
|
if (haveKakSource0)
|
||||||
{
|
{
|
||||||
Crypto.GenerateKek(MasterKeys[i], KeyAreaKeyApplicationSource, KeyAreaKeys[i][0],
|
CryptoOld.GenerateKek(MasterKeys[i], KeyAreaKeyApplicationSource, KeyAreaKeys[i][0],
|
||||||
AesKekGenerationSource, AesKeyGenerationSource);
|
AesKekGenerationSource, AesKeyGenerationSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (haveKakSource1)
|
if (haveKakSource1)
|
||||||
{
|
{
|
||||||
Crypto.GenerateKek(MasterKeys[i], KeyAreaKeyOceanSource, KeyAreaKeys[i][1],
|
CryptoOld.GenerateKek(MasterKeys[i], KeyAreaKeyOceanSource, KeyAreaKeys[i][1],
|
||||||
AesKekGenerationSource, AesKeyGenerationSource);
|
AesKekGenerationSource, AesKeyGenerationSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (haveKakSource2)
|
if (haveKakSource2)
|
||||||
{
|
{
|
||||||
Crypto.GenerateKek(MasterKeys[i], KeyAreaKeySystemSource, KeyAreaKeys[i][2],
|
CryptoOld.GenerateKek(MasterKeys[i], KeyAreaKeySystemSource, KeyAreaKeys[i][2],
|
||||||
AesKekGenerationSource, AesKeyGenerationSource);
|
AesKekGenerationSource, AesKeyGenerationSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (haveTitleKekSource)
|
if (haveTitleKekSource)
|
||||||
{
|
{
|
||||||
Crypto.DecryptEcb(MasterKeys[i], TitleKekSource, TitleKeks[i], 0x10);
|
CryptoOld.DecryptEcb(MasterKeys[i], TitleKekSource, TitleKeks[i], 0x10);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (havePackage2KeySource)
|
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];
|
var headerKek = new byte[0x10];
|
||||||
|
|
||||||
Crypto.GenerateKek(MasterKeys[0], HeaderKekSource, headerKek, AesKekGenerationSource,
|
CryptoOld.GenerateKek(MasterKeys[0], HeaderKekSource, headerKek, AesKekGenerationSource,
|
||||||
AesKeyGenerationSource);
|
AesKeyGenerationSource);
|
||||||
Crypto.DecryptEcb(headerKek, HeaderKeySource, HeaderKey, 0x20);
|
CryptoOld.DecryptEcb(headerKek, HeaderKeySource, HeaderKey, 0x20);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeriveSdCardKeys()
|
public void DeriveSdCardKeys()
|
||||||
{
|
{
|
||||||
var sdKek = new byte[0x10];
|
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++)
|
for (int k = 0; k < SdCardKeyIdCount; k++)
|
||||||
{
|
{
|
||||||
|
@ -460,7 +460,7 @@ namespace LibHac
|
||||||
|
|
||||||
for (int k = 0; k < SdCardKeyIdCount; k++)
|
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
|
// Derive sd card save key
|
||||||
|
@ -473,8 +473,8 @@ namespace LibHac
|
||||||
keySource[i] = (byte)(SaveMacSdCardKeySource[i] ^ SdSeed[i]);
|
keySource[i] = (byte)(SaveMacSdCardKeySource[i] ^ SdSeed[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Crypto.GenerateKek(MasterKeys[0], SaveMacSdCardKekSource, sdKek, AesKekGenerationSource, null);
|
CryptoOld.GenerateKek(MasterKeys[0], SaveMacSdCardKekSource, sdKek, AesKekGenerationSource, null);
|
||||||
Crypto.DecryptEcb(sdKek, keySource, SaveMacSdCardKey, 0x10);
|
CryptoOld.DecryptEcb(sdKek, keySource, SaveMacSdCardKey, 0x10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace LibHac.Npdm
|
||||||
{
|
{
|
||||||
reader.BaseStream.Position = offset + 0x100;
|
reader.BaseStream.Position = offset + 0x100;
|
||||||
byte[] signatureData = reader.ReadBytes(Size);
|
byte[] signatureData = reader.ReadBytes(Size);
|
||||||
SignatureValidity = Crypto.Rsa2048PssVerify(signatureData, Rsa2048Signature, keyset.AcidFixedKeyModulus);
|
SignatureValidity = CryptoOld.Rsa2048PssVerify(signatureData, Rsa2048Signature, keyset.AcidFixedKeyModulus);
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.BaseStream.Position = offset + 0x208;
|
reader.BaseStream.Position = offset + 0x208;
|
||||||
|
|
|
@ -151,7 +151,7 @@ namespace LibHac
|
||||||
|
|
||||||
Signature = reader.ReadBytes(0x100);
|
Signature = reader.ReadBytes(0x100);
|
||||||
byte[] sigData = 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;
|
reader.BaseStream.Position -= 0x100;
|
||||||
Counter = reader.ReadBytes(0x10);
|
Counter = reader.ReadBytes(0x10);
|
||||||
|
|
|
@ -153,7 +153,7 @@ namespace LibHac
|
||||||
return commonKey;
|
return commonKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Crypto.DecryptTitleKey(TitleKeyBlock, keyset.EticketExtKeyRsa);
|
return CryptoOld.DecryptTitleKey(TitleKeyBlock, keyset.EticketExtKeyRsa);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ namespace LibHac
|
||||||
byte[] sigData = reader.ReadBytes(SignatureSize);
|
byte[] sigData = reader.ReadBytes(SignatureSize);
|
||||||
reader.BaseStream.Position = SignatureSize + 4;
|
reader.BaseStream.Position = SignatureSize + 4;
|
||||||
|
|
||||||
SignatureValidity = Crypto.Rsa2048Pkcs1Verify(sigData, Signature, _xciHeaderPubk);
|
SignatureValidity = CryptoOld.Rsa2048Pkcs1Verify(sigData, Signature, _xciHeaderPubk);
|
||||||
|
|
||||||
RomAreaStartPage = reader.ReadInt32();
|
RomAreaStartPage = reader.ReadInt32();
|
||||||
BackupAreaStartPage = reader.ReadInt32();
|
BackupAreaStartPage = reader.ReadInt32();
|
||||||
|
@ -95,12 +95,12 @@ namespace LibHac
|
||||||
Flags = (GameCardAttribute)reader.ReadByte();
|
Flags = (GameCardAttribute)reader.ReadByte();
|
||||||
PackageId = reader.ReadUInt64();
|
PackageId = reader.ReadUInt64();
|
||||||
ValidDataEndPage = reader.ReadInt64();
|
ValidDataEndPage = reader.ReadInt64();
|
||||||
AesCbcIv = reader.ReadBytes(Crypto.Aes128Size);
|
AesCbcIv = reader.ReadBytes(CryptoOld.Aes128Size);
|
||||||
Array.Reverse(AesCbcIv);
|
Array.Reverse(AesCbcIv);
|
||||||
RootPartitionOffset = reader.ReadInt64();
|
RootPartitionOffset = reader.ReadInt64();
|
||||||
RootPartitionHeaderSize = reader.ReadInt64();
|
RootPartitionHeaderSize = reader.ReadInt64();
|
||||||
RootPartitionHeaderHash = reader.ReadBytes(Crypto.Sha256DigestSize);
|
RootPartitionHeaderHash = reader.ReadBytes(CryptoOld.Sha256DigestSize);
|
||||||
InitialDataHash = reader.ReadBytes(Crypto.Sha256DigestSize);
|
InitialDataHash = reader.ReadBytes(CryptoOld.Sha256DigestSize);
|
||||||
SelSec = reader.ReadInt32();
|
SelSec = reader.ReadInt32();
|
||||||
SelT1Key = reader.ReadInt32();
|
SelT1Key = reader.ReadInt32();
|
||||||
SelKey = reader.ReadInt32();
|
SelKey = reader.ReadInt32();
|
||||||
|
@ -110,7 +110,7 @@ namespace LibHac
|
||||||
{
|
{
|
||||||
byte[] encHeader = reader.ReadBytes(EncryptedHeaderSize);
|
byte[] encHeader = reader.ReadBytes(EncryptedHeaderSize);
|
||||||
var decHeader = new byte[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)))
|
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;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using LibHac;
|
using LibHac;
|
||||||
using LibHac.Crypto2;
|
using LibHac.Crypto;
|
||||||
using LibHac.Fs;
|
using LibHac.Fs;
|
||||||
using LibHac.FsSystem;
|
using LibHac.FsSystem;
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ namespace LibHac.Tests
|
||||||
{
|
{
|
||||||
var actual = new byte[0x10];
|
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);
|
Assert.Equal(data.Expected, actual);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using LibHac.Crypto2;
|
using LibHac.Crypto;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace LibHac.Tests.CryptoTests
|
namespace LibHac.Tests.CryptoTests
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using LibHac.Crypto2;
|
using LibHac.Crypto;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace LibHac.Tests.CryptoTests
|
namespace LibHac.Tests.CryptoTests
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using LibHac.Crypto2;
|
using LibHac.Crypto;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace LibHac.Tests.CryptoTests
|
namespace LibHac.Tests.CryptoTests
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using LibHac.Crypto2;
|
using LibHac.Crypto;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace LibHac.Tests.CryptoTests
|
namespace LibHac.Tests.CryptoTests
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using LibHac.Crypto2;
|
using LibHac.Crypto;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace LibHac.Tests.CryptoTests
|
namespace LibHac.Tests.CryptoTests
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using LibHac.Crypto2;
|
using LibHac.Crypto;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace LibHac.Tests.CryptoTests
|
namespace LibHac.Tests.CryptoTests
|
||||||
|
|
Loading…
Reference in a new issue