ctr_encryption_layer.h 924 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include "core/crypto/aes_util.h"
  7. #include "core/crypto/encryption_layer.h"
  8. #include "core/crypto/key_manager.h"
  9. namespace Core::Crypto {
  10. // Sits on top of a VirtualFile and provides CTR-mode AES decription.
  11. class CTREncryptionLayer : public EncryptionLayer {
  12. public:
  13. using IVData = std::array<u8, 16>;
  14. CTREncryptionLayer(FileSys::VirtualFile base_, Key128 key_, std::size_t base_offset_);
  15. std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override;
  16. void SetIV(const IVData& iv);
  17. private:
  18. std::size_t base_offset;
  19. // Must be mutable as operations modify cipher contexts.
  20. mutable AESCipher<Key128> cipher;
  21. mutable IVData iv{};
  22. void UpdateIV(std::size_t offset) const;
  23. };
  24. } // namespace Core::Crypto