ctr_encryption_layer.h 897 B

123456789101112131415161718192021222324252627282930313233
  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 <vector>
  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. CTREncryptionLayer(FileSys::VirtualFile base, Key128 key, std::size_t base_offset);
  14. std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override;
  15. void SetIV(const std::vector<u8>& iv);
  16. private:
  17. std::size_t base_offset;
  18. // Must be mutable as operations modify cipher contexts.
  19. mutable AESCipher<Key128> cipher;
  20. mutable std::vector<u8> iv;
  21. void UpdateIV(std::size_t offset) const;
  22. };
  23. } // namespace Core::Crypto