public void kirk_CMD1(byte* outbuff, byte* inbuff, int size, bool do_check = true)
{
fixed (Crypto.AES_ctx* aes_kirk1_ptr = &_aes_kirk1)
{
check_initialized();
var header = *(AES128CMACHeader*)inbuff;
if (header.Mode != KirkMode.Cmd1)
{
//Console.Error.WriteLine("ResultEnum.PSP_KIRK_INVALID_MODE");
Console.Error.WriteLine("{0}", header.ToStringDefault(true));
Console.WriteLine("Input:");
ArrayUtils.HexDump(PointerUtils.PointerToByteArray(inbuff, 0x100));
Console.WriteLine("Output:");
ArrayUtils.HexDump(PointerUtils.PointerToByteArray(outbuff, 0x100));
throw (new KirkException(ResultEnum.PSP_KIRK_INVALID_MODE, String.Format("Expected mode Cmd1 but found {0}", header.Mode)));
}
Console.WriteLine("Input:");
ArrayUtils.HexDump(PointerUtils.PointerToByteArray(inbuff, 0x100));
//Console.WriteLine("header.DataOffset = 0x{0:X8}", header.DataOffset);
//Console.WriteLine("header.DataSize = 0x{0:X8}", header.DataSize);
// Decrypts AES and CMAC keys.
header_keys keys; //0-15 AES key, 16-31 CMAC key
#if USE_DOTNET_CRYPTO
DecryptAes(kirk1_key, inbuff, (byte*)&keys, 16 * 2); //decrypt AES & CMAC key to temp buffer
#else
Crypto.AES_cbc_decrypt(aes_kirk1_ptr, inbuff, (byte*)&keys, 16 * 2);
#endif
// HOAX WARRING! I have no idea why the hash check on last IPL block fails, so there is an option to disable checking
if (do_check)
{
kirk_CMD10(inbuff, size);
}
//var AES = new RijndaelManaged();
#if USE_DOTNET_CRYPTO
DecryptAes(
PointerUtils.PointerToByteArray(keys.AES, 16),
inbuff + sizeof(AES128CMACHeader) + header->DataOffset,
outbuff,
header->DataSize
);
#else
Crypto.AES_ctx k1;
Crypto.AES_set_key(&k1, keys.AES, 128);
Crypto.AES_cbc_decrypt(
ctx: &k1,
src: inbuff + sizeof(AES128CMACHeader) + header.DataOffset,
dst: outbuff,
size: header.DataSize
);
#endif
}
}