Skip to content

Commit 7b4a5c1

Browse files
committed
check range in _rijndael_ecb_ functions
There is no check that the 'skey' structure has been properly initialized. For example, the skey->rijndael.Nr is assumed to contain a positive number corresponding to the number of AES rounds to perform. In _rijndael_ecb_encrypt the skey->rijndael.Nr is subtracted by two, which can result in an integer underflow if the structure hasn't been initialized correctly. By clamping the value for skey->rijndael.Nr into the valid rounds for AES we can return an error instead of ending up reading outside the boundaries (of skey->rijndael.eK). Signed-off-by: Joakim Bech <joakim.bech@linaro.org> Reported-by: Martijn Bogaard <bogaard@riscure.com>
1 parent e01e4c5 commit 7b4a5c1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/ciphers/aes/aes.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ int ECB_ENC(const unsigned char *pt, unsigned char *ct, const symmetric_key *ske
295295
LTC_ARGCHK(skey != NULL);
296296

297297
Nr = skey->rijndael.Nr;
298+
299+
if (Nr < 2 || Nr > 16)
300+
return CRYPT_INVALID_ROUNDS;
301+
298302
rk = skey->rijndael.eK;
299303

300304
/*
@@ -475,6 +479,10 @@ int ECB_DEC(const unsigned char *ct, unsigned char *pt, const symmetric_key *ske
475479
LTC_ARGCHK(skey != NULL);
476480

477481
Nr = skey->rijndael.Nr;
482+
483+
if (Nr < 2 || Nr > 16)
484+
return CRYPT_INVALID_ROUNDS;
485+
478486
rk = skey->rijndael.dK;
479487

480488
/*

0 commit comments

Comments
 (0)