Commit Graph

790 Commits

Author SHA1 Message Date
Stefan Berger
0de1cea8a5 tpm2: rev164: Trivial whitespace, comment, and libtpms-unused change
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-26 12:20:14 -04:00
Stefan Berger
687f0de78c tpm2: Add publicArea and sensitive params to CryptRsaGenerateKey
The upstream function switches entirely to publicArea and sensitive
parameters for CrytpRsaGenerateKey getting rid of the OBJECT. We still
need the OBJECT at this point, so keep it for now but annotate the
code and add a consitency check that ensures that the publicArea and
sensitive parameters are from the OBJECT. This holds for the single
caller.

Adjust the single caller to the change in parameters.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-26 12:20:14 -04:00
Stefan Berger
c10974ab85 tpm2: Check result from CryptRsaLoadPrivateExponent in RSADP
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-26 11:17:26 -04:00
Stefan Berger
9e6e0fdc50 tpm2: Rework the logic validating the keys in ObjectLoad
Previously the key check was done when object == NULL. Now this
particular case is handle by a check being done when parent == NULL
since the only caller of ObjectLoad() with object == NULL also has
parent == NULL, so there's no behavior change. All other cases
are handled as before.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-26 11:17:26 -04:00
Stefan Berger
d2d425a126 tpm2: Apply some trivial changes to RSADP
- Use UnsignedCompareB() rather than BnUnsignedCmp()
- Use VERIFY to check results and add failure exit.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-26 11:17:26 -04:00
Stefan Berger
6dd7cf4eff tpm2: Apply some trivial changes to RsaPrivateKeyOp
- Remove code related to CRT_FORMAT_RSA == NO.
- Remove N parameter from function and adjust callers
- Use VERIFY after each statement

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-26 11:17:26 -04:00
Stefan Berger
a33fd3b0de tpm2: Apply some trivial changes to CryptRsaGenerateKey
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-26 11:17:26 -04:00
Stefan Berger
f1ea4f51cb tpm2: Helpers: Remove CRT_FORMAT_RSA == YES checks
Since CRT_FORMAT_RSA can only be YES, remove the checks for
this #define.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-26 09:41:54 -04:00
Stefan Berger
2d110169a6 tpm2: Sync part of ComputePrivateExponent
- Remove support for CRT_FORMAT_RSA == NO
- Remove now unused parameter N from function signature; adjust callers
- Rename E to pubExp
- Rename temp to pT

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-26 09:41:54 -04:00
Stefan Berger
982b8678c5 tpm2: Sync part of CryptRsaGenerateKey
- Continue the prime number generation while retVal == TPM_RC_NO_RESULT
- Terminate the loop when BnGeneratePrimeForRSA() returns a failure

The changes should not lead to any different primary keys than before.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-26 09:41:54 -04:00
Stefan Berger
a9a8e8fb93 tpm2: Sync: Remove CRT_FORMAT_RSA from RsaInitializeExponent
Since CRT_FORMAT_RSA == NO is not supported, remove it from
RsaInitializeExponent.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-26 09:41:54 -04:00
Stefan Berger
c579a3c8de tpm2: Sync RSAEP with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-26 09:41:54 -04:00
Stefan Berger
eace1d8fee tpm2: Sync: Add checks for g_inFailure mode after DRBG ops
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-26 09:41:54 -04:00
Stefan Berger
bed0069d1f tpm2: Sync: Replace salt size call by call to CryptRsaPssSaltSize
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-25 22:57:45 -04:00
Stefan Berger
b015702b43 tpm2: Sync defintion of RSA-related BN_TYPE's
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-25 22:57:45 -04:00
Stefan Berger
44e31a3263 tpm2: Remove unused RSA_KEY typedef struct
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-25 22:57:45 -04:00
Stefan Berger
55d64c75dd tpm2: Use sensitive instead of equivalent object->sensitive
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-25 22:57:45 -04:00
Stefan Berger
9916aa936e tpm2: Remove duplicate init of sensitive.sym.t.size
The called function is also initializing this field with the same value.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-25 22:57:45 -04:00
Stefan Berger
cf9d0d32b9 tpm2: Add missing libtpms changed comments to sm4 related code
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-25 22:57:45 -04:00
Stefan Berger
9f15d86413 tpm2: Sync zeroization of variables with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-25 22:57:45 -04:00
Stefan Berger
c235a90932 tpm2: ExecuteCommand: Handle unreasonably large command sizes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-25 22:57:45 -04:00
Stefan Berger
4bee97102b tpm2: Pass correct RSA_PRIVATE_SIZE tpp TPM2B_Unmarshal
RSA_PRIVATE_SIZE is the correct size to use since this is the size that
TPM2B_PRIVATE_KEY_RSA has been defined with.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-25 22:57:45 -04:00
Stefan Berger
de921c3ead Revert "Object: clear out sensitive area if on load if not provided"
This reverts commit e82727e546.

