tpm2: Move code out of RsaAdjustPrimeCandidate

To simplify the code and get rid of the libtpms-specific implementation
of RsaAdjustPrimeCandidate move its code into the case statements in
TpmRsa_GeneratePrimeForRSA.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2024-01-03 14:43:20 -05:00 committed by Stefan Berger
parent aa582228d6
commit 09a67f4588
2 changed files with 6 additions and 30 deletions

View File

@ -124,12 +124,6 @@ TpmRsa_GeneratePrimeForRSA(
RAND_STATE* rand // IN: the random state
);
// libtpms: added begin
void RsaAdjustPrimeCandidate(Crypt_Int* prime,
SEED_COMPAT_LEVEL seedCompatLevel // IN: compatibility level
);
// libtpms: added end
#endif // ALG_RSA
#endif // _CRYPT_PRIME_FP_H_

View File

@ -392,25 +392,6 @@ RsaAdjustPrimeCandidate_New(
// issues.
//
LIB_EXPORT void RsaAdjustPrimeCandidate(Crypt_Int* prime,
SEED_COMPAT_LEVEL seedCompatLevel // IN: compatibility level; libtpms added
)
{
switch (seedCompatLevel) {
case SEED_COMPAT_LEVEL_ORIGINAL:
RsaAdjustPrimeCandidate_PreRev155(prime);
break;
case SEED_COMPAT_LEVEL_LAST:
/* case SEED_COMPAT_LEVEL_RSA_PRIME_ADJUST_FIX: */
RsaAdjustPrimeCandidate_New(prime);
break;
default:
FAIL(FATAL_ERROR_INTERNAL);
}
}
//***TpmRsa_GeneratePrimeForRSA()
// Function to generate a prime of the desired size with the proper attributes
// for an RSA prime.
@ -444,16 +425,17 @@ TPM_RC TpmRsa_GeneratePrimeForRSA(
DRBG_Generate(rand, (BYTE *)prime->d, (UINT16)BITS_TO_BYTES(bits));
if (g_inFailureMode)
return TPM_RC_FAILURE;
RsaAdjustPrimeCandidate_PreRev155(prime);
break;
case SEED_COMPAT_LEVEL_LAST:
/* case SEED_COMPAT_LEVEL_RSA_PRIME_ADJUST_FIX: */
/* case SEED_COMPAT_LEVEL_RSA_PRIME_ADJUST_FIX: */
if(!TpmMath_GetRandomInteger(prime, bits, rand)) // new
return TPM_RC_FAILURE;
break;
default:
FAIL(FATAL_ERROR_INTERNAL);
RsaAdjustPrimeCandidate_New(prime);
break;
default:
FAIL(FATAL_ERROR_INTERNAL);
}
RsaAdjustPrimeCandidate(prime, DRBG_GetSeedCompatLevel(rand));
// libtpms changed end
found = RsaCheckPrime(prime, exponent, rand) == TPM_RC_SUCCESS;
}