xref: /aosp_15_r20/external/ms-tpm-20-ref/README.md (revision 5c591343844d1f9da7da26467c4bf7efc8a7a413)
1*5c591343SA. Cody Schuffelen# Official TPM 2.0 Reference Implementation (by Microsoft) #
2*5c591343SA. Cody Schuffelen
3*5c591343SA. Cody Schuffelen[![Build Status](https://travis-ci.org/Microsoft/ms-tpm-20-ref.svg?branch=master)](https://travis-ci.org/Microsoft/ms-tpm-20-ref)
4*5c591343SA. Cody Schuffelen
5*5c591343SA. Cody SchuffelenThis is the official TCG reference implementation of the [TPM 2.0 Specification](https://trustedcomputinggroup.org/tpm-library-specification). The project contains complete source code of the reference implementation with a Microsoft Visual Studio solution and Linux autotools build scripts.
6*5c591343SA. Cody Schuffelen
7*5c591343SA. Cody SchuffelenSee the definition of the `SPEC_VERSION`, `SPEC_YEAR` and `SPEC_DAY_OF_YEAR` values in the [TpmTypes.h](TPMCmd/tpm/include/TpmTypes.h) header for the exact revision/date of the TPM 2.0 specification, which the given source tree snapshot corresponds to.
8*5c591343SA. Cody Schuffelen
9*5c591343SA. Cody SchuffelenThe reference implementation can be directly used via the [TPM 2.0 simulator](TPMCmd/Simulator) that emulates a TPM 2.0 device and can be accessed via a custom TCP based protocol. The simplest way to work with the simulator is to use a [TSS library](https://github.com/Microsoft/TSS.MSR) for the programming language of your choice - C#/.Net, C++, Java, Python, JavaScript/Node.js are currently supported. The C language TSS implementing the TCG's TSS API specifiaction is available [here](https://github.com/tpm2-software/tpm2-tss).
10*5c591343SA. Cody Schuffelen
11*5c591343SA. Cody Schuffelen## Windows build ##
12*5c591343SA. Cody Schuffelen
13*5c591343SA. Cody SchuffelenWindows build is implemented as a Visual Studio 2017 solution. Before building it:
14*5c591343SA. Cody Schuffelen
15*5c591343SA. Cody Schuffelen* Setup one or both of the following underlying cryptographic libraries:
16*5c591343SA. Cody Schuffelen
17*5c591343SA. Cody Schuffelen   ### OpenSSL library ###
18*5c591343SA. Cody Schuffelen
19*5c591343SA. Cody Schuffelen   1. Create `TPMCmd/lib` folder and place a static OpenSSL library (`libcrypto.lib`) built for the `x86` architecture there. For the `x64` architecture use the `TPMCmd/lib/x64` folder.
20*5c591343SA. Cody Schuffelen
21*5c591343SA. Cody Schuffelen        The static libs can be either static libraries proper, or import libraries accompanying the corresponding DLLs. In the latter case you'll need to ensure that ther is a matching copy of the OpenSSL DLL in the standard Windows search path, so that it is available when you run the simulator executable (e.g. copy it into the same folder where `simulator.exe` is located).
22*5c591343SA. Cody Schuffelen
23*5c591343SA. Cody Schuffelen        Recommended version of OpenSSL is `1.1.1d` or higher.
24*5c591343SA. Cody Schuffelen
25*5c591343SA. Cody Schuffelen   2. Create `TPMCmd/OsslInclude/openssl` folder and copy there the contents of the `openssl/include/openssl` folder in the OpenSSL source tree used to build the OpenSSL library.
26*5c591343SA. Cody Schuffelen
27*5c591343SA. Cody Schuffelen      If you enable SM{2,3,4} algorithms in `TpmProfile.h`, the build may fail because of missing `SM{2,3,4}.h` headers. In this case you will need to manually copy them over from OpenSSL’s `include/crypt` folder.
28*5c591343SA. Cody Schuffelen
29*5c591343SA. Cody Schuffelen   3. Build the solution with either Debug or Release as the active configuration.
30*5c591343SA. Cody Schuffelen
31*5c591343SA. Cody Schuffelen   ### Wolfcrypt library (wolfSSL) ###
32*5c591343SA. Cody Schuffelen
33*5c591343SA. Cody Schuffelen   1. WolfSSL is included as a submodule. Initialize and update the submodule to fetch the project and checkout the appropriate commit.
34*5c591343SA. Cody Schuffelen
35*5c591343SA. Cody Schuffelen        > git submodule init
36*5c591343SA. Cody Schuffelen        > git submodule update
37*5c591343SA. Cody Schuffelen
38*5c591343SA. Cody Schuffelen        The current commit will point the minimum recommended version of wolfSSL. Moving to a more recent tag or commit should also be supported but might not be tested.
39*5c591343SA. Cody Schuffelen
40*5c591343SA. Cody Schuffelen   2. Build the solution with either WolfDebug or WolfRelease as the active configuration, either from inside the Visual Studio or with the following command line:
41*5c591343SA. Cody Schuffelen
42*5c591343SA. Cody Schuffelen        > msbuild TPMCmd\simulator.sln /p:Configuration=WolfDebug
43*5c591343SA. Cody Schuffelen
44*5c591343SA. Cody Schuffelen* If necessary, update the definitions of the following macros in the [VendorString.h](TPMCmd/tpm/include/VendorString.h) header: `MANUFACTURER`, `VENDOR_STRING_1`, `FIRMWARE_V1 and FIRMWARE_V2`
45*5c591343SA. Cody Schuffelen
46*5c591343SA. Cody Schuffelen## Linux build
47*5c591343SA. Cody Schuffelen
48*5c591343SA. Cody SchuffelenFollows the common `./bootstrap && ./configure && make` convention.
49*5c591343SA. Cody Schuffelen
50*5c591343SA. Cody SchuffelenNote that autotools scripts require the following prerequisite packages: `autoconf-archive`, `pkg-config`, and sometimes `build-essential` and `automake`. Their absence is not automatically detected. The build also needs `gcc` and `libssl-dev` packages.
51*5c591343SA. Cody Schuffelen
52*5c591343SA. Cody SchuffelenSimilarly to the Windows build, if you enable SM{2,3,4} algorithms in `TpmProfile.h`, the build may fail because of missing `SM{2,3,4}.h` headers. In this case you will need to manually copy them over from OpenSSL’s `include/crypt` folder.
53