Skip to content

Commit 0704e9b

Browse files
committed
Fix type casting in min function calls in MySigningAtsha204 ####
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.
1 parent 72cdb70 commit 0704e9b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

core/MySigningAtsha204.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ bool signerAtsha204GetNonce(MyMessage &msg)
127127
}
128128
(void)memcpy((void *)_signing_verifying_nonce, (const void *)signerSha256(_signing_verifying_nonce,
129129
32),
130-
min((uint8_t)MAX_PAYLOAD_SIZE, 32u));
130+
min((uint8_t)MAX_PAYLOAD_SIZE, (uint8_t)32u));
131131

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

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

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

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

202202
return true;
203203
}
@@ -257,7 +257,7 @@ bool signerAtsha204VerifyMsg(MyMessage &msg)
257257

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

282282
while (bytes_left) {
283-
uint16_t bytes_to_include = min(bytes_left, 32);
283+
uint16_t bytes_to_include = min(bytes_left, (uint16_t)32u);
284284

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

0 commit comments

Comments
 (0)