mirror of
https://github.com/PabloMK7/citra.git
synced 2025-09-12 13:50:03 +00:00
code: Use std::span where appropriate (#6658)
* code: Use std::span when possible * code: Prefix memcpy and memcmp with std::
This commit is contained in:
parent
4ccd9f24fb
commit
cf9bb90ae3
106 changed files with 362 additions and 329 deletions
|
@ -42,7 +42,7 @@ public:
|
|||
|
||||
} // namespace
|
||||
|
||||
std::vector<u8> EncryptSignCCM(const std::vector<u8>& pdata, const CCMNonce& nonce,
|
||||
std::vector<u8> EncryptSignCCM(std::span<const u8> pdata, const CCMNonce& nonce,
|
||||
std::size_t slot_id) {
|
||||
if (!IsNormalKeyAvailable(slot_id)) {
|
||||
LOG_ERROR(HW_AES, "Key slot {} not available. Will use zero key.", slot_id);
|
||||
|
@ -63,7 +63,7 @@ std::vector<u8> EncryptSignCCM(const std::vector<u8>& pdata, const CCMNonce& non
|
|||
return cipher;
|
||||
}
|
||||
|
||||
std::vector<u8> DecryptVerifyCCM(const std::vector<u8>& cipher, const CCMNonce& nonce,
|
||||
std::vector<u8> DecryptVerifyCCM(std::span<const u8> cipher, const CCMNonce& nonce,
|
||||
std::size_t slot_id) {
|
||||
if (!IsNormalKeyAvailable(slot_id)) {
|
||||
LOG_ERROR(HW_AES, "Key slot {} not available. Will use zero key.", slot_id);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
#include "common/common_types.h"
|
||||
|
||||
|
@ -23,7 +24,7 @@ using CCMNonce = std::array<u8, CCM_NONCE_SIZE>;
|
|||
* @param slot_id The slot ID of the key to use for encryption
|
||||
* @returns a vector of u8 containing the encrypted data with MAC at the end
|
||||
*/
|
||||
std::vector<u8> EncryptSignCCM(const std::vector<u8>& pdata, const CCMNonce& nonce,
|
||||
std::vector<u8> EncryptSignCCM(std::span<const u8> pdata, const CCMNonce& nonce,
|
||||
std::size_t slot_id);
|
||||
|
||||
/**
|
||||
|
@ -33,7 +34,7 @@ std::vector<u8> EncryptSignCCM(const std::vector<u8>& pdata, const CCMNonce& non
|
|||
* @param slot_id The slot ID of the key to use for decryption
|
||||
* @returns a vector of u8 containing the decrypted data; an empty vector if the verification fails
|
||||
*/
|
||||
std::vector<u8> DecryptVerifyCCM(const std::vector<u8>& cipher, const CCMNonce& nonce,
|
||||
std::vector<u8> DecryptVerifyCCM(std::span<const u8> cipher, const CCMNonce& nonce,
|
||||
std::size_t slot_id);
|
||||
|
||||
} // namespace HW::AES
|
||||
|
|
|
@ -116,13 +116,13 @@ static void MemoryFill(const Regs::MemoryFillConfig& config) {
|
|||
u32 value = config.value_32bit;
|
||||
std::size_t len = (end - start) / sizeof(u32);
|
||||
for (std::size_t i = 0; i < len; ++i)
|
||||
memcpy(&start[i * sizeof(u32)], &value, sizeof(u32));
|
||||
std::memcpy(&start[i * sizeof(u32)], &value, sizeof(u32));
|
||||
}
|
||||
} else {
|
||||
// fill with 16-bit values
|
||||
u16 value_16bit = config.value_16bit.Value();
|
||||
for (u8* ptr = start; ptr < end; ptr += sizeof(u16))
|
||||
memcpy(ptr, &value_16bit, sizeof(u16));
|
||||
std::memcpy(ptr, &value_16bit, sizeof(u16));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -521,7 +521,7 @@ static void VBlankCallback(std::uintptr_t user_data, s64 cycles_late) {
|
|||
/// Initialize hardware
|
||||
void Init(Memory::MemorySystem& memory) {
|
||||
g_memory = &memory;
|
||||
memset(&g_regs, 0, sizeof(g_regs));
|
||||
std::memset(&g_regs, 0, sizeof(g_regs));
|
||||
|
||||
auto& framebuffer_top = g_regs.framebuffer_config[0];
|
||||
auto& framebuffer_sub = g_regs.framebuffer_config[1];
|
||||
|
|
|
@ -64,7 +64,7 @@ template void Write<u8>(u32 addr, const u8 data);
|
|||
|
||||
/// Initialize hardware
|
||||
void Init() {
|
||||
memset(&g_regs, 0, sizeof(g_regs));
|
||||
std::memset(&g_regs, 0, sizeof(g_regs));
|
||||
LOG_DEBUG(HW_LCD, "initialized OK");
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ std::vector<u8> HexToBytes(const std::string& hex) {
|
|||
constexpr std::size_t SlotSize = 4;
|
||||
std::array<RsaSlot, SlotSize> rsa_slots;
|
||||
|
||||
std::vector<u8> RsaSlot::GetSignature(const std::vector<u8>& message) const {
|
||||
std::vector<u8> RsaSlot::GetSignature(std::span<const u8> message) const {
|
||||
CryptoPP::Integer sig =
|
||||
CryptoPP::ModularExponentiation(CryptoPP::Integer(message.data(), message.size()),
|
||||
CryptoPP::Integer(exponent.data(), exponent.size()),
|
||||
|
@ -85,7 +85,7 @@ RsaSlot GetSlot(std::size_t slot_id) {
|
|||
return rsa_slots[slot_id];
|
||||
}
|
||||
|
||||
std::vector<u8> CreateASN1Message(const std::vector<u8>& data) {
|
||||
std::vector<u8> CreateASN1Message(std::span<const u8> data) {
|
||||
static constexpr std::array<u8, 224> asn1_header = {
|
||||
{0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
|
@ -110,4 +110,4 @@ std::vector<u8> CreateASN1Message(const std::vector<u8>& data) {
|
|||
return message;
|
||||
}
|
||||
|
||||
} // namespace HW::RSA
|
||||
} // namespace HW::RSA
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <span>
|
||||
#include <vector>
|
||||
#include "common/common_types.h"
|
||||
|
||||
|
@ -14,7 +15,7 @@ public:
|
|||
RsaSlot() = default;
|
||||
RsaSlot(std::vector<u8> exponent, std::vector<u8> modulus)
|
||||
: init(true), exponent(std::move(exponent)), modulus(std::move(modulus)) {}
|
||||
std::vector<u8> GetSignature(const std::vector<u8>& message) const;
|
||||
std::vector<u8> GetSignature(std::span<const u8> message) const;
|
||||
|
||||
explicit operator bool() const {
|
||||
// TODO(B3N30): Maybe check if exponent and modulus are vailid
|
||||
|
@ -31,6 +32,6 @@ void InitSlots();
|
|||
|
||||
RsaSlot GetSlot(std::size_t slot_id);
|
||||
|
||||
std::vector<u8> CreateASN1Message(const std::vector<u8>& data);
|
||||
std::vector<u8> CreateASN1Message(std::span<const u8> data);
|
||||
|
||||
} // namespace HW::RSA
|
||||
} // namespace HW::RSA
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue