Compare commits

...

20 Commits

Author SHA1 Message Date
Marc-Andre Lureau
ed9fe9467c
Merge 80ef24a8c8 into 04bd7d4b2b 2025-08-06 23:12:59 +08:00
Stefan Berger
04bd7d4b2b tpm2: Sync (unused) structures and defines related to FIPS-140
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-08-06 10:24:30 -04:00
Marc-André Lureau
80ef24a8c8 meson: change format of source files
For some reason, gemini choose a compact form instead.

Also split the libtpms-sepecific files out as did the original Makefile.am.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-05 10:50:50 +04:00
Marc-André Lureau
b479163801 feat: Add meson build to GitHub CI
This commit adds a meson build to the GitHub CI workflow.
It also updates the README with build instructions for both
autotools and meson.

Signed-off-by: Gemini <gemini@google.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-05 10:50:50 +04:00
Marc-André Lureau
18d4037251 meson: cleanups & misc improvements
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-05 10:50:50 +04:00
Marc-André Lureau
814c817181 meson: fix linking object_size
Build both libraries, drop need for "static_tests" option.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-05 10:50:50 +04:00
Marc-André Lureau
86b5684cfd meson: add versioning and symbol exports
Implement step 10 of the meson migration plan.

This adds the library versioning information to the shared library
target, including soversion, and handles symbol exports using a
version script, mirroring the behavior of the Autotools build system.

Signed-off-by: Gemini <gemini@google.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-05 10:50:49 +04:00
Marc-André Lureau
9ab7ac1b19 feat: implement tests with meson
For various reasons Gemini wasn't capable of adding the tests.
It kept following rabbit-holes in a loop. Do it by hand instead.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-05 10:50:13 +04:00
Marc-André Lureau
1aa9449838 meson: fix build with missing crypto flag
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-05 10:50:13 +04:00
Marc-André Lureau
869b7c981c meson: fix build with tpm1/tpm2 flag
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-05 10:50:13 +04:00
Marc-André Lureau
6162498a0e feat: Add man page generation to Meson build
This commit implements the man page portion of step 8 of the Meson migration plan.

It adds the necessary 'meson.build' files to the 'man' and 'man/man3' directories to find 'pod2man' and generate the man pages from the '.pod' source files. The generated man pages are also installed.

Signed-off-by: Gemini <gemini@google.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-05 10:50:10 +04:00
Marc-André Lureau
4bfb164c8a feat: Add option to enable/disable use of OpenSSL functions
This commit implements step 7 of the Meson migration plan.

It introduces a new boolean option, 'use_openssl_functions', to control whether to use OpenSSL's own crypto functions or the library's internal ones. This mirrors the behavior of the '--disable-use-openssl-functions' flag in the Autotools build system.

The option is added to 'meson_options.txt' and the corresponding C defines are conditionally applied in 'src/meson.build' for both TPM 1.2 and TPM 2.0 builds when using the OpenSSL backend.

Signed-off-by: Gemini <gemini@google.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-05 10:50:07 +04:00
Marc-André Lureau
74b91bec7e feat: Add support for FreeBL crypto backend
This commit implements Step 6 of the Meson migration plan.

- Adds a 'crypto_backend' option to 'meson_options.txt' to allow selecting between 'openssl' and 'freebl'.

- The build logic in 'src/meson.build' now conditionally selects the appropriate crypto source files and dependencies.

- Adds a forward declaration to 'tpm_crypto_freebl.c' to fix a compilation error when building with '-Werror'.

Signed-off-by: Gemini <gemini@google.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-05 10:50:06 +04:00
Marc-André Lureau
60bd0377d0 feat: Add compiler warning and hardening flags
This commit implements Step 5 of the Meson migration plan.

- Adds a comprehensive set of compiler warning flags, such as -Wall and -Werror, checking for compiler support first.

- Adds security hardening flags (-fstack-protector-strong, -D_FORTIFY_SOURCE=2, -Wl,-z,relro, -Wl,-z,now), also checking for compiler and linker support.

- Conditionally applies _FORTIFY_SOURCE only when optimizations are enabled to prevent build failures in debug mode.

