2018-08-07 07:17:51 +00:00
|
|
|
#include <nn/hac/XciUtils.h>
|
2018-04-21 09:37:30 +00:00
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::XciUtils::getXciHeaderAesIv(const nn::hac::sXciHeader* hdr, byte_t* iv)
|
2018-04-21 09:37:30 +00:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
iv[15-i] = hdr->aescbc_iv.iv[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::XciUtils::decryptXciHeader(const byte_t* src, byte_t* dst, const byte_t* key)
|
2018-04-21 09:37:30 +00:00
|
|
|
{
|
|
|
|
byte_t iv[crypto::aes::kAesBlockSize];
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
getXciHeaderAesIv((const nn::hac::sXciHeader*)src, iv);
|
2018-04-21 09:37:30 +00:00
|
|
|
|
|
|
|
// copy plain
|
2018-08-07 07:17:51 +00:00
|
|
|
memcpy(dst, src, nn::hac::xci::kHeaderEncOffset);
|
2018-04-21 09:37:30 +00:00
|
|
|
|
|
|
|
// decrypt encrypted data
|
2018-08-07 07:17:51 +00:00
|
|
|
crypto::aes::AesCbcDecrypt(src + nn::hac::xci::kHeaderEncOffset, nn::hac::xci::kHeaderEncSize, key, iv, dst + nn::hac::xci::kHeaderEncOffset);
|
2018-04-21 09:37:30 +00:00
|
|
|
}
|