public kirk_CMD7 ( byte outbuff, byte inbuff, int size ) : void | ||
outbuff | byte | |
inbuff | byte | |
size | int | |
return | void |
public void kirk_CMD7(byte* outbuff, byte* inbuff, int size)
{
check_initialized();
var Header = (KIRK_AES128CBC_HEADER*)inbuff;
if (Header->Mode != KirkMode.DecryptCbc)
{
throw (new KirkException(ResultEnum.PSP_KIRK_INVALID_MODE));
}
if (Header->Datasize == 0)
{
throw (new KirkException(ResultEnum.PSP_KIRK_DATA_SIZE_IS_ZERO));
}
#if USE_DOTNET_CRYPTO
var Output = DecryptAes(
PointerUtils.PointerToByteArray(inbuff + sizeof(KIRK_AES128CBC_HEADER), size),
_kirk_4_7_get_key(Header->KeySeed)
);
PointerUtils.ByteArrayToPointer(Output, outbuff);
#else
kirk_4_7_get_key(Header->KeySeed, (key) =>
{
//Set the key
Crypto.AES_ctx aesKey;
Crypto.AES_set_key(&aesKey, key, 128);
Crypto.AES_cbc_decrypt(&aesKey, inbuff + sizeof(KIRK_AES128CBC_HEADER), outbuff, size);
});
#endif
}
public void TestCmd7() { var Kirk = new Kirk(); Kirk.kirk_init(); var _src = new byte[0x20 + 0x14]; var _dst = new byte[0x20]; var ExpectedOutput = new byte[] { 0xE4, 0x8B, 0x57, 0x4C, 0x6E, 0xAF, 0x62, 0x51, 0x5C, 0x44, 0x52, 0x1D, 0xBA, 0x7D, 0xD4, 0x32, 0xE4, 0x8B, 0x57, 0x4C, 0x6E, 0xAF, 0x62, 0x51, 0x5C, 0x44, 0x52, 0x1D, 0xBA, 0x7D, 0xD4, 0x32 }; fixed (byte* src = _src) fixed (byte* dst = _dst) { *(uint*)(&src[0x00]) = 5; // Mode *(uint*)(&src[0x0C]) = 0x03; // KeySeed *(uint*)(&src[0x10]) = 1; // DataSize Kirk.kirk_CMD7(dst, src, 0x20); Console.WriteLine("_src: {0}", BitConverter.ToString(_src)); Console.WriteLine("_dst: {0}", BitConverter.ToString(_dst)); CollectionAssert.AreEqual(ExpectedOutput, _dst); } }