2020-01-23 15:47:49 +00:00
|
|
|
// Copyright 2020 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-01-23 15:47:49 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <limits>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
#include "DiscIO/VolumeWii.h"
|
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
|
|
|
class BlobReader;
|
|
|
|
|
|
|
|
class WiiEncryptionCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using Key = std::array<u8, VolumeWii::AES_KEY_SIZE>;
|
2020-01-27 15:12:56 +00:00
|
|
|
using HashExceptionCallback = std::function<void(
|
|
|
|
VolumeWii::HashBlock hash_blocks[VolumeWii::BLOCKS_PER_GROUP], u64 offset)>;
|
2020-01-23 15:47:49 +00:00
|
|
|
|
|
|
|
// The blob pointer is kept around for the lifetime of this object.
|
|
|
|
explicit WiiEncryptionCache(BlobReader* blob);
|
|
|
|
~WiiEncryptionCache();
|
|
|
|
|
2020-10-20 09:33:38 +00:00
|
|
|
WiiEncryptionCache(WiiEncryptionCache&&) = default;
|
|
|
|
WiiEncryptionCache& operator=(WiiEncryptionCache&&) = default;
|
|
|
|
|
|
|
|
// It would be possible to write a custom copy constructor and assignment operator
|
|
|
|
// for this class, but there has been no reason to do so.
|
|
|
|
WiiEncryptionCache(const WiiEncryptionCache&) = delete;
|
|
|
|
WiiEncryptionCache& operator=(const WiiEncryptionCache&) = delete;
|
|
|
|
|
2020-01-23 15:47:49 +00:00
|
|
|
// Encrypts exactly one group.
|
|
|
|
// If the returned pointer is nullptr, reading from the blob failed.
|
|
|
|
// If the returned pointer is not nullptr, it is guaranteed to be valid until
|
|
|
|
// the next call of this function or the destruction of this object.
|
2020-01-27 15:12:56 +00:00
|
|
|
const std::array<u8, VolumeWii::GROUP_TOTAL_SIZE>*
|
|
|
|
EncryptGroup(u64 offset, u64 partition_data_offset, u64 partition_data_decrypted_size,
|
|
|
|
const Key& key, const HashExceptionCallback& hash_exception_callback = {});
|
2020-01-23 15:47:49 +00:00
|
|
|
|
|
|
|
// Encrypts a variable number of groups, as determined by the offset and size parameters.
|
|
|
|
// Supports reading groups partially.
|
|
|
|
bool EncryptGroups(u64 offset, u64 size, u8* out_ptr, u64 partition_data_offset,
|
2020-01-27 15:12:56 +00:00
|
|
|
u64 partition_data_decrypted_size, const Key& key,
|
|
|
|
const HashExceptionCallback& hash_exception_callback = {});
|
2020-01-23 15:47:49 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
BlobReader* m_blob;
|
|
|
|
std::unique_ptr<std::array<u8, VolumeWii::GROUP_TOTAL_SIZE>> m_cache;
|
2021-09-04 04:43:19 +00:00
|
|
|
u64 m_cached_offset = 0;
|
2020-01-23 15:47:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace DiscIO
|