summaryrefslogtreecommitdiffstats
path: root/src/core/crypto/aes_util.cpp
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2020-08-03 20:14:39 +0200
committerLioncash <mathew1800@gmail.com>2020-08-03 20:29:58 +0200
commit15660bd8570735139d91d0165a2614747f570202 (patch)
tree6886854694175d87bf33924c1799b1b46e4fd05d /src/core/crypto/aes_util.cpp
parentipc: Allow all trivially copyable objects to be passed directly into WriteBuffer (#4465) (diff)
downloadyuzu-15660bd8570735139d91d0165a2614747f570202.tar
yuzu-15660bd8570735139d91d0165a2614747f570202.tar.gz
yuzu-15660bd8570735139d91d0165a2614747f570202.tar.bz2
yuzu-15660bd8570735139d91d0165a2614747f570202.tar.lz
yuzu-15660bd8570735139d91d0165a2614747f570202.tar.xz
yuzu-15660bd8570735139d91d0165a2614747f570202.tar.zst
yuzu-15660bd8570735139d91d0165a2614747f570202.zip
Diffstat (limited to '')
-rw-r--r--src/core/crypto/aes_util.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/core/crypto/aes_util.cpp b/src/core/crypto/aes_util.cpp
index 4be76bb43..330996b24 100644
--- a/src/core/crypto/aes_util.cpp
+++ b/src/core/crypto/aes_util.cpp
@@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#include <array>
#include <mbedtls/cipher.h>
#include "common/assert.h"
#include "common/logging/log.h"
@@ -10,8 +11,10 @@
namespace Core::Crypto {
namespace {
-std::vector<u8> CalculateNintendoTweak(std::size_t sector_id) {
- std::vector<u8> out(0x10);
+using NintendoTweak = std::array<u8, 16>;
+
+NintendoTweak CalculateNintendoTweak(std::size_t sector_id) {
+ NintendoTweak out{};
for (std::size_t i = 0xF; i <= 0xF; --i) {
out[i] = sector_id & 0xFF;
sector_id >>= 8;
@@ -64,13 +67,6 @@ AESCipher<Key, KeySize>::~AESCipher() {
}
template <typename Key, std::size_t KeySize>
-void AESCipher<Key, KeySize>::SetIV(std::vector<u8> iv) {
- ASSERT_MSG((mbedtls_cipher_set_iv(&ctx->encryption_context, iv.data(), iv.size()) ||
- mbedtls_cipher_set_iv(&ctx->decryption_context, iv.data(), iv.size())) == 0,
- "Failed to set IV on mbedtls ciphers.");
-}
-
-template <typename Key, std::size_t KeySize>
void AESCipher<Key, KeySize>::Transcode(const u8* src, std::size_t size, u8* dest, Op op) const {
auto* const context = op == Op::Encrypt ? &ctx->encryption_context : &ctx->decryption_context;
@@ -124,6 +120,13 @@ void AESCipher<Key, KeySize>::XTSTranscode(const u8* src, std::size_t size, u8*
}
}
+template <typename Key, std::size_t KeySize>
+void AESCipher<Key, KeySize>::SetIVImpl(const u8* data, std::size_t size) {
+ ASSERT_MSG((mbedtls_cipher_set_iv(&ctx->encryption_context, data, size) ||
+ mbedtls_cipher_set_iv(&ctx->decryption_context, data, size)) == 0,
+ "Failed to set IV on mbedtls ciphers.");
+}
+
template class AESCipher<Key128>;
template class AESCipher<Key256>;
} // namespace Core::Crypto