Commit Graph

997 Commits

Author SHA1 Message Date
Stefan Berger
5b55e9d9a2 rev180: Sync other #defines in GpMacros.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
1e22e15bdd rev180: Sync #defines and #includes in GpMacros.h with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
23704dcfbe rev180: Sync _TPM_Init with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
2e74c49c41 rev180: Add _plat__ACT_GetPending/Tick prototypes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
a750cfe419 rev180: Sync a pAssert in SessionCapGetSaved
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
3fbcdbcd06 rev180: Sync PCR related headers
Since GLOBAL_C is now set in Platform.h it is necessary to adjust the usage
of this #define in NVMarshal.c.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
bfbd6fd078 rev180: Rename and sync random number generating functions
Rename the functions and adjust callers everywhere:
- BnGetRandomBits to TpmMath_GetRandomInteger
- BnGenerateRandomInRange to TpmMath_GetRandomInRange

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
a9b810a401 rev180: Move some random number functions to TpmMath_Util.c
This is a straight move of 2 random number generating functions
into TpmMath_Util.c

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
5728a16848 rev180: Sync TpmFailureMode with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
d7b2ff804f rev180: Add ALLOW_FORCE_FAILURE_MODE with 'NO' and use it
Set ALLOW_FORCE_FAILURE_MODE to 'NO' and used it in some places where
SIMULATION was used, which is also set to 'NO'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
831a9410ad rev180: Sync unused TPM/__plat_TearDown functions
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
c161176bcd rev180: Sync bignum related headers
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
05fe5a20c2 rev180: Sync BnToOsslMath.h with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
ab548892a7 rev180: Merge unused prototypes into CryptPrimeSieve_fp.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
a2bcafe53b rev180: Add BnOssl.h and use it instread of Tpm.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
3e0cf3eb45 rev180: Sync ECC and dependencies with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
67820395b9 rev180: Move types of ECC signature functions into type-specific files
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
f89b536fdd rev180: Reformat (renamed) BnToOsslMath.h
Remove an unnecessary include of openssl/ecdsa.h.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
ccd3fd8f9e rev180: Sync usage of DRBG_Uninstantiate (where missing)
Add calls to DRBG_Uninstantiate where it was missing.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
b10299da26 rev180: Sync VENDOR_PERMANENT_AUTH_ENABLED and it usage with upstream
VENDOR_PERMANENT was not defined by libtpms and therefore it was not
used. Now libtpms sets VENDOR_PERMANENT_AUTH_ENABLED to NO to replace
the VENDOR_PERMANENT from before.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
d0501e06d8 rev180: Replace bn_primt_t with ci_prime_t
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
56c73983e3 rev180: Sync CryptKDFe with upstream (bugfix)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
60ee31d866 rev180: Add BnSupportLibInit() prototype to TpmToOsslSupport_fp.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
1b929f0366 rev180: Remove HASH_ALIGNMENT from TpmToOsslHash.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
dc15065e35 rev180: Sync reformatting of BnToOsslMath.c with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
6bfa750639 rev180: Replace LOG_FAILURE + return FALSE with FAIL_BOOL
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
6241305be4 rev180: Sync CryptPrimeSieve with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
f29174361d rev180: Sync unused TpmMath_IsProbablyPrime with upstream
Since libtpms sets RSA_KEY_SIEVE = YES the TpmMath_IsProbablyPrime is
unused and can be modified in any way without affecting anything.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
4fc596a724 rev180: Convert rest of CrytpRsa.c to use Crypt_Int*
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
e703875190 rev180: Sync LIB_INCLUDE and dependencies and their usages
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
9bc963aef4 rev180: Use renamed function ExtMath_Debug_CompatibilityCheck()
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
c62adba500 rev180: Change data type of s_ComposeOfSmallPrimes to const Crypt_Int*
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
f34500922f rev180: Replace bigNum with Crypt_Int* (part 2)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
ae7e37017f rev180: Replace bigNum with Crypt_Int*
Add new #define's for Crypt_Int* numbers, which are compatible to bigNum
anf bitConst. Only add some functions that support Crypt_Int* in this step.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
d7ebbb364b rev180: Sync MinMax.h with upstream
Remove previously disablement of #define since now it compiles properly.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
aa7219cae7 rev180: Add tpm_public.h and VerifyConfiguration.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
54d8572cef rev180: Move some defines from GpMacros.h to TpmCalculatedAttributes.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
6b855d84ab rev180: Move radix-related defines into tpm_radix.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
ed3b62dc38 rev180: Add struct_type param to BN_STRUCT_DEF and adjust all users
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
be2bb5b00d rev180: Add FAIL_RC & FAIL_NULL & FAIL_IMMEDIATE and use them
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
3eee74f6d3 rev180: Sync _plat__GetUnique with upstream
The value returned from a call to this function is written into
g_platformUniqueDetails but not used by libtpms since VENDOR_PERMANENT is
not set.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
f61c319275 rev180: Move g_manufactured to Global.c
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
a0a48464ac rev180: Add (unused) parameter to PublicAttributesValidation
Add yet unused parameter 'primaryHierarchy to PublicAttributesValidation.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
ba195ee8ab rev180: Rename header to BnSupport_interface.h and rename a few functions
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
1f4ba7dcb1 rev180: Make Msb a static function
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
f66e894b82 rev180: Make TpmSetFailureMode static
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
50b135e2b4 rev180: Move TPM2B_STRING definitions into Global.c
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
2ab5de852e rev180: Replace ERROR_RETURN with ERROR_EXIT
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
a8fe6dd40d rev180: Move SM2KeyExchange prototype into header file
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
1832a89202 rev180: Sync X509ProcessExtensions with upstream (bugfix)
Set badRestricted if keyEncipherment flag is set rather than keyAgreement
bit.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
4addb2168d rev180: Sync ASN1EndMarshalContext with upstream
Remove a part that has disappeared in upstream.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
951012e293 rev180: Sync TPM_Manufacture with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
67578c8df1 rev180: Sync CryptSecretEncrypt/Decrypt with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
b3c0a85995 rev180: Rename TpmAsn1/Asn1_fp.h to TpmASN1/ASN1_fp.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
6dcb416ddf rev180: Add VendorInfo.c and use its functions
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
26bb7d87d2 rev180: Move some #define's into new VendorInfo.h
Some of the defines are used in JSON strings and to have them properly
formatted, remove the surrounding '()' from numbers.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
ab8e7065ba rev180: Sync PCRBelongsTCBGroup with upstream
The custom code can be removed since the PCR table now handles the values
appropriately.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
36e4f0a9c6 rev180: Sync PCRStartup with upstream
The function has been tested to show that the PCRs are initialized
with the same values as before.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
db5291789d rev180: Sync GetPcrPointer and dependencies with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
83288a0230 rev180: Sync PCRManufacture and enable all SHA banks (as before)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
2aecb49691 rev180: Make PCRGetProperty a public function
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
af4fc0e66d rev180: Sync PCRBelongsAuthGroup/PolicyGroup with upstream (bugfix?)
Since none of the authValuesGroup'd and policyAuthGroup's are != 0,
the two functions will now always return false even though they
returned TRUE before for 20 <= PCR <= 22.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
a12cb47243 rev180: Add PCR related headers and sync up on PCR function changes
Disable some PCR functions that are not needed in this step, use
other ones and adjust call sites.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
fa037c9741 rev180: Sync GpMacros.h with upstream
Remove unused TEST_HASH.
Temporarily disable the #define in MinMax.h to enable compilation.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
8f62382f61 rev180: Sync _plat__NvDisable with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
db4a439a93 rev180: Replace __plat_NvIsDifferent with _plat__NvGetChangedStatus
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
eef8cf3a2f rev180: Add TpmProfile_ErrorCodes.h and use it instead of TpmError.h
Replace TpmError.h with TpmProfile_ErrorCodes.h.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
d37894d010 rev180: Replace _plat__IsNvAvailable with _plat__GetNvReadyState
Replace _plat__IsNvAvailable with _plat__GetNvReadyState and use #define's
as return values. Adjust call sites.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
425f7bafce rev180: Sync parameters passed to _plat__NVEnable and adjust callers
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
5fc9f68f33 rev180: Sync NVMem.c with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
b1da8a11ab rev180: Sync _plat__ClockRateAdjust and adjust caller
Replace _plat__ClockAdjustRate with _plat__ClockRateAdjust and use its
new #defines at the call sites.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
74ac34c0a2 rev180: Add platform_public_interface.h and remove protos in other files
Add platform_public_interface.h from upstream and disable some prototypes
and #defines for functions that are not needed or not needed yet. Remove
prototypes in other header files to avoid duplicates.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
5a82f07f73 rev180: Add platform_to_tpm_interface.h and use it
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
b3a00577e8 rev180: Add HierarchyNormalizeHandle and use it
Add a simplified version of HierarchyNormalizeHandle that simply returns
the passed handle and sync the callers with upstream.
HierarchyNormalizeHandle will be extended at some later point.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
150e7115b7 rev180: Use DecomposeHandle in HierarchyGetPrimarySeedCompatLevel
Since HierarchyGetPrimarySeedCompatLevel may in the future be called with
some other hierachies than the currently existing ones, return the value
SEED_COMPAT_LEVEL_LAST in this case instead of causing an internal
failure.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
9c17a56946 rev180: Add ValidateHierarchy and use it in HierarchyIsEnabled
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
eb38a9d822 rev180: Return TPM_RC from HierarchyGetProof/PrimarySeed & adjust callchain
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
71ed8325bb rev180: Rename Platform_fp.h to platform_public_interface.h and sync
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
0599339e61 rev180: Move g_rcIndex from Global.h to Global.c
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
29dbcfa10c rev180: Move #defines from TpmProfile.h into other header files
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
25a66c4463 rev180: Move NvGetIndexName to NV_spt.c
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
9dfa4b4e4f rev180: Move TPM_CC_FIRST/LAST to TpmTypes.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
6d38dc72da rev180: Rename swap.h to endian_swap.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
9d71aa4299 rev180: Rename PCRSimStart to PCRManufacture
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
0043f1ba9d rev180: Replace VERIFY with GOTO_ERROR_UNLESS
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
16c9d51a3e rev180: Add Marshal.h and sync its usage with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
2c63bf6c81 rev180: Define MUST_BE and replace cAssert with it
Introduce MUST_BE #define and replace cAssert with it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
fd2e55e3a5 rev180: Add compiler dependencies header for gcc and msvc
Add compiler dependencies files for gcc and msvc and remove some of
the existing #define from CompilerDependencies.h

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
f01c9776f5 rev180: Sync whitespace, comment and trivial changes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-03 20:23:19 -05:00
Stefan Berger
920aa5e02b tpm2: Use Carmichael function for RSA priv. exponent D (>= 2048 bits)
Like OpenSSL use the Carmichael function for the RSA private exponent D
when an RSA key has >= 2048 bits and public exponent e uses more than
2 bytes. Otherwise use the Euler totient function.

