addressed review comments

This commit is contained in:
B3n30 2020-03-28 21:43:13 +01:00
parent eaaa76b922
commit ab76b0b684
2 changed files with 27 additions and 13 deletions

View file

@ -233,7 +233,7 @@ void LoadNativeFirmKeysOld3DS() {
firm->Read(0, firm_buffer.size(), firm_buffer.data());
firm->Close();
constexpr std::size_t SLOT_0x25_KEY_X_SECRET_OFFSET = 934444;
constexpr std::size_t SLOT_0x25_KEY_X_SECRET_OFFSET = 933480;
constexpr std::size_t SLOT_0x25_KEY_X_SECRET_SIZE = 64;
std::vector<u8> secret_data(SLOT_0x25_KEY_X_SECRET_SIZE);
std::memcpy(secret_data.data(), firm_buffer.data() + SLOT_0x25_KEY_X_SECRET_OFFSET,

View file

@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <sstream>
#include <cryptopp/hex.h>
#include <cryptopp/integer.h>
#include <cryptopp/nbtheory.h>
#include <cryptopp/sha.h>
@ -37,6 +38,11 @@ std::vector<u8> RsaSlot::GetSignature(const std::vector<u8>& message) {
CryptoPP::Integer(modulus.data(), modulus.size()));
std::stringstream ss;
ss << std::hex << sig;
CryptoPP::HexDecoder decoder;
decoder.Put(reinterpret_cast<unsigned char*>(ss.str().data()), ss.str().size());
decoder.MessageEnd();
std::vector<u8> result(decoder.MaxRetrievable());
decoder.Get(result.data(), result.size());
return HexToBytes(ss.str());
}
@ -80,19 +86,27 @@ RsaSlot GetSlot(std::size_t slot_id) {
}
std::vector<u8> CreateASN1Message(const std::vector<u8>& data) {
static constexpr auto asn1_header =
"0001FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF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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, 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, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x30, 0x31, 0x30, 0x0D, 0x06,
0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20}};
std::vector<u8> message(asn1_header.begin(), asn1_header.end());
CryptoPP::SHA256 sha;
std::array<u8, CryptoPP::SHA256::DIGESTSIZE> hash;
sha.CalculateDigest(hash.data(), data.data(), data.size());
std::copy(hash.begin(), hash.end(), std::back_inserter(message));
message.resize(message.size() + CryptoPP::SHA256::DIGESTSIZE);
sha.CalculateDigest(message.data() + asn1_header.size(), data.data(), data.size());
return message;
}