// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include #include #include #include "common/common_types.h" #include "core/file_sys/vfs.h" namespace Core::Crypto { struct CipherContext; enum class Mode { CTR = 11, ECB = 2, XTS = 70, }; enum class Op { Encrypt, Decrypt, }; template class AESCipher { static_assert(std::is_same_v>, "Key must be std::array of u8."); static_assert(KeySize == 0x10 || KeySize == 0x20, "KeySize must be 128 or 256."); public: AESCipher(Key key, Mode mode); ~AESCipher(); void SetIV(std::span data); template void Transcode(const Source* src, std::size_t size, Dest* dest, Op op) const { static_assert(std::is_trivially_copyable_v && std::is_trivially_copyable_v, "Transcode source and destination types must be trivially copyable."); Transcode(reinterpret_cast(src), size, reinterpret_cast(dest), op); } void Transcode(const u8* src, std::size_t size, u8* dest, Op op) const; template void XTSTranscode(const Source* src, std::size_t size, Dest* dest, std::size_t sector_id, std::size_t sector_size, Op op) { static_assert(std::is_trivially_copyable_v && std::is_trivially_copyable_v, "XTSTranscode source and destination types must be trivially copyable."); XTSTranscode(reinterpret_cast(src), size, reinterpret_cast(dest), sector_id, sector_size, op); } void XTSTranscode(const u8* src, std::size_t size, u8* dest, std::size_t sector_id, std::size_t sector_size, Op op); private: std::unique_ptr ctx; }; } // namespace Core::Crypto