diff --git a/src/tpm2/crypto/CryptRsa.h b/src/tpm2/crypto/CryptRsa.h index 0d470880..953c2798 100644 --- a/src/tpm2/crypto/CryptRsa.h +++ b/src/tpm2/crypto/CryptRsa.h @@ -79,7 +79,12 @@ BN_TYPE(prime, (MAX_RSA_KEY_BITS / 2)); # error This verson only works with CRT formatted data #endif // !CRT_FORMAT_RSA -typedef struct privateExponent + // libtpms added begin: keep old privateExponent +/* The privateExponentOld is part of the OBJECT and we keep it there even though + * upstream got rid of it and stores Q, dP, dQ, and qInv by appending them to + * P stored in TPMT_SENSITIVE.TPMU_SENSITIVE_COMPOSITE.TPM2B_PRIVATE_KEY_RSA + */ +typedef struct privateExponentOld { bn_prime_t Q; bn_prime_t dP; @@ -87,5 +92,18 @@ typedef struct privateExponent bn_prime_t qInv; } privateExponent_t; +#include "BnMemory_fp.h" + +static inline void +RsaInitializeExponentOld( + privateExponent_t *pExp + ) +{ + BN_INIT(pExp->Q); + BN_INIT(pExp->dP); + BN_INIT(pExp->dQ); + BN_INIT(pExp->qInv); +} // libtpms added end + #endif // _CRYPT_RSA_H diff --git a/src/tpm2/crypto/CryptRsa_fp.h b/src/tpm2/crypto/CryptRsa_fp.h index 47ca40f2..4b099f20 100644 --- a/src/tpm2/crypto/CryptRsa_fp.h +++ b/src/tpm2/crypto/CryptRsa_fp.h @@ -69,10 +69,6 @@ BOOL CryptRsaStartup( void ); -void -RsaInitializeExponent( - privateExponent_t *pExp - ); INT16 CryptRsaPssSaltSize( INT16 hashSize, diff --git a/src/tpm2/crypto/openssl/CryptRsa.c b/src/tpm2/crypto/openssl/CryptRsa.c index d3b93447..619b5958 100644 --- a/src/tpm2/crypto/openssl/CryptRsa.c +++ b/src/tpm2/crypto/openssl/CryptRsa.c @@ -97,17 +97,6 @@ CryptRsaStartup( function returns the pointer to the private exponent value so that it can be used in an initializer for a data declaration */ -void -RsaInitializeExponent( - privateExponent_t *pExp - ) -{ - BN_INIT(pExp->Q); - BN_INIT(pExp->dP); - BN_INIT(pExp->dQ); - BN_INIT(pExp->qInv); -} - #if 0 // libtpms added /* 10.2.17.4.2 MakePgreaterThanQ() */ /* This function swaps the pointers for P and Q if Q happens to be larger than Q. */ @@ -200,7 +189,7 @@ ComputePrivateExponent( BOOL qOK; BN_PRIME(pT); // - RsaInitializeExponent(pExp); + RsaInitializeExponentOld(pExp); BnCopy((bigNum)&pExp->Q, Q); // make p the larger value so that m2 is always less than p if(BnUnsignedCmp(P, Q) < 0) @@ -1007,7 +996,7 @@ CryptRsaLoadPrivateExponent( { TEST(TPM_ALG_NULL); // Make sure that the bigNum used for the exponent is properly initialized - RsaInitializeExponent(&rsaKey->privateExponent); + RsaInitializeExponentOld(&rsaKey->privateExponent); // Find the second prime by division BnDiv(bnQ, bnQr, bnN, bnP); if(!BnEqualZero(bnQr)) @@ -1322,7 +1311,7 @@ CryptRsaGenerateKey( return OpenSSLCryptRsaGenerateKey(rsaKey, e, keySizeInBits); #endif // libtpms added end // Need to initialize the privateExponent structure - RsaInitializeExponent(&rsaKey->privateExponent); + RsaInitializeExponentOld(&rsaKey->privateExponent); // The prime is computed in P. When a new prime is found, Q is checked to // see if it is zero. If so, P is copied to Q and a new P is found. diff --git a/src/tpm2/crypto/openssl/Helpers.c b/src/tpm2/crypto/openssl/Helpers.c index 71a6b503..ecf91030 100644 --- a/src/tpm2/crypto/openssl/Helpers.c +++ b/src/tpm2/crypto/openssl/Helpers.c @@ -877,7 +877,7 @@ OpenSSLCryptRsaGenerateKey( ERROR_RETURN(TPM_RC_FAILURE); // Need to initialize the privateExponent structure - RsaInitializeExponent(&rsaKey->privateExponent); + RsaInitializeExponentOld(&rsaKey->privateExponent); if ((ctx = EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL)) == NULL || EVP_PKEY_keygen_init(ctx) != 1 || @@ -943,7 +943,7 @@ OpenSSLCryptRsaGenerateKey( ERROR_RETURN(TPM_RC_FAILURE); // Need to initialize the privateExponent structure - RsaInitializeExponent(&rsaKey->privateExponent); + RsaInitializeExponentOld(&rsaKey->privateExponent); rsa = RSA_new(); if (rsa == NULL)