1*5c591343SA. Cody Schuffelen /* Microsoft Reference Implementation for TPM 2.0 2*5c591343SA. Cody Schuffelen * 3*5c591343SA. Cody Schuffelen * The copyright in this software is being made available under the BSD License, 4*5c591343SA. Cody Schuffelen * included below. This software may be subject to other third party and 5*5c591343SA. Cody Schuffelen * contributor rights, including patent rights, and no such rights are granted 6*5c591343SA. Cody Schuffelen * under this license. 7*5c591343SA. Cody Schuffelen * 8*5c591343SA. Cody Schuffelen * Copyright (c) Microsoft Corporation 9*5c591343SA. Cody Schuffelen * 10*5c591343SA. Cody Schuffelen * All rights reserved. 11*5c591343SA. Cody Schuffelen * 12*5c591343SA. Cody Schuffelen * BSD License 13*5c591343SA. Cody Schuffelen * 14*5c591343SA. Cody Schuffelen * Redistribution and use in source and binary forms, with or without modification, 15*5c591343SA. Cody Schuffelen * are permitted provided that the following conditions are met: 16*5c591343SA. Cody Schuffelen * 17*5c591343SA. Cody Schuffelen * Redistributions of source code must retain the above copyright notice, this list 18*5c591343SA. Cody Schuffelen * of conditions and the following disclaimer. 19*5c591343SA. Cody Schuffelen * 20*5c591343SA. Cody Schuffelen * Redistributions in binary form must reproduce the above copyright notice, this 21*5c591343SA. Cody Schuffelen * list of conditions and the following disclaimer in the documentation and/or 22*5c591343SA. Cody Schuffelen * other materials provided with the distribution. 23*5c591343SA. Cody Schuffelen * 24*5c591343SA. Cody Schuffelen * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" 25*5c591343SA. Cody Schuffelen * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26*5c591343SA. Cody Schuffelen * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27*5c591343SA. Cody Schuffelen * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 28*5c591343SA. Cody Schuffelen * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29*5c591343SA. Cody Schuffelen * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30*5c591343SA. Cody Schuffelen * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 31*5c591343SA. Cody Schuffelen * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32*5c591343SA. Cody Schuffelen * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33*5c591343SA. Cody Schuffelen * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34*5c591343SA. Cody Schuffelen */ 35*5c591343SA. Cody Schuffelen //** Introduction 36*5c591343SA. Cody Schuffelen // This file is a collection of miscellaneous macros. 37*5c591343SA. Cody Schuffelen 38*5c591343SA. Cody Schuffelen #ifndef GP_MACROS_H 39*5c591343SA. Cody Schuffelen #define GP_MACROS_H 40*5c591343SA. Cody Schuffelen 41*5c591343SA. Cody Schuffelen #ifndef NULL 42*5c591343SA. Cody Schuffelen #define NULL 0 43*5c591343SA. Cody Schuffelen #endif 44*5c591343SA. Cody Schuffelen 45*5c591343SA. Cody Schuffelen #include "swap.h" 46*5c591343SA. Cody Schuffelen #include "VendorString.h" 47*5c591343SA. Cody Schuffelen 48*5c591343SA. Cody Schuffelen 49*5c591343SA. Cody Schuffelen //** For Self-test 50*5c591343SA. Cody Schuffelen // These macros are used in CryptUtil to invoke the incremental self test. 51*5c591343SA. Cody Schuffelen #if SELF_TEST 52*5c591343SA. Cody Schuffelen # define TEST(alg) if(TEST_BIT(alg, g_toTest)) CryptTestAlgorithm(alg, NULL) 53*5c591343SA. Cody Schuffelen 54*5c591343SA. Cody Schuffelen // Use of TPM_ALG_NULL is reserved for RSAEP/RSADP testing. If someone is wanting 55*5c591343SA. Cody Schuffelen // to test a hash with that value, don't do it. 56*5c591343SA. Cody Schuffelen # define TEST_HASH(alg) \ 57*5c591343SA. Cody Schuffelen if(TEST_BIT(alg, g_toTest) \ 58*5c591343SA. Cody Schuffelen && (alg != TPM_ALG_NULL)) \ 59*5c591343SA. Cody Schuffelen CryptTestAlgorithm(alg, NULL) 60*5c591343SA. Cody Schuffelen #else 61*5c591343SA. Cody Schuffelen # define TEST(alg) 62*5c591343SA. Cody Schuffelen # define TEST_HASH(alg) 63*5c591343SA. Cody Schuffelen #endif // SELF_TEST 64*5c591343SA. Cody Schuffelen 65*5c591343SA. Cody Schuffelen //** For Failures 66*5c591343SA. Cody Schuffelen #if defined _POSIX_ 67*5c591343SA. Cody Schuffelen # define FUNCTION_NAME 0 68*5c591343SA. Cody Schuffelen #else 69*5c591343SA. Cody Schuffelen # define FUNCTION_NAME __FUNCTION__ 70*5c591343SA. Cody Schuffelen #endif 71*5c591343SA. Cody Schuffelen 72*5c591343SA. Cody Schuffelen #if !FAIL_TRACE 73*5c591343SA. Cody Schuffelen # define FAIL(errorCode) (TpmFail(errorCode)) 74*5c591343SA. Cody Schuffelen # define LOG_FAILURE(errorCode) (TpmLogFailure(errorCode)) 75*5c591343SA. Cody Schuffelen #else 76*5c591343SA. Cody Schuffelen # define FAIL(errorCode) TpmFail(FUNCTION_NAME, __LINE__, errorCode) 77*5c591343SA. Cody Schuffelen # define LOG_FAILURE(errorCode) TpmLogFailure(FUNCTION_NAME, __LINE__, errorCode) 78*5c591343SA. Cody Schuffelen #endif 79*5c591343SA. Cody Schuffelen 80*5c591343SA. Cody Schuffelen // If implementation is using longjmp, then the call to TpmFail() does not return 81*5c591343SA. Cody Schuffelen // and the compiler will complain about unreachable code that comes after. To allow 82*5c591343SA. Cody Schuffelen // for not having longjmp, TpmFail() will return and the subsequent code will be 83*5c591343SA. Cody Schuffelen // executed. This macro accounts for the difference. 84*5c591343SA. Cody Schuffelen #ifndef NO_LONGJMP 85*5c591343SA. Cody Schuffelen # define FAIL_RETURN(returnCode) 86*5c591343SA. Cody Schuffelen # define TPM_FAIL_RETURN NORETURN void 87*5c591343SA. Cody Schuffelen #else 88*5c591343SA. Cody Schuffelen # define FAIL_RETURN(returnCode) return (returnCode) 89*5c591343SA. Cody Schuffelen # define TPM_FAIL_RETURN void 90*5c591343SA. Cody Schuffelen #endif 91*5c591343SA. Cody Schuffelen 92*5c591343SA. Cody Schuffelen // This macro tests that a condition is TRUE and puts the TPM into failure mode 93*5c591343SA. Cody Schuffelen // if it is not. If longjmp is being used, then the FAIL(FATAL_ERROR_) macro makes 94*5c591343SA. Cody Schuffelen // a call from which there is no return. Otherwise, it returns and the function 95*5c591343SA. Cody Schuffelen // will exit with the appropriate return code. 96*5c591343SA. Cody Schuffelen #define REQUIRE(condition, errorCode, returnCode) \ 97*5c591343SA. Cody Schuffelen { \ 98*5c591343SA. Cody Schuffelen if(!!(condition)) \ 99*5c591343SA. Cody Schuffelen { \ 100*5c591343SA. Cody Schuffelen FAIL(FATAL_ERROR_errorCode); \ 101*5c591343SA. Cody Schuffelen FAIL_RETURN(returnCode); \ 102*5c591343SA. Cody Schuffelen } \ 103*5c591343SA. Cody Schuffelen } 104*5c591343SA. Cody Schuffelen 105*5c591343SA. Cody Schuffelen #define PARAMETER_CHECK(condition, returnCode) \ 106*5c591343SA. Cody Schuffelen REQUIRE((condition), PARAMETER, returnCode) 107*5c591343SA. Cody Schuffelen 108*5c591343SA. Cody Schuffelen #if (defined EMPTY_ASSERT) && (EMPTY_ASSERT != NO) 109*5c591343SA. Cody Schuffelen # define pAssert(a) ((void)0) 110*5c591343SA. Cody Schuffelen #else 111*5c591343SA. Cody Schuffelen # define pAssert(a) {if(!(a)) FAIL(FATAL_ERROR_PARAMETER);} 112*5c591343SA. Cody Schuffelen #endif 113*5c591343SA. Cody Schuffelen 114*5c591343SA. Cody Schuffelen //** Derived from Vendor-specific values 115*5c591343SA. Cody Schuffelen // Values derived from vendor specific settings in TpmProfile.h 116*5c591343SA. Cody Schuffelen #define PCR_SELECT_MIN ((PLATFORM_PCR+7)/8) 117*5c591343SA. Cody Schuffelen #define PCR_SELECT_MAX ((IMPLEMENTATION_PCR+7)/8) 118*5c591343SA. Cody Schuffelen #define MAX_ORDERLY_COUNT ((1 << ORDERLY_BITS) - 1) 119*5c591343SA. Cody Schuffelen #define RSA_MAX_PRIME (MAX_RSA_KEY_BYTES / 2) 120*5c591343SA. Cody Schuffelen #define RSA_PRIVATE_SIZE (RSA_MAX_PRIME * 5) 121*5c591343SA. Cody Schuffelen 122*5c591343SA. Cody Schuffelen 123*5c591343SA. Cody Schuffelen //** Compile-time Checks 124*5c591343SA. Cody Schuffelen // In some cases, the relationship between two values may be dependent 125*5c591343SA. Cody Schuffelen // on things that change based on various selections like the chosen cryptographic 126*5c591343SA. Cody Schuffelen // libraries. It is possible that these selections will result in incompatible 127*5c591343SA. Cody Schuffelen // settings. These are often detectable by the compiler but it is not always 128*5c591343SA. Cody Schuffelen // possible to do the check in the preprocessor code. For example, when the 129*5c591343SA. Cody Schuffelen // check requires use of "sizeof" then the preprocessor can't do the comparison. 130*5c591343SA. Cody Schuffelen // For these cases, we include a special macro that, depending on the compiler 131*5c591343SA. Cody Schuffelen // will generate a warning to indicate if the check always passes or always fails 132*5c591343SA. Cody Schuffelen // because it involves fixed constants. To run these checks, define COMPILER_CHECKS 133*5c591343SA. Cody Schuffelen // in TpmBuildSwitches.h 134*5c591343SA. Cody Schuffelen #if COMPILER_CHECKS 135*5c591343SA. Cody Schuffelen # define cAssert pAssert 136*5c591343SA. Cody Schuffelen #else 137*5c591343SA. Cody Schuffelen # define cAssert(value) 138*5c591343SA. Cody Schuffelen #endif 139*5c591343SA. Cody Schuffelen 140*5c591343SA. Cody Schuffelen // This is used commonly in the "Crypt" code as a way to keep listings from 141*5c591343SA. Cody Schuffelen // getting too long. This is not to save paper but to allow one to see more 142*5c591343SA. Cody Schuffelen // useful stuff on the screen at any given time. 143*5c591343SA. Cody Schuffelen #define ERROR_RETURN(returnCode) \ 144*5c591343SA. Cody Schuffelen { \ 145*5c591343SA. Cody Schuffelen retVal = returnCode; \ 146*5c591343SA. Cody Schuffelen goto Exit; \ 147*5c591343SA. Cody Schuffelen } 148*5c591343SA. Cody Schuffelen 149*5c591343SA. Cody Schuffelen #ifndef MAX 150*5c591343SA. Cody Schuffelen # define MAX(a, b) ((a) > (b) ? (a) : (b)) 151*5c591343SA. Cody Schuffelen #endif 152*5c591343SA. Cody Schuffelen #ifndef MIN 153*5c591343SA. Cody Schuffelen # define MIN(a, b) ((a) < (b) ? (a) : (b)) 154*5c591343SA. Cody Schuffelen #endif 155*5c591343SA. Cody Schuffelen #ifndef IsOdd 156*5c591343SA. Cody Schuffelen # define IsOdd(a) (((a) & 1) != 0) 157*5c591343SA. Cody Schuffelen #endif 158*5c591343SA. Cody Schuffelen 159*5c591343SA. Cody Schuffelen #ifndef BITS_TO_BYTES 160*5c591343SA. Cody Schuffelen # define BITS_TO_BYTES(bits) (((bits) + 7) >> 3) 161*5c591343SA. Cody Schuffelen #endif 162*5c591343SA. Cody Schuffelen 163*5c591343SA. Cody Schuffelen // These are defined for use when the size of the vector being checked is known 164*5c591343SA. Cody Schuffelen // at compile time. 165*5c591343SA. Cody Schuffelen #define TEST_BIT(bit, vector) TestBit((bit), (BYTE *)&(vector), sizeof(vector)) 166*5c591343SA. Cody Schuffelen #define SET_BIT(bit, vector) SetBit((bit), (BYTE *)&(vector), sizeof(vector)) 167*5c591343SA. Cody Schuffelen #define CLEAR_BIT(bit, vector) ClearBit((bit), (BYTE *)&(vector), sizeof(vector)) 168*5c591343SA. Cody Schuffelen 169*5c591343SA. Cody Schuffelen 170*5c591343SA. Cody Schuffelen // The following definitions are used if they have not already been defined. The 171*5c591343SA. Cody Schuffelen // defaults for these settings are compatible with ISO/IEC 9899:2011 (E) 172*5c591343SA. Cody Schuffelen #ifndef LIB_EXPORT 173*5c591343SA. Cody Schuffelen # define LIB_EXPORT 174*5c591343SA. Cody Schuffelen # define LIB_IMPORT 175*5c591343SA. Cody Schuffelen #endif 176*5c591343SA. Cody Schuffelen #ifndef NORETURN 177*5c591343SA. Cody Schuffelen # define NORETURN _Noreturn 178*5c591343SA. Cody Schuffelen #endif 179*5c591343SA. Cody Schuffelen #ifndef NOT_REFERENCED 180*5c591343SA. Cody Schuffelen # define NOT_REFERENCED(x = x) ((void) (x)) 181*5c591343SA. Cody Schuffelen #endif 182*5c591343SA. Cody Schuffelen 183*5c591343SA. Cody Schuffelen #define STD_RESPONSE_HEADER (sizeof(TPM_ST) + sizeof(UINT32) + sizeof(TPM_RC)) 184*5c591343SA. Cody Schuffelen 185*5c591343SA. Cody Schuffelen #define JOIN(x, y) x##y 186*5c591343SA. Cody Schuffelen #define JOIN3(x, y, z) x##y##z 187*5c591343SA. Cody Schuffelen #define CONCAT(x, y) JOIN(x, y) 188*5c591343SA. Cody Schuffelen #define CONCAT3(x, y, z) JOIN3(x,y,z) 189*5c591343SA. Cody Schuffelen 190*5c591343SA. Cody Schuffelen // If CONTEXT_INTEGRITY_HASH_ALG is defined, then the vendor is using the old style 191*5c591343SA. Cody Schuffelen // table. Otherwise, pick the "strongest" implemented hash algorithm as the context 192*5c591343SA. Cody Schuffelen // hash. 193*5c591343SA. Cody Schuffelen #ifndef CONTEXT_HASH_ALGORITHM 194*5c591343SA. Cody Schuffelen # if defined ALG_SHA3_512 && ALG_SHA3_512 == YES 195*5c591343SA. Cody Schuffelen # define CONTEXT_HASH_ALGORITHM SHA3_512 196*5c591343SA. Cody Schuffelen # elif defined ALG_SHA512 && ALG_SHA512 == YES 197*5c591343SA. Cody Schuffelen # define CONTEXT_HASH_ALGORITHM SHA512 198*5c591343SA. Cody Schuffelen # elif defined ALG_SHA3_384 && ALG_SHA3_384 == YES 199*5c591343SA. Cody Schuffelen # define CONTEXT_HASH_ALGORITHM SHA3_384 200*5c591343SA. Cody Schuffelen # elif defined ALG_SHA384 && ALG_SHA384 == YES 201*5c591343SA. Cody Schuffelen # define CONTEXT_HASH_ALGORITHM SHA384 202*5c591343SA. Cody Schuffelen # elif defined ALG_SHA3_256 && ALG_SHA3_256 == YES 203*5c591343SA. Cody Schuffelen # define CONTEXT_HASH_ALGORITHM SHA3_256 204*5c591343SA. Cody Schuffelen # elif defined ALG_SHA256 && ALG_SHA256 == YES 205*5c591343SA. Cody Schuffelen # define CONTEXT_HASH_ALGORITHM SHA256 206*5c591343SA. Cody Schuffelen # elif defined ALG_SM3_256 && ALG_SM3_256 == YES 207*5c591343SA. Cody Schuffelen # define CONTEXT_HASH_ALGORITHM SM3_256 208*5c591343SA. Cody Schuffelen # elif defined ALG_SHA1 && ALG_SHA1 == YES 209*5c591343SA. Cody Schuffelen # define CONTEXT_HASH_ALGORITHM SHA1 210*5c591343SA. Cody Schuffelen # endif 211*5c591343SA. Cody Schuffelen # define CONTEXT_INTEGRITY_HASH_ALG CONCAT(TPM_ALG_, CONTEXT_HASH_ALGORITHM) 212*5c591343SA. Cody Schuffelen #endif 213*5c591343SA. Cody Schuffelen 214*5c591343SA. Cody Schuffelen #ifndef CONTEXT_INTEGRITY_HASH_SIZE 215*5c591343SA. Cody Schuffelen #define CONTEXT_INTEGRITY_HASH_SIZE CONCAT(CONTEXT_HASH_ALGORITHM, _DIGEST_SIZE) 216*5c591343SA. Cody Schuffelen #endif 217*5c591343SA. Cody Schuffelen #if ALG_RSA 218*5c591343SA. Cody Schuffelen #define RSA_SECURITY_STRENGTH (MAX_RSA_KEY_BITS >= 15360 ? 256 : \ 219*5c591343SA. Cody Schuffelen (MAX_RSA_KEY_BITS >= 7680 ? 192 : \ 220*5c591343SA. Cody Schuffelen (MAX_RSA_KEY_BITS >= 3072 ? 128 : \ 221*5c591343SA. Cody Schuffelen (MAX_RSA_KEY_BITS >= 2048 ? 112 : \ 222*5c591343SA. Cody Schuffelen (MAX_RSA_KEY_BITS >= 1024 ? 80 : 0))))) 223*5c591343SA. Cody Schuffelen #else 224*5c591343SA. Cody Schuffelen #define RSA_SECURITY_STRENGTH 0 225*5c591343SA. Cody Schuffelen #endif // ALG_RSA 226*5c591343SA. Cody Schuffelen 227*5c591343SA. Cody Schuffelen #if ALG_ECC 228*5c591343SA. Cody Schuffelen #define ECC_SECURITY_STRENGTH (MAX_ECC_KEY_BITS >= 521 ? 256 : \ 229*5c591343SA. Cody Schuffelen (MAX_ECC_KEY_BITS >= 384 ? 192 : \ 230*5c591343SA. Cody Schuffelen (MAX_ECC_KEY_BITS >= 256 ? 128 : 0))) 231*5c591343SA. Cody Schuffelen #else 232*5c591343SA. Cody Schuffelen #define ECC_SECURITY_STRENGTH 0 233*5c591343SA. Cody Schuffelen #endif // ALG_ECC 234*5c591343SA. Cody Schuffelen 235*5c591343SA. Cody Schuffelen #define MAX_ASYM_SECURITY_STRENGTH \ 236*5c591343SA. Cody Schuffelen MAX(RSA_SECURITY_STRENGTH, ECC_SECURITY_STRENGTH) 237*5c591343SA. Cody Schuffelen 238*5c591343SA. Cody Schuffelen #define MAX_HASH_SECURITY_STRENGTH ((CONTEXT_INTEGRITY_HASH_SIZE * 8) / 2) 239*5c591343SA. Cody Schuffelen 240*5c591343SA. Cody Schuffelen // Unless some algorithm is broken... 241*5c591343SA. Cody Schuffelen #define MAX_SYM_SECURITY_STRENGTH MAX_SYM_KEY_BITS 242*5c591343SA. Cody Schuffelen 243*5c591343SA. Cody Schuffelen #define MAX_SECURITY_STRENGTH_BITS \ 244*5c591343SA. Cody Schuffelen MAX(MAX_ASYM_SECURITY_STRENGTH, \ 245*5c591343SA. Cody Schuffelen MAX(MAX_SYM_SECURITY_STRENGTH, \ 246*5c591343SA. Cody Schuffelen MAX_HASH_SECURITY_STRENGTH)) 247*5c591343SA. Cody Schuffelen 248*5c591343SA. Cody Schuffelen // This is the size that was used before the 1.38 errata requiring that P1.14.4 be 249*5c591343SA. Cody Schuffelen // followed 250*5c591343SA. Cody Schuffelen #define PROOF_SIZE CONTEXT_INTEGRITY_HASH_SIZE 251*5c591343SA. Cody Schuffelen 252*5c591343SA. Cody Schuffelen // As required by P1.14.4 253*5c591343SA. Cody Schuffelen #define COMPLIANT_PROOF_SIZE \ 254*5c591343SA. Cody Schuffelen (MAX(CONTEXT_INTEGRITY_HASH_SIZE, (2 * MAX_SYM_KEY_BYTES))) 255*5c591343SA. Cody Schuffelen 256*5c591343SA. Cody Schuffelen // As required by P1.14.3.1 257*5c591343SA. Cody Schuffelen #define COMPLIANT_PRIMARY_SEED_SIZE \ 258*5c591343SA. Cody Schuffelen BITS_TO_BYTES(MAX_SECURITY_STRENGTH_BITS * 2) 259*5c591343SA. Cody Schuffelen 260*5c591343SA. Cody Schuffelen // This is the pre-errata version 261*5c591343SA. Cody Schuffelen #ifndef PRIMARY_SEED_SIZE 262*5c591343SA. Cody Schuffelen # define PRIMARY_SEED_SIZE PROOF_SIZE 263*5c591343SA. Cody Schuffelen #endif 264*5c591343SA. Cody Schuffelen 265*5c591343SA. Cody Schuffelen #if USE_SPEC_COMPLIANT_PROOFS 266*5c591343SA. Cody Schuffelen # undef PROOF_SIZE 267*5c591343SA. Cody Schuffelen # define PROOF_SIZE COMPLIANT_PROOF_SIZE 268*5c591343SA. Cody Schuffelen # undef PRIMARY_SEED_SIZE 269*5c591343SA. Cody Schuffelen # define PRIMARY_SEED_SIZE COMPLIANT_PRIMARY_SEED_SIZE 270*5c591343SA. Cody Schuffelen #endif // USE_SPEC_COMPLIANT_PROOFS 271*5c591343SA. Cody Schuffelen 272*5c591343SA. Cody Schuffelen #if !SKIP_PROOF_ERRORS 273*5c591343SA. Cody Schuffelen # if PROOF_SIZE < COMPLIANT_PROOF_SIZE 274*5c591343SA. Cody Schuffelen # error "PROOF_SIZE is not compliant with TPM specification" 275*5c591343SA. Cody Schuffelen # endif 276*5c591343SA. Cody Schuffelen # if PRIMARY_SEED_SIZE < COMPLIANT_PRIMARY_SEED_SIZE 277*5c591343SA. Cody Schuffelen # error Non-compliant PRIMARY_SEED_SIZE 278*5c591343SA. Cody Schuffelen # endif 279*5c591343SA. Cody Schuffelen #endif // !SKIP_PROOF_ERRORS 280*5c591343SA. Cody Schuffelen 281*5c591343SA. Cody Schuffelen // If CONTEXT_ENCRYPT_ALG is defined, then the vendor is using the old style table 282*5c591343SA. Cody Schuffelen #if defined CONTEXT_ENCRYPT_ALG 283*5c591343SA. Cody Schuffelen # undef CONTEXT_ENCRYPT_ALGORITHM 284*5c591343SA. Cody Schuffelen # if CONTEXT_ENCRYPT_ALG == ALG_AES_VALUE 285*5c591343SA. Cody Schuffelen # define CONTEXT_ENCRYPT_ALGORITHM AES 286*5c591343SA. Cody Schuffelen # elif CONTEXT_ENCRYPT_ALG == ALG_SM4_VALUE 287*5c591343SA. Cody Schuffelen # define CONTEXT_ENCRYPT_ALGORITHM SM4 288*5c591343SA. Cody Schuffelen # elif CONTEXT_ENCRYPT_ALG == ALG_CAMELLIA_VALUE 289*5c591343SA. Cody Schuffelen # define CONTEXT_ENCRYPT_ALGORITHM CAMELLIA 290*5c591343SA. Cody Schuffelen # elif CONTEXT_ENCRYPT_ALG == ALG_TDES_VALUE 291*5c591343SA. Cody Schuffelen # error Are you kidding? 292*5c591343SA. Cody Schuffelen # else 293*5c591343SA. Cody Schuffelen # error Unknown value for CONTEXT_ENCRYPT_ALG 294*5c591343SA. Cody Schuffelen # endif // CONTEXT_ENCRYPT_ALG == ALG_AES_VALUE 295*5c591343SA. Cody Schuffelen #else 296*5c591343SA. Cody Schuffelen # define CONTEXT_ENCRYPT_ALG \ 297*5c591343SA. Cody Schuffelen CONCAT3(ALG_, CONTEXT_ENCRYPT_ALGORITHM, _VALUE) 298*5c591343SA. Cody Schuffelen #endif // CONTEXT_ENCRYPT_ALG 299*5c591343SA. Cody Schuffelen #define CONTEXT_ENCRYPT_KEY_BITS \ 300*5c591343SA. Cody Schuffelen CONCAT(CONTEXT_ENCRYPT_ALGORITHM, _MAX_KEY_SIZE_BITS) 301*5c591343SA. Cody Schuffelen #define CONTEXT_ENCRYPT_KEY_BYTES ((CONTEXT_ENCRYPT_KEY_BITS+7)/8) 302*5c591343SA. Cody Schuffelen 303*5c591343SA. Cody Schuffelen // This is updated to follow the requirement of P2 that the label not be larger 304*5c591343SA. Cody Schuffelen // than 32 bytes. 305*5c591343SA. Cody Schuffelen #ifndef LABEL_MAX_BUFFER 306*5c591343SA. Cody Schuffelen #define LABEL_MAX_BUFFER MIN(32, MAX(MAX_ECC_KEY_BYTES, MAX_DIGEST_SIZE)) 307*5c591343SA. Cody Schuffelen #endif 308*5c591343SA. Cody Schuffelen 309*5c591343SA. Cody Schuffelen // This bit is used to indicate that an authorization ticket expires on TPM Reset 310*5c591343SA. Cody Schuffelen // and TPM Restart. It is added to the timeout value returned by TPM2_PoliySigned() 311*5c591343SA. Cody Schuffelen // and TPM2_PolicySecret() and used by TPM2_PolicyTicket(). The timeout value is 312*5c591343SA. Cody Schuffelen // relative to Time (g_time). Time is reset whenever the TPM loses power and cannot 313*5c591343SA. Cody Schuffelen // be moved forward by the user (as can Clock). 'g_time' is a 64-bit value expressing 314*5c591343SA. Cody Schuffelen // time in ms. Stealing the MSb for a flag means that the TPM needs to be reset 315*5c591343SA. Cody Schuffelen // at least once every 292,471,208 years rather than once every 584,942,417 years. 316*5c591343SA. Cody Schuffelen #define EXPIRATION_BIT ((UINT64)1 << 63) 317*5c591343SA. Cody Schuffelen 318*5c591343SA. Cody Schuffelen // Check for consistency of the bit ordering of bit fields 319*5c591343SA. Cody Schuffelen #if BIG_ENDIAN_TPM && MOST_SIGNIFICANT_BIT_0 && USE_BIT_FIELD_STRUCTURES 320*5c591343SA. Cody Schuffelen # error "Settings not consistent" 321*5c591343SA. Cody Schuffelen #endif 322*5c591343SA. Cody Schuffelen 323*5c591343SA. Cody Schuffelen // These macros are used to handle the variation in handling of bit fields. If 324*5c591343SA. Cody Schuffelen #if USE_BIT_FIELD_STRUCTURES // The default, old version, with bit fields 325*5c591343SA. Cody Schuffelen # define IS_ATTRIBUTE(a, type, b) ((a.b) != 0) 326*5c591343SA. Cody Schuffelen # define SET_ATTRIBUTE(a, type, b) (a.b = SET) 327*5c591343SA. Cody Schuffelen # define CLEAR_ATTRIBUTE(a, type, b) (a.b = CLEAR) 328*5c591343SA. Cody Schuffelen # define GET_ATTRIBUTE(a, type, b) (a.b) 329*5c591343SA. Cody Schuffelen # define TPMA_ZERO_INITIALIZER() {0} 330*5c591343SA. Cody Schuffelen #else 331*5c591343SA. Cody Schuffelen # define IS_ATTRIBUTE(a, type, b) ((a & type##_##b) != 0) 332*5c591343SA. Cody Schuffelen # define SET_ATTRIBUTE(a, type, b) (a |= type##_##b) 333*5c591343SA. Cody Schuffelen # define CLEAR_ATTRIBUTE(a, type, b) (a &= ~type##_##b) 334*5c591343SA. Cody Schuffelen # define GET_ATTRIBUTE(a, type, b) \ 335*5c591343SA. Cody Schuffelen (type)((a & type##_##b) >> type##_##b##_SHIFT) 336*5c591343SA. Cody Schuffelen # define TPMA_ZERO_INITIALIZER() (0) 337*5c591343SA. Cody Schuffelen #endif 338*5c591343SA. Cody Schuffelen 339*5c591343SA. Cody Schuffelen #define VERIFY(_X) if(!(_X)) goto Error 340*5c591343SA. Cody Schuffelen 341*5c591343SA. Cody Schuffelen // These macros determine if the values in this file are referenced or instanced. 342*5c591343SA. Cody Schuffelen // Global.c defines GLOBAL_C so all the values in this file will be instanced in 343*5c591343SA. Cody Schuffelen // Global.obj. For all other files that include this file, the values will simply 344*5c591343SA. Cody Schuffelen // be external references. For constants, there can be an initializer. 345*5c591343SA. Cody Schuffelen #ifdef GLOBAL_C 346*5c591343SA. Cody Schuffelen #define EXTERN 347*5c591343SA. Cody Schuffelen #define INITIALIZER(_value_) = _value_ 348*5c591343SA. Cody Schuffelen #else 349*5c591343SA. Cody Schuffelen #define EXTERN extern 350*5c591343SA. Cody Schuffelen #define INITIALIZER(_value_) 351*5c591343SA. Cody Schuffelen #endif 352*5c591343SA. Cody Schuffelen 353*5c591343SA. Cody Schuffelen // This macro will create an OID. All OIDs are in DER form with a first octet of 354*5c591343SA. Cody Schuffelen // 0x06 indicating an OID fallowed by an octet indicating the number of octets in the 355*5c591343SA. Cody Schuffelen // rest of the OID. This allows a user of this OID to know how much/little to copy. 356*5c591343SA. Cody Schuffelen #define MAKE_OID(NAME) \ 357*5c591343SA. Cody Schuffelen EXTERN const BYTE OID##NAME[] INITIALIZER({OID##NAME##_VALUE}) 358*5c591343SA. Cody Schuffelen 359*5c591343SA. Cody Schuffelen // This definition is moved from TpmProfile.h because it is not actually vendor- 360*5c591343SA. Cody Schuffelen // specific. It has to be the same size as the 'sequence' parameter of a TPMS_CONTEXT 361*5c591343SA. Cody Schuffelen // and that is a UINT64. So, this is an invariant value 362*5c591343SA. Cody Schuffelen #define CONTEXT_COUNTER UINT64 363*5c591343SA. Cody Schuffelen 364*5c591343SA. Cody Schuffelen #endif // GP_MACROS_H