tpm2: Add support for CRYPTO_LIB_REPORTING but do not use it

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2025-07-30 09:48:10 -04:00 committed by Stefan Berger
parent 74bd4ee1d6
commit fccc05845b
7 changed files with 154 additions and 1 deletions

View File

@ -365,6 +365,7 @@ noinst_HEADERS += \
tpm2/Create_fp.h \
tpm2/CreateLoaded_fp.h \
tpm2/CreatePrimary_fp.h \
tpm2/CryptoInterface.h \
tpm2/CryptSelfTest_fp.h \
tpm2/DA_fp.h \
tpm2/DebugHelpers_fp.h \

View File

@ -79,6 +79,7 @@
#define BN_SUPPORT_INTERFACE_H
// TODO_RENAME_INC_FOLDER:private refers to the TPM_CoreLib private headers
#include "GpMacros.h"
#include "CryptoInterface.h"
#include "BnValues.h"
//** BnSupportLibInit()
@ -167,6 +168,14 @@ LIB_EXPORT BOOL BnEccAdd(
#endif // ALG_ECC
#if CRYPTO_LIB_REPORTING
//** BnGetImplementation()
// This function reports the underlying library being used for bignum operations.
void BnGetImplementation(_CRYPTO_IMPL_DESCRIPTION* result);
#endif // CRYPTO_LIB_REPORTING
// libtpms: added begin
bigCurveData*
BnCurveInitialize(

View File

@ -0,0 +1,66 @@
/********************************************************************************/
/* */
/* CryptoInterface header file */
/* Written by Stefan Berger */
/* IBM Thomas J. Watson Research Center */
/* */
/* (c) Copyright IBM Corporation 2017,2018. */
/* */
/* All rights reserved. */
/* */
/* Redistribution and use in source and binary forms, with or without */
/* modification, are permitted provided that the following conditions are */
/* met: */
/* */
/* Redistributions of source code must retain the above copyright notice, */
/* this list of conditions and the following disclaimer. */
/* */
/* Redistributions in binary form must reproduce the above copyright */
/* notice, this list of conditions and the following disclaimer in the */
/* documentation and/or other materials provided with the distribution. */
/* */
/* Neither the names of the IBM Corporation nor the names of its */
/* contributors may be used to endorse or promote products derived from */
/* this software without specific prior written permission. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */
/* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
/* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */
/* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */
/* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/********************************************************************************/
//** Introduction
//
// This file contains prototypes that are common to all TPM crypto interfaces.
//
#ifndef CRYPTO_INTERFACE_H
#define CRYPTO_INTERFACE_H
#include "TpmBuildSwitches.h"
#if SIMULATION && CRYPTO_LIB_REPORTING
typedef struct crypto_impl_description
{
// The name of the crypto library, ASCII encoded.
char name[32];
// The version of the crypto library, ASCII encoded.
char version[32];
} _CRYPTO_IMPL_DESCRIPTION;
// When building the simulator, the plugged-in crypto libraries can report its
// version information by implementing these interfaces.
void _crypto_GetSymImpl(_CRYPTO_IMPL_DESCRIPTION* result);
void _crypto_GetHashImpl(_CRYPTO_IMPL_DESCRIPTION* result);
void _crypto_GetMathImpl(_CRYPTO_IMPL_DESCRIPTION* result);
#endif // SIMULATION && CRYPTO_LIB_REPORTING
#endif // CRYPTO_INTERFACE_H

View File

@ -110,6 +110,10 @@
// ones in the Simulator project.
#define SIMULATION NO // libtpms: changed to NO
// The CRYPTO_LIB_REPORTING switch allows the TPM to report its
// crypto library implementation, e.g., at simulation startup.
#define CRYPTO_LIB_REPORTING NO // libtpms: NO
// If doing debug, can set the DRBG to print out the intermediate test values.
// Before enabling this, make sure that the dbgDumpMemBlock() function
// has been added someplace (preferably, somewhere in CryptRand.c)

View File

@ -73,4 +73,14 @@
#include "BnMemory_fp.h"
#include "BnMath_fp.h"
#include "BnConvert_fp.h"
#endif
#if CRYPTO_LIB_REPORTING
# include <CryptoInterface.h>
//*** OsslGetVersion()
// Report the current version of OpenSSL.
void OsslGetVersion(_CRYPTO_IMPL_DESCRIPTION* result);
#endif // CRYPTO_LIB_REPORTING
#endif // _BNOSSL_H_

View File

@ -680,4 +680,15 @@ LIB_EXPORT BOOL BnEccAdd(bigPoint R, // OUT: computed point
# endif // ALG_ECC
# if CRYPTO_LIB_REPORTING
//** BnGetImplementation()
// This function reports the underlying library being used for bignum operations.
void BnGetImplementation(_CRYPTO_IMPL_DESCRIPTION* result)
{
OsslGetVersion(result);
}
# endif // CRYPTO_LIB_REPORTING
#endif // MATHLIB OSSL

View File

@ -66,6 +66,34 @@
//** Defines and Includes
#include "BnOssl.h"
#include "CryptoInterface.h"
#include "TpmToOsslSym.h"
#include "TpmToOsslHash.h"
#include <openssl/opensslv.h>
#include <stdio.h>
#if CRYPTO_LIB_REPORTING
//*** OsslGetVersion()
// Report the version of OpenSSL.
void OsslGetVersion(_CRYPTO_IMPL_DESCRIPTION* result)
{
snprintf(result->name, sizeof(result->name), "OpenSSL");
# if defined(OPENSSL_VERSION_STR)
snprintf(result->version, sizeof(result->version), "%s", OPENSSL_VERSION_STR);
# else
// decode the hex version string according to the rules described in opensslv.h
snprintf(result->version,
sizeof(result->version),
"%d.%d.%d%c",
(unsigned char)((OPENSSL_VERSION_NUMBER >> 28) & 0x0f),
(unsigned char)((OPENSSL_VERSION_NUMBER >> 20) & 0xff),
(unsigned char)((OPENSSL_VERSION_NUMBER >> 12) & 0xff),
(char)((OPENSSL_VERSION_NUMBER >> 4) & 0xff) - 1 + 'a');
# endif //OPENSSL_VERSION_STR
}
#endif //CRYPTO_LIB_REPORTING
#if defined(HASH_LIB_OSSL) || defined(MATH_LIB_OSSL) || defined(SYM_LIB_OSSL)
// Used to pass the pointers to the correct sub-keys
@ -117,4 +145,28 @@ void OsslPopContext(BN_CTX* CTX)
BN_CTX_end(CTX);
}
# if CRYPTO_LIB_REPORTING
# if defined(SYM_LIB_OSSL) && SIMULATION && CRYPTO_LIB_REPORTING
//*** _crypto_GetSymImpl()
// Report the version of OpenSSL being used for symmetric crypto.
void _crypto_GetSymImpl(_CRYPTO_IMPL_DESCRIPTION* result)
{
OsslGetVersion(result);
}
# else
# error huh?
# endif // defined(SYM_LIB_OSSL) && SIMULATION
# if defined(HASH_LIB_OSSL) && SIMULATION && CRYPTO_LIB_REPORTING
//*** _crypto_GetHashImpl()
// Report the version of OpenSSL being used for hashing.
void _crypto_GetHashImpl(_CRYPTO_IMPL_DESCRIPTION* result)
{
OsslGetVersion(result);
}
# endif // defined(HASH_LIB_OSSL) && SIMULATION
# endif // CRYPTO_LIB_REPORTING
#endif // HASH_LIB_OSSL || MATH_LIB_OSSL || SYM_LIB_OSSL