Commit Graph

1258 Commits

Author SHA1 Message Date
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