Skip to content

Commit

Permalink
Fix overflow on 16 bit systems
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Aug 15, 2020
1 parent fd8fe83 commit 34d24e9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ctaes.c
Expand Up @@ -25,7 +25,7 @@
static void LoadByte(AES_state* s, unsigned char byte, int r, int c) {
int i;
for (i = 0; i < 8; i++) {
s->slice[i] |= (byte & 1) << (r * 4 + c);
s->slice[i] |= (uint16_t)(byte & 1) << (r * 4 + c);
byte >>= 1;
}
}
Expand Down Expand Up @@ -255,7 +255,7 @@ static void SubBytes(AES_state *s, int inv) {
}
}

#define BIT_RANGE(from,to) (((1 << ((to) - (from))) - 1) << (from))
#define BIT_RANGE(from,to) ((uint16_t)((1 << ((to) - (from))) - 1) << (from))

#define BIT_RANGE_LEFT(x,from,to,shift) (((x) & BIT_RANGE((from), (to))) << (shift))
#define BIT_RANGE_RIGHT(x,from,to,shift) (((x) & BIT_RANGE((from), (to))) >> (shift))
Expand Down

0 comments on commit 34d24e9

Please sign in to comment.