Ejemplo n.º 1
0
        private void DecryptHeader(ReadOnlySpan <byte> key, ref Package2Meta source, ref Package2Meta dest)
        {
            Buffer16 iv = source.HeaderIv;

            Aes.DecryptCtr128(SpanHelpers.AsByteSpan(ref source), SpanHelpers.AsByteSpan(ref dest), key, iv);

            // Copy the IV to the output because the IV field will be garbage after "decrypting" it
            Unsafe.As <Package2Meta, Buffer16>(ref dest) = iv;
        }
Ejemplo n.º 2
0
        private static void DecryptKeyBlobs(KeySet s, IProgressReport logger = null)
        {
            var cmac = new AesCmac();

            for (int i = 0; i < KeySet.UsedKeyBlobCount; i++)
            {
                if (s.KeyBlobKeys[i].IsZeros() || s.KeyBlobMacKeys[i].IsZeros() || s.EncryptedKeyBlobs[i].IsZeros())
                {
                    continue;
                }

                Aes.CalculateCmac(cmac, s.EncryptedKeyBlobs[i].Bytes.Slice(0x10, 0xA0), s.KeyBlobMacKeys[i]);

                if (!Utilities.SpansEqual <byte>(cmac, s.EncryptedKeyBlobs[i].Cmac))
                {
                    logger?.LogMessage($"Warning: Keyblob MAC {i:x2} is invalid. Are SBK/TSEC key correct?");
                }

                Aes.DecryptCtr128(s.EncryptedKeyBlobs[i].Bytes.Slice(0x20), s.KeyBlobs[i].Bytes, s.KeyBlobKeys[i],
                                  s.EncryptedKeyBlobs[i].Counter);
            }
        }