The main difference is that by TPM 2 using the Carmichael function OpenSSL
now behaves the same way as when it is used by other programs that for
example load keys from PEM files where the private exponent D was
calculated with this function. The difference is seen when for example
blobs cannot be decrypted where newer versions of OpenSSL (with implicit
rejection enabled) returned results of 48 bytes every time rather than a
deterministic (for same input blob) but varying number of bytes (Euler
totient).

Switching to the Carmichael function does not have any negative impact
on interoperatibility with OpenSSL nor does it affect interoperability
between versions of TPM 2 code that did not use it. This means that
data encrypted or signed by OpenSSL or TPM 2 can be decrypted or verified
by TPM 2 or OpenSSL and that data encrypted or signed with either new
or old code in TPM 2 can be decrypted or verified with either old or
new code in TPM 2.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-02 18:16:51 -05:00
Stefan Berger
6566330177 tpm2: Compute RSA private key before saving
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-02 18:09:13 -05:00
Stefan Berger
27a3e7e2d2 tpm2: Get rid of written variable and replace with objectSize
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-02 18:09:13 -05:00
Stefan Berger
87fbcfd73d tpm2: Replace a few BOOLs with ints
Since BOOL's are effectively int's the replacement does not change anything.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-12-28 13:42:28 -05:00
Stefan Berger
e11413f2e0 tpm2: NVMarshal: Add #error when a #define's are not supported
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-12-28 13:42:28 -05:00
Stefan Berger
09c9ea1a44 tpm2: Add missing semicolons after pAsserts
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-12-28 13:42:28 -05:00
Stefan Berger
01ffc69132 tpm2: Comment and rearrange some code
Rearrange the call to RsaInitializeExponentOld in CryptyRsaGenerateKey
so that this function can be removed from the OpenSSLCryptRsaGenerateKey
implementations.

