2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:09:55 +00:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2017-03-03 19:43:52 +00:00
|
|
|
#include "DiscIO/VolumeWiiCrypted.h"
|
|
|
|
|
2015-04-21 09:24:13 +00:00
|
|
|
#include <algorithm>
|
2014-02-21 00:47:53 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstring>
|
2015-04-09 15:44:53 +00:00
|
|
|
#include <map>
|
2016-06-24 08:43:46 +00:00
|
|
|
#include <mbedtls/aes.h>
|
|
|
|
#include <mbedtls/sha1.h>
|
2015-08-31 23:27:18 +00:00
|
|
|
#include <memory>
|
2014-02-21 00:47:53 +00:00
|
|
|
#include <string>
|
2015-08-31 23:27:18 +00:00
|
|
|
#include <utility>
|
2014-02-21 00:47:53 +00:00
|
|
|
#include <vector>
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2016-10-30 22:39:12 +00:00
|
|
|
#include "Common/Assert.h"
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-09-19 04:17:41 +00:00
|
|
|
#include "Common/Logging/Log.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "Common/MsgHandler.h"
|
2017-03-03 19:43:52 +00:00
|
|
|
#include "Common/Swap.h"
|
|
|
|
|
2014-02-21 00:47:53 +00:00
|
|
|
#include "DiscIO/Blob.h"
|
2016-07-06 18:33:05 +00:00
|
|
|
#include "DiscIO/Enums.h"
|
2015-04-10 21:18:41 +00:00
|
|
|
#include "DiscIO/Filesystem.h"
|
2014-02-21 00:47:53 +00:00
|
|
|
#include "DiscIO/Volume.h"
|
2014-05-29 10:38:39 +00:00
|
|
|
#include "DiscIO/VolumeCreator.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
namespace DiscIO
|
|
|
|
{
|
2015-08-31 23:27:18 +00:00
|
|
|
CVolumeWiiCrypted::CVolumeWiiCrypted(std::unique_ptr<IBlobReader> reader, u64 _VolumeOffset,
|
2016-06-24 08:43:46 +00:00
|
|
|
const unsigned char* _pVolumeKey)
|
|
|
|
: m_pReader(std::move(reader)), m_AES_ctx(std::make_unique<mbedtls_aes_context>()),
|
2015-04-21 09:17:39 +00:00
|
|
|
m_VolumeOffset(_VolumeOffset), m_dataOffset(0x20000), m_last_decrypted_block(-1)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-10-30 22:39:12 +00:00
|
|
|
_assert_(m_pReader);
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
mbedtls_aes_setkey_dec(m_AES_ctx.get(), _pVolumeKey, 128);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2014-05-29 10:38:39 +00:00
|
|
|
bool CVolumeWiiCrypted::ChangePartition(u64 offset)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_VolumeOffset = offset;
|
2014-05-29 10:38:39 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
u8 volume_key[16];
|
|
|
|
DiscIO::VolumeKeyForPartition(*m_pReader, offset, volume_key);
|
|
|
|
mbedtls_aes_setkey_dec(m_AES_ctx.get(), volume_key, 128);
|
|
|
|
return true;
|
2014-05-29 10:38:39 +00:00
|
|
|
}
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
CVolumeWiiCrypted::~CVolumeWiiCrypted()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-12-28 09:35:48 +00:00
|
|
|
bool CVolumeWiiCrypted::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer, bool decrypt) const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (!decrypt)
|
|
|
|
return m_pReader->Read(_ReadOffset, _Length, _pBuffer);
|
|
|
|
|
2017-02-10 15:56:40 +00:00
|
|
|
std::vector<u8> read_buffer(BLOCK_TOTAL_SIZE);
|
2016-06-24 08:43:46 +00:00
|
|
|
while (_Length > 0)
|
|
|
|
{
|
2015-04-21 09:17:39 +00:00
|
|
|
// Calculate offsets
|
|
|
|
u64 block_offset_on_disc =
|
|
|
|
m_VolumeOffset + m_dataOffset + _ReadOffset / BLOCK_DATA_SIZE * BLOCK_TOTAL_SIZE;
|
|
|
|
u64 data_offset_in_block = _ReadOffset % BLOCK_DATA_SIZE;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-04-21 09:17:39 +00:00
|
|
|
if (m_last_decrypted_block != block_offset_on_disc)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
// Read the current block
|
2015-04-21 09:17:39 +00:00
|
|
|
if (!m_pReader->Read(block_offset_on_disc, BLOCK_TOTAL_SIZE, read_buffer.data()))
|
2016-06-24 08:43:46 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Decrypt the block's data.
|
2015-04-21 09:17:39 +00:00
|
|
|
// 0x3D0 - 0x3DF in read_buffer will be overwritten,
|
2016-06-24 08:43:46 +00:00
|
|
|
// but that won't affect anything, because we won't
|
2015-04-21 09:17:39 +00:00
|
|
|
// use the content of read_buffer anymore after this
|
2017-02-10 15:56:40 +00:00
|
|
|
mbedtls_aes_crypt_cbc(m_AES_ctx.get(), MBEDTLS_AES_DECRYPT, BLOCK_DATA_SIZE,
|
|
|
|
&read_buffer[0x3D0], &read_buffer[BLOCK_HEADER_SIZE],
|
2015-04-21 09:17:39 +00:00
|
|
|
m_last_decrypted_block_data);
|
|
|
|
m_last_decrypted_block = block_offset_on_disc;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
// The only thing we currently use from the 0x000 - 0x3FF part
|
|
|
|
// of the block is the IV (at 0x3D0), but it also contains SHA-1
|
|
|
|
// hashes that IOS uses to check that discs aren't tampered with.
|
|
|
|
// http://wiibrew.org/wiki/Wii_Disc#Encrypted
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the decrypted data
|
2015-04-21 09:24:13 +00:00
|
|
|
u64 copy_size = std::min(_Length, BLOCK_DATA_SIZE - data_offset_in_block);
|
|
|
|
memcpy(_pBuffer, &m_last_decrypted_block_data[data_offset_in_block],
|
|
|
|
static_cast<size_t>(copy_size));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
// Update offsets
|
2015-04-21 09:24:13 +00:00
|
|
|
_Length -= copy_size;
|
|
|
|
_pBuffer += copy_size;
|
|
|
|
_ReadOffset += copy_size;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2015-09-22 17:25:54 +00:00
|
|
|
bool CVolumeWiiCrypted::GetTitleID(u64* buffer) const
|
2010-01-14 07:19:10 +00:00
|
|
|
{
|
2017-03-09 18:44:38 +00:00
|
|
|
return ReadSwapped(m_VolumeOffset + 0x1DC, buffer, false);
|
2010-01-14 07:19:10 +00:00
|
|
|
}
|
2014-12-03 09:54:09 +00:00
|
|
|
|
2017-02-26 16:26:08 +00:00
|
|
|
IOS::ES::TicketReader CVolumeWiiCrypted::GetTicket() const
|
|
|
|
{
|
|
|
|
std::vector<u8> buffer(0x2a4);
|
|
|
|
Read(m_VolumeOffset, buffer.size(), buffer.data(), false);
|
|
|
|
return IOS::ES::TicketReader{std::move(buffer)};
|
|
|
|
}
|
|
|
|
|
2017-02-11 07:57:47 +00:00
|
|
|
IOS::ES::TMDReader CVolumeWiiCrypted::GetTMD() const
|
2010-09-08 00:20:19 +00:00
|
|
|
{
|
2017-03-24 23:32:45 +00:00
|
|
|
u32 tmd_size = 0;
|
|
|
|
u32 tmd_address = 0;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-03-24 23:32:45 +00:00
|
|
|
if (!ReadSwapped(m_VolumeOffset + 0x2a4, &tmd_size, false))
|
|
|
|
return {};
|
|
|
|
if (!ReadSwapped(m_VolumeOffset + 0x2a8, &tmd_address, false))
|
|
|
|
return {};
|
2017-03-09 18:44:38 +00:00
|
|
|
tmd_address <<= 2;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
if (tmd_size > 1024 * 1024 * 4)
|
|
|
|
{
|
|
|
|
// The size is checked so that a malicious or corrupt ISO
|
|
|
|
// can't force Dolphin to allocate up to 4 GiB of memory.
|
|
|
|
// 4 MiB should be much bigger than the size of TMDs and much smaller
|
|
|
|
// than the amount of RAM in a computer that can run Dolphin.
|
|
|
|
PanicAlert("TMD > 4 MiB");
|
|
|
|
tmd_size = 1024 * 1024 * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<u8> buffer(tmd_size);
|
2017-03-24 23:32:45 +00:00
|
|
|
if (!Read(m_VolumeOffset + tmd_address, tmd_size, buffer.data(), false))
|
|
|
|
return {};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-02-11 07:57:47 +00:00
|
|
|
return IOS::ES::TMDReader{std::move(buffer)};
|
2010-09-08 00:20:19 +00:00
|
|
|
}
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2017-02-10 17:57:58 +00:00
|
|
|
u64 CVolumeWiiCrypted::PartitionOffsetToRawOffset(u64 offset) const
|
|
|
|
{
|
|
|
|
return m_VolumeOffset + m_dataOffset + (offset / BLOCK_DATA_SIZE * BLOCK_TOTAL_SIZE) +
|
|
|
|
(offset % BLOCK_DATA_SIZE);
|
|
|
|
}
|
|
|
|
|
2016-10-29 12:42:43 +00:00
|
|
|
std::string CVolumeWiiCrypted::GetGameID() const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
char ID[6];
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2017-03-09 17:47:40 +00:00
|
|
|
if (!Read(0, 6, (u8*)ID, true))
|
2016-06-24 08:43:46 +00:00
|
|
|
return std::string();
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return DecodeString(ID);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 17:41:21 +00:00
|
|
|
Region CVolumeWiiCrypted::GetRegion() const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-12-23 17:41:21 +00:00
|
|
|
u32 region_code;
|
|
|
|
if (!ReadSwapped(0x4E000, ®ion_code, false))
|
|
|
|
return Region::UNKNOWN_REGION;
|
|
|
|
|
|
|
|
return static_cast<Region>(region_code);
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-12-23 17:41:21 +00:00
|
|
|
Country CVolumeWiiCrypted::GetCountry() const
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
u8 country_byte;
|
2017-03-09 17:47:40 +00:00
|
|
|
if (!ReadSwapped(3, &country_byte, true))
|
2016-07-06 18:33:05 +00:00
|
|
|
return Country::COUNTRY_UNKNOWN;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-12-23 17:41:21 +00:00
|
|
|
const Region region = GetRegion();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-03-17 20:16:59 +00:00
|
|
|
if (RegionSwitchWii(country_byte) != region)
|
|
|
|
return TypicalCountryForRegion(region);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-03-17 20:16:59 +00:00
|
|
|
return CountrySwitch(country_byte);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 19:19:15 +00:00
|
|
|
std::string CVolumeWiiCrypted::GetMakerID() const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
char makerID[2];
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2017-03-09 17:47:40 +00:00
|
|
|
if (!Read(0x4, 0x2, (u8*)&makerID, true))
|
2016-06-24 08:43:46 +00:00
|
|
|
return std::string();
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return DecodeString(makerID);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2015-05-29 19:14:02 +00:00
|
|
|
u16 CVolumeWiiCrypted::GetRevision() const
|
2014-11-15 01:59:39 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
u8 revision;
|
2017-03-09 17:47:40 +00:00
|
|
|
if (!ReadSwapped(7, &revision, true))
|
2016-06-24 08:43:46 +00:00
|
|
|
return 0;
|
2014-11-15 01:59:39 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return revision;
|
2014-11-15 01:59:39 +00:00
|
|
|
}
|
|
|
|
|
2015-05-11 09:19:30 +00:00
|
|
|
std::string CVolumeWiiCrypted::GetInternalName() const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
char name_buffer[0x60];
|
2017-03-09 18:44:38 +00:00
|
|
|
if (Read(0x20, 0x60, (u8*)&name_buffer, true))
|
2016-06-24 08:43:46 +00:00
|
|
|
return DecodeString(name_buffer);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return "";
|
2015-04-10 20:10:49 +00:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2016-07-06 18:33:05 +00:00
|
|
|
std::map<Language, std::string> CVolumeWiiCrypted::GetLongNames() const
|
2015-04-10 20:10:49 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::unique_ptr<IFileSystem> file_system(CreateFileSystem(this));
|
|
|
|
std::vector<u8> opening_bnr(NAMES_TOTAL_BYTES);
|
2016-07-06 18:33:05 +00:00
|
|
|
size_t size = file_system->ReadFile("opening.bnr", opening_bnr.data(), opening_bnr.size(), 0x5C);
|
|
|
|
opening_bnr.resize(size);
|
2016-06-24 08:43:46 +00:00
|
|
|
return ReadWiiNames(opening_bnr);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2015-12-03 16:29:59 +00:00
|
|
|
std::vector<u32> CVolumeWiiCrypted::GetBanner(int* width, int* height) const
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
*width = 0;
|
|
|
|
*height = 0;
|
2015-12-03 16:29:59 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
u64 title_id;
|
|
|
|
if (!GetTitleID(&title_id))
|
|
|
|
return std::vector<u32>();
|
2015-12-03 16:29:59 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return GetWiiBanner(width, height, title_id);
|
2015-12-03 16:29:59 +00:00
|
|
|
}
|
|
|
|
|
2015-08-10 14:35:23 +00:00
|
|
|
u64 CVolumeWiiCrypted::GetFSTSize() const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
u32 size;
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (!Read(0x428, 0x4, (u8*)&size, true))
|
|
|
|
return 0;
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return (u64)Common::swap32(size) << 2;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 19:19:15 +00:00
|
|
|
std::string CVolumeWiiCrypted::GetApploaderDate() const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
char date[16];
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (!Read(0x2440, 0x10, (u8*)&date, true))
|
|
|
|
return std::string();
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return DecodeString(date);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2016-07-06 18:33:05 +00:00
|
|
|
Platform CVolumeWiiCrypted::GetVolumeType() const
|
2015-01-17 12:21:02 +00:00
|
|
|
{
|
2016-07-06 18:33:05 +00:00
|
|
|
return Platform::WII_DISC;
|
2015-01-17 12:21:02 +00:00
|
|
|
}
|
|
|
|
|
2015-05-29 19:14:02 +00:00
|
|
|
u8 CVolumeWiiCrypted::GetDiscNumber() const
|
2015-02-26 22:10:18 +00:00
|
|
|
{
|
2017-03-24 23:32:45 +00:00
|
|
|
u8 disc_number = 0;
|
2017-03-09 17:47:40 +00:00
|
|
|
ReadSwapped(6, &disc_number, true);
|
2016-06-24 08:43:46 +00:00
|
|
|
return disc_number;
|
2015-02-26 22:10:18 +00:00
|
|
|
}
|
|
|
|
|
2015-09-27 12:01:12 +00:00
|
|
|
BlobType CVolumeWiiCrypted::GetBlobType() const
|
2015-09-26 13:24:29 +00:00
|
|
|
{
|
2016-10-30 22:39:12 +00:00
|
|
|
return m_pReader->GetBlobType();
|
2015-09-26 13:24:29 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 19:19:15 +00:00
|
|
|
u64 CVolumeWiiCrypted::GetSize() const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-10-30 22:39:12 +00:00
|
|
|
return m_pReader->GetDataSize();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
2009-02-22 13:59:06 +00:00
|
|
|
|
2013-04-09 17:58:56 +00:00
|
|
|
u64 CVolumeWiiCrypted::GetRawSize() const
|
|
|
|
{
|
2016-10-30 22:39:12 +00:00
|
|
|
return m_pReader->GetRawSize();
|
2013-04-09 17:58:56 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 10:49:10 +00:00
|
|
|
bool CVolumeWiiCrypted::CheckIntegrity() const
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// Get partition data size
|
|
|
|
u32 partSizeDiv4;
|
|
|
|
Read(m_VolumeOffset + 0x2BC, 4, (u8*)&partSizeDiv4, false);
|
|
|
|
u64 partDataSize = (u64)Common::swap32(partSizeDiv4) * 4;
|
|
|
|
|
|
|
|
u32 nClusters = (u32)(partDataSize / 0x8000);
|
|
|
|
for (u32 clusterID = 0; clusterID < nClusters; ++clusterID)
|
|
|
|
{
|
|
|
|
u64 clusterOff = m_VolumeOffset + m_dataOffset + (u64)clusterID * 0x8000;
|
|
|
|
|
|
|
|
// Read and decrypt the cluster metadata
|
|
|
|
u8 clusterMDCrypted[0x400];
|
|
|
|
u8 clusterMD[0x400];
|
|
|
|
u8 IV[16] = {0};
|
2017-03-09 18:44:38 +00:00
|
|
|
if (!Read(clusterOff, 0x400, clusterMDCrypted, false))
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-09-24 23:06:47 +00:00
|
|
|
WARN_LOG(DISCIO, "Integrity Check: fail at cluster %d: could not read metadata", clusterID);
|
2016-06-24 08:43:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mbedtls_aes_crypt_cbc(m_AES_ctx.get(), MBEDTLS_AES_DECRYPT, 0x400, IV, clusterMDCrypted,
|
|
|
|
clusterMD);
|
|
|
|
|
|
|
|
// Some clusters have invalid data and metadata because they aren't
|
|
|
|
// meant to be read by the game (for example, holes between files). To
|
|
|
|
// try to avoid reporting errors because of these clusters, we check
|
|
|
|
// the 0x00 paddings in the metadata.
|
|
|
|
//
|
|
|
|
// This may cause some false negatives though: some bad clusters may be
|
|
|
|
// skipped because they are *too* bad and are not even recognized as
|
|
|
|
// valid clusters. To be improved.
|
|
|
|
bool meaningless = false;
|
|
|
|
for (u32 idx = 0x26C; idx < 0x280; ++idx)
|
|
|
|
if (clusterMD[idx] != 0)
|
|
|
|
meaningless = true;
|
|
|
|
|
|
|
|
if (meaningless)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
u8 clusterData[0x7C00];
|
|
|
|
if (!Read((u64)clusterID * 0x7C00, 0x7C00, clusterData, true))
|
|
|
|
{
|
2016-09-24 23:06:47 +00:00
|
|
|
WARN_LOG(DISCIO, "Integrity Check: fail at cluster %d: could not read data", clusterID);
|
2016-06-24 08:43:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (u32 hashID = 0; hashID < 31; ++hashID)
|
|
|
|
{
|
|
|
|
u8 hash[20];
|
|
|
|
|
|
|
|
mbedtls_sha1(clusterData + hashID * 0x400, 0x400, hash);
|
|
|
|
|
|
|
|
// Note that we do not use strncmp here
|
|
|
|
if (memcmp(hash, clusterMD + hashID * 20, 20))
|
|
|
|
{
|
2016-09-24 23:06:47 +00:00
|
|
|
WARN_LOG(DISCIO, "Integrity Check: fail at cluster %d: hash %d is invalid", clusterID,
|
|
|
|
hashID);
|
2016-06-24 08:43:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2012-05-04 10:49:10 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
} // namespace
|