tpm2: Fix issue related to CryptGenerateKeyDes (TPM 2 errata v1.4)

Fix the following issue from TPM 2 errata v1.4 2.6.3:

"The function CryptGenerateKeyDes() in the reference code in Part 4,
0.2.9.2.3 does not correctly check the symmetric key size provided in the
sensitive parameter. To fix the issue, the function will check that the
size of the requested TDES key is a multiple of 8 bytes or otherwise the
TPM will return TPM_RC_SYMMETRIC."

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2023-03-06 15:55:58 -05:00 committed by Stefan Berger
parent 6e95c68503
commit fb86111ca9

View File

@ -3,7 +3,6 @@
/* Functions Required for TDES */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: CryptDes.c 1398 2018-12-17 22:37:57Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -55,7 +54,7 @@
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2016 - 2018 */
/* (c) Copyright IBM Corp. and others, 2016 - 2023 */
/* */
/********************************************************************************/
@ -166,6 +165,12 @@ CryptGenerateKeyDes(
// number of bits.
sensitive->sensitive.sym.t.size =
BITS_TO_BYTES(publicArea->parameters.symDetail.sym.keyBits.sym);
// Because we use BYTE_ARRAY_TO_UINT64 below, require the requested DES key
// to be a multiple of 8 bytes in size.
if((sensitive->sensitive.sym.t.size % 8) != 0)
{
return TPM_RC_SYMMETRIC;
}
#if USE_OPENSSL_FUNCTIONS_SYMMETRIC // libtpms added begin
if (rand == NULL)
return OpenSSLCryptGenerateKeyDes(sensitive);