From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web09.7379.1575596960773516367 for ; Thu, 05 Dec 2019 17:49:20 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: shenglei.zhang@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Dec 2019 17:49:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,282,1571727600"; d="scan'208";a="214297257" Received: from shenglei-dev.ccr.corp.intel.com ([10.239.158.52]) by orsmga006.jf.intel.com with ESMTP; 05 Dec 2019 17:49:19 -0800 From: "Zhang, Shenglei" To: devel@edk2.groups.io Cc: Jiewen Yao , Jian J Wang , Chao Zhang Subject: [PATCH] SecurityPkg/RngDxe: Add ASSERT for array Ek Date: Fri, 6 Dec 2019 09:49:12 +0800 Message-Id: <20191206014912.19944-1-shenglei.zhang@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 Add ASSERT for Ek to ensure things out of EK would not be visited. Cc: Jiewen Yao Cc: Jian J Wang Cc: Chao Zhang Signed-off-by: Shenglei Zhang --- SecurityPkg/RandomNumberGenerator/RngDxe/AesCore.c | 2 ++ SecurityPkg/RandomNumberGenerator/RngDxe/AesCore.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AesCore.c b/SecurityPkg/RandomNumberGenerator/RngDxe/AesCore.c index 66edaf10c468..6c99ec83e822 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AesCore.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AesCore.c @@ -160,6 +160,7 @@ AesExpandKey ( // Initialize the encryption key scheduler // for (Index2 = Nk, Index3 = 0; Index2 < Nw; Index2 += Nk, Index3++) { + ASSERT(Index2 < sizeof(Ek)/sizeof(Ek[0])); Temp = Ek[Index2 - 1]; Ek[Index2] = Ek[Index2 - Nk] ^ (AES_FT2((Temp >> 16) & 0xFF) & 0xFF000000) ^ (AES_FT3((Temp >> 8) & 0xFF) & 0x00FF0000) ^ @@ -181,6 +182,7 @@ AesExpandKey ( Ek [Index1 + Index2] = Ek[Index1 + Index2 - Nk] ^ Ek[Index1 + Index2 - 1]; } if (Index2 + 4 < Nw) { + ASSERT((Index2 +4) < sizeof(Ek)/sizeof(Ek[0])); Temp = Ek[Index2 + 3]; Ek[Index2 + 4] = Ek[Index2 + 4 - Nk] ^ (AES_FT2((Temp >> 24) & 0xFF) & 0xFF000000) ^ (AES_FT3((Temp >> 16) & 0xFF) & 0x00FF0000) ^ diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AesCore.h b/SecurityPkg/RandomNumberGenerator/RngDxe/AesCore.h index e07f90050ac3..40d6b13d2b81 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AesCore.h +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AesCore.h @@ -9,6 +9,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #ifndef __AES_CORE_H__ #define __AES_CORE_H__ +#include + /** Encrypts one single block data (128 bits) with AES algorithm. -- 2.18.0.windows.1