Skip to content

Commit

Permalink
Fix inconsistency with int types
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryOderNichts committed May 18, 2024
1 parent eb1983d commit a115921
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 65 deletions.
22 changes: 11 additions & 11 deletions src/Cafe/IOSU/ccr_nfc/iosu_ccr_nfc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,31 @@ namespace iosu
return CCR_NFC_ERROR;
}

sint32 CCRNFCAESCTRCrypt(const uint8* key, const void* ivNonce, const void* inData, uint32_t inSize, void* outData, uint32_t outSize)
sint32 CCRNFCAESCTRCrypt(const uint8* key, const void* ivNonce, const void* inData, uint32 inSize, void* outData, uint32 outSize)
{
uint8_t tmpIv[0x10];
uint8 tmpIv[0x10];
memcpy(tmpIv, ivNonce, sizeof(tmpIv));

memcpy(outData, inData, inSize);
AES128CTR_transform((uint8*)outData, outSize, (uint8*)key, tmpIv);
return 0;
}

sint32 __CCRNFCGenerateKey(const uint8* hmacKey, uint32 hmacKeySize, const uint8* name, uint32_t nameSize, const uint8* inData, uint32_t inSize, uint8* outData, uint32_t outSize)
sint32 __CCRNFCGenerateKey(const uint8* hmacKey, uint32 hmacKeySize, const uint8* name, uint32 nameSize, const uint8* inData, uint32 inSize, uint8* outData, uint32 outSize)
{
if (nameSize != 0xe || outSize != 0x40)
{
return CCR_NFC_ERROR;
}

// Create a buffer containing 2 counter bytes, the key name, and the key data
uint8_t buffer[0x50];
uint8 buffer[0x50];
buffer[0] = 0;
buffer[1] = 0;
memcpy(buffer + 2, name, nameSize);
memcpy(buffer + nameSize + 2, inData, inSize);

uint16_t counter = 0;
uint16 counter = 0;
while (outSize > 0)
{
// Set counter bytes and increment counter
Expand All @@ -118,9 +118,9 @@ namespace iosu

sint32 __CCRNFCGenerateInternalKeys(const CCRNFCCryptData* in, const uint8* keyGenSalt)
{
uint8_t lockedSecretBuffer[0x40] = { 0 };
uint8_t unfixedInfosBuffer[0x40] = { 0 };
uint8_t outBuffer[0x40] = { 0 };
uint8 lockedSecretBuffer[0x40] = { 0 };
uint8 unfixedInfosBuffer[0x40] = { 0 };
uint8 outBuffer[0x40] = { 0 };

// Fill the locked secret buffer
memcpy(lockedSecretBuffer, sLockedSecretMagicBytes, sizeof(sLockedSecretMagicBytes));
Expand Down Expand Up @@ -193,7 +193,7 @@ namespace iosu
sint32 __CCRNFCCryptData(const CCRNFCCryptData* in, CCRNFCCryptData* out, bool decrypt)
{
// Decrypt key generation salt
uint8_t keyGenSalt[0x20];
uint8 keyGenSalt[0x20];
sint32 res = CCRNFCAESCTRCrypt(sNfcKey, sNfcKeyIV, in->data + in->keyGenSaltOffset, 0x20, keyGenSalt, sizeof(keyGenSalt));
if (res != 0)
{
Expand Down Expand Up @@ -227,7 +227,7 @@ namespace iosu
}

// Verify HMACs
uint8_t hmacBuffer[0x20];
uint8 hmacBuffer[0x20];
uint32 hmacLen = sizeof(hmacBuffer);

if (!HMAC(EVP_sha256(), sLockedSecretInternalHmacKey, sizeof(sLockedSecretInternalHmacKey), out->data + in->lockedSecretHmacOffset + 0x20, (in->dataSize - in->lockedSecretHmacOffset) - 0x20, hmacBuffer, &hmacLen))
Expand Down Expand Up @@ -258,7 +258,7 @@ namespace iosu
}
else
{
uint8_t hmacBuffer[0x20];
uint8 hmacBuffer[0x20];
uint32 hmacLen = sizeof(hmacBuffer);

if (!HMAC(EVP_sha256(), sLockedSecretInternalHmacKey, sizeof(sLockedSecretInternalHmacKey), out->data + in->lockedSecretHmacOffset + 0x20, (in->dataSize - in->lockedSecretHmacOffset) - 0x20, hmacBuffer, &hmacLen))
Expand Down
12 changes: 6 additions & 6 deletions src/Cafe/OS/libs/nfc/TLV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ std::vector<TLV> TLV::FromBytes(const std::span<std::byte>& data)
while (stream.GetRemaining() > 0 && !hasTerminator)
{
// Read the tag
uint8_t byte;
uint8 byte;
stream >> byte;
Tag tag = static_cast<Tag>(byte);

Expand All @@ -43,7 +43,7 @@ std::vector<TLV> TLV::FromBytes(const std::span<std::byte>& data)
default:
{
// Read the length
uint16_t length;
uint16 length;
stream >> byte;
length = byte;

Expand Down Expand Up @@ -85,7 +85,7 @@ std::vector<std::byte> TLV::ToBytes() const
VectorStream stream(bytes, std::endian::big);

// Write tag
stream << std::uint8_t(mTag);
stream << uint8(mTag);

switch (mTag)
{
Expand All @@ -99,12 +99,12 @@ std::vector<std::byte> TLV::ToBytes() const
// Write length (decide if as a 8-bit or 16-bit value)
if (mValue.size() >= 0xff)
{
stream << std::uint8_t(0xff);
stream << std::uint16_t(mValue.size());
stream << uint8(0xff);
stream << uint16(mValue.size());
}
else
{
stream << std::uint8_t(mValue.size());
stream << uint8(mValue.size());
}

// Write value
Expand Down
42 changes: 21 additions & 21 deletions src/Cafe/OS/libs/nfc/TagV0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ namespace
constexpr std::size_t kTagSize = 512u;
constexpr std::size_t kMaxBlockCount = kTagSize / sizeof(TagV0::Block);

constexpr std::uint8_t kLockbyteBlock0 = 0xe;
constexpr std::uint8_t kLockbytesStart0 = 0x0;
constexpr std::uint8_t kLockbytesEnd0 = 0x2;
constexpr std::uint8_t kLockbyteBlock1 = 0xf;
constexpr std::uint8_t kLockbytesStart1 = 0x2;
constexpr std::uint8_t kLockbytesEnd1 = 0x8;
constexpr uint8 kLockbyteBlock0 = 0xe;
constexpr uint8 kLockbytesStart0 = 0x0;
constexpr uint8 kLockbytesEnd0 = 0x2;
constexpr uint8 kLockbyteBlock1 = 0xf;
constexpr uint8 kLockbytesStart1 = 0x2;
constexpr uint8 kLockbytesEnd1 = 0x8;

constexpr std::uint8_t kNDEFMagicNumber = 0xe1;
constexpr uint8 kNDEFMagicNumber = 0xe1;

// These blocks are not part of the locked area
constexpr bool IsBlockLockedOrReserved(std::uint8_t blockIdx)
constexpr bool IsBlockLockedOrReserved(uint8 blockIdx)
{
// Block 0 is the UID
if (blockIdx == 0x0)
Expand Down Expand Up @@ -153,7 +153,7 @@ std::vector<std::byte> TagV0::ToBytes() const

// The rest will be the data area
auto dataIterator = dataArea.begin();
for (std::uint8_t currentBlock = 0; currentBlock < kMaxBlockCount; currentBlock++)
for (uint8 currentBlock = 0; currentBlock < kMaxBlockCount; currentBlock++)
{
// All blocks which aren't locked make up the dataArea
if (!IsBlockLocked(currentBlock))
Expand Down Expand Up @@ -189,15 +189,15 @@ void TagV0::SetNDEFData(const std::span<const std::byte>& data)

bool TagV0::ParseLockedArea(const std::span<const std::byte>& data)
{
std::uint8_t currentBlock = 0;
uint8 currentBlock = 0;

// Start by parsing the first set of lock bytes
for (std::uint8_t i = kLockbytesStart0; i < kLockbytesEnd0; i++)
for (uint8 i = kLockbytesStart0; i < kLockbytesEnd0; i++)
{
std::uint8_t lockByte = std::uint8_t(data[kLockbyteBlock0 * sizeof(Block) + i]);
uint8 lockByte = uint8(data[kLockbyteBlock0 * sizeof(Block) + i]);

// Iterate over the individual bits in the lock byte
for (std::uint8_t j = 0; j < 8; j++)
for (uint8 j = 0; j < 8; j++)
{
// Is block locked?
if (lockByte & (1u << j))
Expand All @@ -221,11 +221,11 @@ bool TagV0::ParseLockedArea(const std::span<const std::byte>& data)
}

// Parse the second set of lock bytes
for (std::uint8_t i = kLockbytesStart1; i < kLockbytesEnd1; i++) {
std::uint8_t lockByte = std::uint8_t(data[kLockbyteBlock1 * sizeof(Block) + i]);
for (uint8 i = kLockbytesStart1; i < kLockbytesEnd1; i++) {
uint8 lockByte = uint8(data[kLockbyteBlock1 * sizeof(Block) + i]);

// Iterate over the individual bits in the lock byte
for (std::uint8_t j = 0; j < 8; j++)
for (uint8 j = 0; j < 8; j++)
{
// Is block locked?
if (lockByte & (1u << j))
Expand All @@ -251,14 +251,14 @@ bool TagV0::ParseLockedArea(const std::span<const std::byte>& data)
return true;
}

bool TagV0::IsBlockLocked(std::uint8_t blockIdx) const
bool TagV0::IsBlockLocked(uint8 blockIdx) const
{
return mLockedBlocks.contains(blockIdx) || IsBlockLockedOrReserved(blockIdx);
}

bool TagV0::ParseDataArea(const std::span<const std::byte>& data, std::vector<std::byte>& dataArea)
{
for (std::uint8_t currentBlock = 0; currentBlock < kMaxBlockCount; currentBlock++)
for (uint8 currentBlock = 0; currentBlock < kMaxBlockCount; currentBlock++)
{
// All blocks which aren't locked make up the dataArea
if (!IsBlockLocked(currentBlock))
Expand All @@ -274,23 +274,23 @@ bool TagV0::ParseDataArea(const std::span<const std::byte>& data, std::vector<st
bool TagV0::ValidateCapabilityContainer()
{
// NDEF Magic Number
std::uint8_t nmn = mCapabilityContainer[0];
uint8 nmn = mCapabilityContainer[0];
if (nmn != kNDEFMagicNumber)
{
cemuLog_log(LogType::Force, "Error: CC: Invalid NDEF Magic Number");
return false;
}

// Version Number
std::uint8_t vno = mCapabilityContainer[1];
uint8 vno = mCapabilityContainer[1];
if (vno >> 4 != 1)
{
cemuLog_log(LogType::Force, "Error: CC: Invalid Version Number");
return false;
}

// Tag memory size
std::uint8_t tms = mCapabilityContainer[2];
uint8 tms = mCapabilityContainer[2];
if (8u * (tms + 1) < kTagSize)
{
cemuLog_log(LogType::Force, "Error: CC: Incomplete tag memory size");
Expand Down
8 changes: 4 additions & 4 deletions src/Cafe/OS/libs/nfc/TagV0.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ class TagV0

private:
bool ParseLockedArea(const std::span<const std::byte>& data);
bool IsBlockLocked(std::uint8_t blockIdx) const;
bool IsBlockLocked(uint8 blockIdx) const;
bool ParseDataArea(const std::span<const std::byte>& data, std::vector<std::byte>& dataArea);
bool ValidateCapabilityContainer();

std::map<std::uint8_t, Block> mLockedOrReservedBlocks;
std::map<std::uint8_t, Block> mLockedBlocks;
std::array<std::uint8_t, 0x4> mCapabilityContainer;
std::map<uint8, Block> mLockedOrReservedBlocks;
std::map<uint8, Block> mLockedBlocks;
std::array<uint8, 0x4> mCapabilityContainer;
std::vector<TLV> mTLVs;
std::size_t mNdefTlvIdx;
std::vector<std::byte> mLockedArea;
Expand Down
26 changes: 13 additions & 13 deletions src/Cafe/OS/libs/nfc/ndef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ namespace ndef
Record rec;

// Read record header
uint8_t recHdr;
uint8 recHdr;
stream >> recHdr;
rec.mFlags = recHdr & ~NDEF_TNF_MASK;
rec.mTNF = static_cast<TypeNameFormat>(recHdr & NDEF_TNF_MASK);

// Type length
uint8_t typeLen;
uint8 typeLen;
stream >> typeLen;

// Payload length;
uint32_t payloadLen;
uint32 payloadLen;
if (recHdr & NDEF_SR)
{
uint8_t len;
uint8 len;
stream >> len;
payloadLen = len;
}
Expand All @@ -48,7 +48,7 @@ namespace ndef
}

// ID length
uint8_t idLen = 0;
uint8 idLen = 0;
if (recHdr & NDEF_IL)
{
stream >> idLen;
Expand Down Expand Up @@ -81,35 +81,35 @@ namespace ndef
return rec;
}

std::vector<std::byte> Record::ToBytes(uint8_t flags) const
std::vector<std::byte> Record::ToBytes(uint8 flags) const
{
std::vector<std::byte> bytes;
VectorStream stream(bytes, std::endian::big);

// Combine flags (clear message begin and end flags)
std::uint8_t finalFlags = mFlags & ~(NDEF_MB | NDEF_ME);
uint8 finalFlags = mFlags & ~(NDEF_MB | NDEF_ME);
finalFlags |= flags;

// Write flags + tnf
stream << std::uint8_t(finalFlags | std::uint8_t(mTNF));
stream << uint8(finalFlags | uint8(mTNF));

// Type length
stream << std::uint8_t(mType.size());
stream << uint8(mType.size());

// Payload length
if (IsShort())
{
stream << std::uint8_t(mPayload.size());
stream << uint8(mPayload.size());
}
else
{
stream << std::uint32_t(mPayload.size());
stream << uint32(mPayload.size());
}

// ID length
if (mFlags & NDEF_IL)
{
stream << std::uint8_t(mID.size());
stream << uint8(mID.size());
}

// Type
Expand Down Expand Up @@ -249,7 +249,7 @@ namespace ndef

for (std::size_t i = 0; i < mRecords.size(); i++)
{
std::uint8_t flags = 0;
uint8 flags = 0;

// Add message begin flag to first record
if (i == 0)
Expand Down
4 changes: 2 additions & 2 deletions src/Cafe/OS/libs/nfc/ndef.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace ndef
virtual ~Record();

static std::optional<Record> FromStream(Stream& stream);
std::vector<std::byte> ToBytes(uint8_t flags = 0) const;
std::vector<std::byte> ToBytes(uint8 flags = 0) const;

TypeNameFormat GetTNF() const;
const std::vector<std::byte>& GetID() const;
Expand All @@ -55,7 +55,7 @@ namespace ndef
bool IsShort() const;

private:
uint8_t mFlags;
uint8 mFlags;
TypeNameFormat mTNF;
std::vector<std::byte> mID;
std::vector<std::byte> mType;
Expand Down
4 changes: 2 additions & 2 deletions src/Cafe/OS/libs/nfc/nfc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ namespace nfc
StackAllocator<NFCUid> uid;
bool readOnly = false;
uint32 dataSize = 0;
StackAllocator<uint8_t, 0x200> data;
StackAllocator<uint8, 0x200> data;
uint32 lockedDataSize = 0;
StackAllocator<uint8_t, 0x200> lockedData;
StackAllocator<uint8, 0x200> lockedData;

if (ctx->tag)
{
Expand Down
Loading

0 comments on commit a115921

Please sign in to comment.