Skip to content

Commit 02b9104

Browse files
committed
ZGW-3441: serialapi: Harden SerialAPI_AES128_Encrypt use of rijndael alg
This mitigates a bit use of invalid input data. Also note rijndaelEncrypt is not returning an 1error on wrong arguments, this is prone to misuse or malicious attacks. After more investigations in zipgwateway it looks like "rijndael-alg-fst.c" was a copy of "Optimised C code v3.0" (under public domain). I also note that upstream stated that: IMPORTANT NOTE ! This code was written in order to clarify the mathematical description, and to run the statistical test. Without modification, it should not be used to encrypt files, or for any other application. And the downstream changes over that code are minimal. So we can assume the absent check were done on purpose, since it is the fast version of the original "Reference code in ANSI C v2.2". Please refer to related context. Origin: #36 Bug-SiliconLabs: ZGW-3441 Relate-to: j.s.c/b/UIC-3660 Relate-to: SiliconLabsSoftware/z-wave-protocol-controller-legacy#95 Relate-to: c.s.c/x/MbQ4Jg Relate-to: SLVDBBP-3113159 Signed-off-by: Philippe Coval <philippe.coval@silabs.com>
1 parent d0420b8 commit 02b9104

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/serialapi/Serialapi.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,6 +3475,12 @@ BOOL ZW_IsPrimaryCtrl (void) {
34753475
BOOL SerialAPI_AES128_Encrypt(const BYTE *ext_input, BYTE *ext_output, const BYTE *cipherKey) CC_REENTRANT_ARG{
34763476
int Nr; /* key-length-dependent number of rounds */
34773477
u32 rk[4*(MAXNR + 1)]; /* key schedule */
3478+
3479+
if (ext_input == NULL || ext_output == NULL || cipherKey == NULL) {
3480+
ASSERT(0); // Invalid input params
3481+
return 0;
3482+
}
3483+
34783484
/*if(SupportsCommand(FUNC_ID_ZW_AES_ECB)) {
34793485
memcpy(&buffer[0],cipherKey,16);
34803486
memcpy(&buffer[16],ext_input,16);
@@ -3483,6 +3489,10 @@ BOOL SerialAPI_AES128_Encrypt(const BYTE *ext_input, BYTE *ext_output, const BYT
34833489
return 1;
34843490
} else*/ {
34853491
Nr = rijndaelKeySetupEnc(rk, cipherKey, 128);
3492+
if (Nr <= 0) {
3493+
ASSERT(0); // Key setup failed
3494+
return 0;
3495+
}
34863496
rijndaelEncrypt(rk, Nr, ext_input, ext_output);
34873497
return 1;
34883498
}

0 commit comments

Comments
 (0)