From 34d24e93b540b11fa11684226978c4405ea23896 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 14 Aug 2020 15:34:21 -0700 Subject: [PATCH] Fix overflow on 16 bit systems --- ctaes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ctaes.c b/ctaes.c index f3681ae..83d65e4 100644 --- a/ctaes.c +++ b/ctaes.c @@ -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; } } @@ -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))