The issue has previously been resolved in commit 17255da54c.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-17 20:28:04 -04:00
Rob Shearman
e82727e546 Object: clear out sensitive area if on load if not provided
When an object is later marshalled in TPM2_ContextSave, the publicOnly
attribute isn't taken into account and therefore potentially stale
sensitive information can be marshalled, which is a problem if the
buffer sizes it contains have values that are too large - this
triggers assertion failures.

Avoid this by clearing out the sensitive area upon ObjectLoad if not
provided, making the behaviour consistent with when a fresh, unused,
object entry is used.

Signed-off-by: Rob Shearman <rob@graphiant.com>
2023-08-14 08:45:55 -04:00
Stefan Berger
c702d72afb tpm2: Use GET_ATTRIBUTE to get commandIndex from s_ccAttr
Fix two locations where s_ccAttr[0].commandIndex is used to access the
commandIndex, which does not work when bitfields are not used. Use
GET_ATTRIBUTE() to access the field so that it works when bitfields are
used and when they are not used. There are several locations in this
file where GET_ATTRIBUTE() is already used to access commandIndex.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-03 11:34:43 -04:00
Stefan Berger
6690ea89f7 tpm2: Fix spelling errors
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-07-17 20:37:20 -04:00
Stefan Berger
63b9c36a16 Insert assert ensuring *buflen != BUFLEN_EMPTY_BUFFER (Coverity)
Address a false positive issue detect by Coverity (CID 1517797)
about *buflen.

Per this assignment of buflen

cached_blobs[st].buflen = buffer ? buflen : BUFLEN_EMPTY_BUFFER;

the following is true:

If cached_blobs[].buffer is     NULL then *buflen  = BUFLEN_EMPTY_BUFFER
If cached_blobs[].buffer is not NULL then *buflen != BUFLEN_EMPTY_BUFFER

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-07-13 16:40:35 -04:00
Stefan Berger
f2b5d0c128 tpm12: Use proper format specifier %zu for size_t (CID1517801 & 1517798)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-07-12 18:31:22 -04:00
Fergus Dall
52e98e9758 tpm2: Add test vectors for camellia-192
Signed-off-by: Fergus Dall <sidereal@google.com>
2023-06-05 07:28:16 -04:00
Ben Lytle
0c32f39788 tpm2: fix missing algorithm macro checks
Signed-off-by: Ben Lytle <ben.dav.lytle@hpe.com>
2023-03-17 15:28:36 -04:00
Stefan Berger
dc1aac1ecf tpm2: rev164: Synchronize _TPM_Init() with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-07 12:11:50 -05:00
Stefan Berger
5a7d238653 tpm2: rev164: Sync BN_CONST definition (not used by libtpms)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-07 12:11:50 -05:00
Stefan Berger
2f1fb4c549 tpm2: rev164: Add implementation for TPM2_ECC_Encrypt/Decrypt
Add the implementation for TPM2_ECC_Encrypt/Decrypt. It cannot be
easily enabled due to possible downgrading requirements and also
issues with size-expansion of the PERSISTENT_DATA.auditCommands from
14 to 15 bytes.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-07 12:11:50 -05:00
Stefan Berger
6ac04e4681 tpm2: rev164: Simplify SignedCompareB() implementation
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-07 12:11:50 -05:00
Stefan Berger
496b64c561 tpm2: rev164: Fix CommandDispatchData for CertifyX509Data
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-07 12:11:50 -05:00
Stefan Berger
74a9ab5515 tpm2: rev164: Trivial whitespace, command, and libtpms-unused changes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-07 12:11:50 -05:00
Stefan Berger
c9f9fc52cf tpm2: Fix issue in CryptParameterEncryption() (TPM 2 errata v1.4)
Sync with upstream to fix issue in CryptParameterEncryption() from TPM 2
errate v1.4 2.6.1:

