Skip to content

Commit 0b066f8

Browse files
committed
[hf seos] Carry when incrementing
1 parent 7fa548f commit 0b066f8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

client/src/cmdhfseos.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,12 @@ static int decrypt_cryptogram(uint8_t *key, uint8_t *input, uint8_t *out, int in
163163
}
164164

165165
static void increment_command_wrapper(uint8_t *input, int input_len) {
166-
input[input_len - 1]++; // Increment the last element of the header by 1
166+
// Increment the last element of the header by 1
167+
// If it overflows, increment the next-to-last, and so on
168+
for (uint8_t i=0; i<input_len-1; i++) {
169+
input[input_len - 1 - i]++;
170+
if (input[input_len - 1 - i] != 0x00) return;
171+
}
167172
}
168173

169174
static void padToBlockSize(const uint8_t *input, int *inputSize, int blockSize, uint8_t *output) {

0 commit comments

Comments
 (0)