From 15660bd8570735139d91d0165a2614747f570202 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Aug 2020 14:14:39 -0400 Subject: aes_util: Allow SetIV to be non-allocating In a few places, the data to be set as the IV is already within an array. We shouldn't require this data to be heap-allocated if it doesn't need to be. This allows certain callers to reduce heap churn. --- src/core/file_sys/content_archive.cpp | 7 ++++--- src/core/file_sys/nca_patch.cpp | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/core/file_sys') diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp index 473245d5a..5039341c7 100644 --- a/src/core/file_sys/content_archive.cpp +++ b/src/core/file_sys/content_archive.cpp @@ -495,9 +495,10 @@ VirtualFile NCA::Decrypt(const NCASectionHeader& s_header, VirtualFile in, u64 s auto out = std::make_shared(std::move(in), *key, starting_offset); - std::vector iv(16); - for (u8 i = 0; i < 8; ++i) - iv[i] = s_header.raw.section_ctr[0x8 - i - 1]; + Core::Crypto::CTREncryptionLayer::IVData iv{}; + for (std::size_t i = 0; i < 8; ++i) { + iv[i] = s_header.raw.section_ctr[8 - i - 1]; + } out->SetIV(iv); return std::static_pointer_cast(out); } diff --git a/src/core/file_sys/nca_patch.cpp b/src/core/file_sys/nca_patch.cpp index 0090cc6c4..fe7375e84 100644 --- a/src/core/file_sys/nca_patch.cpp +++ b/src/core/file_sys/nca_patch.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include @@ -66,7 +67,7 @@ std::size_t BKTR::Read(u8* data, std::size_t length, std::size_t offset) const { Core::Crypto::AESCipher cipher(key, Core::Crypto::Mode::CTR); // Calculate AES IV - std::vector iv(16); + std::array iv{}; auto subsection_ctr = subsection.ctr; auto offset_iv = section_offset + base_offset; for (std::size_t i = 0; i < section_ctr.size(); ++i) -- cgit v1.2.3