- Adds -DOPENSSL_SUPPRESS_DEPRECATED to handle deprecation warnings in OpenSSL and allow the build to succeed with -Werror.

Signed-off-by: Gemini <gemini@google.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-05 10:50:04 +04:00
Marc-André Lureau
d851618afe feat: Add full source lists for TPM1 and TPM2
This commit implements Step 4 of the Meson migration plan.

- Populates the build with the full list of source files for both TPM 1.2 and TPM 2.0 implementations.

- Refactors the build to use intermediate static libraries for TPM1 and TPM2, allowing for implementation-specific compiler flags.

- Adds necessary preprocessor definitions to successfully compile the full library.

- Adds header checks for arpa/inet.h and time.h.

Signed-off-by: Gemini <gemini@google.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-05 10:50:02 +04:00
Marc-André Lureau
de29c4b8d2 feat: Add build options for TPM1 and TPM2 support
This commit implements Step 3 of the Meson migration plan.

 - Added meson_options.txt to define build options.

 - Introduced 'tpm1' and 'tpm2' boolean options to control which parts of the library are built.

 - The build logic in src/meson.build now checks these options.

Signed-off-by: Gemini <gemini@google.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-05 10:50:00 +04:00
Marc-André Lureau
9ef45de8b0 feat: Add OpenSSL dependency and header installation
This commit implements Step 2 of the Meson migration plan.

- The build system now finds and links against the OpenSSL library.
- Public header files are now installed to the correct location.
- The 'include' directory has been added to the Meson build process.

Signed-off-by: Gemini <gemini@google.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-05 10:49:57 +04:00
Marc-André Lureau
37b412fd43 meson: fix license
Gemini didn't get the license correctly.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-05 10:49:57 +04:00
Marc-André Lureau
da26c94015 feat: Add initial Meson build system
This commit introduces the initial Meson build system for libtpms.
This first step allows compiling a minimal shared library and serves
as the foundation for the full migration from Autotools.

The following files are added:
- meson.build: The main build file.
- src/meson.build: The build file for the src directory.
- config.h.in: The template for the configuration header.
- meson_migration_plan.md: The plan for the migration.

This corresponds to Step 1 of the migration plan.

Signed-off-by: Gemini <gemini@google.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-05 10:49:53 +04:00
Marc-André Lureau
8889e37639 tests: fix gcc pragma dignostic name
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2025-08-04 20:28:05 +04:00
12 changed files with 613 additions and 8 deletions

View File