Sync the PackExponent and UnpackExponent functions calls with upstream
but comment them since libtpms does not used them (will not remove
privateExponent from OBJECT).

Add comments to diffs between libtpms and upstream.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-29 21:20:07 -04:00
Stefan Berger
95e54b0d9c tpm2: Sync MarshalSensitive with upstream
Since we never set the RSA_prime_flag or pack Q, dP, dQ, qInv into the
sensitive->rsa TPM 2, dactivate the block checking this flag because
it will never be used.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-29 21:20:07 -04:00
Stefan Berger
5620106e47 tpm2: Sync ObjectLoad with upstream
Sync ObjectLoad with upstream. Now CryptRsaLoadPrivateExponent may be
called with the object parameter being NULL, which happens only when
it is called from TPM2_Import().

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-29 21:20:07 -04:00
Stefan Berger
66a503b709 tpm2: Add TPMT_PUBLIC & TPMT_SENSITIVE params to CryptRsaLoadPrivateExponent
In the next patch there will be ObjectLoad calling
CryptRsaLoadPrivateExponent without providing an OBJECT to this function
but only to use it to check the consistency of TPMT_PUBLIC and
TPMT_SENSITIVE parameters. To allow this, add these two parameter to the
function (= sync with upstream) but also keep the rsaKey as an optional
parameter (libtpms only) so that the flag attributes.privateExp can still
be set on the key in case the values for dP, dQ, qINv are valid.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-29 21:20:07 -04:00
Stefan Berger
8532cd818a tpm2: Sync part of CryptRsaLoadPrivateExponent with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-29 21:20:07 -04:00
Stefan Berger
36d1e03368 tpm2: Use new privateExponent also for dP, dQ, and qInv
Also use the new privatExponent for dP, dQ and qInv.