"The functions CryptParameterEncryption() and CryptParameterDecryption() in
the reference code in Part 4, 10.2.6.6.5 and 10.2.6.6.6 do not correctly
check the size of the parameter buffer to be encrypted or decrypted. To fix
the issue, the functions should be corrected to check that the parameter
buffer (a TPM2B type field) is at least 2 bytes in length and should use
the function UINT16_Unmarshal() to read the size of the buffer instead of"
BYTE_ARRAY_TO_UINT16().

[...]

The fixed CryptParameterEncryption() function will enter failure mode and
return TPM_RC_FAILURE if the internal response buffer does not contain
enough data for the UINT16 size field."

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-06 17:39:55 -05:00
Stefan Berger
9425f82960 tpm2: Sync fix in TPM2_PolicyAuthorize() with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-06 17:39:55 -05:00
Stefan Berger
d35a48b284 tpm2: Sync CryptParameterDecrypt implementation with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-03-06 17:39:55 -05:00
Stefan Berger
fb86111ca9 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>
2023-03-06 17:39:55 -05:00
Stefan Berger
92f470c1b0 tpm2: Check size of TPM2B_NAME buffer before reading 2 bytes from it
Fix the missing buffer size check that the TPM 2 errata v1.4 mentions in
2.6.2 by adding a buffer size check before reading 2 bytes from a
TPM2B_NAME buffer. There's no known CVE for this.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-28 17:26:57 -05:00
Stefan Berger
324dbb4c27 tpm2: Check size of buffer before accessing it (CVE-2023-1017 & -1018)
Check that there are sufficient bytes in the buffer before reading the
cipherSize from it. Also, reduce the bufferSize variable by the number
of bytes that make up the cipherSize to avoid reading and writing bytes
beyond the buffer in subsequent steps that do in-place decryption.

This fixes CVE-2023-1017 & CVE-2023-1018.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-28 15:56:38 -05:00
Stefan Berger
b87306ca12 tpm2: Add a caching layer to GetEVPCipher() helper function
Add a caching layer to GetEVPCipher() to avoid having to call evpfn()
mulitple times. Instead, return the 'const EVP_CIPHER *' that a single
call to evpfn() (for a particular algorithm + mode + key size) returned
and cache it for subsequent calls.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-28 12:04:59 -05:00
Stefan Berger
0de6f656b8 tpm2: Replace usage of deprecated DES_random_key() (OSSL 3)
Replace usage of deprecated DES_random_key() with EVP_CIPHER API calls.
These newer calls are much more time consuming than the deprecated call.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-23 17:24:17 -05:00
Stefan Berger
7b8572355b tpm2: Replace deprecated EC_POINTs_mul() (OSSL 3)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-23 17:15:11 -05:00
Stefan Berger
d08b929ded tpm2: Use EVP_CIPHER_CTX_get_params() to get IV
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-13 06:50:42 -05:00
Stefan Berger
06ada5ad3e tpm2: Skip call to DoEVPGetIV() if ivLen = 0
The ivLen may be 0 for ECB and in this case we can skip the call to
DoEVPGetIV().

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-13 06:50:42 -05:00
Stefan Berger
f531ad6927 tpm2: Refactor code that gets current IV
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-13 06:50:42 -05:00
William Roberts
c6c8f63686 Revert "tpm_crypto: support libressl api"
This reverts commit 9afebc712a.

The issue is that opensslv.h is not included and thus the
OPENSSL_VERSION_NUMBER is not getting set.

Signed-off-by: William Roberts <william.c.roberts@intel.com>
2022-07-12 11:28:47 -04:00
William Roberts
27beabc518 tpm_crypto: support libressl api
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2022-07-09 13:30:55 -04:00