Skip to content

Commit

Permalink
Fix of by one error on encryption of multiples of 16
Browse files Browse the repository at this point in the history
Function `lw_encrypt` overruns data sizes which are a multiple of
the key length (and thus encrypts whatever comes next in memory.
This fix takes care of the edge case.
  • Loading branch information
kratenko committed Sep 12, 2019
1 parent d5178fa commit ae8f547
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lw/lw.c
Expand Up @@ -1596,7 +1596,10 @@ int lw_encrypt(uint8_t *out, lw_key_t *key)
uint8_t A[LW_KEY_LEN];

uint16_t const over_hang_bytes = key->len%LW_KEY_LEN;
int blocks = key->len/LW_KEY_LEN + 1;
int blocks = key->len/LW_KEY_LEN;
if (over_hang_bytes) {
++blocks;
}

memset(A, 0, LW_KEY_LEN);

Expand Down

0 comments on commit ae8f547

Please sign in to comment.