Skip to content

Commit 1012a3e

Browse files
ivaniushkovFlavio Ceolin
authored andcommitted
Fix warnings reported by UBSAN
fixed the following warnings reported by UBSAN: 1) modules/crypto/tinycrypt/lib/source/aes_encrypt.c:93:8: runtime error: left shift of 251 by 24 places cannot be represented in type 'int' 2)modules/crypto/tinycrypt/lib/source/aes_encrypt.c:86:25: runtime error: left shift of 250 by 24 places cannot be represented in type 'int' Signed-off-by: Ivan Iushkov <[email protected]>
1 parent 3e9a49d commit 1012a3e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/source/aes_encrypt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static inline unsigned int rotword(unsigned int a)
6464
return (((a) >> 24)|((a) << 8));
6565
}
6666

67-
#define subbyte(a, o)(sbox[((a) >> (o))&0xff] << (o))
67+
#define subbyte(a, o)((uint32_t)sbox[((a) >> (o))&0xff] << (o))
6868
#define subword(a)(subbyte(a, 24)|subbyte(a, 16)|subbyte(a, 8)|subbyte(a, 0))
6969

7070
int tc_aes128_set_encrypt_key(TCAesKeySched_t s, const uint8_t *k)
@@ -83,7 +83,7 @@ int tc_aes128_set_encrypt_key(TCAesKeySched_t s, const uint8_t *k)
8383
}
8484

8585
for (i = 0; i < Nk; ++i) {
86-
s->words[i] = (k[Nb*i]<<24) | (k[Nb*i+1]<<16) |
86+
s->words[i] = ((uint32_t)k[Nb*i]<<24) | (k[Nb*i+1]<<16) |
8787
(k[Nb*i+2]<<8) | (k[Nb*i+3]);
8888
}
8989

0 commit comments

Comments
 (0)