mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Handle Terra card header hashes in XciHeader
This commit is contained in:
parent
f0477a87dc
commit
a8bb53fc68
1 changed files with 13 additions and 2 deletions
|
@ -10,6 +10,7 @@ using LibHac.Fs;
|
|||
using LibHac.Gc.Impl;
|
||||
using LibHac.Tools.Crypto;
|
||||
using LibHac.Tools.FsSystem;
|
||||
using LibHac.Util;
|
||||
using Aes = LibHac.Crypto.Aes;
|
||||
|
||||
namespace LibHac.Tools.Fs;
|
||||
|
@ -177,9 +178,19 @@ public class XciHeader
|
|||
|
||||
reader.BaseStream.Position = RootPartitionOffset;
|
||||
byte[] headerBytes = reader.ReadBytes((int)RootPartitionHeaderSize);
|
||||
|
||||
Span<byte> actualHeaderHash = stackalloc byte[Sha256.DigestSize];
|
||||
Sha256.GenerateSha256Hash(headerBytes, actualHeaderHash);
|
||||
|
||||
Optional<byte> salt = CompatibilityType == 0 ? new Optional<byte>() : CompatibilityType;
|
||||
|
||||
var generator = new Sha256Generator();
|
||||
generator.Initialize();
|
||||
generator.Update(headerBytes);
|
||||
if (salt.HasValue)
|
||||
{
|
||||
generator.Update(SpanHelpers.AsReadOnlyByteSpan(in salt.ValueRo));
|
||||
}
|
||||
|
||||
generator.GetHash(actualHeaderHash);
|
||||
|
||||
PartitionFsHeaderValidity = Utilities.SpansEqual(RootPartitionHeaderHash, actualHeaderHash) ? Validity.Valid : Validity.Invalid;
|
||||
|
||||
|
|
Loading…
Reference in a new issue