There are two functions that need to be adapted:
- ComputePrivateExponent: producer of these parameters
- RsaPrivateKeyOp       : consumer of these parameters

ComputePrivateExponent is converted to store the results into Z->dP,
Z->dQ, and Z->qInv. Therefore, remove the old privateExponent parameter
*pExp, that was previously used to store them, from the signature of this
function and pull out the initialization of pExp and preservation of Q
to be done before calling this function. This is done in the 2 calling
functions. After returning from the function copy the values of Z->dP,
Z->dQ, and Z->qInv to the old privateExponent where the results had
been stored previously and where we need to have them.

This change results in a sequence like this for the 2 callers:

RsaInitializeExponentOld(&rsaKey->privateExponent);
BnCopy((bigNum)&rsaKey->privateExponent.Q, Z->Q); // preserve Q

VERIFY(ComputePrivateExponent(bnE, Z));

RsaSetExponentOld(&rsaKey->privateExponent, Z);   // duplicate dP, dQ, qInv

The values for dP, dQ, ad qInv are consumed by RsaPrivateKeyOp. Therefore,
adjust this functions signature by removing the old privateExponent
parameter *pExp from it and make sure that callers initialize Z->dP,
Z->dQ, and Z->qInv before calling this functions. There are two call-sites
where the one in RSADP looks like this:

RsaSetExponentFromOld(Z, &key->privateExponent); // copy Q, dP, dQ, qInv to Z
VERIFY(RsaPrivateKeyOp(bnM, Z));

The call site in CryptRsaGenerateKey has called ComputePrivateExponent
before, therefore it already holds the values in Z.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-29 21:20:07 -04:00
Stefan Berger
c9a0650e52 tpm2: Use new privateExponent struct in RsaPrivateKeyOp
Pass the new privateExponent to RsaPrivateKeyOp replacing the P parameter.
To be able to use MakePgreaterThanQ(Z), make sure that both callers of
this function have Z->P and Z->Q values properly set.

This function has the following two callers:
- CryptRsaPrivateKey: Z->P and Z->Q are already holding valid values
- RSADP: Copy the value of privateExponent.Q to Z->Q.

An inconsequential side effect of the changes to RsaPrivateKeyOp()
is that Z->P is greater than Z->Q upon return from this function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-29 21:20:07 -04:00
Stefan Berger
7edfb28a2e tpm2: RSADP: Replace local bnP with P of new privateExponent
Replace the local variable bnP with Z->P. Initialize Z->P with the
value that bnP had been initialized with.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-29 21:20:07 -04:00
Stefan Berger
a866dda5ed tpm2: Replace P and Q params of ComputerPrivateExponent with new privateExponent
Replace the P and Q parameters of ComputePrivateExponent with the new
privateExponent struct (sync with upstream).

ComputePrivateExponent has two callers:
- CryptRsaGenerateKey: Z already holds P and Q from previous change
- CryptRsaLoadPrivateExponent: Sync the code with upstream so that we can also
     use the privateExponent Z as parameter to ComputePrivateExponent holding
     valid values in Z->P and Z->Q.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-29 21:20:07 -04:00
Stefan Berger
218337ea2a tpm2: Use new privateExponent struct in CryptRsaGenerateKey for P and Q
- Import RsaInitializeExponent from upstream
- CryptRsaGenerateKey: Replace local bnP and bnQ variables by using Z->P
  and Z->Q respectively

The only side-effect this change has is that it costs more initialization
time when NEW_PRIVATE_EXPONENT initializes the currently unused variables
dP_unused, dQ_unused, and qInv_unused.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-29 21:20:07 -04:00
Stefan Berger
9b16a500d3 tpm2: Add new typedef privateExponent used by upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-29 21:20:07 -04:00
Stefan Berger
d28f4e0e34 tpm2: Rename RsaInitializeExponent to RsaInitializeExponentOld
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-29 21:20:07 -04:00
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