Compare commits

...

18 Commits

Author SHA1 Message Date
Stefan Berger
13a41ca095 tpm2: Add missing defines for existing structures, remove others
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
2a5baa8800 tpm2: Sync up RunCommand.c with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
e60fafc61a tpm2: Add missing SVN-related cases in TPMPropertyIsDefined
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
b2839e2613 tpm2: Sync TPM_PT_MODES case in TPMPropertyIsDefined
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
865b356292 tpm2: Add missing '|| TABLE_DRIVEN_MARSHAL' to CommandDispatcher.c
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
fccc05845b tpm2: Add support for CRYPTO_LIB_REPORTING but do not use it
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
74bd4ee1d6 tpm2: Use TPM2B_DIGEST in MAC_Out
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
79e233c607 tpm2: Remove CLOCK_ defines for header since already in Clock.c
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
1278421db9 tpm2: Add TPMI_RH_BASE_HIERARCHY type and use it
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
04dab706c5 tpm2: Add (unused) defines to TpmTcpProtocol.h
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
fa637145b8 tpm2: Fix definition of CertifyX509 error codes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
0945ad07ef tpm2: Fix definition of ChangePPS error codes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
a954fa214b tpm2: Fix definition of NV_ReadPublic error codes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
2360ec6d83 tpm2: Fix definition of HierarchyChnageAuth error codes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
bd282cce6a tpm2: Fix definition of SequenceUpdate error codes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
f8ddf879af tpm2: Replace occurrences of xorr with xor
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
4c7dcf2db3 tpm2: Rebase on TPM v1.83: Reduce diffs
- Rename files so the filenames match
- Reduce whitespace diffs
- Other trivial changes

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
5de6c7fe40 scripts: Implement scripts to be able to use meld on upstream codebase
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
350 changed files with 31518 additions and 27298 deletions

98
scripts/meld-all Executable file
View File

@ -0,0 +1,98 @@
#!/usr/bin/env bash
SKIP_FILES="(Marshal.c|Marshal_fp.h)"
NO_MELD_FLAG=$((1<<0))
main()
{
local opts f fname upstream flags
flags=0
prgname="$0"
if ! opts=$(getopt -l "help,no-meld,diff-only" -n "$prgname" -- "$prgname" "$@"); then
echo "Error: Failed to parse options." >&2
return 1
fi
eval set -- "${opts}"
while :; do
case "$1" in
--no-meld|diff-only)
flags=$((flags | NO_MELD_FLAG))
shift
;;
--)
shift
break
;;
--help)
help "$prgname"
return 0
;;
*)
echo "Internal error: Unregonized option '$1'" >&2
shift
return
;;
esac
done
if [ ! -r "$1" ]; then
echo "Cannot find file '$1' in libtpms repo."
exit 1
fi
if [ ! -d "$1" ]; then
echo "'$1' is not a directory."
exit 1
fi
if [ ! -d "${TCG_TPM_HOME}" ]; then
echo "TCG_TPM_HOME must point to a directory."
exit 1
fi
for f in $(find "$1" -type f -name '*.[ch]'); do
fname=$(basename "$f")
if [[ "${fname}" =~ ^${SKIP_FILES}$ ]]; then
echo "skipping ${fname}"
continue
fi
upstream=$(find "${TCG_TPM_HOME}" | grep -E "/${fname}\$")
if [ -n "${upstream}" ]; then
# find first empty line presumably after license
line=$(grep -m 1 -E "^$" -n "${f}" | cut -d":" -f1)
if [ -z "$line" ]; then
if [ $((flags & NO_MELD_FLAG)) -eq 0 ]; then
meld "${upstrean}" "${f}"
else
echo "Something wrong with file $f"
fi
fi
line=$((line+1))
if [ $((flags & NO_MELD_FLAG)) -ne 0 ]; then
echo "============================================================================"
echo "${f}"
diff --ignore-trailing-space <(sed -n "${line},\$p" < "${f}") "${upstream}"
fi
if ! diff --ignore-trailing-space <(sed -n "${line},\$p" < "${f}") "${upstream}" >/dev/null; then
if [ $((flags & NO_MELD_FLAG)) -eq 0 ]; then
meld "${upstream}" "$f"
fi
else
echo "${f}: nothing to do"
fi
else
echo "Could not find file ${fname} in TCG TPM repo"
fi
done
}
main "$@"
exit $?

23
scripts/meld-find Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env bash
if [ ! -f "$1" ]; then
echo "Cannot find file '$1' in libtpms repo."
exit 1
fi
if [ -z "${TCG_TPM_HOME}" ]; then
echo "TCG_TPM_HOME must be set to the TCG TPM repo checkout."
exit 1
fi
if [ ! -d "${TCG_TPM_HOME}" ]; then
echo "TCG_TPM_HOME must point to a directory."
exit 1
fi
fname=$(basename "$1")
upstream=$(find "${TCG_TPM_HOME}" | grep -E "/${fname}\$")
meld "${upstream}" "$1"

View File

@ -237,9 +237,9 @@ libtpms_tpm2_la_SOURCES = \
tpm2/MathOnByteBuffers.c \
tpm2/Memory.c \
tpm2/NVCommands.c \
tpm2/NVDynamic.c \
tpm2/NvDynamic.c \
tpm2/NVMem.c \
tpm2/NVReserved.c \
tpm2/NvReserved.c \
tpm2/NV_spt.c \
tpm2/Object.c \
tpm2/ObjectCommands.c \
@ -268,7 +268,7 @@ libtpms_tpm2_la_SOURCES = \
tpm2/TestingCommands.c \
tpm2/Ticket.c \
tpm2/Time.c \
tpm2/TpmAsn1.c \
tpm2/TpmASN1.c \
tpm2/TpmBigNumThunks.c \
tpm2/TpmEcc_Signature_ECDAA.c \
tpm2/TpmEcc_Signature_ECDSA.c \
@ -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 \
@ -426,7 +427,7 @@ noinst_HEADERS += \
tpm2/NV_ChangeAuth_fp.h \
tpm2/NV_DefineSpace_fp.h \
tpm2/NV_DefineSpace2_fp.h \
tpm2/NVDynamic_fp.h \
tpm2/NvDynamic_fp.h \
tpm2/NV_Extend_fp.h \
tpm2/NV_GlobalWriteLock_fp.h \
tpm2/NV.h \
@ -435,7 +436,7 @@ noinst_HEADERS += \
tpm2/NV_ReadLock_fp.h \
tpm2/NV_ReadPublic_fp.h \
tpm2/NV_ReadPublic2_fp.h \
tpm2/NVReserved_fp.h \
tpm2/NvReserved_fp.h \
tpm2/NV_SetBits_fp.h \
tpm2/NV_spt_fp.h \
tpm2/NV_UndefineSpace_fp.h \

View File

@ -59,199 +59,213 @@
/* */
/********************************************************************************/
// 5.24 ACT.h
#ifndef _ACT_H_
#define _ACT_H_
#include "TpmProfile.h"
#if 0 // libtpms added
#if ACT_SUPPORT \
!= (RH_ACT_0 | RH_ACT_1 | RH_ACT_2 | RH_ACT_3 | RH_ACT_4 | RH_ACT_5 | RH_ACT_6 \
| RH_ACT_7 | RH_ACT_8 | RH_ACT_9 | RH_ACT_A | RH_ACT_B | RH_ACT_C | RH_ACT_D \
| RH_ACT_E | RH_ACT_F)
# error "If ACT_SUPPORT == NO, no ACTs can be enabled"
#endif // (ACT_SUPPORT != ...)
#endif // libtpms added
#if !(defined RH_ACT_0) || (RH_ACT_0 != YES)
# undef RH_ACT_0
# define RH_ACT_0 NO
# define IF_ACT_0_IMPLEMENTED(op)
# undef RH_ACT_0
# define RH_ACT_0 NO
# define IF_ACT_0_IMPLEMENTED(op)
#else
# define IF_ACT_0_IMPLEMENTED(op) op(0)
# define IF_ACT_0_IMPLEMENTED(op) op(0)
#endif
#if !(defined RH_ACT_1) || (RH_ACT_1 != YES)
# undef RH_ACT_1
# define RH_ACT_1 NO
# define IF_ACT_1_IMPLEMENTED(op)
# undef RH_ACT_1
# define RH_ACT_1 NO
# define IF_ACT_1_IMPLEMENTED(op)
#else
# define IF_ACT_1_IMPLEMENTED(op) op(1)
# define IF_ACT_1_IMPLEMENTED(op) op(1)
#endif
#if !(defined RH_ACT_2) || (RH_ACT_2 != YES)
# undef RH_ACT_2
# define RH_ACT_2 NO
# define IF_ACT_2_IMPLEMENTED(op)
# undef RH_ACT_2
# define RH_ACT_2 NO
# define IF_ACT_2_IMPLEMENTED(op)
#else
# define IF_ACT_2_IMPLEMENTED(op) op(2)
# define IF_ACT_2_IMPLEMENTED(op) op(2)
#endif
#if !(defined RH_ACT_3) || (RH_ACT_3 != YES)
# undef RH_ACT_3
# define RH_ACT_3 NO
# define IF_ACT_3_IMPLEMENTED(op)
# undef RH_ACT_3
# define RH_ACT_3 NO
# define IF_ACT_3_IMPLEMENTED(op)
#else
# define IF_ACT_3_IMPLEMENTED(op) op(3)
# define IF_ACT_3_IMPLEMENTED(op) op(3)
#endif
#if !(defined RH_ACT_4) || (RH_ACT_4 != YES)
# undef RH_ACT_4
# define RH_ACT_4 NO
# define IF_ACT_4_IMPLEMENTED(op)
# undef RH_ACT_4
# define RH_ACT_4 NO
# define IF_ACT_4_IMPLEMENTED(op)
#else
# define IF_ACT_4_IMPLEMENTED(op) op(4)
# define IF_ACT_4_IMPLEMENTED(op) op(4)
#endif
#if !(defined RH_ACT_5) || (RH_ACT_5 != YES)
# undef RH_ACT_5
# define RH_ACT_5 NO
# define IF_ACT_5_IMPLEMENTED(op)
# undef RH_ACT_5
# define RH_ACT_5 NO
# define IF_ACT_5_IMPLEMENTED(op)
#else
# define IF_ACT_5_IMPLEMENTED(op) op(5)
# define IF_ACT_5_IMPLEMENTED(op) op(5)
#endif
#if !(defined RH_ACT_6) || (RH_ACT_6 != YES)
# undef RH_ACT_6
# define RH_ACT_6 NO
# define IF_ACT_6_IMPLEMENTED(op)
# undef RH_ACT_6
# define RH_ACT_6 NO
# define IF_ACT_6_IMPLEMENTED(op)
#else
# define IF_ACT_6_IMPLEMENTED(op) op(6)
# define IF_ACT_6_IMPLEMENTED(op) op(6)
#endif
#if !(defined RH_ACT_7) || (RH_ACT_7 != YES)
# undef RH_ACT_7
# define RH_ACT_7 NO
# define IF_ACT_7_IMPLEMENTED(op)
# undef RH_ACT_7
# define RH_ACT_7 NO
# define IF_ACT_7_IMPLEMENTED(op)
#else
# define IF_ACT_7_IMPLEMENTED(op) op(7)
# define IF_ACT_7_IMPLEMENTED(op) op(7)
#endif
#if !(defined RH_ACT_8) || (RH_ACT_8 != YES)
# undef RH_ACT_8
# define RH_ACT_8 NO
# define IF_ACT_8_IMPLEMENTED(op)
# undef RH_ACT_8
# define RH_ACT_8 NO
# define IF_ACT_8_IMPLEMENTED(op)
#else
# define IF_ACT_8_IMPLEMENTED(op) op(8)
# define IF_ACT_8_IMPLEMENTED(op) op(8)
#endif
#if !(defined RH_ACT_9) || (RH_ACT_9 != YES)
# undef RH_ACT_9
# define RH_ACT_9 NO
# define IF_ACT_9_IMPLEMENTED(op)
# undef RH_ACT_9
# define RH_ACT_9 NO
# define IF_ACT_9_IMPLEMENTED(op)
#else
# define IF_ACT_9_IMPLEMENTED(op) op(9)
# define IF_ACT_9_IMPLEMENTED(op) op(9)
#endif
#if !(defined RH_ACT_A) || (RH_ACT_A != YES)
# undef RH_ACT_A
# define RH_ACT_A NO
# define IF_ACT_A_IMPLEMENTED(op)
# undef RH_ACT_A
# define RH_ACT_A NO
# define IF_ACT_A_IMPLEMENTED(op)
#else
# define IF_ACT_A_IMPLEMENTED(op) op(A)
# define IF_ACT_A_IMPLEMENTED(op) op(A)
#endif
#if !(defined RH_ACT_B) || (RH_ACT_B != YES)
# undef RH_ACT_B
# define RH_ACT_B NO
# define IF_ACT_B_IMPLEMENTED(op)
# undef RH_ACT_B
# define RH_ACT_B NO
# define IF_ACT_B_IMPLEMENTED(op)
#else
# define IF_ACT_B_IMPLEMENTED(op) op(B)
# define IF_ACT_B_IMPLEMENTED(op) op(B)
#endif
#if !(defined RH_ACT_C) || (RH_ACT_C != YES)
# undef RH_ACT_C
# define RH_ACT_C NO
# define IF_ACT_C_IMPLEMENTED(op)
# undef RH_ACT_C
# define RH_ACT_C NO
# define IF_ACT_C_IMPLEMENTED(op)
#else
# define IF_ACT_C_IMPLEMENTED(op) op(C)
# define IF_ACT_C_IMPLEMENTED(op) op(C)
#endif
#if !(defined RH_ACT_D) || (RH_ACT_D != YES)
# undef RH_ACT_D
# define RH_ACT_D NO
# define IF_ACT_D_IMPLEMENTED(op)
# undef RH_ACT_D
# define RH_ACT_D NO
# define IF_ACT_D_IMPLEMENTED(op)
#else
# define IF_ACT_D_IMPLEMENTED(op) op(D)
# define IF_ACT_D_IMPLEMENTED(op) op(D)
#endif
#if !(defined RH_ACT_E) || (RH_ACT_E != YES)
# undef RH_ACT_E
# define RH_ACT_E NO
# define IF_ACT_E_IMPLEMENTED(op)
# undef RH_ACT_E
# define RH_ACT_E NO
# define IF_ACT_E_IMPLEMENTED(op)
#else
# define IF_ACT_E_IMPLEMENTED(op) op(E)
# define IF_ACT_E_IMPLEMENTED(op) op(E)
#endif
#if !(defined RH_ACT_F) || (RH_ACT_F != YES)
# undef RH_ACT_F
# define RH_ACT_F NO
# define IF_ACT_F_IMPLEMENTED(op)
# undef RH_ACT_F
# define RH_ACT_F NO
# define IF_ACT_F_IMPLEMENTED(op)
#else
# define IF_ACT_F_IMPLEMENTED(op) op(F)
# define IF_ACT_F_IMPLEMENTED(op) op(F)
#endif
#ifndef TPM_RH_ACT_0
#error Need numeric definition for TPM_RH_ACT_0
# error Need numeric definition for TPM_RH_ACT_0
#endif
#ifndef TPM_RH_ACT_1
# define TPM_RH_ACT_1 (TPM_RH_ACT_0 + 1)
# define TPM_RH_ACT_1 (TPM_RH_ACT_0 + 1)
#endif
#ifndef TPM_RH_ACT_2
# define TPM_RH_ACT_2 (TPM_RH_ACT_0 + 2)
# define TPM_RH_ACT_2 (TPM_RH_ACT_0 + 2)
#endif
#ifndef TPM_RH_ACT_3
# define TPM_RH_ACT_3 (TPM_RH_ACT_0 + 3)
# define TPM_RH_ACT_3 (TPM_RH_ACT_0 + 3)
#endif
#ifndef TPM_RH_ACT_4
# define TPM_RH_ACT_4 (TPM_RH_ACT_0 + 4)
# define TPM_RH_ACT_4 (TPM_RH_ACT_0 + 4)
#endif
#ifndef TPM_RH_ACT_5
# define TPM_RH_ACT_5 (TPM_RH_ACT_0 + 5)
# define TPM_RH_ACT_5 (TPM_RH_ACT_0 + 5)
#endif
#ifndef TPM_RH_ACT_6
# define TPM_RH_ACT_6 (TPM_RH_ACT_0 + 6)
# define TPM_RH_ACT_6 (TPM_RH_ACT_0 + 6)
#endif
#ifndef TPM_RH_ACT_7
# define TPM_RH_ACT_7 (TPM_RH_ACT_0 + 7)
# define TPM_RH_ACT_7 (TPM_RH_ACT_0 + 7)
#endif
#ifndef TPM_RH_ACT_8
# define TPM_RH_ACT_8 (TPM_RH_ACT_0 + 8)
# define TPM_RH_ACT_8 (TPM_RH_ACT_0 + 8)
#endif
#ifndef TPM_RH_ACT_9
# define TPM_RH_ACT_9 (TPM_RH_ACT_0 + 9)
# define TPM_RH_ACT_9 (TPM_RH_ACT_0 + 9)
#endif
#ifndef TPM_RH_ACT_A
# define TPM_RH_ACT_A (TPM_RH_ACT_0 + 0xA)
# define TPM_RH_ACT_A (TPM_RH_ACT_0 + 0xA)
#endif
#ifndef TPM_RH_ACT_B
# define TPM_RH_ACT_B (TPM_RH_ACT_0 + 0xB)
# define TPM_RH_ACT_B (TPM_RH_ACT_0 + 0xB)
#endif
#ifndef TPM_RH_ACT_C
# define TPM_RH_ACT_C (TPM_RH_ACT_0 + 0xC)
# define TPM_RH_ACT_C (TPM_RH_ACT_0 + 0xC)
#endif
#ifndef TPM_RH_ACT_D
# define TPM_RH_ACT_D (TPM_RH_ACT_0 + 0xD)
# define TPM_RH_ACT_D (TPM_RH_ACT_0 + 0xD)
#endif
#ifndef TPM_RH_ACT_E
# define TPM_RH_ACT_E (TPM_RH_ACT_0 + 0xE)
# define TPM_RH_ACT_E (TPM_RH_ACT_0 + 0xE)
#endif
#ifndef TPM_RH_ACT_F
# define TPM_RH_ACT_F (TPM_RH_ACT_0 + 0xF)
# define TPM_RH_ACT_F (TPM_RH_ACT_0 + 0xF)
#endif
#define FOR_EACH_ACT(op) \
IF_ACT_0_IMPLEMENTED(op) \
IF_ACT_1_IMPLEMENTED(op) \
IF_ACT_2_IMPLEMENTED(op) \
IF_ACT_3_IMPLEMENTED(op) \
IF_ACT_4_IMPLEMENTED(op) \
IF_ACT_5_IMPLEMENTED(op) \
IF_ACT_6_IMPLEMENTED(op) \
IF_ACT_7_IMPLEMENTED(op) \
IF_ACT_8_IMPLEMENTED(op) \
IF_ACT_9_IMPLEMENTED(op) \
IF_ACT_A_IMPLEMENTED(op) \
IF_ACT_B_IMPLEMENTED(op) \
IF_ACT_C_IMPLEMENTED(op) \
IF_ACT_D_IMPLEMENTED(op) \
IF_ACT_E_IMPLEMENTED(op) \
#define FOR_EACH_ACT(op) \
IF_ACT_0_IMPLEMENTED(op) \
IF_ACT_1_IMPLEMENTED(op) \
IF_ACT_2_IMPLEMENTED(op) \
IF_ACT_3_IMPLEMENTED(op) \
IF_ACT_4_IMPLEMENTED(op) \
IF_ACT_5_IMPLEMENTED(op) \
IF_ACT_6_IMPLEMENTED(op) \
IF_ACT_7_IMPLEMENTED(op) \
IF_ACT_8_IMPLEMENTED(op) \
IF_ACT_9_IMPLEMENTED(op) \
IF_ACT_A_IMPLEMENTED(op) \
IF_ACT_B_IMPLEMENTED(op) \
IF_ACT_C_IMPLEMENTED(op) \
IF_ACT_D_IMPLEMENTED(op) \
IF_ACT_E_IMPLEMENTED(op) \
IF_ACT_F_IMPLEMENTED(op)
// This is the mask for ACT that are implemented
//#define ACT_MASK(N) | (1 << 0x##N)
//#define ACT_IMPLEMENTED_MASK (0 FOR_EACH_ACT(ACT_MASK))
#define CASE_ACT_HANDLE(N) case TPM_RH_ACT_##N:
#define CASE_ACT_NUMBER(N) case 0x##N:
#define CASE_ACT_HANDLE(N) case TPM_RH_ACT_##N:
#define CASE_ACT_NUMBER(N) case 0x##N:
typedef struct ACT_STATE
{
UINT32 remaining;
TPM_ALG_ID hashAlg;
TPM2B_DIGEST authPolicy;
UINT32 remaining;
TPM_ALG_ID hashAlg;
TPM2B_DIGEST authPolicy;
} ACT_STATE, *P_ACT_STATE;
#endif // _ACT_H_
#endif // _ACT_H_

View File

@ -1,79 +1,86 @@
/********************************************************************************/
/* */
/* TPM2_ACT_SetTimeout Header */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id$ */
/* */
/* Licenses and Notices */
/* */
/* 1. Copyright Licenses: */
/* */
/* - Trusted Computing Group (TCG) grants to the user of the source code in */
/* this specification (the "Source Code") a worldwide, irrevocable, */
/* nonexclusive, royalty free, copyright license to reproduce, create */
/* derivative works, distribute, display and perform the Source Code and */
/* derivative works thereof, and to grant others the rights granted herein. */
/* */
/* - The TCG grants to the user of the other parts of the specification */
/* (other than the Source Code) the rights to reproduce, distribute, */
/* display, and perform the specification solely for the purpose of */
/* developing products based on such documents. */
/* */
/* 2. Source Code Distribution Conditions: */
/* */
/* - Redistributions of Source Code must retain the above copyright licenses, */
/* this list of conditions and the following disclaimers. */
/* */
/* - Redistributions in binary form must reproduce the above copyright */
/* licenses, this list of conditions and the following disclaimers in the */
/* documentation and/or other materials provided with the distribution. */
/* */
/* 3. Disclaimers: */
/* */
/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */
/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */
/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */
/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */
/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */
/* information on specification licensing rights available through TCG */
/* membership agreements. */
/* */
/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */
/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */
/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */
/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */
/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */
/* */
/* - Without limitation, TCG and its members and licensors disclaim all */
/* liability, including liability for infringement of any proprietary */
/* rights, relating to use of information in this specification and to the */
/* implementation of this specification, and TCG disclaims all liability for */
/* cost of procurement of substitute goods or services, lost profits, loss */
/* of use, loss of data or any incidental, consequential, direct, indirect, */
/* or special damages, whether under contract, tort, warranty or otherwise, */
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2019 */
/* */
/********************************************************************************/
#ifndef ACT_SETTIMEOUT_FP_H
#define ACT_SETTIMEOUT_FP_H
typedef struct {
TPMI_RH_ACT actHandle;
UINT32 startTimeout;
} ACT_SetTimeout_In;
#define RC_ACT_SetTimeout_actHandle (TPM_RC_H + TPM_RC_1)
#define RC_ACT_SetTimeout_startTimeout (TPM_RC_H + TPM_RC_2)
TPM_RC
TPM2_ACT_SetTimeout(
ACT_SetTimeout_In *in // IN: input parameter list
);
#endif
/********************************************************************************/
/* */
/* TPM2_ACT_SetTimeout Header */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id$ */
/* */
/* Licenses and Notices */
/* */
/* 1. Copyright Licenses: */
/* */
/* - Trusted Computing Group (TCG) grants to the user of the source code in */
/* this specification (the "Source Code") a worldwide, irrevocable, */
/* nonexclusive, royalty free, copyright license to reproduce, create */
/* derivative works, distribute, display and perform the Source Code and */
/* derivative works thereof, and to grant others the rights granted herein. */
/* */
/* - The TCG grants to the user of the other parts of the specification */
/* (other than the Source Code) the rights to reproduce, distribute, */
/* display, and perform the specification solely for the purpose of */
/* developing products based on such documents. */
/* */
/* 2. Source Code Distribution Conditions: */
/* */
/* - Redistributions of Source Code must retain the above copyright licenses, */
/* this list of conditions and the following disclaimers. */
/* */
/* - Redistributions in binary form must reproduce the above copyright */
/* licenses, this list of conditions and the following disclaimers in the */
/* documentation and/or other materials provided with the distribution. */
/* */
/* 3. Disclaimers: */
/* */
/* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */
/* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */
/* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */
/* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */
/* Contact TCG Administration (admin@trustedcomputinggroup.org) for */
/* information on specification licensing rights available through TCG */
/* membership agreements. */
/* */
/* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */
/* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */
/* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */
/* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */
/* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */
/* */
/* - Without limitation, TCG and its members and licensors disclaim all */
/* liability, including liability for infringement of any proprietary */
/* rights, relating to use of information in this specification and to the */
/* implementation of this specification, and TCG disclaims all liability for */
/* cost of procurement of substitute goods or services, lost profits, loss */
/* of use, loss of data or any incidental, consequential, direct, indirect, */
/* or special damages, whether under contract, tort, warranty or otherwise, */
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2019 */
/* */
/********************************************************************************/
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
#if CC_ACT_SetTimeout // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_ACT_SETTIMEOUT_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_ACT_SETTIMEOUT_FP_H_
// Input structure definition
typedef struct
{
TPMI_RH_ACT actHandle;
UINT32 startTimeout;
} ACT_SetTimeout_In;
// Response code modifiers
# define RC_ACT_SetTimeout_actHandle (TPM_RC_H + TPM_RC_1)
# define RC_ACT_SetTimeout_startTimeout (TPM_RC_P + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_ACT_SetTimeout(ACT_SetTimeout_In* in);
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_ACT_SETTIMEOUT_FP_H_
#endif // CC_ACT_SetTimeout

View File

@ -82,15 +82,15 @@
// and turns signaling back on if necessary.
#ifndef __ACT_DISABLED // libtpms added
static void _ActResume(UINT32 act, //IN: the act number
ACT_STATE* actData //IN: pointer to the saved ACT data
)
ACT_STATE* actData //IN: pointer to the saved ACT data
)
{
// If the act was non-zero, then restore the counter value.
if(actData->remaining > 0)
_plat__ACT_UpdateCounter(act, actData->remaining);
_plat__ACT_UpdateCounter(act, actData->remaining);
// if the counter was zero and the ACT signaling, enable the signaling.
else if(go.signaledACT & (1 << act))
_plat__ACT_SetSignaled(act, TRUE);
_plat__ACT_SetSignaled(act, TRUE);
}
#endif // libtpms added
@ -100,35 +100,35 @@ BOOL ActStartup(STARTUP_TYPE type)
{
// Reset all the ACT hardware
_plat__ACT_Initialize();
// If this not a cold start, copy all the current 'signaled' settings to
// 'preservedSignaled'.
#ifndef __ACT_DISABLED // libtpms added
if(g_powerWasLost)
go.preservedSignaled = 0;
go.preservedSignaled = 0;
else
go.preservedSignaled |= go.signaledACT;
go.preservedSignaled |= go.signaledACT;
#endif // libtpms added
// For TPM_RESET or TPM_RESTART, the ACTs will all be disabled and the output
// de-asserted.
if(type != SU_RESUME)
{
{
#ifndef __ACT_DISABLED // libtpms added
go.signaledACT = 0;
go.signaledACT = 0;
#endif // libtpms added
# define CLEAR_ACT_POLICY(N) \
go.ACT_##N.hashAlg = TPM_ALG_NULL; \
go.ACT_##N.authPolicy.b.size = 0;
FOR_EACH_ACT(CLEAR_ACT_POLICY)
}
# define CLEAR_ACT_POLICY(N) \
go.ACT_##N.hashAlg = TPM_ALG_NULL; \
go.ACT_##N.authPolicy.b.size = 0;
FOR_EACH_ACT(CLEAR_ACT_POLICY)
}
else
{
// Resume each of the implemented ACT
{
// Resume each of the implemented ACT
# define RESUME_ACT(N) _ActResume(0x##N, &go.ACT_##N);
FOR_EACH_ACT(RESUME_ACT)
}
FOR_EACH_ACT(RESUME_ACT)
}
// set no ACT updated since last startup. This is to enable the halving of the
// timeout value
s_ActUpdated = 0;
@ -146,13 +146,13 @@ static void _ActSaveState(UINT32 act, P_ACT_STATE actData)
// If the ACT hasn't been updated since the last startup, then it should be
// be halved.
if((s_ActUpdated & (1 << act)) == 0)
{
// Don't halve if the count is set to max or if halving would make it zero
if((actData->remaining != UINT32_MAX) && (actData->remaining > 1))
actData->remaining /= 2;
}
{
// Don't halve if the count is set to max or if halving would make it zero
if((actData->remaining != UINT32_MAX) && (actData->remaining > 1))
actData->remaining /= 2;
}
if(_plat__ACT_GetSignaled(act))
go.signaledACT |= (1 << act);
go.signaledACT |= (1 << act);
}
//*** ActGetSignaled()
@ -168,7 +168,7 @@ BOOL ActGetSignaled(TPM_RH actHandle)
//***ActShutdown()
// This function saves the current state of the counters
BOOL ActShutdown(TPM_SU state //IN: the type of the shutdown.
)
)
{
// if this is not shutdown state, then the only type of startup is TPM_RESTART
// so the timer values will be cleared. If this is shutdown state, get the current
@ -176,16 +176,16 @@ BOOL ActShutdown(TPM_SU state //IN: the type of the shutdown.
// since the last restart, divide the time by 2 so that there is no attack on the
// countdown by saving the countdown state early and then not using the TPM.
if(state == TPM_SU_STATE)
{
// This will be populated as each of the ACT is queried
{
// This will be populated as each of the ACT is queried
#ifndef __ACT_DISABLED // libtpms added
go.signaledACT = 0;
go.signaledACT = 0;
#endif // libtpms added
// Get the current count and the signaled state
// Get the current count and the signaled state
# define SAVE_ACT_STATE(N) _ActSaveState(0x##N, &go.ACT_##N);
FOR_EACH_ACT(SAVE_ACT_STATE);
}
FOR_EACH_ACT(SAVE_ACT_STATE);
}
return TRUE;
}
@ -196,16 +196,16 @@ BOOL ActIsImplemented(UINT32 act)
{
// This switch accounts for the TPM implemented values.
switch(act)
{
{
#ifndef __ACT_DISABLED // libtpms added
FOR_EACH_ACT(CASE_ACT_NUMBER)
// This ensures that the platform implements the values implemented by
// the TPM
return _plat__ACT_GetImplemented(act);
FOR_EACH_ACT(CASE_ACT_NUMBER)
// This ensures that the platform implements the values implemented by
// the TPM
return _plat__ACT_GetImplemented(act);
#endif // libtpms added
default:
break;
}
default:
break;
}
return FALSE;
}
@ -215,8 +215,8 @@ BOOL ActIsImplemented(UINT32 act)
// it returns TPM_RC_RETRY so that the update can be tried again later.
TPM_RC
ActCounterUpdate(TPM_RH handle, //IN: the handle of the act
UINT32 newValue //IN: the value to set in the ACT
)
UINT32 newValue //IN: the value to set in the ACT
)
{
UINT32 act;
TPM_RC result;
@ -224,31 +224,31 @@ ActCounterUpdate(TPM_RH handle, //IN: the handle of the act
act = handle - TPM_RH_ACT_0;
// This should never fail, but...
if(!_plat__ACT_GetImplemented(act))
result = TPM_RC_VALUE;
result = TPM_RC_VALUE;
else
{
// Will need to clear orderly so fail if we are orderly and NV is
// not available
if(NV_IS_ORDERLY)
RETURN_IF_NV_IS_NOT_AVAILABLE;
// if the attempt to update the counter fails, it means that there is an
// update pending so wait until it has occurred and then do an update.
if(!_plat__ACT_UpdateCounter(act, newValue))
result = TPM_RC_RETRY;
else
{
// Indicate that the ACT has been updated since last TPM2_Startup().
s_ActUpdated |= (UINT16)(1 << act);
// Clear the preservedSignaled attribute.
go.preservedSignaled &= ~((UINT16)(1 << act));
// Need to clear the orderly flag
g_clearOrderly = TRUE;
result = TPM_RC_SUCCESS;
}
}
{
// Will need to clear orderly so fail if we are orderly and NV is
// not available
if(NV_IS_ORDERLY)
RETURN_IF_NV_IS_NOT_AVAILABLE;
// if the attempt to update the counter fails, it means that there is an
// update pending so wait until it has occurred and then do an update.
if(!_plat__ACT_UpdateCounter(act, newValue))
result = TPM_RC_RETRY;
else
{
// Indicate that the ACT has been updated since last TPM2_Startup().
s_ActUpdated |= (UINT16)(1 << act);
// Clear the preservedSignaled attribute.
go.preservedSignaled &= ~((UINT16)(1 << act));
// Need to clear the orderly flag
g_clearOrderly = TRUE;
result = TPM_RC_SUCCESS;
}
}
return result;
}
#endif // libtpms added
@ -260,49 +260,49 @@ ActCounterUpdate(TPM_RH handle, //IN: the handle of the act
// NO if no more ACT data to
TPMI_YES_NO
ActGetCapabilityData(TPM_HANDLE actHandle, // IN: the handle for the starting ACT
UINT32 maxCount, // IN: maximum allowed return values
TPML_ACT_DATA* actList // OUT: ACT data list
)
UINT32 maxCount, // IN: maximum allowed return values
TPML_ACT_DATA* actList // OUT: ACT data list
)
{
// Initialize output property list
actList->count = 0;
// Make sure that the starting handle value is in range (again)
if((actHandle < TPM_RH_ACT_0) || (actHandle > TPM_RH_ACT_F))
return FALSE;
return FALSE;
// The maximum count of curves we may return is MAX_ECC_CURVES
if(maxCount > MAX_ACT_DATA)
maxCount = MAX_ACT_DATA;
// Scan the ACT data from the starting ACT
for(; actHandle <= TPM_RH_ACT_F; actHandle++)
{
UINT32 act = actHandle - TPM_RH_ACT_0;
if(actList->count < maxCount)
{
if(ActIsImplemented(act))
{
TPMS_ACT_DATA* actData = &actList->actData[actList->count];
//
memset(&actData->attributes, 0, sizeof(actData->attributes));
actData->handle = actHandle;
actData->timeout = _plat__ACT_GetRemaining(act);
if(_plat__ACT_GetSignaled(act))
SET_ATTRIBUTE(actData->attributes, TPMA_ACT, signaled);
else
CLEAR_ATTRIBUTE(actData->attributes, TPMA_ACT, signaled);
{
UINT32 act = actHandle - TPM_RH_ACT_0;
if(actList->count < maxCount)
{
if(ActIsImplemented(act))
{
TPMS_ACT_DATA* actData = &actList->actData[actList->count];
//
memset(&actData->attributes, 0, sizeof(actData->attributes));
actData->handle = actHandle;
actData->timeout = _plat__ACT_GetRemaining(act);
if(_plat__ACT_GetSignaled(act))
SET_ATTRIBUTE(actData->attributes, TPMA_ACT, signaled);
else
CLEAR_ATTRIBUTE(actData->attributes, TPMA_ACT, signaled);
#ifndef __ACT_DISABLED // libtpms added
if(go.preservedSignaled & (1 << act))
SET_ATTRIBUTE(actData->attributes, TPMA_ACT, preserveSignaled);
if(go.preservedSignaled & (1 << act))
SET_ATTRIBUTE(actData->attributes, TPMA_ACT, preserveSignaled);
#endif // libtpms added
actList->count++;
}
}
else
{
if(_plat__ACT_GetImplemented(act))
return YES;
}
}
actList->count++;
}
}
else
{
if(_plat__ACT_GetImplemented(act))
return YES;
}
}
// If we get here, either all of the ACT values were put in the list, or the list
// was filled and there are no more ACT values to return
return NO;
@ -312,24 +312,24 @@ ActGetCapabilityData(TPM_HANDLE actHandle, // IN: the handle for the starti
//*** ActGetOneCapability()
// This function returns an ACT's capability, if present.
BOOL ActGetOneCapability(TPM_HANDLE actHandle, // IN: the handle for the ACT
TPMS_ACT_DATA* actData // OUT: ACT data
)
TPMS_ACT_DATA* actData // OUT: ACT data
)
{
UINT32 act = actHandle - TPM_RH_ACT_0;
if(ActIsImplemented(actHandle - TPM_RH_ACT_0))
{
memset(&actData->attributes, 0, sizeof(actData->attributes));
actData->handle = actHandle;
actData->timeout = _plat__ACT_GetRemaining(act);
if(_plat__ACT_GetSignaled(act))
SET_ATTRIBUTE(actData->attributes, TPMA_ACT, signaled);
else
CLEAR_ATTRIBUTE(actData->attributes, TPMA_ACT, signaled);
if(go.preservedSignaled & (1 << act))
SET_ATTRIBUTE(actData->attributes, TPMA_ACT, preserveSignaled);
return TRUE;
}
{
memset(&actData->attributes, 0, sizeof(actData->attributes));
actData->handle = actHandle;
actData->timeout = _plat__ACT_GetRemaining(act);
if(_plat__ACT_GetSignaled(act))
SET_ATTRIBUTE(actData->attributes, TPMA_ACT, signaled);
else
CLEAR_ATTRIBUTE(actData->attributes, TPMA_ACT, signaled);
if(go.preservedSignaled & (1 << act))
SET_ATTRIBUTE(actData->attributes, TPMA_ACT, preserveSignaled);
return TRUE;
}
return FALSE;
}
#endif // libtpms: added

View File

@ -77,7 +77,7 @@ BOOL ActGetSignaled(TPM_RH actHandle);
//***ActShutdown()
// This function saves the current state of the counters
BOOL ActShutdown(TPM_SU state //IN: the type of the shutdown.
);
);
//*** ActIsImplemented()
// This function determines if an ACT is implemented in both the TPM and the platform
@ -89,8 +89,8 @@ BOOL ActIsImplemented(UINT32 act);
// it returns TPM_RC_RETRY so that the update can be tried again later.
TPM_RC
ActCounterUpdate(TPM_RH handle, //IN: the handle of the act
UINT32 newValue //IN: the value to set in the ACT
);
UINT32 newValue //IN: the value to set in the ACT
);
//*** ActGetCapabilityData()
// This function returns the list of ACT data
@ -99,14 +99,14 @@ ActCounterUpdate(TPM_RH handle, //IN: the handle of the act
// NO if no more ACT data to
TPMI_YES_NO
ActGetCapabilityData(TPM_HANDLE actHandle, // IN: the handle for the starting ACT
UINT32 maxCount, // IN: maximum allowed return values
TPML_ACT_DATA* actList // OUT: ACT data list
);
UINT32 maxCount, // IN: maximum allowed return values
TPML_ACT_DATA* actList // OUT: ACT data list
);
//*** ActGetOneCapability()
// This function returns an ACT's capability, if present.
BOOL ActGetOneCapability(TPM_HANDLE actHandle, // IN: the handle for the ACT
TPMS_ACT_DATA* actData // OUT: ACT data
);
TPMS_ACT_DATA* actData // OUT: ACT data
);
#endif // _ACT_SPT_FP_H_

View File

@ -59,30 +59,38 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef ACTIVATECREDENTIAL_FP_H
#define ACTIVATECREDENTIAL_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_DH_OBJECT activateHandle;
TPMI_DH_OBJECT keyHandle;
TPM2B_ID_OBJECT credentialBlob;
TPM2B_ENCRYPTED_SECRET secret;
#if CC_ActivateCredential // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_ACTIVATECREDENTIAL_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_ACTIVATECREDENTIAL_FP_H_
// Input structure definition
typedef struct
{
TPMI_DH_OBJECT activateHandle;
TPMI_DH_OBJECT keyHandle;
TPM2B_ID_OBJECT credentialBlob;
TPM2B_ENCRYPTED_SECRET secret;
} ActivateCredential_In;
#define RC_ActivateCredential_activateHandle (TPM_RC_H + TPM_RC_1)
#define RC_ActivateCredential_keyHandle (TPM_RC_H + TPM_RC_2)
#define RC_ActivateCredential_credentialBlob (TPM_RC_P + TPM_RC_1)
#define RC_ActivateCredential_secret (TPM_RC_P + TPM_RC_2)
typedef struct {
TPM2B_DIGEST certInfo;
// Output structure definition
typedef struct
{
TPM2B_DIGEST certInfo;
} ActivateCredential_Out;
// Response code modifiers
# define RC_ActivateCredential_activateHandle (TPM_RC_H + TPM_RC_1)
# define RC_ActivateCredential_keyHandle (TPM_RC_H + TPM_RC_2)
# define RC_ActivateCredential_credentialBlob (TPM_RC_P + TPM_RC_1)
# define RC_ActivateCredential_secret (TPM_RC_P + TPM_RC_2)
// Function prototype
TPM_RC
TPM2_ActivateCredential(
ActivateCredential_In *in, // IN: input parameter list
ActivateCredential_Out *out // OUT: output parameter list
);
#endif
TPM2_ActivateCredential(ActivateCredential_In* in, ActivateCredential_Out* out);
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_ACTIVATECREDENTIAL_FP_H_
#endif // CC_ActivateCredential

View File

@ -58,170 +58,188 @@
/* */
/********************************************************************************/
/* 9.1 AlgorithmCap.c */
/* 9.1.1 Description */
/* This file contains the algorithm property definitions for the algorithms and the code for the
TPM2_GetCapability() to return the algorithm properties. */
/* 9.1.2 Includes and Defines */
//** Description
// This file contains the algorithm property definitions for the algorithms and the
// code for the TPM2_GetCapability() to return the algorithm properties.
//** Includes and Defines
#include "Tpm.h"
typedef struct
{
TPM_ALG_ID algID;
TPMA_ALGORITHM attributes;
TPM_ALG_ID algID;
TPMA_ALGORITHM attributes;
} ALGORITHM;
static const ALGORITHM s_algorithms[] =
{
// The entries in this table need to be in ascending order but the table doesn't
// need to be full (gaps are allowed). One day, a tool might exist to fill in the
// table from the TPM_ALG description
static const ALGORITHM s_algorithms[] = {
// The entries in this table need to be in ascending order but the table doesn't
// need to be full (gaps are allowed). One day, a tool might exist to fill in the
// table from the TPM_ALG description
#if ALG_RSA
{TPM_ALG_RSA, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 1, 0, 0, 0, 0, 0)},
{TPM_ALG_RSA, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 1, 0, 0, 0, 0, 0)},
#endif
#if ALG_TDES
#if ALG_TDES // libtpms added begin
{TPM_ALG_TDES, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 0, 0, 0, 0)},
#endif
#endif // libtpms added end
#if ALG_SHA1
{TPM_ALG_SHA1, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 0, 0)},
{TPM_ALG_SHA1, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 0, 0)},
#endif
{TPM_ALG_HMAC, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 1, 0, 0, 0)},
{TPM_ALG_HMAC, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 1, 0, 0, 0)},
#if ALG_AES
{TPM_ALG_AES, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 0, 0, 0, 0)},
{TPM_ALG_AES, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 0, 0, 0, 0)},
#endif
#if ALG_MGF1
{TPM_ALG_MGF1, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 1, 0)},
{TPM_ALG_MGF1, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 1, 0)},
#endif
{TPM_ALG_KEYEDHASH, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 1, 0, 1, 1, 0, 0)},
{TPM_ALG_KEYEDHASH, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 1, 0, 1, 1, 0, 0)},
#if ALG_XOR
{TPM_ALG_XOR, TPMA_ALGORITHM_INITIALIZER(0, 1, 1, 0, 0, 0, 0, 0, 0)},
{TPM_ALG_XOR, TPMA_ALGORITHM_INITIALIZER(0, 1, 1, 0, 0, 0, 0, 0, 0)},
#endif
#if ALG_SHA256
{TPM_ALG_SHA256, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 0, 0)},
{TPM_ALG_SHA256, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 0, 0)},
#endif
#if ALG_SHA384
{TPM_ALG_SHA384, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 0, 0)},
{TPM_ALG_SHA384, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 0, 0)},
#endif
#if ALG_SHA512
{TPM_ALG_SHA512, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 0, 0)},
{TPM_ALG_SHA512, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 0, 0)},
#endif
#if ALG_SM3_256
{TPM_ALG_SM3_256, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 0, 0)},
{TPM_ALG_SM3_256, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 0, 0)},
#endif
#if ALG_SM4
{TPM_ALG_SM4, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 0, 0, 0, 0)},
{TPM_ALG_SM4, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 0, 0, 0, 0)},
#endif
#if ALG_RSASSA
{TPM_ALG_RSASSA, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 1, 0, 0, 0)},
{TPM_ALG_RSASSA, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 1, 0, 0, 0)},
#endif
#if ALG_RSAES
{TPM_ALG_RSAES, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 0, 1, 0, 0)},
{TPM_ALG_RSAES, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 0, 1, 0, 0)},
#endif
#if ALG_RSAPSS
{TPM_ALG_RSAPSS, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 1, 0, 0, 0)},
{TPM_ALG_RSAPSS, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 1, 0, 0, 0)},
#endif
#if ALG_OAEP
{TPM_ALG_OAEP, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 0, 1, 0, 0)},
{TPM_ALG_OAEP, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 0, 1, 0, 0)},
#endif
#if ALG_ECDSA
{TPM_ALG_ECDSA, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 1, 0, 0, 0)},
{TPM_ALG_ECDSA, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 1, 0, 0, 0)},
#endif
#if ALG_ECDH
{TPM_ALG_ECDH, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 0, 0, 1, 0)},
{TPM_ALG_ECDH, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 0, 0, 1, 0)},
#endif
#if ALG_ECDAA
{TPM_ALG_ECDAA, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 1, 0, 0, 0)},
{TPM_ALG_ECDAA, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 1, 0, 0, 0)},
#endif
#if ALG_SM2
{TPM_ALG_SM2, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 1, 0, 1, 0)},
{TPM_ALG_SM2, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 1, 0, 1, 0)},
#endif
#if ALG_ECSCHNORR
{TPM_ALG_ECSCHNORR, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 1, 0, 0, 0)},
{TPM_ALG_ECSCHNORR, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 1, 0, 0, 0)},
#endif
#if ALG_ECMQV
{TPM_ALG_ECMQV, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 0, 0, 1, 0)},
{TPM_ALG_ECMQV, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 0, 0, 0, 0, 1, 0)},
#endif
#if ALG_KDF1_SP800_56A
{TPM_ALG_KDF1_SP800_56A, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 1, 0)},
{TPM_ALG_KDF1_SP800_56A, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 1, 0)},
#endif
#if ALG_KDF2
{TPM_ALG_KDF2, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 1, 0)},
{TPM_ALG_KDF2, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 1, 0)},
#endif
#if ALG_KDF1_SP800_108
{TPM_ALG_KDF1_SP800_108, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 1, 0)},
{TPM_ALG_KDF1_SP800_108, TPMA_ALGORITHM_INITIALIZER(0, 0, 1, 0, 0, 0, 0, 1, 0)},
#endif
#if ALG_ECC
{TPM_ALG_ECC, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 1, 0, 0, 0, 0, 0)},
{TPM_ALG_ECC, TPMA_ALGORITHM_INITIALIZER(1, 0, 0, 1, 0, 0, 0, 0, 0)},
#endif
{TPM_ALG_SYMCIPHER, TPMA_ALGORITHM_INITIALIZER(0, 0, 0, 1, 0, 0, 0, 0, 0)},
{TPM_ALG_SYMCIPHER, TPMA_ALGORITHM_INITIALIZER(0, 0, 0, 1, 0, 0, 0, 0, 0)},
#if ALG_CAMELLIA
{TPM_ALG_CAMELLIA, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 0, 0, 0, 0)},
{TPM_ALG_CAMELLIA, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 0, 0, 0, 0)},
#endif
#if ALG_CMAC
{TPM_ALG_CMAC, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 1, 0, 0, 0)},
{TPM_ALG_CMAC, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 1, 0, 0, 0)},
#endif
#if ALG_CTR
{TPM_ALG_CTR, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 0, 1, 0, 0)},
{TPM_ALG_CTR, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 0, 1, 0, 0)},
#endif
#if ALG_OFB
{TPM_ALG_OFB, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 0, 1, 0, 0)},
{TPM_ALG_OFB, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 0, 1, 0, 0)},
#endif
#if ALG_CBC
{TPM_ALG_CBC, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 0, 1, 0, 0)},
{TPM_ALG_CBC, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 0, 1, 0, 0)},
#endif
#if ALG_CFB
{TPM_ALG_CFB, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 0, 1, 0, 0)},
{TPM_ALG_CFB, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 0, 1, 0, 0)},
#endif
#if ALG_ECB
{TPM_ALG_ECB, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 0, 1, 0, 0)},
{TPM_ALG_ECB, TPMA_ALGORITHM_INITIALIZER(0, 1, 0, 0, 0, 0, 1, 0, 0)},
#endif
};
/* 9.1.3 AlgorithmCapGetImplemented() */
/* This function is used by TPM2_GetCapability() to return a list of the implemented algorithms. */
/* Return Values Meaning */
/* YES more algorithms to report */
/* NO no more algorithms to report */
};
//** AlgorithmCapGetImplemented()
// This function is used by TPM2_GetCapability() to return a list of the
// implemented algorithms.
//
// Return Type: TPMI_YES_NO
// YES more algorithms to report
// NO no more algorithms to report
TPMI_YES_NO
AlgorithmCapGetImplemented(
TPM_ALG_ID algID, // IN: the starting algorithm ID
UINT32 count, // IN: count of returned algorithms
TPML_ALG_PROPERTY *algList // OUT: algorithm list
)
AlgorithmCapGetImplemented(TPM_ALG_ID algID, // IN: the starting algorithm ID
UINT32 count, // IN: count of returned algorithms
TPML_ALG_PROPERTY* algList // OUT: algorithm list
)
{
TPMI_YES_NO more = NO;
UINT32 i;
UINT32 algNum;
TPMI_YES_NO more = NO;
UINT32 i;
UINT32 algNum;
// initialize output algorithm list
algList->count = 0;
// The maximum count of algorithms we may return is MAX_CAP_ALGS.
if(count > MAX_CAP_ALGS)
count = MAX_CAP_ALGS;
count = MAX_CAP_ALGS;
// Compute how many algorithms are defined in s_algorithms array.
algNum = sizeof(s_algorithms) / sizeof(s_algorithms[0]);
// Scan the implemented algorithm list to see if there is a match to 'algID'.
for(i = 0; i < algNum; i++)
{
// If algID is less than the starting algorithm ID, skip it
if(s_algorithms[i].algID < algID)
continue;
if(!RuntimeAlgorithmCheckEnabled(&g_RuntimeProfile.RuntimeAlgorithm,// libtpms added begin
s_algorithms[i].algID))
continue; // libtpms added end
if(algList->count < count)
{
// If we have not filled up the return list, add more algorithms
// to it
algList->algProperties[algList->count].alg = s_algorithms[i].algID;
algList->algProperties[algList->count].algProperties =
s_algorithms[i].attributes;
algList->count++;
}
else
{
// If the return list is full but we still have algorithms
// available, report this and stop scanning.
more = YES;
break;
}
}
{
// If algID is less than the starting algorithm ID, skip it
if(s_algorithms[i].algID < algID)
continue;
if(!RuntimeAlgorithmCheckEnabled(&g_RuntimeProfile.RuntimeAlgorithm,// libtpms added begin
s_algorithms[i].algID))
continue; // libtpms added end
if(algList->count < count)
{
// If we have not filled up the return list, add more algorithms
// to it
algList->algProperties[algList->count].alg = s_algorithms[i].algID;
algList->algProperties[algList->count].algProperties =
s_algorithms[i].attributes;
algList->count++;
}
else
{
// If the return list is full but we still have algorithms
// available, report this and stop scanning.
more = YES;
break;
}
}
return more;
}
@ -229,9 +247,9 @@ AlgorithmCapGetImplemented(
// This function returns whether a single algorithm was implemented, along
// with its properties (if implemented).
BOOL AlgorithmCapGetOneImplemented(
TPM_ALG_ID algID, // IN: the algorithm ID
TPMS_ALG_PROPERTY* algProperty // OUT: algorithm properties
)
TPM_ALG_ID algID, // IN: the algorithm ID
TPMS_ALG_PROPERTY* algProperty // OUT: algorithm properties
)
{
UINT32 i;
UINT32 algNum;
@ -244,39 +262,37 @@ BOOL AlgorithmCapGetOneImplemented(
// Scan the implemented algorithm list to see if there is a match to 'algID'.
for(i = 0; i < algNum; i++)
{
// If algID is less than the starting algorithm ID, skip it
if(s_algorithms[i].algID == algID)
{
algProperty->alg = algID;
algProperty->algProperties = s_algorithms[i].attributes;
return TRUE;
}
}
{
// If algID is less than the starting algorithm ID, skip it
if(s_algorithms[i].algID == algID)
{
algProperty->alg = algID;
algProperty->algProperties = s_algorithms[i].attributes;
return TRUE;
}
}
return FALSE;
}
/* 9.1.4 AlgorithmGetImplementedVector()
This function returns the bit vector of the implemented algorithms.
*/
//** AlgorithmGetImplementedVector()
// This function returns the bit vector of the implemented algorithms.
LIB_EXPORT
void
AlgorithmGetImplementedVector(
ALGORITHM_VECTOR *implemented // OUT: the implemented bits are SET
)
void AlgorithmGetImplementedVector(
ALGORITHM_VECTOR* implemented // OUT: the implemented bits are SET
)
{
int index;
int index;
// Nothing implemented until we say it is
MemorySet(implemented, 0, sizeof(ALGORITHM_VECTOR));
// Go through the list of implemented algorithms and SET the corresponding bit in
// in the implemented vector
for(index = (sizeof(s_algorithms) / sizeof(s_algorithms[0])) - 1;
index >= 0; index--) { // libtpms changed
if (RuntimeAlgorithmCheckEnabled(&g_RuntimeProfile.RuntimeAlgorithm, // libtpms added begin
s_algorithms[index].algID))
SET_BIT(s_algorithms[index].algID, *implemented);
for(index = (sizeof(s_algorithms) / sizeof(s_algorithms[0])) - 1; index >= 0;
index--) { // libtpms changed
if (RuntimeAlgorithmCheckEnabled(&g_RuntimeProfile.RuntimeAlgorithm, // libtpms added begin
s_algorithms[index].algID))
SET_BIT(s_algorithms[index].algID, *implemented);
} // libtpms added end
return;
}

View File

@ -58,28 +58,40 @@
/* */
/********************************************************************************/
#ifndef ALGORITHMCAP_FP_H
#define ALGORITHMCAP_FP_H
/*(Auto-generated)
* Created by TpmPrototypes; Version 3.0 July 18, 2017
* Date: Mar 28, 2019 Time: 08:25:19PM
*/
#ifndef _ALGORITHM_CAP_FP_H_
#define _ALGORITHM_CAP_FP_H_
//** AlgorithmCapGetImplemented()
// This function is used by TPM2_GetCapability() to return a list of the
// implemented algorithms.
//
// Return Type: TPMI_YES_NO
// YES more algorithms to report
// NO no more algorithms to report
TPMI_YES_NO
AlgorithmCapGetImplemented(
TPM_ALG_ID algID, // IN: the starting algorithm ID
UINT32 count, // IN: count of returned algorithms
TPML_ALG_PROPERTY *algList // OUT: algorithm list
);
AlgorithmCapGetImplemented(TPM_ALG_ID algID, // IN: the starting algorithm ID
UINT32 count, // IN: count of returned algorithms
TPML_ALG_PROPERTY* algList // OUT: algorithm list
);
//** AlgorithmCapGetOneImplemented()
// This function returns whether a single algorithm was implemented, along
// with its properties (if implemented).
BOOL AlgorithmCapGetOneImplemented(
TPM_ALG_ID algID, // IN: the algorithm ID
TPMS_ALG_PROPERTY* algProperty // OUT: algorithm properties
);
TPM_ALG_ID algID, // IN: the algorithm ID
TPMS_ALG_PROPERTY* algProperty // OUT: algorithm properties
);
//** AlgorithmGetImplementedVector()
// This function returns the bit vector of the implemented algorithms.
LIB_EXPORT
void
AlgorithmGetImplementedVector(
ALGORITHM_VECTOR *implemented // OUT: the implemented bits are SET
);
void AlgorithmGetImplementedVector(
ALGORITHM_VECTOR* implemented // OUT: the implemented bits are SET
);
#endif
#endif // _ALGORITHM_CAP_FP_H_

File diff suppressed because it is too large Load Diff

View File

@ -58,17 +58,38 @@
/* */
/********************************************************************************/
#ifndef ALGORITHMTESTS_FP_H
#define ALGORITHMTESTS_FP_H
/*(Auto-generated)
* Created by TpmPrototypes; Version 3.0 July 18, 2017
* Date: Mar 4, 2020 Time: 02:36:44PM
*/
#ifndef _ALGORITHM_TESTS_FP_H_
#define _ALGORITHM_TESTS_FP_H_
#if ENABLE_SELF_TESTS
//*** TestAlgorithm()
// Dispatches to the correct test function for the algorithm or gets a list of
// testable algorithms.
//
// If 'toTest' is not NULL, then the test decisions are based on the algorithm
// selections in 'toTest'. Otherwise, 'g_toTest' is used. When bits are clear in
// 'g_toTest' they will also be cleared 'toTest'.
//
// If there doesn't happen to be a test for the algorithm, its associated bit is
// quietly cleared.
//
// If 'alg' is zero (TPM_ALG_ERROR), then the toTest vector is cleared of any bits
// for which there is no test (i.e. no tests are actually run but the vector is
// cleared).
//
// Note: 'toTest' will only ever have bits set for implemented algorithms but 'alg'
// can be anything.
// Return Type: TPM_RC
// TPM_RC_CANCELED test was canceled
LIB_EXPORT
TPM_RC
TestAlgorithm(
TPM_ALG_ID alg,
ALGORITHM_VECTOR *toTest
);
TestAlgorithm(TPM_ALG_ID alg, ALGORITHM_VECTOR* toTest);
#endif // ENABLE_SELF_TESTS
#endif // ALGORITHMTESTS_FP_H
#endif // _ALGORITHM_TESTS_FP_H_

View File

@ -59,151 +59,172 @@
/* */
/********************************************************************************/
//** Includes
#include "Tpm.h"
#include "Attest_spt_fp.h"
/* 7.2.2 Functions */
/* 7.2.2.1 FillInAttestInfo() */
/* Fill in common fields of TPMS_ATTEST structure. */
void
FillInAttestInfo(
TPMI_DH_OBJECT signHandle, // IN: handle of signing object
TPMT_SIG_SCHEME *scheme, // IN/OUT: scheme to be used for signing
TPM2B_DATA *data, // IN: qualifying data
TPMS_ATTEST *attest // OUT: attest structure
)
#include "Marshal.h"
//** Functions
//***FillInAttestInfo()
// Fill in common fields of TPMS_ATTEST structure.
void FillInAttestInfo(
TPMI_DH_OBJECT signHandle, // IN: handle of signing object
TPMT_SIG_SCHEME* scheme, // IN/OUT: scheme to be used for signing
TPM2B_DATA* data, // IN: qualifying data
TPMS_ATTEST* attest // OUT: attest structure
)
{
OBJECT *signObject = HandleToObject(signHandle);
OBJECT* signObject = HandleToObject(signHandle);
// Magic number
attest->magic = TPM_GENERATED_VALUE;
if(signObject == NULL)
{
// The name for a null handle is TPM_RH_NULL
// This is defined because UINT32_TO_BYTE_ARRAY does a cast. If the
// size of the cast is smaller than a constant, the compiler warns
// about the truncation of a constant value.
TPM_HANDLE nullHandle = TPM_RH_NULL;
attest->qualifiedSigner.t.size = sizeof(TPM_HANDLE);
UINT32_TO_BYTE_ARRAY(nullHandle, attest->qualifiedSigner.t.name);
}
{
// The name for a null handle is TPM_RH_NULL
// This is defined because UINT32_TO_BYTE_ARRAY does a cast. If the
// size of the cast is smaller than a constant, the compiler warns
// about the truncation of a constant value.
TPM_HANDLE nullHandle = TPM_RH_NULL;
attest->qualifiedSigner.t.size = sizeof(TPM_HANDLE);
UINT32_TO_BYTE_ARRAY(nullHandle, attest->qualifiedSigner.t.name);
}
else
{
// Certifying object qualified name
// if the scheme is anonymous, this is an empty buffer
if(CryptIsSchemeAnonymous(scheme->scheme))
attest->qualifiedSigner.t.size = 0;
else
attest->qualifiedSigner = signObject->qualifiedName;
}
{
// Certifying object qualified name
// if the scheme is anonymous, this is an empty buffer
if(CryptIsSchemeAnonymous(scheme->scheme))
attest->qualifiedSigner.t.size = 0;
else
attest->qualifiedSigner = signObject->qualifiedName;
}
// current clock in plain text
TimeFillInfo(&attest->clockInfo);
// Firmware version in plain text
attest->firmwareVersion = ((UINT64)gp.firmwareV1 << (sizeof(UINT32) * 8));
attest->firmwareVersion += gp.firmwareV2;
// Check the hierarchy of sign object. For NULL sign handle, the hierarchy
// will be TPM_RH_NULL
if((signObject == NULL)
|| (!signObject->attributes.epsHierarchy
&& !signObject->attributes.ppsHierarchy))
{
// For signing key that is not in platform or endorsement hierarchy,
// obfuscate the reset, restart and firmware version information
UINT64 obfuscation[2];
CryptKDFa(CONTEXT_INTEGRITY_HASH_ALG, &gp.shProof.b, OBFUSCATE_STRING,
&attest->qualifiedSigner.b, NULL, 128,
(BYTE *)&obfuscation[0], NULL, FALSE);
// Obfuscate data
attest->firmwareVersion += obfuscation[0];
attest->clockInfo.resetCount += (UINT32)(obfuscation[1] >> 32);
attest->clockInfo.restartCount += (UINT32)obfuscation[1];
}
&& !signObject->attributes.ppsHierarchy))
{
// For signing key that is not in platform or endorsement hierarchy,
// obfuscate the reset, restart and firmware version information
UINT64 obfuscation[2];
CryptKDFa(CONTEXT_INTEGRITY_HASH_ALG,
&gp.shProof.b,
OBFUSCATE_STRING,
&attest->qualifiedSigner.b,
NULL,
128,
(BYTE*)&obfuscation[0],
NULL,
FALSE);
// Obfuscate data
attest->firmwareVersion += obfuscation[0];
attest->clockInfo.resetCount += (UINT32)(obfuscation[1] >> 32);
attest->clockInfo.restartCount += (UINT32)obfuscation[1];
}
// External data
if(CryptIsSchemeAnonymous(scheme->scheme))
attest->extraData.t.size = 0;
attest->extraData.t.size = 0;
else
{
// If we move the data to the attestation structure, then it is not
// used in the signing operation except as part of the signed data
attest->extraData = *data;
data->t.size = 0;
}
}
/* 7.2.2.2 SignAttestInfo() */
/* Sign a TPMS_ATTEST structure. If signHandle is TPM_RH_NULL, a null signature is returned. */
/* Error Returns Meaning */
/* TPM_RC_ATTRIBUTES signHandle references not a signing key */
/* TPM_RC_SCHEME scheme is not compatible with signHandle type */
/* TPM_RC_VALUE digest generated for the given scheme is greater than the modulus of signHandle (for
an RSA key); invalid commit status or failed to generate r value (for an ECC key) */
TPM_RC
SignAttestInfo(
OBJECT *signKey, // IN: sign object
TPMT_SIG_SCHEME *scheme, // IN: sign scheme
TPMS_ATTEST *certifyInfo, // IN: the data to be signed
TPM2B_DATA *qualifyingData, // IN: extra data for the signing
// process
TPM2B_ATTEST *attest, // OUT: marshaled attest blob to be
// signed
TPMT_SIGNATURE *signature // OUT: signature
)
{
BYTE *buffer;
HASH_STATE hashState;
TPM2B_DIGEST digest;
TPM_RC result;
// Marshal TPMS_ATTEST structure for hash
buffer = attest->t.attestationData;
attest->t.size = TPMS_ATTEST_Marshal(certifyInfo, &buffer, NULL);
if(signKey == NULL)
{
signature->sigAlg = TPM_ALG_NULL;
result = TPM_RC_SUCCESS;
}
else
{
TPMI_ALG_HASH hashAlg;
// Compute hash
hashAlg = scheme->details.any.hashAlg;
// need to set the receive buffer to get something put in it
digest.t.size = sizeof(digest.t.buffer);
digest.t.size = CryptHashBlock(hashAlg, attest->t.size,
attest->t.attestationData,
digest.t.size, digest.t.buffer);
// If there is qualifying data, need to rehash the data
// hash(qualifyingData || hash(attestationData))
if(qualifyingData->t.size != 0)
{
CryptHashStart(&hashState, hashAlg);
CryptDigestUpdate2B(&hashState, &qualifyingData->b);
CryptDigestUpdate2B(&hashState, &digest.b);
CryptHashEnd2B(&hashState, &digest.b);
}
// Sign the hash. A TPM_RC_VALUE, TPM_RC_SCHEME, or
// TPM_RC_ATTRIBUTES error may be returned at this point
result = CryptSign(signKey, scheme, &digest, signature);
// Since the clock is used in an attestation, the state in NV is no longer
// "orderly" with respect to the data in RAM if the signature is valid
if(result == TPM_RC_SUCCESS)
{
// Command uses the clock so need to clear the orderly state if it is
// set.
result = NvClearOrderly();
}
}
return result;
}
/* 7.2.2.3 IsSigningObject() */
/* Checks to see if the object is OK for signing. This is here rather than in Object_spt.c because
all the attestation commands use this file but not Object_spt.c. */
/* Return Values Meaning */
/* TRUE object may sign */
/* FALSE object may not sign */
BOOL
IsSigningObject(
OBJECT *object // IN:
)
{
return ((object == NULL)
|| ((IS_ATTRIBUTE(object->publicArea.objectAttributes, TPMA_OBJECT, sign)
&& object->publicArea.type != TPM_ALG_SYMCIPHER)));
{
// If we move the data to the attestation structure, then it is not
// used in the signing operation except as part of the signed data
attest->extraData = *data;
data->t.size = 0;
}
}
//***SignAttestInfo()
// Sign a TPMS_ATTEST structure. If signHandle is TPM_RH_NULL, a null signature
// is returned.
//
// Return Type: TPM_RC
// TPM_RC_ATTRIBUTES 'signHandle' references not a signing key
// TPM_RC_SCHEME 'scheme' is not compatible with 'signHandle' type
// TPM_RC_VALUE digest generated for the given 'scheme' is greater than
// the modulus of 'signHandle' (for an RSA key);
// invalid commit status or failed to generate "r" value
// (for an ECC key)
TPM_RC
SignAttestInfo(OBJECT* signKey, // IN: sign object
TPMT_SIG_SCHEME* scheme, // IN: sign scheme
TPMS_ATTEST* certifyInfo, // IN: the data to be signed
TPM2B_DATA* qualifyingData, // IN: extra data for the signing
// process
TPM2B_ATTEST* attest, // OUT: marshaled attest blob to be
// signed
TPMT_SIGNATURE* signature // OUT: signature
)
{
BYTE* buffer;
HASH_STATE hashState;
TPM2B_DIGEST digest;
TPM_RC result;
// Marshal TPMS_ATTEST structure for hash
buffer = attest->t.attestationData;
attest->t.size = TPMS_ATTEST_Marshal(certifyInfo, &buffer, NULL);
if(signKey == NULL)
{
signature->sigAlg = TPM_ALG_NULL;
result = TPM_RC_SUCCESS;
}
else
{
TPMI_ALG_HASH hashAlg;
// Compute hash
hashAlg = scheme->details.any.hashAlg;
// need to set the receive buffer to get something put in it
digest.t.size = sizeof(digest.t.buffer);
digest.t.size = CryptHashBlock(hashAlg,
attest->t.size,
attest->t.attestationData,
digest.t.size,
digest.t.buffer);
// If there is qualifying data, need to rehash the data
// hash(qualifyingData || hash(attestationData))
if(qualifyingData->t.size != 0)
{
CryptHashStart(&hashState, hashAlg);
CryptDigestUpdate2B(&hashState, &qualifyingData->b);
CryptDigestUpdate2B(&hashState, &digest.b);
CryptHashEnd2B(&hashState, &digest.b);
}
// Sign the hash. A TPM_RC_VALUE, TPM_RC_SCHEME, or
// TPM_RC_ATTRIBUTES error may be returned at this point
result = CryptSign(signKey, scheme, &digest, signature);
// Since the clock is used in an attestation, the state in NV is no longer
// "orderly" with respect to the data in RAM if the signature is valid
if(result == TPM_RC_SUCCESS)
{
// Command uses the clock so need to clear the orderly state if it is
// set.
result = NvClearOrderly();
}
}
return result;
}
//*** IsSigningObject()
// Checks to see if the object is OK for signing. This is here rather than in
// Object_spt.c because all the attestation commands use this file but not
// Object_spt.c.
// Return Type: BOOL
// TRUE(1) object may sign
// FALSE(0) object may not sign
BOOL IsSigningObject(OBJECT* object // IN:
)
{
return ((object == NULL)
|| ((IS_ATTRIBUTE(object->publicArea.objectAttributes, TPMA_OBJECT, sign)
&& object->publicArea.type != TPM_ALG_SYMCIPHER)));
}

View File

@ -59,34 +59,53 @@
/* */
/********************************************************************************/
#ifndef ATTEST_SPT_FP_H
#define ATTEST_SPT_FP_H
/*(Auto-generated)
* Created by TpmPrototypes; Version 3.0 July 18, 2017
* Date: Mar 28, 2019 Time: 08:25:18PM
*/
void
FillInAttestInfo(
TPMI_DH_OBJECT signHandle, // IN: handle of signing object
TPMT_SIG_SCHEME *scheme, // IN/OUT: scheme to be used for signing
TPM2B_DATA *data, // IN: qualifying data
TPMS_ATTEST *attest // OUT: attest structure
);
#ifndef _ATTEST_SPT_FP_H_
#define _ATTEST_SPT_FP_H_
//***FillInAttestInfo()
// Fill in common fields of TPMS_ATTEST structure.
void FillInAttestInfo(
TPMI_DH_OBJECT signHandle, // IN: handle of signing object
TPMT_SIG_SCHEME* scheme, // IN/OUT: scheme to be used for signing
TPM2B_DATA* data, // IN: qualifying data
TPMS_ATTEST* attest // OUT: attest structure
);
//***SignAttestInfo()
// Sign a TPMS_ATTEST structure. If signHandle is TPM_RH_NULL, a null signature
// is returned.
//
// Return Type: TPM_RC
// TPM_RC_ATTRIBUTES 'signHandle' references not a signing key
// TPM_RC_SCHEME 'scheme' is not compatible with 'signHandle' type
// TPM_RC_VALUE digest generated for the given 'scheme' is greater than
// the modulus of 'signHandle' (for an RSA key);
// invalid commit status or failed to generate "r" value
// (for an ECC key)
TPM_RC
SignAttestInfo(
OBJECT *signKey, // IN: sign object
TPMT_SIG_SCHEME *scheme, // IN: sign scheme
TPMS_ATTEST *certifyInfo, // IN: the data to be signed
TPM2B_DATA *qualifyingData, // IN: extra data for the signing
// process
TPM2B_ATTEST *attest, // OUT: marshaled attest blob to be
// signed
TPMT_SIGNATURE *signature // OUT: signature
);
BOOL
IsSigningObject(
OBJECT *object // IN:
);
SignAttestInfo(OBJECT* signKey, // IN: sign object
TPMT_SIG_SCHEME* scheme, // IN: sign scheme
TPMS_ATTEST* certifyInfo, // IN: the data to be signed
TPM2B_DATA* qualifyingData, // IN: extra data for the signing
// process
TPM2B_ATTEST* attest, // OUT: marshaled attest blob to be
// signed
TPMT_SIGNATURE* signature // OUT: signature
);
//*** IsSigningObject()
// Checks to see if the object is OK for signing. This is here rather than in
// Object_spt.c because all the attestation commands use this file but not
// Object_spt.c.
// Return Type: BOOL
// TRUE(1) object may sign
// FALSE(0) object may not sign
BOOL IsSigningObject(OBJECT* object // IN:
);
#endif
#endif // _ATTEST_SPT_FP_H_

View File

@ -59,27 +59,26 @@
/* */
/********************************************************************************/
/* 5.2 BaseTypes.h */
#ifndef BASETYPES_H
#define BASETYPES_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
#include <stdint.h>
#ifndef _TPM_INCLUDE_PUBLIC_BASETYPES_H_
#define _TPM_INCLUDE_PUBLIC_BASETYPES_H_
/* NULL definition */
// NULL definition
#ifndef NULL
# define NULL (0)
#endif // NULL
#ifndef NULL
#define NULL (0)
#endif
typedef uint8_t UINT8;
typedef uint8_t BYTE;
typedef int8_t INT8;
typedef int BOOL;
typedef uint16_t UINT16;
typedef int16_t INT16;
typedef uint32_t UINT32;
typedef int32_t INT32;
typedef uint64_t UINT64;
typedef int64_t INT64;
typedef uint8_t UINT8;
typedef uint8_t BYTE;
typedef int8_t INT8;
typedef int BOOL;
typedef uint16_t UINT16;
typedef int16_t INT16;
typedef uint32_t UINT32;
typedef int32_t INT32;
typedef uint64_t UINT64;
typedef int64_t INT64;
#endif
#endif // _TPM_INCLUDE_PUBLIC_BASETYPES_H_

View File

@ -59,55 +59,53 @@
/* */
/********************************************************************************/
/* 9.2 Bits.c */
/* 9.2.1 Introduction */
/* This file contains bit manipulation routines. They operate on bit arrays. */
/* The 0th bit in the array is the right-most bit in the 0th octet in the array. */
/* NOTE: If pAssert() is defined, the functions will assert if the indicated bit number is outside
of the range of bArray. How the assert is handled is implementation dependent. */
/* 9.2.2 Includes */
#include "Tpm.h"
/* 9.2.3 Functions */
/* 9.2.3.1 TestBit() */
/* This function is used to check the setting of a bit in an array of bits. */
/* Return Values Meaning */
/* TRUE bit is set */
/* FALSE bit is not set */
//** Introduction
// This file contains bit manipulation routines. They operate on bit arrays.
//
// The 0th bit in the array is the right-most bit in the 0th octet in
// the array.
//
// NOTE: If pAssert() is defined, the functions will assert if the indicated bit
// number is outside of the range of 'bArray'. How the assert is handled is
// implementation dependent.
BOOL
TestBit(
unsigned int bitNum, // IN: number of the bit in 'bArray'
BYTE *bArray, // IN: array containing the bits
unsigned int bytesInArray // IN: size in bytes of 'bArray'
)
//** Includes
#include "Tpm.h"
//** Functions
//*** TestBit()
// This function is used to check the setting of a bit in an array of bits.
// Return Type: BOOL
// TRUE(1) bit is set
// FALSE(0) bit is not set
BOOL TestBit(unsigned int bitNum, // IN: number of the bit in 'bArray'
BYTE* bArray, // IN: array containing the bits
unsigned int bytesInArray // IN: size in bytes of 'bArray'
)
{
pAssert(bytesInArray > (bitNum >> 3));
return((bArray[bitNum >> 3] & (1 << (bitNum & 7))) != 0);
return ((bArray[bitNum >> 3] & (1 << (bitNum & 7))) != 0);
}
/* 9.2.3.2 SetBit() */
/* This function will set the indicated bit in bArray. */
void
SetBit(
unsigned int bitNum, // IN: number of the bit in 'bArray'
BYTE *bArray, // IN: array containing the bits
unsigned int bytesInArray // IN: size in bytes of 'bArray'
)
//*** SetBit()
// This function will set the indicated bit in 'bArray'.
void SetBit(unsigned int bitNum, // IN: number of the bit in 'bArray'
BYTE* bArray, // IN: array containing the bits
unsigned int bytesInArray // IN: size in bytes of 'bArray'
)
{
pAssert(bytesInArray > (bitNum >> 3));
bArray[bitNum >> 3] |= (1 << (bitNum & 7));
}
/* 9.2.3.3 ClearBit() */
/* This function will clear the indicated bit in bArray. */
void
ClearBit(
unsigned int bitNum, // IN: number of the bit in 'bArray'.
BYTE *bArray, // IN: array containing the bits
unsigned int bytesInArray // IN: size in bytes of 'bArray'
)
//*** ClearBit()
// This function will clear the indicated bit in 'bArray'.
void ClearBit(unsigned int bitNum, // IN: number of the bit in 'bArray'.
BYTE* bArray, // IN: array containing the bits
unsigned int bytesInArray // IN: size in bytes of 'bArray'
)
{
pAssert(bytesInArray > (bitNum >> 3));
bArray[bitNum >> 3] &= ~(1 << (bitNum & 7));

View File

@ -59,40 +59,36 @@
/* */
/********************************************************************************/
#ifndef BITS_FP_H
#define BITS_FP_H
/*(Auto-generated)
* Created by TpmPrototypes; Version 3.0 July 18, 2017
* Date: Mar 28, 2019 Time: 08:25:19PM
*/
/* 5.3.1 TestBit() */
/* This function is used to check the setting of a bit in an array of bits. */
/* Return Value Meaning */
/* TRUE bit is set */
/* FALSE bit is not set */
#ifndef _BITS_FP_H_
#define _BITS_FP_H_
BOOL
TestBit(
unsigned int bitNum, // IN: number of the bit in 'bArray'
BYTE *bArray, // IN: array containing the bits
unsigned int bytesInArray // IN: size in bytes of 'bArray'
);
//*** TestBit()
// This function is used to check the setting of a bit in an array of bits.
// Return Type: BOOL
// TRUE(1) bit is set
// FALSE(0) bit is not set
BOOL TestBit(unsigned int bitNum, // IN: number of the bit in 'bArray'
BYTE* bArray, // IN: array containing the bits
unsigned int bytesInArray // IN: size in bytes of 'bArray'
);
/* 5.3.2 SetBit() */
/* This function will set the indicated bit in bArray. */
//*** SetBit()
// This function will set the indicated bit in 'bArray'.
void SetBit(unsigned int bitNum, // IN: number of the bit in 'bArray'
BYTE* bArray, // IN: array containing the bits
unsigned int bytesInArray // IN: size in bytes of 'bArray'
);
void
SetBit(
unsigned int bitNum, // IN: number of the bit in 'bArray'
BYTE *bArray, // IN: array containing the bits
unsigned int bytesInArray // IN: size in bytes of 'bArray'
);
//*** ClearBit()
// This function will clear the indicated bit in 'bArray'.
void ClearBit(unsigned int bitNum, // IN: number of the bit in 'bArray'.
BYTE* bArray, // IN: array containing the bits
unsigned int bytesInArray // IN: size in bytes of 'bArray'
);
/* 5.3.3 ClearBit() */
/* This function will clear the indicated bit in bArray. */
void
ClearBit(
unsigned int bitNum, // IN: number of the bit in 'bArray'.
BYTE *bArray, // IN: array containing the bits
unsigned int bytesInArray // IN: size in bytes of 'bArray'
);
#endif
#endif // _BITS_FP_H_

View File

@ -84,32 +84,32 @@ LIB_EXPORT bigNum BnFromBytes(bigNum bn, const BYTE* bytes, NUMBYTES nBytes)
// If nothing in, nothing out
if(bn == NULL)
return NULL;
return NULL;
// make sure things fit
pAssert(BnGetAllocated(bn) >= size);
if(size > 0)
{
// Clear the topmost word in case it is not filled with data
bn->d[size - 1] = 0;
// Moving the input bytes from the end of the list (LSB) end
pFrom = bytes + nBytes - 1;
// To the LS0 of the LSW of the bigNum.
pTo = (BYTE*)bn->d;
for(; nBytes != 0; nBytes--)
*pTo++ = *pFrom--;
// For a little-endian machine, the conversion is a straight byte
// reversal. For a big-endian machine, we have to put the words in
// big-endian byte order
{
// Clear the topmost word in case it is not filled with data
bn->d[size - 1] = 0;
// Moving the input bytes from the end of the list (LSB) end
pFrom = bytes + nBytes - 1;
// To the LS0 of the LSW of the bigNum.
pTo = (BYTE*)bn->d;
for(; nBytes != 0; nBytes--)
*pTo++ = *pFrom--;
// For a little-endian machine, the conversion is a straight byte
// reversal. For a big-endian machine, we have to put the words in
// big-endian byte order
#if BIG_ENDIAN_TPM
{
crypt_word_t t;
for(t = (crypt_word_t)size - 1; t >= 0; t--)
bn->d[t] = SWAP_CRYPT_WORD(bn->d[t]);
}
{
crypt_word_t t;
for(t = (crypt_word_t)size - 1; t >= 0; t--)
bn->d[t] = SWAP_CRYPT_WORD(bn->d[t]);
}
#endif
}
}
BnSetTop(bn, size);
return bn;
}
@ -119,11 +119,11 @@ LIB_EXPORT bigNum BnFromBytes(bigNum bn, const BYTE* bytes, NUMBYTES nBytes)
// If the input value does not exist, or the output does not exist, or the input
// will not fit into the output the function returns NULL
LIB_EXPORT bigNum BnFrom2B(bigNum bn, // OUT:
const TPM2B* a2B // IN: number to convert
)
const TPM2B* a2B // IN: number to convert
)
{
if(a2B != NULL)
return BnFromBytes(bn, a2B->buffer, a2B->size);
return BnFromBytes(bn, a2B->buffer, a2B->size);
// Make sure that the number has an initialized value rather than whatever
// was there before
BnSetTop(bn, 0); // Function accepts NULL
@ -142,11 +142,11 @@ LIB_EXPORT bigNum BnFrom2B(bigNum bn, // OUT:
// unpack each word individually, the bigNum is converted to little-endian words,
// copied, and then converted back to big-endian.
LIB_EXPORT BOOL BnToBytes(bigConst bn,
BYTE* buffer,
NUMBYTES* size // This the number of bytes that are
// available in the buffer. The result
// should be this big.
)
BYTE* buffer,
NUMBYTES* size // This the number of bytes that are
// available in the buffer. The result
// should be this big.
)
{
crypt_uword_t requiredSize;
BYTE* pFrom;
@ -158,41 +158,41 @@ LIB_EXPORT BOOL BnToBytes(bigConst bn,
requiredSize = (BnSizeInBits(bn) + 7) / 8;
if(requiredSize == 0)
{
// If the input value is 0, return a byte of zero
*size = 1;
*buffer = 0;
}
{
// If the input value is 0, return a byte of zero
*size = 1;
*buffer = 0;
}
else
{
{
#if BIG_ENDIAN_TPM
// Copy the constant input value into a modifiable value
BN_VAR(bnL, LARGEST_NUMBER_BITS * 2);
BnCopy(bnL, bn);
// byte swap the words in the local value to make them little-endian
for(count = 0; count < bnL->size; count++)
bnL->d[count] = SWAP_CRYPT_WORD(bnL->d[count]);
bn = (bigConst)bnL;
// Copy the constant input value into a modifiable value
BN_VAR(bnL, LARGEST_NUMBER_BITS * 2);
BnCopy(bnL, bn);
// byte swap the words in the local value to make them little-endian
for(count = 0; count < bnL->size; count++)
bnL->d[count] = SWAP_CRYPT_WORD(bnL->d[count]);
bn = (bigConst)bnL;
#endif
if(*size == 0)
*size = (NUMBYTES)requiredSize;
pAssert(requiredSize <= *size);
// Byte swap the number (not words but the whole value)
count = *size;
// Start from the least significant word and offset to the most significant
// byte which is in some high word
pFrom = (BYTE*)(&bn->d[0]) + requiredSize - 1;
pTo = buffer;
if(*size == 0)
*size = (NUMBYTES)requiredSize;
pAssert(requiredSize <= *size);
// Byte swap the number (not words but the whole value)
count = *size;
// Start from the least significant word and offset to the most significant
// byte which is in some high word
pFrom = (BYTE*)(&bn->d[0]) + requiredSize - 1;
pTo = buffer;
// If the number of output bytes is larger than the number bytes required
// for the input number, pad with zeros
for(count = *size; count > requiredSize; count--)
*pTo++ = 0;
// Move the most significant byte at the end of the BigNum to the next most
// significant byte position of the 2B and repeat for all significant bytes.
for(; requiredSize > 0; requiredSize--)
*pTo++ = *pFrom--;
}
// If the number of output bytes is larger than the number bytes required
// for the input number, pad with zeros
for(count = *size; count > requiredSize; count--)
*pTo++ = 0;
// Move the most significant byte at the end of the BigNum to the next most
// significant byte position of the 2B and repeat for all significant bytes.
for(; requiredSize > 0; requiredSize--)
*pTo++ = *pFrom--;
}
return TRUE;
}
@ -203,16 +203,16 @@ LIB_EXPORT BOOL BnToBytes(bigConst bn,
// is returned. If 'size' is zero, then the TPM2B is assumed to be large enough
// for the data and a2b->size will be adjusted accordingly.
LIB_EXPORT BOOL BnTo2B(bigConst bn, // IN:
TPM2B* a2B, // OUT:
NUMBYTES size // IN: the desired size
)
TPM2B* a2B, // OUT:
NUMBYTES size // IN: the desired size
)
{
// Set the output size
if(bn && a2B)
{
a2B->size = size;
return BnToBytes(bn, a2B->buffer, &a2B->size);
}
{
a2B->size = size;
return BnToBytes(bn, a2B->buffer, &a2B->size);
}
return FALSE;
}
@ -223,21 +223,21 @@ LIB_EXPORT BOOL BnTo2B(bigConst bn, // IN:
// A point is going to be two ECC values in the same buffer. The values are going
// to be the size of the modulus. They are in modular form.
LIB_EXPORT bn_point_t* BnPointFromBytes(
bigPoint ecP, // OUT: the preallocated point structure
const BYTE* x,
NUMBYTES nBytesX,
const BYTE* y,
NUMBYTES nBytesY)
bigPoint ecP, // OUT: the preallocated point structure
const BYTE* x,
NUMBYTES nBytesX,
const BYTE* y,
NUMBYTES nBytesY)
{
if(x == NULL || y == NULL)
return NULL;
return NULL;
if(NULL != ecP)
{
BnFromBytes(ecP->x, x, nBytesX);
BnFromBytes(ecP->y, y, nBytesY);
BnSetWord(ecP->z, 1);
}
{
BnFromBytes(ecP->x, x, nBytesX);
BnFromBytes(ecP->y, y, nBytesY);
BnSetWord(ecP->z, 1);
}
return ecP;
}
@ -248,11 +248,11 @@ LIB_EXPORT bn_point_t* BnPointFromBytes(
// on input the NUMBYTES* parameters indicate the maximum buffer size.
// on output, they represent the amount of significant data in that buffer.
LIB_EXPORT BOOL BnPointToBytes(
pointConst ecP, // OUT: the preallocated point structure
BYTE* x,
NUMBYTES* pBytesX,
BYTE* y,
NUMBYTES* pBytesY)
pointConst ecP, // OUT: the preallocated point structure
BYTE* x,
NUMBYTES* pBytesX,
BYTE* y,
NUMBYTES* pBytesY)
{
pAssert(ecP && x && y && pBytesX && pBytesY);
pAssert(BnEqualWord(ecP->z, 1));

View File

@ -93,13 +93,13 @@
# define TO_ECC_528(a, b, c, d, e, f, g, h, i) i, h, g, f, e, d, c, b, a
# define TO_ECC_640(a, b, c, d, e, f, g, h, i, j) j, i, h, g, f, e, d, c, b, a
# define BN_MIN_ALLOC(bytes) \
(BYTES_TO_CRYPT_WORDS(bytes) == 0) ? 1 : BYTES_TO_CRYPT_WORDS(bytes)
# define ECC_CONST(NAME, bytes, initializer) \
const struct \
{ \
crypt_uword_t allocate, size, d[BN_MIN_ALLOC(bytes)]; \
} NAME = {BN_MIN_ALLOC(bytes), BYTES_TO_CRYPT_WORDS(bytes), {initializer}}
# define BN_MIN_ALLOC(bytes) \
(BYTES_TO_CRYPT_WORDS(bytes) == 0) ? 1 : BYTES_TO_CRYPT_WORDS(bytes)
# define ECC_CONST(NAME, bytes, initializer) \
const struct \
{ \
crypt_uword_t allocate, size, d[BN_MIN_ALLOC(bytes)]; \
} NAME = {BN_MIN_ALLOC(bytes), BYTES_TO_CRYPT_WORDS(bytes), {initializer}}
// This file contains the raw data for ECC curve constants. The data is wrapped
// in macros so this file can be included in other files that format the data in
@ -110,98 +110,98 @@
# if ECC_NIST_P192
const TPMBN_ECC_CURVE_CONSTANTS NIST_P192 = {TPM_ECC_NIST_P192,
(bigNum)&NIST_P192_p,
(bigNum)&NIST_P192_n,
(bigNum)&NIST_P192_h,
(bigNum)&NIST_P192_a,
(bigNum)&NIST_P192_b,
{(bigNum)&NIST_P192_gX,
(bigNum)&NIST_P192_gY,
(bigNum)&NIST_P192_gZ}};
(bigNum)&NIST_P192_p,
(bigNum)&NIST_P192_n,
(bigNum)&NIST_P192_h,
(bigNum)&NIST_P192_a,
(bigNum)&NIST_P192_b,
{(bigNum)&NIST_P192_gX,
(bigNum)&NIST_P192_gY,
(bigNum)&NIST_P192_gZ}};
# endif // ECC_NIST_P192
# if ECC_NIST_P224
const TPMBN_ECC_CURVE_CONSTANTS NIST_P224 = {TPM_ECC_NIST_P224,
(bigNum)&NIST_P224_p,
(bigNum)&NIST_P224_n,
(bigNum)&NIST_P224_h,
(bigNum)&NIST_P224_a,
(bigNum)&NIST_P224_b,
{(bigNum)&NIST_P224_gX,
(bigNum)&NIST_P224_gY,
(bigNum)&NIST_P224_gZ}};
(bigNum)&NIST_P224_p,
(bigNum)&NIST_P224_n,
(bigNum)&NIST_P224_h,
(bigNum)&NIST_P224_a,
(bigNum)&NIST_P224_b,
{(bigNum)&NIST_P224_gX,
(bigNum)&NIST_P224_gY,
(bigNum)&NIST_P224_gZ}};
# endif // ECC_NIST_P224
# if ECC_NIST_P256
const TPMBN_ECC_CURVE_CONSTANTS NIST_P256 = {TPM_ECC_NIST_P256,
(bigNum)&NIST_P256_p,
(bigNum)&NIST_P256_n,
(bigNum)&NIST_P256_h,
(bigNum)&NIST_P256_a,
(bigNum)&NIST_P256_b,
{(bigNum)&NIST_P256_gX,
(bigNum)&NIST_P256_gY,
(bigNum)&NIST_P256_gZ}};
(bigNum)&NIST_P256_p,
(bigNum)&NIST_P256_n,
(bigNum)&NIST_P256_h,
(bigNum)&NIST_P256_a,
(bigNum)&NIST_P256_b,
{(bigNum)&NIST_P256_gX,
(bigNum)&NIST_P256_gY,
(bigNum)&NIST_P256_gZ}};
# endif // ECC_NIST_P256
# if ECC_NIST_P384
const TPMBN_ECC_CURVE_CONSTANTS NIST_P384 = {TPM_ECC_NIST_P384,
(bigNum)&NIST_P384_p,
(bigNum)&NIST_P384_n,
(bigNum)&NIST_P384_h,
(bigNum)&NIST_P384_a,
(bigNum)&NIST_P384_b,
{(bigNum)&NIST_P384_gX,
(bigNum)&NIST_P384_gY,
(bigNum)&NIST_P384_gZ}};
(bigNum)&NIST_P384_p,
(bigNum)&NIST_P384_n,
(bigNum)&NIST_P384_h,
(bigNum)&NIST_P384_a,
(bigNum)&NIST_P384_b,
{(bigNum)&NIST_P384_gX,
(bigNum)&NIST_P384_gY,
(bigNum)&NIST_P384_gZ}};
# endif // ECC_NIST_P384
# if ECC_NIST_P521
const TPMBN_ECC_CURVE_CONSTANTS NIST_P521 = {TPM_ECC_NIST_P521,
(bigNum)&NIST_P521_p,
(bigNum)&NIST_P521_n,
(bigNum)&NIST_P521_h,
(bigNum)&NIST_P521_a,
(bigNum)&NIST_P521_b,
{(bigNum)&NIST_P521_gX,
(bigNum)&NIST_P521_gY,
(bigNum)&NIST_P521_gZ}};
(bigNum)&NIST_P521_p,
(bigNum)&NIST_P521_n,
(bigNum)&NIST_P521_h,
(bigNum)&NIST_P521_a,
(bigNum)&NIST_P521_b,
{(bigNum)&NIST_P521_gX,
(bigNum)&NIST_P521_gY,
(bigNum)&NIST_P521_gZ}};
# endif // ECC_NIST_P521
# if ECC_BN_P256
const TPMBN_ECC_CURVE_CONSTANTS BN_P256 = {TPM_ECC_BN_P256,
(bigNum)&BN_P256_p,
(bigNum)&BN_P256_n,
(bigNum)&BN_P256_h,
(bigNum)&BN_P256_a,
(bigNum)&BN_P256_b,
{(bigNum)&BN_P256_gX,
(bigNum)&BN_P256_gY,
(bigNum)&BN_P256_gZ}};
(bigNum)&BN_P256_p,
(bigNum)&BN_P256_n,
(bigNum)&BN_P256_h,
(bigNum)&BN_P256_a,
(bigNum)&BN_P256_b,
{(bigNum)&BN_P256_gX,
(bigNum)&BN_P256_gY,
(bigNum)&BN_P256_gZ}};
# endif // ECC_BN_P256
# if ECC_BN_P638
const TPMBN_ECC_CURVE_CONSTANTS BN_P638 = {TPM_ECC_BN_P638,
(bigNum)&BN_P638_p,
(bigNum)&BN_P638_n,
(bigNum)&BN_P638_h,
(bigNum)&BN_P638_a,
(bigNum)&BN_P638_b,
{(bigNum)&BN_P638_gX,
(bigNum)&BN_P638_gY,
(bigNum)&BN_P638_gZ}};
(bigNum)&BN_P638_p,
(bigNum)&BN_P638_n,
(bigNum)&BN_P638_h,
(bigNum)&BN_P638_a,
(bigNum)&BN_P638_b,
{(bigNum)&BN_P638_gX,
(bigNum)&BN_P638_gY,
(bigNum)&BN_P638_gZ}};
# endif // ECC_BN_P638
# if ECC_SM2_P256
const TPMBN_ECC_CURVE_CONSTANTS SM2_P256 = {TPM_ECC_SM2_P256,
(bigNum)&SM2_P256_p,
(bigNum)&SM2_P256_n,
(bigNum)&SM2_P256_h,
(bigNum)&SM2_P256_a,
(bigNum)&SM2_P256_b,
{(bigNum)&SM2_P256_gX,
(bigNum)&SM2_P256_gY,
(bigNum)&SM2_P256_gZ}};
(bigNum)&SM2_P256_p,
(bigNum)&SM2_P256_n,
(bigNum)&SM2_P256_h,
(bigNum)&SM2_P256_a,
(bigNum)&SM2_P256_b,
{(bigNum)&SM2_P256_gX,
(bigNum)&SM2_P256_gY,
(bigNum)&SM2_P256_gZ}};
# endif // ECC_SM2_P256
# define comma
@ -240,10 +240,10 @@ MUST_BE((sizeof(bnEccCurveData) / sizeof(bnEccCurveData[0])) == (ECC_CURVE_COUNT
const TPMBN_ECC_CURVE_CONSTANTS* BnGetCurveData(TPM_ECC_CURVE curveId)
{
for(int i = 0; i < ECC_CURVE_COUNT; i++)
{
if(bnEccCurveData[i]->curveId == curveId)
return bnEccCurveData[i];
}
{
if(bnEccCurveData[i]->curveId == curveId)
return bnEccCurveData[i];
}
return NULL;
}

View File

@ -87,7 +87,7 @@
//** Includes
#include "Tpm.h" // libtpms: for CryptRand.h
#include "TpmMath_Util_fp.h"
#include "TpmMath_Util_fp.h" // libtpms: added
#include "TpmBigNum.h"
extern BOOL g_inFailureMode; // can't use global.h because we can't use tpm.h
@ -107,45 +107,45 @@ const bignum_t BnConstZero = {1, 0, {0}};
// 0 no carry out
// 1 carry out
static BOOL AddSame(crypt_uword_t* result,
const crypt_uword_t* op1,
const crypt_uword_t* op2,
int count)
const crypt_uword_t* op1,
const crypt_uword_t* op2,
int count)
{
int carry = 0;
int i;
for(i = 0; i < count; i++)
{
crypt_uword_t a = op1[i];
crypt_uword_t sum = a + op2[i];
result[i] = sum + carry;
// generate a carry if the sum is less than either of the inputs
// propagate a carry if there was a carry and the sum + carry is zero
// do this using bit operations rather than logical operations so that
// the time is about the same.
// propagate term | generate term
carry = ((result[i] == 0) & carry) | (sum < a);
}
{
crypt_uword_t a = op1[i];
crypt_uword_t sum = a + op2[i];
result[i] = sum + carry;
// generate a carry if the sum is less than either of the inputs
// propagate a carry if there was a carry and the sum + carry is zero
// do this using bit operations rather than logical operations so that
// the time is about the same.
// propagate term | generate term
carry = ((result[i] == 0) & carry) | (sum < a);
}
return carry;
}
//*** CarryProp()
// Propagate a carry
static int CarryProp(
crypt_uword_t* result, const crypt_uword_t* op, int count, int carry)
crypt_uword_t* result, const crypt_uword_t* op, int count, int carry)
{
for(; count; count--)
carry = ((*result++ = *op++ + carry) == 0) & carry;
carry = ((*result++ = *op++ + carry) == 0) & carry;
return carry;
}
static void CarryResolve(bigNum result, int stop, int carry)
{
if(carry)
{
pAssert((unsigned)stop < result->allocated);
result->d[stop++] = 1;
}
{
pAssert((unsigned)stop < result->allocated);
result->d[stop++] = 1;
}
BnSetTop(result, stop);
}
@ -160,16 +160,16 @@ LIB_EXPORT BOOL BnAdd(bigNum result, bigConst op1, bigConst op2)
//
if(n2->size > n1->size)
{
n1 = op2;
n2 = op1;
}
{
n1 = op2;
n2 = op1;
}
pAssert(result->allocated >= n1->size);
stop = MIN(n1->size, n2->allocated);
carry = (int)AddSame(result->d, n1->d, n2->d, (int)stop);
if(n1->size > stop)
carry =
CarryProp(&result->d[stop], &n1->d[stop], (int)(n1->size - stop), carry);
carry =
CarryProp(&result->d[stop], &n1->d[stop], (int)(n1->size - stop), carry);
CarryResolve(result, (int)n1->size, carry);
return TRUE;
}
@ -189,20 +189,20 @@ LIB_EXPORT BOOL BnAddWord(bigNum result, bigConst op, crypt_uword_t word)
//*** SubSame()
// This function subtracts two values that have the same size.
static int SubSame(crypt_uword_t* result,
const crypt_uword_t* op1,
const crypt_uword_t* op2,
int count)
const crypt_uword_t* op1,
const crypt_uword_t* op2,
int count)
{
int borrow = 0;
int i;
for(i = 0; i < count; i++)
{
crypt_uword_t a = op1[i];
crypt_uword_t diff = a - op2[i];
result[i] = diff - borrow;
// generate | propagate
borrow = (diff > a) | ((diff == 0) & borrow);
}
{
crypt_uword_t a = op1[i];
crypt_uword_t diff = a - op2[i];
result[i] = diff - borrow;
// generate | propagate
borrow = (diff > a) | ((diff == 0) & borrow);
}
return borrow;
}
@ -214,10 +214,10 @@ static int SubSame(crypt_uword_t* result,
// are on large positive numbers (primes) or on fields.
// Propagate a borrow.
static int BorrowProp(
crypt_uword_t* result, const crypt_uword_t* op, int size, int borrow)
crypt_uword_t* result, const crypt_uword_t* op, int size, int borrow)
{
for(; size > 0; size--)
borrow = ((*result++ = *op++ - borrow) == MAX_CRYPT_UWORD) && borrow;
borrow = ((*result++ = *op++ - borrow) == MAX_CRYPT_UWORD) && borrow;
return borrow;
}
@ -234,8 +234,8 @@ LIB_EXPORT BOOL BnSub(bigNum result, bigConst op1, bigConst op2)
pAssert(op1->size >= op2->size);
borrow = SubSame(result->d, op1->d, op2->d, stop);
if(op1->size > (crypt_uword_t)stop)
borrow = BorrowProp(
&result->d[stop], &op1->d[stop], (int)(op1->size - stop), borrow);
borrow = BorrowProp(
&result->d[stop], &op1->d[stop], (int)(op1->size - stop), borrow);
pAssert(!borrow);
BnSetTop(result, op1->size);
return TRUE;
@ -274,15 +274,15 @@ LIB_EXPORT int BnUnsignedCmp(bigConst op1, bigConst op2)
pAssert((op1 != NULL) && (op2 != NULL));
retVal = (int)(op1->size - op2->size);
if(retVal == 0)
{
for(i = (int)(op1->size - 1); i >= 0; i--)
{
diff = (op1->d[i] < op2->d[i]) ? -1 : (op1->d[i] != op2->d[i]);
retVal = retVal == 0 ? diff : retVal;
}
}
{
for(i = (int)(op1->size - 1); i >= 0; i--)
{
diff = (op1->d[i] < op2->d[i]) ? -1 : (op1->d[i] != op2->d[i]);
retVal = retVal == 0 ? diff : retVal;
}
}
else
retVal = (retVal < 0) ? -1 : 1;
retVal = (retVal < 0) ? -1 : 1;
return retVal;
}
@ -295,12 +295,12 @@ LIB_EXPORT int BnUnsignedCmp(bigConst op1, bigConst op2)
LIB_EXPORT int BnUnsignedCmpWord(bigConst op1, crypt_uword_t word)
{
if(op1->size > 1)
return 1;
return 1;
else if(op1->size == 1)
return (op1->d[0] < word) ? -1 : (op1->d[0] > word);
return (op1->d[0] < word) ? -1 : (op1->d[0] > word);
else // op1 is zero
// equal if word is zero
return (word == 0) ? 0 : -1;
// equal if word is zero
return (word == 0) ? 0 : -1;
}
//*** BnModWord()
@ -327,39 +327,39 @@ LIB_EXPORT crypt_word_t BnModWord(bigConst numerator, crypt_word_t modulus)
static int Msb(crypt_uword_t word)
{
int retVal = -1;
//
//
#if RADIX_BITS == 64
if(word & 0xffffffff00000000)
{
retVal += 32;
word >>= 32;
}
{
retVal += 32;
word >>= 32;
}
#endif
if(word & 0xffff0000)
{
retVal += 16;
word >>= 16;
}
{
retVal += 16;
word >>= 16;
}
if(word & 0x0000ff00)
{
retVal += 8;
word >>= 8;
}
{
retVal += 8;
word >>= 8;
}
if(word & 0x000000f0)
{
retVal += 4;
word >>= 4;
}
{
retVal += 4;
word >>= 4;
}
if(word & 0x0000000c)
{
retVal += 2;
word >>= 2;
}
{
retVal += 2;
word >>= 2;
}
if(word & 0x00000002)
{
retVal += 1;
word >>= 1;
}
{
retVal += 1;
word >>= 1;
}
return retVal + (int)word;
}
@ -372,13 +372,13 @@ LIB_EXPORT int BnMsb(bigConst bn)
{
// If the value is NULL, or the size is zero then treat as zero and return -1
if(bn != NULL && bn->size > 0)
{
int retVal = Msb(bn->d[bn->size - 1]);
retVal += (int)(bn->size - 1) * RADIX_BITS;
return retVal;
}
{
int retVal = Msb(bn->d[bn->size - 1]);
retVal += (int)(bn->size - 1) * RADIX_BITS;
return retVal;
}
else
return -1;
return -1;
}
//*** BnSizeInBits()
@ -397,11 +397,11 @@ LIB_EXPORT unsigned BnSizeInBits(bigConst n)
LIB_EXPORT bigNum BnSetWord(bigNum n, crypt_uword_t w)
{
if(n != NULL)
{
pAssert(n->allocated > 1);
n->d[0] = w;
BnSetTop(n, (w != 0) ? 1 : 0);
}
{
pAssert(n->allocated > 1);
n->d[0] = w;
BnSetTop(n, (w != 0) ? 1 : 0);
}
return n;
}
@ -409,18 +409,18 @@ LIB_EXPORT bigNum BnSetWord(bigNum n, crypt_uword_t w)
// This function will SET a bit in a bigNum. Bit 0 is the least-significant bit in
// the 0th digit_t. The function will return FALSE if the bitNum is invalid, else TRUE.
LIB_EXPORT BOOL BnSetBit(bigNum bn, // IN/OUT: big number to modify
unsigned int bitNum // IN: Bit number to SET
)
unsigned int bitNum // IN: Bit number to SET
)
{
crypt_uword_t offset = bitNum / RADIX_BITS;
if(bitNum > bn->allocated * RADIX_BITS)
{
// out of range
return FALSE;
}
{
// out of range
return FALSE;
}
// Grow the number if necessary to set the bit.
while(bn->size <= offset)
bn->d[bn->size++] = 0;
bn->d[bn->size++] = 0;
bn->d[offset] |= ((crypt_uword_t)1 << RADIX_MOD(bitNum));
return TRUE;
}
@ -432,15 +432,15 @@ LIB_EXPORT BOOL BnSetBit(bigNum bn, // IN/OUT: big number to modify
// TRUE(1) the bit is set
// FALSE(0) the bit is not set or the number is out of range
LIB_EXPORT BOOL BnTestBit(bigNum bn, // IN: number to check
unsigned int bitNum // IN: bit to test
)
unsigned int bitNum // IN: bit to test
)
{
crypt_uword_t offset = RADIX_DIV(bitNum);
//
if(bn->size > offset)
return ((bn->d[offset] & (((crypt_uword_t)1) << RADIX_MOD(bitNum))) != 0);
return ((bn->d[offset] & (((crypt_uword_t)1) << RADIX_MOD(bitNum))) != 0);
else
return FALSE;
return FALSE;
}
//***BnMaskBits()
@ -452,8 +452,8 @@ LIB_EXPORT BOOL BnTestBit(bigNum bn, // IN: number to check
// TRUE(1) result masked
// FALSE(0) the input was not as large as the mask
LIB_EXPORT BOOL BnMaskBits(bigNum bn, // IN/OUT: number to mask
crypt_uword_t maskBit // IN: the bit number for the mask.
)
crypt_uword_t maskBit // IN: the bit number for the mask.
)
{
crypt_uword_t finalSize;
BOOL retVal;
@ -461,11 +461,11 @@ LIB_EXPORT BOOL BnMaskBits(bigNum bn, // IN/OUT: number to mask
finalSize = BITS_TO_CRYPT_WORDS(maskBit);
retVal = (finalSize <= bn->allocated);
if(retVal && (finalSize > 0))
{
crypt_uword_t mask;
mask = ~((crypt_uword_t)0) >> RADIX_MOD(maskBit);
bn->d[finalSize - 1] &= mask;
}
{
crypt_uword_t mask;
mask = ~((crypt_uword_t)0) >> RADIX_MOD(maskBit);
bn->d[finalSize - 1] &= mask;
}
BnSetTop(bn, finalSize);
return retVal;
}
@ -486,24 +486,24 @@ LIB_EXPORT BOOL BnShiftRight(bigNum result, bigConst toShift, uint32_t shiftAmou
// The end size is toShift->size - offset less one additional
// word if the shiftAmount would make the upper word == 0
if(toShift->size > offset)
{
finalSize = toShift->size - offset;
finalSize -= (toShift->d[toShift->size - 1] >> shiftAmount) == 0 ? 1 : 0;
}
{
finalSize = toShift->size - offset;
finalSize -= (toShift->d[toShift->size - 1] >> shiftAmount) == 0 ? 1 : 0;
}
else
finalSize = 0;
finalSize = 0;
pAssert(finalSize <= result->allocated);
if(finalSize != 0)
{
for(i = 0; i < finalSize; i++)
{
result->d[i] = (toShift->d[i + offset] >> shiftAmount)
| (toShift->d[i + offset + 1] << shiftIn);
}
if(offset == 0)
result->d[i] = toShift->d[i] >> shiftAmount;
}
{
for(i = 0; i < finalSize; i++)
{
result->d[i] = (toShift->d[i + offset] >> shiftAmount)
| (toShift->d[i + offset + 1] << shiftIn);
}
if(offset == 0)
result->d[i] = toShift->d[i] >> shiftAmount;
}
BnSetTop(result, finalSize);
return TRUE;
}
@ -537,9 +537,9 @@ BOOL BnIsPointOnCurve(pointConst Q, const TPMBN_ECC_CURVE_CONSTANTS* C)
BnMod(right, prime);
if(BnUnsignedCmp(left, right) == 0)
return TRUE;
return TRUE;
else
return FALSE;
return FALSE;
}
// libtpms added begin

View File

@ -59,142 +59,133 @@
/* */
/********************************************************************************/
/* 10.2.5 BnMemory.c */
/* 10.2.5.1 Introduction */
/* This file contains the memory setup functions used by the bigNum functions in CryptoEngine() */
/* 10.2.5.2 Includes */
#include "Tpm.h"
/* 10.2.5.3 Functions */
/* 10.2.5.3.1 BnSetTop() */
/* This function is used when the size of a bignum_t is changed. It makes sure that the unused words
are set to zero and that any significant words of zeros are eliminated from the used size
indicator. */
LIB_EXPORT bigNum
BnSetTop(
bigNum bn, // IN/OUT: number to clean
crypt_uword_t top // IN: the new top
)
//** Introduction
// This file contains the memory setup functions used by the bigNum functions
// in CryptoEngine
//** Includes
#include "TpmBigNum.h"
//** Functions
//*** BnSetTop()
// This function is used when the size of a bignum_t is changed. It
// makes sure that the unused words are set to zero and that any significant
// words of zeros are eliminated from the used size indicator.
LIB_EXPORT bigNum BnSetTop(bigNum bn, // IN/OUT: number to clean
crypt_uword_t top // IN: the new top
)
{
if(bn != NULL)
{
pAssert(top <= bn->allocated);
// If forcing the size to be decreased, make sure that the words being
// discarded are being set to 0
while(bn->size > top)
bn->d[--bn->size] = 0;
bn->size = top;
// Now make sure that the words that are left are 'normalized' (no high-order
// words of zero.
while((bn->size > 0) && (bn->d[bn->size - 1] == 0))
bn->size -= 1;
}
{
pAssert(top <= bn->allocated);
// If forcing the size to be decreased, make sure that the words being
// discarded are being set to 0
while(bn->size > top)
bn->d[--bn->size] = 0;
bn->size = top;
// Now make sure that the words that are left are 'normalized' (no high-order
// words of zero.
while((bn->size > 0) && (bn->d[bn->size - 1] == 0))
bn->size -= 1;
}
return bn;
}
#if 0 /* libtpms added */
/* 10.2.5.3.2 BnClearTop() */
/* This function will make sure that all unused words are zero. */
LIB_EXPORT bigNum
BnClearTop(
bigNum bn
)
//*** BnClearTop()
// This function will make sure that all unused words are zero.
LIB_EXPORT bigNum BnClearTop(bigNum bn)
{
crypt_uword_t i;
crypt_uword_t i;
//
if(bn != NULL)
{
for(i = bn->size; i < bn->allocated; i++)
bn->d[i] = 0;
while((bn->size > 0) && (bn->d[bn->size] == 0))
bn->size -= 1;
}
{
for(i = bn->size; i < bn->allocated; i++)
bn->d[i] = 0;
while((bn->size > 0) && (bn->d[bn->size] == 0))
bn->size -= 1;
}
return bn;
}
#endif /* libtpms added */
/* 10.2.5.3.3 BnInitializeWord() */
/* This function is used to initialize an allocated bigNum with a word value. The bigNum does not
have to be allocated with a single word. */
LIB_EXPORT bigNum
BnInitializeWord(
bigNum bn, // IN:
crypt_uword_t allocated, // IN:
crypt_uword_t word // IN:
)
//*** BnInitializeWord()
// This function is used to initialize an allocated bigNum with a word value. The
// bigNum does not have to be allocated with a single word.
LIB_EXPORT bigNum BnInitializeWord(bigNum bn, // IN:
crypt_uword_t allocated, // IN:
crypt_uword_t word // IN:
)
{
bn->allocated = allocated;
bn->size = (word != 0);
bn->d[0] = word;
bn->size = (word != 0);
bn->d[0] = word;
while(allocated > 1)
bn->d[--allocated] = 0;
bn->d[--allocated] = 0;
return bn;
}
/* 10.2.5.3.4 BnInit() */
/* This function initializes a stack allocated bignum_t. It initializes allocated and size and zeros
the words of d. */
LIB_EXPORT bigNum
BnInit(
bigNum bn,
crypt_uword_t allocated
)
//*** BnInit()
// This function initializes a stack allocated bignum_t. It initializes
// 'allocated' and 'size' and zeros the words of 'd'.
LIB_EXPORT bigNum BnInit(bigNum bn, crypt_uword_t allocated)
{
if(bn != NULL)
{
bn->allocated = allocated;
bn->size = 0;
while(allocated != 0)
bn->d[--allocated] = 0;
}
{
bn->allocated = allocated;
bn->size = 0;
while(allocated != 0)
bn->d[--allocated] = 0;
}
return bn;
}
/* 10.2.5.3.5 BnCopy() */
/* Function to copy a bignum_t. If the output is NULL, then nothing happens. If the input is NULL,
the output is set to zero. */
LIB_EXPORT BOOL
BnCopy(
bigNum out,
bigConst in
)
//*** BnCopy()
// Function to copy a bignum_t. If the output is NULL, then
// nothing happens. If the input is NULL, the output is set
// to zero.
LIB_EXPORT BOOL BnCopy(bigNum out, bigConst in)
{
if(in == out)
BnSetTop(out, BnGetSize(out));
BnSetTop(out, BnGetSize(out));
else if(out != NULL)
{
if(in != NULL)
{
unsigned int i;
pAssert(BnGetAllocated(out) >= BnGetSize(in));
for(i = 0; i < BnGetSize(in); i++)
out->d[i] = in->d[i];
BnSetTop(out, BnGetSize(in));
}
else
BnSetTop(out, 0);
}
{
if(in != NULL)
{
unsigned int i;
pAssert(BnGetAllocated(out) >= BnGetSize(in));
for(i = 0; i < BnGetSize(in); i++)
out->d[i] = in->d[i];
BnSetTop(out, BnGetSize(in));
}
else
BnSetTop(out, 0);
}
return TRUE;
}
#if ALG_ECC
#if 0 /* libtpms added */
/* 10.2.5.3.6 BnPointCopy() */
/* Function to copy a bn point. */
LIB_EXPORT BOOL
BnPointCopy(
bigPoint pOut,
pointConst pIn
)
//*** BnPointCopy()
// Function to copy a bn point.
LIB_EXPORT BOOL BnPointCopy(bigPoint pOut, pointConst pIn)
{
return BnCopy(pOut->x, pIn->x)
&& BnCopy(pOut->y, pIn->y)
&& BnCopy(pOut->z, pIn->z);
return BnCopy(pOut->x, pIn->x) && BnCopy(pOut->y, pIn->y)
&& BnCopy(pOut->z, pIn->z);
}
#endif /* libtpms added */
/* 10.2.5.3.7 BnInitializePoint() */
/* This function is used to initialize a point structure with the addresses of the coordinates. */
LIB_EXPORT bn_point_t *
BnInitializePoint(
bigPoint p, // OUT: structure to receive pointers
bigNum x, // IN: x coordinate
bigNum y, // IN: y coordinate
bigNum z // IN: x coordinate
)
//*** BnInitializePoint()
// This function is used to initialize a point structure with the addresses
// of the coordinates.
LIB_EXPORT bn_point_t* BnInitializePoint(
bigPoint p, // OUT: structure to receive pointers
bigNum x, // IN: x coordinate
bigNum y, // IN: y coordinate
bigNum z // IN: x coordinate
)
{
p->x = x;
p->y = y;
@ -202,4 +193,5 @@ BnInitializePoint(
BnSetWord(z, 1);
return p;
}
#endif // TPM_ALG_ECC
#endif // ALG_ECC

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()
@ -95,7 +96,7 @@ BOOL BnMathLibraryCompatibilityCheck(void);
//** BnModMult()
// Does 'op1' * 'op2' and divide by 'modulus' returning the remainder of the divide.
LIB_EXPORT BOOL BnModMult(
bigNum result, bigConst op1, bigConst op2, bigConst modulus);
bigNum result, bigConst op1, bigConst op2, bigConst modulus);
//** BnMult()
// Multiplies two numbers and returns the result
@ -105,7 +106,7 @@ LIB_EXPORT BOOL BnMult(bigNum result, bigConst multiplicand, bigConst multiplier
// This function divides two bigNum values. The function returns FALSE if there is
// an error in the operation.
LIB_EXPORT BOOL BnDiv(
bigNum quotient, bigNum remainder, bigConst dividend, bigConst divisor);
bigNum quotient, bigNum remainder, bigConst dividend, bigConst divisor);
//** BnMod()
#define BnMod(a, b) BnDiv(NULL, (a), (a), (b))
@ -119,11 +120,11 @@ LIB_EXPORT BOOL BnGcd(bigNum gcd, bigConst number1, bigConst number2);
// Do modular exponentiation using bigNum values. This function is only needed
// when the TPM implements RSA.
LIB_EXPORT BOOL BnModExp(
bigNum result, bigConst number, bigConst exponent, bigConst modulus);
bigNum result, bigConst number, bigConst exponent, bigConst modulus);
#endif // ALG_RSA
//** BnModInverse()
// Modular multiplicative inverse.
//** BnModInverse()
// Modular multiplicative inverse.
LIB_EXPORT BOOL BnModInverse(bigNum result, bigConst number, bigConst modulus);
#if ALG_ECC
@ -145,28 +146,36 @@ LIB_EXPORT void BnCurveFree(bigCurveData* E);
// indicates that the result was the point at infinity. This function is only needed
// if the TPM supports ECC.
LIB_EXPORT BOOL BnEccModMult(
bigPoint R, pointConst S, bigConst d, const bigCurveData* E);
bigPoint R, pointConst S, bigConst d, const bigCurveData* E);
//** BnEccModMult2()
// This function does a point multiply of the form R = [d]S + [u]Q. A return of
// FALSE indicates that the result was the point at infinity. This function is only
// needed if the TPM supports ECC.
LIB_EXPORT BOOL BnEccModMult2(bigPoint R,
pointConst S,
bigConst d,
pointConst Q,
bigConst u,
const bigCurveData* E);
pointConst S,
bigConst d,
pointConst Q,
bigConst u,
const bigCurveData* E);
//** BnEccAdd()
// This function does a point add R = S + Q. A return of FALSE
// indicates that the result was the point at infinity. This function is only needed
// if the TPM supports ECC.
LIB_EXPORT BOOL BnEccAdd(
bigPoint R, pointConst S, pointConst Q, const bigCurveData* E);
bigPoint R, pointConst S, pointConst Q, const bigCurveData* E);
#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

@ -59,41 +59,38 @@
/* */
/********************************************************************************/
/* C.2 Cancel.c */
/* C.2.1. Description */
/* This module simulates the cancel pins on the TPM. */
/* C.2.2. Includes, Typedefs, Structures, and Defines */
//** Description
//
// This module simulates the cancel pins on the TPM.
//
//** Includes, Typedefs, Structures, and Defines
#include "Platform.h"
/* C.2.3. Functions */
/* C.2.3.1. _plat__IsCanceled() */
/* Check if the cancel flag is set */
/* Return Values Meaning */
/* TRUE(1) if cancel flag is set */
/* FALSE(0) if cancel flag is not set */
LIB_EXPORT int
_plat__IsCanceled(
void
)
//** Functions
//***_plat__IsCanceled()
// Check if the cancel flag is set
// Return Type: int
// TRUE(1) if cancel flag is set
// FALSE(0) if cancel flag is not set
LIB_EXPORT int _plat__IsCanceled(void)
{
// return cancel flag
return s_isCanceled;
}
/* C.2.3.2. _plat__SetCancel() */
/* Set cancel flag. */
LIB_EXPORT void
_plat__SetCancel(
void
)
//***_plat__SetCancel()
// Set cancel flag.
LIB_EXPORT void _plat__SetCancel(void)
{
s_isCanceled = TRUE;
return;
}
/* C.2.3.3. _plat__ClearCancel() */
/* Clear cancel flag */
LIB_EXPORT void
_plat__ClearCancel(
void
)
//***_plat__ClearCancel()
// Clear cancel flag
LIB_EXPORT void _plat__ClearCancel(void)
{
s_isCanceled = FALSE;
return;

View File

@ -59,18 +59,18 @@
/* */
/********************************************************************************/
#ifndef _CAPABILITIES_H
#define _CAPABILITIES_H
#ifndef _CAPABILITIES_H
#define _CAPABILITIES_H
#define MAX_CAP_DATA (MAX_CAP_BUFFER - sizeof(TPM_CAP)-sizeof(UINT32))
#define MAX_CAP_ALGS (MAX_CAP_DATA / sizeof(TPMS_ALG_PROPERTY))
#define MAX_CAP_HANDLES (MAX_CAP_DATA / sizeof(TPM_HANDLE))
#define MAX_CAP_CC (MAX_CAP_DATA / sizeof(TPM_CC))
#define MAX_TPM_PROPERTIES (MAX_CAP_DATA / sizeof(TPMS_TAGGED_PROPERTY))
#define MAX_PCR_PROPERTIES (MAX_CAP_DATA / sizeof(TPMS_TAGGED_PCR_SELECT))
#define MAX_ECC_CURVES (MAX_CAP_DATA / sizeof(TPM_ECC_CURVE))
#define MAX_TAGGED_POLICIES (MAX_CAP_DATA / sizeof(TPMS_TAGGED_POLICY))
#define MAX_ACT_DATA (MAX_CAP_DATA / sizeof(TPMS_ACT_DATA))
#define MAX_AC_CAPABILITIES (MAX_CAP_DATA / sizeof(TPMS_AC_OUTPUT))
#define MAX_CAP_DATA (MAX_CAP_BUFFER - sizeof(TPM_CAP) - sizeof(UINT32))
#define MAX_CAP_ALGS (MAX_CAP_DATA / sizeof(TPMS_ALG_PROPERTY))
#define MAX_CAP_HANDLES (MAX_CAP_DATA / sizeof(TPM_HANDLE))
#define MAX_CAP_CC (MAX_CAP_DATA / sizeof(TPM_CC))
#define MAX_TPM_PROPERTIES (MAX_CAP_DATA / sizeof(TPMS_TAGGED_PROPERTY))
#define MAX_PCR_PROPERTIES (MAX_CAP_DATA / sizeof(TPMS_TAGGED_PCR_SELECT))
#define MAX_ECC_CURVES (MAX_CAP_DATA / sizeof(TPM_ECC_CURVE))
#define MAX_TAGGED_POLICIES (MAX_CAP_DATA / sizeof(TPMS_TAGGED_POLICY))
#define MAX_ACT_DATA (MAX_CAP_DATA / sizeof(TPMS_ACT_DATA))
#define MAX_AC_CAPABILITIES (MAX_CAP_DATA / sizeof(TPMS_AC_OUTPUT))
#endif

View File

@ -59,37 +59,43 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef CERTIFYCREATION_FP_H
#define CERTIFYCREATION_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_DH_OBJECT signHandle;
TPMI_DH_OBJECT objectHandle;
TPM2B_DATA qualifyingData;
TPM2B_DIGEST creationHash;
TPMT_SIG_SCHEME inScheme;
TPMT_TK_CREATION creationTicket;
#if CC_CertifyCreation // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_CERTIFYCREATION_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_CERTIFYCREATION_FP_H_
// Input structure definition
typedef struct
{
TPMI_DH_OBJECT signHandle;
TPMI_DH_OBJECT objectHandle;
TPM2B_DATA qualifyingData;
TPM2B_DIGEST creationHash;
TPMT_SIG_SCHEME inScheme;
TPMT_TK_CREATION creationTicket;
} CertifyCreation_In;
#define RC_CertifyCreation_signHandle (TPM_RC_H + TPM_RC_1)
#define RC_CertifyCreation_objectHandle (TPM_RC_H + TPM_RC_2)
#define RC_CertifyCreation_qualifyingData (TPM_RC_P + TPM_RC_1)
#define RC_CertifyCreation_creationHash (TPM_RC_P + TPM_RC_2)
#define RC_CertifyCreation_inScheme (TPM_RC_P + TPM_RC_3)
#define RC_CertifyCreation_creationTicket (TPM_RC_P + TPM_RC_4)
typedef struct {
TPM2B_ATTEST certifyInfo;
TPMT_SIGNATURE signature;
// Output structure definition
typedef struct
{
TPM2B_ATTEST certifyInfo;
TPMT_SIGNATURE signature;
} CertifyCreation_Out;
// Response code modifiers
# define RC_CertifyCreation_signHandle (TPM_RC_H + TPM_RC_1)
# define RC_CertifyCreation_objectHandle (TPM_RC_H + TPM_RC_2)
# define RC_CertifyCreation_qualifyingData (TPM_RC_P + TPM_RC_1)
# define RC_CertifyCreation_creationHash (TPM_RC_P + TPM_RC_2)
# define RC_CertifyCreation_inScheme (TPM_RC_P + TPM_RC_3)
# define RC_CertifyCreation_creationTicket (TPM_RC_P + TPM_RC_4)
// Function prototype
TPM_RC
TPM2_CertifyCreation(
CertifyCreation_In *in, // IN: input parameter list
CertifyCreation_Out *out // OUT: output parameter list
);
TPM2_CertifyCreation(CertifyCreation_In* in, CertifyCreation_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_CERTIFYCREATION_FP_H_
#endif // CC_CertifyCreation

View File

@ -59,35 +59,42 @@
/* */
/********************************************************************************/
/* rev 155 */
#ifndef CERTIFYX509_FP_H
#define CERTIFYX509_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_DH_OBJECT objectHandle;
TPMI_DH_OBJECT signHandle;
TPM2B_DATA reserved;
TPMT_SIG_SCHEME inScheme;
TPM2B_MAX_BUFFER partialCertificate;
#if CC_CertifyX509 // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_CERTIFYX509_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_CERTIFYX509_FP_H_
// Input structure definition
typedef struct
{
TPMI_DH_OBJECT objectHandle;
TPMI_DH_OBJECT signHandle;
TPM2B_DATA reserved;
TPMT_SIG_SCHEME inScheme;
TPM2B_MAX_BUFFER partialCertificate;
} CertifyX509_In;
#define RC_CertifyX509_signHandle (TPM_RC_H + TPM_RC_1)
#define RC_CertifyX509_objectHandle (TPM_RC_H + TPM_RC_2)
#define RC_CertifyX509_reserved (TPM_RC_P + TPM_RC_1)
#define RC_CertifyX509_inScheme (TPM_RC_P + TPM_RC_2)
#define RC_CertifyX509_partialCertificate (TPM_RC_P + TPM_RC_3)
typedef struct {
TPM2B_MAX_BUFFER addedToCertificate;
TPM2B_DIGEST tbsDigest;
TPMT_SIGNATURE signature;
// Output structure definition
typedef struct
{
TPM2B_MAX_BUFFER addedToCertificate;
TPM2B_DIGEST tbsDigest;
TPMT_SIGNATURE signature;
} CertifyX509_Out;
TPM_RC
TPM2_CertifyX509(
CertifyX509_In *in, // IN: input parameter list
CertifyX509_Out *out // OUT: output parameter list
);
// Response code modifiers
# define RC_CertifyX509_objectHandle (TPM_RC_H + TPM_RC_1)
# define RC_CertifyX509_signHandle (TPM_RC_H + TPM_RC_2)
# define RC_CertifyX509_reserved (TPM_RC_P + TPM_RC_1)
# define RC_CertifyX509_inScheme (TPM_RC_P + TPM_RC_2)
# define RC_CertifyX509_partialCertificate (TPM_RC_P + TPM_RC_3)
#endif
// Function prototype
TPM_RC
TPM2_CertifyX509(CertifyX509_In* in, CertifyX509_Out* out);
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_CERTIFYX509_FP_H_
#endif // CC_CertifyX509

View File

@ -59,35 +59,39 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef CERTIFY_FP_H
#define CERTIFY_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_DH_OBJECT objectHandle;
TPMI_DH_OBJECT signHandle;
TPM2B_DATA qualifyingData;
TPMT_SIG_SCHEME inScheme;
#if CC_Certify // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_CERTIFY_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_CERTIFY_FP_H_
// Input structure definition
typedef struct
{
TPMI_DH_OBJECT objectHandle;
TPMI_DH_OBJECT signHandle;
TPM2B_DATA qualifyingData;
TPMT_SIG_SCHEME inScheme;
} Certify_In;
#define RC_Certify_objectHandle (TPM_RC_H + TPM_RC_1)
#define RC_Certify_signHandle (TPM_RC_H + TPM_RC_2)
#define RC_Certify_qualifyingData (TPM_RC_P + TPM_RC_1)
#define RC_Certify_inScheme (TPM_RC_P + TPM_RC_2)
typedef struct {
TPM2B_ATTEST certifyInfo;
TPMT_SIGNATURE signature;
// Output structure definition
typedef struct
{
TPM2B_ATTEST certifyInfo;
TPMT_SIGNATURE signature;
} Certify_Out;
// Response code modifiers
# define RC_Certify_objectHandle (TPM_RC_H + TPM_RC_1)
# define RC_Certify_signHandle (TPM_RC_H + TPM_RC_2)
# define RC_Certify_qualifyingData (TPM_RC_P + TPM_RC_1)
# define RC_Certify_inScheme (TPM_RC_P + TPM_RC_2)
// Function prototype
TPM_RC
TPM2_Certify(
Certify_In *in, // IN: input parameter list
Certify_Out *out // OUT: output parameter list
);
TPM2_Certify(Certify_In* in, Certify_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_CERTIFY_FP_H_
#endif // CC_Certify

View File

@ -59,21 +59,26 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef CHANGEEPS_FP_H
#define CHANGEEPS_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_RH_PLATFORM authHandle;
#if CC_ChangeEPS // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_CHANGEEPS_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_CHANGEEPS_FP_H_
// Input structure definition
typedef struct
{
TPMI_RH_PLATFORM authHandle;
} ChangeEPS_In;
#define RC_ChangeEPS_authHandle (TPM_RC_H + TPM_RC_1)
// Response code modifiers
# define RC_ChangeEPS_authHandle (TPM_RC_H + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_ChangeEPS(
ChangeEPS_In *in // IN: input parameter list
);
TPM2_ChangeEPS(ChangeEPS_In* in);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_CHANGEEPS_FP_H_
#endif // CC_ChangeEPS

View File

@ -59,21 +59,26 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef CHANGEPPS_FP_H
#define CHANGEPPS_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_RH_PLATFORM authHandle;
#if CC_ChangePPS // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_CHANGEPPS_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_CHANGEPPS_FP_H_
// Input structure definition
typedef struct
{
TPMI_RH_PLATFORM authHandle;
} ChangePPS_In;
#define RC_ChangePPS_authHandle (TPM_RC_P + TPM_RC_1)
// Response code modifiers
# define RC_ChangePPS_authHandle (TPM_RC_H + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_ChangePPS(
ChangePPS_In *in // IN: input parameter list
);
TPM2_ChangePPS(ChangePPS_In* in);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_CHANGEPPS_FP_H_
#endif // CC_ChangePPS

View File

@ -59,21 +59,28 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef CLEARCONTROL_FP_H
#define CLEARCONTROL_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_RH_CLEAR auth;
TPMI_YES_NO disable;
#if CC_ClearControl // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_CLEARCONTROL_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_CLEARCONTROL_FP_H_
// Input structure definition
typedef struct
{
TPMI_RH_CLEAR auth;
TPMI_YES_NO disable;
} ClearControl_In;
#define RC_ClearControl_auth (TPM_RC_H + TPM_RC_1)
#define RC_ClearControl_disable (TPM_RC_P + TPM_RC_1)
// Response code modifiers
# define RC_ClearControl_auth (TPM_RC_H + TPM_RC_1)
# define RC_ClearControl_disable (TPM_RC_P + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_ClearControl(
ClearControl_In *in // IN: input parameter list
);
#endif
TPM2_ClearControl(ClearControl_In* in);
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_CLEARCONTROL_FP_H_
#endif // CC_ClearControl

View File

@ -59,20 +59,26 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef CLEAR_FP_H
#define CLEAR_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_RH_CLEAR authHandle;
#if CC_Clear // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_CLEAR_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_CLEAR_FP_H_
// Input structure definition
typedef struct
{
TPMI_RH_CLEAR authHandle;
} Clear_In;
#define RC_Clear_authHandle (TPM_RC_H + TPM_RC_1)
// Response code modifiers
# define RC_Clear_authHandle (TPM_RC_H + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_Clear(
Clear_In *in // IN: input parameter list
);
TPM2_Clear(Clear_In* in);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_CLEAR_FP_H_
#endif // CC_Clear

View File

@ -175,16 +175,16 @@ clock_t debugTime;
LIB_EXPORT uint64_t _plat__RealTime(void)
{
clock64_t time;
//#ifdef _MSC_VER kgold
//#ifdef _MSC_VER kgold // libtpms changed begin
#ifdef TPM_WINDOWS
#include <sys/timeb.h>
#include <sys/timeb.h> // libtpms changed end
struct _timeb sysTime;
//
_ftime(&sysTime); /* kgold, mingw doesn't have _ftime_s */
time = (clock64_t)(sysTime.time) * 1000 + sysTime.millitm;
// set the time back by one hour if daylight savings
if(sysTime.dstflag)
time -= 1000 * 60 * 60; // mSec/sec * sec/min * min/hour = ms/hour
time -= 1000 * 60 * 60; // mSec/sec * sec/min * min/hour = ms/hour
#else
// hopefully, this will work with most UNIX systems
struct timespec systime;
@ -226,7 +226,7 @@ LIB_EXPORT uint64_t _plat__TimerRead(void)
# error "need a defintion for reading the hardware clock"
return HARDWARE_CLOCK
#else
clock64_t timeDiff;
clock64_t timeDiff;
clock64_t adjustedTimeDiff;
clock64_t timeNow;
clock64_t readjustedTimeDiff;
@ -236,17 +236,17 @@ LIB_EXPORT uint64_t _plat__TimerRead(void)
// if this hasn't been initialized, initialize it
if(s_lastSystemTime == 0)
{
s_lastSystemTime = timeNow;
debugTime = clock();
s_lastReportedTime = 0;
s_realTimePrevious = 0;
}
{
s_lastSystemTime = timeNow;
debugTime = clock();
s_lastReportedTime = 0;
s_realTimePrevious = 0;
}
// The system time can bounce around and that's OK as long as we don't allow
// time to go backwards. When the time does appear to go backwards, set
// lastSystemTime to be the new value and then update the reported time.
if(timeNow < s_lastReportedTime)
s_lastSystemTime = timeNow;
s_lastSystemTime = timeNow;
s_lastReportedTime = s_lastReportedTime + timeNow - s_lastSystemTime;
s_lastSystemTime = timeNow;
timeNow = s_lastReportedTime;
@ -257,7 +257,7 @@ LIB_EXPORT uint64_t _plat__TimerRead(void)
// uses that value and does the rate adjustment on the time value.
// If there is no difference in time, then skip all the computations
if(s_realTimePrevious >= timeNow)
return s_tpmTime;
return s_tpmTime;
// Compute the amount of time since the last update of the system clock
timeDiff = timeNow - s_realTimePrevious;
@ -324,71 +324,33 @@ LIB_EXPORT void _plat__ClockRateAdjust(_plat__ClockAdjustStep adjust)
// We expect the caller should only use a fixed set of constant values to
// adjust the rate
switch(adjust)
{
// slower increases the divisor
case PLAT_TPM_CLOCK_ADJUST_COARSE_SLOWER:
s_adjustRate += CLOCK_ADJUST_COARSE;
break;
case PLAT_TPM_CLOCK_ADJUST_MEDIUM_SLOWER:
s_adjustRate += CLOCK_ADJUST_MEDIUM;
break;
case PLAT_TPM_CLOCK_ADJUST_FINE_SLOWER:
s_adjustRate += CLOCK_ADJUST_FINE;
break;
// faster decreases the divisor
case PLAT_TPM_CLOCK_ADJUST_FINE_FASTER:
s_adjustRate -= CLOCK_ADJUST_FINE;
break;
case PLAT_TPM_CLOCK_ADJUST_MEDIUM_FASTER:
s_adjustRate -= CLOCK_ADJUST_MEDIUM;
break;
case PLAT_TPM_CLOCK_ADJUST_COARSE_FASTER:
s_adjustRate -= CLOCK_ADJUST_COARSE;
break;
}
{
// slower increases the divisor
case PLAT_TPM_CLOCK_ADJUST_COARSE_SLOWER:
s_adjustRate += CLOCK_ADJUST_COARSE;
break;
case PLAT_TPM_CLOCK_ADJUST_MEDIUM_SLOWER:
s_adjustRate += CLOCK_ADJUST_MEDIUM;
break;
case PLAT_TPM_CLOCK_ADJUST_FINE_SLOWER:
s_adjustRate += CLOCK_ADJUST_FINE;
break;
// faster decreases the divisor
case PLAT_TPM_CLOCK_ADJUST_FINE_FASTER:
s_adjustRate -= CLOCK_ADJUST_FINE;
break;
case PLAT_TPM_CLOCK_ADJUST_MEDIUM_FASTER:
s_adjustRate -= CLOCK_ADJUST_MEDIUM;
break;
case PLAT_TPM_CLOCK_ADJUST_COARSE_FASTER:
s_adjustRate -= CLOCK_ADJUST_COARSE;
break;
}
if(s_adjustRate > (CLOCK_NOMINAL + CLOCK_ADJUST_LIMIT))
s_adjustRate = CLOCK_NOMINAL + CLOCK_ADJUST_LIMIT;
s_adjustRate = CLOCK_NOMINAL + CLOCK_ADJUST_LIMIT;
if(s_adjustRate < (CLOCK_NOMINAL - CLOCK_ADJUST_LIMIT))
s_adjustRate = CLOCK_NOMINAL - CLOCK_ADJUST_LIMIT;
s_adjustRate = CLOCK_NOMINAL - CLOCK_ADJUST_LIMIT;
return;
}
#if 0
/* added for portability because Linux clock is 32 bits */
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include "TpmFail_fp.h"
LIB_EXPORT uint64_t
_plat__RealTime(
void
)
{
clock64_t time;
//#ifdef _MSC_VER kgold
#ifdef TPM_WINDOWS
#include <sys/timeb.h>
struct _timeb sysTime;
//
_ftime(&sysTime); /* kgold, mingw doesn't have _ftime_s */
time = (clock64_t)(sysTime.time) * 1000 + sysTime.millitm;
// set the time back by one hour if daylight savings
if(sysTime.dstflag)
time -= 1000 * 60 * 60; // mSec/sec * sec/min * min/hour = ms/hour
#else
// hopefully, this will work with most UNIX systems
struct timespec systime;
//
clock_gettime(CLOCK_MONOTONIC, &systime);
time = (clock64_t)systime.tv_sec * 1000 + (systime.tv_nsec / 1000000);
#endif
return time;
}
#endif

View File

@ -59,23 +59,28 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef CLOCKRATEADJUST_FP_H
#define CLOCKRATEADJUST_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_RH_PROVISION auth;
TPM_CLOCK_ADJUST rateAdjust;
#if CC_ClockRateAdjust // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_CLOCKRATEADJUST_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_CLOCKRATEADJUST_FP_H_
// Input structure definition
typedef struct
{
TPMI_RH_PROVISION auth;
TPM_CLOCK_ADJUST rateAdjust;
} ClockRateAdjust_In;
#define RC_ClockRateAdjust_auth (TPM_RC_H + TPM_RC_1)
#define RC_ClockRateAdjust_rateAdjust (TPM_RC_P + TPM_RC_1)
// Response code modifiers
# define RC_ClockRateAdjust_auth (TPM_RC_H + TPM_RC_1)
# define RC_ClockRateAdjust_rateAdjust (TPM_RC_P + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_ClockRateAdjust(
ClockRateAdjust_In *in // IN: input parameter list
);
TPM2_ClockRateAdjust(ClockRateAdjust_In* in);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_CLOCKRATEADJUST_FP_H_
#endif // CC_ClockRateAdjust

View File

@ -59,23 +59,28 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef CLOCKSET_FP_H
#define CLOCKSET_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_RH_PROVISION auth;
UINT64 newTime;
#if CC_ClockSet // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_CLOCKSET_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_CLOCKSET_FP_H_
// Input structure definition
typedef struct
{
TPMI_RH_PROVISION auth;
UINT64 newTime;
} ClockSet_In;
#define RC_ClockSet_auth (TPM_RC_H + TPM_RC_1)
#define RC_ClockSet_newTime (TPM_RC_P + TPM_RC_1)
// Response code modifiers
# define RC_ClockSet_auth (TPM_RC_H + TPM_RC_1)
# define RC_ClockSet_newTime (TPM_RC_P + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_ClockSet(
ClockSet_In *in // IN: input parameter list
);
TPM2_ClockSet(ClockSet_In* in);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_CLOCKSET_FP_H_
#endif // CC_ClockSet

File diff suppressed because it is too large Load Diff

View File

@ -59,30 +59,36 @@
/* */
/********************************************************************************/
#ifndef COMMANDATTRIBUTES_H
#define COMMANDATTRIBUTES_H
/*(Auto-generated)
* Created by TpmStructures; Version 4.4 Mar 26, 2019
* Date: Aug 30, 2019 Time: 02:11:52PM
*/
/* 5.7 CommandAttributes.h */
/* The attributes defined in this file are produced by the parser that creates the structure
definitions from Part 3. The attributes are defined in that parser and should track the
attributes being tested in CommandCodeAttributes.c. Generally, when an attribute is added to this
list, new code will be needed in CommandCodeAttributes.c to test it. */
// The attributes defined in this file are produced by the parser that
// creates the structure definitions from Part 3. The attributes are defined
// in that parser and should track the attributes being tested in
// CommandCodeAttributes.c. Generally, when an attribute is added to this list,
// new code will be needed in CommandCodeAttributes.c to test it.
typedef UINT16 COMMAND_ATTRIBUTES;
#define NOT_IMPLEMENTED (COMMAND_ATTRIBUTES)(0)
#define ENCRYPT_2 ((COMMAND_ATTRIBUTES)1 << 0)
#define ENCRYPT_4 ((COMMAND_ATTRIBUTES)1 << 1)
#define DECRYPT_2 ((COMMAND_ATTRIBUTES)1 << 2)
#define DECRYPT_4 ((COMMAND_ATTRIBUTES)1 << 3)
#define HANDLE_1_USER ((COMMAND_ATTRIBUTES)1 << 4)
#define HANDLE_1_ADMIN ((COMMAND_ATTRIBUTES)1 << 5)
#define HANDLE_1_DUP ((COMMAND_ATTRIBUTES)1 << 6)
#define HANDLE_2_USER ((COMMAND_ATTRIBUTES)1 << 7)
#define PP_COMMAND ((COMMAND_ATTRIBUTES)1 << 8)
#define IS_IMPLEMENTED ((COMMAND_ATTRIBUTES)1 << 9)
#define NO_SESSIONS ((COMMAND_ATTRIBUTES)1 << 10)
#define NV_COMMAND ((COMMAND_ATTRIBUTES)1 << 11)
#define PP_REQUIRED ((COMMAND_ATTRIBUTES)1 << 12)
#define R_HANDLE ((COMMAND_ATTRIBUTES)1 << 13)
#define ALLOW_TRIAL ((COMMAND_ATTRIBUTES)1 << 14)
#endif // COMMAND_ATTRIBUTES_H
#ifndef COMMAND_ATTRIBUTES_H
#define COMMAND_ATTRIBUTES_H
typedef UINT16 COMMAND_ATTRIBUTES;
#define NOT_IMPLEMENTED (COMMAND_ATTRIBUTES)(0)
#define ENCRYPT_2 ((COMMAND_ATTRIBUTES)1 << 0)
#define ENCRYPT_4 ((COMMAND_ATTRIBUTES)1 << 1)
#define DECRYPT_2 ((COMMAND_ATTRIBUTES)1 << 2)
#define DECRYPT_4 ((COMMAND_ATTRIBUTES)1 << 3)
#define HANDLE_1_USER ((COMMAND_ATTRIBUTES)1 << 4)
#define HANDLE_1_ADMIN ((COMMAND_ATTRIBUTES)1 << 5)
#define HANDLE_1_DUP ((COMMAND_ATTRIBUTES)1 << 6)
#define HANDLE_2_USER ((COMMAND_ATTRIBUTES)1 << 7)
#define PP_COMMAND ((COMMAND_ATTRIBUTES)1 << 8)
#define IS_IMPLEMENTED ((COMMAND_ATTRIBUTES)1 << 9)
#define NO_SESSIONS ((COMMAND_ATTRIBUTES)1 << 10)
#define NV_COMMAND ((COMMAND_ATTRIBUTES)1 << 11)
#define PP_REQUIRED ((COMMAND_ATTRIBUTES)1 << 12)
#define R_HANDLE ((COMMAND_ATTRIBUTES)1 << 13)
#define ALLOW_TRIAL ((COMMAND_ATTRIBUTES)1 << 14)
#endif // COMMAND_ATTRIBUTES_H

View File

@ -100,13 +100,13 @@ void CommandAuditPreInstall_Init(void)
//*** CommandAuditStartup()
// This function clears the command audit digest on a TPM Reset.
BOOL CommandAuditStartup(STARTUP_TYPE type // IN: start up type
)
)
{
if((type != SU_RESTART) && (type != SU_RESUME))
{
// Reset the digest size to initialize the digest
gr.commandAuditDigest.t.size = 0;
}
{
// Reset the digest size to initialize the digest
gr.commandAuditDigest.t.size = 0;
}
return TRUE;
}
@ -124,24 +124,24 @@ BOOL CommandAuditStartup(STARTUP_TYPE type // IN: start up type
// TRUE(1) command code audit status was changed
// FALSE(0) command code audit status was not changed
BOOL CommandAuditSet(TPM_CC commandCode // IN: command code
)
)
{
COMMAND_INDEX commandIndex = CommandCodeToCommandIndex(commandCode);
// Only SET a bit if the corresponding command is implemented
if(commandIndex != UNIMPLEMENTED_COMMAND_INDEX)
{
// Can't audit shutdown
if(commandCode != TPM_CC_Shutdown)
{
if(!TEST_BIT(commandIndex, gp.auditCommands))
{
// Set bit
SET_BIT(commandIndex, gp.auditCommands);
return TRUE;
}
}
}
{
// Can't audit shutdown
if(commandCode != TPM_CC_Shutdown)
{
if(!TEST_BIT(commandIndex, gp.auditCommands))
{
// Set bit
SET_BIT(commandIndex, gp.auditCommands);
return TRUE;
}
}
}
// No change
return FALSE;
}
@ -158,25 +158,25 @@ BOOL CommandAuditSet(TPM_CC commandCode // IN: command code
// TRUE(1) command code audit status was changed
// FALSE(0) command code audit status was not changed
BOOL CommandAuditClear(TPM_CC commandCode // IN: command code
)
)
{
COMMAND_INDEX commandIndex = CommandCodeToCommandIndex(commandCode);
// Do nothing if the command is not implemented
if(commandIndex != UNIMPLEMENTED_COMMAND_INDEX)
{
// The bit associated with TPM_CC_SetCommandCodeAuditStatus() cannot be
// cleared
if(commandCode != TPM_CC_SetCommandCodeAuditStatus)
{
if(TEST_BIT(commandIndex, gp.auditCommands))
{
// Clear bit
CLEAR_BIT(commandIndex, gp.auditCommands);
return TRUE;
}
}
}
{
// The bit associated with TPM_CC_SetCommandCodeAuditStatus() cannot be
// cleared
if(commandCode != TPM_CC_SetCommandCodeAuditStatus)
{
if(TEST_BIT(commandIndex, gp.auditCommands))
{
// Clear bit
CLEAR_BIT(commandIndex, gp.auditCommands);
return TRUE;
}
}
}
// No change
return FALSE;
}
@ -187,7 +187,7 @@ BOOL CommandAuditClear(TPM_CC commandCode // IN: command code
// TRUE(1) command is audited
// FALSE(0) command is not audited
BOOL CommandAuditIsRequired(COMMAND_INDEX commandIndex // IN: command index
)
)
{
// Check the bit map. If the bit is SET, command audit is required
return (TEST_BIT(commandIndex, gp.auditCommands));
@ -202,9 +202,9 @@ BOOL CommandAuditIsRequired(COMMAND_INDEX commandIndex // IN: command index
// NO all the available command code has been returned
TPMI_YES_NO
CommandAuditCapGetCCList(TPM_CC commandCode, // IN: start command code
UINT32 count, // IN: count of returned TPM_CC
TPML_CC* commandList // OUT: list of TPM_CC
)
UINT32 count, // IN: count of returned TPM_CC
TPML_CC* commandList // OUT: list of TPM_CC
)
{
TPMI_YES_NO more = NO;
COMMAND_INDEX commandIndex;
@ -214,37 +214,37 @@ CommandAuditCapGetCCList(TPM_CC commandCode, // IN: start command code
// The maximum count of command we may return is MAX_CAP_CC
if(count > MAX_CAP_CC)
count = MAX_CAP_CC;
count = MAX_CAP_CC;
// Find the implemented command that has a command code that is the same or
// higher than the input
// Collect audit commands
for(commandIndex = GetClosestCommandIndex(commandCode);
commandIndex != UNIMPLEMENTED_COMMAND_INDEX;
commandIndex = GetNextCommandIndex(commandIndex))
{
if(CommandAuditIsRequired(commandIndex))
{
if(commandList->count < count)
{
// If we have not filled up the return list, add this command
// code to its
TPM_CC cc =
GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, commandIndex);
if(IS_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, V))
cc += (1 << 29);
commandList->commandCodes[commandList->count] = cc;
commandList->count++;
}
else
{
// If the return list is full but we still have command
// available, report this and stop iterating
more = YES;
break;
}
}
}
commandIndex != UNIMPLEMENTED_COMMAND_INDEX;
commandIndex = GetNextCommandIndex(commandIndex))
{
if(CommandAuditIsRequired(commandIndex))
{
if(commandList->count < count)
{
// If we have not filled up the return list, add this command
// code to its
TPM_CC cc =
GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, commandIndex);
if(IS_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, V))
cc += (1 << 29);
commandList->commandCodes[commandList->count] = cc;
commandList->count++;
}
else
{
// If the return list is full but we still have command
// available, report this and stop iterating
more = YES;
break;
}
}
}
return more;
}
@ -255,9 +255,9 @@ BOOL CommandAuditCapGetOneCC(TPM_CC commandCode) // IN: command code
{
COMMAND_INDEX commandIndex = CommandCodeToCommandIndex(commandCode);
if(commandIndex != UNIMPLEMENTED_COMMAND_INDEX)
{
return CommandAuditIsRequired(commandIndex);
}
{
return CommandAuditIsRequired(commandIndex);
}
return FALSE;
}
@ -267,7 +267,7 @@ BOOL CommandAuditCapGetOneCC(TPM_CC commandCode) // IN: command code
// added to a hash. This operates as if all the audited command codes were
// concatenated and then hashed.
void CommandAuditGetDigest(TPM2B_DIGEST* digest // OUT: command digest
)
)
{
TPM_CC commandCode;
COMMAND_INDEX commandIndex;
@ -278,13 +278,13 @@ void CommandAuditGetDigest(TPM2B_DIGEST* digest // OUT: command digest
// Add command code
for(commandIndex = 0; commandIndex < COMMAND_COUNT; commandIndex++)
{
if(CommandAuditIsRequired(commandIndex))
{
commandCode = GetCommandCode(commandIndex);
CryptDigestUpdateInt(&hashState, sizeof(commandCode), commandCode);
}
}
{
if(CommandAuditIsRequired(commandIndex))
{
commandCode = GetCommandCode(commandIndex);
CryptDigestUpdateInt(&hashState, sizeof(commandCode), commandCode);
}
}
// Complete hash
CryptHashEnd2B(&hashState, &digest->b);

View File

@ -58,41 +58,91 @@
/* */
/********************************************************************************/
#ifndef COMMANDAUDIT_FP_H
#define COMMANDAUDIT_FP_H
/*(Auto-generated)
* Created by TpmPrototypes; Version 3.0 July 18, 2017
* Date: Apr 2, 2019 Time: 04:23:27PM
*/
void
CommandAuditPreInstall_Init(
void
);
BOOL
CommandAuditStartup(
STARTUP_TYPE type // IN: start up type
);
BOOL
CommandAuditSet(
TPM_CC commandCode // IN: command code
);
BOOL
CommandAuditClear(
TPM_CC commandCode // IN: command code
);
BOOL
CommandAuditIsRequired(
COMMAND_INDEX commandIndex // IN: command index
);
#ifndef _COMMAND_AUDIT_FP_H_
#define _COMMAND_AUDIT_FP_H_
//*** CommandAuditPreInstall_Init()
// This function initializes the command audit list. This function simulates
// the behavior of manufacturing. A function is used instead of a structure
// definition because this is easier than figuring out the initialization value
// for a bit array.
//
// This function would not be implemented outside of a manufacturing or
// simulation environment.
void CommandAuditPreInstall_Init(void);
//*** CommandAuditStartup()
// This function clears the command audit digest on a TPM Reset.
BOOL CommandAuditStartup(STARTUP_TYPE type // IN: start up type
);
//*** CommandAuditSet()
// This function will SET the audit flag for a command. This function
// will not SET the audit flag for a command that is not implemented. This
// ensures that the audit status is not SET when TPM2_GetCapability() is
// used to read the list of audited commands.
//
// This function is only used by TPM2_SetCommandCodeAuditStatus().
//
// The actions in TPM2_SetCommandCodeAuditStatus() are expected to cause the
// changes to be saved to NV after it is setting and clearing bits.
// Return Type: BOOL
// TRUE(1) command code audit status was changed
// FALSE(0) command code audit status was not changed
BOOL CommandAuditSet(TPM_CC commandCode // IN: command code
);
//*** CommandAuditClear()
// This function will CLEAR the audit flag for a command. It will not CLEAR the
// audit flag for TPM_CC_SetCommandCodeAuditStatus().
//
// This function is only used by TPM2_SetCommandCodeAuditStatus().
//
// The actions in TPM2_SetCommandCodeAuditStatus() are expected to cause the
// changes to be saved to NV after it is setting and clearing bits.
// Return Type: BOOL
// TRUE(1) command code audit status was changed
// FALSE(0) command code audit status was not changed
BOOL CommandAuditClear(TPM_CC commandCode // IN: command code
);
//*** CommandAuditIsRequired()
// This function indicates if the audit flag is SET for a command.
// Return Type: BOOL
// TRUE(1) command is audited
// FALSE(0) command is not audited
BOOL CommandAuditIsRequired(COMMAND_INDEX commandIndex // IN: command index
);
//*** CommandAuditCapGetCCList()
// This function returns a list of commands that have their audit bit SET.
//
// The list starts at the input commandCode.
// Return Type: TPMI_YES_NO
// YES if there are more command code available
// NO all the available command code has been returned
TPMI_YES_NO
CommandAuditCapGetCCList(
TPM_CC commandCode, // IN: start command code
UINT32 count, // IN: count of returned TPM_CC
TPML_CC *commandList // OUT: list of TPM_CC
);
CommandAuditCapGetCCList(TPM_CC commandCode, // IN: start command code
UINT32 count, // IN: count of returned TPM_CC
TPML_CC* commandList // OUT: list of TPM_CC
);
//*** CommandAuditCapGetOneCC()
// This function returns true if a command has its audit bit set.
BOOL CommandAuditCapGetOneCC(TPM_CC commandCode // IN: command code
);
void
CommandAuditGetDigest(
TPM2B_DIGEST *digest // OUT: command digest
);
);
//*** CommandAuditGetDigest
// This command is used to create a digest of the commands being audited. The
// commands are processed in ascending numeric order with a list of TPM_CC being
// added to a hash. This operates as if all the audited command codes were
// concatenated and then hashed.
void CommandAuditGetDigest(TPM2B_DIGEST* digest // OUT: command digest
);
#endif
#endif // _COMMAND_AUDIT_FP_H_

View File

@ -58,532 +58,534 @@
/* */
/********************************************************************************/
/* 9.3 CommandCodeAttributes.c */
/* 9.3.1 Introduction */
/* This file contains the functions for testing various command properties. */
/* 9.3.2 Includes and Defines */
//** Introduction
// This file contains the functions for testing various command properties.
//** Includes and Defines
#include "Tpm.h"
#include "CommandCodeAttributes_fp.h"
/* Set the default value for CC_VEND if not already set */
#ifndef CC_VEND
#define CC_VEND (TPM_CC)(0x20000000)
#endif
typedef UINT16 ATTRIBUTE_TYPE;
/* The following file is produced from the command tables in part 3 of the specification. It defines
the attributes for each of the commands. */
/* NOTE: This file is currently produced by an automated process. Files produced from Part 2 or Part
3 tables through automated processes are not included in the specification so that there is no
ambiguity about the table containing the information being the normative definition. */
#define _COMMAND_CODE_ATTRIBUTES_
#include "CommandAttributeData.h"
/* 9.3.3 Command Attribute Functions */
/* 9.3.3.1 NextImplementedIndex() */
/* This function is used when the lists are not compressed. In a compressed list, only the
implemented commands are present. So, a search might find a value but that value may not be
implemented. This function checks to see if the input commandIndex points to an implemented
command and, if not, it searches upwards until it finds one. When the list is compressed, this
function gets defined as a no-op. */
/* Return Value Meaning */
/* UNIMPLEMENTED_COMMAND_INDEX command is not implemented */
/* other index of the command */
// Set the default value for CC_VEND if not already set
#ifndef CC_VEND
# define CC_VEND (TPM_CC)(0x20000000)
#endif
typedef UINT16 ATTRIBUTE_TYPE;
// The following file is produced from the command tables in part 3 of the
// specification. It defines the attributes for each of the commands.
// NOTE: This file is currently produced by an automated process. Files
// produced from Part 2 or Part 3 tables through automated processes are not
// included in the specification so that their is no ambiguity about the
// table containing the information being the normative definition.
#define _COMMAND_CODE_ATTRIBUTES_
#include "CommandAttributeData.h"
//** Command Attribute Functions
//*** NextImplementedIndex()
// This function is used when the lists are not compressed. In a compressed list,
// only the implemented commands are present. So, a search might find a value
// but that value may not be implemented. This function checks to see if the input
// commandIndex points to an implemented command and, if not, it searches upwards
// until it finds one. When the list is compressed, this function gets defined
// as a no-op.
// Return Type: COMMAND_INDEX
// UNIMPLEMENTED_COMMAND_INDEX command is not implemented
// other index of the command
#if !COMPRESSED_LISTS
static COMMAND_INDEX
NextImplementedIndex(
COMMAND_INDEX commandIndex
)
static COMMAND_INDEX NextImplementedIndex(COMMAND_INDEX commandIndex)
{
for(;commandIndex < COMMAND_COUNT; commandIndex++)
{
if((s_commandAttributes[commandIndex] & IS_IMPLEMENTED) && // libtpms changed
RuntimeCommandsCheckEnabled(&g_RuntimeProfile.RuntimeCommands, // libtpms added begin
GET_ATTRIBUTE(s_ccAttr[commandIndex],
TPMA_CC, commandIndex)))// libtpms added end
return commandIndex;
}
for(; commandIndex < COMMAND_COUNT; commandIndex++)
{
if((s_commandAttributes[commandIndex] & IS_IMPLEMENTED) && // libtpms changed
RuntimeCommandsCheckEnabled(&g_RuntimeProfile.RuntimeCommands, // libtpms added begin
GET_ATTRIBUTE(s_ccAttr[commandIndex],
TPMA_CC, commandIndex))) // libtpms added end
return commandIndex;
}
return UNIMPLEMENTED_COMMAND_INDEX;
}
#else
#define NextImplementedIndex(x) (x)
# define NextImplementedIndex(x) (x)
#endif
/* 9.3.3.2 GetClosestCommandIndex() */
/* This function returns the command index for the command with a value that is equal to or greater
than the input value */
/* Return Value Meaning */
/* UNIMPLEMENTED_COMMAND_INDEX command is not implemented */
/* other index of the command */
//*** GetClosestCommandIndex()
// This function returns the command index for the command with a value that is
// equal to or greater than the input value
// Return Type: COMMAND_INDEX
// UNIMPLEMENTED_COMMAND_INDEX command is not implemented
// other index of a command
COMMAND_INDEX
GetClosestCommandIndex(
TPM_CC commandCode // IN: the command code to start at
)
GetClosestCommandIndex(TPM_CC commandCode // IN: the command code to start at
)
{
BOOL vendor = (commandCode & CC_VEND) != 0;
COMMAND_INDEX searchIndex = (COMMAND_INDEX)commandCode;
BOOL vendor = (commandCode & CC_VEND) != 0;
COMMAND_INDEX searchIndex = (COMMAND_INDEX)commandCode;
// The commandCode is a UINT32 and the search index is UINT16. We are going to
// search for a match but need to make sure that the commandCode value is not
// out of range. To do this, need to clear the vendor bit of the commandCode
// (if set) and compare the result to the 16-bit searchIndex value. If it is
// out of range, indicate that the command is not implemented
if((commandCode & ~CC_VEND) != searchIndex)
return UNIMPLEMENTED_COMMAND_INDEX;
return UNIMPLEMENTED_COMMAND_INDEX;
// if there is at least one vendor command, the last entry in the array will
// have the v bit set. If the input commandCode is larger than the last
// vendor-command, then it is out of range.
if(vendor)
{
{
#if VENDOR_COMMAND_ARRAY_SIZE > 0
COMMAND_INDEX commandIndex;
COMMAND_INDEX min;
COMMAND_INDEX max;
int diff;
#if LIBRARY_COMMAND_ARRAY_SIZE == COMMAND_COUNT
#error "Constants are not consistent."
#endif
// Check to see if the value is equal to or below the minimum
// entry.
// Note: Put this check first so that the typical case of only one vendor-
// specific command doesn't waste any more time.
if(GET_ATTRIBUTE(s_ccAttr[LIBRARY_COMMAND_ARRAY_SIZE], TPMA_CC,
commandIndex) >= searchIndex)
{
// the vendor array is always assumed to be packed so there is
// no need to check to see if the command is implemented
return LIBRARY_COMMAND_ARRAY_SIZE;
}
// See if this is out of range on the top
if(GET_ATTRIBUTE(s_ccAttr[COMMAND_COUNT - 1], TPMA_CC, commandIndex)
< searchIndex)
{
return UNIMPLEMENTED_COMMAND_INDEX;
}
commandIndex = UNIMPLEMENTED_COMMAND_INDEX; // Needs initialization to keep
// compiler happy
min = LIBRARY_COMMAND_ARRAY_SIZE; // first vendor command
max = COMMAND_COUNT - 1; // last vendor command
diff = 1; // needs initialization to keep
// compiler happy
while(min <= max)
{
commandIndex = (min + max + 1) / 2;
diff = GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, commandIndex)
- searchIndex;
if(diff == 0)
return commandIndex;
if(diff > 0)
max = commandIndex - 1;
else
min = commandIndex + 1;
}
// didn't find and exact match. commandIndex will be pointing at the last
// item tested. If 'diff' is positive, then the last item tested was
// larger index of the command code so it is the smallest value
// larger than the requested value.
if(diff > 0)
return commandIndex;
// if 'diff' is negative, then the value tested was smaller than
// the commandCode index and the next higher value is the correct one.
// Note: this will necessarily be in range because of the earlier check
// that the index was within range.
return commandIndex + 1;
COMMAND_INDEX commandIndex;
COMMAND_INDEX min;
COMMAND_INDEX max;
int diff;
# if LIBRARY_COMMAND_ARRAY_SIZE == COMMAND_COUNT
# error "Constants are not consistent."
# endif
// Check to see if the value is equal to or below the minimum
// entry.
// Note: Put this check first so that the typical case of only one vendor-
// specific command doesn't waste any more time.
if(GET_ATTRIBUTE(s_ccAttr[LIBRARY_COMMAND_ARRAY_SIZE], TPMA_CC, commandIndex)
>= searchIndex)
{
// the vendor array is always assumed to be packed so there is
// no need to check to see if the command is implemented
return LIBRARY_COMMAND_ARRAY_SIZE;
}
// See if this is out of range on the top
if(GET_ATTRIBUTE(s_ccAttr[COMMAND_COUNT - 1], TPMA_CC, commandIndex)
< searchIndex)
{
return UNIMPLEMENTED_COMMAND_INDEX;
}
commandIndex = UNIMPLEMENTED_COMMAND_INDEX; // Needs initialization to keep
// compiler happy
min = LIBRARY_COMMAND_ARRAY_SIZE; // first vendor command
max = COMMAND_COUNT - 1; // last vendor command
diff = 1; // needs initialization to keep
// compiler happy
while(min <= max)
{
commandIndex = (min + max + 1) / 2;
diff = GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, commandIndex)
- searchIndex;
if(diff == 0)
return commandIndex;
if(diff > 0)
max = commandIndex - 1;
else
min = commandIndex + 1;
}
// didn't find and exact match. commandIndex will be pointing at the last
// item tested. If 'diff' is positive, then the last item tested was
// larger index of the command code so it is the smallest value
// larger than the requested value.
if(diff > 0)
return commandIndex;
// if 'diff' is negative, then the value tested was smaller than
// the commandCode index and the next higher value is the correct one.
// Note: this will necessarily be in range because of the earlier check
// that the index was within range.
return commandIndex + 1;
#else
// If there are no vendor commands so anything with the vendor bit set is out
// of range
return UNIMPLEMENTED_COMMAND_INDEX;
// If there are no vendor commands so anything with the vendor bit set is out
// of range
return UNIMPLEMENTED_COMMAND_INDEX;
#endif
}
}
// Get here if the V-Bit was not set in 'commandCode'
if(GET_ATTRIBUTE(s_ccAttr[LIBRARY_COMMAND_ARRAY_SIZE - 1], TPMA_CC,
commandIndex) < searchIndex)
{
// requested index is out of the range to the top
if(GET_ATTRIBUTE(s_ccAttr[LIBRARY_COMMAND_ARRAY_SIZE - 1], TPMA_CC, commandIndex)
< searchIndex)
{
// requested index is out of the range to the top
#if VENDOR_COMMAND_ARRAY_SIZE > 0
// If there are vendor commands, then the first vendor command
// is the next value greater than the commandCode.
// NOTE: we got here if the starting index did not have the V bit but we
// reached the end of the array of library commands (non-vendor). Since
// there is at least one vendor command, and vendor commands are always
// in a compressed list that starts after the library list, the next
// index value contains a valid vendor command.
return LIBRARY_COMMAND_ARRAY_SIZE;
// If there are vendor commands, then the first vendor command
// is the next value greater than the commandCode.
// NOTE: we got here if the starting index did not have the V bit but we
// reached the end of the array of library commands (non-vendor). Since
// there is at least one vendor command, and vendor commands are always
// in a compressed list that starts after the library list, the next
// index value contains a valid vendor command.
return LIBRARY_COMMAND_ARRAY_SIZE;
#else
// if there are no vendor commands, then this is out of range
return UNIMPLEMENTED_COMMAND_INDEX;
// if there are no vendor commands, then this is out of range
return UNIMPLEMENTED_COMMAND_INDEX;
#endif
}
}
// If the request is lower than any value in the array, then return
// the lowest value (needs to be an index for an implemented command
if(GET_ATTRIBUTE(s_ccAttr[0], TPMA_CC, commandIndex) >= searchIndex)
{
return NextImplementedIndex(0);
}
{
return NextImplementedIndex(0);
}
else
{
{
#if COMPRESSED_LISTS
COMMAND_INDEX commandIndex = UNIMPLEMENTED_COMMAND_INDEX;
COMMAND_INDEX min = 0;
COMMAND_INDEX max = LIBRARY_COMMAND_ARRAY_SIZE - 1;
int diff = 1;
#if LIBRARY_COMMAND_ARRAY_SIZE == 0
#error "Something is terribly wrong"
#endif
// The s_ccAttr array contains an extra entry at the end (a zero value).
// Don't count this as an array entry. This means that max should start
// out pointing to the last valid entry in the array which is - 2
pAssert(max == (sizeof(s_ccAttr) / sizeof(TPMA_CC)
- VENDOR_COMMAND_ARRAY_SIZE - 2));
while(min <= max)
{
commandIndex = (min + max + 1) / 2;
diff = GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC,
commandIndex) - searchIndex;
if(diff == 0)
return commandIndex;
if(diff > 0)
max = commandIndex - 1;
else
min = commandIndex + 1;
}
// didn't find and exact match. commandIndex will be pointing at the
// last item tested. If diff is positive, then the last item tested was
// larger index of the command code so it is the smallest value
// larger than the requested value.
if(diff > 0)
return commandIndex;
// if diff is negative, then the value tested was smaller than
// the commandCode index and the next higher value is the correct one.
// Note: this will necessarily be in range because of the earlier check
// that the index was within range.
return commandIndex + 1;
COMMAND_INDEX commandIndex = UNIMPLEMENTED_COMMAND_INDEX;
COMMAND_INDEX min = 0;
COMMAND_INDEX max = LIBRARY_COMMAND_ARRAY_SIZE - 1;
int diff = 1;
# if LIBRARY_COMMAND_ARRAY_SIZE == 0
# error "Something is terribly wrong"
# endif
// The s_ccAttr array contains an extra entry at the end (a zero value).
// Don't count this as an array entry. This means that max should start
// out pointing to the last valid entry in the array which is - 2
pAssert(
max
== (sizeof(s_ccAttr) / sizeof(TPMA_CC) - VENDOR_COMMAND_ARRAY_SIZE - 2));
while(min <= max)
{
commandIndex = (min + max + 1) / 2;
diff = GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, commandIndex)
- searchIndex;
if(diff == 0)
return commandIndex;
if(diff > 0)
max = commandIndex - 1;
else
min = commandIndex + 1;
}
// didn't find and exact match. commandIndex will be pointing at the
// last item tested. If diff is positive, then the last item tested was
// larger index of the command code so it is the smallest value
// larger than the requested value.
if(diff > 0)
return commandIndex;
// if diff is negative, then the value tested was smaller than
// the commandCode index and the next higher value is the correct one.
// Note: this will necessarily be in range because of the earlier check
// that the index was within range.
return commandIndex + 1;
#else
// The list is not compressed so offset into the array by the command
// code value of the first entry in the list. Then go find the first
// implemented command.
return NextImplementedIndex(searchIndex
- (COMMAND_INDEX)GET_ATTRIBUTE(s_ccAttr[0], TPMA_CC, commandIndex)); // libtpms changed
// The list is not compressed so offset into the array by the command
// code value of the first entry in the list. Then go find the first
// implemented command.
return NextImplementedIndex(
searchIndex - (COMMAND_INDEX)GET_ATTRIBUTE(s_ccAttr[0], TPMA_CC, commandIndex)); // libtpms changed
#endif
}
}
}
/* 9.3.3.3 CommandCodeToComandIndex() */
/* This function returns the index in the various attributes arrays of the command. */
/* Return Values Meaning */
/* UNIMPLEMENTED_COMMAND_INDEX command is not implemented */
/* other index of the command */
//*** CommandCodeToComandIndex()
// This function returns the index in the various attributes arrays of the
// command.
// Return Type: COMMAND_INDEX
// UNIMPLEMENTED_COMMAND_INDEX command is not implemented
// other index of the command
COMMAND_INDEX
CommandCodeToCommandIndex(
TPM_CC commandCode // IN: the command code to look up
)
CommandCodeToCommandIndex(TPM_CC commandCode // IN: the command code to look up
)
{
// Extract the low 16-bits of the command code to get the starting search index
COMMAND_INDEX searchIndex = (COMMAND_INDEX)commandCode;
BOOL vendor = (commandCode & CC_VEND) != 0;
COMMAND_INDEX commandIndex;
COMMAND_INDEX searchIndex = (COMMAND_INDEX)commandCode;
BOOL vendor = (commandCode & CC_VEND) != 0;
COMMAND_INDEX commandIndex;
#if !COMPRESSED_LISTS
if(!vendor)
{
commandIndex = searchIndex - (COMMAND_INDEX)GET_ATTRIBUTE(s_ccAttr[0], TPMA_CC, commandIndex); // libtpms changed
// Check for out of range or unimplemented.
// Note, since a COMMAND_INDEX is unsigned, if searchIndex is smaller than
// the lowest value of command, it will become a 'negative' number making
// it look like a large unsigned number, this will cause it to fail
// the unsigned check below.
if(commandIndex >= LIBRARY_COMMAND_ARRAY_SIZE
|| (s_commandAttributes[commandIndex] & IS_IMPLEMENTED) == 0
|| !RuntimeCommandsCheckEnabled(&g_RuntimeProfile.RuntimeCommands,// libtpms added
commandCode)) // libtpms added
return UNIMPLEMENTED_COMMAND_INDEX;
return commandIndex;
}
{
commandIndex = searchIndex - (COMMAND_INDEX)GET_ATTRIBUTE(s_ccAttr[0], TPMA_CC, commandIndex); // libtpms changed
// Check for out of range or unimplemented.
// Note, since a COMMAND_INDEX is unsigned, if searchIndex is smaller than
// the lowest value of command, it will become a 'negative' number making
// it look like a large unsigned number, this will cause it to fail
// the unsigned check below.
if(commandIndex >= LIBRARY_COMMAND_ARRAY_SIZE
|| (s_commandAttributes[commandIndex] & IS_IMPLEMENTED) == 0
|| !RuntimeCommandsCheckEnabled(&g_RuntimeProfile.RuntimeCommands, // libtpms added
commandCode)) // libtpms added
return UNIMPLEMENTED_COMMAND_INDEX;
return commandIndex;
}
#endif
// Need this code for any vendor code lookup or for compressed lists
commandIndex = GetClosestCommandIndex(commandCode);
// Look at the returned value from get closest. If it isn't the one that was
// requested, then the command is not implemented.
// libtpms: Or it may be runtime-disabled
if(commandIndex != UNIMPLEMENTED_COMMAND_INDEX)
{
if((GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, commandIndex)
!= searchIndex)
|| (IS_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, V)) != vendor
|| !RuntimeCommandsCheckEnabled(&g_RuntimeProfile.RuntimeCommands,// libtpms added
commandCode)) // libtpms added
commandIndex = UNIMPLEMENTED_COMMAND_INDEX;
}
{
if((GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, commandIndex)
!= searchIndex)
|| (IS_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, V)) != vendor
|| !RuntimeCommandsCheckEnabled(&g_RuntimeProfile.RuntimeCommands, // libtpms added
commandCode)) // libtpms added
commandIndex = UNIMPLEMENTED_COMMAND_INDEX;
}
return commandIndex;
}
/* 9.3.3.4 GetNextCommandIndex() */
/* This function returns the index of the next implemented command. */
/* Return Values Meaning */
/* UNIMPLEMENTED_COMMAND_INDEX no more implemented commands */
/* other the index of the next implemented command */
//*** GetNextCommandIndex()
// This function returns the index of the next implemented command.
// Return Type: COMMAND_INDEX
// UNIMPLEMENTED_COMMAND_INDEX no more implemented commands
// other the index of the next implemented command
COMMAND_INDEX
GetNextCommandIndex(
COMMAND_INDEX commandIndex // IN: the starting index
)
GetNextCommandIndex(COMMAND_INDEX commandIndex // IN: the starting index
)
{
while(++commandIndex < COMMAND_COUNT)
{
if(!RuntimeCommandsCheckEnabled(&g_RuntimeProfile.RuntimeCommands, // libtpms added begin
GET_ATTRIBUTE(s_ccAttr[commandIndex],
TPMA_CC, commandIndex)))
continue; // libtpms added end
{
if(!RuntimeCommandsCheckEnabled(&g_RuntimeProfile.RuntimeCommands, // libtpms added begin
GET_ATTRIBUTE(s_ccAttr[commandIndex],
TPMA_CC, commandIndex)))
continue; // libtpms added end
#if !COMPRESSED_LISTS
if(s_commandAttributes[commandIndex] & IS_IMPLEMENTED)
if(s_commandAttributes[commandIndex] & IS_IMPLEMENTED)
#endif
return commandIndex;
}
return commandIndex;
}
return UNIMPLEMENTED_COMMAND_INDEX;
}
/* 9.3.3.5 GetCommandCode() */
/* This function returns the commandCode associated with the command index */
//*** GetCommandCode()
// This function returns the commandCode associated with the command index
TPM_CC
GetCommandCode(
COMMAND_INDEX commandIndex // IN: the command index
)
GetCommandCode(COMMAND_INDEX commandIndex // IN: the command index
)
{
TPM_CC commandCode = GET_ATTRIBUTE(s_ccAttr[commandIndex],
TPMA_CC, commandIndex);
TPM_CC commandCode = GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, commandIndex);
if(IS_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, V))
commandCode += CC_VEND;
commandCode += CC_VEND;
return commandCode;
}
/* 9.3.3.6 CommandAuthRole() */
/* This function returns the authorization role required of a handle. */
/* Return Values Meaning */
/* AUTH_NONE no authorization is required */
/* AUTH_USER user role authorization is required */
/* AUTH_ADMIN admin role authorization is required */
/* AUTH_DUP duplication role authorization is required */
//*** CommandAuthRole()
//
// This function returns the authorization role required of a handle.
//
// Return Type: AUTH_ROLE
// AUTH_NONE no authorization is required
// AUTH_USER user role authorization is required
// AUTH_ADMIN admin role authorization is required
// AUTH_DUP duplication role authorization is required
AUTH_ROLE
CommandAuthRole(
COMMAND_INDEX commandIndex, // IN: command index
UINT32 handleIndex // IN: handle index (zero based)
)
CommandAuthRole(COMMAND_INDEX commandIndex, // IN: command index
UINT32 handleIndex // IN: handle index (zero based)
)
{
if(0 == handleIndex)
{
// Any authorization role set?
COMMAND_ATTRIBUTES properties = s_commandAttributes[commandIndex];
if(properties & HANDLE_1_USER)
return AUTH_USER;
if(properties & HANDLE_1_ADMIN)
return AUTH_ADMIN;
if(properties & HANDLE_1_DUP)
return AUTH_DUP;
}
{
// Any authorization role set?
COMMAND_ATTRIBUTES properties = s_commandAttributes[commandIndex];
if(properties & HANDLE_1_USER)
return AUTH_USER;
if(properties & HANDLE_1_ADMIN)
return AUTH_ADMIN;
if(properties & HANDLE_1_DUP)
return AUTH_DUP;
}
else if(1 == handleIndex)
{
if(s_commandAttributes[commandIndex] & HANDLE_2_USER)
return AUTH_USER;
}
{
if(s_commandAttributes[commandIndex] & HANDLE_2_USER)
return AUTH_USER;
}
return AUTH_NONE;
}
/* 9.3.3.7 EncryptSize() */
/* This function returns the size of the decrypt size field. This function returns 0 if encryption
is not allowed */
/* Return Values Meaning */
/* 0 encryption not allowed */
/* 2 size field is two bytes */
/* 4 size field is four bytes */
int
EncryptSize(
COMMAND_INDEX commandIndex // IN: command index
)
//*** EncryptSize()
// This function returns the size of the decrypt size field. This function returns
// 0 if encryption is not allowed
// Return Type: int
// 0 encryption not allowed
// 2 size field is two bytes
// 4 size field is four bytes
int EncryptSize(COMMAND_INDEX commandIndex // IN: command index
)
{
return ((s_commandAttributes[commandIndex] & ENCRYPT_2) ? 2 :
(s_commandAttributes[commandIndex] & ENCRYPT_4) ? 4 : 0);
return ((s_commandAttributes[commandIndex] & ENCRYPT_2) ? 2
: (s_commandAttributes[commandIndex] & ENCRYPT_4) ? 4
: 0);
}
/* 9.3.3.8 DecryptSize() */
/* This function returns the size of the decrypt size field. This function returns 0 if decryption
is not allowed */
/* Return Values Meaning */
/* 0 encryption not allowed */
/* 2 size field is two bytes */
/* 4 size field is four bytes */
int
DecryptSize(
COMMAND_INDEX commandIndex // IN: command index
)
//*** DecryptSize()
// This function returns the size of the decrypt size field. This function returns
// 0 if decryption is not allowed
// Return Type: int
// 0 encryption not allowed
// 2 size field is two bytes
// 4 size field is four bytes
int DecryptSize(COMMAND_INDEX commandIndex // IN: command index
)
{
return ((s_commandAttributes[commandIndex] & DECRYPT_2) ? 2 :
(s_commandAttributes[commandIndex] & DECRYPT_4) ? 4 : 0);
return ((s_commandAttributes[commandIndex] & DECRYPT_2) ? 2
: (s_commandAttributes[commandIndex] & DECRYPT_4) ? 4
: 0);
}
/* 9.3.3.9 IsSessionAllowed() */
/* This function indicates if the command is allowed to have sessions. */
/* This function must not be called if the command is not known to be implemented. */
/* Return Values Meaning */
/* TRUE session is allowed with this command */
/* FALSE session is not allowed with this command */
BOOL
IsSessionAllowed(
COMMAND_INDEX commandIndex // IN: the command to be checked
)
//*** IsSessionAllowed()
//
// This function indicates if the command is allowed to have sessions.
//
// This function must not be called if the command is not known to be implemented.
//
// Return Type: BOOL
// TRUE(1) session is allowed with this command
// FALSE(0) session is not allowed with this command
BOOL IsSessionAllowed(COMMAND_INDEX commandIndex // IN: the command to be checked
)
{
return ((s_commandAttributes[commandIndex] & NO_SESSIONS) == 0);
}
/* 9.3.3.10 IsHandleInResponse() */
/* This function determines if a command has a handle in the response */
BOOL
IsHandleInResponse(
COMMAND_INDEX commandIndex
)
//*** IsHandleInResponse()
// This function determines if a command has a handle in the response
BOOL IsHandleInResponse(COMMAND_INDEX commandIndex)
{
return ((s_commandAttributes[commandIndex] & R_HANDLE) != 0);
}
/* 9.3.3.11 IsWriteOperation() */
/* Checks to see if an operation will write to an NV Index and is subject to being blocked by
read-lock */
BOOL
IsWriteOperation(
COMMAND_INDEX commandIndex // IN: Command to check
)
//*** IsWriteOperation()
// Checks to see if an operation will write to an NV Index and is subject to being
// blocked by read-lock
BOOL IsWriteOperation(COMMAND_INDEX commandIndex // IN: Command to check
)
{
#ifdef WRITE_LOCK
#ifdef WRITE_LOCK
return ((s_commandAttributes[commandIndex] & WRITE_LOCK) != 0);
#else
if(!IS_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, V))
{
switch(GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, commandIndex))
{
case TPM_CC_NV_Write:
#if CC_NV_Increment
case TPM_CC_NV_Increment:
#endif
#if CC_NV_SetBits
case TPM_CC_NV_SetBits:
#endif
#if CC_NV_Extend
case TPM_CC_NV_Extend:
#endif
#if CC_AC_Send
case TPM_CC_AC_Send:
#endif
// NV write lock counts as a write operation for authorization purposes.
// We check to see if the NV is write locked before we do the
// authorization. If it is locked, we fail the command early.
case TPM_CC_NV_WriteLock:
return TRUE;
default:
break;
}
}
{
switch(GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, commandIndex))
{
case TPM_CC_NV_Write:
# if CC_NV_Increment
case TPM_CC_NV_Increment:
# endif
# if CC_NV_SetBits
case TPM_CC_NV_SetBits:
# endif
# if CC_NV_Extend
case TPM_CC_NV_Extend:
# endif
# if CC_AC_Send
case TPM_CC_AC_Send:
# endif
// NV write lock counts as a write operation for authorization purposes.
// We check to see if the NV is write locked before we do the
// authorization. If it is locked, we fail the command early.
case TPM_CC_NV_WriteLock:
return TRUE;
default:
break;
}
}
return FALSE;
#endif
}
/* 9.3.3.12 IsReadOperation() */
/* Checks to see if an operation will write to an NV Index and is subject to being blocked by
write-lock. */
BOOL
IsReadOperation(
COMMAND_INDEX commandIndex // IN: Command to check
)
//*** IsReadOperation()
// Checks to see if an operation will write to an NV Index and is
// subject to being blocked by write-lock.
BOOL IsReadOperation(COMMAND_INDEX commandIndex // IN: Command to check
)
{
#ifdef READ_LOCK
#ifdef READ_LOCK
return ((s_commandAttributes[commandIndex] & READ_LOCK) != 0);
#else
if(!IS_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, V))
{
switch(GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, commandIndex))
{
case TPM_CC_NV_Read:
case TPM_CC_PolicyNV:
case TPM_CC_NV_Certify:
// NV read lock counts as a read operation for authorization purposes.
// We check to see if the NV is read locked before we do the
// authorization. If it is locked, we fail the command early.
case TPM_CC_NV_ReadLock:
return TRUE;
default:
break;
}
}
{
switch(GET_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, commandIndex))
{
case TPM_CC_NV_Read:
case TPM_CC_PolicyNV:
case TPM_CC_NV_Certify:
// NV read lock counts as a read operation for authorization purposes.
// We check to see if the NV is read locked before we do the
// authorization. If it is locked, we fail the command early.
case TPM_CC_NV_ReadLock:
return TRUE;
default:
break;
}
}
return FALSE;
#endif
}
/* 9.3.3.13 CommandCapGetCCList() */
/* This function returns a list of implemented commands and command attributes starting from the
command in commandCode. */
/* Return Values Meaning */
/* YES more command attributes are available */
/* NO no more command attributes are available */
//*** CommandCapGetCCList()
// This function returns a list of implemented commands and command attributes
// starting from the command in 'commandCode'.
// Return Type: TPMI_YES_NO
// YES more command attributes are available
// NO no more command attributes are available
TPMI_YES_NO
CommandCapGetCCList(
TPM_CC commandCode, // IN: start command code
UINT32 count, // IN: maximum count for number of entries in
// 'commandList'
TPML_CCA *commandList // OUT: list of TPMA_CC
)
CommandCapGetCCList(TPM_CC commandCode, // IN: start command code
UINT32 count, // IN: maximum count for number of entries in
// 'commandList'
TPML_CCA* commandList // OUT: list of TPMA_CC
)
{
TPMI_YES_NO more = NO;
COMMAND_INDEX commandIndex;
TPMI_YES_NO more = NO;
COMMAND_INDEX commandIndex;
// initialize output handle list count
commandList->count = 0;
for(commandIndex = GetClosestCommandIndex(commandCode);
commandIndex != UNIMPLEMENTED_COMMAND_INDEX;
commandIndex = GetNextCommandIndex(commandIndex))
{
commandIndex != UNIMPLEMENTED_COMMAND_INDEX;
commandIndex = GetNextCommandIndex(commandIndex))
{
#if !COMPRESSED_LISTS
// this check isn't needed for compressed lists.
if(!(s_commandAttributes[commandIndex] & IS_IMPLEMENTED))
continue;
// this check isn't needed for compressed lists.
if(!(s_commandAttributes[commandIndex] & IS_IMPLEMENTED))
continue;
#endif
if (!RuntimeCommandsCheckEnabled(&g_RuntimeProfile.RuntimeCommands, // libtpms added begin
GET_ATTRIBUTE(s_ccAttr[commandIndex],
TPMA_CC, commandIndex)))
continue; // libtpms added end
if(commandList->count < count)
{
// If the list is not full, add the attributes for this command.
commandList->commandAttributes[commandList->count]
= s_ccAttr[commandIndex];
commandList->count++;
}
else
{
// If the list is full but there are more commands to report,
// indicate this and return.
more = YES;
break;
}
}
if (!RuntimeCommandsCheckEnabled(&g_RuntimeProfile.RuntimeCommands, // libtpms added begin
GET_ATTRIBUTE(s_ccAttr[commandIndex],
TPMA_CC, commandIndex)))
continue; // libtpms added end
if(commandList->count < count)
{
// If the list is not full, add the attributes for this command.
commandList->commandAttributes[commandList->count] =
s_ccAttr[commandIndex];
commandList->count++;
}
else
{
// If the list is full but there are more commands to report,
// indicate this and return.
more = YES;
break;
}
}
return more;
}
//*** CommandCapGetOneCC()
// This function checks whether a command is implemented, and returns its
// attributes if so.
BOOL CommandCapGetOneCC(TPM_CC commandCode, // IN: command code
TPMA_CC* commandAttributes // OUT: command attributes
)
TPMA_CC* commandAttributes // OUT: command attributes
)
{
COMMAND_INDEX commandIndex = CommandCodeToCommandIndex(commandCode);
if(commandIndex != UNIMPLEMENTED_COMMAND_INDEX)
{
*commandAttributes = s_ccAttr[commandIndex];
return TRUE;
}
{
*commandAttributes = s_ccAttr[commandIndex];
return TRUE;
}
return FALSE;
}
#if 0 /* libtpms added */
/* 9.3.3.14 IsVendorCommand() */
/* Function indicates if a command index references a vendor command. */
/* Return Values Meaning */
/* TRUE command is a vendor command */
/* FALSE command is not a vendor command */
BOOL
IsVendorCommand(
COMMAND_INDEX commandIndex // IN: command index to check
)
//*** IsVendorCommand()
// Function indicates if a command index references a vendor command.
// Return Type: BOOL
// TRUE(1) command is a vendor command
// FALSE(0) command is not a vendor command
BOOL IsVendorCommand(COMMAND_INDEX commandIndex // IN: command index to check
)
{
return (IS_ATTRIBUTE(s_ccAttr[commandIndex], TPMA_CC, V));
}
#endif /* libtpms added */

View File

@ -58,70 +58,141 @@
/* */
/********************************************************************************/
#ifndef COMMANDCODEATTRIBUTES_FP_H
#define COMMANDCODEATTRIBUTES_FP_H
/*(Auto-generated)
* Created by TpmPrototypes; Version 3.0 July 18, 2017
* Date: Mar 28, 2019 Time: 08:25:19PM
*/
#ifndef _COMMAND_CODE_ATTRIBUTES_FP_H_
#define _COMMAND_CODE_ATTRIBUTES_FP_H_
//*** GetClosestCommandIndex()
// This function returns the command index for the command with a value that is
// equal to or greater than the input value
// Return Type: COMMAND_INDEX
// UNIMPLEMENTED_COMMAND_INDEX command is not implemented
// other index of a command
COMMAND_INDEX
GetClosestCommandIndex(
TPM_CC commandCode // IN: the command code to start at
);
GetClosestCommandIndex(TPM_CC commandCode // IN: the command code to start at
);
//*** CommandCodeToComandIndex()
// This function returns the index in the various attributes arrays of the
// command.
// Return Type: COMMAND_INDEX
// UNIMPLEMENTED_COMMAND_INDEX command is not implemented
// other index of the command
COMMAND_INDEX
CommandCodeToCommandIndex(
TPM_CC commandCode // IN: the command code to look up
);
CommandCodeToCommandIndex(TPM_CC commandCode // IN: the command code to look up
);
//*** GetNextCommandIndex()
// This function returns the index of the next implemented command.
// Return Type: COMMAND_INDEX
// UNIMPLEMENTED_COMMAND_INDEX no more implemented commands
// other the index of the next implemented command
COMMAND_INDEX
GetNextCommandIndex(
COMMAND_INDEX commandIndex // IN: the starting index
);
GetNextCommandIndex(COMMAND_INDEX commandIndex // IN: the starting index
);
//*** GetCommandCode()
// This function returns the commandCode associated with the command index
TPM_CC
GetCommandCode(
COMMAND_INDEX commandIndex // IN: the command index
);
GetCommandCode(COMMAND_INDEX commandIndex // IN: the command index
);
//*** CommandAuthRole()
//
// This function returns the authorization role required of a handle.
//
// Return Type: AUTH_ROLE
// AUTH_NONE no authorization is required
// AUTH_USER user role authorization is required
// AUTH_ADMIN admin role authorization is required
// AUTH_DUP duplication role authorization is required
AUTH_ROLE
CommandAuthRole(
COMMAND_INDEX commandIndex, // IN: command index
UINT32 handleIndex // IN: handle index (zero based)
);
int
EncryptSize(
COMMAND_INDEX commandIndex // IN: command index
);
int
DecryptSize(
COMMAND_INDEX commandIndex // IN: command index
);
BOOL
IsSessionAllowed(
COMMAND_INDEX commandIndex // IN: the command to be checked
);
BOOL
IsHandleInResponse(
COMMAND_INDEX commandIndex
);
BOOL
IsWriteOperation(
COMMAND_INDEX commandIndex // IN: Command to check
);
BOOL
IsReadOperation(
COMMAND_INDEX commandIndex // IN: Command to check
);
CommandAuthRole(COMMAND_INDEX commandIndex, // IN: command index
UINT32 handleIndex // IN: handle index (zero based)
);
//*** EncryptSize()
// This function returns the size of the decrypt size field. This function returns
// 0 if encryption is not allowed
// Return Type: int
// 0 encryption not allowed
// 2 size field is two bytes
// 4 size field is four bytes
int EncryptSize(COMMAND_INDEX commandIndex // IN: command index
);
//*** DecryptSize()
// This function returns the size of the decrypt size field. This function returns
// 0 if decryption is not allowed
// Return Type: int
// 0 encryption not allowed
// 2 size field is two bytes
// 4 size field is four bytes
int DecryptSize(COMMAND_INDEX commandIndex // IN: command index
);
//*** IsSessionAllowed()
//
// This function indicates if the command is allowed to have sessions.
//
// This function must not be called if the command is not known to be implemented.
//
// Return Type: BOOL
// TRUE(1) session is allowed with this command
// FALSE(0) session is not allowed with this command
BOOL IsSessionAllowed(COMMAND_INDEX commandIndex // IN: the command to be checked
);
//*** IsHandleInResponse()
// This function determines if a command has a handle in the response
BOOL IsHandleInResponse(COMMAND_INDEX commandIndex);
//*** IsWriteOperation()
// Checks to see if an operation will write to an NV Index and is subject to being
// blocked by read-lock
BOOL IsWriteOperation(COMMAND_INDEX commandIndex // IN: Command to check
);
//*** IsReadOperation()
// Checks to see if an operation will write to an NV Index and is
// subject to being blocked by write-lock.
BOOL IsReadOperation(COMMAND_INDEX commandIndex // IN: Command to check
);
//*** CommandCapGetCCList()
// This function returns a list of implemented commands and command attributes
// starting from the command in 'commandCode'.
// Return Type: TPMI_YES_NO
// YES more command attributes are available
// NO no more command attributes are available
TPMI_YES_NO
CommandCapGetCCList(
TPM_CC commandCode, // IN: start command code
UINT32 count, // IN: maximum count for number of entries in
// 'commandList'
TPML_CCA *commandList // OUT: list of TPMA_CC
);
CommandCapGetCCList(TPM_CC commandCode, // IN: start command code
UINT32 count, // IN: maximum count for number of entries in
// 'commandList'
TPML_CCA* commandList // OUT: list of TPMA_CC
);
//*** CommandCapGetOneCC()
// This function checks whether a command is implemented, and returns its
// attributes if so.
BOOL CommandCapGetOneCC(TPM_CC commandCode, // IN: command code
TPMA_CC* commandAttributes // OUT: Command attributes
);
TPMA_CC* commandAttributes // OUT: Command attributes
);
#if 0 /* libtpms added */
BOOL
IsVendorCommand(
COMMAND_INDEX commandIndex // IN: command index to check
);
//*** IsVendorCommand()
// Function indicates if a command index references a vendor command.
// Return Type: BOOL
// TRUE(1) command is a vendor command
// FALSE(0) command is not a vendor command
BOOL IsVendorCommand(COMMAND_INDEX commandIndex // IN: command index to check
);
#endif /* libtpms added */
#endif
#endif // _COMMAND_CODE_ATTRIBUTES_FP_H_

File diff suppressed because it is too large Load Diff

View File

@ -59,350 +59,424 @@
/* */
/********************************************************************************/
/* 6.3 CommandDispatcher.c */
/* CommandDispatcher() performs the following operations: */
/* * unmarshals command parameters from the input buffer; */
/* NOTE Unlike other unmarshaling functions, parmBufferStart does not advance. parmBufferSize Is
reduced. */
/* * invokes the function that performs the command actions; */
/* * marshals the returned handles, if any; and */
/* * marshals the returned parameters, if any, into the output buffer putting in the
* parameterSize field if authorization sessions are present. */
/* NOTE 1 The output buffer is the return from the MemoryGetResponseBuffer() function. It includes
the header, handles, response parameters, and authorization area. respParmSize is the response
parameter size, and does not include the header, handles, or authorization area. */
/* NOTE 2 The reference implementation is permitted to do compare operations over a union as a byte
array. Therefore, the command parameter in structure must be initialized (e.g., zeroed) before
unmarshaling so that the compare operation is valid in cases where some bytes are unused. */
/* 6.3.1.1 Includes and Typedefs */
//* Includes and Typedefs
#include "Tpm.h"
// #include "Marshal.h" kgold
#include "Marshal.h"
#if TABLE_DRIVEN_DISPATCH || TABLE_DRIVEN_MARSHAL
typedef TPM_RC(NoFlagFunction)(void* target, BYTE** buffer, INT32* size);
typedef TPM_RC(FlagFunction)(void* target, BYTE** buffer, INT32* size, BOOL flag);
typedef FlagFunction* UNMARSHAL_t;
typedef INT16(MarshalFunction)(void* source, BYTE** buffer, INT32* size);
typedef MarshalFunction* MARSHAL_t;
#if TABLE_DRIVEN_DISPATCH
typedef TPM_RC(NoFlagFunction)(void *target, BYTE **buffer, INT32 *size);
typedef TPM_RC(FlagFunction)(void *target, BYTE **buffer, INT32 *size, BOOL flag);
typedef FlagFunction *UNMARSHAL_t;
typedef INT16(MarshalFunction)(void *source, BYTE **buffer, INT32 *size);
typedef MarshalFunction *MARSHAL_t;
typedef TPM_RC(COMMAND_NO_ARGS)(void);
typedef TPM_RC(COMMAND_IN_ARG)(void *in);
typedef TPM_RC(COMMAND_OUT_ARG)(void *out);
typedef TPM_RC(COMMAND_INOUT_ARG)(void *in, void *out);
typedef union
typedef TPM_RC(COMMAND_IN_ARG)(void* in);
typedef TPM_RC(COMMAND_OUT_ARG)(void* out);
typedef TPM_RC(COMMAND_INOUT_ARG)(void* in, void* out);
typedef union COMMAND_t
{
COMMAND_NO_ARGS *noArgs;
COMMAND_IN_ARG *inArg;
COMMAND_OUT_ARG *outArg;
COMMAND_INOUT_ARG *inOutArg;
COMMAND_NO_ARGS* noArgs;
COMMAND_IN_ARG* inArg;
COMMAND_OUT_ARG* outArg;
COMMAND_INOUT_ARG* inOutArg;
} COMMAND_t;
typedef struct
// This structure is used by ParseHandleBuffer() and CommandDispatcher(). The
// parameters in this structure are unique for each command. The parameters are:
// command holds the address of the command processing function that is called
// by Command Dispatcher
// inSize This is the size of the command-dependent input structure. The
// input structure holds the unmarshaled handles and command
// parameters. If the command takes no arguments (handles or
// parameters) then inSize will have a value of 0.
// outSize This is the size of the command-dependent output structure. The
// output structure holds the results of the command in an unmarshaled
// form. When command processing is completed, these values are
// marshaled into the output buffer. It is always the case that the
// unmarshaled version of an output structure is larger then the
// marshaled version. This is because the marshaled version contains
// the exact same number of significant bytes but with padding removed.
// typesOffsets This parameter points to the list of data types that are to be
// marshaled or unmarshaled. The list of types follows the 'offsets'
// array. The offsets array is variable sized so the typesOffset filed
// is necessary for the handle and command processing to be able to
// find the types that are being handled. The 'offsets' array may be
// empty. The 'types' structure is described below.
// offsets This is an array of offsets of each of the parameters in the
// command or response. When processing the command parameters (not
// handles) the list contains the offset of the next parameter. For
// example, if the first command parameter has a size of 4 and there is
// a second command parameter, then the offset would be 4, indicating
// that the second parameter starts at 4. If the second parameter has
// a size of 8, and there is a third parameter, then the second entry
// in offsets is 12 (4 for the first parameter and 8 for the second).
// An offset value of 0 in the list indicates the start of the response
// parameter list. When CommandDispatcher hits this value, it will stop
// unmarshaling the parameters and call 'command'. If a command has no
// response parameters and only one command parameter, then offsets can
// be an empty list.
typedef struct COMMAND_DESCRIPTOR_t
{
COMMAND_t command; // Address of the command
UINT16 inSize; // Maximum size of the input structure
UINT16 outSize; // Maximum size of the output structure
UINT16 typesOffset; // address of the types field
UINT16 offsets[1];
COMMAND_t command; // Address of the command
UINT16 inSize; // Maximum size of the input structure
UINT16 outSize; // Maximum size of the output structure
UINT16 typesOffset; // address of the types field
UINT16 offsets[1];
} COMMAND_DESCRIPTOR_t;
#if COMPRESSED_LISTS
# define PAD_LIST 0
// The 'types' list is an encoded byte array. The byte value has two parts. The most
// significant bit is used when a parameter takes a flag and indicates if the flag
// should be SET or not. The remaining 7 bits are an index into an array of
// addresses of marshaling and unmarshaling functions.
// The array of functions is divided into 6 sections with a value assigned
// to denote the start of that section (and the end of the previous section). The
// defined offset values for each section are:
// 0 unmarshaling for handles that do not take flags
// HANDLE_FIRST_FLAG_TYPE unmarshaling for handles that take flags
// PARAMETER_FIRST_TYPE unmarshaling for parameters that do not take flags
// PARAMETER_FIRST_FLAG_TYPE unmarshaling for parameters that take flags
// PARAMETER_LAST_TYPE + 1 marshaling for handles
// RESPONSE_PARAMETER_FIRST_TYPE marshaling for parameters
// RESPONSE_PARAMETER_LAST_TYPE is the last value in the list of marshaling and
// unmarshaling functions.
//
// The types list is constructed with a byte of 0xff at the end of the command
// parameters and with an 0xff at the end of the response parameters.
# if COMPRESSED_LISTS
# define PAD_LIST 0
# else
# define PAD_LIST 1
# endif
# define _COMMAND_TABLE_DISPATCH_
# include "CommandDispatchData.h"
# define TEST_COMMAND TPM_CC_Startup
# define NEW_CC
#else
# define PAD_LIST 1
#endif
#define _COMMAND_TABLE_DISPATCH_
#include "CommandDispatchData.h"
#define TEST_COMMAND TPM_CC_Startup
#define NEW_CC
#else
#include "Commands.h"
# include "Commands.h"
#endif
/* 6.3.1.2 Marshal/Unmarshal Functions */
/* 6.3.1.2.1 ParseHandleBuffer() */
/* This is the table-driven version of the handle buffer unmarshaling code */
//* Marshal/Unmarshal Functions
//** ParseHandleBuffer()
// This is the table-driven version of the handle buffer unmarshaling code
TPM_RC
ParseHandleBuffer(
COMMAND *command
)
ParseHandleBuffer(COMMAND* command)
{
TPM_RC result;
#if TABLE_DRIVEN_DISPATCH
COMMAND_DESCRIPTOR_t *desc;
BYTE *types;
BYTE type;
BYTE dType;
TPM_RC result;
#if TABLE_DRIVEN_DISPATCH || TABLE_DRIVEN_MARSHAL
COMMAND_DESCRIPTOR_t* desc;
BYTE* types;
BYTE type;
BYTE dType;
// Make sure that nothing strange has happened
pAssert(command->index
< sizeof(s_CommandDataArray) / sizeof(COMMAND_DESCRIPTOR_t *));
pAssert(
command->index < sizeof(s_CommandDataArray) / sizeof(COMMAND_DESCRIPTOR_t*));
// Get the address of the descriptor for this command
desc = s_CommandDataArray[command->index];
pAssert(desc != NULL);
// Get the associated list of unmarshaling data types.
types = &((BYTE *)desc)[desc->typesOffset];
types = &((BYTE*)desc)[desc->typesOffset];
// if(s_ccAttr[commandIndex].commandIndex == TEST_COMMAND)
// commandIndex = commandIndex;
// No handles yet
command->handleNum = 0;
// Get the first type value
for(type = *types++;
// check each byte to make sure that we have not hit the start
// of the parameters
(dType = (type & 0x7F)) < PARAMETER_FIRST_TYPE;
// get the next type
type = *types++)
{
#if TABLE_DRIVEN_MARSHAL
marshalIndex_t index;
index = unmarshalArray[dType] | ((type & 0x80) ? NULL_FLAG : 0);
result = Unmarshal(index, &(command->handles[command->handleNum]),
&command->parameterBuffer, &command->parameterSize);
#else
// check each byte to make sure that we have not hit the start
// of the parameters
(dType = (type & 0x7F)) < PARAMETER_FIRST_TYPE;
// get the next type
type = *types++)
{
# if TABLE_DRIVEN_MARSHAL
marshalIndex_t index;
index = unmarshalArray[dType] | ((type & 0x80) ? NULL_FLAG : 0);
result = Unmarshal(index,
&(command->handles[command->handleNum]),
&command->parameterBuffer,
&command->parameterSize);
// See if unmarshaling of this handle type requires a flag
if(dType < HANDLE_FIRST_FLAG_TYPE)
{
// Look up the function to do the unmarshaling
NoFlagFunction *f = (NoFlagFunction *)unmarshalArray[dType];
// call it
result = f(&(command->handles[command->handleNum]),
&command->parameterBuffer,
&command->parameterSize);
}
else
{
// Look up the function
FlagFunction *f = unmarshalArray[dType];
// Call it setting the flag to the appropriate value
result = f(&(command->handles[command->handleNum]),
&command->parameterBuffer,
&command->parameterSize, (type & 0x80) != 0);
}
#endif
// Got a handle
// We do this first so that the match for the handle offset of the
// response code works correctly.
command->handleNum += 1;
if(result != TPM_RC_SUCCESS)
// if the unmarshaling failed, return the response code with the
// handle indication set
return result + TPM_RC_H + (command->handleNum * TPM_RC_1);
}
# else
// See if unmarshaling of this handle type requires a flag
if(dType < HANDLE_FIRST_FLAG_TYPE)
{
// Look up the function to do the unmarshaling
NoFlagFunction* f = (NoFlagFunction*)unmarshalArray[dType];
// call it
result = f(&(command->handles[command->handleNum]),
&command->parameterBuffer,
&command->parameterSize);
}
else
{
// Look up the function
FlagFunction* f = unmarshalArray[dType];
// Call it setting the flag to the appropriate value
result = f(&(command->handles[command->handleNum]),
&command->parameterBuffer,
&command->parameterSize,
(type & 0x80) != 0);
}
# endif
// Got a handle
// We do this first so that the match for the handle offset of the
// response code works correctly.
command->handleNum += 1;
if(result != TPM_RC_SUCCESS)
// if the unmarshaling failed, return the response code with the
// handle indication set
return result + TPM_RC_H + (command->handleNum * TPM_RC_1);
}
#else
BYTE **handleBufferStart = &command->parameterBuffer;
INT32 *bufferRemainingSize = &command->parameterSize;
TPM_HANDLE *handles = &command->handles[0];
UINT32 *handleCount = &command->handleNum;
*handleCount = 0;
BYTE** handleBufferStart = &command->parameterBuffer;
INT32* bufferRemainingSize = &command->parameterSize;
TPM_HANDLE* handles = &command->handles[0];
UINT32* handleCount = &command->handleNum;
*handleCount = 0;
switch(command->code)
{
#include "HandleProcess.h"
#undef handles
default:
FAIL(FATAL_ERROR_INTERNAL);
break;
}
{
# include "HandleProcess.h"
# undef handles
default:
FAIL(FATAL_ERROR_INTERNAL);
break;
}
#endif
return TPM_RC_SUCCESS;
}
/* 6.3.1.2.2 CommandDispatcher() */
/* Function to unmarshal the command parameters, call the selected action code, and marshal the
response parameters. */
//** CommandDispatcher()
// Function to unmarshal the command parameters, call the selected action code, and
// marshal the response parameters.
TPM_RC
CommandDispatcher(
COMMAND *command
)
CommandDispatcher(COMMAND* command)
{
#if !TABLE_DRIVEN_DISPATCH
TPM_RC result;
BYTE **paramBuffer = &command->parameterBuffer;
INT32 *paramBufferSize = &command->parameterSize;
BYTE **responseBuffer = &command->responseBuffer;
INT32 *respParmSize = &command->parameterSize;
INT32 rSize;
TPM_HANDLE *handles = &command->handles[0];
command->handleNum = 0; /* The command-specific code knows how many handles there are. This
is for cataloging the number of response handles */
MemoryIoBufferAllocationReset(); /* Initialize so that allocation will work properly */
#if !TABLE_DRIVEN_DISPATCH || TABLE_DRIVEN_MARSHAL
TPM_RC result;
BYTE** paramBuffer = &command->parameterBuffer;
INT32* paramBufferSize = &command->parameterSize;
BYTE** responseBuffer = &command->responseBuffer;
INT32* respParmSize = &command->parameterSize;
INT32 rSize;
TPM_HANDLE* handles = &command->handles[0];
//
command->handleNum = 0; // The command-specific code knows how
// many handles there are. This is for
// cataloging the number of response
// handles
MemoryIoBufferAllocationReset(); // Initialize so that allocation will
// work properly
switch(GetCommandCode(command->index))
{
#include "CommandDispatcher.h"
default:
FAIL(FATAL_ERROR_INTERNAL);
break;
}
Exit:
{
# include "CommandDispatcher.h"
default:
FAIL(FATAL_ERROR_INTERNAL);
break;
}
Exit:
MemoryIoBufferZero();
return result;
#else
COMMAND_DESCRIPTOR_t *desc;
BYTE *types;
BYTE type;
UINT16 *offsets;
UINT16 offset = 0;
UINT32 maxInSize;
BYTE *commandIn;
INT32 maxOutSize;
BYTE *commandOut;
COMMAND_t cmd;
TPM_HANDLE *handles;
UINT32 hasInParameters = 0;
BOOL hasOutParameters = FALSE;
UINT32 pNum = 0;
BYTE dType; // dispatch type
TPM_RC result;
COMMAND_DESCRIPTOR_t* desc;
BYTE* types;
BYTE type;
UINT16* offsets;
UINT16 offset = 0;
UINT32 maxInSize;
BYTE* commandIn;
INT32 maxOutSize;
BYTE* commandOut;
COMMAND_t cmd;
TPM_HANDLE* handles;
UINT32 hasInParameters = 0;
BOOL hasOutParameters = FALSE;
UINT32 pNum = 0;
BYTE dType; // dispatch type
TPM_RC result;
//
// Get the address of the descriptor for this command
pAssert(command->index
< sizeof(s_CommandDataArray) / sizeof(COMMAND_DESCRIPTOR_t *));
pAssert(
command->index < sizeof(s_CommandDataArray) / sizeof(COMMAND_DESCRIPTOR_t*));
desc = s_CommandDataArray[command->index];
// Get the list of parameter types for this command
pAssert(desc != NULL);
types = &((BYTE *)desc)[desc->typesOffset];
types = &((BYTE*)desc)[desc->typesOffset];
// Get a pointer to the list of parameter offsets
offsets = &desc->offsets[0];
// pointer to handles
handles = command->handles;
// Get the size required to hold all the unmarshaled parameters for this command
maxInSize = desc->inSize;
// and the size of the output parameter structure returned by this command
maxOutSize = desc->outSize;
MemoryIoBufferAllocationReset();
// Get a buffer for the input parameters
commandIn = MemoryGetInBuffer(maxInSize);
// And the output parameters
commandOut = (BYTE *)MemoryGetOutBuffer((UINT32)maxOutSize);
commandOut = (BYTE*)MemoryGetOutBuffer((UINT32)maxOutSize);
// Get the address of the action code dispatch
cmd = desc->command;
// Copy any handles into the input buffer
for(type = *types++; (type & 0x7F) < PARAMETER_FIRST_TYPE; type = *types++)
{
// 'offset' was initialized to zero so the first unmarshaling will always
// be to the start of the data structure
*(TPM_HANDLE *)&(commandIn[offset]) = *handles++;
// This check is used so that we don't have to add an additional offset
// value to the offsets list to correspond to the stop value in the
// command parameter list.
if(*types != 0xFF)
offset = *offsets++;
// maxInSize -= sizeof(TPM_HANDLE);
hasInParameters++;
}
{
// 'offset' was initialized to zero so the first unmarshaling will always
// be to the start of the data structure
*(TPM_HANDLE*)&(commandIn[offset]) = *handles++;
// This check is used so that we don't have to add an additional offset
// value to the offsets list to correspond to the stop value in the
// command parameter list.
if(*types != 0xFF)
offset = *offsets++;
// maxInSize -= sizeof(TPM_HANDLE);
hasInParameters++;
}
// Exit loop with type containing the last value read from types
// maxInSize has the amount of space remaining in the command action input
// buffer. Make sure that we don't have more data to unmarshal than is going to
// fit.
// type contains the last value read from types so it is not necessary to
// reload it, which is good because *types now points to the next value
for(; (dType = (type & 0x7F)) <= PARAMETER_LAST_TYPE; type = *types++)
{
pNum++;
#if TABLE_DRIVEN_MARSHAL
{
marshalIndex_t index = unmarshalArray[dType];
index |= (type & 0x80) ? NULL_FLAG : 0;
result = Unmarshal(index, &commandIn[offset], &command->parameterBuffer,
&command->parameterSize);
}
#else
if(dType < PARAMETER_FIRST_FLAG_TYPE)
{
NoFlagFunction *f = (NoFlagFunction *)unmarshalArray[dType];
result = f(&commandIn[offset], &command->parameterBuffer,
&command->parameterSize);
}
else
{
FlagFunction *f = unmarshalArray[dType];
result = f(&commandIn[offset], &command->parameterBuffer,
&command->parameterSize,
(type & 0x80) != 0);
}
#endif
if(result != TPM_RC_SUCCESS)
{
result += TPM_RC_P + (TPM_RC_1 * pNum);
goto Exit;
}
// This check is used so that we don't have to add an additional offset
// value to the offsets list to correspond to the stop value in the
// command parameter list.
if(*types != 0xFF)
offset = *offsets++;
hasInParameters++;
}
{
pNum++;
# if TABLE_DRIVEN_MARSHAL
{
marshalIndex_t index = unmarshalArray[dType];
index |= (type & 0x80) ? NULL_FLAG : 0;
result = Unmarshal(index,
&commandIn[offset],
&command->parameterBuffer,
&command->parameterSize);
}
# else
if(dType < PARAMETER_FIRST_FLAG_TYPE)
{
NoFlagFunction* f = (NoFlagFunction*)unmarshalArray[dType];
result = f(&commandIn[offset],
&command->parameterBuffer,
&command->parameterSize);
}
else
{
FlagFunction* f = unmarshalArray[dType];
result = f(&commandIn[offset],
&command->parameterBuffer,
&command->parameterSize,
(type & 0x80) != 0);
}
# endif
if(result != TPM_RC_SUCCESS)
{
result += TPM_RC_P + (TPM_RC_1 * pNum);
goto Exit;
}
// This check is used so that we don't have to add an additional offset
// value to the offsets list to correspond to the stop value in the
// command parameter list.
if(*types != 0xFF)
offset = *offsets++;
hasInParameters++;
}
// Should have used all the bytes in the input
if(command->parameterSize != 0)
{
result = TPM_RC_SIZE;
goto Exit;
}
{
result = TPM_RC_SIZE;
goto Exit;
}
// The command parameter unmarshaling stopped when it hit a value that was out
// of range for unmarshaling values and left *types pointing to the first
// marshaling type. If that type happens to be the STOP value, then there
// are no response parameters. So, set the flag to indicate if there are
// output parameters.
hasOutParameters = *types != 0xFF;
// There are four cases for calling, with and without input parameters and with
// and without output parameters.
if(hasInParameters > 0)
{
if(hasOutParameters)
result = cmd.inOutArg(commandIn, commandOut);
else
result = cmd.inArg(commandIn);
}
{
if(hasOutParameters)
result = cmd.inOutArg(commandIn, commandOut);
else
result = cmd.inArg(commandIn);
}
else
{
if(hasOutParameters)
result = cmd.outArg(commandOut);
else
result = cmd.noArgs();
}
{
if(hasOutParameters)
result = cmd.outArg(commandOut);
else
result = cmd.noArgs();
}
if(result != TPM_RC_SUCCESS)
goto Exit;
goto Exit;
// Offset in the marshaled output structure
offset = 0;
// Process the return handles, if any
command->handleNum = 0;
// Could make this a loop to process output handles but there is only ever
// one handle in the outputs (for now).
type = *types++;
if((dType = (type & 0x7F)) < RESPONSE_PARAMETER_FIRST_TYPE)
{
// The out->handle value was referenced as TPM_HANDLE in the
// action code so it has to be properly aligned.
command->handles[command->handleNum++] =
*((TPM_HANDLE *)&(commandOut[offset]));
maxOutSize -= sizeof(UINT32);
type = *types++;
offset = *offsets++;
}
{
// The out->handle value was referenced as TPM_HANDLE in the
// action code so it has to be properly aligned.
command->handles[command->handleNum++] =
*((TPM_HANDLE*)&(commandOut[offset]));
maxOutSize -= sizeof(UINT32);
type = *types++;
offset = *offsets++;
}
// Use the size of the command action output buffer as the maximum for the
// number of bytes that can get marshaled. Since the marshaling code has
// no pointers to data, all of the data being returned has to be in the
// command action output buffer. If we try to marshal more bytes than
// could fit into the output buffer, we need to fail.
for(;(dType = (type & 0x7F)) <= RESPONSE_PARAMETER_LAST_TYPE
&& !g_inFailureMode; type = *types++)
{
#if TABLE_DRIVEN_MARSHAL
marshalIndex_t index = marshalArray[dType];
command->parameterSize += Marshal(index, &commandOut[offset],
&command->responseBuffer,
&maxOutSize);
#else
const MARSHAL_t f = marshalArray[dType];
command->parameterSize += f(&commandOut[offset], &command->responseBuffer,
&maxOutSize);
#endif
offset = *offsets++;
}
for(; (dType = (type & 0x7F)) <= RESPONSE_PARAMETER_LAST_TYPE && !g_inFailureMode;
type = *types++)
{
# if TABLE_DRIVEN_MARSHAL
marshalIndex_t index = marshalArray[dType];
command->parameterSize += Marshal(
index, &commandOut[offset], &command->responseBuffer, &maxOutSize);
# else
const MARSHAL_t f = marshalArray[dType];
command->parameterSize +=
f(&commandOut[offset], &command->responseBuffer, &maxOutSize);
# endif
offset = *offsets++;
}
result = (maxOutSize < 0) ? TPM_RC_FAILURE : TPM_RC_SUCCESS;
Exit:
Exit:
MemoryIoBufferZero();
return result;
#endif

View File

@ -59,17 +59,23 @@
/* */
/********************************************************************************/
#ifndef COMMANDDISPATCHER_FP_H
#define COMMANDDISPATCHER_FP_H
/*(Auto-generated)
* Created by TpmPrototypes; Version 3.0 July 18, 2017
* Date: Mar 7, 2020 Time: 07:06:44PM
*/
#ifndef _COMMAND_DISPATCHER_FP_H_
#define _COMMAND_DISPATCHER_FP_H_
//** ParseHandleBuffer()
// This is the table-driven version of the handle buffer unmarshaling code
TPM_RC
CommandDispatcher(
COMMAND *command
);
ParseHandleBuffer(COMMAND* command);
//** CommandDispatcher()
// Function to unmarshal the command parameters, call the selected action code, and
// marshal the response parameters.
TPM_RC
ParseHandleBuffer(
COMMAND *command
);
CommandDispatcher(COMMAND* command);
#endif
#endif // _COMMAND_DISPATCHER_FP_H_

View File

@ -59,36 +59,41 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef COMMIT_FP_H
#define COMMIT_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_DH_OBJECT signHandle;
TPM2B_ECC_POINT P1;
TPM2B_SENSITIVE_DATA s2;
TPM2B_ECC_PARAMETER y2;
#if CC_Commit // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_COMMIT_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_COMMIT_FP_H_
// Input structure definition
typedef struct
{
TPMI_DH_OBJECT signHandle;
TPM2B_ECC_POINT P1;
TPM2B_SENSITIVE_DATA s2;
TPM2B_ECC_PARAMETER y2;
} Commit_In;
#define RC_Commit_signHandle (TPM_RC_H + TPM_RC_1)
#define RC_Commit_P1 (TPM_RC_P + TPM_RC_1)
#define RC_Commit_s2 (TPM_RC_P + TPM_RC_2)
#define RC_Commit_y2 (TPM_RC_P + TPM_RC_3)
typedef struct {
TPM2B_ECC_POINT K;
TPM2B_ECC_POINT L;
TPM2B_ECC_POINT E;
UINT16 counter;
// Output structure definition
typedef struct
{
TPM2B_ECC_POINT K;
TPM2B_ECC_POINT L;
TPM2B_ECC_POINT E;
UINT16 counter;
} Commit_Out;
// Response code modifiers
# define RC_Commit_signHandle (TPM_RC_H + TPM_RC_1)
# define RC_Commit_P1 (TPM_RC_P + TPM_RC_1)
# define RC_Commit_s2 (TPM_RC_P + TPM_RC_2)
# define RC_Commit_y2 (TPM_RC_P + TPM_RC_3)
// Function prototype
TPM_RC
TPM2_Commit(
Commit_In *in, // IN: input parameter list
Commit_Out *out // OUT: output parameter list
);
TPM2_Commit(Commit_In* in, Commit_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_COMMIT_FP_H_
#endif // CC_Commit

View File

@ -59,26 +59,32 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef CONTEXTLOAD_FP_H
#define CONTEXTLOAD_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMS_CONTEXT context;
#if CC_ContextLoad // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_CONTEXTLOAD_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_CONTEXTLOAD_FP_H_
// Input structure definition
typedef struct
{
TPMS_CONTEXT context;
} ContextLoad_In;
#define RC_ContextLoad_context (TPM_RC_P + TPM_RC_1)
typedef struct {
TPMI_DH_CONTEXT loadedHandle;
// Output structure definition
typedef struct
{
TPMI_DH_CONTEXT loadedHandle;
} ContextLoad_Out;
// Response code modifiers
# define RC_ContextLoad_context (TPM_RC_P + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_ContextLoad(
ContextLoad_In *in, // IN: input parameter list
ContextLoad_Out *out // OUT: output parameter list
);
TPM2_ContextLoad(ContextLoad_In* in, ContextLoad_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_CONTEXTLOAD_FP_H_
#endif // CC_ContextLoad

View File

@ -59,26 +59,32 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef CONTEXTSAVE_FP_H
#define CONTEXTSAVE_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_DH_CONTEXT saveHandle;
#if CC_ContextSave // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_CONTEXTSAVE_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_CONTEXTSAVE_FP_H_
// Input structure definition
typedef struct
{
TPMI_DH_CONTEXT saveHandle;
} ContextSave_In;
#define RC_ContextSave_saveHandle (TPM_RC_P + TPM_RC_1)
typedef struct {
TPMS_CONTEXT context;
// Output structure definition
typedef struct
{
TPMS_CONTEXT context;
} ContextSave_Out;
// Response code modifiers
# define RC_ContextSave_saveHandle (TPM_RC_H + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_ContextSave(
ContextSave_In *in, // IN: input parameter list
ContextSave_Out *out // OUT: output parameter list
);
TPM2_ContextSave(ContextSave_In* in, ContextSave_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_CONTEXTSAVE_FP_H_
#endif // CC_ContextSave

View File

@ -70,18 +70,18 @@
// It is used by TPM2_ConextSave and TPM2_ContextLoad to create the symmetric
// encryption key and iv
/*(See part 1 specification)
KDFa is used to generate the symmetric encryption key and IV. The parameters
of the call are:
Symkey = KDFa(hashAlg, hProof, vendorString, sequence, handle, bits)
where
hashAlg a vendor-defined hash algorithm
hProof the hierarchy proof as selected by the hierarchy parameter
of the TPMS_CONTEXT
vendorString a value used to differentiate the uses of the KDF
sequence the sequence parameter of the TPMS_CONTEXT
handle the handle parameter of the TPMS_CONTEXT
bits the number of bits needed for a symmetric key and IV for
the context encryption
KDFa is used to generate the symmetric encryption key and IV. The parameters
of the call are:
Symkey = KDFa(hashAlg, hProof, vendorString, sequence, handle, bits)
where
hashAlg a vendor-defined hash algorithm
hProof the hierarchy proof as selected by the hierarchy parameter
of the TPMS_CONTEXT
vendorString a value used to differentiate the uses of the KDF
sequence the sequence parameter of the TPMS_CONTEXT
handle the handle parameter of the TPMS_CONTEXT
bits the number of bits needed for a symmetric key and IV for
the context encryption
*/
// Return Type: TPM_RC
// TPM_RC_FW_LIMITED The requested hierarchy is FW-limited, but the TPM
@ -92,13 +92,13 @@
// failed to derive the Firmware SVN Secret for the
// requested SVN.
TPM_RC ComputeContextProtectionKey(TPMS_CONTEXT* contextBlob, // IN: context blob
TPM2B_SYM_KEY* symKey, // OUT: the symmetric key
TPM2B_IV* iv // OUT: the IV.
)
TPM2B_SYM_KEY* symKey, // OUT: the symmetric key
TPM2B_IV* iv // OUT: the IV.
)
{
TPM_RC result = TPM_RC_SUCCESS;
UINT16 symKeyBits; // number of bits in the parent's
// symmetric key
// symmetric key
TPM2B_PROOF proof; // the proof value to use
BYTE kdfResult[sizeof(TPMU_HA) * 2]; // Value produced by the KDF
@ -124,18 +124,18 @@ TPM_RC ComputeContextProtectionKey(TPMS_CONTEXT* contextBlob, // IN: context b
// Get proof value
result = HierarchyGetProof(contextBlob->hierarchy, &proof);
if(result != TPM_RC_SUCCESS)
return result;
return result;
// KDFa to generate symmetric key and IV value
CryptKDFa(CONTEXT_INTEGRITY_HASH_ALG,
&proof.b,
CONTEXT_KEY,
&sequence2B.b,
&handle2B.b,
(symKey->t.size + iv->t.size) * 8,
kdfResult,
NULL,
FALSE);
&proof.b,
CONTEXT_KEY,
&sequence2B.b,
&handle2B.b,
(symKey->t.size + iv->t.size) * 8,
kdfResult,
NULL,
FALSE);
MemorySet(proof.b.buffer, 0, proof.b.size);
@ -155,23 +155,23 @@ TPM_RC ComputeContextProtectionKey(TPMS_CONTEXT* contextBlob, // IN: context b
// It is used by TPM2_ContextSave to create an integrity hash
// and by TPM2_ContextLoad to compare an integrity hash
/*(See part 1 specification)
The HMAC integrity computation for a saved context is:
HMACvendorAlg(hProof, resetValue {|| clearCount} || sequence || handle ||
encContext)
where
HMACvendorAlg HMAC using a vendor-defined hash algorithm
hProof the hierarchy proof as selected by the hierarchy
parameter of the TPMS_CONTEXT
resetValue either a counter value that increments on each TPM Reset
and is not reset over the lifetime of the TPM or a random
value that changes on each TPM Reset and has the size of
the digest produced by vendorAlg
clearCount a counter value that is incremented on each TPM Reset
or TPM Restart. This value is only included if the handle
value is 0x80000002.
sequence the sequence parameter of the TPMS_CONTEXT
handle the handle parameter of the TPMS_CONTEXT
encContext the encrypted context blob
The HMAC integrity computation for a saved context is:
HMACvendorAlg(hProof, resetValue {|| clearCount} || sequence || handle ||
encContext)
where
HMACvendorAlg HMAC using a vendor-defined hash algorithm
hProof the hierarchy proof as selected by the hierarchy
parameter of the TPMS_CONTEXT
resetValue either a counter value that increments on each TPM Reset
and is not reset over the lifetime of the TPM or a random
value that changes on each TPM Reset and has the size of
the digest produced by vendorAlg
clearCount a counter value that is incremented on each TPM Reset
or TPM Restart. This value is only included if the handle
value is 0x80000002.
sequence the sequence parameter of the TPMS_CONTEXT
handle the handle parameter of the TPMS_CONTEXT
encContext the encrypted context blob
*/
// Return Type: TPM_RC
// TPM_RC_FW_LIMITED The requested hierarchy is FW-limited, but the TPM
@ -182,8 +182,8 @@ TPM_RC ComputeContextProtectionKey(TPMS_CONTEXT* contextBlob, // IN: context b
// failed to derive the Firmware SVN Secret for the
// requested SVN.
TPM_RC ComputeContextIntegrity(TPMS_CONTEXT* contextBlob, // IN: context blob
TPM2B_DIGEST* integrity // OUT: integrity
)
TPM2B_DIGEST* integrity // OUT: integrity
)
{
TPM_RC result = TPM_RC_SUCCESS;
HMAC_STATE hmacState;
@ -193,11 +193,11 @@ TPM_RC ComputeContextIntegrity(TPMS_CONTEXT* contextBlob, // IN: context blob
// Get proof value
result = HierarchyGetProof(contextBlob->hierarchy, &proof);
if(result != TPM_RC_SUCCESS)
return result;
return result;
// Start HMAC
integrity->t.size =
CryptHmacStart2B(&hmacState, CONTEXT_INTEGRITY_HASH_ALG, &proof.b);
CryptHmacStart2B(&hmacState, CONTEXT_INTEGRITY_HASH_ALG, &proof.b);
MemorySet(proof.b.buffer, 0, proof.b.size);
@ -207,28 +207,28 @@ TPM_RC ComputeContextIntegrity(TPMS_CONTEXT* contextBlob, // IN: context blob
// Adding total reset counter so that the context cannot be
// used after a TPM Reset
CryptDigestUpdateInt(
&hmacState.hashState, sizeof(gp.totalResetCount), gp.totalResetCount);
&hmacState.hashState, sizeof(gp.totalResetCount), gp.totalResetCount);
// If this is a ST_CLEAR object, add the clear count
// so that this contest cannot be loaded after a TPM Restart
if(contextBlob->savedHandle == 0x80000002)
CryptDigestUpdateInt(
&hmacState.hashState, sizeof(gr.clearCount), gr.clearCount);
CryptDigestUpdateInt(
&hmacState.hashState, sizeof(gr.clearCount), gr.clearCount);
// Adding sequence number to the HMAC to make sure that it doesn't
// get changed
CryptDigestUpdateInt(
&hmacState.hashState, sizeof(contextBlob->sequence), contextBlob->sequence);
&hmacState.hashState, sizeof(contextBlob->sequence), contextBlob->sequence);
// Protect the handle
CryptDigestUpdateInt(&hmacState.hashState,
sizeof(contextBlob->savedHandle),
contextBlob->savedHandle);
sizeof(contextBlob->savedHandle),
contextBlob->savedHandle);
// Adding sensitive contextData, skip the leading integrity area
CryptDigestUpdate(&hmacState.hashState,
contextBlob->contextBlob.t.size - integritySize,
contextBlob->contextBlob.t.buffer + integritySize);
contextBlob->contextBlob.t.size - integritySize,
contextBlob->contextBlob.t.buffer + integritySize);
// Complete HMAC
CryptHmacEnd2B(&hmacState, &integrity->b);
@ -236,7 +236,7 @@ TPM_RC ComputeContextIntegrity(TPMS_CONTEXT* contextBlob, // IN: context blob
return TPM_RC_SUCCESS;
}
#if 0
#if 0 // libtpms added
//*** SequenceDataExport();
// This function is used scan through the sequence object and
// either modify the hash state data for export (contextSave) or to
@ -247,21 +247,21 @@ TPM_RC ComputeContextIntegrity(TPMS_CONTEXT* contextBlob, // IN: context blob
// same size as the internal representation so nothing outsize of the hash context
// area gets modified.
void SequenceDataExport(
HASH_OBJECT* object, // IN: an internal hash object
HASH_OBJECT_BUFFER* exportObject // OUT: a sequence context in a buffer
)
HASH_OBJECT* object, // IN: an internal hash object
HASH_OBJECT_BUFFER* exportObject // OUT: a sequence context in a buffer
)
{
// If the hash object is not an event, then only one hash context is needed
int count = (object->attributes.eventSeq) ? HASH_COUNT : 1;
for(count--; count >= 0; count--)
{
HASH_STATE* hash = &object->state.hashState[count];
size_t offset = (BYTE*)hash - (BYTE*)object;
BYTE* exportHash = &((BYTE*)exportObject)[offset];
{
HASH_STATE* hash = &object->state.hashState[count];
size_t offset = (BYTE*)hash - (BYTE*)object;
BYTE* exportHash = &((BYTE*)exportObject)[offset];
CryptHashExportState(hash, (EXPORT_HASH_STATE*)exportHash);
}
CryptHashExportState(hash, (EXPORT_HASH_STATE*)exportHash);
}
}
//*** SequenceDataImport();
@ -274,20 +274,20 @@ void SequenceDataExport(
// same size as the internal representation so nothing outsize of the hash context
// area gets modified.
void SequenceDataImport(
HASH_OBJECT* object, // IN/OUT: an internal hash object
HASH_OBJECT_BUFFER* exportObject // IN/OUT: a sequence context in a buffer
)
HASH_OBJECT* object, // IN/OUT: an internal hash object
HASH_OBJECT_BUFFER* exportObject // IN/OUT: a sequence context in a buffer
)
{
// If the hash object is not an event, then only one hash context is needed
int count = (object->attributes.eventSeq) ? HASH_COUNT : 1;
for(count--; count >= 0; count--)
{
HASH_STATE* hash = &object->state.hashState[count];
size_t offset = (BYTE*)hash - (BYTE*)object;
BYTE* importHash = &((BYTE*)exportObject)[offset];
//
CryptHashImportState(hash, (EXPORT_HASH_STATE*)importHash);
}
{
HASH_STATE* hash = &object->state.hashState[count];
size_t offset = (BYTE*)hash - (BYTE*)object;
BYTE* importHash = &((BYTE*)exportObject)[offset];
//
CryptHashImportState(hash, (EXPORT_HASH_STATE*)importHash);
}
}
#endif
#endif // libtpms added

View File

@ -79,9 +79,9 @@
// failed to derive the Firmware SVN Secret for the
// requested SVN.
TPM_RC ComputeContextProtectionKey(TPMS_CONTEXT* contextBlob, // IN: context blob
TPM2B_SYM_KEY* symKey, // OUT: the symmetric key
TPM2B_IV* iv // OUT: the IV.
);
TPM2B_SYM_KEY* symKey, // OUT: the symmetric key
TPM2B_IV* iv // OUT: the IV.
);
//*** ComputeContextIntegrity()
// Generate the integrity hash for a context
@ -96,8 +96,8 @@ TPM_RC ComputeContextProtectionKey(TPMS_CONTEXT* contextBlob, // IN: context b
// failed to derive the Firmware SVN Secret for the
// requested SVN.
TPM_RC ComputeContextIntegrity(TPMS_CONTEXT* contextBlob, // IN: context blob
TPM2B_DIGEST* integrity // OUT: integrity
);
TPM2B_DIGEST* integrity // OUT: integrity
);
//*** SequenceDataExport()
// This function is used scan through the sequence object and
@ -109,9 +109,9 @@ TPM_RC ComputeContextIntegrity(TPMS_CONTEXT* contextBlob, // IN: context blob
// same size as the internal representation so nothing outsize of the hash context
// area gets modified.
void SequenceDataExport(
HASH_OBJECT* object, // IN: an internal hash object
HASH_OBJECT_BUFFER* exportObject // OUT: a sequence context in a buffer
);
HASH_OBJECT* object, // IN: an internal hash object
HASH_OBJECT_BUFFER* exportObject // OUT: a sequence context in a buffer
);
//*** SequenceDataImport()
// This function is used scan through the sequence object and
@ -123,8 +123,8 @@ void SequenceDataExport(
// same size as the internal representation so nothing outsize of the hash context
// area gets modified.
void SequenceDataImport(
HASH_OBJECT* object, // IN/OUT: an internal hash object
HASH_OBJECT_BUFFER* exportObject // IN/OUT: a sequence context in a buffer
);
HASH_OBJECT* object, // IN/OUT: an internal hash object
HASH_OBJECT_BUFFER* exportObject // IN/OUT: a sequence context in a buffer
);
#endif // _CONTEXT_SPT_FP_H_

View File

@ -59,32 +59,39 @@
/* */
/********************************************************************************/
#ifndef CREATELOADED_FP_H
#define CREATELOADED_FP_H
/* rev 136 */
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_DH_PARENT parentHandle;
TPM2B_SENSITIVE_CREATE inSensitive;
TPM2B_TEMPLATE inPublic;
#if CC_CreateLoaded // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_CREATELOADED_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_CREATELOADED_FP_H_
// Input structure definition
typedef struct
{
TPMI_DH_PARENT parentHandle;
TPM2B_SENSITIVE_CREATE inSensitive;
TPM2B_TEMPLATE inPublic;
} CreateLoaded_In;
#define RC_CreateLoaded_parentHandle (TPM_RC_H + TPM_RC_1)
#define RC_CreateLoaded_inSensitive (TPM_RC_P + TPM_RC_1)
#define RC_CreateLoaded_inPublic (TPM_RC_P + TPM_RC_2)
typedef struct {
TPM_HANDLE objectHandle;
TPM2B_PRIVATE outPrivate;
TPM2B_PUBLIC outPublic;
TPM2B_NAME name;
// Output structure definition
typedef struct
{
TPM_HANDLE objectHandle;
TPM2B_PRIVATE outPrivate;
TPM2B_PUBLIC outPublic;
TPM2B_NAME name;
} CreateLoaded_Out;
TPM_RC
TPM2_CreateLoaded(
CreateLoaded_In *in, // IN: input parameter list
CreateLoaded_Out *out // OUT: output parameter list
);
// Response code modifiers
# define RC_CreateLoaded_parentHandle (TPM_RC_H + TPM_RC_1)
# define RC_CreateLoaded_inSensitive (TPM_RC_P + TPM_RC_1)
# define RC_CreateLoaded_inPublic (TPM_RC_P + TPM_RC_2)
#endif
// Function prototype
TPM_RC
TPM2_CreateLoaded(CreateLoaded_In* in, CreateLoaded_Out* out);
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_CREATELOADED_FP_H_
#endif // CC_CreateLoaded

View File

@ -59,38 +59,45 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef CREATEPRIMARY_FP_H
#define CREATEPRIMARY_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_RH_HIERARCHY primaryHandle;
TPM2B_SENSITIVE_CREATE inSensitive;
TPM2B_PUBLIC inPublic;
TPM2B_DATA outsideInfo;
TPML_PCR_SELECTION creationPCR;
#if CC_CreatePrimary // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_CREATEPRIMARY_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_CREATEPRIMARY_FP_H_
// Input structure definition
typedef struct
{
TPMI_RH_HIERARCHY primaryHandle;
TPM2B_SENSITIVE_CREATE inSensitive;
TPM2B_PUBLIC inPublic;
TPM2B_DATA outsideInfo;
TPML_PCR_SELECTION creationPCR;
} CreatePrimary_In;
#define RC_CreatePrimary_primaryHandle (TPM_RC_H + TPM_RC_1)
#define RC_CreatePrimary_inSensitive (TPM_RC_P + TPM_RC_1)
#define RC_CreatePrimary_inPublic (TPM_RC_P + TPM_RC_2)
#define RC_CreatePrimary_outsideInfo (TPM_RC_P + TPM_RC_3)
#define RC_CreatePrimary_creationPCR (TPM_RC_P + TPM_RC_4)
typedef struct {
TPM_HANDLE objectHandle;
TPM2B_PUBLIC outPublic;
TPM2B_CREATION_DATA creationData;
TPM2B_DIGEST creationHash;
TPMT_TK_CREATION creationTicket;
TPM2B_NAME name;
// Output structure definition
typedef struct
{
TPM_HANDLE objectHandle;
TPM2B_PUBLIC outPublic;
TPM2B_CREATION_DATA creationData;
TPM2B_DIGEST creationHash;
TPMT_TK_CREATION creationTicket;
TPM2B_NAME name;
} CreatePrimary_Out;
TPM_RC
TPM2_CreatePrimary(
CreatePrimary_In *in, // IN: input parameter list
CreatePrimary_Out *out // OUT: output parameter list
);
// Response code modifiers
# define RC_CreatePrimary_primaryHandle (TPM_RC_H + TPM_RC_1)
# define RC_CreatePrimary_inSensitive (TPM_RC_P + TPM_RC_1)
# define RC_CreatePrimary_inPublic (TPM_RC_P + TPM_RC_2)
# define RC_CreatePrimary_outsideInfo (TPM_RC_P + TPM_RC_3)
# define RC_CreatePrimary_creationPCR (TPM_RC_P + TPM_RC_4)
#endif
// Function prototype
TPM_RC
TPM2_CreatePrimary(CreatePrimary_In* in, CreatePrimary_Out* out);
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_CREATEPRIMARY_FP_H_
#endif // CC_CreatePrimary

View File

@ -59,38 +59,44 @@
/* */
/********************************************************************************/
/* rev 137 */
#ifndef CREATE_FP_H
#define CREATE_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_DH_OBJECT parentHandle;
TPM2B_SENSITIVE_CREATE inSensitive;
TPM2B_PUBLIC inPublic;
TPM2B_DATA outsideInfo;
TPML_PCR_SELECTION creationPCR;
} Create_In;
#if CC_Create // Command must be enabled
#define RC_Create_parentHandle (TPM_RC_H + TPM_RC_1)
#define RC_Create_inSensitive (TPM_RC_P + TPM_RC_1)
#define RC_Create_inPublic (TPM_RC_P + TPM_RC_2)
#define RC_Create_outsideInfo (TPM_RC_P + TPM_RC_3)
#define RC_Create_creationPCR (TPM_RC_P + TPM_RC_4)
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_CREATE_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_CREATE_FP_H_
typedef struct {
TPM2B_PRIVATE outPrivate;
TPM2B_PUBLIC outPublic;
TPM2B_CREATION_DATA creationData;
TPM2B_DIGEST creationHash;
TPMT_TK_CREATION creationTicket;
// Input structure definition
typedef struct
{
TPMI_DH_OBJECT parentHandle;
TPM2B_SENSITIVE_CREATE inSensitive;
TPM2B_PUBLIC inPublic;
TPM2B_DATA outsideInfo;
TPML_PCR_SELECTION creationPCR;
} Create_In;
// Output structure definition
typedef struct
{
TPM2B_PRIVATE outPrivate;
TPM2B_PUBLIC outPublic;
TPM2B_CREATION_DATA creationData;
TPM2B_DIGEST creationHash;
TPMT_TK_CREATION creationTicket;
} Create_Out;
// Response code modifiers
# define RC_Create_parentHandle (TPM_RC_H + TPM_RC_1)
# define RC_Create_inSensitive (TPM_RC_P + TPM_RC_1)
# define RC_Create_inPublic (TPM_RC_P + TPM_RC_2)
# define RC_Create_outsideInfo (TPM_RC_P + TPM_RC_3)
# define RC_Create_creationPCR (TPM_RC_P + TPM_RC_4)
// Function prototype
TPM_RC
TPM2_Create(
Create_In *in, // IN: input parameter list
Create_Out *out // OUT: output parameter list
);
TPM2_Create(Create_In* in, Create_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_CREATE_FP_H_
#endif // CC_Create

View File

@ -79,73 +79,73 @@
const TPM_ECC_CURVE_METADATA eccCurves[] = {
# if ECC_NIST_P192
comma{TPM_ECC_NIST_P192,
192,
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SHA256}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
OID_ECC_NIST_P192 CURVE_NAME("NIST_P192")}
192,
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SHA256}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
OID_ECC_NIST_P192 CURVE_NAME("NIST_P192")}
# undef comma
# define comma ,
# endif // ECC_NIST_P192
# if ECC_NIST_P224
comma{TPM_ECC_NIST_P224,
224,
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SHA256}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
OID_ECC_NIST_P224 CURVE_NAME("NIST_P224")}
224,
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SHA256}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
OID_ECC_NIST_P224 CURVE_NAME("NIST_P224")}
# undef comma
# define comma ,
# endif // ECC_NIST_P224
# if ECC_NIST_P256
comma{TPM_ECC_NIST_P256,
256,
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SHA256}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
OID_ECC_NIST_P256 CURVE_NAME("NIST_P256")}
256,
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SHA256}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
OID_ECC_NIST_P256 CURVE_NAME("NIST_P256")}
# undef comma
# define comma ,
# endif // ECC_NIST_P256
# if ECC_NIST_P384
comma{TPM_ECC_NIST_P384,
384,
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SHA384}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
OID_ECC_NIST_P384 CURVE_NAME("NIST_P384")}
384,
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SHA384}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
OID_ECC_NIST_P384 CURVE_NAME("NIST_P384")}
# undef comma
# define comma ,
# endif // ECC_NIST_P384
# if ECC_NIST_P521
comma{TPM_ECC_NIST_P521,
521,
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SHA512}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
OID_ECC_NIST_P521 CURVE_NAME("NIST_P521")}
521,
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SHA512}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
OID_ECC_NIST_P521 CURVE_NAME("NIST_P521")}
# undef comma
# define comma ,
# endif // ECC_NIST_P521
# if ECC_BN_P256
comma{TPM_ECC_BN_P256,
256,
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
OID_ECC_BN_P256 CURVE_NAME("BN_P256")}
256,
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
OID_ECC_BN_P256 CURVE_NAME("BN_P256")}
# undef comma
# define comma ,
# endif // ECC_BN_P256
# if ECC_BN_P638
comma{TPM_ECC_BN_P638,
638,
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
OID_ECC_BN_P638 CURVE_NAME("BN_P638")}
638,
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
OID_ECC_BN_P638 CURVE_NAME("BN_P638")}
# undef comma
# define comma ,
# endif // ECC_BN_P638
# if ECC_SM2_P256
comma{TPM_ECC_SM2_P256,
256,
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SM3_256}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
OID_ECC_SM2_P256 CURVE_NAME("SM2_P256")}
256,
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SM3_256}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
OID_ECC_SM2_P256 CURVE_NAME("SM2_P256")}
# undef comma
# define comma ,
# endif // ECC_SM2_P256

View File

@ -79,22 +79,22 @@
//*** RunSelfTest()
// Local function to run self-test
static TPM_RC CryptRunSelfTests(
ALGORITHM_VECTOR* toTest // IN: the vector of the algorithms to test
)
ALGORITHM_VECTOR* toTest // IN: the vector of the algorithms to test
)
{
TPM_ALG_ID alg;
// For each of the algorithms that are in the toTestVecor, need to run a
// test
for(alg = TPM_ALG_FIRST; alg <= TPM_ALG_LAST; alg++)
{
if(TEST_BIT(alg, *toTest))
{
TPM_RC result = CryptTestAlgorithm(alg, toTest);
if(result != TPM_RC_SUCCESS)
return result;
}
}
{
if(TEST_BIT(alg, *toTest))
{
TPM_RC result = CryptTestAlgorithm(alg, toTest);
if(result != TPM_RC_SUCCESS)
return result;
}
}
return TPM_RC_SUCCESS;
}
@ -114,19 +114,19 @@ static TPM_RC CryptRunSelfTests(
LIB_EXPORT
TPM_RC
CryptSelfTest(TPMI_YES_NO fullTest // IN: if full test is required
)
)
{
#if ALLOW_FORCE_FAILURE_MODE
if(g_forceFailureMode)
FAIL(FATAL_ERROR_FORCED);
FAIL(FATAL_ERROR_FORCED);
#endif
// If the caller requested a full test, then reset the to test vector so that
// all the tests will be run
if(fullTest == YES)
{
MemoryCopy(g_toTest, g_implementedAlgorithms, sizeof(g_toTest));
}
{
MemoryCopy(g_toTest, g_implementedAlgorithms, sizeof(g_toTest));
}
return CryptRunSelfTests(&g_toTest);
}
@ -144,8 +144,8 @@ CryptSelfTest(TPMI_YES_NO fullTest // IN: if full test is required
// TPM_RC_VALUE an algorithm in the toTest list is not implemented
TPM_RC
CryptIncrementalSelfTest(TPML_ALG* toTest, // IN: list of algorithms to be tested
TPML_ALG* toDoList // OUT: list of algorithms needing test
)
TPML_ALG* toDoList // OUT: list of algorithms needing test
)
{
ALGORITHM_VECTOR toTestVector = {0};
TPM_ALG_ID alg;
@ -153,36 +153,36 @@ CryptIncrementalSelfTest(TPML_ALG* toTest, // IN: list of algorithms to be tes
pAssert(toTest != NULL && toDoList != NULL);
if(toTest->count > 0)
{
// Transcribe the toTest list into the toTestVector
for(i = 0; i < toTest->count; i++)
{
alg = toTest->algorithms[i];
{
// Transcribe the toTest list into the toTestVector
for(i = 0; i < toTest->count; i++)
{
alg = toTest->algorithms[i];
// make sure that the algorithm value is not out of range
if((alg > TPM_ALG_LAST) || !TEST_BIT(alg, g_implementedAlgorithms))
return TPM_RC_VALUE;
// libtpms added begin
if(!RuntimeAlgorithmCheckEnabled(&g_RuntimeProfile.RuntimeAlgorithm,
alg))
return TPM_RC_VALUE;
// libtpms added end
SET_BIT(alg, toTestVector);
}
// Run the test
if(CryptRunSelfTests(&toTestVector) == TPM_RC_CANCELED)
return TPM_RC_CANCELED;
}
// make sure that the algorithm value is not out of range
if((alg > TPM_ALG_LAST) || !TEST_BIT(alg, g_implementedAlgorithms))
return TPM_RC_VALUE;
// libtpms added begin
if(!RuntimeAlgorithmCheckEnabled(&g_RuntimeProfile.RuntimeAlgorithm,
alg))
return TPM_RC_VALUE;
// libtpms added end
SET_BIT(alg, toTestVector);
}
// Run the test
if(CryptRunSelfTests(&toTestVector) == TPM_RC_CANCELED)
return TPM_RC_CANCELED;
}
// Fill in the toDoList with the algorithms that are still untested
toDoList->count = 0;
for(alg = TPM_ALG_FIRST;
toDoList->count < MAX_ALG_LIST_SIZE && alg <= TPM_ALG_LAST;
alg++)
{
if(TEST_BIT(alg, g_toTest))
toDoList->algorithms[toDoList->count++] = alg;
}
toDoList->count < MAX_ALG_LIST_SIZE && alg <= TPM_ALG_LAST;
alg++)
{
if(TEST_BIT(alg, g_toTest))
toDoList->algorithms[toDoList->count++] = alg;
}
return TPM_RC_SUCCESS;
}
@ -231,11 +231,11 @@ CryptTestAlgorithm(TPM_ALG_ID alg, ALGORITHM_VECTOR* toTest)
// will over report. This can be changed so that any call to check on which
// algorithms have tests, 'toTest' can be cleared.
if(alg != TPM_ALG_ERROR)
{
CLEAR_BIT(alg, g_toTest);
if(toTest != NULL)
CLEAR_BIT(alg, *toTest);
}
{
CLEAR_BIT(alg, g_toTest);
if(toTest != NULL)
CLEAR_BIT(alg, *toTest);
}
result = TPM_RC_SUCCESS;
#endif
return result;

View File

@ -59,29 +59,69 @@
/* */
/********************************************************************************/
#ifndef CRYPTSELFTEST_FP_H
#define CRYPTSELFTEST_FP_H
/*(Auto-generated)
* Created by TpmPrototypes; Version 3.0 July 18, 2017
* Date: Mar 4, 2020 Time: 02:36:44PM
*/
#ifndef _CRYPT_SELF_TEST_FP_H_
#define _CRYPT_SELF_TEST_FP_H_
//*** CryptSelfTest()
// This function is called to start/complete a full self-test.
// If 'fullTest' is NO, then only the untested algorithms will be run. If
// 'fullTest' is YES, then 'g_untestedDecryptionAlgorithms' is reinitialized and then
// all tests are run.
// This implementation of the reference design does not support processing outside
// the framework of a TPM command. As a consequence, this command does not
// complete until all tests are done. Since this can take a long time, the TPM
// will check after each test to see if the command is canceled. If so, then the
// TPM will returned TPM_RC_CANCELLED. To continue with the self-tests, call
// TPM2_SelfTest(fullTest == No) and the TPM will complete the testing.
// Return Type: TPM_RC
// TPM_RC_CANCELED if the command is canceled
LIB_EXPORT
TPM_RC
CryptSelfTest(
TPMI_YES_NO fullTest // IN: if full test is required
);
CryptSelfTest(TPMI_YES_NO fullTest // IN: if full test is required
);
//*** CryptIncrementalSelfTest()
// This function is used to perform an incremental self-test. This implementation
// will perform the toTest values before returning. That is, it assumes that the
// TPM cannot perform background tasks between commands.
//
// This command may be canceled. If it is, then there is no return result.
// However, this command can be run again and the incremental progress will not
// be lost.
// Return Type: TPM_RC
// TPM_RC_CANCELED processing of this command was canceled
// TPM_RC_TESTING if toTest list is not empty
// TPM_RC_VALUE an algorithm in the toTest list is not implemented
TPM_RC
CryptIncrementalSelfTest(
TPML_ALG *toTest, // IN: list of algorithms to be tested
TPML_ALG *toDoList // OUT: list of algorithms needing test
);
void
CryptInitializeToTest(
void
);
CryptIncrementalSelfTest(TPML_ALG* toTest, // IN: list of algorithms to be tested
TPML_ALG* toDoList // OUT: list of algorithms needing test
);
//*** CryptInitializeToTest()
// This function will initialize the data structures for testing all the
// algorithms. This should not be called unless CryptAlgsSetImplemented() has
// been called
void CryptInitializeToTest(void);
//*** CryptTestAlgorithm()
// Only point of contact with the actual self tests. If a self-test fails, there
// is no return and the TPM goes into failure mode.
// The call to TestAlgorithm uses an algorithm selector and a bit vector. When the
// test is run, the corresponding bit in 'toTest' and in 'g_toTest' is CLEAR. If
// 'toTest' is NULL, then only the bit in 'g_toTest' is CLEAR.
// There is a special case for the call to TestAlgorithm(). When 'alg' is
// ALG_ERROR, TestAlgorithm() will CLEAR any bit in 'toTest' for which it has
// no test. This allows the knowledge about which algorithms have test to be
// accessed through the interface that provides the test.
// Return Type: TPM_RC
// TPM_RC_CANCELED test was canceled
LIB_EXPORT
TPM_RC
CryptTestAlgorithm(
TPM_ALG_ID alg,
ALGORITHM_VECTOR *toTest
);
CryptTestAlgorithm(TPM_ALG_ID alg, ALGORITHM_VECTOR* toTest);
#endif
#endif // _CRYPT_SELF_TEST_FP_H_

File diff suppressed because it is too large Load Diff

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

@ -59,182 +59,193 @@
/* */
/********************************************************************************/
/* 8.2 DA.c */
/* 8.2.1 Introduction */
/* This file contains the functions and data definitions relating to the dictionary attack logic. */
/* 8.2.2 Includes and Data Definitions */
//** Introduction
// This file contains the functions and data definitions relating to the
// dictionary attack logic.
//** Includes and Data Definitions
#define DA_C
#include "Tpm.h"
/* 8.2.3 Functions */
/* 8.2.3.1 DAPreInstall_Init() */
/* This function initializes the DA parameters to their manufacturer-default values. The default
values are determined by a platform-specific specification. */
/* This function should not be called outside of a manufacturing or simulation environment. */
/* The DA parameters will be restored to these initial values by TPM2_Clear(). */
void
DAPreInstall_Init(
void
)
//** Functions
//*** DAPreInstall_Init()
// This function initializes the DA parameters to their manufacturer-default
// values. The default values are determined by a platform-specific specification.
//
// This function should not be called outside of a manufacturing or simulation
// environment.
//
// The DA parameters will be restored to these initial values by TPM2_Clear().
void DAPreInstall_Init(void)
{
gp.failedTries = 0;
gp.maxTries = 3;
gp.recoveryTime = 1000; // in seconds (~16.67 minutes)
gp.lockoutRecovery = 1000; // in seconds
gp.lockOutAuthEnabled = TRUE; // Use of lockoutAuth is enabled
gp.failedTries = 0;
gp.maxTries = 3;
gp.recoveryTime = 1000; // in seconds (~16.67 minutes)
gp.lockoutRecovery = 1000; // in seconds
gp.lockOutAuthEnabled = TRUE; // Use of lockoutAuth is enabled
// Record persistent DA parameter changes to NV
NV_SYNC_PERSISTENT(failedTries);
NV_SYNC_PERSISTENT(maxTries);
NV_SYNC_PERSISTENT(recoveryTime);
NV_SYNC_PERSISTENT(lockoutRecovery);
NV_SYNC_PERSISTENT(lockOutAuthEnabled);
return;
}
/* 8.2.3.2 DAStartup() */
/* This function is called by TPM2_Startup() to initialize the DA parameters. In the case of
Startup(CLEAR), use of lockoutAuth will be enabled if the lockout recovery time is 0. Otherwise,
lockoutAuth will not be enabled until the TPM has been continuously powered for the
lockoutRecovery time. */
/* This function requires that NV be available and not rate limiting. */
BOOL
DAStartup(
STARTUP_TYPE type // IN: startup type
)
//*** DAStartup()
// This function is called by TPM2_Startup() to initialize the DA parameters.
// In the case of Startup(CLEAR), use of lockoutAuth will be enabled if the
// lockout recovery time is 0. Otherwise, lockoutAuth will not be enabled until
// the TPM has been continuously powered for the lockoutRecovery time.
//
// This function requires that NV be available and not rate limiting.
BOOL DAStartup(STARTUP_TYPE type // IN: startup type
)
{
NOT_REFERENCED(type);
#if !ACCUMULATE_SELF_HEAL_TIMER
_plat__TimerWasReset();
s_selfHealTimer = 0;
s_lockoutTimer = 0;
s_lockoutTimer = 0;
#else
if(_plat__TimerWasReset())
{
if(!NV_IS_ORDERLY)
{
// If shutdown was not orderly, then don't really know if go.time has
// any useful value so reset the timer to 0. This is what the tick
// was reset to
s_selfHealTimer = 0;
s_lockoutTimer = 0;
}
else
{
// If we know how much time was accumulated at the last orderly shutdown
// subtract that from the saved timer values so that they effectively
// have the accumulated values
s_selfHealTimer -= go.time;
s_lockoutTimer -= go.time;
}
}
{
if(!NV_IS_ORDERLY)
{
// If shutdown was not orderly, then don't really know if go.time has
// any useful value so reset the timer to 0. This is what the tick
// was reset to
s_selfHealTimer = 0;
s_lockoutTimer = 0;
}
else
{
// If we know how much time was accumulated at the last orderly shutdown
// subtract that from the saved timer values so that they effectively
// have the accumulated values
s_selfHealTimer -= go.time;
s_lockoutTimer -= go.time;
}
}
#endif
// For any Startup(), if lockoutRecovery is 0, enable use of lockoutAuth.
if(gp.lockoutRecovery == 0)
{
gp.lockOutAuthEnabled = TRUE;
// Record the changes to NV
NV_SYNC_PERSISTENT(lockOutAuthEnabled);
}
{
gp.lockOutAuthEnabled = TRUE;
// Record the changes to NV
NV_SYNC_PERSISTENT(lockOutAuthEnabled);
}
// If DA has not been disabled and the previous shutdown is not orderly
// failedTries is not already at its maximum then increment 'failedTries'
if(gp.recoveryTime != 0
&& gp.failedTries < gp.maxTries
if(gp.recoveryTime != 0 && gp.failedTries < gp.maxTries
&& !IS_ORDERLY(g_prevOrderlyState))
{
{
#if USE_DA_USED
gp.failedTries += g_daUsed;
g_daUsed = FALSE;
gp.failedTries += g_daUsed;
g_daUsed = FALSE;
#else
gp.failedTries++;
gp.failedTries++;
#endif
// Record the change to NV
NV_SYNC_PERSISTENT(failedTries);
}
// Record the change to NV
NV_SYNC_PERSISTENT(failedTries);
}
// Before Startup, the TPM will not do clock updates. At startup, need to
// do a time update which will do the DA update.
TimeUpdate();
return TRUE;
}
/* 8.2.3.3 DARegisterFailure() */
/* This function is called when an authorization failure occurs on an entity that is subject to
dictionary-attack protection. When a DA failure is triggered, register the failure by resetting
the relevant self-healing timer to the current time. */
void
DARegisterFailure(
TPM_HANDLE handle // IN: handle for failure
)
//*** DARegisterFailure()
// This function is called when an authorization failure occurs on an entity
// that is subject to dictionary-attack protection. When a DA failure is
// triggered, register the failure by resetting the relevant self-healing
// timer to the current time.
void DARegisterFailure(TPM_HANDLE handle // IN: handle for failure
)
{
// Reset the timer associated with lockout if the handle is the lockoutAuth.
if(handle == TPM_RH_LOCKOUT)
s_lockoutTimer = g_time;
s_lockoutTimer = g_time;
else
s_selfHealTimer = g_time;
s_selfHealTimer = g_time;
return;
}
/* 8.2.3.4 DASelfHeal() */
/* This function is called to check if sufficient time has passed to allow decrement of failedTries
or to re-enable use of lockoutAuth. */
/* This function should be called when the time interval is updated. */
void
DASelfHeal(
void
)
//*** DASelfHeal()
// This function is called to check if sufficient time has passed to allow
// decrement of failedTries or to re-enable use of lockoutAuth.
//
// This function should be called when the time interval is updated.
void DASelfHeal(void)
{
// Regular authorization self healing logic
// If no failed authorization tries, do nothing. Otherwise, try to
// decrease failedTries
if(gp.failedTries != 0)
{
// if recovery time is 0, DA logic has been disabled. Clear failed tries
// immediately
if(gp.recoveryTime == 0)
{
gp.failedTries = 0;
// Update NV record
NV_SYNC_PERSISTENT(failedTries);
}
else
{
UINT64 decreaseCount;
#if 0 // Errata eliminates this code
// In the unlikely event that failedTries should become larger than
// maxTries
if(gp.failedTries > gp.maxTries)
gp.failedTries = gp.maxTries;
{
// if recovery time is 0, DA logic has been disabled. Clear failed tries
// immediately
if(gp.recoveryTime == 0)
{
gp.failedTries = 0;
// Update NV record
NV_SYNC_PERSISTENT(failedTries);
}
else
{
UINT64 decreaseCount;
#if 0
// Errata eliminates this code
// In the unlikely event that failedTries should become larger than
// maxTries
if(gp.failedTries > gp.maxTries)
gp.failedTries = gp.maxTries;
#endif
// How much can failedTries be decreased
// Cast s_selfHealTimer to an int in case it became negative at
// startup
decreaseCount = ((g_time - (INT64)s_selfHealTimer) / 1000)
/ gp.recoveryTime;
if(gp.failedTries <= (UINT32)decreaseCount)
// should not set failedTries below zero
gp.failedTries = 0;
else
gp.failedTries -= (UINT32)decreaseCount;
// the cast prevents overflow of the product
s_selfHealTimer += (decreaseCount * (UINT64)gp.recoveryTime) * 1000;
if(decreaseCount != 0)
// If there was a change to the failedTries, record the changes
// to NV
NV_SYNC_PERSISTENT(failedTries);
}
}
// How much can failedTries be decreased
// Cast s_selfHealTimer to an int in case it became negative at
// startup
decreaseCount =
((g_time - (INT64)s_selfHealTimer) / 1000) / gp.recoveryTime;
if(gp.failedTries <= (UINT32)decreaseCount)
// should not set failedTries below zero
gp.failedTries = 0;
else
gp.failedTries -= (UINT32)decreaseCount;
// the cast prevents overflow of the product
s_selfHealTimer += (decreaseCount * (UINT64)gp.recoveryTime) * 1000;
if(decreaseCount != 0)
// If there was a change to the failedTries, record the changes
// to NV
NV_SYNC_PERSISTENT(failedTries);
}
}
// LockoutAuth self healing logic
// If lockoutAuth is enabled, do nothing. Otherwise, try to see if we
// may enable it
if(!gp.lockOutAuthEnabled)
{
// if lockout authorization recovery time is 0, a reboot is required to
// re-enable use of lockout authorization. Self-healing would not
// apply in this case.
if(gp.lockoutRecovery != 0)
{
if(((g_time - (INT64)s_lockoutTimer) / 1000) >= gp.lockoutRecovery)
{
gp.lockOutAuthEnabled = TRUE;
// Record the changes to NV
NV_SYNC_PERSISTENT(lockOutAuthEnabled);
}
}
}
{
// if lockout authorization recovery time is 0, a reboot is required to
// re-enable use of lockout authorization. Self-healing would not
// apply in this case.
if(gp.lockoutRecovery != 0)
{
if(((g_time - (INT64)s_lockoutTimer) / 1000) >= gp.lockoutRecovery)
{
gp.lockOutAuthEnabled = TRUE;
// Record the changes to NV
NV_SYNC_PERSISTENT(lockOutAuthEnabled);
}
}
}
return;
}

View File

@ -59,29 +59,47 @@
/* */
/********************************************************************************/
#ifndef DA_FP_H
#define DA_FP_H
/*(Auto-generated)
* Created by TpmPrototypes; Version 3.0 July 18, 2017
* Date: Apr 2, 2019 Time: 04:23:27PM
*/
void
DAPreInstall_Init(
void
);
void
DAInit(
void
);
BOOL
DAStartup(
STARTUP_TYPE type // IN: startup type
);
void
DARegisterFailure(
TPM_HANDLE handle // IN: handle for failure
);
void
DASelfHeal(
void
);
#ifndef _DA_FP_H_
#define _DA_FP_H_
//*** DAPreInstall_Init()
// This function initializes the DA parameters to their manufacturer-default
// values. The default values are determined by a platform-specific specification.
//
// This function should not be called outside of a manufacturing or simulation
// environment.
//
// The DA parameters will be restored to these initial values by TPM2_Clear().
void DAPreInstall_Init(void);
#endif
//*** DAStartup()
// This function is called by TPM2_Startup() to initialize the DA parameters.
// In the case of Startup(CLEAR), use of lockoutAuth will be enabled if the
// lockout recovery time is 0. Otherwise, lockoutAuth will not be enabled until
// the TPM has been continuously powered for the lockoutRecovery time.
//
// This function requires that NV be available and not rate limiting.
BOOL DAStartup(STARTUP_TYPE type // IN: startup type
);
//*** DARegisterFailure()
// This function is called when a authorization failure occurs on an entity
// that is subject to dictionary-attack protection. When a DA failure is
// triggered, register the failure by resetting the relevant self-healing
// timer to the current time.
void DARegisterFailure(TPM_HANDLE handle // IN: handle for failure
);
//*** DASelfHeal()
// This function is called to check if sufficient time has passed to allow
// decrement of failedTries or to re-enable use of lockoutAuth.
//
// This function should be called when the time interval is updated.
void DASelfHeal(void);
#endif // _DA_FP_H_

View File

@ -59,102 +59,89 @@
/* */
/********************************************************************************/
/* C.13 DebugHelpers.c */
/* C.13.1. Description */
/* This file contains the NV read and write access methods. This implementation uses RAM/file and
does not manage the RAM/file as NV blocks. The implementation may become more sophisticated over
time. */
/* C.13.2. Includes and Local */
#include <stdio.h>
#include <time.h>
//** Description
//
// This file contains the NV read and write access methods. This implementation
// uses RAM/file and does not manage the RAM/file as NV blocks.
// The implementation may become more sophisticated over time.
//
//** Includes and Local
#include <stdio.h>
#include <time.h>
#include "Platform.h"
#include "DebugHelpers_fp.h"
#if CERTIFYX509_DEBUG
const char *debugFileName = "DebugFile.txt";
/* C.13.2.1. fileOpen() */
const char* debugFileName = "DebugFile.txt";
/* This exists to allow use of the safe version of fopen() with a MS runtime. */
static FILE *
fileOpen(
const char *fn,
const char *mode
)
//*** fileOpen()
// This exists to allow use of the 'safe' version of fopen() with a MS runtime.
static FILE* fileOpen(const char* fn, const char* mode)
{
FILE *f;
# if defined _MSC_VER
FILE* f;
# if defined _MSC_VER
if(fopen_s(&f, fn, mode) != 0)
f = NULL;
# else
f = NULL;
# else
f = fopen(fn, mode);
# endif
# endif
return f;
}
/* C.13.2.2. DebugFileInit() */
/* This function initializes the file containing the debug data with the time of the file
creation. */
/* This function opens the file used to hold the debug data. */
/* Return Value Meaning */
/* 0 success */
/* != 0 error */
int
DebugFileInit(
void
)
//*** DebugFileInit()
// This function initializes the file containing the debug data with the time of the
// file creation.
// Return Type: int
// 0 success
// != 0 error
int DebugFileInit(void)
{
FILE *f = NULL;
time_t t = time(NULL);
//
// Get current date and time.
# if defined _MSC_VER
char timeString[100];
FILE* f = NULL;
time_t t = time(NULL);
//
// Get current date and time.
# if defined _MSC_VER
char timeString[100];
ctime_s(timeString, (size_t)sizeof(timeString), &t);
# else
char *timeString;
# else
char* timeString;
timeString = ctime(&t);
# endif
# endif
// Try to open the debug file
f = fileOpen(debugFileName, "w");
if(f)
{
/* Initialize the contents with the time. */
fprintf(f, "%s\n", timeString);
fclose(f);
return 0;
}
{
// Initialize the contents with the time.
fprintf(f, "%s\n", timeString);
fclose(f);
return 0;
}
return -1;
}
/* C.13.2.3. DebugDumpBuffer() */
void
DebugDumpBuffer(
int size,
unsigned char *buf,
const char *identifier
)
//*** DebugDumpBuffer()
void DebugDumpBuffer(int size, unsigned char* buf, const char* identifier)
{
int i;
int i;
//
FILE *f = fileOpen(debugFileName, "a");
FILE* f = fileOpen(debugFileName, "a");
if(!f)
return;
return;
if(identifier)
fprintf(f, "%s\n", identifier);
fprintf(f, "%s\n", identifier);
if(buf)
{
for(i = 0; i < size; i++)
{
if(((i % 16) == 0) && (i))
fprintf(f, "\n");
fprintf(f, " %02X", buf[i]);
}
if((size % 16) != 0)
fprintf(f, "\n");
}
{
for(i = 0; i < size; i++)
{
if(((i % 16) == 0) && (i))
fprintf(f, "\n");
fprintf(f, " %02X", buf[i]);
}
if((size % 16) != 0)
fprintf(f, "\n");
}
fclose(f);
}
#endif // CERTIFYX509_DEBUG
#endif // CERTIFYX509_DEBUG

View File

@ -59,21 +59,26 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef DICTIONARYATTACKLOCKRESET_FP_H
#define DICTIONARYATTACKLOCKRESET_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_RH_LOCKOUT lockHandle;
#if CC_DictionaryAttackLockReset // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_DICTIONARYATTACKLOCKRESET_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_DICTIONARYATTACKLOCKRESET_FP_H_
// Input structure definition
typedef struct
{
TPMI_RH_LOCKOUT lockHandle;
} DictionaryAttackLockReset_In;
#define RC_DictionaryAttackLockReset_lockHandle (TPM_RC_H + TPM_RC_1)
// Response code modifiers
# define RC_DictionaryAttackLockReset_lockHandle (TPM_RC_H + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_DictionaryAttackLockReset(
DictionaryAttackLockReset_In *in // IN: input parameter list
);
TPM2_DictionaryAttackLockReset(DictionaryAttackLockReset_In* in);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_DICTIONARYATTACKLOCKRESET_FP_H_
#endif // CC_DictionaryAttackLockReset

View File

@ -59,28 +59,32 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef DICTIONARYATTACKPARAMETERS_FP_H
#define DICTIONARYATTACKPARAMETERS_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
#if CC_DictionaryAttackParameters // Command must be enabled
typedef struct {
TPMI_RH_LOCKOUT lockHandle;
UINT32 newMaxTries;
UINT32 newRecoveryTime;
UINT32 lockoutRecovery;
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_DICTIONARYATTACKPARAMETERS_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_DICTIONARYATTACKPARAMETERS_FP_H_
// Input structure definition
typedef struct
{
TPMI_RH_LOCKOUT lockHandle;
UINT32 newMaxTries;
UINT32 newRecoveryTime;
UINT32 lockoutRecovery;
} DictionaryAttackParameters_In;
#define RC_DictionaryAttackParameters_lockHandle (TPM_RC_H + TPM_RC_1)
#define RC_DictionaryAttackParameters_newMaxTries (TPM_RC_P + TPM_RC_1)
#define RC_DictionaryAttackParameters_newRecoveryTime (TPM_RC_P + TPM_RC_2)
#define RC_DictionaryAttackParameters_lockoutRecovery (TPM_RC_P + TPM_RC_3)
// Response code modifiers
# define RC_DictionaryAttackParameters_lockHandle (TPM_RC_H + TPM_RC_1)
# define RC_DictionaryAttackParameters_newMaxTries (TPM_RC_P + TPM_RC_1)
# define RC_DictionaryAttackParameters_newRecoveryTime (TPM_RC_P + TPM_RC_2)
# define RC_DictionaryAttackParameters_lockoutRecovery (TPM_RC_P + TPM_RC_3)
// Function prototype
TPM_RC
TPM2_DictionaryAttackParameters(
DictionaryAttackParameters_In *in // IN: input parameter list
);
TPM2_DictionaryAttackParameters(DictionaryAttackParameters_In* in);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_DICTIONARYATTACKPARAMETERS_FP_H_
#endif // CC_DictionaryAttackParameters

View File

@ -59,33 +59,40 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef DUPLICATE_FP_H
#define DUPLICATE_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_DH_OBJECT objectHandle;
TPMI_DH_OBJECT newParentHandle;
TPM2B_DATA encryptionKeyIn;
TPMT_SYM_DEF_OBJECT symmetricAlg;
#if CC_Duplicate // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_DUPLICATE_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_DUPLICATE_FP_H_
// Input structure definition
typedef struct
{
TPMI_DH_OBJECT objectHandle;
TPMI_DH_OBJECT newParentHandle;
TPM2B_DATA encryptionKeyIn;
TPMT_SYM_DEF_OBJECT symmetricAlg;
} Duplicate_In;
typedef struct {
TPM2B_DATA encryptionKeyOut;
TPM2B_PRIVATE duplicate;
TPM2B_ENCRYPTED_SECRET outSymSeed;
// Output structure definition
typedef struct
{
TPM2B_DATA encryptionKeyOut;
TPM2B_PRIVATE duplicate;
TPM2B_ENCRYPTED_SECRET outSymSeed;
} Duplicate_Out;
#define RC_Duplicate_objectHandle (TPM_RC_H + TPM_RC_1)
#define RC_Duplicate_newParentHandle (TPM_RC_H + TPM_RC_2)
#define RC_Duplicate_encryptionKeyIn (TPM_RC_P + TPM_RC_1)
#define RC_Duplicate_symmetricAlg (TPM_RC_P + TPM_RC_2)
// Response code modifiers
# define RC_Duplicate_objectHandle (TPM_RC_H + TPM_RC_1)
# define RC_Duplicate_newParentHandle (TPM_RC_H + TPM_RC_2)
# define RC_Duplicate_encryptionKeyIn (TPM_RC_P + TPM_RC_1)
# define RC_Duplicate_symmetricAlg (TPM_RC_P + TPM_RC_2)
// Function prototype
TPM_RC
TPM2_Duplicate(
Duplicate_In *in, // IN: input parameter list
Duplicate_Out *out // OUT: output parameter list
);
TPM2_Duplicate(Duplicate_In* in, Duplicate_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_DUPLICATE_FP_H_
#endif // CC_Duplicate

View File

@ -1643,7 +1643,7 @@ TPM2_PolicyAuthorizeNV(PolicyAuthorizeNV_In* in)
#include "CommandCodeAttributes_fp.h"
#include "CryptEccMain_fp.h"
#include "Handle_fp.h"
#include "NVDynamic_fp.h"
#include "NvDynamic_fp.h"
#include "Object_fp.h"
#include "PCR_fp.h"
#include "PP_fp.h"

View File

@ -59,26 +59,32 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef ECC_PARAMETERS_FP_H
#define ECC_PARAMETERS_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_ECC_CURVE curveID;
#if CC_ECC_Parameters // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_ECC_PARAMETERS_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_ECC_PARAMETERS_FP_H_
// Input structure definition
typedef struct
{
TPMI_ECC_CURVE curveID;
} ECC_Parameters_In;
#define RC_ECC_Parameters_curveID (TPM_RC_P + TPM_RC_1)
typedef struct {
TPMS_ALGORITHM_DETAIL_ECC parameters;
// Output structure definition
typedef struct
{
TPMS_ALGORITHM_DETAIL_ECC parameters;
} ECC_Parameters_Out;
// Response code modifiers
# define RC_ECC_Parameters_curveID (TPM_RC_P + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_ECC_Parameters(
ECC_Parameters_In *in, // IN: input parameter list
ECC_Parameters_Out *out // OUT: output parameter list
);
TPM2_ECC_Parameters(ECC_Parameters_In* in, ECC_Parameters_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_ECC_PARAMETERS_FP_H_
#endif // CC_ECC_Parameters

View File

@ -59,27 +59,33 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef ECDH_KEYGEN_FP_H
#define ECDH_KEYGEN_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_DH_OBJECT keyHandle;
#if CC_ECDH_KeyGen // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_ECDH_KEYGEN_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_ECDH_KEYGEN_FP_H_
// Input structure definition
typedef struct
{
TPMI_DH_OBJECT keyHandle;
} ECDH_KeyGen_In;
#define RC_ECDH_KeyGen_keyHandle (TPM_RC_H + TPM_RC_1)
typedef struct {
TPM2B_ECC_POINT zPoint;
TPM2B_ECC_POINT pubPoint;
// Output structure definition
typedef struct
{
TPM2B_ECC_POINT zPoint;
TPM2B_ECC_POINT pubPoint;
} ECDH_KeyGen_Out;
// Response code modifiers
# define RC_ECDH_KeyGen_keyHandle (TPM_RC_H + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_ECDH_KeyGen(
ECDH_KeyGen_In *in, // IN: input parameter list
ECDH_KeyGen_Out *out // OUT: output parameter list
);
TPM2_ECDH_KeyGen(ECDH_KeyGen_In* in, ECDH_KeyGen_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_ECDH_KEYGEN_FP_H_
#endif // CC_ECDH_KeyGen

View File

@ -59,28 +59,34 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef ECDH_ZGEN_FP_H
#define ECDH_ZGEN_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_DH_OBJECT keyHandle;
TPM2B_ECC_POINT inPoint;
#if CC_ECDH_ZGen // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_ECDH_ZGEN_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_ECDH_ZGEN_FP_H_
// Input structure definition
typedef struct
{
TPMI_DH_OBJECT keyHandle;
TPM2B_ECC_POINT inPoint;
} ECDH_ZGen_In;
#define RC_ECDH_ZGen_keyHandle (TPM_RC_H + TPM_RC_1)
#define RC_ECDH_ZGen_inPoint (TPM_RC_P + TPM_RC_1)
typedef struct {
TPM2B_ECC_POINT outPoint;
// Output structure definition
typedef struct
{
TPM2B_ECC_POINT outPoint;
} ECDH_ZGen_Out;
// Response code modifiers
# define RC_ECDH_ZGen_keyHandle (TPM_RC_H + TPM_RC_1)
# define RC_ECDH_ZGen_inPoint (TPM_RC_P + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_ECDH_ZGen(
ECDH_ZGen_In *in, // IN: input parameter list
ECDH_ZGen_Out *out // OUT: output parameter list
);
TPM2_ECDH_ZGen(ECDH_ZGen_In* in, ECDH_ZGen_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_ECDH_ZGEN_FP_H_
#endif // CC_ECDH_ZGen

View File

@ -59,26 +59,33 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef EC_EPHEMERAL_FP_H
#define EC_EPHEMERAL_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_ECC_CURVE curveID;
#if CC_EC_Ephemeral // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_EC_EPHEMERAL_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_EC_EPHEMERAL_FP_H_
// Input structure definition
typedef struct
{
TPMI_ECC_CURVE curveID;
} EC_Ephemeral_In;
#define RC_EC_Ephemeral_curveID (TPM_RC_P + TPM_RC_1)
typedef struct {
TPM2B_ECC_POINT Q;
UINT16 counter;
// Output structure definition
typedef struct
{
TPM2B_ECC_POINT Q;
UINT16 counter;
} EC_Ephemeral_Out;
TPM_RC
TPM2_EC_Ephemeral(
EC_Ephemeral_In *in, // IN: input parameter list
EC_Ephemeral_Out *out // OUT: output parameter list
);
// Response code modifiers
# define RC_EC_Ephemeral_curveID (TPM_RC_P + TPM_RC_1)
#endif
// Function prototype
TPM_RC
TPM2_EC_Ephemeral(EC_Ephemeral_In* in, EC_Ephemeral_Out* out);
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_EC_EPHEMERAL_FP_H_
#endif // CC_EC_Ephemeral

View File

@ -59,97 +59,153 @@
/* */
/********************************************************************************/
#ifdef SELF_TEST_DATA
TPM2B_TYPE(EC_TEST, 32);
const TPM_ECC_CURVE c_testCurve = 00003;
// The static key
const TPM2B_EC_TEST c_ecTestKey_ds = {{32, {
0xdf,0x8d,0xa4,0xa3,0x88,0xf6,0x76,0x96,0x89,0xfc,0x2f,0x2d,0xa1,0xb4,0x39,0x7a,
0x78,0xc4,0x7f,0x71,0x8c,0xa6,0x91,0x85,0xc0,0xbf,0xf3,0x54,0x20,0x91,0x2f,0x73}}};
const TPM2B_EC_TEST c_ecTestKey_QsX = {{32, {
0x17,0xad,0x2f,0xcb,0x18,0xd4,0xdb,0x3f,0x2c,0x53,0x13,0x82,0x42,0x97,0xff,0x8d,
0x99,0x50,0x16,0x02,0x35,0xa7,0x06,0xae,0x1f,0xda,0xe2,0x9c,0x12,0x77,0xc0,0xf9}}};
const TPM2B_EC_TEST c_ecTestKey_QsY = {{32, {
0xa6,0xca,0xf2,0x18,0x45,0x96,0x6e,0x58,0xe6,0x72,0x34,0x12,0x89,0xcd,0xaa,0xad,
0xcb,0x68,0xb2,0x51,0xdc,0x5e,0xd1,0x6d,0x38,0x20,0x35,0x57,0xb2,0xfd,0xc7,0x52}}};
// The ephemeral key
const TPM2B_EC_TEST c_ecTestKey_de = {{32, {
0xb6,0xb5,0x33,0x5c,0xd1,0xee,0x52,0x07,0x99,0xea,0x2e,0x8f,0x8b,0x19,0x18,0x07,
0xc1,0xf8,0xdf,0xdd,0xb8,0x77,0x00,0xc7,0xd6,0x53,0x21,0xed,0x02,0x53,0xee,0xac}}};
const TPM2B_EC_TEST c_ecTestKey_QeX = {{32, {
0xa5,0x1e,0x80,0xd1,0x76,0x3e,0x8b,0x96,0xce,0xcc,0x21,0x82,0xc9,0xa2,0xa2,0xed,
0x47,0x21,0x89,0x53,0x44,0xe9,0xc7,0x92,0xe7,0x31,0x48,0x38,0xe6,0xea,0x93,0x47}}};
const TPM2B_EC_TEST c_ecTestKey_QeY = {{32, {
0x30,0xe6,0x4f,0x97,0x03,0xa1,0xcb,0x3b,0x32,0x2a,0x70,0x39,0x94,0xeb,0x4e,0xea,
0x55,0x88,0x81,0x3f,0xb5,0x00,0xb8,0x54,0x25,0xab,0xd4,0xda,0xfd,0x53,0x7a,0x18}}};
// ECDH test results
const TPM2B_EC_TEST c_ecTestEcdh_X = {{32, {
0x64,0x02,0x68,0x92,0x78,0xdb,0x33,0x52,0xed,0x3b,0xfa,0x3b,0x74,0xa3,0x3d,0x2c,
0x2f,0x9c,0x59,0x03,0x07,0xf8,0x22,0x90,0xed,0xe3,0x45,0xf8,0x2a,0x0a,0xd8,0x1d}}};
const TPM2B_EC_TEST c_ecTestEcdh_Y = {{32, {
0x58,0x94,0x05,0x82,0xbe,0x5f,0x33,0x02,0x25,0x90,0x3a,0x33,0x90,0x89,0xe3,0xe5,
0x10,0x4a,0xbc,0x78,0xa5,0xc5,0x07,0x64,0xaf,0x91,0xbc,0xe6,0xff,0x85,0x11,0x40}}};
TPM2B_TYPE(TEST_VALUE, 64);
const TPM2B_TEST_VALUE c_ecTestValue = {{64, {
0x78,0xd5,0xd4,0x56,0x43,0x61,0xdb,0x97,0xa4,0x32,0xc4,0x0b,0x06,0xa9,0xa8,0xa0,
0xf4,0x45,0x7f,0x13,0xd8,0x13,0x81,0x0b,0xe5,0x76,0xbe,0xaa,0xb6,0x3f,0x8d,0x4d,
0x23,0x65,0xcc,0xa7,0xc9,0x19,0x10,0xce,0x69,0xcb,0x0c,0xc7,0x11,0x8d,0xc3,0xff,
0x62,0x69,0xa2,0xbe,0x46,0x90,0xe7,0x7d,0x81,0x77,0x94,0x65,0x1c,0x3e,0xc1,0x3e}}};
#if ALG_SHA1_VALUE == DEFAULT_TEST_HASH
const TPM2B_EC_TEST c_TestEcDsa_r = {{32, {
0x57,0xf3,0x36,0xb7,0xec,0xc2,0xdd,0x76,0x0e,0xe2,0x81,0x21,0x49,0xc5,0x66,0x11,
0x4b,0x8a,0x4f,0x17,0x62,0x82,0xcc,0x06,0xf6,0x64,0x78,0xef,0x6b,0x7c,0xf2,0x6c}}};
const TPM2B_EC_TEST c_TestEcDsa_s = {{32, {
0x1b,0xed,0x23,0x72,0x8f,0x17,0x5f,0x47,0x2e,0xa7,0x97,0x2c,0x51,0x57,0x20,0x70,
0x6f,0x89,0x74,0x8a,0xa8,0xf4,0x26,0xf4,0x96,0xa1,0xb8,0x3e,0xe5,0x35,0xc5,0x94}}};
const TPM2B_EC_TEST c_TestEcSchnorr_r = {{32,{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1b,0x08,0x9f,0xde,
0xef,0x62,0xe3,0xf1,0x14,0xcb,0x54,0x28,0x13,0x76,0xfc,0x6d,0x69,0x22,0xb5,0x3e}}};
const TPM2B_EC_TEST c_TestEcSchnorr_s = {{32,{
0xd9,0xd3,0x20,0xfb,0x4d,0x16,0xf2,0xe6,0xe2,0x45,0x07,0x45,0x1c,0x92,0x92,0x92,
0xa9,0x6b,0x48,0xf8,0xd1,0x98,0x29,0x4d,0xd3,0x8f,0x56,0xf2,0xbb,0x2e,0x22,0x3b}}};
#endif // SHA1
#if ALG_SHA256_VALUE == DEFAULT_TEST_HASH
const TPM2B_EC_TEST c_TestEcDsa_r = {{32, {
0x04,0x7d,0x54,0xeb,0x04,0x6f,0x56,0xec,0xa2,0x6c,0x38,0x8c,0xeb,0x43,0x0b,0x71,
0xf8,0xf2,0xf4,0xa5,0xe0,0x1d,0x3c,0xa2,0x39,0x31,0xe4,0xe7,0x36,0x3b,0xb5,0x5f}}};
const TPM2B_EC_TEST c_TestEcDsa_s = {{32, {
0x8f,0xd0,0x12,0xd9,0x24,0x75,0xf6,0xc4,0x3b,0xb5,0x46,0x75,0x3a,0x41,0x8d,0x80,
0x23,0x99,0x38,0xd7,0xe2,0x40,0xca,0x9a,0x19,0x2a,0xfc,0x54,0x75,0xd3,0x4a,0x6e}}};
const TPM2B_EC_TEST c_TestEcSchnorr_r = {{32, {
0xf7,0xb9,0x15,0x4c,0x34,0xf6,0x41,0x19,0xa3,0xd2,0xf1,0xbd,0xf4,0x13,0x6a,0x4f,
0x63,0xb8,0x4d,0xb5,0xc8,0xcd,0xde,0x85,0x95,0xa5,0x39,0x0a,0x14,0x49,0x3d,0x2f}}};
const TPM2B_EC_TEST c_TestEcSchnorr_s = {{32,{
0xfe,0xbe,0x17,0xaa,0x31,0x22,0x9f,0xd0,0xd2,0xf5,0x25,0x04,0x92,0xb0,0xaa,0x4e,
0xcc,0x1c,0xb6,0x79,0xd6,0x42,0xb3,0x4e,0x3f,0xbb,0xfe,0x5f,0xd0,0xd0,0x8b,0xc3}}};
#endif // SHA256
#if ALG_SHA384_VALUE == DEFAULT_TEST_HASH
const TPM2B_EC_TEST c_TestEcDsa_r = {{32, {
0xf5,0x74,0x6d,0xd6,0xc6,0x56,0x86,0xbb,0xba,0x1c,0xba,0x75,0x65,0xee,0x64,0x31,
0xce,0x04,0xe3,0x9f,0x24,0x3f,0xbd,0xfe,0x04,0xcd,0xab,0x7e,0xfe,0xad,0xcb,0x82}}};
const TPM2B_EC_TEST c_TestEcDsa_s = {{32, {
0xc2,0x4f,0x32,0xa1,0x06,0xc0,0x85,0x4f,0xc6,0xd8,0x31,0x66,0x91,0x9f,0x79,0xcd,
0x5b,0xe5,0x7b,0x94,0xa1,0x91,0x38,0xac,0xd4,0x20,0xa2,0x10,0xf0,0xd5,0x9d,0xbf}}};
const TPM2B_EC_TEST c_TestEcSchnorr_r = {{32, {
0x1e,0xb8,0xe1,0xbf,0xa1,0x9e,0x39,0x1e,0x58,0xa2,0xe6,0x59,0xd0,0x1a,0x6a,0x03,
0x6a,0x1f,0x1c,0x4f,0x36,0x19,0xc1,0xec,0x30,0xa4,0x85,0x1b,0xe9,0x74,0x35,0x66}}};
const TPM2B_EC_TEST c_TestEcSchnorr_s = {{32,{
0xb9,0xe6,0xe3,0x7e,0xcb,0xb9,0xea,0xf1,0xcc,0xf4,0x48,0x44,0x4a,0xda,0xc8,0xd7,
0x87,0xb4,0xba,0x40,0xfe,0x5b,0x68,0x11,0x14,0xcf,0xa0,0x0e,0x85,0x46,0x99,0x01}}};
#endif // SHA384
#if ALG_SHA512_VALUE == DEFAULT_TEST_HASH
const TPM2B_EC_TEST c_TestEcDsa_r = {{32, {
0xc9,0x71,0xa6,0xb4,0xaf,0x46,0x26,0x8c,0x27,0x00,0x06,0x3b,0x00,0x0f,0xa3,0x17,
0x72,0x48,0x40,0x49,0x4d,0x51,0x4f,0xa4,0xcb,0x7e,0x86,0xe9,0xe7,0xb4,0x79,0xb2}}};
const TPM2B_EC_TEST c_TestEcDsa_s = {{32,{
0x87,0xbc,0xc0,0xed,0x74,0x60,0x9e,0xfa,0x4e,0xe8,0x16,0xf3,0xf9,0x6b,0x26,0x07,
0x3c,0x74,0x31,0x7e,0xf0,0x62,0x46,0xdc,0xd6,0x45,0x22,0x47,0x3e,0x0c,0xa0,0x02}}};
const TPM2B_EC_TEST c_TestEcSchnorr_r = {{32,{
0xcc,0x07,0xad,0x65,0x91,0xdd,0xa0,0x10,0x23,0xae,0x53,0xec,0xdf,0xf1,0x50,0x90,
0x16,0x96,0xf4,0x45,0x09,0x73,0x9c,0x84,0xb5,0x5c,0x5f,0x08,0x51,0xcb,0x60,0x01}}};
const TPM2B_EC_TEST c_TestEcSchnorr_s = {{32,{
0x55,0x20,0x21,0x54,0xe2,0x49,0x07,0x47,0x71,0xf4,0x99,0x15,0x54,0xf3,0xab,0x14,
0xdb,0x8e,0xda,0x79,0xb6,0x02,0x0e,0xe3,0x5e,0x6f,0x2c,0xb6,0x05,0xbd,0x14,0x10}}};
#endif // SHA512
#endif // SELF_TEST_DATA
// This file contains the parameter data for ECC testing.
#ifdef SELF_TEST_DATA
TPM2B_TYPE(EC_TEST, 32);
const TPM_ECC_CURVE c_testCurve = 00003;
// The "static" key
const TPM2B_EC_TEST c_ecTestKey_ds = {
{32, {0xdf, 0x8d, 0xa4, 0xa3, 0x88, 0xf6, 0x76, 0x96, 0x89, 0xfc, 0x2f,
0x2d, 0xa1, 0xb4, 0x39, 0x7a, 0x78, 0xc4, 0x7f, 0x71, 0x8c, 0xa6,
0x91, 0x85, 0xc0, 0xbf, 0xf3, 0x54, 0x20, 0x91, 0x2f, 0x73}}};
const TPM2B_EC_TEST c_ecTestKey_QsX = {
{32, {0x17, 0xad, 0x2f, 0xcb, 0x18, 0xd4, 0xdb, 0x3f, 0x2c, 0x53, 0x13,
0x82, 0x42, 0x97, 0xff, 0x8d, 0x99, 0x50, 0x16, 0x02, 0x35, 0xa7,
0x06, 0xae, 0x1f, 0xda, 0xe2, 0x9c, 0x12, 0x77, 0xc0, 0xf9}}};
const TPM2B_EC_TEST c_ecTestKey_QsY = {
{32, {0xa6, 0xca, 0xf2, 0x18, 0x45, 0x96, 0x6e, 0x58, 0xe6, 0x72, 0x34,
0x12, 0x89, 0xcd, 0xaa, 0xad, 0xcb, 0x68, 0xb2, 0x51, 0xdc, 0x5e,
0xd1, 0x6d, 0x38, 0x20, 0x35, 0x57, 0xb2, 0xfd, 0xc7, 0x52}}};
// The "ephemeral" key
const TPM2B_EC_TEST c_ecTestKey_de = {
{32, {0xb6, 0xb5, 0x33, 0x5c, 0xd1, 0xee, 0x52, 0x07, 0x99, 0xea, 0x2e,
0x8f, 0x8b, 0x19, 0x18, 0x07, 0xc1, 0xf8, 0xdf, 0xdd, 0xb8, 0x77,
0x00, 0xc7, 0xd6, 0x53, 0x21, 0xed, 0x02, 0x53, 0xee, 0xac}}};
const TPM2B_EC_TEST c_ecTestKey_QeX = {
{32, {0xa5, 0x1e, 0x80, 0xd1, 0x76, 0x3e, 0x8b, 0x96, 0xce, 0xcc, 0x21,
0x82, 0xc9, 0xa2, 0xa2, 0xed, 0x47, 0x21, 0x89, 0x53, 0x44, 0xe9,
0xc7, 0x92, 0xe7, 0x31, 0x48, 0x38, 0xe6, 0xea, 0x93, 0x47}}};
const TPM2B_EC_TEST c_ecTestKey_QeY = {
{32, {0x30, 0xe6, 0x4f, 0x97, 0x03, 0xa1, 0xcb, 0x3b, 0x32, 0x2a, 0x70,
0x39, 0x94, 0xeb, 0x4e, 0xea, 0x55, 0x88, 0x81, 0x3f, 0xb5, 0x00,
0xb8, 0x54, 0x25, 0xab, 0xd4, 0xda, 0xfd, 0x53, 0x7a, 0x18}}};
// ECDH test results
const TPM2B_EC_TEST c_ecTestEcdh_X = {
{32, {0x64, 0x02, 0x68, 0x92, 0x78, 0xdb, 0x33, 0x52, 0xed, 0x3b, 0xfa,
0x3b, 0x74, 0xa3, 0x3d, 0x2c, 0x2f, 0x9c, 0x59, 0x03, 0x07, 0xf8,
0x22, 0x90, 0xed, 0xe3, 0x45, 0xf8, 0x2a, 0x0a, 0xd8, 0x1d}}};
const TPM2B_EC_TEST c_ecTestEcdh_Y = {
{32, {0x58, 0x94, 0x05, 0x82, 0xbe, 0x5f, 0x33, 0x02, 0x25, 0x90, 0x3a,
0x33, 0x90, 0x89, 0xe3, 0xe5, 0x10, 0x4a, 0xbc, 0x78, 0xa5, 0xc5,
0x07, 0x64, 0xaf, 0x91, 0xbc, 0xe6, 0xff, 0x85, 0x11, 0x40}}};
TPM2B_TYPE(TEST_VALUE, 64);
const TPM2B_TEST_VALUE c_ecTestValue = {
{64,
{0x78, 0xd5, 0xd4, 0x56, 0x43, 0x61, 0xdb, 0x97, 0xa4, 0x32, 0xc4, 0x0b, 0x06,
0xa9, 0xa8, 0xa0, 0xf4, 0x45, 0x7f, 0x13, 0xd8, 0x13, 0x81, 0x0b, 0xe5, 0x76,
0xbe, 0xaa, 0xb6, 0x3f, 0x8d, 0x4d, 0x23, 0x65, 0xcc, 0xa7, 0xc9, 0x19, 0x10,
0xce, 0x69, 0xcb, 0x0c, 0xc7, 0x11, 0x8d, 0xc3, 0xff, 0x62, 0x69, 0xa2, 0xbe,
0x46, 0x90, 0xe7, 0x7d, 0x81, 0x77, 0x94, 0x65, 0x1c, 0x3e, 0xc1, 0x3e}}};
# if ALG_SHA1_VALUE == DEFAULT_TEST_HASH
const TPM2B_EC_TEST c_TestEcDsa_r = {
{32, {0x57, 0xf3, 0x36, 0xb7, 0xec, 0xc2, 0xdd, 0x76, 0x0e, 0xe2, 0x81,
0x21, 0x49, 0xc5, 0x66, 0x11, 0x4b, 0x8a, 0x4f, 0x17, 0x62, 0x82,
0xcc, 0x06, 0xf6, 0x64, 0x78, 0xef, 0x6b, 0x7c, 0xf2, 0x6c}}};
const TPM2B_EC_TEST c_TestEcDsa_s = {
{32, {0x1b, 0xed, 0x23, 0x72, 0x8f, 0x17, 0x5f, 0x47, 0x2e, 0xa7, 0x97,
0x2c, 0x51, 0x57, 0x20, 0x70, 0x6f, 0x89, 0x74, 0x8a, 0xa8, 0xf4,
0x26, 0xf4, 0x96, 0xa1, 0xb8, 0x3e, 0xe5, 0x35, 0xc5, 0x94}}};
const TPM2B_EC_TEST c_TestEcSchnorr_r = {
{32, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1b, 0x08, 0x9f, 0xde, 0xef, 0x62, 0xe3, 0xf1, 0x14, 0xcb,
0x54, 0x28, 0x13, 0x76, 0xfc, 0x6d, 0x69, 0x22, 0xb5, 0x3e}}};
const TPM2B_EC_TEST c_TestEcSchnorr_s = {
{32, {0xd9, 0xd3, 0x20, 0xfb, 0x4d, 0x16, 0xf2, 0xe6, 0xe2, 0x45, 0x07,
0x45, 0x1c, 0x92, 0x92, 0x92, 0xa9, 0x6b, 0x48, 0xf8, 0xd1, 0x98,
0x29, 0x4d, 0xd3, 0x8f, 0x56, 0xf2, 0xbb, 0x2e, 0x22, 0x3b}}};
# endif // SHA1
# if ALG_SHA256_VALUE == DEFAULT_TEST_HASH
const TPM2B_EC_TEST c_TestEcDsa_r = {
{32, {0x04, 0x7d, 0x54, 0xeb, 0x04, 0x6f, 0x56, 0xec, 0xa2, 0x6c, 0x38,
0x8c, 0xeb, 0x43, 0x0b, 0x71, 0xf8, 0xf2, 0xf4, 0xa5, 0xe0, 0x1d,
0x3c, 0xa2, 0x39, 0x31, 0xe4, 0xe7, 0x36, 0x3b, 0xb5, 0x5f}}};
const TPM2B_EC_TEST c_TestEcDsa_s = {
{32, {0x8f, 0xd0, 0x12, 0xd9, 0x24, 0x75, 0xf6, 0xc4, 0x3b, 0xb5, 0x46,
0x75, 0x3a, 0x41, 0x8d, 0x80, 0x23, 0x99, 0x38, 0xd7, 0xe2, 0x40,
0xca, 0x9a, 0x19, 0x2a, 0xfc, 0x54, 0x75, 0xd3, 0x4a, 0x6e}}};
const TPM2B_EC_TEST c_TestEcSchnorr_r = {
{32, {0xf7, 0xb9, 0x15, 0x4c, 0x34, 0xf6, 0x41, 0x19, 0xa3, 0xd2, 0xf1,
0xbd, 0xf4, 0x13, 0x6a, 0x4f, 0x63, 0xb8, 0x4d, 0xb5, 0xc8, 0xcd,
0xde, 0x85, 0x95, 0xa5, 0x39, 0x0a, 0x14, 0x49, 0x3d, 0x2f}}};
const TPM2B_EC_TEST c_TestEcSchnorr_s = {
{32, {0xfe, 0xbe, 0x17, 0xaa, 0x31, 0x22, 0x9f, 0xd0, 0xd2, 0xf5, 0x25,
0x04, 0x92, 0xb0, 0xaa, 0x4e, 0xcc, 0x1c, 0xb6, 0x79, 0xd6, 0x42,
0xb3, 0x4e, 0x3f, 0xbb, 0xfe, 0x5f, 0xd0, 0xd0, 0x8b, 0xc3}}};
# endif // SHA256
# if ALG_SHA384_VALUE == DEFAULT_TEST_HASH
const TPM2B_EC_TEST c_TestEcDsa_r = {
{32, {0xf5, 0x74, 0x6d, 0xd6, 0xc6, 0x56, 0x86, 0xbb, 0xba, 0x1c, 0xba,
0x75, 0x65, 0xee, 0x64, 0x31, 0xce, 0x04, 0xe3, 0x9f, 0x24, 0x3f,
0xbd, 0xfe, 0x04, 0xcd, 0xab, 0x7e, 0xfe, 0xad, 0xcb, 0x82}}};
const TPM2B_EC_TEST c_TestEcDsa_s = {
{32, {0xc2, 0x4f, 0x32, 0xa1, 0x06, 0xc0, 0x85, 0x4f, 0xc6, 0xd8, 0x31,
0x66, 0x91, 0x9f, 0x79, 0xcd, 0x5b, 0xe5, 0x7b, 0x94, 0xa1, 0x91,
0x38, 0xac, 0xd4, 0x20, 0xa2, 0x10, 0xf0, 0xd5, 0x9d, 0xbf}}};
const TPM2B_EC_TEST c_TestEcSchnorr_r = {
{32, {0x1e, 0xb8, 0xe1, 0xbf, 0xa1, 0x9e, 0x39, 0x1e, 0x58, 0xa2, 0xe6,
0x59, 0xd0, 0x1a, 0x6a, 0x03, 0x6a, 0x1f, 0x1c, 0x4f, 0x36, 0x19,
0xc1, 0xec, 0x30, 0xa4, 0x85, 0x1b, 0xe9, 0x74, 0x35, 0x66}}};
const TPM2B_EC_TEST c_TestEcSchnorr_s = {
{32, {0xb9, 0xe6, 0xe3, 0x7e, 0xcb, 0xb9, 0xea, 0xf1, 0xcc, 0xf4, 0x48,
0x44, 0x4a, 0xda, 0xc8, 0xd7, 0x87, 0xb4, 0xba, 0x40, 0xfe, 0x5b,
0x68, 0x11, 0x14, 0xcf, 0xa0, 0x0e, 0x85, 0x46, 0x99, 0x01}}};
# endif // SHA384
# if ALG_SHA512_VALUE == DEFAULT_TEST_HASH
const TPM2B_EC_TEST c_TestEcDsa_r = {
{32, {0xc9, 0x71, 0xa6, 0xb4, 0xaf, 0x46, 0x26, 0x8c, 0x27, 0x00, 0x06,
0x3b, 0x00, 0x0f, 0xa3, 0x17, 0x72, 0x48, 0x40, 0x49, 0x4d, 0x51,
0x4f, 0xa4, 0xcb, 0x7e, 0x86, 0xe9, 0xe7, 0xb4, 0x79, 0xb2}}};
const TPM2B_EC_TEST c_TestEcDsa_s = {
{32, {0x87, 0xbc, 0xc0, 0xed, 0x74, 0x60, 0x9e, 0xfa, 0x4e, 0xe8, 0x16,
0xf3, 0xf9, 0x6b, 0x26, 0x07, 0x3c, 0x74, 0x31, 0x7e, 0xf0, 0x62,
0x46, 0xdc, 0xd6, 0x45, 0x22, 0x47, 0x3e, 0x0c, 0xa0, 0x02}}};
const TPM2B_EC_TEST c_TestEcSchnorr_r = {
{32, {0xcc, 0x07, 0xad, 0x65, 0x91, 0xdd, 0xa0, 0x10, 0x23, 0xae, 0x53,
0xec, 0xdf, 0xf1, 0x50, 0x90, 0x16, 0x96, 0xf4, 0x45, 0x09, 0x73,
0x9c, 0x84, 0xb5, 0x5c, 0x5f, 0x08, 0x51, 0xcb, 0x60, 0x01}}};
const TPM2B_EC_TEST c_TestEcSchnorr_s = {
{32, {0x55, 0x20, 0x21, 0x54, 0xe2, 0x49, 0x07, 0x47, 0x71, 0xf4, 0x99,
0x15, 0x54, 0xf3, 0xab, 0x14, 0xdb, 0x8e, 0xda, 0x79, 0xb6, 0x02,
0x0e, 0xe3, 0x5e, 0x6f, 0x2c, 0xb6, 0x05, 0xbd, 0x14, 0x10}}};
# endif // SHA512
#endif // SELF_TEST_DATA

View File

@ -59,35 +59,41 @@
/* */
/********************************************************************************/
/* rev 146 */
#ifndef ENCRYPTDECRYPT2_FP_H
#define ENCRYPTDECRYPT2_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_DH_OBJECT keyHandle;
TPM2B_MAX_BUFFER inData;
TPMI_YES_NO decrypt;
TPMI_ALG_CIPHER_MODE mode;
TPM2B_IV ivIn;
#if CC_EncryptDecrypt2 // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_ENCRYPTDECRYPT2_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_ENCRYPTDECRYPT2_FP_H_
// Input structure definition
typedef struct
{
TPMI_DH_OBJECT keyHandle;
TPM2B_MAX_BUFFER inData;
TPMI_YES_NO decrypt;
TPMI_ALG_CIPHER_MODE mode;
TPM2B_IV ivIn;
} EncryptDecrypt2_In;
#define RC_EncryptDecrypt2_keyHandle (TPM_RC_H + TPM_RC_1)
#define RC_EncryptDecrypt2_inData (TPM_RC_P + TPM_RC_1)
#define RC_EncryptDecrypt2_decrypt (TPM_RC_P + TPM_RC_2)
#define RC_EncryptDecrypt2_mode (TPM_RC_P + TPM_RC_3)
#define RC_EncryptDecrypt2_ivIn (TPM_RC_P + TPM_RC_4)
typedef struct {
TPM2B_MAX_BUFFER outData;
TPM2B_IV ivOut;
// Output structure definition
typedef struct
{
TPM2B_MAX_BUFFER outData;
TPM2B_IV ivOut;
} EncryptDecrypt2_Out;
// Response code modifiers
# define RC_EncryptDecrypt2_keyHandle (TPM_RC_H + TPM_RC_1)
# define RC_EncryptDecrypt2_inData (TPM_RC_P + TPM_RC_1)
# define RC_EncryptDecrypt2_decrypt (TPM_RC_P + TPM_RC_2)
# define RC_EncryptDecrypt2_mode (TPM_RC_P + TPM_RC_3)
# define RC_EncryptDecrypt2_ivIn (TPM_RC_P + TPM_RC_4)
// Function prototype
TPM_RC
TPM2_EncryptDecrypt2(
EncryptDecrypt2_In *in, // IN: input parameter list
EncryptDecrypt2_Out *out // OUT: output parameter list
);
TPM2_EncryptDecrypt2(EncryptDecrypt2_In* in, EncryptDecrypt2_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_ENCRYPTDECRYPT2_FP_H_
#endif // CC_EncryptDecrypt2

View File

@ -59,35 +59,41 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef ENCRYPTDECRYPT_FP_H
#define ENCRYPTDECRYPT_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_DH_OBJECT keyHandle;
TPMI_YES_NO decrypt;
TPMI_ALG_CIPHER_MODE mode;
TPM2B_IV ivIn;
TPM2B_MAX_BUFFER inData;
#if CC_EncryptDecrypt // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_ENCRYPTDECRYPT_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_ENCRYPTDECRYPT_FP_H_
// Input structure definition
typedef struct
{
TPMI_DH_OBJECT keyHandle;
TPMI_YES_NO decrypt;
TPMI_ALG_CIPHER_MODE mode;
TPM2B_IV ivIn;
TPM2B_MAX_BUFFER inData;
} EncryptDecrypt_In;
#define RC_EncryptDecrypt_keyHandle (TPM_RC_H + TPM_RC_1)
#define RC_EncryptDecrypt_decrypt (TPM_RC_P + TPM_RC_1)
#define RC_EncryptDecrypt_mode (TPM_RC_P + TPM_RC_2)
#define RC_EncryptDecrypt_ivIn (TPM_RC_P + TPM_RC_3)
#define RC_EncryptDecrypt_inData (TPM_RC_P + TPM_RC_4)
typedef struct {
TPM2B_MAX_BUFFER outData;
TPM2B_IV ivOut;
// Output structure definition
typedef struct
{
TPM2B_MAX_BUFFER outData;
TPM2B_IV ivOut;
} EncryptDecrypt_Out;
// Response code modifiers
# define RC_EncryptDecrypt_keyHandle (TPM_RC_H + TPM_RC_1)
# define RC_EncryptDecrypt_decrypt (TPM_RC_P + TPM_RC_1)
# define RC_EncryptDecrypt_mode (TPM_RC_P + TPM_RC_2)
# define RC_EncryptDecrypt_ivIn (TPM_RC_P + TPM_RC_3)
# define RC_EncryptDecrypt_inData (TPM_RC_P + TPM_RC_4)
// Function prototype
TPM_RC
TPM2_EncryptDecrypt(
EncryptDecrypt_In *in, // IN: input parameter list
EncryptDecrypt_Out *out // OUT: output parameter list
);
TPM2_EncryptDecrypt(EncryptDecrypt_In* in, EncryptDecrypt_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_ENCRYPTDECRYPT_FP_H_
#endif // CC_EncryptDecrypt

View File

@ -59,108 +59,132 @@
/* */
/********************************************************************************/
/* 7.7 Encrypt Decrypt Support (EncryptDecrypt_spt.c) */
#include "Tpm.h"
#include "EncryptDecrypt_fp.h"
#include "EncryptDecrypt_spt_fp.h"
#if CC_EncryptDecrypt2
/* Error Returns Meaning */
/* TPM_RC_KEY is not a symmetric decryption key with both public and private portions loaded */
/* TPM_RC_SIZE IvIn size is incompatible with the block cipher mode; or inData size is not an even
multiple of the block size for CBC or ECB mode */
/* TPM_RC_VALUE keyHandle is restricted and the argument mode does not match the key's mode */
/*(See part 3 specification)
// symmetric encryption or decryption
*/
// Return Type: TPM_RC
// TPM_RC_KEY is not a symmetric decryption key with both
// public and private portions loaded
// TPM_RC_SIZE 'IvIn' size is incompatible with the block cipher mode;
// or 'inData' size is not an even multiple of the block
// size for CBC or ECB mode
// TPM_RC_VALUE 'keyHandle' is restricted and the argument 'mode' does
// not match the key's mode
TPM_RC
EncryptDecryptShared(
TPMI_DH_OBJECT keyHandleIn,
TPMI_YES_NO decryptIn,
TPMI_ALG_SYM_MODE modeIn,
TPM2B_IV *ivIn,
TPM2B_MAX_BUFFER *inData,
EncryptDecrypt_Out *out
)
EncryptDecryptShared(TPMI_DH_OBJECT keyHandleIn,
TPMI_YES_NO decryptIn,
TPMI_ALG_SYM_MODE modeIn,
TPM2B_IV* ivIn,
TPM2B_MAX_BUFFER* inData,
EncryptDecrypt_Out* out)
{
OBJECT *symKey;
UINT16 keySize;
UINT16 blockSize;
BYTE *key;
TPM_ALG_ID alg;
TPM_ALG_ID mode;
TPM_RC result;
BOOL OK;
OBJECT* symKey;
UINT16 keySize;
UINT16 blockSize;
BYTE* key;
TPM_ALG_ID alg;
TPM_ALG_ID mode;
TPM_RC result;
BOOL OK;
// Input Validation
symKey = HandleToObject(keyHandleIn);
mode = symKey->publicArea.parameters.symDetail.sym.mode.sym;
mode = symKey->publicArea.parameters.symDetail.sym.mode.sym;
// The input key should be a symmetric key
if(symKey->publicArea.type != TPM_ALG_SYMCIPHER)
return TPM_RCS_KEY + RC_EncryptDecrypt_keyHandle;
return TPM_RCS_KEY + RC_EncryptDecrypt_keyHandle;
// The key must be unrestricted and allow the selected operation
OK = !IS_ATTRIBUTE(symKey->publicArea.objectAttributes,
TPMA_OBJECT, restricted);
OK = !IS_ATTRIBUTE(symKey->publicArea.objectAttributes, TPMA_OBJECT, restricted);
if(YES == decryptIn)
OK = OK && IS_ATTRIBUTE(symKey->publicArea.objectAttributes,
TPMA_OBJECT, decrypt);
OK = OK
&& IS_ATTRIBUTE(
symKey->publicArea.objectAttributes, TPMA_OBJECT, decrypt);
else
OK = OK && IS_ATTRIBUTE(symKey->publicArea.objectAttributes,
TPMA_OBJECT, sign);
OK = OK
&& IS_ATTRIBUTE(symKey->publicArea.objectAttributes, TPMA_OBJECT, sign);
if(!OK)
return TPM_RCS_ATTRIBUTES + RC_EncryptDecrypt_keyHandle;
return TPM_RCS_ATTRIBUTES + RC_EncryptDecrypt_keyHandle;
// Make sure that key is an encrypt/decrypt key and not SMAC
if(!CryptSymModeIsValid(mode, TRUE))
return TPM_RCS_MODE + RC_EncryptDecrypt_keyHandle;
return TPM_RCS_MODE + RC_EncryptDecrypt_keyHandle;
// If the key mode is not TPM_ALG_NULL...
// or TPM_ALG_NULL
if(mode != TPM_ALG_NULL)
{
// then the input mode has to be TPM_ALG_NULL or the same as the key
if((modeIn != TPM_ALG_NULL) && (modeIn != mode))
return TPM_RCS_MODE + RC_EncryptDecrypt_mode;
}
{
// then the input mode has to be TPM_ALG_NULL or the same as the key
if((modeIn != TPM_ALG_NULL) && (modeIn != mode))
return TPM_RCS_MODE + RC_EncryptDecrypt_mode;
}
else
{
// if the key mode is null, then the input can't be null
if(modeIn == TPM_ALG_NULL)
return TPM_RCS_MODE + RC_EncryptDecrypt_mode;
mode = modeIn;
}
{
// if the key mode is null, then the input can't be null
if(modeIn == TPM_ALG_NULL)
return TPM_RCS_MODE + RC_EncryptDecrypt_mode;
mode = modeIn;
}
// The input iv for ECB mode should be an Empty Buffer. All the other modes
// should have an iv size same as encryption block size
keySize = symKey->publicArea.parameters.symDetail.sym.keyBits.sym;
alg = symKey->publicArea.parameters.symDetail.sym.algorithm;
keySize = symKey->publicArea.parameters.symDetail.sym.keyBits.sym;
alg = symKey->publicArea.parameters.symDetail.sym.algorithm;
blockSize = CryptGetSymmetricBlockSize(alg, keySize);
// reverify the algorithm. This is mainly to keep static analysis tools happy
if(blockSize == 0)
return TPM_RCS_KEY + RC_EncryptDecrypt_keyHandle;
return TPM_RCS_KEY + RC_EncryptDecrypt_keyHandle;
if(((mode == TPM_ALG_ECB) && (ivIn->t.size != 0))
|| ((mode != TPM_ALG_ECB) && (ivIn->t.size != blockSize)))
return TPM_RCS_SIZE + RC_EncryptDecrypt_ivIn;
return TPM_RCS_SIZE + RC_EncryptDecrypt_ivIn;
// The input data size of CBC mode or ECB mode must be an even multiple of
// the symmetric algorithm's block size
if(((mode == TPM_ALG_CBC) || (mode == TPM_ALG_ECB))
&& ((inData->t.size % blockSize) != 0))
return TPM_RCS_SIZE + RC_EncryptDecrypt_inData;
return TPM_RCS_SIZE + RC_EncryptDecrypt_inData;
// Copy IV
// Note: This is copied here so that the calls to the encrypt/decrypt functions
// will modify the output buffer, not the input buffer
out->ivOut = *ivIn;
// Command Output
key = symKey->sensitive.sensitive.sym.t.buffer;
// For symmetric encryption, the cipher data size is the same as plain data
// size.
out->outData.t.size = inData->t.size;
if(decryptIn == YES)
{
// Decrypt data to output
result = CryptSymmetricDecrypt(out->outData.t.buffer, alg, keySize, key,
&(out->ivOut), mode, inData->t.size,
inData->t.buffer);
}
{
// Decrypt data to output
result = CryptSymmetricDecrypt(out->outData.t.buffer,
alg,
keySize,
key,
&(out->ivOut),
mode,
inData->t.size,
inData->t.buffer);
}
else
{
// Encrypt data to output
result = CryptSymmetricEncrypt(out->outData.t.buffer, alg, keySize, key,
&(out->ivOut), mode, inData->t.size,
inData->t.buffer);
}
{
// Encrypt data to output
result = CryptSymmetricEncrypt(out->outData.t.buffer,
alg,
keySize,
key,
&(out->ivOut),
mode,
inData->t.size,
inData->t.buffer);
}
return result;
}
#endif // CC_EncryptDecrypt
#endif // CC_EncryptDecrypt

View File

@ -59,17 +59,31 @@
/* */
/********************************************************************************/
#ifndef ENCRYPTDECRYPT_SPT_FP_H
#define ENCRYPTDECRYPT_SPT_FP_H
/*(Auto-generated)
* Created by TpmPrototypes; Version 3.0 July 18, 2017
* Date: Mar 28, 2019 Time: 08:25:18PM
*/
#ifndef _ENCRYPT_DECRYPT_SPT_FP_H_
#define _ENCRYPT_DECRYPT_SPT_FP_H_
#if CC_EncryptDecrypt2
// Return Type: TPM_RC
// TPM_RC_KEY is not a symmetric decryption key with both
// public and private portions loaded
// TPM_RC_SIZE 'IvIn' size is incompatible with the block cipher mode;
// or 'inData' size is not an even multiple of the block
// size for CBC or ECB mode
// TPM_RC_VALUE 'keyHandle' is restricted and the argument 'mode' does
// not match the key's mode
TPM_RC
EncryptDecryptShared(
TPMI_DH_OBJECT keyHandleIn,
TPMI_YES_NO decryptIn,
TPMI_ALG_SYM_MODE modeIn,
TPM2B_IV *ivIn,
TPM2B_MAX_BUFFER *inData,
EncryptDecrypt_Out *out
);
EncryptDecryptShared(TPMI_DH_OBJECT keyHandleIn,
TPMI_YES_NO decryptIn,
TPMI_ALG_SYM_MODE modeIn,
TPM2B_IV* ivIn,
TPM2B_MAX_BUFFER* inData,
EncryptDecrypt_Out* out);
#endif // CC_EncryptDecrypt
#endif
#endif // _ENCRYPT_DECRYPT_SPT_FP_H_

View File

@ -78,133 +78,133 @@
// space to load it to RAM
TPM_RC
EntityGetLoadStatus(COMMAND* command // IN/OUT: command parsing structure
)
)
{
UINT32 i;
TPM_RC result = TPM_RC_SUCCESS;
//
for(i = 0; i < command->handleNum; i++)
{
TPM_HANDLE handle = command->handles[i];
switch(HandleGetType(handle))
{
// For handles associated with hierarchies, the entity is present
// only if the associated enable is SET.
case TPM_HT_PERMANENT:
switch(handle)
{
// First handle non-hierarchy cases
{
TPM_HANDLE handle = command->handles[i];
switch(HandleGetType(handle))
{
// For handles associated with hierarchies, the entity is present
// only if the associated enable is SET.
case TPM_HT_PERMANENT:
switch(handle)
{
// First handle non-hierarchy cases
#if VENDOR_PERMANENT_AUTH_ENABLED == YES
case VENDOR_PERMANENT_AUTH_HANDLE:
if(!gc.ehEnable)
result = TPM_RC_HIERARCHY;
break;
case VENDOR_PERMANENT_AUTH_HANDLE:
if(!gc.ehEnable)
result = TPM_RC_HIERARCHY;
break;
#endif
// PW session handle and lockout handle are always available
case TPM_RS_PW:
// Need to be careful for lockout. Lockout is always available
// for policy checks but not always available when authValue
// is being checked.
case TPM_RH_LOCKOUT:
// Rather than have #ifdefs all over the code,
// CASE_ACT_HANDLE is defined in ACT.h. It is 'case TPM_RH_ACT_x:'
// FOR_EACH_ACT(CASE_ACT_HANDLE) creates a simple
// case TPM_RH_ACT_x: // for each of the implemented ACT.
FOR_EACH_ACT(CASE_ACT_HANDLE)
break;
default:
// If the implementation has a manufacturer-specific value
// then test for it here. Since this implementation does
// not have any, this implementation returns the same failure
// that unmarshaling of a bad handle would produce.
if(((TPM_RH)handle >= TPM_RH_AUTH_00)
&& ((TPM_RH)handle <= TPM_RH_AUTH_FF))
// if the implementation has a manufacturer-specific value
result = TPM_RC_VALUE;
else
// The handle either refers to a hierarchy or is invalid.
result = ValidateHierarchy(handle);
break;
}
break;
case TPM_HT_TRANSIENT:
// For a transient object, check if the handle is associated
// with a loaded object.
if(!IsObjectPresent(handle))
result = TPM_RC_REFERENCE_H0;
break;
case TPM_HT_PERSISTENT:
// Persistent object
// Copy the persistent object to RAM and replace the handle with the
// handle of the assigned slot. A TPM_RC_OBJECT_MEMORY,
// TPM_RC_HIERARCHY or TPM_RC_REFERENCE_H0 error may be returned by
// ObjectLoadEvict()
result = ObjectLoadEvict(&command->handles[i], command->index);
break;
case TPM_HT_HMAC_SESSION:
// For an HMAC session, see if the session is loaded
// and if the session in the session slot is actually
// an HMAC session.
if(SessionIsLoaded(handle))
{
SESSION* session;
session = SessionGet(handle);
// Check if the session is a HMAC session
if(session->attributes.isPolicy == SET)
result = TPM_RC_HANDLE;
}
else
result = TPM_RC_REFERENCE_H0;
break;
case TPM_HT_POLICY_SESSION:
// For a policy session, see if the session is loaded
// and if the session in the session slot is actually
// a policy session.
if(SessionIsLoaded(handle))
{
SESSION* session;
session = SessionGet(handle);
// Check if the session is a policy session
if(session->attributes.isPolicy == CLEAR)
result = TPM_RC_HANDLE;
}
else
result = TPM_RC_REFERENCE_H0;
break;
case TPM_HT_NV_INDEX:
// For an NV Index, use the TPM-specific routine
// to search the IN Index space.
result = NvIndexIsAccessible(handle);
break;
case TPM_HT_PCR:
// Any PCR handle that is unmarshaled successfully referenced
// a PCR that is defined.
break;
// PW session handle and lockout handle are always available
case TPM_RS_PW:
// Need to be careful for lockout. Lockout is always available
// for policy checks but not always available when authValue
// is being checked.
case TPM_RH_LOCKOUT:
// Rather than have #ifdefs all over the code,
// CASE_ACT_HANDLE is defined in ACT.h. It is 'case TPM_RH_ACT_x:'
// FOR_EACH_ACT(CASE_ACT_HANDLE) creates a simple
// case TPM_RH_ACT_x: // for each of the implemented ACT.
FOR_EACH_ACT(CASE_ACT_HANDLE)
break;
default:
// If the implementation has a manufacturer-specific value
// then test for it here. Since this implementation does
// not have any, this implementation returns the same failure
// that unmarshaling of a bad handle would produce.
if(((TPM_RH)handle >= TPM_RH_AUTH_00)
&& ((TPM_RH)handle <= TPM_RH_AUTH_FF))
// if the implementation has a manufacturer-specific value
result = TPM_RC_VALUE;
else
// The handle either refers to a hierarchy or is invalid.
result = ValidateHierarchy(handle);
break;
}
break;
case TPM_HT_TRANSIENT:
// For a transient object, check if the handle is associated
// with a loaded object.
if(!IsObjectPresent(handle))
result = TPM_RC_REFERENCE_H0;
break;
case TPM_HT_PERSISTENT:
// Persistent object
// Copy the persistent object to RAM and replace the handle with the
// handle of the assigned slot. A TPM_RC_OBJECT_MEMORY,
// TPM_RC_HIERARCHY or TPM_RC_REFERENCE_H0 error may be returned by
// ObjectLoadEvict()
result = ObjectLoadEvict(&command->handles[i], command->index);
break;
case TPM_HT_HMAC_SESSION:
// For an HMAC session, see if the session is loaded
// and if the session in the session slot is actually
// an HMAC session.
if(SessionIsLoaded(handle))
{
SESSION* session;
session = SessionGet(handle);
// Check if the session is a HMAC session
if(session->attributes.isPolicy == SET)
result = TPM_RC_HANDLE;
}
else
result = TPM_RC_REFERENCE_H0;
break;
case TPM_HT_POLICY_SESSION:
// For a policy session, see if the session is loaded
// and if the session in the session slot is actually
// a policy session.
if(SessionIsLoaded(handle))
{
SESSION* session;
session = SessionGet(handle);
// Check if the session is a policy session
if(session->attributes.isPolicy == CLEAR)
result = TPM_RC_HANDLE;
}
else
result = TPM_RC_REFERENCE_H0;
break;
case TPM_HT_NV_INDEX:
// For an NV Index, use the TPM-specific routine
// to search the IN Index space.
result = NvIndexIsAccessible(handle);
break;
case TPM_HT_PCR:
// Any PCR handle that is unmarshaled successfully referenced
// a PCR that is defined.
break;
#if CC_AC_Send
case TPM_HT_AC:
// Use the TPM-specific routine to search for the AC
result = AcIsAccessible(handle);
break;
case TPM_HT_AC:
// Use the TPM-specific routine to search for the AC
result = AcIsAccessible(handle);
break;
#endif
case TPM_HT_EXTERNAL_NV:
case TPM_HT_PERMANENT_NV:
// Not yet supported.
result = TPM_RC_VALUE;
break;
default:
// Any other handle type is a defect in the unmarshaling code.
FAIL(FATAL_ERROR_INTERNAL);
break;
}
if(result != TPM_RC_SUCCESS)
{
if(result == TPM_RC_REFERENCE_H0)
result = result + i;
else
result = RcSafeAddToResult(result, TPM_RC_H + g_rcIndex[i]);
break;
}
}
case TPM_HT_EXTERNAL_NV:
case TPM_HT_PERMANENT_NV:
// Not yet supported.
result = TPM_RC_VALUE;
break;
default:
// Any other handle type is a defect in the unmarshaling code.
FAIL(FATAL_ERROR_INTERNAL);
break;
}
if(result != TPM_RC_SUCCESS)
{
if(result == TPM_RC_REFERENCE_H0)
result = result + i;
else
result = RcSafeAddToResult(result, TPM_RC_H + g_rcIndex[i]);
break;
}
}
return result;
}
@ -221,96 +221,96 @@ EntityGetLoadStatus(COMMAND* command // IN/OUT: command parsing structure
UINT16
EntityGetAuthValue(TPMI_DH_ENTITY handle, // IN: handle of entity
TPM2B_AUTH* auth // OUT: authValue of the entity
)
)
{
TPM2B_AUTH* pAuth = NULL;
auth->t.size = 0;
switch(HandleGetType(handle))
{
case TPM_HT_PERMANENT:
{
switch(HierarchyNormalizeHandle(handle))
{
case TPM_RH_OWNER:
// ownerAuth for TPM_RH_OWNER
pAuth = &gp.ownerAuth;
break;
case TPM_RH_ENDORSEMENT:
// endorsementAuth for TPM_RH_ENDORSEMENT
pAuth = &gp.endorsementAuth;
break;
{
case TPM_HT_PERMANENT:
{
switch(HierarchyNormalizeHandle(handle))
{
case TPM_RH_OWNER:
// ownerAuth for TPM_RH_OWNER
pAuth = &gp.ownerAuth;
break;
case TPM_RH_ENDORSEMENT:
// endorsementAuth for TPM_RH_ENDORSEMENT
pAuth = &gp.endorsementAuth;
break;
// The ACT use platformAuth for auth
FOR_EACH_ACT(CASE_ACT_HANDLE)
// The ACT use platformAuth for auth
FOR_EACH_ACT(CASE_ACT_HANDLE)
case TPM_RH_PLATFORM:
// platformAuth for TPM_RH_PLATFORM
pAuth = &gc.platformAuth;
break;
case TPM_RH_LOCKOUT:
// lockoutAuth for TPM_RH_LOCKOUT
pAuth = &gp.lockoutAuth;
break;
case TPM_RH_NULL:
// nullAuth for TPM_RH_NULL. Return 0 directly here
return 0;
break;
case TPM_RH_PLATFORM:
// platformAuth for TPM_RH_PLATFORM
pAuth = &gc.platformAuth;
break;
case TPM_RH_LOCKOUT:
// lockoutAuth for TPM_RH_LOCKOUT
pAuth = &gp.lockoutAuth;
break;
case TPM_RH_NULL:
// nullAuth for TPM_RH_NULL. Return 0 directly here
return 0;
break;
#if VENDOR_PERMANENT_AUTH_ENABLED == YES
case VENDOR_PERMANENT_AUTH_HANDLE:
// vendor authorization value
pAuth = &g_platformUniqueAuth;
case VENDOR_PERMANENT_AUTH_HANDLE:
// vendor authorization value
pAuth = &g_platformUniqueAuth;
#endif
default:
// If any other permanent handle is present it is
// a code defect.
FAIL(FATAL_ERROR_INTERNAL);
break;
}
break;
}
case TPM_HT_TRANSIENT:
default:
// If any other permanent handle is present it is
// a code defect.
FAIL(FATAL_ERROR_INTERNAL);
break;
}
break;
}
case TPM_HT_TRANSIENT:
// authValue for an object
// A persistent object would have been copied into RAM
// and would have an transient object handle here.
{
OBJECT* object;
{
OBJECT* object;
object = HandleToObject(handle);
// special handling if this is a sequence object
if(ObjectIsSequence(object))
{
pAuth = &((HASH_OBJECT*)object)->auth;
}
else
{
// Authorization is available only when the private portion of
// the object is loaded. The check should be made before
// this function is called
pAssert(object->attributes.publicOnly == CLEAR);
pAuth = &object->sensitive.authValue;
}
}
break;
case TPM_HT_NV_INDEX:
object = HandleToObject(handle);
// special handling if this is a sequence object
if(ObjectIsSequence(object))
{
pAuth = &((HASH_OBJECT*)object)->auth;
}
else
{
// Authorization is available only when the private portion of
// the object is loaded. The check should be made before
// this function is called
pAssert(object->attributes.publicOnly == CLEAR);
pAuth = &object->sensitive.authValue;
}
}
break;
case TPM_HT_NV_INDEX:
// authValue for an NV index
{
NV_INDEX* nvIndex = NvGetIndexInfo(handle, NULL);
pAssert(nvIndex != NULL);
pAuth = &nvIndex->authValue;
}
break;
case TPM_HT_PCR:
{
NV_INDEX* nvIndex = NvGetIndexInfo(handle, NULL);
pAssert(nvIndex != NULL);
pAuth = &nvIndex->authValue;
}
break;
case TPM_HT_PCR:
// authValue for PCR
pAuth = PCRGetAuthValue(handle);
break;
default:
default:
// If any other handle type is present here, then there is a defect
// in the unmarshaling code.
FAIL(FATAL_ERROR_INTERNAL);
break;
}
}
// Copy the authValue
MemoryCopy2B((TPM2B*)auth, (TPM2B*)pAuth, sizeof(auth->t.buffer));
MemoryRemoveTrailingZeros(auth);
@ -330,74 +330,74 @@ EntityGetAuthValue(TPMI_DH_ENTITY handle, // IN: handle of entity
TPMI_ALG_HASH
EntityGetAuthPolicy(TPMI_DH_ENTITY handle, // IN: handle of entity
TPM2B_DIGEST* authPolicy // OUT: authPolicy of the entity
)
)
{
TPMI_ALG_HASH hashAlg = TPM_ALG_NULL;
authPolicy->t.size = 0;
switch(HandleGetType(handle))
{
case TPM_HT_PERMANENT:
{
case TPM_HT_PERMANENT:
switch(HierarchyNormalizeHandle(handle))
{
case TPM_RH_OWNER:
{
case TPM_RH_OWNER:
// ownerPolicy for TPM_RH_OWNER
*authPolicy = gp.ownerPolicy;
hashAlg = gp.ownerAlg;
break;
case TPM_RH_ENDORSEMENT:
case TPM_RH_ENDORSEMENT:
// endorsementPolicy for TPM_RH_ENDORSEMENT
*authPolicy = gp.endorsementPolicy;
hashAlg = gp.endorsementAlg;
break;
case TPM_RH_PLATFORM:
case TPM_RH_PLATFORM:
// platformPolicy for TPM_RH_PLATFORM
*authPolicy = gc.platformPolicy;
hashAlg = gc.platformAlg;
break;
case TPM_RH_LOCKOUT:
case TPM_RH_LOCKOUT:
// lockoutPolicy for TPM_RH_LOCKOUT
*authPolicy = gp.lockoutPolicy;
hashAlg = gp.lockoutAlg;
break;
#define ACT_GET_POLICY(N) \
case TPM_RH_ACT_##N: \
*authPolicy = go.ACT_##N.authPolicy; \
hashAlg = go.ACT_##N.hashAlg; \
break;
#define ACT_GET_POLICY(N) \
case TPM_RH_ACT_##N: \
*authPolicy = go.ACT_##N.authPolicy; \
hashAlg = go.ACT_##N.hashAlg; \
break;
// Get the policy for each implemented ACT
FOR_EACH_ACT(ACT_GET_POLICY)
default:
default:
hashAlg = TPM_ALG_ERROR;
break;
}
}
break;
case TPM_HT_TRANSIENT:
case TPM_HT_TRANSIENT:
// authPolicy for an object
{
OBJECT* object = HandleToObject(handle);
*authPolicy = object->publicArea.authPolicy;
hashAlg = object->publicArea.nameAlg;
}
break;
case TPM_HT_NV_INDEX:
{
OBJECT* object = HandleToObject(handle);
*authPolicy = object->publicArea.authPolicy;
hashAlg = object->publicArea.nameAlg;
}
break;
case TPM_HT_NV_INDEX:
// authPolicy for a NV index
{
NV_INDEX* nvIndex = NvGetIndexInfo(handle, NULL);
pAssert(nvIndex != 0);
*authPolicy = nvIndex->publicArea.authPolicy;
hashAlg = nvIndex->publicArea.nameAlg;
}
break;
case TPM_HT_PCR:
{
NV_INDEX* nvIndex = NvGetIndexInfo(handle, NULL);
pAssert(nvIndex != 0);
*authPolicy = nvIndex->publicArea.authPolicy;
hashAlg = nvIndex->publicArea.nameAlg;
}
break;
case TPM_HT_PCR:
// authPolicy for a PCR
hashAlg = PCRGetAuthPolicy(handle, authPolicy);
break;
default:
default:
// If any other handle type is present it is a code defect.
FAIL(FATAL_ERROR_INTERNAL);
break;
}
}
return hashAlg;
}
@ -405,31 +405,31 @@ EntityGetAuthPolicy(TPMI_DH_ENTITY handle, // IN: handle of entity
// This function returns the Name associated with a handle.
TPM2B_NAME* EntityGetName(TPMI_DH_ENTITY handle, // IN: handle of entity
TPM2B_NAME* name // OUT: name of entity
)
)
{
switch(HandleGetType(handle))
{
case TPM_HT_TRANSIENT:
{
// Name for an object
OBJECT* object = HandleToObject(handle);
// an object with no nameAlg has no name
if(object->publicArea.nameAlg == TPM_ALG_NULL)
name->b.size = 0;
else
*name = object->name;
break;
}
case TPM_HT_NV_INDEX:
{
case TPM_HT_TRANSIENT:
{
// Name for an object
OBJECT* object = HandleToObject(handle);
// an object with no nameAlg has no name
if(object->publicArea.nameAlg == TPM_ALG_NULL)
name->b.size = 0;
else
*name = object->name;
break;
}
case TPM_HT_NV_INDEX:
// Name for a NV index
NvGetNameByIndexHandle(handle, name);
break;
default:
default:
// For all other types, the handle is the Name
name->t.size = sizeof(TPM_HANDLE);
UINT32_TO_BYTE_ARRAY(handle, name->t.name);
break;
}
}
return name;
}
@ -441,77 +441,77 @@ TPM2B_NAME* EntityGetName(TPMI_DH_ENTITY handle, // IN: handle of entity
// c) An object handle belongs to its hierarchy.
TPMI_RH_HIERARCHY
EntityGetHierarchy(TPMI_DH_ENTITY handle // IN :handle of entity
)
)
{
TPMI_RH_HIERARCHY hierarchy = TPM_RH_NULL;
switch(HandleGetType(handle))
{
case TPM_HT_PERMANENT:
{
case TPM_HT_PERMANENT:
// hierarchy for a permanent handle
if(HierarchyIsFirmwareLimited(handle) || HierarchyIsSvnLimited(handle))
{
hierarchy = handle;
break;
}
{
hierarchy = handle;
break;
}
switch(handle)
{
case TPM_RH_PLATFORM:
case TPM_RH_ENDORSEMENT:
case TPM_RH_NULL:
{
case TPM_RH_PLATFORM:
case TPM_RH_ENDORSEMENT:
case TPM_RH_NULL:
hierarchy = handle;
break;
// all other permanent handles are associated with the owner
// hierarchy. (should only be TPM_RH_OWNER and TPM_RH_LOCKOUT)
default:
// all other permanent handles are associated with the owner
// hierarchy. (should only be TPM_RH_OWNER and TPM_RH_LOCKOUT)
default:
hierarchy = TPM_RH_OWNER;
break;
}
}
break;
case TPM_HT_NV_INDEX:
case TPM_HT_NV_INDEX:
// hierarchy for NV index
{
NV_INDEX* nvIndex = NvGetIndexInfo(handle, NULL);
pAssert(nvIndex != NULL);
{
NV_INDEX* nvIndex = NvGetIndexInfo(handle, NULL);
pAssert(nvIndex != NULL);
// If only the platform can delete the index, then it is
// considered to be in the platform hierarchy, otherwise it
// is in the owner hierarchy.
if(IS_ATTRIBUTE(
nvIndex->publicArea.attributes, TPMA_NV, PLATFORMCREATE))
hierarchy = TPM_RH_PLATFORM;
else
hierarchy = TPM_RH_OWNER;
}
break;
case TPM_HT_TRANSIENT:
// If only the platform can delete the index, then it is
// considered to be in the platform hierarchy, otherwise it
// is in the owner hierarchy.
if(IS_ATTRIBUTE(
nvIndex->publicArea.attributes, TPMA_NV, PLATFORMCREATE))
hierarchy = TPM_RH_PLATFORM;
else
hierarchy = TPM_RH_OWNER;
}
break;
case TPM_HT_TRANSIENT:
// hierarchy for an object
{
OBJECT* object;
object = HandleToObject(handle);
if(object->attributes.ppsHierarchy)
{
hierarchy = TPM_RH_PLATFORM;
}
else if(object->attributes.epsHierarchy)
{
hierarchy = TPM_RH_ENDORSEMENT;
}
else if(object->attributes.spsHierarchy)
{
hierarchy = TPM_RH_OWNER;
}
}
break;
case TPM_HT_PCR:
{
OBJECT* object;
object = HandleToObject(handle);
if(object->attributes.ppsHierarchy)
{
hierarchy = TPM_RH_PLATFORM;
}
else if(object->attributes.epsHierarchy)
{
hierarchy = TPM_RH_ENDORSEMENT;
}
else if(object->attributes.spsHierarchy)
{
hierarchy = TPM_RH_OWNER;
}
}
break;
case TPM_HT_PCR:
hierarchy = TPM_RH_OWNER;
break;
default:
default:
FAIL(FATAL_ERROR_INTERNAL);
break;
}
}
// this is unreachable but it provides a return value for the default
// case which makes the complier happy
return hierarchy;

View File

@ -59,32 +59,71 @@
/* */
/********************************************************************************/
#ifndef ENTITY_FP_H
#define ENTITY_FP_H
/*(Auto-generated)
* Created by TpmPrototypes; Version 3.0 July 18, 2017
* Date: Mar 7, 2020 Time: 07:19:36PM
*/
#ifndef _ENTITY_FP_H_
#define _ENTITY_FP_H_
//** Functions
//*** EntityGetLoadStatus()
// This function will check that all the handles access loaded entities.
// Return Type: TPM_RC
// TPM_RC_HANDLE handle type does not match
// TPM_RC_REFERENCE_Hx entity is not present
// TPM_RC_HIERARCHY entity belongs to a disabled hierarchy
// TPM_RC_OBJECT_MEMORY handle is an evict object but there is no
// space to load it to RAM
TPM_RC
EntityGetLoadStatus(
COMMAND *command // IN/OUT: command parsing structure
);
EntityGetLoadStatus(COMMAND* command // IN/OUT: command parsing structure
);
//*** EntityGetAuthValue()
// This function is used to access the 'authValue' associated with a handle.
// This function assumes that the handle references an entity that is accessible
// and the handle is not for a persistent objects. That is EntityGetLoadStatus()
// should have been called. Also, the accessibility of the authValue should have
// been verified by IsAuthValueAvailable().
//
// This function copies the authorization value of the entity to 'auth'.
// Return Type: UINT16
// count number of bytes in the authValue with 0's stripped
UINT16
EntityGetAuthValue(
TPMI_DH_ENTITY handle, // IN: handle of entity
TPM2B_AUTH *auth // OUT: authValue of the entity
);
EntityGetAuthValue(TPMI_DH_ENTITY handle, // IN: handle of entity
TPM2B_AUTH* auth // OUT: authValue of the entity
);
//*** EntityGetAuthPolicy()
// This function is used to access the 'authPolicy' associated with a handle.
// This function assumes that the handle references an entity that is accessible
// and the handle is not for a persistent objects. That is EntityGetLoadStatus()
// should have been called. Also, the accessibility of the authPolicy should have
// been verified by IsAuthPolicyAvailable().
//
// This function copies the authorization policy of the entity to 'authPolicy'.
//
// The return value is the hash algorithm for the policy.
TPMI_ALG_HASH
EntityGetAuthPolicy(
TPMI_DH_ENTITY handle, // IN: handle of entity
TPM2B_DIGEST *authPolicy // OUT: authPolicy of the entity
);
TPM2B_NAME *
EntityGetName(
TPMI_DH_ENTITY handle, // IN: handle of entity
TPM2B_NAME *name // OUT: name of entity
);
EntityGetAuthPolicy(TPMI_DH_ENTITY handle, // IN: handle of entity
TPM2B_DIGEST* authPolicy // OUT: authPolicy of the entity
);
//*** EntityGetName()
// This function returns the Name associated with a handle.
TPM2B_NAME* EntityGetName(TPMI_DH_ENTITY handle, // IN: handle of entity
TPM2B_NAME* name // OUT: name of entity
);
//*** EntityGetHierarchy()
// This function returns the hierarchy handle associated with an entity.
// a) A handle that is a hierarchy handle is associated with itself.
// b) An NV index belongs to TPM_RH_PLATFORM if TPMA_NV_PLATFORMCREATE,
// is SET, otherwise it belongs to TPM_RH_OWNER
// c) An object handle belongs to its hierarchy.
TPMI_RH_HIERARCHY
EntityGetHierarchy(
TPMI_DH_ENTITY handle // IN :handle of entity
);
EntityGetHierarchy(TPMI_DH_ENTITY handle // IN :handle of entity
);
#endif
#endif // _ENTITY_FP_H_

View File

@ -59,8 +59,8 @@
/* */
/********************************************************************************/
/* C.4 Entropy.c */
/* C.4.1. Includes and Local values*/
//** Includes and Local Values
#define _CRT_RAND_S
#include <stdlib.h>
#include <memory.h>
@ -70,31 +70,31 @@
#include <time.h>
#include "Platform.h"
#if defined _MSC_VER || defined _MINGW
#include <process.h>
#if defined _MSC_VER || defined _MINGW // libtpms changed
# include <process.h>
#else
#include <unistd.h>
# include <unistd.h>
#endif
/* This is the last 32-bits of hardware entropy produced. We have to check to see that two
consecutive 32-bit values are not the same because (according to FIPS 140-2, annex C */
/* "If each call to a RNG produces blocks of n bits (where n > 15), the first n-bit block generated
after power-up, initialization, or reset shall not be used, but shall be saved for comparison
with the next n-bit block to be generated. Each subsequent generation of an n-bit block shall be
compared with the previously generated block. The test shall fail if any two compared n-bit
blocks are equal." */
extern uint32_t lastEntropy;
// This is the last 32-bits of hardware entropy produced. We have to check to
// see that two consecutive 32-bit values are not the same because
// according to FIPS 140-2, annex C:
//
// "If each call to an RNG produces blocks of n bits (where n > 15), the first
// n-bit block generated after power-up, initialization, or reset shall not be
// used, but shall be saved for comparison with the next n-bit block to be
// generated. Each subsequent generation of an n-bit block shall be compared with
// the previously generated block. The test shall fail if any two compared n-bit
// blocks are equal."
extern uint32_t lastEntropy;
/* C.4.2. Functions */
/* C.4.2.1. rand32() */
/* Local function to get a 32-bit random number */
//** Functions
static uint32_t
rand32(
void
)
//*** rand32()
// Local function to get a 32-bit random number
static uint32_t rand32(void)
{
uint32_t rndNum = rand();
uint32_t rndNum = rand();
#if RAND_MAX < UINT16_MAX
// If the maximum value of the random number is a 15-bit number, then shift it up
// 15 bits, get 15 more bits, shift that up 2 and then XOR in another value to get
@ -111,20 +111,20 @@ rand32(
return rndNum;
}
/* C.4.2.2 _plat__GetEntropy() */
/* This function is used to get available hardware entropy. In a hardware implementation of this
function, there would be no call to the system to get entropy. */
/* Return Values Meaning */
/* < 0 hardware failure of the entropy generator, this is sticky */
/* >= 0 the returned amount of entropy (bytes) */
LIB_EXPORT int32_t
_plat__GetEntropy(
unsigned char *entropy, // output buffer
uint32_t amount // amount requested
)
//*** _plat__GetEntropy()
// This function is used to get available hardware entropy. In a hardware
// implementation of this function, there would be no call to the system
// to get entropy.
// Return Type: int32_t
// < 0 hardware failure of the entropy generator, this is sticky
// >= 0 the returned amount of entropy (bytes)
//
LIB_EXPORT int32_t _plat__GetEntropy(unsigned char* entropy, // output buffer
uint32_t amount // amount requested
)
{
uint32_t rndNum;
int32_t ret;
uint32_t rndNum;
int32_t ret;
//
// libtpms added begin
if (amount > 0 && RAND_bytes(entropy, amount) == 1)
@ -133,53 +133,53 @@ _plat__GetEntropy(
// libtpms added end
if(amount == 0)
{
// Seed the platform entropy source if the entropy source is software. There is
// no reason to put a guard macro (#if or #ifdef) around this code because this
// code would not be here if someone was changing it for a system with actual
// hardware.
//
// NOTE 1: The following command does not provide proper cryptographic entropy.
// Its primary purpose to make sure that different instances of the simulator,
// possibly started by a script on the same machine, are seeded differently.
// Vendors of the actual TPMs need to ensure availability of proper entropy
// using their platform specific means.
//
// NOTE 2: In debug builds by default the reference implementation will seed
// its RNG deterministically (without using any platform provided randomness).
// See the USE_DEBUG_RNG macro and DRBG_GetEntropy() function.
#if defined _MSC_VER || defined _MINGW
srand((unsigned)_plat__RealTime() ^ _getpid());
{
// Seed the platform entropy source if the entropy source is software. There
// is no reason to put a guard macro (#if or #ifdef) around this code because
// this code would not be here if someone was changing it for a system with
// actual hardware.
//
// NOTE 1: The following command does not provide proper cryptographic
// entropy. Its primary purpose to make sure that different instances of the
// simulator, possibly started by a script on the same machine, are seeded
// differently. Vendors of the actual TPMs need to ensure availability of
// proper entropy using their platform-specific means.
//
// NOTE 2: In debug builds by default the reference implementation will seed
// its RNG deterministically (without using any platform provided randomness).
// See the USE_DEBUG_RNG macro and DRBG_GetEntropy() function.
#if defined _MSC_VER || defined _MINGW // libtpms changed
srand((unsigned)_plat__RealTime() ^ _getpid());
#else
srand((unsigned)_plat__RealTime() ^ getpid());
srand((unsigned)_plat__RealTime() ^ getpid());
#endif
lastEntropy = rand32();
ret = 0;
}
lastEntropy = rand32();
ret = 0;
}
else
{
rndNum = rand32();
if(rndNum == lastEntropy)
{
ret = -1;
}
else
{
lastEntropy = rndNum;
// Each process will have its random number generator initialized according
// to the process id and the initialization time. This is not a lot of
// entropy so, to add a bit more, XOR the current time value into the
// returned entropy value.
// NOTE: the reason for including the time here rather than have it in
// in the value assigned to lastEntropy is that rand() could be broken and
// using the time would in the lastEntropy value would hide this.
rndNum ^= (uint32_t)_plat__RealTime();
// Only provide entropy 32 bits at a time to test the ability
// of the caller to deal with partial results.
ret = MIN(amount, sizeof(rndNum));
memcpy(entropy, &rndNum, ret);
}
}
{
rndNum = rand32();
if(rndNum == lastEntropy)
{
ret = -1;
}
else
{
lastEntropy = rndNum;
// Each process will have its random number generator initialized
// according to the process id and the initialization time. This is not a
// lot of entropy so, to add a bit more, XOR the current time value into
// the returned entropy value.
// NOTE: the reason for including the time here rather than have it in
// in the value assigned to lastEntropy is that rand() could be broken and
// using the time would in the lastEntropy value would hide this.
rndNum ^= (uint32_t)_plat__RealTime();
// Only provide entropy 32 bits at a time to test the ability
// of the caller to deal with partial results.
ret = MIN(amount, sizeof(rndNum));
memcpy(entropy, &rndNum, ret);
}
}
return ret;
}

View File

@ -59,30 +59,37 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef EVENTSEQUENCECOMPLETE_FP_H
#define EVENTSEQUENCECOMPLETE_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_DH_PCR pcrHandle;
TPMI_DH_OBJECT sequenceHandle;
TPM2B_MAX_BUFFER buffer;
#if CC_EventSequenceComplete // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_EVENTSEQUENCECOMPLETE_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_EVENTSEQUENCECOMPLETE_FP_H_
// Input structure definition
typedef struct
{
TPMI_DH_PCR pcrHandle;
TPMI_DH_OBJECT sequenceHandle;
TPM2B_MAX_BUFFER buffer;
} EventSequenceComplete_In;
#define RC_EventSequenceComplete_pcrHandle (TPM_RC_H + TPM_RC_1)
#define RC_EventSequenceComplete_sequenceHandle (TPM_RC_H + TPM_RC_2)
#define RC_EventSequenceComplete_buffer (TPM_RC_P + TPM_RC_1)
typedef struct {
TPML_DIGEST_VALUES results;
// Output structure definition
typedef struct
{
TPML_DIGEST_VALUES results;
} EventSequenceComplete_Out;
// Response code modifiers
# define RC_EventSequenceComplete_pcrHandle (TPM_RC_H + TPM_RC_1)
# define RC_EventSequenceComplete_sequenceHandle (TPM_RC_H + TPM_RC_2)
# define RC_EventSequenceComplete_buffer (TPM_RC_P + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_EventSequenceComplete(
EventSequenceComplete_In *in, // IN: input parameter list
EventSequenceComplete_Out *out // OUT: output parameter list
);
TPM2_EventSequenceComplete(EventSequenceComplete_In* in,
EventSequenceComplete_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_EVENTSEQUENCECOMPLETE_FP_H_
#endif // CC_EventSequenceComplete

View File

@ -59,24 +59,30 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef EVICTCONTROL_FP_H
#define EVICTCONTROL_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_RH_PROVISION auth;
TPMI_DH_OBJECT objectHandle;
TPMI_DH_PERSISTENT persistentHandle;
#if CC_EvictControl // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_EVICTCONTROL_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_EVICTCONTROL_FP_H_
// Input structure definition
typedef struct
{
TPMI_RH_PROVISION auth;
TPMI_DH_OBJECT objectHandle;
TPMI_DH_PERSISTENT persistentHandle;
} EvictControl_In;
#define RC_EvictControl_auth (TPM_RC_H + TPM_RC_1)
#define RC_EvictControl_objectHandle (TPM_RC_H + TPM_RC_2)
#define RC_EvictControl_persistentHandle (TPM_RC_P + TPM_RC_1)
// Response code modifiers
# define RC_EvictControl_auth (TPM_RC_H + TPM_RC_1)
# define RC_EvictControl_objectHandle (TPM_RC_H + TPM_RC_2)
# define RC_EvictControl_persistentHandle (TPM_RC_P + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_EvictControl(
EvictControl_In *in // IN: input parameter list
);
TPM2_EvictControl(EvictControl_In* in);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_EVICTCONTROL_FP_H_
#endif // CC_EvictControl

View File

@ -58,59 +58,75 @@
/* */
/********************************************************************************/
/* 6.2 ExecCommand.c */
/* This file contains the entry function ExecuteCommand() which provides the main control flow for
TPM command execution. */
//** Introduction
//
// This file contains the entry function ExecuteCommand() which provides the main
// control flow for TPM command execution.
//** Includes
#include "Tpm.h"
#include "ExecCommand_fp.h"
#include "Marshal.h"
// TODO_RENAME_INC_FOLDER:platform_interface refers to the TPM_CoreLib platform interface
#include "ExecCommand_fp.h" // libtpms changed
// Uncomment this next #include if doing static command/response buffer sizing
// #include "CommandResponseSizes_fp.h"
#define TPM_HAVE_TPM2_DECLARATIONS
#include "tpm_library_intern.h" // libtpms added
/* Uncomment this next #include if doing static command/response buffer sizing */
// #include "CommandResponseSizes_fp.h"
//** ExecuteCommand()
//
// The function performs the following steps.
// a) Parses the command header from input buffer.
// b) Calls ParseHandleBuffer() to parse the handle area of the command.
// c) Validates that each of the handles references a loaded entity.
// d) Calls ParseSessionBuffer() () to:
// 1) unmarshal and parse the session area;
// 2) check the authorizations; and
// 3) when necessary, decrypt a parameter.
// e) Calls CommandDispatcher() to:
// 1) unmarshal the command parameters from the command buffer;
// 2) call the routine that performs the command actions; and
// 3) marshal the responses into the response buffer.
// f) If any error occurs in any of the steps above create the error response and return.
// g) Calls BuildResponseSession() to:
// 1) when necessary, encrypt a parameter
// 2) build the response authorization sessions
// 3) update the audit sessions and nonces
// h) Calls BuildResponseHeader() to complete the construction of the response.
// responseSize is set by the caller to the maximum number of bytes available in the output
// buffer. ExecuteCommand() will adjust the value and return the number of bytes placed in
// the buffer.
// response is also set by the caller to indicate the buffer into which ExecuteCommand() is
// to place the response.
// request and response may point to the same buffer
// NOTE: As of February, 2016, the failure processing has been moved to the platform-specific
// code. When the TPM code encounters an unrecoverable failure, it will SET g_inFailureMode
// and call _plat__Fail(). That function should not return but may call ExecuteCommand().
LIB_EXPORT void
ExecuteCommand(
uint32_t requestSize, // IN: command buffer size
unsigned char *request, // IN: command buffer
uint32_t *responseSize, // IN/OUT: response buffer size
unsigned char **response // IN/OUT: response buffer
)
//
// a) Parses the command header from input buffer.
// b) Calls ParseHandleBuffer() to parse the handle area of the command.
// c) Validates that each of the handles references a loaded entity.
// d) Calls ParseSessionBuffer () to:
// 1) unmarshal and parse the session area;
// 2) check the authorizations; and
// 3) when necessary, decrypt a parameter.
// e) Calls CommandDispatcher() to:
// 1) unmarshal the command parameters from the command buffer;
// 2) call the routine that performs the command actions; and
// 3) marshal the responses into the response buffer.
// f) If any error occurs in any of the steps above create the error response
// and return.
// g) Calls BuildResponseSession() to:
// 1) when necessary, encrypt a parameter
// 2) build the response authorization sessions
// 3) update the audit sessions and nonces
// h) Calls BuildResponseHeader() to complete the construction of the response.
//
// 'responseSize' is set by the caller to the maximum number of bytes available in
// the output buffer. ExecuteCommand will adjust the value and return the number
// of bytes placed in the buffer.
//
// 'response' is also set by the caller to indicate the buffer into which
// ExecuteCommand is to place the response.
//
// 'request' and 'response' may point to the same buffer
//
// Note: As of February, 2016, the failure processing has been moved to the
// platform-specific code. When the TPM code encounters an unrecoverable failure, it
// will SET g_inFailureMode and call _plat__Fail(). That function should not return
// but may call ExecuteCommand().
//
LIB_EXPORT void ExecuteCommand(
uint32_t requestSize, // IN: command buffer size
unsigned char* request, // IN: command buffer
uint32_t* responseSize, // IN/OUT: response buffer size
unsigned char** response // IN/OUT: response buffer
)
{
// Command local variables
UINT32 commandSize;
COMMAND command;
UINT32 commandSize;
COMMAND command;
// Response local variables
UINT32 maxResponse = *responseSize;
TPM_RC result; // return code for the command
UINT32 maxResponse = *responseSize;
TPM_RC result; // return code for the command
/* check for an unreasonably large command size, since it's cast to a signed integer later */
if (requestSize > INT32_MAX) {
@ -119,7 +135,7 @@ ExecuteCommand(
}
// This next function call is used in development to size the command and response
// buffers. The values printed are the sizes of the internal structures and
// not the sizes of the canonical forms of he command response structures. Also,
// not the sizes of the canonical forms of the command response structures. Also,
// the sizes do not include the tag, command.code, requestSize, or the authorization
// fields.
//CommandResponseSizes();
@ -127,14 +143,14 @@ ExecuteCommand(
// operation that may require a NV write. Note, that this needs to be done
// even when in failure mode. Otherwise, g_updateNV would stay SET while in
// Failure mode and the NV would be written on each call.
g_updateNV = UT_NONE;
g_updateNV = UT_NONE;
g_clearOrderly = FALSE;
if(g_inFailureMode)
{
// Do failure mode processing
TpmFailureMode(requestSize, request, responseSize, response);
return;
}
{
// Do failure mode processing
TpmFailureMode(requestSize, request, responseSize, response);
return;
}
// Query platform to get the NV state. The result state is saved internally
// and will be reported by NvIsAvailable(). The reference code requires that
// accessibility of NV does not change during the execution of a command.
@ -142,34 +158,36 @@ ExecuteCommand(
// is not available later when it is necessary to write to NV, then the TPM
// will go into failure mode.
NvCheckState();
// Due to the limitations of the simulation, TPM clock must be explicitly
// synchronized with the system clock whenever a command is received.
// This function call is not necessary in a hardware TPM. However, taking
// a snapshot of the hardware timer at the beginning of the command allows
// the time value to be consistent for the duration of the command execution.
TimeUpdateToCurrent();
// Any command through this function will unceremoniously end the
// _TPM_Hash_Data/_TPM_Hash_End sequence.
if(g_DRTMHandle != TPM_RH_UNASSIGNED)
ObjectTerminateEvent();
ObjectTerminateEvent();
// Get command buffer size and command buffer.
command.tag = 0; // libtpms added: Coverity
command.parameterBuffer = request;
command.parameterSize = requestSize;
command.parameterSize = requestSize;
// Parse command header: tag, commandSize and command.code.
// First parse the tag. The unmarshaling routine will validate
// that it is either TPM_ST_SESSIONS or TPM_ST_NO_SESSIONS.
result = TPMI_ST_COMMAND_TAG_Unmarshal(&command.tag,
&command.parameterBuffer,
&command.parameterSize);
result = TPMI_ST_COMMAND_TAG_Unmarshal(
&command.tag, &command.parameterBuffer, &command.parameterSize);
if(result != TPM_RC_SUCCESS)
goto Cleanup;
goto Cleanup;
// Unmarshal the commandSize indicator.
result = UINT32_Unmarshal(&commandSize,
&command.parameterBuffer,
&command.parameterSize);
result = UINT32_Unmarshal(
&commandSize, &command.parameterBuffer, &command.parameterSize);
if(result != TPM_RC_SUCCESS)
goto Cleanup;
goto Cleanup;
// On a TPM that receives bytes on a port, the number of bytes that were
// received on that port is requestSize it must be identical to commandSize.
// In addition, commandSize must not be larger than MAX_COMMAND_SIZE allowed
@ -178,150 +196,158 @@ ExecuteCommand(
// places them in the input buffer) would likely have the input truncated when
// it reaches MAX_COMMAND_SIZE, and requestSize would not equal commandSize.
if(commandSize != requestSize || commandSize > MAX_COMMAND_SIZE)
{
result = TPM_RC_COMMAND_SIZE;
goto Cleanup;
}
{
result = TPM_RC_COMMAND_SIZE;
goto Cleanup;
}
// Unmarshal the command code.
result = TPM_CC_Unmarshal(&command.code, &command.parameterBuffer,
&command.parameterSize);
result = TPM_CC_Unmarshal(
&command.code, &command.parameterBuffer, &command.parameterSize);
if(result != TPM_RC_SUCCESS)
goto Cleanup;
goto Cleanup;
// Check to see if the command is implemented.
command.index = CommandCodeToCommandIndex(command.code);
if(UNIMPLEMENTED_COMMAND_INDEX == command.index)
{
result = TPM_RC_COMMAND_CODE;
goto Cleanup;
}
#if FIELD_UPGRADE_IMPLEMENTED == YES
{
result = TPM_RC_COMMAND_CODE;
goto Cleanup;
}
#if FIELD_UPGRADE_IMPLEMENTED == YES
// If the TPM is in FUM, then the only allowed command is
// TPM_CC_FieldUpgradeData.
if(IsFieldUgradeMode() && (command.code != TPM_CC_FieldUpgradeData))
{
result = TPM_RC_UPGRADE;
goto Cleanup;
}
{
result = TPM_RC_UPGRADE;
goto Cleanup;
}
else
#endif
// Excepting FUM, the TPM only accepts TPM2_Startup() after
// _TPM_Init. After getting a TPM2_Startup(), TPM2_Startup()
// is no longer allowed.
if((!TPMIsStarted() && command.code != TPM_CC_Startup)
|| (TPMIsStarted() && command.code == TPM_CC_Startup))
{
result = TPM_RC_INITIALIZE;
goto Cleanup;
}
// Excepting FUM, the TPM only accepts TPM2_Startup() after
// _TPM_Init. After getting a TPM2_Startup(), TPM2_Startup()
// is no longer allowed.
if((!TPMIsStarted() && command.code != TPM_CC_Startup)
|| (TPMIsStarted() && command.code == TPM_CC_Startup))
{
result = TPM_RC_INITIALIZE;
goto Cleanup;
}
// Start regular command process.
NvIndexCacheInit();
// Parse Handle buffer.
result = ParseHandleBuffer(&command);
if(result != TPM_RC_SUCCESS)
goto Cleanup;
goto Cleanup;
// All handles in the handle area are required to reference TPM-resident
// entities.
result = EntityGetLoadStatus(&command);
if(result != TPM_RC_SUCCESS)
goto Cleanup;
goto Cleanup;
// Authorization session handling for the command.
ClearCpRpHashes(&command);
if(command.tag == TPM_ST_SESSIONS)
{
// Find out session buffer size.
result = UINT32_Unmarshal((UINT32 *)&command.authSize,
&command.parameterBuffer,
&command.parameterSize);
if(result != TPM_RC_SUCCESS)
goto Cleanup;
// Perform sanity check on the unmarshaled value. If it is smaller than
// the smallest possible session or larger than the remaining size of
// the command, then it is an error. NOTE: This check could pass but the
// session size could still be wrong. That will be determined after the
// sessions are unmarshaled.
if(command.authSize < 9
|| command.authSize > command.parameterSize)
{
result = TPM_RC_SIZE;
goto Cleanup;
}
command.parameterSize -= command.authSize;
// The actions of ParseSessionBuffer() are described in the introduction.
// As the sessions are parsed command.parameterBuffer is advanced so, on a
// successful return, command.parameterBuffer should be pointing at the
// first byte of the parameters.
result = ParseSessionBuffer(&command);
if(result != TPM_RC_SUCCESS)
goto Cleanup;
}
{
// Find out session buffer size.
result = UINT32_Unmarshal((UINT32*)&command.authSize,
&command.parameterBuffer,
&command.parameterSize);
if(result != TPM_RC_SUCCESS)
goto Cleanup;
// Perform sanity check on the unmarshaled value. If it is smaller than
// the smallest possible session or larger than the remaining size of
// the command, then it is an error. NOTE: This check could pass but the
// session size could still be wrong. That will be determined after the
// sessions are unmarshaled.
if(command.authSize < 9 || command.authSize > command.parameterSize)
{
result = TPM_RC_SIZE;
goto Cleanup;
}
command.parameterSize -= command.authSize;
// The actions of ParseSessionBuffer() are described in the introduction.
// As the sessions are parsed command.parameterBuffer is advanced so, on a
// successful return, command.parameterBuffer should be pointing at the
// first byte of the parameters.
result = ParseSessionBuffer(&command);
if(result != TPM_RC_SUCCESS)
goto Cleanup;
}
else
{
command.authSize = 0;
// The command has no authorization sessions.
// If the command requires authorizations, then CheckAuthNoSession() will
// return an error.
result = CheckAuthNoSession(&command);
if(result != TPM_RC_SUCCESS)
goto Cleanup;
}
{
command.authSize = 0;
// The command has no authorization sessions.
// If the command requires authorizations, then CheckAuthNoSession() will
// return an error.
result = CheckAuthNoSession(&command);
if(result != TPM_RC_SUCCESS)
goto Cleanup;
}
// Set up the response buffer pointers. CommandDispatch will marshal the
// response parameters starting at the address in command.responseBuffer.
// *response = MemoryGetResponseBuffer(command.index);
//*response = MemoryGetResponseBuffer(command.index);
// leave space for the command header
command.responseBuffer = *response + STD_RESPONSE_HEADER;
// leave space for the parameter size field if needed
if(command.tag == TPM_ST_SESSIONS)
command.responseBuffer += sizeof(UINT32);
command.responseBuffer += sizeof(UINT32);
if(IsHandleInResponse(command.index))
command.responseBuffer += sizeof(TPM_HANDLE);
command.responseBuffer += sizeof(TPM_HANDLE);
// CommandDispatcher returns a response handle buffer and a response parameter
// buffer if it succeeds. It will also set the parameterSize field in the
// buffer if the tag is TPM_RC_SESSIONS.
result = CommandDispatcher(&command);
if(result != TPM_RC_SUCCESS)
goto Cleanup;
goto Cleanup;
// Build the session area at the end of the parameter area.
result = BuildResponseSession(&command);
if(result != TPM_RC_SUCCESS)
{
goto Cleanup;
}
Cleanup:
if(g_clearOrderly == TRUE
&& NV_IS_ORDERLY)
{
{
goto Cleanup;
}
Cleanup:
if(g_clearOrderly == TRUE && NV_IS_ORDERLY)
{
#if USE_DA_USED
gp.orderlyState = g_daUsed ? SU_DA_USED_VALUE : SU_NONE_VALUE;
gp.orderlyState = g_daUsed ? SU_DA_USED_VALUE : SU_NONE_VALUE;
#else
gp.orderlyState = SU_NONE_VALUE;
gp.orderlyState = SU_NONE_VALUE;
#endif
NV_SYNC_PERSISTENT(orderlyState);
}
NV_SYNC_PERSISTENT(orderlyState);
}
// This implementation loads an "evict" object to a transient object slot in
// RAM whenever an "evict" object handle is used in a command so that the
// access to any object is the same. These temporary objects need to be
// cleared from RAM whether the command succeeds or fails.
ObjectCleanupEvict();
// The parameters and sessions have been marshaled. Now tack on the header and
// set the sizes
BuildResponseHeader(&command, *response, result);
// Try to commit all the writes to NV if any NV write happened during this
// command execution. This check should be made for both succeeded and failed
// commands, because a failed one may trigger a NV write in DA logic as well.
// This is the only place in the command execution path that may call the NV
// commit. If the NV commit fails, the TPM should be put in failure mode.
if((g_updateNV != UT_NONE) && !g_inFailureMode)
{
if(g_updateNV == UT_ORDERLY)
NvUpdateIndexOrderlyData();
if(!NvCommit())
FAIL(FATAL_ERROR_INTERNAL);
g_updateNV = UT_NONE;
}
{
if(g_updateNV == UT_ORDERLY)
NvUpdateIndexOrderlyData();
if(!NvCommit())
FAIL(FATAL_ERROR_INTERNAL);
g_updateNV = UT_NONE;
}
pAssert((UINT32)command.parameterSize <= maxResponse);
// Clear unused bits in response buffer.
MemorySet(*response + *responseSize, 0, maxResponse - *responseSize);
// as a final act, and not before, update the response size.
*responseSize = (UINT32)command.parameterSize;
return;
}

View File

@ -59,15 +59,56 @@
/* */
/********************************************************************************/
#ifndef EXECCOMMAND_FP_H
#define EXECCOMMAND_FP_H
/*(Auto-generated)
* Created by TpmPrototypes; Version 3.0 July 18, 2017
* Date: Mar 28, 2019 Time: 08:25:19PM
*/
LIB_EXPORT void
ExecuteCommand(
uint32_t requestSize, // IN: command buffer size
unsigned char *request, // IN: command buffer
uint32_t *responseSize, // IN/OUT: response buffer size
unsigned char **response // IN/OUT: response buffer
);
#ifndef _EXEC_COMMAND_FP_H_
#define _EXEC_COMMAND_FP_H_
#endif
//** ExecuteCommand()
//
// The function performs the following steps.
//
// a) Parses the command header from input buffer.
// b) Calls ParseHandleBuffer() to parse the handle area of the command.
// c) Validates that each of the handles references a loaded entity.
// d) Calls ParseSessionBuffer () to:
// 1) unmarshal and parse the session area;
// 2) check the authorizations; and
// 3) when necessary, decrypt a parameter.
// e) Calls CommandDispatcher() to:
// 1) unmarshal the command parameters from the command buffer;
// 2) call the routine that performs the command actions; and
// 3) marshal the responses into the response buffer.
// f) If any error occurs in any of the steps above create the error response
// and return.
// g) Calls BuildResponseSession() to:
// 1) when necessary, encrypt a parameter
// 2) build the response authorization sessions
// 3) update the audit sessions and nonces
// h) Calls BuildResponseHeader() to complete the construction of the response.
//
// 'responseSize' is set by the caller to the maximum number of bytes available in
// the output buffer. ExecuteCommand will adjust the value and return the number
// of bytes placed in the buffer.
//
// 'response' is also set by the caller to indicate the buffer into which
// ExecuteCommand is to place the response.
//
// 'request' and 'response' may point to the same buffer
//
// Note: As of February, 2016, the failure processing has been moved to the
// platform-specific code. When the TPM code encounters an unrecoverable failure, it
// will SET g_inFailureMode and call _plat__Fail(). That function should not return
// but may call ExecuteCommand().
//
LIB_EXPORT void ExecuteCommand(
uint32_t requestSize, // IN: command buffer size
unsigned char* request, // IN: command buffer
uint32_t* responseSize, // IN/OUT: response buffer size
unsigned char** response // IN/OUT: response buffer
);
#endif // _EXEC_COMMAND_FP_H_

View File

@ -81,10 +81,10 @@
// manufacture and CLEAR. The buffer will contain the last value provided
// to the Core library.
LIB_EXPORT void _plat__GetPlatformManufactureData(uint8_t* pPlatformPersistentData,
uint32_t bufferSize)
uint32_t bufferSize)
{
if(bufferSize != 0)
{
memset((void*)pPlatformPersistentData, 0xFF, bufferSize);
}
{
memset((void*)pPlatformPersistentData, 0xFF, bufferSize);
}
}

View File

@ -59,20 +59,26 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef FLUSHCONTEXT_FP_H
#define FLUSHCONTEXT_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_DH_CONTEXT flushHandle;
#if CC_FlushContext // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_FLUSHCONTEXT_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_FLUSHCONTEXT_FP_H_
// Input structure definition
typedef struct
{
TPMI_DH_CONTEXT flushHandle;
} FlushContext_In;
#define RC_FlushContext_flushHandle (TPM_RC_P + TPM_RC_1)
// Response code modifiers
# define RC_FlushContext_flushHandle (TPM_RC_P + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_FlushContext(
FlushContext_In *in // IN: input parameter list
);
TPM2_FlushContext(FlushContext_In* in);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_FLUSHCONTEXT_FP_H_
#endif // CC_FlushContext

View File

@ -59,32 +59,37 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef GETCAPABILITY_FP_H
#define GETCAPABILITY_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPM_CAP capability;
UINT32 property;
UINT32 propertyCount;
#if CC_GetCapability // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETCAPABILITY_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETCAPABILITY_FP_H_
// Input structure definition
typedef struct
{
TPM_CAP capability;
UINT32 property;
UINT32 propertyCount;
} GetCapability_In;
#define RC_GetCapability_capability (TPM_RC_P + TPM_RC_1)
#define RC_GetCapability_property (TPM_RC_P + TPM_RC_2)
#define RC_GetCapability_propertyCount (TPM_RC_P + TPM_RC_3)
typedef struct {
TPMI_YES_NO moreData;
TPMS_CAPABILITY_DATA capabilityData;
// Output structure definition
typedef struct
{
TPMI_YES_NO moreData;
TPMS_CAPABILITY_DATA capabilityData;
} GetCapability_Out;
// Response code modifiers
# define RC_GetCapability_capability (TPM_RC_P + TPM_RC_1)
# define RC_GetCapability_property (TPM_RC_P + TPM_RC_2)
# define RC_GetCapability_propertyCount (TPM_RC_P + TPM_RC_3)
// Function prototype
TPM_RC
TPM2_GetCapability(
GetCapability_In *in, // IN: input parameter list
GetCapability_Out *out // OUT: output parameter list
);
TPM2_GetCapability(GetCapability_In* in, GetCapability_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETCAPABILITY_FP_H_
#endif // CC_GetCapability

View File

@ -59,33 +59,40 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef GETCOMMANDAUDITDIGEST_FP_H
#define GETCOMMANDAUDITDIGEST_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_RH_ENDORSEMENT privacyHandle;
TPMI_DH_OBJECT signHandle;
TPM2B_DATA qualifyingData;
TPMT_SIG_SCHEME inScheme;
#if CC_GetCommandAuditDigest // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETCOMMANDAUDITDIGEST_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETCOMMANDAUDITDIGEST_FP_H_
// Input structure definition
typedef struct
{
TPMI_RH_ENDORSEMENT privacyHandle;
TPMI_DH_OBJECT signHandle;
TPM2B_DATA qualifyingData;
TPMT_SIG_SCHEME inScheme;
} GetCommandAuditDigest_In;
#define RC_GetCommandAuditDigest_privacyHandle (TPM_RC_H + TPM_RC_1)
#define RC_GetCommandAuditDigest_signHandle (TPM_RC_H + TPM_RC_2)
#define RC_GetCommandAuditDigest_qualifyingData (TPM_RC_P + TPM_RC_1)
#define RC_GetCommandAuditDigest_inScheme (TPM_RC_P + TPM_RC_2)
typedef struct {
TPM2B_ATTEST auditInfo;
TPMT_SIGNATURE signature;
// Output structure definition
typedef struct
{
TPM2B_ATTEST auditInfo;
TPMT_SIGNATURE signature;
} GetCommandAuditDigest_Out;
// Response code modifiers
# define RC_GetCommandAuditDigest_privacyHandle (TPM_RC_H + TPM_RC_1)
# define RC_GetCommandAuditDigest_signHandle (TPM_RC_H + TPM_RC_2)
# define RC_GetCommandAuditDigest_qualifyingData (TPM_RC_P + TPM_RC_1)
# define RC_GetCommandAuditDigest_inScheme (TPM_RC_P + TPM_RC_2)
// Function prototype
TPM_RC
TPM2_GetCommandAuditDigest(
GetCommandAuditDigest_In *in, // IN: input parameter list
GetCommandAuditDigest_Out *out // OUT: output parameter list
);
TPM2_GetCommandAuditDigest(GetCommandAuditDigest_In* in,
GetCommandAuditDigest_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETCOMMANDAUDITDIGEST_FP_H_
#endif // CC_GetCommandAuditDigest

View File

@ -59,26 +59,32 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef GETRANDOM_FP_H
#define GETRANDOM_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
UINT16 bytesRequested;
#if CC_GetRandom // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETRANDOM_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETRANDOM_FP_H_
// Input structure definition
typedef struct
{
UINT16 bytesRequested;
} GetRandom_In;
#define RC_GetRandom_bytesRequested (TPM_RC_P + TPM_RC_1)
typedef struct {
TPM2B_DIGEST randomBytes;
// Output structure definition
typedef struct
{
TPM2B_DIGEST randomBytes;
} GetRandom_Out;
// Response code modifiers
# define RC_GetRandom_bytesRequested (TPM_RC_P + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_GetRandom(
GetRandom_In *in, // IN: input parameter list
GetRandom_Out *out // OUT: output parameter list
);
TPM2_GetRandom(GetRandom_In* in, GetRandom_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETRANDOM_FP_H_
#endif // CC_GetRandom

View File

@ -59,35 +59,42 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef GETSESSIONAUDITDIGEST_FP_H
#define GETSESSIONAUDITDIGEST_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_RH_ENDORSEMENT privacyAdminHandle;
TPMI_DH_OBJECT signHandle;
TPMI_SH_HMAC sessionHandle;
TPM2B_DATA qualifyingData;
TPMT_SIG_SCHEME inScheme;
#if CC_GetSessionAuditDigest // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETSESSIONAUDITDIGEST_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETSESSIONAUDITDIGEST_FP_H_
// Input structure definition
typedef struct
{
TPMI_RH_ENDORSEMENT privacyAdminHandle;
TPMI_DH_OBJECT signHandle;
TPMI_SH_HMAC sessionHandle;
TPM2B_DATA qualifyingData;
TPMT_SIG_SCHEME inScheme;
} GetSessionAuditDigest_In;
#define RC_GetSessionAuditDigest_privacyAdminHandle (TPM_RC_H + TPM_RC_1)
#define RC_GetSessionAuditDigest_signHandle (TPM_RC_H + TPM_RC_2)
#define RC_GetSessionAuditDigest_sessionHandle (TPM_RC_H + TPM_RC_3)
#define RC_GetSessionAuditDigest_qualifyingData (TPM_RC_P + TPM_RC_1)
#define RC_GetSessionAuditDigest_inScheme (TPM_RC_P + TPM_RC_2)
typedef struct {
TPM2B_ATTEST auditInfo;
TPMT_SIGNATURE signature;
// Output structure definition
typedef struct
{
TPM2B_ATTEST auditInfo;
TPMT_SIGNATURE signature;
} GetSessionAuditDigest_Out;
// Response code modifiers
# define RC_GetSessionAuditDigest_privacyAdminHandle (TPM_RC_H + TPM_RC_1)
# define RC_GetSessionAuditDigest_signHandle (TPM_RC_H + TPM_RC_2)
# define RC_GetSessionAuditDigest_sessionHandle (TPM_RC_H + TPM_RC_3)
# define RC_GetSessionAuditDigest_qualifyingData (TPM_RC_P + TPM_RC_1)
# define RC_GetSessionAuditDigest_inScheme (TPM_RC_P + TPM_RC_2)
// Function prototype
TPM_RC
TPM2_GetSessionAuditDigest(
GetSessionAuditDigest_In *in, // IN: input parameter list
GetSessionAuditDigest_Out *out // OUT: output parameter list
);
TPM2_GetSessionAuditDigest(GetSessionAuditDigest_In* in,
GetSessionAuditDigest_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETSESSIONAUDITDIGEST_FP_H_
#endif // CC_GetSessionAuditDigest

View File

@ -59,21 +59,24 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef GETTESTRESULT_FP_H
#define GETTESTRESULT_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct{
TPM2B_MAX_BUFFER outData;
TPM_RC testResult;
#if CC_GetTestResult // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETTESTRESULT_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETTESTRESULT_FP_H_
// Output structure definition
typedef struct
{
TPM2B_MAX_BUFFER outData;
TPM_RC testResult;
} GetTestResult_Out;
// Function prototype
TPM_RC
TPM2_GetTestResult(GetTestResult_Out* out);
TPM_RC
TPM2_GetTestResult(
GetTestResult_Out *out // OUT: output parameter list
);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETTESTRESULT_FP_H_
#endif // CC_GetTestResult

View File

@ -59,33 +59,39 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef GETTIME_FP_H
#define GETTIME_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_RH_ENDORSEMENT privacyAdminHandle;
TPMI_DH_OBJECT signHandle;
TPM2B_DATA qualifyingData;
TPMT_SIG_SCHEME inScheme;
#if CC_GetTime // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETTIME_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETTIME_FP_H_
// Input structure definition
typedef struct
{
TPMI_RH_ENDORSEMENT privacyAdminHandle;
TPMI_DH_OBJECT signHandle;
TPM2B_DATA qualifyingData;
TPMT_SIG_SCHEME inScheme;
} GetTime_In;
#define RC_GetTime_privacyAdminHandle (TPM_RC_H + TPM_RC_1)
#define RC_GetTime_signHandle (TPM_RC_H + TPM_RC_2)
#define RC_GetTime_qualifyingData (TPM_RC_P + TPM_RC_1)
#define RC_GetTime_inScheme (TPM_RC_P + TPM_RC_2)
typedef struct {
TPM2B_ATTEST timeInfo;
TPMT_SIGNATURE signature;
// Output structure definition
typedef struct
{
TPM2B_ATTEST timeInfo;
TPMT_SIGNATURE signature;
} GetTime_Out;
// Response code modifiers
# define RC_GetTime_privacyAdminHandle (TPM_RC_H + TPM_RC_1)
# define RC_GetTime_signHandle (TPM_RC_H + TPM_RC_2)
# define RC_GetTime_qualifyingData (TPM_RC_P + TPM_RC_1)
# define RC_GetTime_inScheme (TPM_RC_P + TPM_RC_2)
// Function prototype
TPM_RC
TPM2_GetTime(
GetTime_In *in, // IN: input parameter list
GetTime_Out *out // OUT: output parameter list
);
TPM2_GetTime(GetTime_In* in, GetTime_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_GETTIME_FP_H_
#endif // CC_GetTime

View File

@ -92,17 +92,17 @@
// are all using consistent string values.
// each instance must define a different struct since the buffer sizes vary.
#define TPM2B_STRING(name, value) \
typedef union name##_ \
{ \
struct \
{ \
UINT16 size; \
BYTE buffer[sizeof(value)]; \
} t; \
TPM2B b; \
} TPM2B_##name##_; \
const TPM2B_##name##_ name##_data = {{sizeof(value), {value}}}; \
#define TPM2B_STRING(name, value) \
typedef union name##_ \
{ \
struct \
{ \
UINT16 size; \
BYTE buffer[sizeof(value)]; \
} t; \
TPM2B b; \
} TPM2B_##name##_; \
const TPM2B_##name##_ name##_data = {{sizeof(value), {value}}}; \
const TPM2B* name = &name##_data.b
TPM2B_STRING(PRIMARY_OBJECT_CREATION, "Primary Object Creation");
@ -127,19 +127,19 @@ TPM2B_STRING(OAEP_TEST_STRING, "OAEP Test Value");
//*** g_rcIndex[]
const UINT16 g_rcIndex[15] = {TPM_RC_1,
TPM_RC_2,
TPM_RC_3,
TPM_RC_4,
TPM_RC_5,
TPM_RC_6,
TPM_RC_7,
TPM_RC_8,
TPM_RC_9,
TPM_RC_A,
TPM_RC_B,
TPM_RC_C,
TPM_RC_D,
TPM_RC_E,
TPM_RC_F};
TPM_RC_2,
TPM_RC_3,
TPM_RC_4,
TPM_RC_5,
TPM_RC_6,
TPM_RC_7,
TPM_RC_8,
TPM_RC_9,
TPM_RC_A,
TPM_RC_B,
TPM_RC_C,
TPM_RC_D,
TPM_RC_E,
TPM_RC_F};
BOOL g_manufactured = FALSE;

View File

@ -157,36 +157,36 @@ typedef struct
{
#if LITTLE_ENDIAN_TPM == YES /* libtpms added */
unsigned publicOnly : 1; //0) SET if only the public portion of
// an object is loaded
// an object is loaded
unsigned epsHierarchy : 1; //1) SET if the object belongs to EPS
// Hierarchy
// Hierarchy
unsigned ppsHierarchy : 1; //2) SET if the object belongs to PPS
// Hierarchy
// Hierarchy
unsigned spsHierarchy : 1; //3) SET f the object belongs to SPS
// Hierarchy
// Hierarchy
unsigned evict : 1; //4) SET if the object is a platform or
// owner evict object. Platform-
// evict object belongs to PPS
// hierarchy, owner-evict object
// belongs to SPS or EPS hierarchy.
// This bit is also used to mark a
// completed sequence object so it
// will be flush when the
// SequenceComplete command succeeds.
// owner evict object. Platform-
// evict object belongs to PPS
// hierarchy, owner-evict object
// belongs to SPS or EPS hierarchy.
// This bit is also used to mark a
// completed sequence object so it
// will be flush when the
// SequenceComplete command succeeds.
unsigned primary : 1; //5) SET for a primary object
unsigned temporary : 1; //6) SET for a temporary object
unsigned stClear : 1; //7) SET for an stClear object
unsigned hmacSeq : 1; //8) SET for an HMAC or MAC sequence
// object
// object
unsigned hashSeq : 1; //9) SET for a hash sequence object
unsigned eventSeq : 1; //10) SET for an event sequence object
unsigned ticketSafe : 1; //11) SET if a ticket is safe to create
// for hash sequence object
// for hash sequence object
unsigned firstBlock : 1; //12) SET if the first block of hash
// data has been received. It
// works with ticketSafe bit
// data has been received. It
// works with ticketSafe bit
unsigned isParent : 1; //13) SET if the key has the proper
// attributes to be a parent key
// attributes to be a parent key
unsigned privateExp : 1; //14) SET when the private exponent // libtpms: keep
// // of an RSA key has been validated.
#if 0 // lbtpms added
@ -253,18 +253,18 @@ typedef struct OBJECT
#endif // libtpms added end
TPM2B_NAME qualifiedName; // object qualified name
TPMI_DH_OBJECT evictHandle; // if the object is an evict object,
// the original handle is kept here.
// The 'working' handle will be the
// handle of an object slot.
// the original handle is kept here.
// The 'working' handle will be the
// handle of an object slot.
TPM2B_NAME name; // Name of the object name. Kept here
// to avoid repeatedly computing it.
// to avoid repeatedly computing it.
TPMI_RH_HIERARCHY hierarchy; // Hierarchy for the object. While the
// base hierarchy can be deduced from
// 'attributes', if the hierarchy is
// firmware-bound or SVN-bound then
// this field carries additional metadata
// needed to derive the proof value for
// the object.
// base hierarchy can be deduced from
// 'attributes', if the hierarchy is
// firmware-bound or SVN-bound then
// this field carries additional metadata
// needed to derive the proof value for
// the object.
#if __LONG_WIDTH__ == 32
UINT8 _pad1[4]; /* 32 bit targets need padding */
#endif
@ -292,13 +292,13 @@ typedef struct HASH_OBJECT
TPMI_ALG_PUBLIC type; // algorithm
TPMI_ALG_HASH nameAlg; // name algorithm
TPMA_OBJECT objectAttributes; // object attributes
// The data below is unique to a sequence object
TPM2B_AUTH auth; // authorization for use of sequence
union
{
HASH_STATE hashState[HASH_COUNT];
HMAC_STATE hmacState;
HASH_STATE hashState[HASH_COUNT];
HMAC_STATE hmacState;
} state;
} HASH_OBJECT;
@ -436,46 +436,46 @@ typedef struct SESSION
{
SESSION_ATTRIBUTES attributes; // session attributes
UINT32 pcrCounter; // PCR counter value when PCR is
// included (policy session)
// If no PCR is included, this
// value is 0.
// included (policy session)
// If no PCR is included, this
// value is 0.
UINT64 startTime; // The value in g_time when the session
// was started (policy session)
// was started (policy session)
UINT64 timeout; // The timeout relative to g_time
// There is no timeout if this value
// is 0.
// There is no timeout if this value
// is 0.
CLOCK_NONCE epoch; // The g_clockEpoch value when the
// session was started. If g_clockEpoch
// does not match this value when the
// timeout is used, then
// then the command will fail.
// session was started. If g_clockEpoch
// does not match this value when the
// timeout is used, then
// then the command will fail.
TPM_CC commandCode; // command code (policy session)
TPM_ALG_ID authHashAlg; // session hash algorithm
TPMA_LOCALITY commandLocality; // command locality (policy session)
TPMT_SYM_DEF symmetric; // session symmetric algorithm (if any)
TPM2B_AUTH sessionKey; // session secret value used for
// this session
// this session
TPM2B_NONCE nonceTPM; // last TPM-generated nonce for
// generating HMAC and encryption keys
// generating HMAC and encryption keys
union
{
TPM2B_NAME boundEntity; // value used to track the entity to
// which the session is bound
TPM2B_DIGEST cpHash; // the required cpHash value for the
// command being authorized
TPM2B_DIGEST nameHash; // the required nameHash
TPM2B_DIGEST templateHash; // the required template for creation
TPM2B_DIGEST pHash; // the required parameter hash value for the
// command being authorized
TPM2B_NAME boundEntity; // value used to track the entity to
// which the session is bound
TPM2B_DIGEST cpHash; // the required cpHash value for the
// command being authorized
TPM2B_DIGEST nameHash; // the required nameHash
TPM2B_DIGEST templateHash; // the required template for creation
TPM2B_DIGEST pHash; // the required parameter hash value for the
// command being authorized
} u1;
union
{
TPM2B_DIGEST auditDigest; // audit session digest
TPM2B_DIGEST policyDigest; // policyHash
TPM2B_DIGEST auditDigest; // audit session digest
TPM2B_DIGEST policyDigest; // policyHash
} u2; // audit log and policyHash may
// share space to save memory
// share space to save memory
} SESSION;
# define EXPIRES_ON_RESET INT32_MIN
@ -499,7 +499,7 @@ typedef BYTE SESSION_BUF[sizeof(SESSION)];
typedef struct PCR_SAVE
{
FOR_EACH_HASH(PCR_SAVE_SPACE)
// This counter increments whenever the PCR are updated.
// NOTE: A platform-specific specification may designate
// certain PCR changes as not causing this counter
@ -531,11 +531,11 @@ typedef struct PCR_AUTH_VALUE
// This enumeration is the possible startup types. The type is determined
// by the combination of TPM2_ShutDown and TPM2_Startup.
typedef enum
{
SU_RESET,
SU_RESTART,
SU_RESUME
} STARTUP_TYPE;
{
SU_RESET,
SU_RESTART,
SU_RESUME
} STARTUP_TYPE;
//**NV
@ -797,15 +797,15 @@ typedef struct
// data provided by the platform library during manufacturing.
// Opaque to the TPM Core library, but may be used by the platform library.
BYTE platformReserved[PERSISTENT_DATA_PLATFORM_SPACE];
//*********************************************************************************
// Hierarchy
//*********************************************************************************
// The values in this section are related to the hierarchies.
BOOL disableClear; // TRUE if TPM2_Clear() using
// lockoutAuth is disabled
// lockoutAuth is disabled
// Hierarchy authPolicies
TPMI_ALG_HASH ownerAlg;
TPMI_ALG_HASH endorsementAlg;
@ -813,12 +813,12 @@ typedef struct
TPM2B_DIGEST ownerPolicy;
TPM2B_DIGEST endorsementPolicy;
TPM2B_DIGEST lockoutPolicy;
// Hierarchy authValues
TPM2B_AUTH ownerAuth;
TPM2B_AUTH endorsementAuth;
TPM2B_AUTH lockoutAuth;
// Primary Seeds
TPM2B_SEED EPSeed;
TPM2B_SEED SPSeed;
@ -828,13 +828,13 @@ typedef struct
SEED_COMPAT_LEVEL SPSeedCompatLevel;
SEED_COMPAT_LEVEL PPSeedCompatLevel; // libtpms added end
// Note there is a nullSeed in the state_reset memory.
// Hierarchy proofs
TPM2B_PROOF phProof;
TPM2B_PROOF shProof;
TPM2B_PROOF ehProof;
// Note there is a nullProof in the state_reset memory.
//*********************************************************************************
// Reset Events
//*********************************************************************************
@ -843,28 +843,28 @@ typedef struct
// manufacture process. It is used to invalidate all saved contexts after a TPM
// Reset.
UINT64 totalResetCount;
// This counter increments on each TPM Reset. The counter is reset by
// TPM2_Clear().
UINT32 resetCount;
//*********************************************************************************
// PCR
//*********************************************************************************
// This structure hold the policies for those PCR that have an update policy.
// This implementation only supports a single group of PCR controlled by
// policy. If more are required, then this structure would be changed to
// an array.
//*********************************************************************************
// PCR
//*********************************************************************************
// This structure hold the policies for those PCR that have an update policy.
// This implementation only supports a single group of PCR controlled by
// policy. If more are required, then this structure would be changed to
// an array.
# if defined NUM_POLICY_PCR_GROUP && NUM_POLICY_PCR_GROUP > 0
PCR_POLICY pcrPolicies;
# endif
// This structure indicates the allocation of PCR. The structure contains a
// list of PCR allocations for each implemented algorithm. If no PCR are
// allocated for an algorithm, a list entry still exists but the bit map
// will contain no SET bits.
TPML_PCR_SELECTION pcrAllocated;
//*********************************************************************************
// Physical Presence
//*********************************************************************************
@ -875,41 +875,41 @@ typedef struct
//
// These bits may be changed with TPM2_PP_Commands().
BYTE ppList[(COMMAND_COUNT + 7) / 8];
//*********************************************************************************
// Dictionary attack values
//*********************************************************************************
// These values are used for dictionary attack tracking and control.
UINT32 failedTries; // the current count of unexpired
// authorization failures
// authorization failures
UINT32 maxTries; // number of unexpired authorization
// failures before the TPM is in
// lockout
// failures before the TPM is in
// lockout
UINT32 recoveryTime; // time between authorization failures
// before failedTries is decremented
// before failedTries is decremented
UINT32 lockoutRecovery; // time that must expire between
// authorization failures associated
// with lockoutAuth
// authorization failures associated
// with lockoutAuth
BOOL lockOutAuthEnabled; // TRUE if use of lockoutAuth is
// allowed
// allowed
//*****************************************************************************
// Orderly State
//*****************************************************************************
// The orderly state for current cycle
TPM_SU orderlyState;
//*****************************************************************************
// Command audit values.
//*****************************************************************************
BYTE auditCommands[((COMMAND_COUNT + 1) + 7) / 8];
TPMI_ALG_HASH auditHashAlg;
UINT64 auditCounter;
//*****************************************************************************
// Algorithm selection
//*****************************************************************************
@ -917,7 +917,7 @@ typedef struct
// The 'algorithmSet' value indicates the collection of algorithms that are
// currently in used on the TPM. The interpretation of value is vendor dependent.
UINT32 algorithmSet;
//*****************************************************************************
// Firmware version
//*****************************************************************************
@ -927,26 +927,26 @@ typedef struct
// is consistent with vendor needs. The values are maintained in RAM for simplified
// access with a master version in NV. These values are modified in a
// vendor-specific way.
// g_firmwareV1 contains the more significant 32-bits of the vendor version number.
// In the reference implementation, if this value is printed as a hex
// value, it will have the format of YYYYMMDD
UINT32 firmwareV1;
// g_firmwareV1 contains the less significant 32-bits of the vendor version number.
// In the reference implementation, if this value is printed as a hex
// value, it will have the format of 00 HH MM SS
UINT32 firmwareV2;
//*****************************************************************************
// Timer Epoch
//*****************************************************************************
// timeEpoch contains a nonce that has a vendor=specific size (should not be
// less than 8 bytes. This nonce changes when the clock epoch changes. The clock
// epoch changes when there is a discontinuity in the timing of the TPM.
//*****************************************************************************
// Timer Epoch
//*****************************************************************************
// timeEpoch contains a nonce that has a vendor=specific size (should not be
// less than 8 bytes. This nonce changes when the clock epoch changes. The clock
// epoch changes when there is a discontinuity in the timing of the TPM.
# if !CLOCK_STOPS
CLOCK_NONCE timeEpoch;
# endif
} PERSISTENT_DATA;
EXTERN PERSISTENT_DATA gp;
@ -962,18 +962,18 @@ typedef struct orderly_data
//*****************************************************************************
// TIME
//*****************************************************************************
// Clock has two parts. One is the state save part and one is the NV part. The
// state save version is updated on each command. When the clock rolls over, the
// NV version is updated. When the TPM starts up, if the TPM was shutdown in and
// orderly way, then the sClock value is used to initialize the clock. If the
// TPM shutdown was not orderly, then the persistent value is used and the safe
// attribute is clear.
UINT64 clock; // The orderly version of clock
TPMI_YES_NO clockSafe; // Indicates if the clock value is
// safe.
// safe.
// In many implementations, the quality of the entropy available is not that
// high. To compensate, the current value of the drbgState can be saved and
// restored on each power cycle. This prevents the internal state from reverting
@ -981,31 +981,31 @@ typedef struct orderly_data
// of entropy. By keeping the old state and adding entropy, the entropy will
// accumulate.
DRBG_STATE drbgState;
// These values allow the accumulation of self-healing time across orderly shutdown
// of the TPM.
// These values allow the accumulation of self-healing time across orderly shutdown
// of the TPM.
# if ACCUMULATE_SELF_HEAL_TIMER
UINT64 selfHealTimer; // current value of s_selfHealTimer
UINT64 lockoutTimer; // current value of s_lockoutTimer
UINT64 time; // current value of g_time at shutdown
# endif // ACCUMULATE_SELF_HEAL_TIMER
#ifndef __ACT_DISABLED // libtpms added
#error ACT not supported in ORDERLY_DATA!
// These are the ACT Timeout values. They are saved with the other timers
// These are the ACT Timeout values. They are saved with the other timers
# define DefineActData(N) ACT_STATE ACT_##N;
FOR_EACH_ACT(DefineActData)
// this is the 'signaled' attribute data for all the ACT. It is done this way so
// that they can be manipulated by ACT number rather than having to access a
// structure.
UINT16 signaledACT;
UINT16 preservedSignaled;
# if ORDERLY_DATA_PADDING != 0
BYTE reserved[ORDERLY_DATA_PADDING];
# endif
#endif // libtpms added
} ORDERLY_DATA;
@ -1042,27 +1042,27 @@ typedef struct state_clear_data
TPMI_ALG_HASH platformAlg; // default reset is TPM_ALG_NULL
TPM2B_DIGEST platformPolicy; // default reset is an Empty Buffer
TPM2B_AUTH platformAuth; // default reset is an Empty Buffer
//*****************************************************************************
// PCR
//*****************************************************************************
// The set of PCR to be saved on Shutdown(STATE)
PCR_SAVE pcrSave; // default reset is 0...0
// This structure hold the authorization values for those PCR that have an
// update authorization.
// This implementation only supports a single group of PCR controlled by
// authorization. If more are required, then this structure would be changed to
// an array.
PCR_AUTHVALUE pcrAuthValues;
#ifndef __ACT_DISABLED // libtpms added
//*****************************************************************************
// ACT
//*****************************************************************************
//*****************************************************************************
// ACT
//*****************************************************************************
# define DefineActPolicySpace(N) TPMT_HA act_##N;
FOR_EACH_ACT(DefineActPolicySpace)
# if STATE_CLEAR_DATA_PADDING != 0
BYTE reserved[STATE_CLEAR_DATA_PADDING];
# endif
@ -1089,14 +1089,14 @@ typedef struct state_reset_data
// Hierarchy Control
//*****************************************************************************
TPM2B_PROOF nullProof; // The proof value associated with
// the TPM_RH_NULL hierarchy. The
// default reset value is from the RNG.
// the TPM_RH_NULL hierarchy. The
// default reset value is from the RNG.
TPM2B_SEED nullSeed; // The seed value for the TPM_RN_NULL
// hierarchy. The default reset value
// is from the RNG.
SEED_COMPAT_LEVEL nullSeedCompatLevel; // libtpms added
// hierarchy. The default reset value
// is from the RNG.
//*****************************************************************************
// Context
//*****************************************************************************
@ -1107,21 +1107,21 @@ typedef struct state_reset_data
// If 'clearCount' is at its maximum value when the TPM receives a Shutdown(STATE),
// the TPM will return TPM_RC_RANGE and the TPM will only accept Shutdown(CLEAR).
UINT32 clearCount; // The default reset value is 0.
UINT64 objectContextID; // This is the context ID for a saved
// object context. The default reset
// value is 0.
// object context. The default reset
// value is 0.
CONTEXT_SLOT contextArray[MAX_ACTIVE_SESSIONS]; // This array contains
// contains the values used to track
// the version numbers of saved
// contexts (see
// Session.c in for details). The
// default reset value is {0}.
// contains the values used to track
// the version numbers of saved
// contexts (see
// Session.c in for details). The
// default reset value is {0}.
CONTEXT_COUNTER contextCounter; // This is the value from which the
// 'contextID' is derived. The
// default reset value is {0}.
// 'contextID' is derived. The
// default reset value is {0}.
//*****************************************************************************
// Command Audit
//*****************************************************************************
@ -1130,18 +1130,18 @@ typedef struct state_reset_data
// TPM will extend the cpHash and rpHash for the command to this value. If this
// digest was the Zero Digest before the cpHash was extended, the audit counter
// is incremented.
TPM2B_DIGEST commandAuditDigest; // This value is set to an Empty Digest
// by TPM2_GetCommandAuditDigest() or a
// TPM Reset.
// by TPM2_GetCommandAuditDigest() or a
// TPM Reset.
//*****************************************************************************
// Boot counter
//*****************************************************************************
UINT32 restartCount; // This counter counts TPM Restarts.
// The default reset value is 0.
// The default reset value is 0.
//*********************************************************************************
// PCR
//*********************************************************************************
@ -1153,25 +1153,25 @@ typedef struct state_reset_data
// NOTE: A platform-specific specification may designate that certain PCR changes
// do not increment this counter to increment.
UINT32 pcrCounter; // The default reset value is 0.
# if ALG_ECC
//*****************************************************************************
// ECDAA
//*****************************************************************************
UINT64 commitCounter; // This counter increments each time
// TPM2_Commit() returns
// TPM_RC_SUCCESS. The default reset
// value is 0.
// TPM2_Commit() returns
// TPM_RC_SUCCESS. The default reset
// value is 0.
TPM2B_NONCE commitNonce; // This random value is used to compute
// the commit values. The default reset
// value is from the RNG.
// the commit values. The default reset
// value is from the RNG.
// This implementation relies on the number of bits in g_commitArray being a
// power of 2 (8, 16, 32, 64, etc.) and no greater than 64K.
BYTE commitArray[16]; // The default reset value is {0}.
# endif // ALG_ECC
# if STATE_RESET_DATA_PADDING != 0
BYTE reserved[STATE_RESET_DATA_PADDING];
@ -1225,14 +1225,14 @@ EXTERN CONTEXT_SLOT s_ContextSlotMask;
//** Global Macro Definitions
// The NV_READ_PERSISTENT and NV_WRITE_PERSISTENT macros are used to access members
// of the PERSISTENT_DATA structure in NV.
# define NV_READ_PERSISTENT(to, from) \
NvRead(&to, offsetof(PERSISTENT_DATA, from), sizeof(to))
# define NV_READ_PERSISTENT(to, from) \
NvRead(&to, offsetof(PERSISTENT_DATA, from), sizeof(to))
# define NV_WRITE_PERSISTENT(to, from) \
NvWrite(offsetof(PERSISTENT_DATA, to), sizeof(gp.to), &from)
# define NV_WRITE_PERSISTENT(to, from) \
NvWrite(offsetof(PERSISTENT_DATA, to), sizeof(gp.to), &from)
# define CLEAR_PERSISTENT(item) \
NvClearPersistent(offsetof(PERSISTENT_DATA, item), sizeof(gp.item))
# define CLEAR_PERSISTENT(item) \
NvClearPersistent(offsetof(PERSISTENT_DATA, item), sizeof(gp.item))
# define NV_SYNC_PERSISTENT(item) NV_WRITE_PERSISTENT(item, gp.item)
@ -1248,9 +1248,9 @@ typedef struct _COMMAND_FLAGS_
{
#if LITTLE_ENDIAN_TPM == YES /* libtpms added */
unsigned trialPolicy : 1; //1) If SET, one of the handles references a
// trial policy and authorization may be
// skipped. This is only allowed for a policy
// command.
// trial policy and authorization may be
// skipped. This is only allowed for a policy
// command.
unsigned reserved : 31; //2-31) /* libtpms added begin */
#endif
#if BIG_ENDIAN_TPM == YES
@ -1276,20 +1276,20 @@ typedef struct COMMAND
TPM_CC code; // the parsed command code
COMMAND_INDEX index; // the computed command index
UINT32 handleNum; // the number of entity handles in the
// handle area of the command
// handle area of the command
TPM_HANDLE handles[MAX_HANDLE_NUM]; // the parsed handle values
UINT32 sessionNum; // the number of sessions found
INT32 parameterSize; // starts out with the parsed command size
// and is reduced and values are
// unmarshaled. Just before calling the
// command actions, this should be zero.
// After the command actions, this number
// should grow as values are marshaled
// in to the response buffer.
// and is reduced and values are
// unmarshaled. Just before calling the
// command actions, this should be zero.
// After the command actions, this number
// should grow as values are marshaled
// in to the response buffer.
INT32 authSize; // this is initialized with the parsed size
// of authorizationSize field and should
// be zero when the authorizations are
// parsed.
// of authorizationSize field and should
// be zero when the authorizations are
// parsed.
BYTE* parameterBuffer; // input to ExecuteCommand
BYTE* responseBuffer; // input to ExecuteCommand
FOR_EACH_HASH(CP_HASH) // space for the CP hashes
@ -1501,7 +1501,7 @@ EXTERN int s_freeSessionSlots;
// dispatch code will marshal the response values into the final output buffer.
EXTERN UINT64 s_actionIoBuffer[768]; // action I/O buffer
EXTERN UINT32 s_actionIoAllocation; // number of UIN64 allocated for the
// action input structure
// action input structure
# endif // IO_BUFFER_C
//*****************************************************************************

View File

@ -101,9 +101,9 @@
# endif
#endif // FAIL_TRACE
// SETFAILED calls TpmFail. It may or may not return based on the NO_LONGJMP flag.
// CODELOCATOR is a macro that expands to either one 64-bit value that encodes the
// location, or two parameters: Function Name and Line Number.
// SETFAILED calls TpmFail. It may or may not return based on the NO_LONGJMP flag.
// CODELOCATOR is a macro that expands to either one 64-bit value that encodes the
// location, or two parameters: Function Name and Line Number.
#define SETFAILED(errorCode) (TpmFail(CODELOCATOR(), errorCode))
// If implementation is using longjmp, then calls to TpmFail() will never
@ -156,12 +156,12 @@
# define FAIL_RC(failCode) SETFAILED(failCode)
# define FAIL_VOID(failCode) SETFAILED(failCode)
# define FAIL_NULL(failCode) SETFAILED(failCode)
# define FAIL_EXIT(failCode, returnVar, returnCode) \
do \
{ \
SETFAILED(failCode); \
goto Exit; \
} while(0)
# define FAIL_EXIT(failCode, returnVar, returnCode) \
do \
{ \
SETFAILED(failCode); \
goto Exit; \
} while(0)
#else // NO_LONGJMP
// no longjmp service is available
@ -175,20 +175,20 @@
# define FAIL_NORET(failCode) SETFAILED(failCode)
// fail and immediately return void
# define FAIL_VOID(failCode) \
do \
{ \
SETFAILED(failCode); \
return; \
} while(0)
# define FAIL_VOID(failCode) \
do \
{ \
SETFAILED(failCode); \
return; \
} while(0)
// fail and immediately return a value
# define FAIL_IMMEDIATE(failCode, retval) \
do \
{ \
SETFAILED(failCode); \
return retval; \
} while(0)
# define FAIL_IMMEDIATE(failCode, retval) \
do \
{ \
SETFAILED(failCode); \
return retval; \
} while(0)
// fail and return FALSE
# define FAIL_BOOL(failCode) FAIL_IMMEDIATE(failCode, FALSE)
@ -200,13 +200,13 @@
# define FAIL_NULL(failCode) FAIL_IMMEDIATE(failCode, NULL)
// fail and return using the goto exit pattern
# define FAIL_EXIT(failCode, returnVar, returnCode) \
do \
{ \
SETFAILED(failCode); \
returnVar = returnCode; \
goto Exit; \
} while(0)
# define FAIL_EXIT(failCode, returnVar, returnCode) \
do \
{ \
SETFAILED(failCode); \
returnVar = returnCode; \
goto Exit; \
} while(0)
#endif
@ -214,66 +214,66 @@
// if it is not. If longjmp is being used, then the macro makes a call from
// which there is no return. Otherwise, the function will return the given
// return code.
#define VERIFY(condition, failCode, returnCode) \
do \
{ \
if(!(condition)) \
{ \
FAIL_IMMEDIATE(failCode, returnCode); \
} \
} while(0)
#define VERIFY(condition, failCode, returnCode) \
do \
{ \
if(!(condition)) \
{ \
FAIL_IMMEDIATE(failCode, returnCode); \
} \
} while(0)
// this function also verifies a condition and enters failure mode, but sets a
// return value and jumps to Exit on failure - allowing for cleanup.
#define VERIFY_OR_EXIT(condition, failCode, returnVar, returnCode) \
do \
{ \
if(!(condition)) \
{ \
FAIL_EXIT(failCode, returnVar, returnCode); \
} \
} while(0)
#define VERIFY_OR_EXIT(condition, failCode, returnVar, returnCode) \
do \
{ \
if(!(condition)) \
{ \
FAIL_EXIT(failCode, returnVar, returnCode); \
} \
} while(0)
// verify the given TPM_RC is success and we are not in
// failure mode. Otherwise, return immediately with TPM_RC_FAILURE.
// note that failure mode is checked first so that an existing FATAL_* error code
// is not overwritten with the default from this macro.
#define VERIFY_RC(rc) \
do \
{ \
if(g_inFailureMode) \
{ \
return TPM_RC_FAILURE; \
} \
if(rc != TPM_RC_SUCCESS) \
{ \
FAIL_IMMEDIATE(FATAL_ERROR_ASSERT, TPM_RC_FAILURE); \
} \
} while(0)
#define VERIFY_RC(rc) \
do \
{ \
if(g_inFailureMode) \
{ \
return TPM_RC_FAILURE; \
} \
if(rc != TPM_RC_SUCCESS) \
{ \
FAIL_IMMEDIATE(FATAL_ERROR_ASSERT, TPM_RC_FAILURE); \
} \
} while(0)
// verify the TPM is not in failure mode or return failure
#define VERIFY_NOT_FAILED() \
do \
{ \
if(g_inFailureMode) \
{ \
return TPM_RC_FAILURE; \
} \
} while(0)
#define VERIFY_NOT_FAILED() \
do \
{ \
if(g_inFailureMode) \
{ \
return TPM_RC_FAILURE; \
} \
} while(0)
// Enter failure mode if the given TPM_RC is not success, return void.
#define VERIFY_RC_VOID(rc) \
do \
{ \
if(g_inFailureMode) \
{ \
return; \
} \
if(rc != TPM_RC_SUCCESS) \
{ \
FAIL_VOID(FATAL_ERROR_ASSERT); \
} \
} while(0)
#define VERIFY_RC_VOID(rc) \
do \
{ \
if(g_inFailureMode) \
{ \
return; \
} \
if(rc != TPM_RC_SUCCESS) \
{ \
FAIL_VOID(FATAL_ERROR_ASSERT); \
} \
} while(0)
// These VERIFY_CRYPTO macros all set failure mode to FATAL_ERROR_CRYPTO
// and immediately return. The general way to parse the names is:
@ -300,95 +300,95 @@
#define VERIFY_CRYPTO_OR_NULL(fn) VERIFY((fn), FATAL_ERROR_CRYPTO, NULL)
// these VERIFY_CRYPTO macros all set a result value and goto Exit
#define VERIFY_CRYPTO_OR_EXIT(fn, returnVar, returnCode) \
#define VERIFY_CRYPTO_OR_EXIT(fn, returnVar, returnCode) \
VERIFY_OR_EXIT(fn, FATAL_ERROR_CRYPTO, returnVar, returnCode);
// these VERIFY_CRYPTO_OR_EXIT functions assume the return value variable is
// named retVal
#define VERIFY_CRYPTO_OR_EXIT_RC(fn) \
#define VERIFY_CRYPTO_OR_EXIT_RC(fn) \
VERIFY_CRYPTO_OR_EXIT_GENERIC(fn, retVal, TPM_RC_FAILURE)
#define VERIFY_CRYPTO_OR_EXIT_FALSE(fn) \
#define VERIFY_CRYPTO_OR_EXIT_FALSE(fn) \
VERIFY_CRYPTO_OR_EXIT_GENERIC(fn, retVal, FALSE)
#define VERIFY_CRYPTO_RC_OR_EXIT(fn) \
do \
{ \
TPM_RC rc = fn; \
if(rc != TPM_RC_SUCCESS) \
{ \
FAIL_EXIT(FATAL_ERROR_CRYPTO, retVal, rc); \
} \
} while(0)
#define VERIFY_CRYPTO_RC_OR_EXIT(fn) \
do \
{ \
TPM_RC rc = fn; \
if(rc != TPM_RC_SUCCESS) \
{ \
FAIL_EXIT(FATAL_ERROR_CRYPTO, retVal, rc); \
} \
} while(0)
#if(defined EMPTY_ASSERT) && (EMPTY_ASSERT != NO)
# define pAssert(a) ((void)0)
#else
# define pAssert(a) \
do \
{ \
if(!(a)) \
FAIL(FATAL_ERROR_PARAMETER); \
} while(0)
# define pAssert(a) \
do \
{ \
if(!(a)) \
FAIL(FATAL_ERROR_PARAMETER); \
} while(0)
# define pAssert_ZERO(a) \
do \
{ \
if(!(a)) \
FAIL_IMMEDIATE(FATAL_ERROR_ASSERT, 0); \
} while(0);
# define pAssert_ZERO(a) \
do \
{ \
if(!(a)) \
FAIL_IMMEDIATE(FATAL_ERROR_ASSERT, 0); \
} while(0);
# define pAssert_RC(a) \
do \
{ \
if(!(a)) \
FAIL_RC(FATAL_ERROR_ASSERT); \
} while(0);
# define pAssert_RC(a) \
do \
{ \
if(!(a)) \
FAIL_RC(FATAL_ERROR_ASSERT); \
} while(0);
# define pAssert_BOOL(a) \
do \
{ \
if(!(a)) \
FAIL_BOOL(FATAL_ERROR_ASSERT); \
} while(0);
# define pAssert_BOOL(a) \
do \
{ \
if(!(a)) \
FAIL_BOOL(FATAL_ERROR_ASSERT); \
} while(0);
# define pAssert_NULL(a) \
do \
{ \
if(!(a)) \
FAIL_NULL(FATAL_ERROR_ASSERT); \
} while(0);
# define pAssert_NULL(a) \
do \
{ \
if(!(a)) \
FAIL_NULL(FATAL_ERROR_ASSERT); \
} while(0);
// using FAIL_NORET isn't optimium but is available in limited cases that
// result in wrong calculated values, and can be checked later
// but should have no vulnerability implications.
# define pAssert_NORET(a) \
{ \
if(!(a)) \
FAIL_NORET(FATAL_ERROR_ASSERT); \
}
# define pAssert_NORET(a) \
{ \
if(!(a)) \
FAIL_NORET(FATAL_ERROR_ASSERT); \
}
// this macro is used where a calling code has been verified to function correctly
// when the failing assert immediately returns without an error code.
// this can be because either the caller checks the fatal error flag, or
// the state is safe and a higher-level check will catch it.
# define pAssert_VOID_OK(a) \
{ \
if(!(a)) \
FAIL_VOID(FATAL_ERROR_ASSERT); \
}
# define pAssert_VOID_OK(a) \
{ \
if(!(a)) \
FAIL_VOID(FATAL_ERROR_ASSERT); \
}
#endif
// These macros are commonly used in the "Crypt" code as a way to keep listings from
// getting too long. This is not to save paper but to allow one to see more
// useful stuff on the screen at any given time. Neither macro sets failure mode.
#define ERROR_EXIT(returnCode) \
do \
{ \
retVal = returnCode; \
goto Exit; \
} while(0)
#define ERROR_EXIT(returnCode) \
do \
{ \
retVal = returnCode; \
goto Exit; \
} while(0)
// braces are necessary for this usage:
// if (y)
@ -397,17 +397,17 @@
// without braces the else would attach to the GOTO macro instead of the
// outer if statement; given the amount of TPM code that doesn't use braces on
// if statements, this is a live risk.
#define GOTO_ERROR_UNLESS(_X) \
do \
{ \
if(!(_X)) \
goto Error; \
} while(0)
#define GOTO_ERROR_UNLESS(_X) \
do \
{ \
if(!(_X)) \
goto Error; \
} while(0)
#include "MinMax.h"
#ifndef IsOdd
# define IsOdd(a) (((a)&1) != 0)
# define IsOdd(a) (((a) & 1) != 0)
#endif
#ifndef BITS_TO_BYTES
@ -455,10 +455,10 @@
# define SET_ATTRIBUTE(a, type, b) (a.b = SET)
# define CLEAR_ATTRIBUTE(a, type, b) (a.b = CLEAR)
# define GET_ATTRIBUTE(a, type, b) (a.b)
# define TPMA_ZERO_INITIALIZER() \
{ \
0 \
}
# define TPMA_ZERO_INITIALIZER() \
{ \
0 \
}
#else
# define IS_ATTRIBUTE(a, type, b) ((a & type##_##b) != 0)
# define SET_ATTRIBUTE(a, type, b) (a |= type##_##b)

View File

@ -59,30 +59,36 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef HMAC_START_FP_H
#define HMAC_START_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_DH_OBJECT handle;
TPM2B_AUTH auth;
TPMI_ALG_HASH hashAlg;
#if CC_HMAC_Start // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_HMAC_START_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_HMAC_START_FP_H_
// Input structure definition
typedef struct
{
TPMI_DH_OBJECT handle;
TPM2B_AUTH auth;
TPMI_ALG_HASH hashAlg;
} HMAC_Start_In;
typedef struct {
TPMI_DH_OBJECT sequenceHandle;
// Output structure definition
typedef struct
{
TPMI_DH_OBJECT sequenceHandle;
} HMAC_Start_Out;
#define RC_HMAC_Start_handle (TPM_RC_H + TPM_RC_1)
#define RC_HMAC_Start_auth (TPM_RC_P + TPM_RC_1)
#define RC_HMAC_Start_hashAlg (TPM_RC_P + TPM_RC_2)
// Response code modifiers
# define RC_HMAC_Start_handle (TPM_RC_H + TPM_RC_1)
# define RC_HMAC_Start_auth (TPM_RC_P + TPM_RC_1)
# define RC_HMAC_Start_hashAlg (TPM_RC_P + TPM_RC_2)
// Function prototype
TPM_RC
TPM2_HMAC_Start(
HMAC_Start_In *in, // IN: input parameter list
HMAC_Start_Out *out // OUT: output parameter list
);
TPM2_HMAC_Start(HMAC_Start_In* in, HMAC_Start_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_HMAC_START_FP_H_
#endif // CC_HMAC_Start

View File

@ -59,30 +59,36 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef HMAC_FP_H
#define HMAC_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_DH_OBJECT handle;
TPM2B_MAX_BUFFER buffer;
TPMI_ALG_HASH hashAlg;
#if CC_HMAC // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_HMAC_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_HMAC_FP_H_
// Input structure definition
typedef struct
{
TPMI_DH_OBJECT handle;
TPM2B_MAX_BUFFER buffer;
TPMI_ALG_HASH hashAlg;
} HMAC_In;
#define RC_HMAC_handle (TPM_RC_H + TPM_RC_1)
#define RC_HMAC_buffer (TPM_RC_P + TPM_RC_1)
#define RC_HMAC_hashAlg (TPM_RC_P + TPM_RC_2)
typedef struct {
TPM2B_DIGEST outHMAC;
// Output structure definition
typedef struct
{
TPM2B_DIGEST outHMAC;
} HMAC_Out;
// Response code modifiers
# define RC_HMAC_handle (TPM_RC_H + TPM_RC_1)
# define RC_HMAC_buffer (TPM_RC_P + TPM_RC_1)
# define RC_HMAC_hashAlg (TPM_RC_P + TPM_RC_2)
// Function prototype
TPM_RC
TPM2_HMAC(
HMAC_In *in, // IN: input parameter list
HMAC_Out *out // OUT: output parameter list
);
TPM2_HMAC(HMAC_In* in, HMAC_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_HMAC_FP_H_
#endif // CC_HMAC

View File

@ -70,7 +70,7 @@
// This function returns the type of a handle which is the MSO of the handle.
TPM_HT
HandleGetType(TPM_HANDLE handle // IN: a handle to be checked
)
)
{
// return the upper bytes of input data
return (TPM_HT)((handle & HR_RANGE_MASK) >> HR_SHIFT);
@ -82,63 +82,63 @@ HandleGetType(TPM_HANDLE handle // IN: a handle to be checked
// is no next higher value, it returns 0:
TPM_HANDLE
NextPermanentHandle(TPM_HANDLE inHandle // IN: the handle to check
)
)
{
// If inHandle is below the start of the range of permanent handles
// set it to the start and scan from there
if(inHandle < TPM_RH_FIRST)
inHandle = TPM_RH_FIRST;
inHandle = TPM_RH_FIRST;
// scan from input value until we find an implemented permanent handle
// or go out of range
for(; inHandle <= TPM_RH_LAST; inHandle++)
{
// Skip over gaps in the reserved handle space.
if(inHandle > TPM_RH_FW_NULL && inHandle < SVN_OWNER_FIRST)
inHandle = SVN_OWNER_FIRST;
if(inHandle > SVN_OWNER_FIRST && inHandle <= SVN_OWNER_LAST)
inHandle = SVN_ENDORSEMENT_FIRST;
if(inHandle > SVN_ENDORSEMENT_FIRST && inHandle <= SVN_ENDORSEMENT_LAST)
inHandle = SVN_PLATFORM_FIRST;
if(inHandle > SVN_PLATFORM_FIRST && inHandle <= SVN_PLATFORM_LAST)
inHandle = SVN_NULL_FIRST;
if(inHandle > SVN_NULL_FIRST)
inHandle = TPM_RH_LAST;
switch(inHandle)
{
case TPM_RH_OWNER:
case TPM_RH_NULL:
case TPM_RS_PW:
case TPM_RH_LOCKOUT:
case TPM_RH_ENDORSEMENT:
case TPM_RH_PLATFORM:
case TPM_RH_PLATFORM_NV:
{
// Skip over gaps in the reserved handle space.
if(inHandle > TPM_RH_FW_NULL && inHandle < SVN_OWNER_FIRST)
inHandle = SVN_OWNER_FIRST;
if(inHandle > SVN_OWNER_FIRST && inHandle <= SVN_OWNER_LAST)
inHandle = SVN_ENDORSEMENT_FIRST;
if(inHandle > SVN_ENDORSEMENT_FIRST && inHandle <= SVN_ENDORSEMENT_LAST)
inHandle = SVN_PLATFORM_FIRST;
if(inHandle > SVN_PLATFORM_FIRST && inHandle <= SVN_PLATFORM_LAST)
inHandle = SVN_NULL_FIRST;
if(inHandle > SVN_NULL_FIRST)
inHandle = TPM_RH_LAST;
switch(inHandle)
{
case TPM_RH_OWNER:
case TPM_RH_NULL:
case TPM_RS_PW:
case TPM_RH_LOCKOUT:
case TPM_RH_ENDORSEMENT:
case TPM_RH_PLATFORM:
case TPM_RH_PLATFORM_NV:
#if FW_LIMITED_SUPPORT
case TPM_RH_FW_OWNER:
case TPM_RH_FW_ENDORSEMENT:
case TPM_RH_FW_PLATFORM:
case TPM_RH_FW_NULL:
case TPM_RH_FW_OWNER:
case TPM_RH_FW_ENDORSEMENT:
case TPM_RH_FW_PLATFORM:
case TPM_RH_FW_NULL:
#endif
#if SVN_LIMITED_SUPPORT
case TPM_RH_SVN_OWNER_BASE:
case TPM_RH_SVN_ENDORSEMENT_BASE:
case TPM_RH_SVN_PLATFORM_BASE:
case TPM_RH_SVN_NULL_BASE:
case TPM_RH_SVN_OWNER_BASE:
case TPM_RH_SVN_ENDORSEMENT_BASE:
case TPM_RH_SVN_PLATFORM_BASE:
case TPM_RH_SVN_NULL_BASE:
#endif
#if VENDOR_PERMANENT_AUTH_ENABLED == YES
case VENDOR_PERMANENT_AUTH_HANDLE:
case VENDOR_PERMANENT_AUTH_HANDLE:
#endif
// Each of the implemented ACT
// Each of the implemented ACT
#define ACT_IMPLEMENTED_CASE(N) case TPM_RH_ACT_##N:
FOR_EACH_ACT(ACT_IMPLEMENTED_CASE)
return inHandle;
break;
default:
break;
}
}
FOR_EACH_ACT(ACT_IMPLEMENTED_CASE)
return inHandle;
break;
default:
break;
}
}
// Out of range on the top
return 0;
}
@ -152,40 +152,40 @@ NextPermanentHandle(TPM_HANDLE inHandle // IN: the handle to check
// NO all the available handles has been returned
TPMI_YES_NO
PermanentCapGetHandles(TPM_HANDLE handle, // IN: start handle
UINT32 count, // IN: count of returned handles
TPML_HANDLE* handleList // OUT: list of handle
)
UINT32 count, // IN: count of returned handles
TPML_HANDLE* handleList // OUT: list of handle
)
{
TPMI_YES_NO more = NO;
UINT32 i;
pAssert(HandleGetType(handle) == TPM_HT_PERMANENT);
// Initialize output handle list
handleList->count = 0;
// The maximum count of handles we may return is MAX_CAP_HANDLES
if(count > MAX_CAP_HANDLES)
count = MAX_CAP_HANDLES;
count = MAX_CAP_HANDLES;
// Iterate permanent handle range
for(i = NextPermanentHandle(handle); i != 0; i = NextPermanentHandle(i + 1))
{
if(handleList->count < count)
{
// If we have not filled up the return list, add this permanent
// handle to it
handleList->handle[handleList->count] = i;
handleList->count++;
}
else
{
// If the return list is full but we still have permanent handle
// available, report this and stop iterating
more = YES;
break;
}
}
{
if(handleList->count < count)
{
// If we have not filled up the return list, add this permanent
// handle to it
handleList->handle[handleList->count] = i;
handleList->count++;
}
else
{
// If the return list is full but we still have permanent handle
// available, report this and stop iterating
more = YES;
break;
}
}
return more;
}
@ -194,17 +194,17 @@ PermanentCapGetHandles(TPM_HANDLE handle, // IN: start handle
BOOL PermanentCapGetOneHandle(TPM_HANDLE handle) // IN: handle
{
UINT32 i;
pAssert(HandleGetType(handle) == TPM_HT_PERMANENT);
// Iterate permanent handle range
for(i = NextPermanentHandle(handle); i != 0; i = NextPermanentHandle(i + 1))
{
if(i == handle)
{
return TRUE;
}
}
{
if(i == handle)
{
return TRUE;
}
}
return FALSE;
}
@ -217,76 +217,76 @@ BOOL PermanentCapGetOneHandle(TPM_HANDLE handle) // IN: handle
// NO all the available handles has been returned
TPMI_YES_NO
PermanentHandleGetPolicy(TPM_HANDLE handle, // IN: start handle
UINT32 count, // IN: max count of returned handles
TPML_TAGGED_POLICY* policyList // OUT: list of handle
)
UINT32 count, // IN: max count of returned handles
TPML_TAGGED_POLICY* policyList // OUT: list of handle
)
{
TPMI_YES_NO more = NO;
pAssert(HandleGetType(handle) == TPM_HT_PERMANENT);
// Initialize output handle list
policyList->count = 0;
// The maximum count of policies we may return is MAX_TAGGED_POLICIES
if(count > MAX_TAGGED_POLICIES)
count = MAX_TAGGED_POLICIES;
count = MAX_TAGGED_POLICIES;
// Iterate permanent handle range
for(handle = NextPermanentHandle(handle); handle != 0;
handle = NextPermanentHandle(handle + 1))
{
TPM2B_DIGEST policyDigest;
TPM_ALG_ID policyAlg;
// Check to see if this permanent handle has a policy
policyAlg = EntityGetAuthPolicy(handle, &policyDigest);
if(policyAlg == TPM_ALG_ERROR)
continue;
if(policyList->count < count)
{
// If we have not filled up the return list, add this
// policy to the list;
policyList->policies[policyList->count].handle = handle;
policyList->policies[policyList->count].policyHash.hashAlg = policyAlg;
MemoryCopy(&policyList->policies[policyList->count].policyHash.digest,
policyDigest.t.buffer,
policyDigest.t.size);
policyList->count++;
}
else
{
// If the return list is full but we still have permanent handle
// available, report this and stop iterating
more = YES;
break;
}
}
handle = NextPermanentHandle(handle + 1))
{
TPM2B_DIGEST policyDigest;
TPM_ALG_ID policyAlg;
// Check to see if this permanent handle has a policy
policyAlg = EntityGetAuthPolicy(handle, &policyDigest);
if(policyAlg == TPM_ALG_ERROR)
continue;
if(policyList->count < count)
{
// If we have not filled up the return list, add this
// policy to the list;
policyList->policies[policyList->count].handle = handle;
policyList->policies[policyList->count].policyHash.hashAlg = policyAlg;
MemoryCopy(&policyList->policies[policyList->count].policyHash.digest,
policyDigest.t.buffer,
policyDigest.t.size);
policyList->count++;
}
else
{
// If the return list is full but we still have permanent handle
// available, report this and stop iterating
more = YES;
break;
}
}
return more;
}
//*** PermanentHandleGetOnePolicy()
// This function returns a permanent handle's policy, if present.
BOOL PermanentHandleGetOnePolicy(TPM_HANDLE handle, // IN: handle
TPMS_TAGGED_POLICY* policy // OUT: tagged policy
)
TPMS_TAGGED_POLICY* policy // OUT: tagged policy
)
{
pAssert(HandleGetType(handle) == TPM_HT_PERMANENT);
if(NextPermanentHandle(handle) == handle)
{
TPM2B_DIGEST policyDigest;
TPM_ALG_ID policyAlg;
// Check to see if this permanent handle has a policy
policyAlg = EntityGetAuthPolicy(handle, &policyDigest);
if(policyAlg == TPM_ALG_ERROR)
{
return FALSE;
}
policy->handle = handle;
policy->policyHash.hashAlg = policyAlg;
MemoryCopy(
&policy->policyHash.digest, policyDigest.t.buffer, policyDigest.t.size);
return TRUE;
}
{
TPM2B_DIGEST policyDigest;
TPM_ALG_ID policyAlg;
// Check to see if this permanent handle has a policy
policyAlg = EntityGetAuthPolicy(handle, &policyDigest);
if(policyAlg == TPM_ALG_ERROR)
{
return FALSE;
}
policy->handle = handle;
policy->policyHash.hashAlg = policyAlg;
MemoryCopy(
&policy->policyHash.digest, policyDigest.t.buffer, policyDigest.t.size);
return TRUE;
}
return FALSE;
}

View File

@ -58,33 +58,63 @@
/* */
/********************************************************************************/
#ifndef HANDLE_FP_H
#define HANDLE_FP_H
/*(Auto-generated)
* Created by TpmPrototypes; Version 3.0 July 18, 2017
* Date: Mar 28, 2019 Time: 08:25:19PM
*/
#ifndef _HANDLE_FP_H_
#define _HANDLE_FP_H_
//*** HandleGetType()
// This function returns the type of a handle which is the MSO of the handle.
TPM_HT
HandleGetType(
TPM_HANDLE handle // IN: a handle to be checked
);
TPM_HANDLE
NextPermanentHandle(
TPM_HANDLE inHandle // IN: the handle to check
);
TPMI_YES_NO
PermanentCapGetHandles(
TPM_HANDLE handle, // IN: start handle
UINT32 count, // IN: count of returned handles
TPML_HANDLE *handleList // OUT: list of handle
);
BOOL PermanentCapGetOneHandle(TPM_HANDLE handle // IN: handle
);
TPMI_YES_NO
PermanentHandleGetPolicy(
TPM_HANDLE handle, // IN: start handle
UINT32 count, // IN: count of returned handles
TPML_TAGGED_POLICY *policyList // OUT: list of handle
);
BOOL PermanentHandleGetOnePolicy(TPM_HANDLE handle, // IN: handle
TPMS_TAGGED_POLICY* policy // OUT: tagged policy
);
HandleGetType(TPM_HANDLE handle // IN: a handle to be checked
);
#endif
//*** NextPermanentHandle()
// This function returns the permanent handle that is equal to the input value or
// is the next higher value. If there is no handle with the input value and there
// is no next higher value, it returns 0:
TPM_HANDLE
NextPermanentHandle(TPM_HANDLE inHandle // IN: the handle to check
);
//*** PermanentCapGetHandles()
// This function returns a list of the permanent handles of PCR, started from
// 'handle'. If 'handle' is larger than the largest permanent handle, an empty list
// will be returned with 'more' set to NO.
// Return Type: TPMI_YES_NO
// YES if there are more handles available
// NO all the available handles has been returned
TPMI_YES_NO
PermanentCapGetHandles(TPM_HANDLE handle, // IN: start handle
UINT32 count, // IN: count of returned handles
TPML_HANDLE* handleList // OUT: list of handle
);
//*** PermanentCapGetOneHandle()
// This function returns whether a permanent handle exists.
BOOL PermanentCapGetOneHandle(TPM_HANDLE handle // IN: handle
);
//*** PermanentHandleGetPolicy()
// This function returns a list of the permanent handles of PCR, started from
// 'handle'. If 'handle' is larger than the largest permanent handle, an empty list
// will be returned with 'more' set to NO.
// Return Type: TPMI_YES_NO
// YES if there are more handles available
// NO all the available handles has been returned
TPMI_YES_NO
PermanentHandleGetPolicy(TPM_HANDLE handle, // IN: start handle
UINT32 count, // IN: max count of returned handles
TPML_TAGGED_POLICY* policyList // OUT: list of handle
);
//*** PermanentHandleGetOnePolicy()
// This function returns a permanent handle's policy, if present.
BOOL PermanentHandleGetOnePolicy(TPM_HANDLE handle, // IN: handle
TPMS_TAGGED_POLICY* policy // OUT: tagged policy
);
#endif // _HANDLE_FP_H_

View File

@ -59,30 +59,34 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef HASHSEQUENCESTART_FP_H
#define HASHSEQUENCESTART_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPM2B_AUTH auth;
TPMI_ALG_HASH hashAlg;
#if CC_HashSequenceStart // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_HASHSEQUENCESTART_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_HASHSEQUENCESTART_FP_H_
// Input structure definition
typedef struct
{
TPM2B_AUTH auth;
TPMI_ALG_HASH hashAlg;
} HashSequenceStart_In;
#define RC_HashSequenceStart_auth (TPM_RC_P + TPM_RC_1)
#define RC_HashSequenceStart_hashAlg (TPM_RC_P + TPM_RC_2)
typedef struct {
TPMI_DH_OBJECT sequenceHandle;
// Output structure definition
typedef struct
{
TPMI_DH_OBJECT sequenceHandle;
} HashSequenceStart_Out;
// Response code modifiers
# define RC_HashSequenceStart_auth (TPM_RC_P + TPM_RC_1)
# define RC_HashSequenceStart_hashAlg (TPM_RC_P + TPM_RC_2)
// Function prototype
TPM_RC
TPM2_HashSequenceStart(
HashSequenceStart_In *in, // IN: input parameter list
HashSequenceStart_Out *out // OUT: output parameter list
);
TPM2_HashSequenceStart(HashSequenceStart_In* in, HashSequenceStart_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_HASHSEQUENCESTART_FP_H_
#endif // CC_HashSequenceStart

View File

@ -59,72 +59,81 @@
/* */
/********************************************************************************/
#ifndef HASHTESTDATA_H
#define HASHTESTDATA_H
//
// Hash Test Vectors
//
/* 10.1.8 HashTestData.h */
/* Hash Test Vectors */
TPM2B_TYPE(HASH_TEST_KEY, 128); // Twice the largest digest size
TPM2B_HASH_TEST_KEY c_hashTestKey = {{128, {
0xa0,0xed,0x5c,0x9a,0xd2,0x4a,0x21,0x40,0x1a,0xd0,0x81,0x47,0x39,0x63,0xf9,0x50,
0xdc,0x59,0x47,0x11,0x40,0x13,0x99,0x92,0xc0,0x72,0xa4,0x0f,0xe2,0x33,0xe4,0x63,
0x9b,0xb6,0x76,0xc3,0x1e,0x6f,0x13,0xee,0xcc,0x99,0x71,0xa5,0xc0,0xcf,0x9a,0x40,
0xcf,0xdb,0x66,0x70,0x05,0x63,0x54,0x12,0x25,0xf4,0xe0,0x1b,0x23,0x35,0xe3,0x70,
0x7d,0x19,0x5f,0x00,0xe4,0xf1,0x61,0x73,0x05,0xd8,0x58,0x7f,0x60,0x61,0x84,0x36,
0xec,0xbe,0x96,0x1b,0x69,0x00,0xf0,0x9a,0x6e,0xe3,0x26,0x73,0x0d,0x17,0x5b,0x33,
0x41,0x44,0x9d,0x90,0xab,0xd9,0x6b,0x7d,0x48,0x99,0x25,0x93,0x29,0x14,0x2b,0xce,
0x93,0x8d,0x8c,0xaf,0x31,0x0e,0x9c,0x57,0xd8,0x5b,0x57,0x20,0x1b,0x9f,0x2d,0xa5
}}};
TPM2B_TYPE(HASH_TEST_KEY, 128); // Twice the largest digest size
TPM2B_HASH_TEST_KEY c_hashTestKey = {
{128,
{0xa0, 0xed, 0x5c, 0x9a, 0xd2, 0x4a, 0x21, 0x40, 0x1a, 0xd0, 0x81, 0x47, 0x39,
0x63, 0xf9, 0x50, 0xdc, 0x59, 0x47, 0x11, 0x40, 0x13, 0x99, 0x92, 0xc0, 0x72,
0xa4, 0x0f, 0xe2, 0x33, 0xe4, 0x63, 0x9b, 0xb6, 0x76, 0xc3, 0x1e, 0x6f, 0x13,
0xee, 0xcc, 0x99, 0x71, 0xa5, 0xc0, 0xcf, 0x9a, 0x40, 0xcf, 0xdb, 0x66, 0x70,
0x05, 0x63, 0x54, 0x12, 0x25, 0xf4, 0xe0, 0x1b, 0x23, 0x35, 0xe3, 0x70, 0x7d,
0x19, 0x5f, 0x00, 0xe4, 0xf1, 0x61, 0x73, 0x05, 0xd8, 0x58, 0x7f, 0x60, 0x61,
0x84, 0x36, 0xec, 0xbe, 0x96, 0x1b, 0x69, 0x00, 0xf0, 0x9a, 0x6e, 0xe3, 0x26,
0x73, 0x0d, 0x17, 0x5b, 0x33, 0x41, 0x44, 0x9d, 0x90, 0xab, 0xd9, 0x6b, 0x7d,
0x48, 0x99, 0x25, 0x93, 0x29, 0x14, 0x2b, 0xce, 0x93, 0x8d, 0x8c, 0xaf, 0x31,
0x0e, 0x9c, 0x57, 0xd8, 0x5b, 0x57, 0x20, 0x1b, 0x9f, 0x2d, 0xa5}}};
TPM2B_TYPE(HASH_TEST_DATA, 256); // Twice the largest block size
TPM2B_HASH_TEST_DATA c_hashTestData = {
{256,
{0x88, 0xac, 0xc3, 0xe5, 0x5f, 0x66, 0x9d, 0x18, 0x80, 0xc9, 0x7a, 0x9c, 0xa4,
0x08, 0x90, 0x98, 0x0f, 0x3a, 0x53, 0x92, 0x4c, 0x67, 0x4e, 0xb7, 0x37, 0xec,
0x67, 0x87, 0xb6, 0xbe, 0x10, 0xca, 0x11, 0x5b, 0x4a, 0x0b, 0x45, 0xc3, 0x32,
0x68, 0x48, 0x69, 0xce, 0x25, 0x1b, 0xc8, 0xaf, 0x44, 0x79, 0x22, 0x83, 0xc8,
0xfb, 0xe2, 0x63, 0x94, 0xa2, 0x3c, 0x59, 0x3e, 0x3e, 0xc6, 0x64, 0x2c, 0x1f,
0x8c, 0x11, 0x93, 0x24, 0xa3, 0x17, 0xc5, 0x2f, 0x37, 0xcf, 0x95, 0x97, 0x8e,
0x63, 0x39, 0x68, 0xd5, 0xca, 0xba, 0x18, 0x37, 0x69, 0x6e, 0x4f, 0x19, 0xfd,
0x8a, 0xc0, 0x8d, 0x87, 0x3a, 0xbc, 0x31, 0x42, 0x04, 0x05, 0xef, 0xb5, 0x02,
0xef, 0x1e, 0x92, 0x4b, 0xb7, 0x73, 0x2c, 0x8c, 0xeb, 0x23, 0x13, 0x81, 0x34,
0xb9, 0xb5, 0xc1, 0x17, 0x37, 0x39, 0xf8, 0x3e, 0xe4, 0x4c, 0x06, 0xa8, 0x81,
0x52, 0x2f, 0xef, 0xc9, 0x9c, 0x69, 0x89, 0xbc, 0x85, 0x9c, 0x30, 0x16, 0x02,
0xca, 0xe3, 0x61, 0xd4, 0x0f, 0xed, 0x34, 0x1b, 0xca, 0xc1, 0x1b, 0xd1, 0xfa,
0xc1, 0xa2, 0xe0, 0xdf, 0x52, 0x2f, 0x0b, 0x4b, 0x9f, 0x0e, 0x45, 0x54, 0xb9,
0x17, 0xb6, 0xaf, 0xd6, 0xd5, 0xca, 0x90, 0x29, 0x57, 0x7b, 0x70, 0x50, 0x94,
0x5c, 0x8e, 0xf6, 0x4e, 0x21, 0x8b, 0xc6, 0x8b, 0xa6, 0xbc, 0xb9, 0x64, 0xd4,
0x4d, 0xf3, 0x68, 0xd8, 0xac, 0xde, 0xd8, 0xd8, 0xb5, 0x6d, 0xcd, 0x93, 0xeb,
0x28, 0xa4, 0xe2, 0x5c, 0x44, 0xef, 0xf0, 0xe1, 0x6f, 0x38, 0x1a, 0x3c, 0xe6,
0xef, 0xa2, 0x9d, 0xb9, 0xa8, 0x05, 0x2a, 0x95, 0xec, 0x5f, 0xdb, 0xb0, 0x25,
0x67, 0x9c, 0x86, 0x7a, 0x8e, 0xea, 0x51, 0xcc, 0xc3, 0xd3, 0xff, 0x6e, 0xf0,
0xed, 0xa3, 0xae, 0xf9, 0x5d, 0x33, 0x70, 0xf2, 0x11}}};
TPM2B_TYPE(HASH_TEST_DATA, 256); // Twice the largest block size
TPM2B_HASH_TEST_DATA c_hashTestData = {{256, {
0x88,0xac,0xc3,0xe5,0x5f,0x66,0x9d,0x18,0x80,0xc9,0x7a,0x9c,0xa4,0x08,0x90,0x98,
0x0f,0x3a,0x53,0x92,0x4c,0x67,0x4e,0xb7,0x37,0xec,0x67,0x87,0xb6,0xbe,0x10,0xca,
0x11,0x5b,0x4a,0x0b,0x45,0xc3,0x32,0x68,0x48,0x69,0xce,0x25,0x1b,0xc8,0xaf,0x44,
0x79,0x22,0x83,0xc8,0xfb,0xe2,0x63,0x94,0xa2,0x3c,0x59,0x3e,0x3e,0xc6,0x64,0x2c,
0x1f,0x8c,0x11,0x93,0x24,0xa3,0x17,0xc5,0x2f,0x37,0xcf,0x95,0x97,0x8e,0x63,0x39,
0x68,0xd5,0xca,0xba,0x18,0x37,0x69,0x6e,0x4f,0x19,0xfd,0x8a,0xc0,0x8d,0x87,0x3a,
0xbc,0x31,0x42,0x04,0x05,0xef,0xb5,0x02,0xef,0x1e,0x92,0x4b,0xb7,0x73,0x2c,0x8c,
0xeb,0x23,0x13,0x81,0x34,0xb9,0xb5,0xc1,0x17,0x37,0x39,0xf8,0x3e,0xe4,0x4c,0x06,
0xa8,0x81,0x52,0x2f,0xef,0xc9,0x9c,0x69,0x89,0xbc,0x85,0x9c,0x30,0x16,0x02,0xca,
0xe3,0x61,0xd4,0x0f,0xed,0x34,0x1b,0xca,0xc1,0x1b,0xd1,0xfa,0xc1,0xa2,0xe0,0xdf,
0x52,0x2f,0x0b,0x4b,0x9f,0x0e,0x45,0x54,0xb9,0x17,0xb6,0xaf,0xd6,0xd5,0xca,0x90,
0x29,0x57,0x7b,0x70,0x50,0x94,0x5c,0x8e,0xf6,0x4e,0x21,0x8b,0xc6,0x8b,0xa6,0xbc,
0xb9,0x64,0xd4,0x4d,0xf3,0x68,0xd8,0xac,0xde,0xd8,0xd8,0xb5,0x6d,0xcd,0x93,0xeb,
0x28,0xa4,0xe2,0x5c,0x44,0xef,0xf0,0xe1,0x6f,0x38,0x1a,0x3c,0xe6,0xef,0xa2,0x9d,
0xb9,0xa8,0x05,0x2a,0x95,0xec,0x5f,0xdb,0xb0,0x25,0x67,0x9c,0x86,0x7a,0x8e,0xea,
0x51,0xcc,0xc3,0xd3,0xff,0x6e,0xf0,0xed,0xa3,0xae,0xf9,0x5d,0x33,0x70,0xf2,0x11
}}};
#if ALG_SHA1 == YES
TPM2B_TYPE(SHA1, 20);
TPM2B_SHA1 c_SHA1_digest = {{20, {
0xee,0x2c,0xef,0x93,0x76,0xbd,0xf8,0x91,0xbc,0xe6,0xe5,0x57,0x53,0x77,0x01,0xb5,
0x70,0x95,0xe5,0x40
}}};
TPM2B_SHA1 c_SHA1_digest = {
{20, {0xee, 0x2c, 0xef, 0x93, 0x76, 0xbd, 0xf8, 0x91, 0xbc, 0xe6,
0xe5, 0x57, 0x53, 0x77, 0x01, 0xb5, 0x70, 0x95, 0xe5, 0x40}}};
#endif
#if ALG_SHA256 == YES
TPM2B_TYPE(SHA256, 32);
TPM2B_SHA256 c_SHA256_digest = {{32, {
0x64,0xe8,0xe0,0xc3,0xa9,0xa4,0x51,0x49,0x10,0x55,0x8d,0x31,0x71,0xe5,0x2f,0x69,
0x3a,0xdc,0xc7,0x11,0x32,0x44,0x61,0xbd,0x34,0x39,0x57,0xb0,0xa8,0x75,0x86,0x1b
}}};
TPM2B_SHA256 c_SHA256_digest = {
{32, {0x64, 0xe8, 0xe0, 0xc3, 0xa9, 0xa4, 0x51, 0x49, 0x10, 0x55, 0x8d,
0x31, 0x71, 0xe5, 0x2f, 0x69, 0x3a, 0xdc, 0xc7, 0x11, 0x32, 0x44,
0x61, 0xbd, 0x34, 0x39, 0x57, 0xb0, 0xa8, 0x75, 0x86, 0x1b}}};
#endif
#if ALG_SHA384 == YES
TPM2B_TYPE(SHA384, 48);
TPM2B_SHA384 c_SHA384_digest = {{48, {
0x37,0x75,0x29,0xb5,0x20,0x15,0x6e,0xa3,0x7e,0xa3,0x0d,0xcd,0x80,0xa8,0xa3,0x3d,
0xeb,0xe8,0xad,0x4e,0x1c,0x77,0x94,0x5a,0xaf,0x6c,0xd0,0xc1,0xfa,0x43,0x3f,0xc7,
0xb8,0xf1,0x01,0xc0,0x60,0xbf,0xf2,0x87,0xe8,0x71,0x9e,0x51,0x97,0xa0,0x09,0x8d
}}};
TPM2B_SHA384 c_SHA384_digest = {
{48, {0x37, 0x75, 0x29, 0xb5, 0x20, 0x15, 0x6e, 0xa3, 0x7e, 0xa3, 0x0d, 0xcd,
0x80, 0xa8, 0xa3, 0x3d, 0xeb, 0xe8, 0xad, 0x4e, 0x1c, 0x77, 0x94, 0x5a,
0xaf, 0x6c, 0xd0, 0xc1, 0xfa, 0x43, 0x3f, 0xc7, 0xb8, 0xf1, 0x01, 0xc0,
0x60, 0xbf, 0xf2, 0x87, 0xe8, 0x71, 0x9e, 0x51, 0x97, 0xa0, 0x09, 0x8d}}};
#endif
#if ALG_SHA512 == YES
TPM2B_TYPE(SHA512, 64);
TPM2B_SHA512 c_SHA512_digest = {{64, {
0xe2,0x7b,0x10,0x3d,0x5e,0x48,0x58,0x44,0x67,0xac,0xa3,0x81,0x8c,0x1d,0xc5,0x71,
0x66,0x92,0x8a,0x89,0xaa,0xd4,0x35,0x51,0x60,0x37,0x31,0xd7,0xba,0xe7,0x93,0x0b,
0x16,0x4d,0xb3,0xc8,0x34,0x98,0x3c,0xd3,0x53,0xde,0x5e,0xe8,0x0c,0xbc,0xaf,0xc9,
0x24,0x2c,0xcc,0xed,0xdb,0xde,0xba,0x1f,0x14,0x14,0x5a,0x95,0x80,0xde,0x66,0xbd
}}};
TPM2B_SHA512 c_SHA512_digest = {
{64,
{0xe2, 0x7b, 0x10, 0x3d, 0x5e, 0x48, 0x58, 0x44, 0x67, 0xac, 0xa3, 0x81, 0x8c,
0x1d, 0xc5, 0x71, 0x66, 0x92, 0x8a, 0x89, 0xaa, 0xd4, 0x35, 0x51, 0x60, 0x37,
0x31, 0xd7, 0xba, 0xe7, 0x93, 0x0b, 0x16, 0x4d, 0xb3, 0xc8, 0x34, 0x98, 0x3c,
0xd3, 0x53, 0xde, 0x5e, 0xe8, 0x0c, 0xbc, 0xaf, 0xc9, 0x24, 0x2c, 0xcc, 0xed,
0xdb, 0xde, 0xba, 0x1f, 0x14, 0x14, 0x5a, 0x95, 0x80, 0xde, 0x66, 0xbd}}};
#endif
TPM2B_TYPE(EMPTY, 1);
@ -207,4 +216,3 @@ static const struct CMACTest {
#endif
// libtpms added end
#endif

View File

@ -59,31 +59,37 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef HASH_FP_H
#define HASH_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPM2B_MAX_BUFFER data;
TPMI_ALG_HASH hashAlg;
TPMI_RH_HIERARCHY hierarchy;
#if CC_Hash // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_HASH_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_HASH_FP_H_
// Input structure definition
typedef struct
{
TPM2B_MAX_BUFFER data;
TPMI_ALG_HASH hashAlg;
TPMI_RH_HIERARCHY hierarchy;
} Hash_In;
#define RC_Hash_data (TPM_RC_P + TPM_RC_1)
#define RC_Hash_hashAlg (TPM_RC_P + TPM_RC_2)
#define RC_Hash_hierarchy (TPM_RC_P + TPM_RC_3)
typedef struct {
TPM2B_DIGEST outHash;
TPMT_TK_HASHCHECK validation;
// Output structure definition
typedef struct
{
TPM2B_DIGEST outHash;
TPMT_TK_HASHCHECK validation;
} Hash_Out;
// Response code modifiers
# define RC_Hash_data (TPM_RC_P + TPM_RC_1)
# define RC_Hash_hashAlg (TPM_RC_P + TPM_RC_2)
# define RC_Hash_hierarchy (TPM_RC_P + TPM_RC_3)
// Function prototype
TPM_RC
TPM2_Hash(
Hash_In *in, // IN: input parameter list
Hash_Out *out // OUT: output parameter list
);
TPM2_Hash(Hash_In* in, Hash_Out* out);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_HASH_FP_H_
#endif // CC_Hash

View File

@ -69,11 +69,11 @@
//**HIERARCHY_MODIFIER_TYPE
// This enumerates the possible hierarchy modifiers.
typedef enum
{
HM_NONE = 0,
HM_FW_LIMITED, // Hierarchy is firmware-limited.
HM_SVN_LIMITED // Hierarchy is SVN-limited.
} HIERARCHY_MODIFIER_TYPE;
{
HM_NONE = 0,
HM_FW_LIMITED, // Hierarchy is firmware-limited.
HM_SVN_LIMITED // Hierarchy is SVN-limited.
} HIERARCHY_MODIFIER_TYPE;
//*** HIERARCHY_MODIFIER Structure
// A HIERARCHY_MODIFIER structure holds metadata about an OBJECT's
@ -82,7 +82,7 @@ typedef struct HIERARCHY_MODIFIER
{
HIERARCHY_MODIFIER_TYPE type; // The type of modification.
uint16_t min_svn; // The minimum SVN to which the hierarchy is limited.
// Only valid if 'type' is HM_SVN_LIMITED.
// Only valid if 'type' is HM_SVN_LIMITED.
} HIERARCHY_MODIFIER;
//** Functions
@ -161,7 +161,7 @@ void HierarchyPreInstall_Init(void)
// This function is called at TPM2_Startup() to initialize the hierarchy
// related values.
BOOL HierarchyStartup(STARTUP_TYPE type // IN: start up type
)
)
{
// phEnable is SET on any startup
g_phEnable = TRUE;
@ -169,24 +169,24 @@ BOOL HierarchyStartup(STARTUP_TYPE type // IN: start up type
// Reset platformAuth, platformPolicy; enable SH and EH at TPM_RESET and
// TPM_RESTART
if(type != SU_RESUME)
{
gc.platformAuth.t.size = 0;
gc.platformPolicy.t.size = 0;
gc.platformAlg = TPM_ALG_NULL;
{
gc.platformAuth.t.size = 0;
gc.platformPolicy.t.size = 0;
gc.platformAlg = TPM_ALG_NULL;
// enable the storage and endorsement hierarchies and the platformNV
gc.shEnable = gc.ehEnable = gc.phEnableNV = TRUE;
}
// enable the storage and endorsement hierarchies and the platformNV
gc.shEnable = gc.ehEnable = gc.phEnableNV = TRUE;
}
// nullProof and nullSeed are updated at every TPM_RESET
if((type != SU_RESTART) && (type != SU_RESUME))
{
gr.nullProof.t.size = sizeof(gr.nullProof.t.buffer);
CryptRandomGenerate(gr.nullProof.t.size, gr.nullProof.t.buffer);
gr.nullSeed.t.size = sizeof(gr.nullSeed.t.buffer);
CryptRandomGenerate(gr.nullSeed.t.size, gr.nullSeed.t.buffer);
gr.nullSeedCompatLevel = RuntimeProfileGetSeedCompatLevel(); // libtpms added
}
{
gr.nullProof.t.size = sizeof(gr.nullProof.t.buffer);
CryptRandomGenerate(gr.nullProof.t.size, gr.nullProof.t.buffer);
gr.nullSeed.t.size = sizeof(gr.nullSeed.t.buffer);
CryptRandomGenerate(gr.nullSeed.t.size, gr.nullSeed.t.buffer);
gr.nullSeedCompatLevel = RuntimeProfileGetSeedCompatLevel(); // libtpms added
}
return TRUE;
}
@ -195,8 +195,8 @@ BOOL HierarchyStartup(STARTUP_TYPE type // IN: start up type
// This function extracts the base hierarchy and modifier from a given handle.
// Returns the base hierarchy.
static TPMI_RH_HIERARCHY DecomposeHandle(TPMI_RH_HIERARCHY handle, // IN
HIERARCHY_MODIFIER* modifier // OUT
)
HIERARCHY_MODIFIER* modifier // OUT
)
{
TPMI_RH_HIERARCHY base_hierarchy = handle;
@ -204,64 +204,64 @@ static TPMI_RH_HIERARCHY DecomposeHandle(TPMI_RH_HIERARCHY handle, // IN
// See if the handle is firmware-bound.
switch(handle)
{
case TPM_RH_FW_OWNER:
{
modifier->type = HM_FW_LIMITED;
base_hierarchy = TPM_RH_OWNER;
break;
}
case TPM_RH_FW_ENDORSEMENT:
{
modifier->type = HM_FW_LIMITED;
base_hierarchy = TPM_RH_ENDORSEMENT;
break;
}
case TPM_RH_FW_PLATFORM:
{
modifier->type = HM_FW_LIMITED;
base_hierarchy = TPM_RH_PLATFORM;
break;
}
case TPM_RH_FW_NULL:
{
modifier->type = HM_FW_LIMITED;
base_hierarchy = TPM_RH_NULL;
break;
}
}
{
case TPM_RH_FW_OWNER:
{
modifier->type = HM_FW_LIMITED;
base_hierarchy = TPM_RH_OWNER;
break;
}
case TPM_RH_FW_ENDORSEMENT:
{
modifier->type = HM_FW_LIMITED;
base_hierarchy = TPM_RH_ENDORSEMENT;
break;
}
case TPM_RH_FW_PLATFORM:
{
modifier->type = HM_FW_LIMITED;
base_hierarchy = TPM_RH_PLATFORM;
break;
}
case TPM_RH_FW_NULL:
{
modifier->type = HM_FW_LIMITED;
base_hierarchy = TPM_RH_NULL;
break;
}
}
if(modifier->type == HM_FW_LIMITED)
{
return base_hierarchy;
}
{
return base_hierarchy;
}
// See if the handle is SVN-bound.
switch(handle & 0xFFFF0000)
{
case TPM_RH_SVN_OWNER_BASE:
modifier->type = HM_SVN_LIMITED;
base_hierarchy = TPM_RH_OWNER;
break;
case TPM_RH_SVN_ENDORSEMENT_BASE:
modifier->type = HM_SVN_LIMITED;
base_hierarchy = TPM_RH_ENDORSEMENT;
break;
case TPM_RH_SVN_PLATFORM_BASE:
modifier->type = HM_SVN_LIMITED;
base_hierarchy = TPM_RH_PLATFORM;
break;
case TPM_RH_SVN_NULL_BASE:
modifier->type = HM_SVN_LIMITED;
base_hierarchy = TPM_RH_NULL;
break;
}
{
case TPM_RH_SVN_OWNER_BASE:
modifier->type = HM_SVN_LIMITED;
base_hierarchy = TPM_RH_OWNER;
break;
case TPM_RH_SVN_ENDORSEMENT_BASE:
modifier->type = HM_SVN_LIMITED;
base_hierarchy = TPM_RH_ENDORSEMENT;
break;
case TPM_RH_SVN_PLATFORM_BASE:
modifier->type = HM_SVN_LIMITED;
base_hierarchy = TPM_RH_PLATFORM;
break;
case TPM_RH_SVN_NULL_BASE:
modifier->type = HM_SVN_LIMITED;
base_hierarchy = TPM_RH_NULL;
break;
}
if(modifier->type == HM_SVN_LIMITED)
{
modifier->min_svn = handle & 0x0000FFFF;
return base_hierarchy;
}
{
modifier->min_svn = handle & 0x0000FFFF;
return base_hierarchy;
}
// Handle is neither FW- nor SVN-bound; return it unmodified.
return handle;
@ -282,55 +282,55 @@ static TPMI_RH_HIERARCHY DecomposeHandle(TPMI_RH_HIERARCHY handle, // IN
// to derive the Firmware SVN Secret for the requested
// SVN.
static TPM_RC GetAdditionalSecret(const HIERARCHY_MODIFIER* modifier, // IN
TPM2B_SEED* secret_buffer, // OUT
const TPM2B** secret_label // OUT
)
TPM2B_SEED* secret_buffer, // OUT
const TPM2B** secret_label // OUT
)
{
switch(modifier->type)
{
case HM_FW_LIMITED:
{
{
case HM_FW_LIMITED:
{
#if FW_LIMITED_SUPPORT
if(_plat__GetTpmFirmwareSecret(sizeof(secret_buffer->t.buffer),
secret_buffer->t.buffer,
&secret_buffer->t.size)
!= 0)
{
return TPM_RC_FW_LIMITED;
}
if(_plat__GetTpmFirmwareSecret(sizeof(secret_buffer->t.buffer),
secret_buffer->t.buffer,
&secret_buffer->t.size)
!= 0)
{
return TPM_RC_FW_LIMITED;
}
*secret_label = HIERARCHY_FW_SECRET_LABEL;
break;
*secret_label = HIERARCHY_FW_SECRET_LABEL;
break;
#else
return TPM_RC_FW_LIMITED;
return TPM_RC_FW_LIMITED;
#endif // FW_LIMITED_SUPPORT
}
case HM_SVN_LIMITED:
{
}
case HM_SVN_LIMITED:
{
#if SVN_LIMITED_SUPPORT
if(_plat__GetTpmFirmwareSvnSecret(modifier->min_svn,
sizeof(secret_buffer->t.buffer),
secret_buffer->t.buffer,
&secret_buffer->t.size)
!= 0)
{
return TPM_RC_SVN_LIMITED;
}
if(_plat__GetTpmFirmwareSvnSecret(modifier->min_svn,
sizeof(secret_buffer->t.buffer),
secret_buffer->t.buffer,
&secret_buffer->t.size)
!= 0)
{
return TPM_RC_SVN_LIMITED;
}
*secret_label = HIERARCHY_SVN_SECRET_LABEL;
break;
*secret_label = HIERARCHY_SVN_SECRET_LABEL;
break;
#else
return TPM_RC_SVN_LIMITED;
return TPM_RC_SVN_LIMITED;
#endif // SVN_LIMITED_SUPPORT
}
case HM_NONE:
default:
{
secret_buffer->t.size = 0;
*secret_label = NULL;
break;
}
}
}
case HM_NONE:
default:
{
secret_buffer->t.size = 0;
*secret_label = NULL;
break;
}
}
return TPM_RC_SUCCESS;
}
@ -351,38 +351,38 @@ static TPM_RC GetAdditionalSecret(const HIERARCHY_MODIFIER* modifier, // I
// to derive the Firmware SVN Secret for the requested
// SVN.
static TPM_RC MixAdditionalSecret(const HIERARCHY_MODIFIER* modifier, // IN
const TPM2B* base_secret_label, // IN
const TPM2B* base_secret, // IN
TPM2B* output_secret // OUT
)
const TPM2B* base_secret_label, // IN
const TPM2B* base_secret, // IN
TPM2B* output_secret // OUT
)
{
TPM_RC result = TPM_RC_SUCCESS;
TPM2B_SEED additional_secret;
const TPM2B* additional_secret_label = NULL;
result =
GetAdditionalSecret(modifier, &additional_secret, &additional_secret_label);
GetAdditionalSecret(modifier, &additional_secret, &additional_secret_label);
if(result != TPM_RC_SUCCESS)
return result;
return result;
output_secret->size = base_secret->size;
if(additional_secret.b.size == 0)
{
memcpy(output_secret->buffer, base_secret->buffer, base_secret->size);
}
{
memcpy(output_secret->buffer, base_secret->buffer, base_secret->size);
}
else
{
CryptKDFa(CONTEXT_INTEGRITY_HASH_ALG,
base_secret,
base_secret_label,
&additional_secret.b,
additional_secret_label,
base_secret->size * 8,
output_secret->buffer,
NULL,
FALSE);
}
{
CryptKDFa(CONTEXT_INTEGRITY_HASH_ALG,
base_secret,
base_secret_label,
&additional_secret.b,
additional_secret_label,
base_secret->size * 8,
output_secret->buffer,
NULL,
FALSE);
}
MemorySet(additional_secret.b.buffer, 0, additional_secret.b.size);
@ -393,90 +393,90 @@ static TPM_RC MixAdditionalSecret(const HIERARCHY_MODIFIER* modifier,
// This function derives the proof value associated with a hierarchy. It returns a
// buffer containing the proof value.
TPM_RC HierarchyGetProof(TPMI_RH_HIERARCHY hierarchy, // IN: hierarchy constant
TPM2B_PROOF* proof // OUT: proof buffer
)
TPM2B_PROOF* proof // OUT: proof buffer
)
{
TPM2B_PROOF* base_proof = NULL;
HIERARCHY_MODIFIER modifier;
switch(DecomposeHandle(hierarchy, &modifier))
{
case TPM_RH_PLATFORM:
// phProof for TPM_RH_PLATFORM
base_proof = &gp.phProof;
break;
case TPM_RH_ENDORSEMENT:
// ehProof for TPM_RH_ENDORSEMENT
base_proof = &gp.ehProof;
break;
case TPM_RH_OWNER:
// shProof for TPM_RH_OWNER
base_proof = &gp.shProof;
break;
default:
// nullProof for TPM_RH_NULL or anything else
base_proof = &gr.nullProof;
break;
}
{
case TPM_RH_PLATFORM:
// phProof for TPM_RH_PLATFORM
base_proof = &gp.phProof;
break;
case TPM_RH_ENDORSEMENT:
// ehProof for TPM_RH_ENDORSEMENT
base_proof = &gp.ehProof;
break;
case TPM_RH_OWNER:
// shProof for TPM_RH_OWNER
base_proof = &gp.shProof;
break;
default:
// nullProof for TPM_RH_NULL or anything else
base_proof = &gr.nullProof;
break;
}
return MixAdditionalSecret(
&modifier, HIERARCHY_PROOF_SECRET_LABEL, &base_proof->b, &proof->b);
&modifier, HIERARCHY_PROOF_SECRET_LABEL, &base_proof->b, &proof->b);
}
//*** HierarchyGetPrimarySeed()
// This function derives the primary seed of a hierarchy.
TPM_RC HierarchyGetPrimarySeed(TPMI_RH_HIERARCHY hierarchy, // IN: hierarchy
TPM2B_SEED* seed // OUT: seed buffer
)
TPM2B_SEED* seed // OUT: seed buffer
)
{
TPM2B_SEED* base_seed = NULL;
HIERARCHY_MODIFIER modifier;
switch(DecomposeHandle(hierarchy, &modifier))
{
case TPM_RH_PLATFORM:
base_seed = &gp.PPSeed;
break;
case TPM_RH_OWNER:
base_seed = &gp.SPSeed;
break;
case TPM_RH_ENDORSEMENT:
base_seed = &gp.EPSeed;
break;
default:
base_seed = &gr.nullSeed;
break;
}
{
case TPM_RH_PLATFORM:
base_seed = &gp.PPSeed;
break;
case TPM_RH_OWNER:
base_seed = &gp.SPSeed;
break;
case TPM_RH_ENDORSEMENT:
base_seed = &gp.EPSeed;
break;
default:
base_seed = &gr.nullSeed;
break;
}
return MixAdditionalSecret(
&modifier, HIERARCHY_SEED_SECRET_LABEL, &base_seed->b, &seed->b);
&modifier, HIERARCHY_SEED_SECRET_LABEL, &base_seed->b, &seed->b);
}
// libtpms added begin
SEED_COMPAT_LEVEL
HierarchyGetPrimarySeedCompatLevel(
TPMI_RH_HIERARCHY hierarchy // IN: hierarchy
)
TPMI_RH_HIERARCHY hierarchy // IN: hierarchy
)
{
HIERARCHY_MODIFIER modifier;
switch(DecomposeHandle(hierarchy, &modifier))
{
case TPM_RH_PLATFORM:
return gp.PPSeedCompatLevel;
break;
case TPM_RH_OWNER:
return gp.SPSeedCompatLevel;
break;
case TPM_RH_ENDORSEMENT:
return gp.EPSeedCompatLevel;
break;
case TPM_RH_NULL:
return gr.nullSeedCompatLevel;
default:
return RuntimeProfileGetSeedCompatLevel();
break;
}
{
case TPM_RH_PLATFORM:
return gp.PPSeedCompatLevel;
break;
case TPM_RH_OWNER:
return gp.SPSeedCompatLevel;
break;
case TPM_RH_ENDORSEMENT:
return gp.EPSeedCompatLevel;
break;
case TPM_RH_NULL:
return gr.nullSeedCompatLevel;
default:
return RuntimeProfileGetSeedCompatLevel();
break;
}
}
// libtpms added end
@ -491,7 +491,7 @@ HierarchyGetPrimarySeedCompatLevel(
// is greater than the TPM's current SVN.
// TPM_RC_VALUE Hierarchy is not valid
TPM_RC ValidateHierarchy(TPMI_RH_HIERARCHY hierarchy // IN: hierarchy
)
)
{
BOOL enabled;
HIERARCHY_MODIFIER modifier;
@ -500,50 +500,50 @@ TPM_RC ValidateHierarchy(TPMI_RH_HIERARCHY hierarchy // IN: hierarchy
// Modifier-specific checks.
switch(modifier.type)
{
case HM_NONE:
break;
case HM_FW_LIMITED:
{
{
case HM_NONE:
break;
case HM_FW_LIMITED:
{
#if FW_LIMITED_SUPPORT
break;
break;
#else
return TPM_RC_FW_LIMITED;
return TPM_RC_FW_LIMITED;
#endif // FW_LIMITED_SUPPORT
}
case HM_SVN_LIMITED:
{
}
case HM_SVN_LIMITED:
{
#if SVN_LIMITED_SUPPORT
// SVN-limited hierarchies are only enabled for SVNs less than or
// equal to the current firmware's SVN.
if(modifier.min_svn > _plat__GetTpmFirmwareSvn())
{
return TPM_RC_SVN_LIMITED;
}
break;
// SVN-limited hierarchies are only enabled for SVNs less than or
// equal to the current firmware's SVN.
if(modifier.min_svn > _plat__GetTpmFirmwareSvn())
{
return TPM_RC_SVN_LIMITED;
}
break;
#else
return TPM_RC_SVN_LIMITED;
return TPM_RC_SVN_LIMITED;
#endif // SVN_LIMITED_SUPPORT
}
}
}
}
switch(hierarchy)
{
case TPM_RH_PLATFORM:
enabled = g_phEnable;
break;
case TPM_RH_OWNER:
enabled = gc.shEnable;
break;
case TPM_RH_ENDORSEMENT:
enabled = gc.ehEnable;
break;
case TPM_RH_NULL:
enabled = TRUE;
break;
default:
return TPM_RC_VALUE;
}
{
case TPM_RH_PLATFORM:
enabled = g_phEnable;
break;
case TPM_RH_OWNER:
enabled = gc.shEnable;
break;
case TPM_RH_ENDORSEMENT:
enabled = gc.ehEnable;
break;
case TPM_RH_NULL:
enabled = TRUE;
break;
default:
return TPM_RC_VALUE;
}
return enabled ? TPM_RC_SUCCESS : TPM_RC_HIERARCHY;
}
@ -555,7 +555,7 @@ TPM_RC ValidateHierarchy(TPMI_RH_HIERARCHY hierarchy // IN: hierarchy
// TRUE(1) hierarchy is enabled
// FALSE(0) hierarchy is disabled
BOOL HierarchyIsEnabled(TPMI_RH_HIERARCHY hierarchy // IN: hierarchy
)
)
{
return ValidateHierarchy(hierarchy) == TPM_RC_SUCCESS;
}
@ -564,7 +564,7 @@ BOOL HierarchyIsEnabled(TPMI_RH_HIERARCHY hierarchy // IN: hierarchy
// This function accepts a handle that may or may not be FW- or SVN-bound,
// and returns the base hierarchy to which the handle refers.
TPMI_RH_HIERARCHY HierarchyNormalizeHandle(TPMI_RH_HIERARCHY handle // IN: handle
)
)
{
HIERARCHY_MODIFIER unused_modifier;
@ -575,7 +575,7 @@ TPMI_RH_HIERARCHY HierarchyNormalizeHandle(TPMI_RH_HIERARCHY handle // IN: hand
// This function accepts a hierarchy handle and returns whether it is firmware-
// limited.
BOOL HierarchyIsFirmwareLimited(TPMI_RH_HIERARCHY handle // IN
)
)
{
HIERARCHY_MODIFIER modifier;
@ -587,7 +587,7 @@ BOOL HierarchyIsFirmwareLimited(TPMI_RH_HIERARCHY handle // IN
// This function accepts a hierarchy handle and returns whether it is SVN-
// limited.
BOOL HierarchyIsSvnLimited(TPMI_RH_HIERARCHY handle // IN
)
)
{
HIERARCHY_MODIFIER modifier;

View File

@ -59,22 +59,28 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef HIERARCHYCHANGEAUTH_FP_H
#define HIERARCHYCHANGEAUTH_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_RH_HIERARCHY_AUTH authHandle;
TPM2B_AUTH newAuth;
#if CC_HierarchyChangeAuth // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_HIERARCHYCHANGEAUTH_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_HIERARCHYCHANGEAUTH_FP_H_
// Input structure definition
typedef struct
{
TPMI_RH_HIERARCHY_AUTH authHandle;
TPM2B_AUTH newAuth;
} HierarchyChangeAuth_In;
#define RC_HierarchyChangeAuth_authHandle (TPM_RC_H + TPM_RC_1)
#define RC_HierarchyChangeAuth_newAuth (TPM_RC_P + TPM_RC_2)
// Response code modifiers
# define RC_HierarchyChangeAuth_authHandle (TPM_RC_H + TPM_RC_1)
# define RC_HierarchyChangeAuth_newAuth (TPM_RC_P + TPM_RC_1)
// Function prototype
TPM_RC
TPM2_HierarchyChangeAuth(
HierarchyChangeAuth_In *in // IN: input parameter list
);
TPM2_HierarchyChangeAuth(HierarchyChangeAuth_In* in);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_HIERARCHYCHANGEAUTH_FP_H_
#endif // CC_HierarchyChangeAuth

View File

@ -59,25 +59,30 @@
/* */
/********************************************************************************/
/* rev 119 */
#ifndef HIERARCHYCONTROL_FP_H
#define HIERARCHYCONTROL_FP_H
// FILE GENERATED BY TpmExtractCode: DO NOT EDIT
typedef struct {
TPMI_RH_HIERARCHY authHandle;
TPMI_RH_ENABLES enable;
TPMI_YES_NO state;
#if CC_HierarchyControl // Command must be enabled
# ifndef _TPM_INCLUDE_PRIVATE_PROTOTYPES_HIERARCHYCONTROL_FP_H_
# define _TPM_INCLUDE_PRIVATE_PROTOTYPES_HIERARCHYCONTROL_FP_H_
// Input structure definition
typedef struct
{
TPMI_RH_BASE_HIERARCHY authHandle;
TPMI_RH_ENABLES enable;
TPMI_YES_NO state;
} HierarchyControl_In;
#define RC_HierarchyControl_authHandle (TPM_RC_H + TPM_RC_1)
#define RC_HierarchyControl_enable (TPM_RC_P + TPM_RC_1)
#define RC_HierarchyControl_state (TPM_RC_P + TPM_RC_2)
// Response code modifiers
# define RC_HierarchyControl_authHandle (TPM_RC_H + TPM_RC_1)
# define RC_HierarchyControl_enable (TPM_RC_P + TPM_RC_1)
# define RC_HierarchyControl_state (TPM_RC_P + TPM_RC_2)
// Function prototype
TPM_RC
TPM2_HierarchyControl(
HierarchyControl_In *in // IN: input parameter list
);
TPM2_HierarchyControl(HierarchyControl_In* in);
#endif
# endif // _TPM_INCLUDE_PRIVATE_PROTOTYPES_HIERARCHYCONTROL_FP_H_
#endif // CC_HierarchyControl

Some files were not shown because too many files have changed in this diff Show More