citra-emu
/
citra
Archived
1
0
Fork 0

service/cecd: Utilize CryptoPP::Base64Encoder for message id

This commit is contained in:
NarcolepticK 2018-09-07 23:09:14 -04:00
parent ff1beca74a
commit 648cecf1aa
3 changed files with 21 additions and 28 deletions

View File

@ -131,6 +131,7 @@ set(cryptopp_SOURCES
cryptopp/algparam.cpp cryptopp/algparam.cpp
cryptopp/asn.cpp cryptopp/asn.cpp
cryptopp/authenc.cpp cryptopp/authenc.cpp
cryptopp/base64.cpp
cryptopp/basecode.cpp cryptopp/basecode.cpp
cryptopp/ccm.cpp cryptopp/ccm.cpp
cryptopp/crc-simd.cpp cryptopp/crc-simd.cpp

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <cryptopp/base64.h>
#include "common/file_util.h" #include "common/file_util.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "common/string_util.h" #include "common/string_util.h"
@ -691,30 +692,23 @@ void Module::Interface::OpenAndRead(Kernel::HLERequestContext& ctx) {
open_mode.check); open_mode.check);
} }
std::string Module::EncodeBase64(const std::vector<u8>& in, const std::string& dictionary) const { std::string Module::EncodeBase64(const std::vector<u8>& in) const {
using namespace CryptoPP;
using Name::EncodingLookupArray;
using Name::InsertLineBreaks;
using Name::Pad;
std::string out; std::string out;
out.reserve((in.size() * 4) / 3); Base64Encoder encoder;
int b; AlgorithmParameters params =
for (int i = 0; i < in.size(); i += 3) { MakeParameters(EncodingLookupArray(), (const byte*)base64_dict.data())(InsertLineBreaks(),
b = (in[i] & 0xFC) >> 2; false)(Pad(), false);
out += dictionary[b];
b = (in[i] & 0x03) << 4; encoder.IsolatedInitialize(params);
if (i + 1 < in.size()) { encoder.Attach(new StringSink(out));
b |= (in[i + 1] & 0xF0) >> 4; encoder.Put(in.data(), in.size());
out += dictionary[b]; encoder.MessageEnd();
b = (in[i + 1] & 0x0F) << 2;
if (i + 2 < in.size()) {
b |= (in[i + 2] & 0xC0) >> 6;
out += dictionary[b];
b = in[i + 2] & 0x3F;
out += dictionary[b];
} else {
out += dictionary[b];
}
} else {
out += dictionary[b];
}
}
return out; return out;
} }
@ -732,11 +726,9 @@ std::string Module::GetCecDataPathTypeAsString(const CecDataPathType type, const
case CecDataPathType::OutboxIndex: case CecDataPathType::OutboxIndex:
return fmt::format("/CEC/{:08x}/OutBox__/OBIndex_____", program_id); return fmt::format("/CEC/{:08x}/OutBox__/OBIndex_____", program_id);
case CecDataPathType::InboxMsg: case CecDataPathType::InboxMsg:
return fmt::format("/CEC/{:08x}/InBox___/_{}", program_id, return fmt::format("/CEC/{:08x}/InBox___/_{}", program_id, EncodeBase64(msg_id));
EncodeBase64(msg_id, base64_dict));
case CecDataPathType::OutboxMsg: case CecDataPathType::OutboxMsg:
return fmt::format("/CEC/{:08x}/OutBox__/_{}", program_id, return fmt::format("/CEC/{:08x}/OutBox__/_{}", program_id, EncodeBase64(msg_id));
EncodeBase64(msg_id, base64_dict));
case CecDataPathType::RootDir: case CecDataPathType::RootDir:
return "/CEC"; return "/CEC";
case CecDataPathType::MboxDir: case CecDataPathType::MboxDir:

View File

@ -589,7 +589,7 @@ private:
0x26, 0x00, 0x01, 0x00}; 0x26, 0x00, 0x01, 0x00};
/// Encoding function used for the message id /// Encoding function used for the message id
std::string EncodeBase64(const std::vector<u8>& in, const std::string& dictionary) const; std::string EncodeBase64(const std::vector<u8>& in) const;
std::string GetCecDataPathTypeAsString(const CecDataPathType type, const u32 program_id, std::string GetCecDataPathTypeAsString(const CecDataPathType type, const u32 program_id,
const std::vector<u8>& msg_id = std::vector<u8>()) const; const std::vector<u8>& msg_id = std::vector<u8>()) const;