Skip to content

Commit

Permalink
Fix type casting in min function calls in MySigningAtsha204 ####
Browse files Browse the repository at this point in the history
Updated min function calls to cast the second argument to
(uint8_t)32u or (uint16_t)32u in MySigningAtsha204.cpp.
Changes applied to functions: signerAtsha204GetNonce,
signerAtsha204PutNonce, signerAtsha204SignMsg,
signerAtsha204VerifyMsg, and signerCalculateSignature.
  • Loading branch information
virtual-maker committed Jan 2, 2025
1 parent 72cdb70 commit 43e24a3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions core/MySigningAtsha204.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ bool signerAtsha204GetNonce(MyMessage &msg)
}
(void)memcpy((void *)_signing_verifying_nonce, (const void *)signerSha256(_signing_verifying_nonce,
32),
min((uint8_t)MAX_PAYLOAD_SIZE, 32u));
min((uint8_t)MAX_PAYLOAD_SIZE, (uint8_t)32u));

// We just idle the chip now since we expect to use it soon when the signed message arrives
atsha204_idle();
Expand All @@ -138,7 +138,7 @@ bool signerAtsha204GetNonce(MyMessage &msg)
}

// Transfer the first part of the nonce to the message
msg.set(_signing_verifying_nonce, min((uint8_t)MAX_PAYLOAD_SIZE, 32u));
msg.set(_signing_verifying_nonce, min((uint8_t)MAX_PAYLOAD_SIZE, (uint8_t)32u));
_signing_verification_ongoing = true;
_signing_timestamp = hwMillis(); // Set timestamp to determine when to purge nonce
return true;
Expand All @@ -152,7 +152,7 @@ void signerAtsha204PutNonce(MyMessage &msg)
}

(void)memcpy((void *)_signing_signing_nonce, (const void *)msg.getCustom(),
min((uint8_t)MAX_PAYLOAD_SIZE, 32u));
min((uint8_t)MAX_PAYLOAD_SIZE, (uint8_t)32u));
if (MAX_PAYLOAD_SIZE < 32u) {
// We set the part of the 32-byte nonce that does not fit into a message to 0xAA
(void)memset((void *)&_signing_signing_nonce[MAX_PAYLOAD_SIZE], 0xAA, 32u - MAX_PAYLOAD_SIZE);
Expand Down Expand Up @@ -197,7 +197,7 @@ bool signerAtsha204SignMsg(MyMessage &msg)

// Transfer as much signature data as the remaining space in the message permits
(void)memcpy((void *)&msg.data[msg.getLength()], (const void *)_signing_hmac,
min(MAX_PAYLOAD_SIZE - msg.getLength(), 32));
min((uint8_t)MAX_PAYLOAD_SIZE - msg.getLength(), (uint8_t)32u));

return true;
}
Expand Down Expand Up @@ -257,7 +257,7 @@ bool signerAtsha204VerifyMsg(MyMessage &msg)

// Compare the calculated signature with the provided signature
if (signerMemcmp(&msg.data[msg.getLength()], _signing_hmac,
min(MAX_PAYLOAD_SIZE - msg.getLength(), 32))) {
min((uint8_t)MAX_PAYLOAD_SIZE - msg.getLength(), (uint8_t)32u))) {
return false;
} else {
return true;
Expand All @@ -280,7 +280,7 @@ static void signerCalculateSignature(MyMessage &msg, bool signing)
#endif

while (bytes_left) {
uint16_t bytes_to_include = min(bytes_left, 32);
uint16_t bytes_to_include = min(bytes_left, (uint16_t)32u);

(void)atsha204_wakeup(_signing_temp_message); // Issue wakeup to reset watchdog
memset(_signing_temp_message, 0, 32);
Expand Down

0 comments on commit 43e24a3

Please sign in to comment.