From 9c5248d101033cbb47739248ddff6e638aa97235 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 23 Apr 2021 09:58:38 -0400 Subject: aes_util: Make use of std::span Allows us to simplify the interface quite a bit as it will handle contiguous sequences for us. --- src/core/crypto/aes_util.cpp | 6 +++--- src/core/crypto/aes_util.h | 8 ++------ 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/core/crypto/aes_util.cpp b/src/core/crypto/aes_util.cpp index cb7506241..85a666de9 100644 --- a/src/core/crypto/aes_util.cpp +++ b/src/core/crypto/aes_util.cpp @@ -119,9 +119,9 @@ void AESCipher::XTSTranscode(const u8* src, std::size_t size, u8* } template -void AESCipher::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, +void AESCipher::SetIV(std::span data) { + ASSERT_MSG((mbedtls_cipher_set_iv(&ctx->encryption_context, data.data(), data.size()) || + mbedtls_cipher_set_iv(&ctx->decryption_context, data.data(), data.size())) == 0, "Failed to set IV on mbedtls ciphers."); } diff --git a/src/core/crypto/aes_util.h b/src/core/crypto/aes_util.h index e2a304186..230451b8f 100644 --- a/src/core/crypto/aes_util.h +++ b/src/core/crypto/aes_util.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include "common/common_types.h" #include "core/file_sys/vfs.h" @@ -33,10 +34,7 @@ public: AESCipher(Key key, Mode mode); ~AESCipher(); - template - void SetIV(const ContiguousContainer& container) { - SetIVImpl(std::data(container), std::size(container)); - } + void SetIV(std::span data); template void Transcode(const Source* src, std::size_t size, Dest* dest, Op op) const { @@ -60,8 +58,6 @@ public: std::size_t sector_size, Op op); private: - void SetIVImpl(const u8* data, std::size_t size); - std::unique_ptr ctx; }; } // namespace Core::Crypto -- cgit v1.2.3