mirror of
https://github.com/SabreTools/NDecrypt.git
synced 2026-07-08 18:06:38 +00:00
Update packages
This commit is contained in:
@@ -2,8 +2,9 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using SabreTools.Hashing;
|
using SabreTools.Hashing;
|
||||||
using SabreTools.IO.Extensions;
|
using SabreTools.Matching;
|
||||||
using SabreTools.Serialization.Wrappers;
|
using SabreTools.Numerics.Extensions;
|
||||||
|
using SabreTools.Wrappers;
|
||||||
|
|
||||||
namespace NDecrypt.Core
|
namespace NDecrypt.Core
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,9 +24,9 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="SabreTools.Hashing" Version="[1.6.1]" />
|
<PackageReference Include="SabreTools.Hashing" Version="[2.0.0]" />
|
||||||
<PackageReference Include="SabreTools.IO" Version="[1.9.1]" />
|
<PackageReference Include="SabreTools.IO" Version="[2.1.0]" />
|
||||||
<PackageReference Include="SabreTools.Serialization" Version="[2.3.0]" />
|
<PackageReference Include="SabreTools.Serialization" Version="[3.0.0]" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,101 +0,0 @@
|
|||||||
using System;
|
|
||||||
using SabreTools.Data.Models.N3DS;
|
|
||||||
using SabreTools.IO.Extensions;
|
|
||||||
|
|
||||||
namespace NDecrypt.Core
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Set of all keys associated with a partition
|
|
||||||
/// </summary>
|
|
||||||
internal class PartitionKeys
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Primary AES-CTR encryption key
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>Used for both EXE-FS and ROM-FS</remarks>
|
|
||||||
public byte[] NormalKey { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Secondary AES-CTR encryption key
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>Used for only EXE-FS</remarks>
|
|
||||||
public byte[] NormalKey2C { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// First 16 bytes of the RSA-2048 signature
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>Used as an XOR value during key generation</remarks>
|
|
||||||
private readonly byte[] KeyY;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create a new set of keys for a given partition
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="signature">RSA-2048 signature from the partition</param>
|
|
||||||
/// <param name="masks">BitMasks from the partition or backup header</param>
|
|
||||||
/// <param name="hardwareConstant">AES hardware constant to use</param>
|
|
||||||
/// <param name="keyX">KeyX value to assign based on crypto method and development status</param>
|
|
||||||
/// <param name="keyX0x2C">KeyX2C value to assign based on development status</param>
|
|
||||||
public PartitionKeys(byte[]? signature, BitMasks masks, byte[] hardwareConstant, byte[] keyX, byte[] keyX0x2C)
|
|
||||||
{
|
|
||||||
// Validate inputs
|
|
||||||
if (signature is not null && signature.Length < 16)
|
|
||||||
throw new ArgumentOutOfRangeException(nameof(signature), $"{nameof(signature)} must be at least 16 bytes");
|
|
||||||
|
|
||||||
// Backup headers can't have a KeyY value set
|
|
||||||
KeyY = new byte[16];
|
|
||||||
if (signature is not null)
|
|
||||||
Array.Copy(signature, KeyY, 16);
|
|
||||||
|
|
||||||
// Special case for zero-key
|
|
||||||
#if NET20 || NET35
|
|
||||||
if ((masks & BitMasks.FixedCryptoKey) > 0)
|
|
||||||
#else
|
|
||||||
if (masks.HasFlag(BitMasks.FixedCryptoKey))
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
Console.WriteLine("Encryption Method: Zero Key");
|
|
||||||
NormalKey = new byte[16];
|
|
||||||
NormalKey2C = new byte[16];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the standard normal key values
|
|
||||||
NormalKey = ProcessKey(keyX, KeyY, hardwareConstant);
|
|
||||||
NormalKey2C = ProcessKey(keyX0x2C, KeyY, hardwareConstant);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Set RomFS values based on the bit masks
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="masks">BitMasks from the partition or backup header</param>
|
|
||||||
/// <param name="hardwareConstant">AES hardware constant to use</param>
|
|
||||||
/// <param name="keyX0x2C">KeyX2C value to assign based on development status</param>
|
|
||||||
public void SetRomFSValues(BitMasks masks, byte[] hardwareConstant, byte[] keyX0x2C)
|
|
||||||
{
|
|
||||||
// NormalKey has a constant value for zero-key
|
|
||||||
#if NET20 || NET35
|
|
||||||
if ((masks & BitMasks.FixedCryptoKey) > 0)
|
|
||||||
#else
|
|
||||||
if (masks.HasFlag(BitMasks.FixedCryptoKey))
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
NormalKey = new byte[16];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encrypting RomFS for partitions 1 and up always use Key0x2C
|
|
||||||
NormalKey = ProcessKey(keyX0x2C, KeyY, hardwareConstant);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Process a key with the standard processing steps
|
|
||||||
/// </summary>
|
|
||||||
private static byte[] ProcessKey(byte[] keyBase, byte[] keyY, byte[] hardwareConstant)
|
|
||||||
{
|
|
||||||
byte[] processed = keyBase.RotateLeft(2);
|
|
||||||
processed = processed.Xor(keyY);
|
|
||||||
processed = processed.Add(hardwareConstant);
|
|
||||||
return processed.RotateLeft(87);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,7 @@ using System.IO;
|
|||||||
using NDecrypt.Core;
|
using NDecrypt.Core;
|
||||||
using SabreTools.CommandLine;
|
using SabreTools.CommandLine;
|
||||||
using SabreTools.CommandLine.Inputs;
|
using SabreTools.CommandLine.Inputs;
|
||||||
using SabreTools.IO.Extensions;
|
using SabreTools.Text.Extensions;
|
||||||
|
|
||||||
namespace NDecrypt.Features
|
namespace NDecrypt.Features
|
||||||
{
|
{
|
||||||
@@ -83,7 +83,7 @@ namespace NDecrypt.Features
|
|||||||
{
|
{
|
||||||
// Set default values for tools
|
// Set default values for tools
|
||||||
_tools[FileType.NDS] = new DSProcessor();
|
_tools[FileType.NDS] = new DSProcessor();
|
||||||
_tools[FileType.N3DS] = new ThreeDSProcessor(development: false);
|
_tools[FileType.N3DS] = new ThreeDSProcessor(new());
|
||||||
|
|
||||||
// Check the configuration path
|
// Check the configuration path
|
||||||
string? configPath = GetString(ConfigName, "config.json");
|
string? configPath = GetString(ConfigName, "config.json");
|
||||||
@@ -117,8 +117,9 @@ namespace NDecrypt.Features
|
|||||||
|
|
||||||
// Create the 3DS tool
|
// Create the 3DS tool
|
||||||
bool development = GetBoolean(DevelopmentName);
|
bool development = GetBoolean(DevelopmentName);
|
||||||
_tools[FileType.N3DS] = new ThreeDSProcessor(development)
|
var encryptionSettings = new SabreTools.Security.Cryptography.N3DSEncryptionSettings
|
||||||
{
|
{
|
||||||
|
Development = development,
|
||||||
AESHardwareConstant = config.AESHardwareConstant.FromHexString() ?? [],
|
AESHardwareConstant = config.AESHardwareConstant.FromHexString() ?? [],
|
||||||
KeyX0x18 = config.KeyX0x18.FromHexString() ?? [],
|
KeyX0x18 = config.KeyX0x18.FromHexString() ?? [],
|
||||||
KeyX0x1B = config.KeyX0x1B.FromHexString() ?? [],
|
KeyX0x1B = config.KeyX0x1B.FromHexString() ?? [],
|
||||||
@@ -129,6 +130,7 @@ namespace NDecrypt.Features
|
|||||||
DevKeyX0x25 = config.DevKeyX0x25.FromHexString() ?? [],
|
DevKeyX0x25 = config.DevKeyX0x25.FromHexString() ?? [],
|
||||||
DevKeyX0x2C = config.DevKeyX0x2C.FromHexString() ?? [],
|
DevKeyX0x2C = config.DevKeyX0x2C.FromHexString() ?? [],
|
||||||
};
|
};
|
||||||
|
_tools[FileType.N3DS] = new ThreeDSProcessor(encryptionSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user