tpm2: Have MathLibraryCompatibilityCheck() return BOOL

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2019-11-17 19:30:04 -05:00 committed by Stefan Berger
parent 0be25cbb22
commit 6d3b2f413b
4 changed files with 32 additions and 21 deletions

View File

@ -91,6 +91,11 @@ TPM_Manufacture(
// compile options.
if(!TpmSizeChecks())
return -1;
#endif
#if LIBRARY_COMPATIBILITY_CHECK
// Make sure that the attached library performs as expected.
if(!MathLibraryCompatibilityCheck())
return -1;
#endif
// If TPM has been manufactured, return indication.
if(!firstTime && g_manufactured)

View File

@ -3,7 +3,7 @@
/* For Selected Math Library */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: SupportLibraryFunctionPrototypes_fp.h 1476 2019-06-10 19:32:03Z kgoldman $ */
/* $Id: SupportLibraryFunctionPrototypes_fp.h 1519 2019-11-15 20:43:51Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -74,7 +74,7 @@ LIB_EXPORT
int SupportLibInit(void);
/* MathLibraryCompatibililtyCheck() This function is only used during development to make sure that
the library that is being referenced is using the same size of data structures as the TPM. */
void
BOOL
MathLibraryCompatibilityCheck(
void
);

View File

@ -223,29 +223,39 @@ BnNewVariable(
}
#if LIBRARY_COMPATIBILITY_CHECK
void
BOOL
MathLibraryCompatibilityCheck(
void
)
{
OSSL_ENTER();
BIGNUM *osslTemp = BN_CTX_get(CTX);
BN_VAR(tpmTemp, 64 * 8); // allocate some space for a test value
crypt_uword_t i;
TPM2B_TYPE(TEST, 16);
TPM2B_TEST test = {{16, {0x0F, 0x0E, 0x0D, 0x0C,
0x0B, 0x0A, 0x09, 0x08,
0x07, 0x06, 0x05, 0x04,
0x03, 0x02, 0x01, 0x00}}};
// Convert the test TPM2B to a bigNum
BnFrom2B(tpmTemp, &test.b);
// Convert the test TPM2B to an OpenSSL BIGNUM
BN_bin2bn(test.t.buffer, test.t.size, osslTemp);
BIGNUM *osslTemp = BnNewVariable(CTX);
#if 0
crypt_uword_t i;
#endif
BYTE test[] = {0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18,
0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10,
0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08,
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00};
BN_VAR(tpmTemp, sizeof(test) * 8); // allocate some space for a test value
//
// Convert the test data to a bigNum
BnFromBytes(tpmTemp, test, sizeof(test));
// Convert the test data to an OpenSSL BIGNUM
BN_bin2bn(test, sizeof(test), osslTemp);
// Make sure the values are consistent
cAssert(osslTemp->top == (int)tpmTemp->size);
#if 0
VERIFY(osslTemp->top == (int)tpmTemp->size);
for(i = 0; i < tpmTemp->size; i++)
cAssert(osslTemp->d[0] == tpmTemp->d[0]);
VERIFY(osslTemp->d[i] == tpmTemp->d[i]);
#endif
OSSL_LEAVE();
return 1;
#if 0
Error:
return 0;
#endif
}
#endif

View File

@ -81,10 +81,6 @@ EcPointInitialized(
bigCurve E
);
// libtpms added end
void
MathLibraryCompatibilityCheck(
void
);
LIB_EXPORT BOOL
BnModMult(
bigNum result,