summaryrefslogtreecommitdiff
path: root/LibTSforge/Crypto
diff options
context:
space:
mode:
authorLyssa2025-04-07 15:19:24 +0000
committerLyssa2025-04-07 15:19:24 +0000
commit0c8b1efaa9005de1d101ebab5e66117edfaec3b2 (patch)
tree3f5fe837f2ec9cbe20238bdf9ced357f3ec1184e /LibTSforge/Crypto
parent3f1c87831802817f0cb3effacde954d3cbadfb6c (diff)
downloadTSforge-0c8b1efaa9005de1d101ebab5e66117edfaec3b2.zip
Minor fixups
Diffstat (limited to 'LibTSforge/Crypto')
-rw-r--r--LibTSforge/Crypto/PhysStoreCrypto.cs38
1 files changed, 19 insertions, 19 deletions
diff --git a/LibTSforge/Crypto/PhysStoreCrypto.cs b/LibTSforge/Crypto/PhysStoreCrypto.cs
index b0acc2e..083841d 100644
--- a/LibTSforge/Crypto/PhysStoreCrypto.cs
+++ b/LibTSforge/Crypto/PhysStoreCrypto.cs
@@ -18,31 +18,31 @@ namespace LibTSforge.Crypto
if (CryptoUtils.RSAVerifySignature(rsaKey, encAesKey, aesKeySig))
{
- byte[] aesKey = CryptoUtils.RSADecrypt(rsaKey, encAesKey);
- byte[] decData = CryptoUtils.AESDecrypt(br.ReadBytes((int)br.BaseStream.Length - 0x110), aesKey);
- byte[] hmacKey = decData.Take(0x10).ToArray(); // SHA-1 salt on Vista
- byte[] hmacSig = decData.Skip(0x10).Take(0x14).ToArray(); // SHA-1 hash on Vista
- byte[] psData = decData.Skip(0x28).ToArray();
+ throw new Exception("Failed to decrypt physical store.");
+ }
+
+ byte[] aesKey = CryptoUtils.RSADecrypt(rsaKey, encAesKey);
+ byte[] decData = CryptoUtils.AESDecrypt(br.ReadBytes((int)br.BaseStream.Length - 0x110), aesKey);
+ byte[] hmacKey = decData.Take(0x10).ToArray(); // SHA-1 salt on Vista
+ byte[] hmacSig = decData.Skip(0x10).Take(0x14).ToArray(); // SHA-1 hash on Vista
+ byte[] psData = decData.Skip(0x28).ToArray();
- if (version != PSVersion.Vista)
+ if (version != PSVersion.Vista)
+ {
+ if (!CryptoUtils.HMACVerify(hmacKey, psData, hmacSig))
{
- if (!CryptoUtils.HMACVerify(hmacKey, psData, hmacSig))
- {
- throw new InvalidDataException("Failed to verify HMAC. Physical store is corrupt.");
- }
+ throw new InvalidDataException("Failed to verify HMAC. Physical store is corrupt.");
}
- else
+ }
+ else
+ {
+ if (!CryptoUtils.SaltSHAVerify(hmacKey, psData, hmacSig))
{
- if (!CryptoUtils.SaltSHAVerify(hmacKey, psData, hmacSig))
- {
- throw new InvalidDataException("Failed to verify checksum. Physical store is corrupt.");
- }
+ throw new InvalidDataException("Failed to verify checksum. Physical store is corrupt.");
}
-
- return psData;
}
- throw new Exception("Failed to decrypt physical store.");
+ return psData;
}
public static byte[] EncryptPhysicalStore(byte[] data, bool production, PSVersion version)
@@ -65,7 +65,7 @@ namespace LibTSforge.Crypto
byte[] aesKeySig = CryptoUtils.RSASign(rsaKey, encAesKey);
byte[] hmacSig = version != PSVersion.Vista ? CryptoUtils.HMACSign(hmacKey, data) : CryptoUtils.SaltSHASum(hmacKey, data);
- byte[] decData = new byte[] { };
+ byte[] decData = { };
decData = decData.Concat(hmacKey).Concat(hmacSig).Concat(BitConverter.GetBytes(0)).Concat(data).ToArray();
byte[] encData = CryptoUtils.AESEncrypt(decData, aesKey);