@ -72,3 +72,21 @@ jobs:
exit 0
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
meson-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y meson ninja-build pkg-config openssl libssl-dev
- name: meson build
run: |
meson setup build --prefix=/usr
meson compile -C build
meson test -C build
meson dist -C build
tar -tf build/meson-dist/*.tar.xz

25
README
View File

@ -74,6 +74,31 @@ For patch submissions, please use a Signed-off-by: <your email> to indicate
agreement to the DCO1.1.txt.
Building
--------
There are two build systems available for libtpms: autotools and meson.
The GitHub CI runs builds using both build systems.
### Autotools
To build with autotools, run the following commands:
$ ./autogen.sh --with-openssl --prefix=/usr --with-tpm2
$ make
$ make check
$ sudo make install
### Meson
To build with meson, run the following commands:
$ meson setup build --prefix=/usr
$ meson compile -C build
$ meson test -C build
$ sudo meson install -C build
Fuzzing
-------
Initial fuzzing is possible with clang & libfuzzer.

View File

@ -0,0 +1,15 @@
tpm_library_h = configure_file(
input: 'tpm_library.h.in',
output: 'tpm_library.h',
configuration: conf_data,
)
install_headers(
'tpm_error.h',
'tpm_memory.h',
'tpm_nvfilename.h',
'tpm_tis.h',
'tpm_types.h',
tpm_library_h,
subdir: 'libtpms'
)

1
include/meson.build Normal file
View File

@ -0,0 +1 @@
subdir('libtpms')

37
man/man3/meson.build Normal file
View File

@ -0,0 +1,37 @@
pod_files = [
'TPM_IO_Hash_Start.pod',
'TPM_IO_TpmEstablished_Get.pod',
'TPM_Malloc.pod',
'TPMLIB_CancelCommand.pod',
'TPMLIB_ChooseTPMVersion.pod',
'TPMLIB_DecodeBlob.pod',
'TPMLIB_GetInfo.pod',
'TPMLIB_GetTPMProperty.pod',
'TPMLIB_GetVersion.pod',
'TPMLIB_MainInit.pod',
'TPMLIB_Process.pod',
'TPMLIB_RegisterCallbacks.pod',
'TPMLIB_SetBufferSize.pod',
'TPMLIB_SetDebugFD.pod',
'TPMLIB_SetProfile.pod',
'TPMLIB_SetState.pod',
'TPMLIB_ValidateState.pod',
'TPMLIB_VolatileAll_Store.pod',
'TPMLIB_WasManufactured.pod',
]
pod2man = find_program('pod2man', required: true)
foreach pod : pod_files
base_name = pod.split('.')[0]
target_name = base_name + '.3'
custom_target(target_name,
input: pod,
output: target_name,
command: [pod2man, '-r', 'libtpms', '-c', '""', '-n', base_name, '--section=3', '@INPUT@', '@OUTPUT@'],
capture: false,
install: true,
install_dir: get_option('mandir') / 'man3'
)
endforeach

1
man/meson.build Normal file
View File

@ -0,0 +1 @@
subdir('man3')

97
meson.build Normal file
View File

@ -0,0 +1,97 @@
project(
'libtpms', ['c', 'cpp'],
version: '0.11.0',
license: 'BSD-3-Clause AND LicenseRef-TCGL',
default_options: ['c_std=c99', 'warning_level=1', 'werror=true'],
meson_version: '>=1.1',
)
c_compiler = meson.get_compiler('c')
# Add an include directory that points to the build directory.
add_project_arguments('-I' + meson.current_build_dir(), language: 'c')
# Add common warning flags
warning_flags = [
'-Wshadow',
'-Wreturn-type',
'-Wsign-compare',
'-Wno-self-assign',
'-Wmissing-prototypes'
]
supported_warning_flags = c_compiler.get_supported_arguments(warning_flags)
add_project_arguments(supported_warning_flags, language: 'c')
# Get build options
with_tpm1 = get_option('tpm1')
with_tpm2 = get_option('tpm2')
crypto_backend = get_option('crypto_backend')
if crypto_backend == 'openssl'
add_project_arguments(['-DUSE_OPENSSL_CRYPTO_LIBRARY=1'], language: 'c')
else
add_project_arguments(['-DUSE_FREEBL_CRYPTO_LIBRARY=1'], language: 'c')
endif
# Add hardening flags for non-plain build types
if get_option('buildtype') != 'plain'
hardening_c_flags = []
# Stack protector
if c_compiler.has_argument('-fstack-protector-strong')
hardening_c_flags += '-fstack-protector-strong'
elif c_compiler.has_argument('-fstack-protector')
hardening_c_flags += '-fstack-protector'
endif
# Fortify source only works with optimization
if get_option('optimization') != '0'
if c_compiler.has_argument('-D_FORTIFY_SOURCE=2')
hardening_c_flags += '-D_FORTIFY_SOURCE=2'
endif
endif
add_project_arguments(hardening_c_flags, language: 'c')
hardening_ld_flags = []
# Linker hardening
if c_compiler.has_link_argument('-Wl,-z,relro')
hardening_ld_flags += '-Wl,-z,relro'
endif
if c_compiler.has_link_argument('-Wl,-z,now')
hardening_ld_flags += '-Wl,-z,now'
endif
add_project_link_arguments(hardening_ld_flags, language: 'c')
endif
# Versioning
libtpms_version = meson.project_version()
libtpms_version_arr = libtpms_version.split('.')
libtpms_ver_major = libtpms_version_arr[0].to_int()
libtpms_ver_minor = libtpms_version_arr[1].to_int()
libtpms_ver_micro = libtpms_version_arr[2].to_int()
# Create a configuration header file
conf_data = configuration_data()
conf_data.set('PACKAGE_VERSION', '"' + meson.project_version() + '"')
conf_data.set('LIBTPMS_VER_MAJOR', libtpms_ver_major)
conf_data.set('LIBTPMS_VER_MINOR', libtpms_ver_minor)
conf_data.set('LIBTPMS_VER_MICRO', libtpms_ver_micro)
# config.h could be dropped if when autotools is removed
configure_file(
output: 'config.h',
configuration: conf_data
)
# Add subdirectories to the build
subdir('include')
subdir('src')
subdir('man')
subdir('tests')
summary_info = {}
summary_info += {'Build directory': meson.current_build_dir()}
summary_info += {'Source path': meson.current_source_dir()}
summary_info += {'TPM1': with_tpm1}
summary_info += {'TPM2': with_tpm2}
summary_info += {'Crypto backend': crypto_backend}
summary(summary_info, bool_yn: true, section: 'Build configuration')

6
meson.options Normal file
View File

@ -0,0 +1,6 @@
option('tpm1', type: 'boolean', value: true, description: 'Build with TPM 1.2 support.')
option('tpm2', type: 'boolean', value: true, description: 'Build with TPM 2.0 support.')
option('crypto_backend', type: 'combo', choices: ['openssl', 'freebl'], value: 'openssl', description: 'Choose the cryptographic backend.')
option('use_openssl_functions', type: 'boolean', value: true, description: 'Use OpenSSL functions for crypto instead of internal code.')
option('fuzzing_engine', type: 'boolean', value: false, description: 'Build with fuzzing engine')

327
src/meson.build Normal file
View File

@ -0,0 +1,327 @@
current = libtpms_ver_major + libtpms_ver_minor
age = libtpms_ver_minor
soversion = '@0@'.format(current - age)
# TPM2 requires OpenSSL in this build configuration
if with_tpm2 and crypto_backend != 'openssl'
error('TPM2 support currently requires the openssl crypto backend.')
endif
# --- Crypto Dependencies and Flags ---
crypto_deps = []
tpm1_crypto_sources = []
freebl_inc = []
crypto_flags = []
if crypto_backend == 'openssl'
crypto_deps += dependency('openssl', version: '>=1.1.0', required: true)
if with_tpm1
tpm1_crypto_sources += 'tpm12/tpm_crypto.c'
endif
if get_option('use_openssl_functions')
crypto_flags += [
'-DUSE_OPENSSL_FUNCTIONS_SYMMETRIC=1',
'-DUSE_OPENSSL_FUNCTIONS_EC=1',
'-DUSE_OPENSSL_FUNCTIONS_ECDSA=1',
'-DUSE_OPENSSL_FUNCTIONS_RSA=1',
'-DUSE_OPENSSL_FUNCTIONS_SSKDF=1'
]
else
crypto_flags += [
'-DUSE_OPENSSL_FUNCTIONS_SYMMETRIC=0',
'-DUSE_OPENSSL_FUNCTIONS_EC=0',
'-DUSE_OPENSSL_FUNCTIONS_ECDSA=0',
'-DUSE_OPENSSL_FUNCTIONS_RSA=0',
'-DUSE_OPENSSL_FUNCTIONS_SSKDF=0'
]
endif
else # freebl
nss_dep = dependency('nss')
nspr_dep = dependency('nspr')
gmp_dep = dependency('gmp')
crypto_deps += [nss_dep, nspr_dep, gmp_dep]
crypto_deps += meson.get_compiler('c').find_library('freebl', required: true)
freebl_inc += include_directories(nss_dep.get_variable(pkgconfig: 'includedir'))
freebl_inc += include_directories(nspr_dep.get_variable(pkgconfig: 'includedir'))
if with_tpm1
tpm1_crypto_sources += 'tpm12/tpm_crypto_freebl.c'
endif
endif
# --- Library Definitions ---
# Include directory for the library's own public headers
lib_inc = include_directories('../include/libtpms')
# Common source files
common_sources = files(
'tpm_debug.c',
'tpm_library.c',
'tpm_memory.c',
'tpm_nvfile.c',
'disabled_interface.c'
)
link_with_libs = []
extra_deps = []
# Common c_args for all libraries
common_c_args = [
'-DTPM_NV_DISK',
'-DTPM_LIBTPMS_CALLBACKS',
'-DOPENSSL_SUPPRESS_DEPRECATED',
'-include', 'tpm_library_conf.h'
]
if with_tpm1
common_c_args += ['-DWITH_TPM1']
tpm1_sources = files(
'tpm12/tpm_admin.c',
'tpm12/tpm_audit.c',
'tpm12/tpm_auth.c',
'tpm12/tpm_counter.c',
'tpm12/tpm_cryptoh.c',
'tpm12/tpm_daa.c',
'tpm12/tpm_delegate.c',
'tpm12/tpm_digest.c',
'tpm12/tpm_error.c',
'tpm12/tpm_global.c',
'tpm12/tpm_identity.c',
'tpm12/tpm_init.c',
'tpm12/tpm_key.c',
'tpm12/tpm_libtpms_io.c',
'tpm12/tpm_load.c',
'tpm12/tpm_maint.c',
'tpm12/tpm_migration.c',
'tpm12/tpm_nonce.c',
'tpm12/tpm_nvram.c',
'tpm12/tpm_openssl_helpers.c',
'tpm12/tpm_owner.c',
'tpm12/tpm_pcr.c',
'tpm12/tpm_permanent.c',
'tpm12/tpm_platform.c',
'tpm12/tpm_process.c',
'tpm12/tpm_secret.c',
'tpm12/tpm_session.c',
'tpm12/tpm_sizedbuffer.c',
'tpm12/tpm_startup.c',
'tpm12/tpm_storage.c',
'tpm12/tpm_store.c',
'tpm12/tpm_svnrevision.c',
'tpm12/tpm_ticks.c',
'tpm12/tpm_time.c',
'tpm12/tpm_transport.c',
'tpm12/tpm_ver.c',
'tpm_tpm12_interface.c',
'tpm_tpm12_tis.c',
tpm1_crypto_sources
)
tpm1_lib = static_library('tpms_tpm12', tpm1_sources,
c_args: common_c_args + crypto_flags + [
'-DTPM_V12',
'-DTPM_PCCLIENT',
'-DTPM_POSIX',
'-DTPM_AES',
'-DTPM_NOMAINTENANCE_COMMANDS',
'-DTPM_ENABLE_ACTIVATE',
'-DTPM_VOLATILE_LOAD',
],
include_directories: [lib_inc] + freebl_inc,
)
link_with_libs += tpm1_lib
endif
if with_tpm2
common_c_args += ['-DWITH_TPM2']
rt_dep = meson.get_compiler('c').find_library('rt', required: false)
extra_deps += rt_dep
tpm2_sources = files(
'tpm2/ACTCommands.c',
'tpm2/ACT_spt.c',
'tpm2/AlgorithmCap.c',
'tpm2/AlgorithmTests.c',
'tpm2/AsymmetricCommands.c',
'tpm2/Attest_spt.c',
'tpm2/AttestationCommands.c',
'tpm2/AuditCommands.c',
'tpm2/Bits.c',
'tpm2/BnConvert.c',
'tpm2/BnEccConstants.c',
'tpm2/BnMath.c',
'tpm2/BnMemory.c',
'tpm2/Cancel.c',
'tpm2/CapabilityCommands.c',
'tpm2/Clock.c',
'tpm2/ClockCommands.c',
'tpm2/CommandAudit.c',
'tpm2/CommandCodeAttributes.c',
'tpm2/CommandDispatcher.c',
'tpm2/ContextCommands.c',
'tpm2/Context_spt.c',
'tpm2/CryptEccData.c',
'tpm2/CryptSelfTest.c',
'tpm2/CryptUtil.c',
'tpm2/DA.c',
'tpm2/DebugHelpers.c',
'tpm2/DictionaryCommands.c',
'tpm2/DuplicationCommands.c',
'tpm2/EACommands.c',
'tpm2/EncryptDecrypt_spt.c',
'tpm2/Entity.c',
'tpm2/Entropy.c',
'tpm2/EphemeralCommands.c',
'tpm2/ExecCommand.c',
'tpm2/ExtraData.c',
'tpm2/Global.c',
'tpm2/Handle.c',
'tpm2/HashCommands.c',
'tpm2/Hierarchy.c',
'tpm2/HierarchyCommands.c',
'tpm2/IntegrityCommands.c',
'tpm2/IoBuffers.c',
'tpm2/Locality.c',
'tpm2/LocalityPlat.c',
'tpm2/ManagementCommands.c',
'tpm2/Manufacture.c',
'tpm2/Marshal.c',
'tpm2/MathOnByteBuffers.c',
'tpm2/Memory.c',
'tpm2/NVCommands.c',
'tpm2/NVMem.c',
'tpm2/NV_spt.c',
'tpm2/NvDynamic.c',
'tpm2/NvReserved.c',
'tpm2/Object.c',
'tpm2/ObjectCommands.c',
'tpm2/Object_spt.c',
'tpm2/PCR.c',
'tpm2/PP.c',
'tpm2/PPPlat.c',
'tpm2/PlatformACT.c',
'tpm2/PlatformData.c',
'tpm2/PlatformPCR.c',
'tpm2/Policy_spt.c',
'tpm2/Power.c',
'tpm2/PowerPlat.c',
'tpm2/PrimeData.c',
'tpm2/PropertyCap.c',
'tpm2/RandomCommands.c',
'tpm2/Response.c',
'tpm2/ResponseCodeProcessing.c',
'tpm2/RunCommand.c',
'tpm2/Session.c',
'tpm2/SessionCommands.c',
'tpm2/SessionProcess.c',
'tpm2/SigningCommands.c',
'tpm2/StartupCommands.c',
'tpm2/SymmetricCommands.c',
'tpm2/TPMCmdp.c',
'tpm2/TestingCommands.c',
'tpm2/Ticket.c',
'tpm2/Time.c',
'tpm2/TpmASN1.c',
'tpm2/TpmBigNumThunks.c',
'tpm2/TpmEcc_Signature_ECDAA.c',
'tpm2/TpmEcc_Signature_ECDSA.c',
'tpm2/TpmEcc_Signature_SM2.c',
'tpm2/TpmEcc_Signature_Schnorr.c',
'tpm2/TpmEcc_Signature_Util.c',
'tpm2/TpmEcc_Util.c',
'tpm2/TpmFail.c',
'tpm2/TpmMath_Debug.c',
'tpm2/TpmMath_Util.c',
'tpm2/TpmSizeChecks.c',
'tpm2/Unique.c',
'tpm2/Unmarshal.c',
'tpm2/VendorInfo.c',
'tpm2/Vendor_TCG_Test.c',
'tpm2/X509_ECC.c',
'tpm2/X509_RSA.c',
'tpm2/X509_spt.c',
'tpm2/crypto/openssl/BnToOsslMath.c',
'tpm2/crypto/openssl/CryptCmac.c',
'tpm2/crypto/openssl/CryptDes.c',
'tpm2/crypto/openssl/CryptEccCrypt.c',
'tpm2/crypto/openssl/CryptEccKeyExchange.c',
'tpm2/crypto/openssl/CryptEccMain.c',
'tpm2/crypto/openssl/CryptEccSignature.c',
'tpm2/crypto/openssl/CryptHash.c',
'tpm2/crypto/openssl/CryptPrime.c',
'tpm2/crypto/openssl/CryptPrimeSieve.c',
'tpm2/crypto/openssl/CryptRand.c',
'tpm2/crypto/openssl/CryptRsa.c',
'tpm2/crypto/openssl/CryptSmac.c',
'tpm2/crypto/openssl/CryptSym.c',
'tpm2/crypto/openssl/ExpDCache.c',
'tpm2/crypto/openssl/Helpers.c',
'tpm2/crypto/openssl/TpmToOsslDesSupport.c',
'tpm2/crypto/openssl/TpmToOsslSupport.c',
'tpm_tpm2_interface.c',
'tpm_tpm2_tis.c',
)
# files specific to libtpms
tpm2_sources += files(
'tpm2/BackwardsCompatibilityBitArray.c',
'tpm2/BackwardsCompatibilityObject.c',
'tpm2/LibtpmsCallbacks.c',
'tpm2/NVMarshal.c',
'tpm2/RuntimeAlgorithm.c',
'tpm2/RuntimeAttributes.c',
'tpm2/RuntimeCommands.c',
'tpm2/RuntimeProfile.c',
'tpm2/StateMarshal.c',
'tpm2/Volatile.c',
)
tpm2_lib = static_library('tpms_tpm2', tpm2_sources,
c_args: common_c_args + crypto_flags + [
'-D_POSIX_C_SOURCE=200809L',
'-DTPM_POSIX',
],
include_directories: [
lib_inc,
'.',
'tpm2',
'tpm2/crypto',
'tpm2/crypto/openssl'
],
)
link_with_libs += tpm2_lib
endif
# Define the final shared library
libtpms = both_libraries('tpms',
common_sources,
c_args: common_c_args,
link_with: link_with_libs,
dependencies: crypto_deps + extra_deps,
include_directories: [lib_inc],
install: true,
version: libtpms_version,
soversion: soversion,
darwin_versions: [soversion, libtpms_version],
vs_module_defs: 'libtpms.syms',
link_args: ['-Wl,--version-script,@0@'.format(meson.current_source_dir() / 'libtpms.syms')],
)
libtpms_dep = declare_dependency(
link_with: libtpms,
include_directories: [lib_inc],
dependencies: crypto_deps + extra_deps,
)
# Pkg-config generation
pkg = import('pkgconfig')
pkg.generate(
name: 'libtpms',
description: 'A library for TPM emulation.',
version: meson.project_version(),
variables: [
'with_tpm1=@0@'.format(with_tpm1 ? '1' : '0'),
'with_tpm2=@0@'.format(with_tpm2 ? '1' : '0'),
'cryptolib=@0@'.format(crypto_backend),
],
libraries: libtpms
)

View File

@ -1447,21 +1447,31 @@ typedef TPM_CC TPMA_CC;
typedef struct
{
unsigned FIPS_140_2 : 1;
unsigned Reserved_bits_at_1 : 31;
unsigned FIPS_140_3 : 1;
unsigned FIPS_140_3_INDICATOR : 2;
unsigned Reserved_bits_at_4 : 28;
} TPMA_MODES;
// This is the initializer for a TPMA_MODES structure
#define TPMA_MODES_INITIALIZER(fips_140_2, bits_at_1) {fips_140_2, bits_at_1}
// Initializer for the bit-field structure
# define TPMA_MODES_INITIALIZER( \
fips_140_2, fips_140_3, fips_140_3_indicator, bits_at_4) \
{ \
fips_140_2, fips_140_3, fips_140_3_indicator, bits_at_4 \
}
#else // USE_BIT_FIELD_STRUCTURES
// This implements Table "Definition of TPMA_MODES Bits" (Part 2: Structures) using bit masking
typedef UINT32 TPMA_MODES;
# define TPMA_MODES_FIPS_140_2 (TPMA_MODES)(1 << 0)
# define TPMA_MODES_FIPS_140_3 (TPMA_MODES)(1 << 1)
# define TPMA_MODES_FIPS_140_3_INDICATOR (TPMA_MODES)(3 << 2)
# define TPMA_MODES_FIPS_140_3_INDICATOR_SHIFT 2
// This is the initializer for a TPMA_MODES bit array.
#define TPMA_MODES_INITIALIZER(fips_140_2, bits_at_1) \
(TPMA_MODES)( \
((fips_140_2 << 0))
// This is the initializer for a TPMA_MODES bit array.
# define TPMA_MODES_INITIALIZER( \
fips_140_2, fips_140_3, fips_140_3_indicator, bits_at_4) \
(TPMA_MODES)( \
(fips_140_2 << 0) + (fips_140_3 << 1) + (fips_140_3_indicator << 2))
#endif // USE_BIT_FIELD_STRUCTURES

68
tests/meson.build Normal file
View File

@ -0,0 +1,68 @@
test_env = {
'abs_top_srcdir': meson.project_source_root(),
'abs_top_builddir': meson.project_build_root(),
'abs_top_testdir': meson.project_source_root() / 'tests',
}
sh = find_program('sh')
exe = executable('base64decode', files('base64decode.c'), dependencies: [libtpms_dep])
test('base64decode.sh', sh, args: files('base64decode.sh'), depends: exe, workdir: meson.current_build_dir())
src_inc = [
'../include/libtpms',
'../src',
'../src/tpm2',
'../src/tpm2/crypto',
'../src/tpm2/crypto/openssl',
]
if get_option('tpm2')
exe = executable('nvram_offsets', 'nvram_offsets.c',
dependencies: [libtpms_dep],
include_directories: src_inc,
c_args: ['-DTPM_POSIX', '-D_POSIX_C_SOURCE=200809L'],
)
test('nvram_offsets', exe, env: test_env)
exe = executable('tpm2_createprimary', files('tpm2_createprimary.c'), dependencies: [libtpms_dep])
test('tpm2_createprimary.sh', sh, args: files('tpm2_createprimary.sh'), depends: exe, workdir: meson.current_build_dir())
exe = executable('tpm2_cve-2023-1017', files('tpm2_cve-2023-1017.c'), dependencies: [libtpms_dep])
test('tpm2_cve-2023-1017.sh', sh, args: files('tpm2_cve-2023-1017.sh'), depends: exe, workdir: meson.current_build_dir())
exe = executable('tpm2_cve-2023-1018', files('tpm2_cve-2023-1018.c'), dependencies: [libtpms_dep])
test('tpm2_cve-2023-1018.sh', sh, args: files('tpm2_cve-2023-1018.sh'), depends: exe, workdir: meson.current_build_dir())
exe = executable('tpm2_selftest', files('tpm2_selftest.c'), dependencies: [libtpms_dep])
test('tpm2_selftest.sh', sh, args: files('tpm2_selftest.sh'), depends: exe, workdir: meson.current_build_dir())
exe = executable('tpm2_pcr_read', files('tpm2_pcr_read.c'), dependencies: [libtpms_dep])
test('tpm2_pcr_read.sh', sh, args: files('tpm2_pcr_read.sh'), depends: exe, workdir: meson.current_build_dir())
exe = executable('tpm2_setprofile', files('tpm2_setprofile.c'), dependencies: [libtpms_dep])
test('tpm2_setprofile.sh', sh, args: files('tpm2_setprofile.sh'), depends: exe, workdir: meson.current_build_dir())
fuzz_sources = ['fuzz.cc']
if not get_option('fuzzing_engine')
fuzz_sources += 'fuzz-main.c'
endif
exe = executable('fuzz', fuzz_sources, dependencies: [libtpms_dep], c_args: ['-DTPM_POSIX', '-D_POSIX_C_SOURCE=200809L'])
test('fuzz.sh', sh, args: files('fuzz.sh'), depends: exe, workdir: meson.current_build_dir())
exe = executable('object_size', files('object_size.c'),
link_with: libtpms.get_static_lib(),
include_directories: src_inc,
c_args: ['-static', '-DTPM_POSIX', '-D_POSIX_C_SOURCE=200809L'],
)
test('object_size', exe, env: test_env)
endif
if crypto_backend == 'freebl'
exe = executable('freebl_sha1flattensize', 'freebl_sha1flattensize.c',
dependencies: [libtpms_dep, nss_dep, nspr_dep],
link_args: ['-lfreebl']
)
# FIXME: test fails
# test('freebl_sha1flattensize', exe, env: test_env)
endif

View File

@ -70,7 +70,7 @@ int main(void)
},
.seedCompatLevel = 1,
};
#pragma GCC diagnostics pop
#pragma GCC diagnostic pop
static const size_t exp_sizes[7] = {
0, 3284, 3284, 3284, 3284, 3284, 3288,
};