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 36*5c591343SA. Cody Schuffelen //** Description 37*5c591343SA. Cody Schuffelen 38*5c591343SA. Cody Schuffelen // This file contains internal global type definitions and data declarations that 39*5c591343SA. Cody Schuffelen // are need between subsystems. The instantiation of global data is in Global.c. 40*5c591343SA. Cody Schuffelen // The initialization of global data is in the subsystem that is the primary owner 41*5c591343SA. Cody Schuffelen // of the data. 42*5c591343SA. Cody Schuffelen // 43*5c591343SA. Cody Schuffelen // The first part of this file has the 'typedefs' for structures and other defines 44*5c591343SA. Cody Schuffelen // used in many portions of the code. After the 'typedef' section, is a section that 45*5c591343SA. Cody Schuffelen // defines global values that are only present in RAM. The next three sections 46*5c591343SA. Cody Schuffelen // define the structures for the NV data areas: persistent, orderly, and state 47*5c591343SA. Cody Schuffelen // save. Additional sections define the data that is used in specific modules. That 48*5c591343SA. Cody Schuffelen // data is private to the module but is collected here to simplify the management 49*5c591343SA. Cody Schuffelen // of the instance data. 50*5c591343SA. Cody Schuffelen // 51*5c591343SA. Cody Schuffelen // All the data is instanced in Global.c. 52*5c591343SA. Cody Schuffelen #if !defined _TPM_H_ 53*5c591343SA. Cody Schuffelen #error "Should only be instanced in TPM.h" 54*5c591343SA. Cody Schuffelen #endif 55*5c591343SA. Cody Schuffelen 56*5c591343SA. Cody Schuffelen 57*5c591343SA. Cody Schuffelen //** Includes 58*5c591343SA. Cody Schuffelen 59*5c591343SA. Cody Schuffelen #ifndef GLOBAL_H 60*5c591343SA. Cody Schuffelen #define GLOBAL_H 61*5c591343SA. Cody Schuffelen 62*5c591343SA. Cody Schuffelen _REDUCE_WARNING_LEVEL_(2) 63*5c591343SA. Cody Schuffelen #include <string.h> 64*5c591343SA. Cody Schuffelen #include <stddef.h> 65*5c591343SA. Cody Schuffelen _NORMAL_WARNING_LEVEL_ 66*5c591343SA. Cody Schuffelen 67*5c591343SA. Cody Schuffelen #include "Capabilities.h" 68*5c591343SA. Cody Schuffelen #include "TpmTypes.h" 69*5c591343SA. Cody Schuffelen #include "CommandAttributes.h" 70*5c591343SA. Cody Schuffelen #include "CryptTest.h" 71*5c591343SA. Cody Schuffelen #include "BnValues.h" 72*5c591343SA. Cody Schuffelen #include "CryptHash.h" 73*5c591343SA. Cody Schuffelen #include "CryptSym.h" 74*5c591343SA. Cody Schuffelen #include "CryptRand.h" 75*5c591343SA. Cody Schuffelen #include "CryptEcc.h" 76*5c591343SA. Cody Schuffelen #include "CryptRsa.h" 77*5c591343SA. Cody Schuffelen #include "CryptTest.h" 78*5c591343SA. Cody Schuffelen #include "TpmError.h" 79*5c591343SA. Cody Schuffelen #include "NV.h" 80*5c591343SA. Cody Schuffelen #include "ACT.h" 81*5c591343SA. Cody Schuffelen 82*5c591343SA. Cody Schuffelen //** Defines and Types 83*5c591343SA. Cody Schuffelen 84*5c591343SA. Cody Schuffelen //*** Size Types 85*5c591343SA. Cody Schuffelen // These types are used to differentiate the two different size values used. 86*5c591343SA. Cody Schuffelen // 87*5c591343SA. Cody Schuffelen // NUMBYTES is used when a size is a number of bytes (usually a TPM2B) 88*5c591343SA. Cody Schuffelen typedef UINT16 NUMBYTES; 89*5c591343SA. Cody Schuffelen 90*5c591343SA. Cody Schuffelen //*** Other Types 91*5c591343SA. Cody Schuffelen // An AUTH_VALUE is a BYTE array containing a digest (TPMU_HA) 92*5c591343SA. Cody Schuffelen typedef BYTE AUTH_VALUE[sizeof(TPMU_HA)]; 93*5c591343SA. Cody Schuffelen 94*5c591343SA. Cody Schuffelen // A TIME_INFO is a BYTE array that can contain a TPMS_TIME_INFO 95*5c591343SA. Cody Schuffelen typedef BYTE TIME_INFO[sizeof(TPMS_TIME_INFO)]; 96*5c591343SA. Cody Schuffelen 97*5c591343SA. Cody Schuffelen // A NAME is a BYTE array that can contain a TPMU_NAME 98*5c591343SA. Cody Schuffelen typedef BYTE NAME[sizeof(TPMU_NAME)]; 99*5c591343SA. Cody Schuffelen 100*5c591343SA. Cody Schuffelen // Definition for a PROOF value 101*5c591343SA. Cody Schuffelen TPM2B_TYPE(PROOF, PROOF_SIZE); 102*5c591343SA. Cody Schuffelen 103*5c591343SA. Cody Schuffelen // Definition for a Primary Seed value 104*5c591343SA. Cody Schuffelen TPM2B_TYPE(SEED, PRIMARY_SEED_SIZE); 105*5c591343SA. Cody Schuffelen 106*5c591343SA. Cody Schuffelen 107*5c591343SA. Cody Schuffelen // A CLOCK_NONCE is used to tag the time value in the authorization session and 108*5c591343SA. Cody Schuffelen // in the ticket computation so that the ticket expires when there is a time 109*5c591343SA. Cody Schuffelen // discontinuity. When the clock stops during normal operation, the nonce is 110*5c591343SA. Cody Schuffelen // 64-bit value kept in RAM but it is a 32-bit counter when the clock only stops 111*5c591343SA. Cody Schuffelen // during power events. 112*5c591343SA. Cody Schuffelen #if CLOCK_STOPS 113*5c591343SA. Cody Schuffelen typedef UINT64 CLOCK_NONCE; 114*5c591343SA. Cody Schuffelen #else 115*5c591343SA. Cody Schuffelen typedef UINT32 CLOCK_NONCE; 116*5c591343SA. Cody Schuffelen #endif 117*5c591343SA. Cody Schuffelen 118*5c591343SA. Cody Schuffelen //** Loaded Object Structures 119*5c591343SA. Cody Schuffelen //*** Description 120*5c591343SA. Cody Schuffelen // The structures in this section define the object layout as it exists in TPM 121*5c591343SA. Cody Schuffelen // memory. 122*5c591343SA. Cody Schuffelen // 123*5c591343SA. Cody Schuffelen // Two types of objects are defined: an ordinary object such as a key, and a 124*5c591343SA. Cody Schuffelen // sequence object that may be a hash, HMAC, or event. 125*5c591343SA. Cody Schuffelen // 126*5c591343SA. Cody Schuffelen //*** OBJECT_ATTRIBUTES 127*5c591343SA. Cody Schuffelen // An OBJECT_ATTRIBUTES structure contains the variable attributes of an object. 128*5c591343SA. Cody Schuffelen // These properties are not part of the public properties but are used by the 129*5c591343SA. Cody Schuffelen // TPM in managing the object. An OBJECT_ATTRIBUTES is used in the definition of 130*5c591343SA. Cody Schuffelen // the OBJECT data type. 131*5c591343SA. Cody Schuffelen 132*5c591343SA. Cody Schuffelen typedef struct 133*5c591343SA. Cody Schuffelen { 134*5c591343SA. Cody Schuffelen unsigned publicOnly : 1; //0) SET if only the public portion of 135*5c591343SA. Cody Schuffelen // an object is loaded 136*5c591343SA. Cody Schuffelen unsigned epsHierarchy : 1; //1) SET if the object belongs to EPS 137*5c591343SA. Cody Schuffelen // Hierarchy 138*5c591343SA. Cody Schuffelen unsigned ppsHierarchy : 1; //2) SET if the object belongs to PPS 139*5c591343SA. Cody Schuffelen // Hierarchy 140*5c591343SA. Cody Schuffelen unsigned spsHierarchy : 1; //3) SET f the object belongs to SPS 141*5c591343SA. Cody Schuffelen // Hierarchy 142*5c591343SA. Cody Schuffelen unsigned evict : 1; //4) SET if the object is a platform or 143*5c591343SA. Cody Schuffelen // owner evict object. Platform- 144*5c591343SA. Cody Schuffelen // evict object belongs to PPS 145*5c591343SA. Cody Schuffelen // hierarchy, owner-evict object 146*5c591343SA. Cody Schuffelen // belongs to SPS or EPS hierarchy. 147*5c591343SA. Cody Schuffelen // This bit is also used to mark a 148*5c591343SA. Cody Schuffelen // completed sequence object so it 149*5c591343SA. Cody Schuffelen // will be flush when the 150*5c591343SA. Cody Schuffelen // SequenceComplete command succeeds. 151*5c591343SA. Cody Schuffelen unsigned primary : 1; //5) SET for a primary object 152*5c591343SA. Cody Schuffelen unsigned temporary : 1; //6) SET for a temporary object 153*5c591343SA. Cody Schuffelen unsigned stClear : 1; //7) SET for an stClear object 154*5c591343SA. Cody Schuffelen unsigned hmacSeq : 1; //8) SET for an HMAC or MAC sequence 155*5c591343SA. Cody Schuffelen // object 156*5c591343SA. Cody Schuffelen unsigned hashSeq : 1; //9) SET for a hash sequence object 157*5c591343SA. Cody Schuffelen unsigned eventSeq : 1; //10) SET for an event sequence object 158*5c591343SA. Cody Schuffelen unsigned ticketSafe : 1; //11) SET if a ticket is safe to create 159*5c591343SA. Cody Schuffelen // for hash sequence object 160*5c591343SA. Cody Schuffelen unsigned firstBlock : 1; //12) SET if the first block of hash 161*5c591343SA. Cody Schuffelen // data has been received. It 162*5c591343SA. Cody Schuffelen // works with ticketSafe bit 163*5c591343SA. Cody Schuffelen unsigned isParent : 1; //13) SET if the key has the proper 164*5c591343SA. Cody Schuffelen // attributes to be a parent key 165*5c591343SA. Cody Schuffelen // unsigned privateExp : 1; //14) SET when the private exponent 166*5c591343SA. Cody Schuffelen // // of an RSA key has been validated. 167*5c591343SA. Cody Schuffelen unsigned not_used_14 : 1; 168*5c591343SA. Cody Schuffelen unsigned occupied : 1; //15) SET when the slot is occupied. 169*5c591343SA. Cody Schuffelen unsigned derivation : 1; //16) SET when the key is a derivation 170*5c591343SA. Cody Schuffelen // parent 171*5c591343SA. Cody Schuffelen unsigned external : 1; //17) SET when the object is loaded with 172*5c591343SA. Cody Schuffelen // TPM2_LoadExternal(); 173*5c591343SA. Cody Schuffelen } OBJECT_ATTRIBUTES; 174*5c591343SA. Cody Schuffelen 175*5c591343SA. Cody Schuffelen #if ALG_RSA 176*5c591343SA. Cody Schuffelen // There is an overload of the sensitive.rsa.t.size field of a TPMT_SENSITIVE when an 177*5c591343SA. Cody Schuffelen // RSA key is loaded. When the sensitive->sensitive contains an RSA key with all of 178*5c591343SA. Cody Schuffelen // the CRT values, then the MSB of the size field will be set to indicate that the 179*5c591343SA. Cody Schuffelen // buffer contains all 5 of the CRT private key values. 180*5c591343SA. Cody Schuffelen #define RSA_prime_flag 0x8000 181*5c591343SA. Cody Schuffelen #endif 182*5c591343SA. Cody Schuffelen 183*5c591343SA. Cody Schuffelen 184*5c591343SA. Cody Schuffelen //*** OBJECT Structure 185*5c591343SA. Cody Schuffelen // An OBJECT structure holds the object public, sensitive, and meta-data 186*5c591343SA. Cody Schuffelen // associated. This structure is implementation dependent. For this 187*5c591343SA. Cody Schuffelen // implementation, the structure is not optimized for space but rather 188*5c591343SA. Cody Schuffelen // for clarity of the reference implementation. Other implementations 189*5c591343SA. Cody Schuffelen // may choose to overlap portions of the structure that are not used 190*5c591343SA. Cody Schuffelen // simultaneously. These changes would necessitate changes to the source 191*5c591343SA. Cody Schuffelen // code but those changes would be compatible with the reference 192*5c591343SA. Cody Schuffelen // implementation. 193*5c591343SA. Cody Schuffelen 194*5c591343SA. Cody Schuffelen typedef struct OBJECT 195*5c591343SA. Cody Schuffelen { 196*5c591343SA. Cody Schuffelen // The attributes field is required to be first followed by the publicArea. 197*5c591343SA. Cody Schuffelen // This allows the overlay of the object structure and a sequence structure 198*5c591343SA. Cody Schuffelen OBJECT_ATTRIBUTES attributes; // object attributes 199*5c591343SA. Cody Schuffelen TPMT_PUBLIC publicArea; // public area of an object 200*5c591343SA. Cody Schuffelen TPMT_SENSITIVE sensitive; // sensitive area of an object 201*5c591343SA. Cody Schuffelen TPM2B_NAME qualifiedName; // object qualified name 202*5c591343SA. Cody Schuffelen TPMI_DH_OBJECT evictHandle; // if the object is an evict object, 203*5c591343SA. Cody Schuffelen // the original handle is kept here. 204*5c591343SA. Cody Schuffelen // The 'working' handle will be the 205*5c591343SA. Cody Schuffelen // handle of an object slot. 206*5c591343SA. Cody Schuffelen TPM2B_NAME name; // Name of the object name. Kept here 207*5c591343SA. Cody Schuffelen // to avoid repeatedly computing it. 208*5c591343SA. Cody Schuffelen } OBJECT; 209*5c591343SA. Cody Schuffelen 210*5c591343SA. Cody Schuffelen //*** HASH_OBJECT Structure 211*5c591343SA. Cody Schuffelen // This structure holds a hash sequence object or an event sequence object. 212*5c591343SA. Cody Schuffelen // 213*5c591343SA. Cody Schuffelen // The first four components of this structure are manually set to be the same as 214*5c591343SA. Cody Schuffelen // the first four components of the object structure. This prevents the object 215*5c591343SA. Cody Schuffelen // from being inadvertently misused as sequence objects occupy the same memory as 216*5c591343SA. Cody Schuffelen // a regular object. A debug check is present to make sure that the offsets are 217*5c591343SA. Cody Schuffelen // what they are supposed to be. 218*5c591343SA. Cody Schuffelen // NOTE: In a future version, this will probably be renamed as SEQUENCE_OBJECT 219*5c591343SA. Cody Schuffelen typedef struct HASH_OBJECT 220*5c591343SA. Cody Schuffelen { 221*5c591343SA. Cody Schuffelen OBJECT_ATTRIBUTES attributes; // The attributes of the HASH object 222*5c591343SA. Cody Schuffelen TPMI_ALG_PUBLIC type; // algorithm 223*5c591343SA. Cody Schuffelen TPMI_ALG_HASH nameAlg; // name algorithm 224*5c591343SA. Cody Schuffelen TPMA_OBJECT objectAttributes; // object attributes 225*5c591343SA. Cody Schuffelen 226*5c591343SA. Cody Schuffelen // The data below is unique to a sequence object 227*5c591343SA. Cody Schuffelen TPM2B_AUTH auth; // authorization for use of sequence 228*5c591343SA. Cody Schuffelen union 229*5c591343SA. Cody Schuffelen { 230*5c591343SA. Cody Schuffelen HASH_STATE hashState[HASH_COUNT]; 231*5c591343SA. Cody Schuffelen HMAC_STATE hmacState; 232*5c591343SA. Cody Schuffelen } state; 233*5c591343SA. Cody Schuffelen } HASH_OBJECT; 234*5c591343SA. Cody Schuffelen 235*5c591343SA. Cody Schuffelen typedef BYTE HASH_OBJECT_BUFFER[sizeof(HASH_OBJECT)]; 236*5c591343SA. Cody Schuffelen 237*5c591343SA. Cody Schuffelen //*** ANY_OBJECT 238*5c591343SA. Cody Schuffelen // This is the union for holding either a sequence object or a regular object 239*5c591343SA. Cody Schuffelen // for ContextSave and ContextLoad. 240*5c591343SA. Cody Schuffelen typedef union ANY_OBJECT 241*5c591343SA. Cody Schuffelen { 242*5c591343SA. Cody Schuffelen OBJECT entity; 243*5c591343SA. Cody Schuffelen HASH_OBJECT hash; 244*5c591343SA. Cody Schuffelen } ANY_OBJECT; 245*5c591343SA. Cody Schuffelen 246*5c591343SA. Cody Schuffelen typedef BYTE ANY_OBJECT_BUFFER[sizeof(ANY_OBJECT)]; 247*5c591343SA. Cody Schuffelen 248*5c591343SA. Cody Schuffelen //**AUTH_DUP Types 249*5c591343SA. Cody Schuffelen // These values are used in the authorization processing. 250*5c591343SA. Cody Schuffelen 251*5c591343SA. Cody Schuffelen typedef UINT32 AUTH_ROLE; 252*5c591343SA. Cody Schuffelen #define AUTH_NONE ((AUTH_ROLE)(0)) 253*5c591343SA. Cody Schuffelen #define AUTH_USER ((AUTH_ROLE)(1)) 254*5c591343SA. Cody Schuffelen #define AUTH_ADMIN ((AUTH_ROLE)(2)) 255*5c591343SA. Cody Schuffelen #define AUTH_DUP ((AUTH_ROLE)(3)) 256*5c591343SA. Cody Schuffelen 257*5c591343SA. Cody Schuffelen //** Active Session Context 258*5c591343SA. Cody Schuffelen //*** Description 259*5c591343SA. Cody Schuffelen // The structures in this section define the internal structure of a session 260*5c591343SA. Cody Schuffelen // context. 261*5c591343SA. Cody Schuffelen // 262*5c591343SA. Cody Schuffelen //*** SESSION_ATTRIBUTES 263*5c591343SA. Cody Schuffelen // The attributes in the SESSION_ATTRIBUTES structure track the various properties 264*5c591343SA. Cody Schuffelen // of the session. It maintains most of the tracking state information for the 265*5c591343SA. Cody Schuffelen // policy session. It is used within the SESSION structure. 266*5c591343SA. Cody Schuffelen 267*5c591343SA. Cody Schuffelen typedef struct SESSION_ATTRIBUTES 268*5c591343SA. Cody Schuffelen { 269*5c591343SA. Cody Schuffelen unsigned isPolicy : 1; //1) SET if the session may only be used 270*5c591343SA. Cody Schuffelen // for policy 271*5c591343SA. Cody Schuffelen unsigned isAudit : 1; //2) SET if the session is used for audit 272*5c591343SA. Cody Schuffelen unsigned isBound : 1; //3) SET if the session is bound to with an 273*5c591343SA. Cody Schuffelen // entity. This attribute will be CLEAR 274*5c591343SA. Cody Schuffelen // if either isPolicy or isAudit is SET. 275*5c591343SA. Cody Schuffelen unsigned isCpHashDefined : 1; //4) SET if the cpHash has been defined 276*5c591343SA. Cody Schuffelen // This attribute is not SET unless 277*5c591343SA. Cody Schuffelen // 'isPolicy' is SET. 278*5c591343SA. Cody Schuffelen unsigned isAuthValueNeeded : 1; //5) SET if the authValue is required for 279*5c591343SA. Cody Schuffelen // computing the session HMAC. This 280*5c591343SA. Cody Schuffelen // attribute is not SET unless 'isPolicy' 281*5c591343SA. Cody Schuffelen // is SET. 282*5c591343SA. Cody Schuffelen unsigned isPasswordNeeded : 1; //6) SET if a password authValue is required 283*5c591343SA. Cody Schuffelen // for authorization This attribute is not 284*5c591343SA. Cody Schuffelen // SET unless 'isPolicy' is SET. 285*5c591343SA. Cody Schuffelen unsigned isPPRequired : 1; //7) SET if physical presence is required to 286*5c591343SA. Cody Schuffelen // be asserted when the authorization is 287*5c591343SA. Cody Schuffelen // checked. This attribute is not SET 288*5c591343SA. Cody Schuffelen // unless 'isPolicy' is SET. 289*5c591343SA. Cody Schuffelen unsigned isTrialPolicy : 1; //8) SET if the policy session is created 290*5c591343SA. Cody Schuffelen // for trial of the policy's policyHash 291*5c591343SA. Cody Schuffelen // generation. This attribute is not SET 292*5c591343SA. Cody Schuffelen // unless 'isPolicy' is SET. 293*5c591343SA. Cody Schuffelen unsigned isDaBound : 1; //9) SET if the bind entity had noDA CLEAR. 294*5c591343SA. Cody Schuffelen // If this is SET, then an authorization 295*5c591343SA. Cody Schuffelen // failure using this session will count 296*5c591343SA. Cody Schuffelen // against lockout even if the object 297*5c591343SA. Cody Schuffelen // being authorized is exempt from DA. 298*5c591343SA. Cody Schuffelen unsigned isLockoutBound : 1; //10) SET if the session is bound to 299*5c591343SA. Cody Schuffelen // lockoutAuth. 300*5c591343SA. Cody Schuffelen unsigned includeAuth : 1; //11) This attribute is SET when the 301*5c591343SA. Cody Schuffelen // authValue of an object is to be 302*5c591343SA. Cody Schuffelen // included in the computation of the 303*5c591343SA. Cody Schuffelen // HMAC key for the command and response 304*5c591343SA. Cody Schuffelen // computations. (was 'requestWasBound') 305*5c591343SA. Cody Schuffelen unsigned checkNvWritten : 1; //12) SET if the TPMA_NV_WRITTEN attribute 306*5c591343SA. Cody Schuffelen // needs to be checked when the policy is 307*5c591343SA. Cody Schuffelen // used for authorization for NV access. 308*5c591343SA. Cody Schuffelen // If this is SET for any other type, the 309*5c591343SA. Cody Schuffelen // policy will fail. 310*5c591343SA. Cody Schuffelen unsigned nvWrittenState : 1; //13) SET if TPMA_NV_WRITTEN is required to 311*5c591343SA. Cody Schuffelen // be SET. Used when 'checkNvWritten' is 312*5c591343SA. Cody Schuffelen // SET 313*5c591343SA. Cody Schuffelen unsigned isTemplateSet : 1; //14) SET if the templateHash needs to be 314*5c591343SA. Cody Schuffelen // checked for Create, CreatePrimary, or 315*5c591343SA. Cody Schuffelen // CreateLoaded. 316*5c591343SA. Cody Schuffelen } SESSION_ATTRIBUTES; 317*5c591343SA. Cody Schuffelen 318*5c591343SA. Cody Schuffelen //*** SESSION Structure 319*5c591343SA. Cody Schuffelen // The SESSION structure contains all the context of a session except for the 320*5c591343SA. Cody Schuffelen // associated contextID. 321*5c591343SA. Cody Schuffelen // 322*5c591343SA. Cody Schuffelen // Note: The contextID of a session is only relevant when the session context 323*5c591343SA. Cody Schuffelen // is stored off the TPM. 324*5c591343SA. Cody Schuffelen 325*5c591343SA. Cody Schuffelen typedef struct SESSION 326*5c591343SA. Cody Schuffelen { 327*5c591343SA. Cody Schuffelen SESSION_ATTRIBUTES attributes; // session attributes 328*5c591343SA. Cody Schuffelen UINT32 pcrCounter; // PCR counter value when PCR is 329*5c591343SA. Cody Schuffelen // included (policy session) 330*5c591343SA. Cody Schuffelen // If no PCR is included, this 331*5c591343SA. Cody Schuffelen // value is 0. 332*5c591343SA. Cody Schuffelen UINT64 startTime; // The value in g_time when the session 333*5c591343SA. Cody Schuffelen // was started (policy session) 334*5c591343SA. Cody Schuffelen UINT64 timeout; // The timeout relative to g_time 335*5c591343SA. Cody Schuffelen // There is no timeout if this value 336*5c591343SA. Cody Schuffelen // is 0. 337*5c591343SA. Cody Schuffelen CLOCK_NONCE epoch; // The g_clockEpoch value when the 338*5c591343SA. Cody Schuffelen // session was started. If g_clockEpoch 339*5c591343SA. Cody Schuffelen // does not match this value when the 340*5c591343SA. Cody Schuffelen // timeout is used, then 341*5c591343SA. Cody Schuffelen // then the command will fail. 342*5c591343SA. Cody Schuffelen TPM_CC commandCode; // command code (policy session) 343*5c591343SA. Cody Schuffelen TPM_ALG_ID authHashAlg; // session hash algorithm 344*5c591343SA. Cody Schuffelen TPMA_LOCALITY commandLocality; // command locality (policy session) 345*5c591343SA. Cody Schuffelen TPMT_SYM_DEF symmetric; // session symmetric algorithm (if any) 346*5c591343SA. Cody Schuffelen TPM2B_AUTH sessionKey; // session secret value used for 347*5c591343SA. Cody Schuffelen // this session 348*5c591343SA. Cody Schuffelen TPM2B_NONCE nonceTPM; // last TPM-generated nonce for 349*5c591343SA. Cody Schuffelen // generating HMAC and encryption keys 350*5c591343SA. Cody Schuffelen union 351*5c591343SA. Cody Schuffelen { 352*5c591343SA. Cody Schuffelen TPM2B_NAME boundEntity; // value used to track the entity to 353*5c591343SA. Cody Schuffelen // which the session is bound 354*5c591343SA. Cody Schuffelen 355*5c591343SA. Cody Schuffelen TPM2B_DIGEST cpHash; // the required cpHash value for the 356*5c591343SA. Cody Schuffelen // command being authorized 357*5c591343SA. Cody Schuffelen TPM2B_DIGEST nameHash; // the required nameHash 358*5c591343SA. Cody Schuffelen TPM2B_DIGEST templateHash; // the required template for creation 359*5c591343SA. Cody Schuffelen } u1; 360*5c591343SA. Cody Schuffelen 361*5c591343SA. Cody Schuffelen union 362*5c591343SA. Cody Schuffelen { 363*5c591343SA. Cody Schuffelen TPM2B_DIGEST auditDigest; // audit session digest 364*5c591343SA. Cody Schuffelen TPM2B_DIGEST policyDigest; // policyHash 365*5c591343SA. Cody Schuffelen } u2; // audit log and policyHash may 366*5c591343SA. Cody Schuffelen // share space to save memory 367*5c591343SA. Cody Schuffelen } SESSION; 368*5c591343SA. Cody Schuffelen 369*5c591343SA. Cody Schuffelen #define EXPIRES_ON_RESET INT32_MIN 370*5c591343SA. Cody Schuffelen #define TIMEOUT_ON_RESET UINT64_MAX 371*5c591343SA. Cody Schuffelen #define EXPIRES_ON_RESTART (INT32_MIN + 1) 372*5c591343SA. Cody Schuffelen #define TIMEOUT_ON_RESTART (UINT64_MAX - 1) 373*5c591343SA. Cody Schuffelen 374*5c591343SA. Cody Schuffelen typedef BYTE SESSION_BUF[sizeof(SESSION)]; 375*5c591343SA. Cody Schuffelen 376*5c591343SA. Cody Schuffelen //********************************************************************************* 377*5c591343SA. Cody Schuffelen //** PCR 378*5c591343SA. Cody Schuffelen //********************************************************************************* 379*5c591343SA. Cody Schuffelen //***PCR_SAVE Structure 380*5c591343SA. Cody Schuffelen // The PCR_SAVE structure type contains the PCR data that are saved across power 381*5c591343SA. Cody Schuffelen // cycles. Only the static PCR are required to be saved across power cycles. The 382*5c591343SA. Cody Schuffelen // DRTM and resettable PCR are not saved. The number of static and resettable PCR 383*5c591343SA. Cody Schuffelen // is determined by the platform-specific specification to which the TPM is built. 384*5c591343SA. Cody Schuffelen 385*5c591343SA. Cody Schuffelen #define PCR_SAVE_SPACE(HASH, Hash) BYTE Hash[NUM_STATIC_PCR][HASH##_DIGEST_SIZE]; 386*5c591343SA. Cody Schuffelen 387*5c591343SA. Cody Schuffelen typedef struct PCR_SAVE 388*5c591343SA. Cody Schuffelen { 389*5c591343SA. Cody Schuffelen FOR_EACH_HASH(PCR_SAVE_SPACE) 390*5c591343SA. Cody Schuffelen 391*5c591343SA. Cody Schuffelen // This counter increments whenever the PCR are updated. 392*5c591343SA. Cody Schuffelen // NOTE: A platform-specific specification may designate 393*5c591343SA. Cody Schuffelen // certain PCR changes as not causing this counter 394*5c591343SA. Cody Schuffelen // to increment. 395*5c591343SA. Cody Schuffelen UINT32 pcrCounter; 396*5c591343SA. Cody Schuffelen } PCR_SAVE; 397*5c591343SA. Cody Schuffelen 398*5c591343SA. Cody Schuffelen //***PCR_POLICY 399*5c591343SA. Cody Schuffelen #if defined NUM_POLICY_PCR_GROUP && NUM_POLICY_PCR_GROUP > 0 400*5c591343SA. Cody Schuffelen // This structure holds the PCR policies, one for each group of PCR controlled 401*5c591343SA. Cody Schuffelen // by policy. 402*5c591343SA. Cody Schuffelen typedef struct PCR_POLICY 403*5c591343SA. Cody Schuffelen { 404*5c591343SA. Cody Schuffelen TPMI_ALG_HASH hashAlg[NUM_POLICY_PCR_GROUP]; 405*5c591343SA. Cody Schuffelen TPM2B_DIGEST a; 406*5c591343SA. Cody Schuffelen TPM2B_DIGEST policy[NUM_POLICY_PCR_GROUP]; 407*5c591343SA. Cody Schuffelen } PCR_POLICY; 408*5c591343SA. Cody Schuffelen #endif 409*5c591343SA. Cody Schuffelen 410*5c591343SA. Cody Schuffelen //***PCR_AUTHVALUE 411*5c591343SA. Cody Schuffelen // This structure holds the PCR policies, one for each group of PCR controlled 412*5c591343SA. Cody Schuffelen // by policy. 413*5c591343SA. Cody Schuffelen typedef struct PCR_AUTH_VALUE 414*5c591343SA. Cody Schuffelen { 415*5c591343SA. Cody Schuffelen TPM2B_DIGEST auth[NUM_AUTHVALUE_PCR_GROUP]; 416*5c591343SA. Cody Schuffelen } PCR_AUTHVALUE; 417*5c591343SA. Cody Schuffelen 418*5c591343SA. Cody Schuffelen 419*5c591343SA. Cody Schuffelen 420*5c591343SA. Cody Schuffelen //**STARTUP_TYPE 421*5c591343SA. Cody Schuffelen // This enumeration is the possible startup types. The type is determined 422*5c591343SA. Cody Schuffelen // by the combination of TPM2_ShutDown and TPM2_Startup. 423*5c591343SA. Cody Schuffelen typedef enum 424*5c591343SA. Cody Schuffelen { 425*5c591343SA. Cody Schuffelen SU_RESET, 426*5c591343SA. Cody Schuffelen SU_RESTART, 427*5c591343SA. Cody Schuffelen SU_RESUME 428*5c591343SA. Cody Schuffelen } STARTUP_TYPE; 429*5c591343SA. Cody Schuffelen 430*5c591343SA. Cody Schuffelen //**NV 431*5c591343SA. Cody Schuffelen 432*5c591343SA. Cody Schuffelen //***NV_INDEX 433*5c591343SA. Cody Schuffelen // The NV_INDEX structure defines the internal format for an NV index. 434*5c591343SA. Cody Schuffelen // The 'indexData' size varies according to the type of the index. 435*5c591343SA. Cody Schuffelen // In this implementation, all of the index is manipulated as a unit. 436*5c591343SA. Cody Schuffelen typedef struct NV_INDEX 437*5c591343SA. Cody Schuffelen { 438*5c591343SA. Cody Schuffelen TPMS_NV_PUBLIC publicArea; 439*5c591343SA. Cody Schuffelen TPM2B_AUTH authValue; 440*5c591343SA. Cody Schuffelen } NV_INDEX; 441*5c591343SA. Cody Schuffelen 442*5c591343SA. Cody Schuffelen //*** NV_REF 443*5c591343SA. Cody Schuffelen // An NV_REF is an opaque value returned by the NV subsystem. It is used to 444*5c591343SA. Cody Schuffelen // reference and NV Index in a relatively efficient way. Rather than having to 445*5c591343SA. Cody Schuffelen // continually search for an Index, its reference value may be used. In this 446*5c591343SA. Cody Schuffelen // implementation, an NV_REF is a byte pointer that points to the copy of the 447*5c591343SA. Cody Schuffelen // NV memory that is kept in RAM. 448*5c591343SA. Cody Schuffelen typedef UINT32 NV_REF; 449*5c591343SA. Cody Schuffelen 450*5c591343SA. Cody Schuffelen typedef BYTE *NV_RAM_REF; 451*5c591343SA. Cody Schuffelen //***NV_PIN 452*5c591343SA. Cody Schuffelen // This structure deals with the possible endianess differences between the 453*5c591343SA. Cody Schuffelen // canonical form of the TPMS_NV_PIN_COUNTER_PARAMETERS structure and the internal 454*5c591343SA. Cody Schuffelen // value. The structures allow the data in a PIN index to be read as an 8-octet 455*5c591343SA. Cody Schuffelen // value using NvReadUINT64Data(). That function will byte swap all the values on a 456*5c591343SA. Cody Schuffelen // little endian system. This will put the bytes with the 4-octet values in the 457*5c591343SA. Cody Schuffelen // correct order but will swap the pinLimit and pinCount values. When written, the 458*5c591343SA. Cody Schuffelen // PIN index is simply handled as a normal index with the octets in canonical order. 459*5c591343SA. Cody Schuffelen #if BIG_ENDIAN_TPM 460*5c591343SA. Cody Schuffelen typedef struct 461*5c591343SA. Cody Schuffelen { 462*5c591343SA. Cody Schuffelen UINT32 pinCount; 463*5c591343SA. Cody Schuffelen UINT32 pinLimit; 464*5c591343SA. Cody Schuffelen } PIN_DATA; 465*5c591343SA. Cody Schuffelen #else 466*5c591343SA. Cody Schuffelen typedef struct 467*5c591343SA. Cody Schuffelen { 468*5c591343SA. Cody Schuffelen UINT32 pinLimit; 469*5c591343SA. Cody Schuffelen UINT32 pinCount; 470*5c591343SA. Cody Schuffelen } PIN_DATA; 471*5c591343SA. Cody Schuffelen #endif 472*5c591343SA. Cody Schuffelen 473*5c591343SA. Cody Schuffelen typedef union 474*5c591343SA. Cody Schuffelen { 475*5c591343SA. Cody Schuffelen UINT64 intVal; 476*5c591343SA. Cody Schuffelen PIN_DATA pin; 477*5c591343SA. Cody Schuffelen } NV_PIN; 478*5c591343SA. Cody Schuffelen 479*5c591343SA. Cody Schuffelen //**COMMIT_INDEX_MASK 480*5c591343SA. Cody Schuffelen // This is the define for the mask value that is used when manipulating 481*5c591343SA. Cody Schuffelen // the bits in the commit bit array. The commit counter is a 64-bit 482*5c591343SA. Cody Schuffelen // value and the low order bits are used to index the commitArray. 483*5c591343SA. Cody Schuffelen // This mask value is applied to the commit counter to extract the 484*5c591343SA. Cody Schuffelen // bit number in the array. 485*5c591343SA. Cody Schuffelen #if ALG_ECC 486*5c591343SA. Cody Schuffelen 487*5c591343SA. Cody Schuffelen #define COMMIT_INDEX_MASK ((UINT16)((sizeof(gr.commitArray)*8)-1)) 488*5c591343SA. Cody Schuffelen 489*5c591343SA. Cody Schuffelen #endif 490*5c591343SA. Cody Schuffelen 491*5c591343SA. Cody Schuffelen //***************************************************************************** 492*5c591343SA. Cody Schuffelen //***************************************************************************** 493*5c591343SA. Cody Schuffelen //** RAM Global Values 494*5c591343SA. Cody Schuffelen //***************************************************************************** 495*5c591343SA. Cody Schuffelen //***************************************************************************** 496*5c591343SA. Cody Schuffelen //*** Description 497*5c591343SA. Cody Schuffelen // The values in this section are only extant in RAM or ROM as constant values. 498*5c591343SA. Cody Schuffelen 499*5c591343SA. Cody Schuffelen //*** Crypto Self-Test Values 500*5c591343SA. Cody Schuffelen EXTERN ALGORITHM_VECTOR g_implementedAlgorithms; 501*5c591343SA. Cody Schuffelen EXTERN ALGORITHM_VECTOR g_toTest; 502*5c591343SA. Cody Schuffelen 503*5c591343SA. Cody Schuffelen //*** g_rcIndex[] 504*5c591343SA. Cody Schuffelen // This array is used to contain the array of values that are added to a return 505*5c591343SA. Cody Schuffelen // code when it is a parameter-, handle-, or session-related error. 506*5c591343SA. Cody Schuffelen // This is an implementation choice and the same result can be achieved by using 507*5c591343SA. Cody Schuffelen // a macro. 508*5c591343SA. Cody Schuffelen #define g_rcIndexInitializer { TPM_RC_1, TPM_RC_2, TPM_RC_3, TPM_RC_4, \ 509*5c591343SA. Cody Schuffelen TPM_RC_5, TPM_RC_6, TPM_RC_7, TPM_RC_8, \ 510*5c591343SA. Cody Schuffelen TPM_RC_9, TPM_RC_A, TPM_RC_B, TPM_RC_C, \ 511*5c591343SA. Cody Schuffelen TPM_RC_D, TPM_RC_E, TPM_RC_F } 512*5c591343SA. Cody Schuffelen EXTERN const UINT16 g_rcIndex[15] INITIALIZER(g_rcIndexInitializer); 513*5c591343SA. Cody Schuffelen 514*5c591343SA. Cody Schuffelen //*** g_exclusiveAuditSession 515*5c591343SA. Cody Schuffelen // This location holds the session handle for the current exclusive audit 516*5c591343SA. Cody Schuffelen // session. If there is no exclusive audit session, the location is set to 517*5c591343SA. Cody Schuffelen // TPM_RH_UNASSIGNED. 518*5c591343SA. Cody Schuffelen EXTERN TPM_HANDLE g_exclusiveAuditSession; 519*5c591343SA. Cody Schuffelen 520*5c591343SA. Cody Schuffelen //*** g_time 521*5c591343SA. Cody Schuffelen // This is the value in which we keep the current command time. This is initialized 522*5c591343SA. Cody Schuffelen // at the start of each command. The time is the accumulated time since the last 523*5c591343SA. Cody Schuffelen // time that the TPM's timer was last powered up. Clock is the accumulated time 524*5c591343SA. Cody Schuffelen // since the last time that the TPM was cleared. g_time is in mS. 525*5c591343SA. Cody Schuffelen EXTERN UINT64 g_time; 526*5c591343SA. Cody Schuffelen 527*5c591343SA. Cody Schuffelen //*** g_timeEpoch 528*5c591343SA. Cody Schuffelen // This value contains the current clock Epoch. It changes when there is a clock 529*5c591343SA. Cody Schuffelen // discontinuity. It may be necessary to place this in NV should the timer be able 530*5c591343SA. Cody Schuffelen // to run across a power down of the TPM but not in all cases (e.g. dead battery). 531*5c591343SA. Cody Schuffelen // If the nonce is placed in NV, it should go in gp because it should be changing 532*5c591343SA. Cody Schuffelen // slowly. 533*5c591343SA. Cody Schuffelen #if CLOCK_STOPS 534*5c591343SA. Cody Schuffelen EXTERN CLOCK_NONCE g_timeEpoch; 535*5c591343SA. Cody Schuffelen #else 536*5c591343SA. Cody Schuffelen #define g_timeEpoch gp.timeEpoch 537*5c591343SA. Cody Schuffelen #endif 538*5c591343SA. Cody Schuffelen 539*5c591343SA. Cody Schuffelen //*** g_phEnable 540*5c591343SA. Cody Schuffelen // This is the platform hierarchy control and determines if the platform hierarchy 541*5c591343SA. Cody Schuffelen // is available. This value is SET on each TPM2_Startup(). The default value is 542*5c591343SA. Cody Schuffelen // SET. 543*5c591343SA. Cody Schuffelen EXTERN BOOL g_phEnable; 544*5c591343SA. Cody Schuffelen 545*5c591343SA. Cody Schuffelen //*** g_pcrReConfig 546*5c591343SA. Cody Schuffelen // This value is SET if a TPM2_PCR_Allocate command successfully executed since 547*5c591343SA. Cody Schuffelen // the last TPM2_Startup(). If so, then the next shutdown is required to be 548*5c591343SA. Cody Schuffelen // Shutdown(CLEAR). 549*5c591343SA. Cody Schuffelen EXTERN BOOL g_pcrReConfig; 550*5c591343SA. Cody Schuffelen 551*5c591343SA. Cody Schuffelen //*** g_DRTMHandle 552*5c591343SA. Cody Schuffelen // This location indicates the sequence object handle that holds the DRTM 553*5c591343SA. Cody Schuffelen // sequence data. When not used, it is set to TPM_RH_UNASSIGNED. A sequence 554*5c591343SA. Cody Schuffelen // DRTM sequence is started on either _TPM_Init or _TPM_Hash_Start. 555*5c591343SA. Cody Schuffelen EXTERN TPMI_DH_OBJECT g_DRTMHandle; 556*5c591343SA. Cody Schuffelen 557*5c591343SA. Cody Schuffelen //*** g_DrtmPreStartup 558*5c591343SA. Cody Schuffelen // This value indicates that an H-CRTM occurred after _TPM_Init but before 559*5c591343SA. Cody Schuffelen // TPM2_Startup(). The define for PRE_STARTUP_FLAG is used to add the 560*5c591343SA. Cody Schuffelen // g_DrtmPreStartup value to gp_orderlyState at shutdown. This hack is to avoid 561*5c591343SA. Cody Schuffelen // adding another NV variable. 562*5c591343SA. Cody Schuffelen EXTERN BOOL g_DrtmPreStartup; 563*5c591343SA. Cody Schuffelen 564*5c591343SA. Cody Schuffelen //*** g_StartupLocality3 565*5c591343SA. Cody Schuffelen // This value indicates that a TPM2_Startup() occurred at locality 3. Otherwise, it 566*5c591343SA. Cody Schuffelen // at locality 0. The define for STARTUP_LOCALITY_3 is to 567*5c591343SA. Cody Schuffelen // indicate that the startup was not at locality 0. This hack is to avoid 568*5c591343SA. Cody Schuffelen // adding another NV variable. 569*5c591343SA. Cody Schuffelen EXTERN BOOL g_StartupLocality3; 570*5c591343SA. Cody Schuffelen 571*5c591343SA. Cody Schuffelen //***TPM_SU_NONE 572*5c591343SA. Cody Schuffelen // Part 2 defines the two shutdown/startup types that may be used in 573*5c591343SA. Cody Schuffelen // TPM2_Shutdown() and TPM2_Starup(). This additional define is 574*5c591343SA. Cody Schuffelen // used by the TPM to indicate that no shutdown was received. 575*5c591343SA. Cody Schuffelen // NOTE: This is a reserved value. 576*5c591343SA. Cody Schuffelen #define SU_NONE_VALUE (0xFFFF) 577*5c591343SA. Cody Schuffelen #define TPM_SU_NONE (TPM_SU)(SU_NONE_VALUE) 578*5c591343SA. Cody Schuffelen 579*5c591343SA. Cody Schuffelen //*** TPM_SU_DA_USED 580*5c591343SA. Cody Schuffelen // As with TPM_SU_NONE, this value is added to allow indication that the shutdown 581*5c591343SA. Cody Schuffelen // was not orderly and that a DA=protected object was reference during the previous 582*5c591343SA. Cody Schuffelen // cycle. 583*5c591343SA. Cody Schuffelen #define SU_DA_USED_VALUE (SU_NONE_VALUE - 1) 584*5c591343SA. Cody Schuffelen #define TPM_SU_DA_USED (TPM_SU)(SU_DA_USED_VALUE) 585*5c591343SA. Cody Schuffelen 586*5c591343SA. Cody Schuffelen 587*5c591343SA. Cody Schuffelen 588*5c591343SA. Cody Schuffelen //*** Startup Flags 589*5c591343SA. Cody Schuffelen // These flags are included in gp.orderlyState. These are hacks and are being 590*5c591343SA. Cody Schuffelen // used to avoid having to change the layout of gp. The PRE_STARTUP_FLAG indicates 591*5c591343SA. Cody Schuffelen // that a _TPM_Hash_Start/_Data/_End sequence was received after _TPM_Init but 592*5c591343SA. Cody Schuffelen // before TPM2_StartUp(). STARTUP_LOCALITY_3 indicates that the last TPM2_Startup() 593*5c591343SA. Cody Schuffelen // was received at locality 3. These flags are only relevant if after a 594*5c591343SA. Cody Schuffelen // TPM2_Shutdown(STATE). 595*5c591343SA. Cody Schuffelen #define PRE_STARTUP_FLAG 0x8000 596*5c591343SA. Cody Schuffelen #define STARTUP_LOCALITY_3 0x4000 597*5c591343SA. Cody Schuffelen 598*5c591343SA. Cody Schuffelen #if USE_DA_USED 599*5c591343SA. Cody Schuffelen //*** g_daUsed 600*5c591343SA. Cody Schuffelen // This location indicates if a DA-protected value is accessed during a boot 601*5c591343SA. Cody Schuffelen // cycle. If none has, then there is no need to increment 'failedTries' on the 602*5c591343SA. Cody Schuffelen // next non-orderly startup. This bit is merged with gp.orderlyState when 603*5c591343SA. Cody Schuffelen // gp.orderly is set to SU_NONE_VALUE 604*5c591343SA. Cody Schuffelen EXTERN BOOL g_daUsed; 605*5c591343SA. Cody Schuffelen #endif 606*5c591343SA. Cody Schuffelen 607*5c591343SA. Cody Schuffelen //*** g_updateNV 608*5c591343SA. Cody Schuffelen // This flag indicates if NV should be updated at the end of a command. 609*5c591343SA. Cody Schuffelen // This flag is set to UT_NONE at the beginning of each command in ExecuteCommand(). 610*5c591343SA. Cody Schuffelen // This flag is checked in ExecuteCommand() after the detailed actions of a command 611*5c591343SA. Cody Schuffelen // complete. If the command execution was successful and this flag is not UT_NONE, 612*5c591343SA. Cody Schuffelen // any pending NV writes will be committed to NV. 613*5c591343SA. Cody Schuffelen // UT_ORDERLY causes any RAM data to be written to the orderly space for staging 614*5c591343SA. Cody Schuffelen // the write to NV. 615*5c591343SA. Cody Schuffelen typedef BYTE UPDATE_TYPE; 616*5c591343SA. Cody Schuffelen #define UT_NONE (UPDATE_TYPE)0 617*5c591343SA. Cody Schuffelen #define UT_NV (UPDATE_TYPE)1 618*5c591343SA. Cody Schuffelen #define UT_ORDERLY (UPDATE_TYPE)(UT_NV + 2) 619*5c591343SA. Cody Schuffelen EXTERN UPDATE_TYPE g_updateNV; 620*5c591343SA. Cody Schuffelen 621*5c591343SA. Cody Schuffelen //*** g_powerWasLost 622*5c591343SA. Cody Schuffelen // This flag is used to indicate if the power was lost. It is SET in _TPM__Init. 623*5c591343SA. Cody Schuffelen // This flag is cleared by TPM2_Startup() after all power-lost activities are 624*5c591343SA. Cody Schuffelen // completed. 625*5c591343SA. Cody Schuffelen // Note: When power is applied, this value can come up as anything. However, 626*5c591343SA. Cody Schuffelen // _plat__WasPowerLost() will provide the proper indication in that case. So, when 627*5c591343SA. Cody Schuffelen // power is actually lost, we get the correct answer. When power was not lost, but 628*5c591343SA. Cody Schuffelen // the power-lost processing has not been completed before the next _TPM_Init(), 629*5c591343SA. Cody Schuffelen // then the TPM still does the correct thing. 630*5c591343SA. Cody Schuffelen EXTERN BOOL g_powerWasLost; 631*5c591343SA. Cody Schuffelen 632*5c591343SA. Cody Schuffelen //*** g_clearOrderly 633*5c591343SA. Cody Schuffelen // This flag indicates if the execution of a command should cause the orderly 634*5c591343SA. Cody Schuffelen // state to be cleared. This flag is set to FALSE at the beginning of each 635*5c591343SA. Cody Schuffelen // command in ExecuteCommand() and is checked in ExecuteCommand() after the 636*5c591343SA. Cody Schuffelen // detailed actions of a command complete but before the check of 637*5c591343SA. Cody Schuffelen // 'g_updateNV'. If this flag is TRUE, and the orderly state is not 638*5c591343SA. Cody Schuffelen // SU_NONE_VALUE, then the orderly state in NV memory will be changed to 639*5c591343SA. Cody Schuffelen // SU_NONE_VALUE or SU_DA_USED_VALUE. 640*5c591343SA. Cody Schuffelen EXTERN BOOL g_clearOrderly; 641*5c591343SA. Cody Schuffelen 642*5c591343SA. Cody Schuffelen //*** g_prevOrderlyState 643*5c591343SA. Cody Schuffelen // This location indicates how the TPM was shut down before the most recent 644*5c591343SA. Cody Schuffelen // TPM2_Startup(). This value, along with the startup type, determines if 645*5c591343SA. Cody Schuffelen // the TPM should do a TPM Reset, TPM Restart, or TPM Resume. 646*5c591343SA. Cody Schuffelen EXTERN TPM_SU g_prevOrderlyState; 647*5c591343SA. Cody Schuffelen 648*5c591343SA. Cody Schuffelen //*** g_nvOk 649*5c591343SA. Cody Schuffelen // This value indicates if the NV integrity check was successful or not. If not and 650*5c591343SA. Cody Schuffelen // the failure was severe, then the TPM would have been put into failure mode after 651*5c591343SA. Cody Schuffelen // it had been re-manufactured. If the NV failure was in the area where the state-save 652*5c591343SA. Cody Schuffelen // data is kept, then this variable will have a value of FALSE indicating that 653*5c591343SA. Cody Schuffelen // a TPM2_Startup(CLEAR) is required. 654*5c591343SA. Cody Schuffelen EXTERN BOOL g_nvOk; 655*5c591343SA. Cody Schuffelen // NV availability is sampled as the start of each command and stored here 656*5c591343SA. Cody Schuffelen // so that its value remains consistent during the command execution 657*5c591343SA. Cody Schuffelen EXTERN TPM_RC g_NvStatus; 658*5c591343SA. Cody Schuffelen 659*5c591343SA. Cody Schuffelen //*** g_platformUnique 660*5c591343SA. Cody Schuffelen // This location contains the unique value(s) used to identify the TPM. It is 661*5c591343SA. Cody Schuffelen // loaded on every _TPM2_Startup() 662*5c591343SA. Cody Schuffelen // The first value is used to seed the RNG. The second value is used as a vendor 663*5c591343SA. Cody Schuffelen // authValue. The value used by the RNG would be the value derived from the 664*5c591343SA. Cody Schuffelen // chip unique value (such as fused) with a dependency on the authorities of the 665*5c591343SA. Cody Schuffelen // code in the TPM boot path. The second would be derived from the chip unique value 666*5c591343SA. Cody Schuffelen // with a dependency on the details of the code in the boot path. That is, the 667*5c591343SA. Cody Schuffelen // first value depends on the various signers of the code and the second depends on 668*5c591343SA. Cody Schuffelen // what was signed. The TPM vendor should not be able to know the first value but 669*5c591343SA. Cody Schuffelen // they are expected to know the second. 670*5c591343SA. Cody Schuffelen EXTERN TPM2B_AUTH g_platformUniqueAuthorities; // Reserved for RNG 671*5c591343SA. Cody Schuffelen 672*5c591343SA. Cody Schuffelen EXTERN TPM2B_AUTH g_platformUniqueDetails; // referenced by VENDOR_PERMANENT 673*5c591343SA. Cody Schuffelen 674*5c591343SA. Cody Schuffelen //********************************************************************************* 675*5c591343SA. Cody Schuffelen //********************************************************************************* 676*5c591343SA. Cody Schuffelen //** Persistent Global Values 677*5c591343SA. Cody Schuffelen //********************************************************************************* 678*5c591343SA. Cody Schuffelen //********************************************************************************* 679*5c591343SA. Cody Schuffelen //*** Description 680*5c591343SA. Cody Schuffelen // The values in this section are global values that are persistent across power 681*5c591343SA. Cody Schuffelen // events. The lifetime of the values determines the structure in which the value 682*5c591343SA. Cody Schuffelen // is placed. 683*5c591343SA. Cody Schuffelen 684*5c591343SA. Cody Schuffelen //********************************************************************************* 685*5c591343SA. Cody Schuffelen //*** PERSISTENT_DATA 686*5c591343SA. Cody Schuffelen //********************************************************************************* 687*5c591343SA. Cody Schuffelen // This structure holds the persistent values that only change as a consequence 688*5c591343SA. Cody Schuffelen // of a specific Protected Capability and are not affected by TPM power events 689*5c591343SA. Cody Schuffelen // (TPM2_Startup() or TPM2_Shutdown(). 690*5c591343SA. Cody Schuffelen typedef struct 691*5c591343SA. Cody Schuffelen { 692*5c591343SA. Cody Schuffelen //********************************************************************************* 693*5c591343SA. Cody Schuffelen // Hierarchy 694*5c591343SA. Cody Schuffelen //********************************************************************************* 695*5c591343SA. Cody Schuffelen // The values in this section are related to the hierarchies. 696*5c591343SA. Cody Schuffelen 697*5c591343SA. Cody Schuffelen BOOL disableClear; // TRUE if TPM2_Clear() using 698*5c591343SA. Cody Schuffelen // lockoutAuth is disabled 699*5c591343SA. Cody Schuffelen 700*5c591343SA. Cody Schuffelen // Hierarchy authPolicies 701*5c591343SA. Cody Schuffelen TPMI_ALG_HASH ownerAlg; 702*5c591343SA. Cody Schuffelen TPMI_ALG_HASH endorsementAlg; 703*5c591343SA. Cody Schuffelen TPMI_ALG_HASH lockoutAlg; 704*5c591343SA. Cody Schuffelen TPM2B_DIGEST ownerPolicy; 705*5c591343SA. Cody Schuffelen TPM2B_DIGEST endorsementPolicy; 706*5c591343SA. Cody Schuffelen TPM2B_DIGEST lockoutPolicy; 707*5c591343SA. Cody Schuffelen 708*5c591343SA. Cody Schuffelen // Hierarchy authValues 709*5c591343SA. Cody Schuffelen TPM2B_AUTH ownerAuth; 710*5c591343SA. Cody Schuffelen TPM2B_AUTH endorsementAuth; 711*5c591343SA. Cody Schuffelen TPM2B_AUTH lockoutAuth; 712*5c591343SA. Cody Schuffelen 713*5c591343SA. Cody Schuffelen // Primary Seeds 714*5c591343SA. Cody Schuffelen TPM2B_SEED EPSeed; 715*5c591343SA. Cody Schuffelen TPM2B_SEED SPSeed; 716*5c591343SA. Cody Schuffelen TPM2B_SEED PPSeed; 717*5c591343SA. Cody Schuffelen // Note there is a nullSeed in the state_reset memory. 718*5c591343SA. Cody Schuffelen 719*5c591343SA. Cody Schuffelen // Hierarchy proofs 720*5c591343SA. Cody Schuffelen TPM2B_PROOF phProof; 721*5c591343SA. Cody Schuffelen TPM2B_PROOF shProof; 722*5c591343SA. Cody Schuffelen TPM2B_PROOF ehProof; 723*5c591343SA. Cody Schuffelen // Note there is a nullProof in the state_reset memory. 724*5c591343SA. Cody Schuffelen 725*5c591343SA. Cody Schuffelen //********************************************************************************* 726*5c591343SA. Cody Schuffelen // Reset Events 727*5c591343SA. Cody Schuffelen //********************************************************************************* 728*5c591343SA. Cody Schuffelen // A count that increments at each TPM reset and never get reset during the life 729*5c591343SA. Cody Schuffelen // time of TPM. The value of this counter is initialized to 1 during TPM 730*5c591343SA. Cody Schuffelen // manufacture process. It is used to invalidate all saved contexts after a TPM 731*5c591343SA. Cody Schuffelen // Reset. 732*5c591343SA. Cody Schuffelen UINT64 totalResetCount; 733*5c591343SA. Cody Schuffelen 734*5c591343SA. Cody Schuffelen // This counter increments on each TPM Reset. The counter is reset by 735*5c591343SA. Cody Schuffelen // TPM2_Clear(). 736*5c591343SA. Cody Schuffelen UINT32 resetCount; 737*5c591343SA. Cody Schuffelen 738*5c591343SA. Cody Schuffelen //********************************************************************************* 739*5c591343SA. Cody Schuffelen // PCR 740*5c591343SA. Cody Schuffelen //********************************************************************************* 741*5c591343SA. Cody Schuffelen // This structure hold the policies for those PCR that have an update policy. 742*5c591343SA. Cody Schuffelen // This implementation only supports a single group of PCR controlled by 743*5c591343SA. Cody Schuffelen // policy. If more are required, then this structure would be changed to 744*5c591343SA. Cody Schuffelen // an array. 745*5c591343SA. Cody Schuffelen #if defined NUM_POLICY_PCR_GROUP && NUM_POLICY_PCR_GROUP > 0 746*5c591343SA. Cody Schuffelen PCR_POLICY pcrPolicies; 747*5c591343SA. Cody Schuffelen #endif 748*5c591343SA. Cody Schuffelen 749*5c591343SA. Cody Schuffelen // This structure indicates the allocation of PCR. The structure contains a 750*5c591343SA. Cody Schuffelen // list of PCR allocations for each implemented algorithm. If no PCR are 751*5c591343SA. Cody Schuffelen // allocated for an algorithm, a list entry still exists but the bit map 752*5c591343SA. Cody Schuffelen // will contain no SET bits. 753*5c591343SA. Cody Schuffelen TPML_PCR_SELECTION pcrAllocated; 754*5c591343SA. Cody Schuffelen 755*5c591343SA. Cody Schuffelen //********************************************************************************* 756*5c591343SA. Cody Schuffelen // Physical Presence 757*5c591343SA. Cody Schuffelen //********************************************************************************* 758*5c591343SA. Cody Schuffelen // The PP_LIST type contains a bit map of the commands that require physical 759*5c591343SA. Cody Schuffelen // to be asserted when the authorization is evaluated. Physical presence will be 760*5c591343SA. Cody Schuffelen // checked if the corresponding bit in the array is SET and if the authorization 761*5c591343SA. Cody Schuffelen // handle is TPM_RH_PLATFORM. 762*5c591343SA. Cody Schuffelen // 763*5c591343SA. Cody Schuffelen // These bits may be changed with TPM2_PP_Commands(). 764*5c591343SA. Cody Schuffelen BYTE ppList[(COMMAND_COUNT + 7) / 8]; 765*5c591343SA. Cody Schuffelen 766*5c591343SA. Cody Schuffelen //********************************************************************************* 767*5c591343SA. Cody Schuffelen // Dictionary attack values 768*5c591343SA. Cody Schuffelen //********************************************************************************* 769*5c591343SA. Cody Schuffelen // These values are used for dictionary attack tracking and control. 770*5c591343SA. Cody Schuffelen UINT32 failedTries; // the current count of unexpired 771*5c591343SA. Cody Schuffelen // authorization failures 772*5c591343SA. Cody Schuffelen 773*5c591343SA. Cody Schuffelen UINT32 maxTries; // number of unexpired authorization 774*5c591343SA. Cody Schuffelen // failures before the TPM is in 775*5c591343SA. Cody Schuffelen // lockout 776*5c591343SA. Cody Schuffelen 777*5c591343SA. Cody Schuffelen UINT32 recoveryTime; // time between authorization failures 778*5c591343SA. Cody Schuffelen // before failedTries is decremented 779*5c591343SA. Cody Schuffelen 780*5c591343SA. Cody Schuffelen UINT32 lockoutRecovery; // time that must expire between 781*5c591343SA. Cody Schuffelen // authorization failures associated 782*5c591343SA. Cody Schuffelen // with lockoutAuth 783*5c591343SA. Cody Schuffelen 784*5c591343SA. Cody Schuffelen BOOL lockOutAuthEnabled; // TRUE if use of lockoutAuth is 785*5c591343SA. Cody Schuffelen // allowed 786*5c591343SA. Cody Schuffelen 787*5c591343SA. Cody Schuffelen //***************************************************************************** 788*5c591343SA. Cody Schuffelen // Orderly State 789*5c591343SA. Cody Schuffelen //***************************************************************************** 790*5c591343SA. Cody Schuffelen // The orderly state for current cycle 791*5c591343SA. Cody Schuffelen TPM_SU orderlyState; 792*5c591343SA. Cody Schuffelen 793*5c591343SA. Cody Schuffelen //***************************************************************************** 794*5c591343SA. Cody Schuffelen // Command audit values. 795*5c591343SA. Cody Schuffelen //***************************************************************************** 796*5c591343SA. Cody Schuffelen BYTE auditCommands[((COMMAND_COUNT + 1) + 7) / 8]; 797*5c591343SA. Cody Schuffelen TPMI_ALG_HASH auditHashAlg; 798*5c591343SA. Cody Schuffelen UINT64 auditCounter; 799*5c591343SA. Cody Schuffelen 800*5c591343SA. Cody Schuffelen //***************************************************************************** 801*5c591343SA. Cody Schuffelen // Algorithm selection 802*5c591343SA. Cody Schuffelen //***************************************************************************** 803*5c591343SA. Cody Schuffelen // 804*5c591343SA. Cody Schuffelen // The 'algorithmSet' value indicates the collection of algorithms that are 805*5c591343SA. Cody Schuffelen // currently in used on the TPM. The interpretation of value is vendor dependent. 806*5c591343SA. Cody Schuffelen UINT32 algorithmSet; 807*5c591343SA. Cody Schuffelen 808*5c591343SA. Cody Schuffelen //***************************************************************************** 809*5c591343SA. Cody Schuffelen // Firmware version 810*5c591343SA. Cody Schuffelen //***************************************************************************** 811*5c591343SA. Cody Schuffelen // The firmwareV1 and firmwareV2 values are instanced in TimeStamp.c. This is 812*5c591343SA. Cody Schuffelen // a scheme used in development to allow determination of the linker build time 813*5c591343SA. Cody Schuffelen // of the TPM. An actual implementation would implement these values in a way that 814*5c591343SA. Cody Schuffelen // is consistent with vendor needs. The values are maintained in RAM for simplified 815*5c591343SA. Cody Schuffelen // access with a master version in NV. These values are modified in a 816*5c591343SA. Cody Schuffelen // vendor-specific way. 817*5c591343SA. Cody Schuffelen 818*5c591343SA. Cody Schuffelen // g_firmwareV1 contains the more significant 32-bits of the vendor version number. 819*5c591343SA. Cody Schuffelen // In the reference implementation, if this value is printed as a hex 820*5c591343SA. Cody Schuffelen // value, it will have the format of YYYYMMDD 821*5c591343SA. Cody Schuffelen UINT32 firmwareV1; 822*5c591343SA. Cody Schuffelen 823*5c591343SA. Cody Schuffelen // g_firmwareV1 contains the less significant 32-bits of the vendor version number. 824*5c591343SA. Cody Schuffelen // In the reference implementation, if this value is printed as a hex 825*5c591343SA. Cody Schuffelen // value, it will have the format of 00 HH MM SS 826*5c591343SA. Cody Schuffelen UINT32 firmwareV2; 827*5c591343SA. Cody Schuffelen //***************************************************************************** 828*5c591343SA. Cody Schuffelen // Timer Epoch 829*5c591343SA. Cody Schuffelen //***************************************************************************** 830*5c591343SA. Cody Schuffelen // timeEpoch contains a nonce that has a vendor=specific size (should not be 831*5c591343SA. Cody Schuffelen // less than 8 bytes. This nonce changes when the clock epoch changes. The clock 832*5c591343SA. Cody Schuffelen // epoch changes when there is a discontinuity in the timing of the TPM. 833*5c591343SA. Cody Schuffelen #if !CLOCK_STOPS 834*5c591343SA. Cody Schuffelen CLOCK_NONCE timeEpoch; 835*5c591343SA. Cody Schuffelen #endif 836*5c591343SA. Cody Schuffelen 837*5c591343SA. Cody Schuffelen } PERSISTENT_DATA; 838*5c591343SA. Cody Schuffelen 839*5c591343SA. Cody Schuffelen EXTERN PERSISTENT_DATA gp; 840*5c591343SA. Cody Schuffelen 841*5c591343SA. Cody Schuffelen //********************************************************************************* 842*5c591343SA. Cody Schuffelen //********************************************************************************* 843*5c591343SA. Cody Schuffelen //*** ORDERLY_DATA 844*5c591343SA. Cody Schuffelen //********************************************************************************* 845*5c591343SA. Cody Schuffelen //********************************************************************************* 846*5c591343SA. Cody Schuffelen // The data in this structure is saved to NV on each TPM2_Shutdown(). 847*5c591343SA. Cody Schuffelen typedef struct orderly_data 848*5c591343SA. Cody Schuffelen { 849*5c591343SA. Cody Schuffelen //***************************************************************************** 850*5c591343SA. Cody Schuffelen // TIME 851*5c591343SA. Cody Schuffelen //***************************************************************************** 852*5c591343SA. Cody Schuffelen 853*5c591343SA. Cody Schuffelen // Clock has two parts. One is the state save part and one is the NV part. The 854*5c591343SA. Cody Schuffelen // state save version is updated on each command. When the clock rolls over, the 855*5c591343SA. Cody Schuffelen // NV version is updated. When the TPM starts up, if the TPM was shutdown in and 856*5c591343SA. Cody Schuffelen // orderly way, then the sClock value is used to initialize the clock. If the 857*5c591343SA. Cody Schuffelen // TPM shutdown was not orderly, then the persistent value is used and the safe 858*5c591343SA. Cody Schuffelen // attribute is clear. 859*5c591343SA. Cody Schuffelen 860*5c591343SA. Cody Schuffelen UINT64 clock; // The orderly version of clock 861*5c591343SA. Cody Schuffelen TPMI_YES_NO clockSafe; // Indicates if the clock value is 862*5c591343SA. Cody Schuffelen // safe. 863*5c591343SA. Cody Schuffelen 864*5c591343SA. Cody Schuffelen // In many implementations, the quality of the entropy available is not that 865*5c591343SA. Cody Schuffelen // high. To compensate, the current value of the drbgState can be saved and 866*5c591343SA. Cody Schuffelen // restored on each power cycle. This prevents the internal state from reverting 867*5c591343SA. Cody Schuffelen // to the initial state on each power cycle and starting with a limited amount 868*5c591343SA. Cody Schuffelen // of entropy. By keeping the old state and adding entropy, the entropy will 869*5c591343SA. Cody Schuffelen // accumulate. 870*5c591343SA. Cody Schuffelen DRBG_STATE drbgState; 871*5c591343SA. Cody Schuffelen 872*5c591343SA. Cody Schuffelen // These values allow the accumulation of self-healing time across orderly shutdown 873*5c591343SA. Cody Schuffelen // of the TPM. 874*5c591343SA. Cody Schuffelen #if ACCUMULATE_SELF_HEAL_TIMER 875*5c591343SA. Cody Schuffelen UINT64 selfHealTimer; // current value of s_selfHealTimer 876*5c591343SA. Cody Schuffelen UINT64 lockoutTimer; // current value of s_lockoutTimer 877*5c591343SA. Cody Schuffelen UINT64 time; // current value of g_time at shutdown 878*5c591343SA. Cody Schuffelen #endif // ACCUMULATE_SELF_HEAL_TIMER 879*5c591343SA. Cody Schuffelen 880*5c591343SA. Cody Schuffelen // These are the ACT Timeout values. They are saved with the other timers 881*5c591343SA. Cody Schuffelen #define DefineActData(N) ACT_STATE ACT_##N; 882*5c591343SA. Cody Schuffelen FOR_EACH_ACT(DefineActData) 883*5c591343SA. Cody Schuffelen 884*5c591343SA. Cody Schuffelen // this is the 'signaled' attribute data for all the ACT. It is done this way so 885*5c591343SA. Cody Schuffelen // that they can be manipulated by ACT number rather than having to access a 886*5c591343SA. Cody Schuffelen // structure. 887*5c591343SA. Cody Schuffelen UINT16 signaledACT; 888*5c591343SA. Cody Schuffelen UINT16 preservedSignaled; 889*5c591343SA. Cody Schuffelen } ORDERLY_DATA; 890*5c591343SA. Cody Schuffelen 891*5c591343SA. Cody Schuffelen #if ACCUMULATE_SELF_HEAL_TIMER 892*5c591343SA. Cody Schuffelen #define s_selfHealTimer go.selfHealTimer 893*5c591343SA. Cody Schuffelen #define s_lockoutTimer go.lockoutTimer 894*5c591343SA. Cody Schuffelen #endif // ACCUMULATE_SELF_HEAL_TIMER 895*5c591343SA. Cody Schuffelen 896*5c591343SA. Cody Schuffelen # define drbgDefault go.drbgState 897*5c591343SA. Cody Schuffelen 898*5c591343SA. Cody Schuffelen EXTERN ORDERLY_DATA go; 899*5c591343SA. Cody Schuffelen 900*5c591343SA. Cody Schuffelen //********************************************************************************* 901*5c591343SA. Cody Schuffelen //********************************************************************************* 902*5c591343SA. Cody Schuffelen //*** STATE_CLEAR_DATA 903*5c591343SA. Cody Schuffelen //********************************************************************************* 904*5c591343SA. Cody Schuffelen //********************************************************************************* 905*5c591343SA. Cody Schuffelen // This structure contains the data that is saved on Shutdown(STATE) 906*5c591343SA. Cody Schuffelen // and restored on Startup(STATE). The values are set to their default 907*5c591343SA. Cody Schuffelen // settings on any Startup(Clear). In other words, the data is only persistent 908*5c591343SA. Cody Schuffelen // across TPM Resume. 909*5c591343SA. Cody Schuffelen // 910*5c591343SA. Cody Schuffelen // If the comments associated with a parameter indicate a default reset value, the 911*5c591343SA. Cody Schuffelen // value is applied on each Startup(CLEAR). 912*5c591343SA. Cody Schuffelen 913*5c591343SA. Cody Schuffelen typedef struct state_clear_data 914*5c591343SA. Cody Schuffelen { 915*5c591343SA. Cody Schuffelen //***************************************************************************** 916*5c591343SA. Cody Schuffelen // Hierarchy Control 917*5c591343SA. Cody Schuffelen //***************************************************************************** 918*5c591343SA. Cody Schuffelen BOOL shEnable; // default reset is SET 919*5c591343SA. Cody Schuffelen BOOL ehEnable; // default reset is SET 920*5c591343SA. Cody Schuffelen BOOL phEnableNV; // default reset is SET 921*5c591343SA. Cody Schuffelen TPMI_ALG_HASH platformAlg; // default reset is TPM_ALG_NULL 922*5c591343SA. Cody Schuffelen TPM2B_DIGEST platformPolicy; // default reset is an Empty Buffer 923*5c591343SA. Cody Schuffelen TPM2B_AUTH platformAuth; // default reset is an Empty Buffer 924*5c591343SA. Cody Schuffelen 925*5c591343SA. Cody Schuffelen //***************************************************************************** 926*5c591343SA. Cody Schuffelen // PCR 927*5c591343SA. Cody Schuffelen //***************************************************************************** 928*5c591343SA. Cody Schuffelen // The set of PCR to be saved on Shutdown(STATE) 929*5c591343SA. Cody Schuffelen PCR_SAVE pcrSave; // default reset is 0...0 930*5c591343SA. Cody Schuffelen 931*5c591343SA. Cody Schuffelen // This structure hold the authorization values for those PCR that have an 932*5c591343SA. Cody Schuffelen // update authorization. 933*5c591343SA. Cody Schuffelen // This implementation only supports a single group of PCR controlled by 934*5c591343SA. Cody Schuffelen // authorization. If more are required, then this structure would be changed to 935*5c591343SA. Cody Schuffelen // an array. 936*5c591343SA. Cody Schuffelen PCR_AUTHVALUE pcrAuthValues; 937*5c591343SA. Cody Schuffelen 938*5c591343SA. Cody Schuffelen //***************************************************************************** 939*5c591343SA. Cody Schuffelen // ACT 940*5c591343SA. Cody Schuffelen //***************************************************************************** 941*5c591343SA. Cody Schuffelen #define DefineActPolicySpace(N) TPMT_HA act_##N; 942*5c591343SA. Cody Schuffelen FOR_EACH_ACT(DefineActPolicySpace) 943*5c591343SA. Cody Schuffelen 944*5c591343SA. Cody Schuffelen } STATE_CLEAR_DATA; 945*5c591343SA. Cody Schuffelen 946*5c591343SA. Cody Schuffelen EXTERN STATE_CLEAR_DATA gc; 947*5c591343SA. Cody Schuffelen 948*5c591343SA. Cody Schuffelen //********************************************************************************* 949*5c591343SA. Cody Schuffelen //********************************************************************************* 950*5c591343SA. Cody Schuffelen //*** State Reset Data 951*5c591343SA. Cody Schuffelen //********************************************************************************* 952*5c591343SA. Cody Schuffelen //********************************************************************************* 953*5c591343SA. Cody Schuffelen // This structure contains data is that is saved on Shutdown(STATE) and restored on 954*5c591343SA. Cody Schuffelen // the subsequent Startup(ANY). That is, the data is preserved across TPM Resume 955*5c591343SA. Cody Schuffelen // and TPM Restart. 956*5c591343SA. Cody Schuffelen // 957*5c591343SA. Cody Schuffelen // If a default value is specified in the comments this value is applied on 958*5c591343SA. Cody Schuffelen // TPM Reset. 959*5c591343SA. Cody Schuffelen 960*5c591343SA. Cody Schuffelen typedef struct state_reset_data 961*5c591343SA. Cody Schuffelen { 962*5c591343SA. Cody Schuffelen //***************************************************************************** 963*5c591343SA. Cody Schuffelen // Hierarchy Control 964*5c591343SA. Cody Schuffelen //***************************************************************************** 965*5c591343SA. Cody Schuffelen TPM2B_PROOF nullProof; // The proof value associated with 966*5c591343SA. Cody Schuffelen // the TPM_RH_NULL hierarchy. The 967*5c591343SA. Cody Schuffelen // default reset value is from the RNG. 968*5c591343SA. Cody Schuffelen 969*5c591343SA. Cody Schuffelen TPM2B_SEED nullSeed; // The seed value for the TPM_RN_NULL 970*5c591343SA. Cody Schuffelen // hierarchy. The default reset value 971*5c591343SA. Cody Schuffelen // is from the RNG. 972*5c591343SA. Cody Schuffelen 973*5c591343SA. Cody Schuffelen //***************************************************************************** 974*5c591343SA. Cody Schuffelen // Context 975*5c591343SA. Cody Schuffelen //***************************************************************************** 976*5c591343SA. Cody Schuffelen // The 'clearCount' counter is incremented each time the TPM successfully executes 977*5c591343SA. Cody Schuffelen // a TPM Resume. The counter is included in each saved context that has 'stClear' 978*5c591343SA. Cody Schuffelen // SET (including descendants of keys that have 'stClear' SET). This prevents these 979*5c591343SA. Cody Schuffelen // objects from being loaded after a TPM Resume. 980*5c591343SA. Cody Schuffelen // If 'clearCount' is at its maximum value when the TPM receives a Shutdown(STATE), 981*5c591343SA. Cody Schuffelen // the TPM will return TPM_RC_RANGE and the TPM will only accept Shutdown(CLEAR). 982*5c591343SA. Cody Schuffelen UINT32 clearCount; // The default reset value is 0. 983*5c591343SA. Cody Schuffelen 984*5c591343SA. Cody Schuffelen UINT64 objectContextID; // This is the context ID for a saved 985*5c591343SA. Cody Schuffelen // object context. The default reset 986*5c591343SA. Cody Schuffelen // value is 0. 987*5c591343SA. Cody Schuffelen CONTEXT_SLOT contextArray[MAX_ACTIVE_SESSIONS]; // This array contains 988*5c591343SA. Cody Schuffelen // contains the values used to track 989*5c591343SA. Cody Schuffelen // the version numbers of saved 990*5c591343SA. Cody Schuffelen // contexts (see 991*5c591343SA. Cody Schuffelen // Session.c in for details). The 992*5c591343SA. Cody Schuffelen // default reset value is {0}. 993*5c591343SA. Cody Schuffelen 994*5c591343SA. Cody Schuffelen CONTEXT_COUNTER contextCounter; // This is the value from which the 995*5c591343SA. Cody Schuffelen // 'contextID' is derived. The 996*5c591343SA. Cody Schuffelen // default reset value is {0}. 997*5c591343SA. Cody Schuffelen 998*5c591343SA. Cody Schuffelen //***************************************************************************** 999*5c591343SA. Cody Schuffelen // Command Audit 1000*5c591343SA. Cody Schuffelen //***************************************************************************** 1001*5c591343SA. Cody Schuffelen // When an audited command completes, ExecuteCommand() checks the return 1002*5c591343SA. Cody Schuffelen // value. If it is TPM_RC_SUCCESS, and the command is an audited command, the 1003*5c591343SA. Cody Schuffelen // TPM will extend the cpHash and rpHash for the command to this value. If this 1004*5c591343SA. Cody Schuffelen // digest was the Zero Digest before the cpHash was extended, the audit counter 1005*5c591343SA. Cody Schuffelen // is incremented. 1006*5c591343SA. Cody Schuffelen 1007*5c591343SA. Cody Schuffelen TPM2B_DIGEST commandAuditDigest; // This value is set to an Empty Digest 1008*5c591343SA. Cody Schuffelen // by TPM2_GetCommandAuditDigest() or a 1009*5c591343SA. Cody Schuffelen // TPM Reset. 1010*5c591343SA. Cody Schuffelen 1011*5c591343SA. Cody Schuffelen //***************************************************************************** 1012*5c591343SA. Cody Schuffelen // Boot counter 1013*5c591343SA. Cody Schuffelen //***************************************************************************** 1014*5c591343SA. Cody Schuffelen 1015*5c591343SA. Cody Schuffelen UINT32 restartCount; // This counter counts TPM Restarts. 1016*5c591343SA. Cody Schuffelen // The default reset value is 0. 1017*5c591343SA. Cody Schuffelen 1018*5c591343SA. Cody Schuffelen //********************************************************************************* 1019*5c591343SA. Cody Schuffelen // PCR 1020*5c591343SA. Cody Schuffelen //********************************************************************************* 1021*5c591343SA. Cody Schuffelen // This counter increments whenever the PCR are updated. This counter is preserved 1022*5c591343SA. Cody Schuffelen // across TPM Resume even though the PCR are not preserved. This is because 1023*5c591343SA. Cody Schuffelen // sessions remain active across TPM Restart and the count value in the session 1024*5c591343SA. Cody Schuffelen // is compared to this counter so this counter must have values that are unique 1025*5c591343SA. Cody Schuffelen // as long as the sessions are active. 1026*5c591343SA. Cody Schuffelen // NOTE: A platform-specific specification may designate that certain PCR changes 1027*5c591343SA. Cody Schuffelen // do not increment this counter to increment. 1028*5c591343SA. Cody Schuffelen UINT32 pcrCounter; // The default reset value is 0. 1029*5c591343SA. Cody Schuffelen 1030*5c591343SA. Cody Schuffelen #if ALG_ECC 1031*5c591343SA. Cody Schuffelen 1032*5c591343SA. Cody Schuffelen //***************************************************************************** 1033*5c591343SA. Cody Schuffelen // ECDAA 1034*5c591343SA. Cody Schuffelen //***************************************************************************** 1035*5c591343SA. Cody Schuffelen UINT64 commitCounter; // This counter increments each time 1036*5c591343SA. Cody Schuffelen // TPM2_Commit() returns 1037*5c591343SA. Cody Schuffelen // TPM_RC_SUCCESS. The default reset 1038*5c591343SA. Cody Schuffelen // value is 0. 1039*5c591343SA. Cody Schuffelen 1040*5c591343SA. Cody Schuffelen TPM2B_NONCE commitNonce; // This random value is used to compute 1041*5c591343SA. Cody Schuffelen // the commit values. The default reset 1042*5c591343SA. Cody Schuffelen // value is from the RNG. 1043*5c591343SA. Cody Schuffelen 1044*5c591343SA. Cody Schuffelen // This implementation relies on the number of bits in g_commitArray being a 1045*5c591343SA. Cody Schuffelen // power of 2 (8, 16, 32, 64, etc.) and no greater than 64K. 1046*5c591343SA. Cody Schuffelen BYTE commitArray[16]; // The default reset value is {0}. 1047*5c591343SA. Cody Schuffelen 1048*5c591343SA. Cody Schuffelen #endif // ALG_ECC 1049*5c591343SA. Cody Schuffelen } STATE_RESET_DATA; 1050*5c591343SA. Cody Schuffelen 1051*5c591343SA. Cody Schuffelen EXTERN STATE_RESET_DATA gr; 1052*5c591343SA. Cody Schuffelen 1053*5c591343SA. Cody Schuffelen //** NV Layout 1054*5c591343SA. Cody Schuffelen // The NV data organization is 1055*5c591343SA. Cody Schuffelen // 1) a PERSISTENT_DATA structure 1056*5c591343SA. Cody Schuffelen // 2) a STATE_RESET_DATA structure 1057*5c591343SA. Cody Schuffelen // 3) a STATE_CLEAR_DATA structure 1058*5c591343SA. Cody Schuffelen // 4) an ORDERLY_DATA structure 1059*5c591343SA. Cody Schuffelen // 5) the user defined NV index space 1060*5c591343SA. Cody Schuffelen #define NV_PERSISTENT_DATA (0) 1061*5c591343SA. Cody Schuffelen #define NV_STATE_RESET_DATA (NV_PERSISTENT_DATA + sizeof(PERSISTENT_DATA)) 1062*5c591343SA. Cody Schuffelen #define NV_STATE_CLEAR_DATA (NV_STATE_RESET_DATA + sizeof(STATE_RESET_DATA)) 1063*5c591343SA. Cody Schuffelen #define NV_ORDERLY_DATA (NV_STATE_CLEAR_DATA + sizeof(STATE_CLEAR_DATA)) 1064*5c591343SA. Cody Schuffelen #define NV_INDEX_RAM_DATA (NV_ORDERLY_DATA + sizeof(ORDERLY_DATA)) 1065*5c591343SA. Cody Schuffelen #define NV_USER_DYNAMIC (NV_INDEX_RAM_DATA + sizeof(s_indexOrderlyRam)) 1066*5c591343SA. Cody Schuffelen #define NV_USER_DYNAMIC_END NV_MEMORY_SIZE 1067*5c591343SA. Cody Schuffelen 1068*5c591343SA. Cody Schuffelen //** Global Macro Definitions 1069*5c591343SA. Cody Schuffelen // The NV_READ_PERSISTENT and NV_WRITE_PERSISTENT macros are used to access members 1070*5c591343SA. Cody Schuffelen // of the PERSISTENT_DATA structure in NV. 1071*5c591343SA. Cody Schuffelen #define NV_READ_PERSISTENT(to, from) \ 1072*5c591343SA. Cody Schuffelen NvRead(&to, offsetof(PERSISTENT_DATA, from), sizeof(to)) 1073*5c591343SA. Cody Schuffelen 1074*5c591343SA. Cody Schuffelen #define NV_WRITE_PERSISTENT(to, from) \ 1075*5c591343SA. Cody Schuffelen NvWrite(offsetof(PERSISTENT_DATA, to), sizeof(gp.to), &from) 1076*5c591343SA. Cody Schuffelen 1077*5c591343SA. Cody Schuffelen #define CLEAR_PERSISTENT(item) \ 1078*5c591343SA. Cody Schuffelen NvClearPersistent(offsetof(PERSISTENT_DATA, item), sizeof(gp.item)) 1079*5c591343SA. Cody Schuffelen 1080*5c591343SA. Cody Schuffelen #define NV_SYNC_PERSISTENT(item) NV_WRITE_PERSISTENT(item, gp.item) 1081*5c591343SA. Cody Schuffelen 1082*5c591343SA. Cody Schuffelen // At the start of command processing, the index of the command is determined. This 1083*5c591343SA. Cody Schuffelen // index value is used to access the various data tables that contain per-command 1084*5c591343SA. Cody Schuffelen // information. There are multiple options for how the per-command tables can be 1085*5c591343SA. Cody Schuffelen // implemented. This is resolved in GetClosestCommandIndex(). 1086*5c591343SA. Cody Schuffelen typedef UINT16 COMMAND_INDEX; 1087*5c591343SA. Cody Schuffelen #define UNIMPLEMENTED_COMMAND_INDEX ((COMMAND_INDEX)(~0)) 1088*5c591343SA. Cody Schuffelen 1089*5c591343SA. Cody Schuffelen typedef struct _COMMAND_FLAGS_ 1090*5c591343SA. Cody Schuffelen { 1091*5c591343SA. Cody Schuffelen unsigned trialPolicy : 1; //1) If SET, one of the handles references a 1092*5c591343SA. Cody Schuffelen // trial policy and authorization may be 1093*5c591343SA. Cody Schuffelen // skipped. This is only allowed for a policy 1094*5c591343SA. Cody Schuffelen // command. 1095*5c591343SA. Cody Schuffelen } COMMAND_FLAGS; 1096*5c591343SA. Cody Schuffelen 1097*5c591343SA. Cody Schuffelen // This structure is used to avoid having to manage a large number of 1098*5c591343SA. Cody Schuffelen // parameters being passed through various levels of the command input processing. 1099*5c591343SA. Cody Schuffelen // 1100*5c591343SA. Cody Schuffelen 1101*5c591343SA. Cody Schuffelen // The following macros are used to define the space for the CP and RP hashes. Space, 1102*5c591343SA. Cody Schuffelen // is provided for each implemented hash algorithm because it is not known what the 1103*5c591343SA. Cody Schuffelen // caller may use. 1104*5c591343SA. Cody Schuffelen #define CP_HASH(HASH, Hash) TPM2B_##HASH##_DIGEST Hash##CpHash; 1105*5c591343SA. Cody Schuffelen #define RP_HASH(HASH, Hash) TPM2B_##HASH##_DIGEST Hash##RpHash; 1106*5c591343SA. Cody Schuffelen 1107*5c591343SA. Cody Schuffelen typedef struct COMMAND 1108*5c591343SA. Cody Schuffelen { 1109*5c591343SA. Cody Schuffelen TPM_ST tag; // the parsed command tag 1110*5c591343SA. Cody Schuffelen TPM_CC code; // the parsed command code 1111*5c591343SA. Cody Schuffelen COMMAND_INDEX index; // the computed command index 1112*5c591343SA. Cody Schuffelen UINT32 handleNum; // the number of entity handles in the 1113*5c591343SA. Cody Schuffelen // handle area of the command 1114*5c591343SA. Cody Schuffelen TPM_HANDLE handles[MAX_HANDLE_NUM]; // the parsed handle values 1115*5c591343SA. Cody Schuffelen UINT32 sessionNum; // the number of sessions found 1116*5c591343SA. Cody Schuffelen INT32 parameterSize; // starts out with the parsed command size 1117*5c591343SA. Cody Schuffelen // and is reduced and values are 1118*5c591343SA. Cody Schuffelen // unmarshaled. Just before calling the 1119*5c591343SA. Cody Schuffelen // command actions, this should be zero. 1120*5c591343SA. Cody Schuffelen // After the command actions, this number 1121*5c591343SA. Cody Schuffelen // should grow as values are marshaled 1122*5c591343SA. Cody Schuffelen // in to the response buffer. 1123*5c591343SA. Cody Schuffelen INT32 authSize; // this is initialized with the parsed size 1124*5c591343SA. Cody Schuffelen // of authorizationSize field and should 1125*5c591343SA. Cody Schuffelen // be zero when the authorizations are 1126*5c591343SA. Cody Schuffelen // parsed. 1127*5c591343SA. Cody Schuffelen BYTE *parameterBuffer; // input to ExecuteCommand 1128*5c591343SA. Cody Schuffelen BYTE *responseBuffer; // input to ExecuteCommand 1129*5c591343SA. Cody Schuffelen FOR_EACH_HASH(CP_HASH) // space for the CP hashes 1130*5c591343SA. Cody Schuffelen FOR_EACH_HASH(RP_HASH) // space for the RP hashes 1131*5c591343SA. Cody Schuffelen } COMMAND; 1132*5c591343SA. Cody Schuffelen 1133*5c591343SA. Cody Schuffelen // Global string constants for consistency in KDF function calls. 1134*5c591343SA. Cody Schuffelen // These string constants are shared across functions to make sure that they 1135*5c591343SA. Cody Schuffelen // are all using consistent string values. 1136*5c591343SA. Cody Schuffelen 1137*5c591343SA. Cody Schuffelen #define STRING_INITIALIZER(value) {{sizeof(value), {value}}} 1138*5c591343SA. Cody Schuffelen #define TPM2B_STRING(name, value) \ 1139*5c591343SA. Cody Schuffelen typedef union name##_ { \ 1140*5c591343SA. Cody Schuffelen struct { \ 1141*5c591343SA. Cody Schuffelen UINT16 size; \ 1142*5c591343SA. Cody Schuffelen BYTE buffer[sizeof(value)]; \ 1143*5c591343SA. Cody Schuffelen } t; \ 1144*5c591343SA. Cody Schuffelen TPM2B b; \ 1145*5c591343SA. Cody Schuffelen } TPM2B_##name##_; \ 1146*5c591343SA. Cody Schuffelen EXTERN const TPM2B_##name##_ name##_ INITIALIZER(STRING_INITIALIZER(value)); \ 1147*5c591343SA. Cody Schuffelen EXTERN const TPM2B *name INITIALIZER(&name##_.b) 1148*5c591343SA. Cody Schuffelen 1149*5c591343SA. Cody Schuffelen TPM2B_STRING(PRIMARY_OBJECT_CREATION, "Primary Object Creation"); 1150*5c591343SA. Cody Schuffelen TPM2B_STRING(CFB_KEY, "CFB"); 1151*5c591343SA. Cody Schuffelen TPM2B_STRING(CONTEXT_KEY, "CONTEXT"); 1152*5c591343SA. Cody Schuffelen TPM2B_STRING(INTEGRITY_KEY, "INTEGRITY"); 1153*5c591343SA. Cody Schuffelen TPM2B_STRING(SECRET_KEY, "SECRET"); 1154*5c591343SA. Cody Schuffelen TPM2B_STRING(SESSION_KEY, "ATH"); 1155*5c591343SA. Cody Schuffelen TPM2B_STRING(STORAGE_KEY, "STORAGE"); 1156*5c591343SA. Cody Schuffelen TPM2B_STRING(XOR_KEY, "XOR"); 1157*5c591343SA. Cody Schuffelen TPM2B_STRING(COMMIT_STRING, "ECDAA Commit"); 1158*5c591343SA. Cody Schuffelen TPM2B_STRING(DUPLICATE_STRING, "DUPLICATE"); 1159*5c591343SA. Cody Schuffelen TPM2B_STRING(IDENTITY_STRING, "IDENTITY"); 1160*5c591343SA. Cody Schuffelen TPM2B_STRING(OBFUSCATE_STRING, "OBFUSCATE"); 1161*5c591343SA. Cody Schuffelen #if SELF_TEST 1162*5c591343SA. Cody Schuffelen TPM2B_STRING(OAEP_TEST_STRING, "OAEP Test Value"); 1163*5c591343SA. Cody Schuffelen #endif // SELF_TEST 1164*5c591343SA. Cody Schuffelen 1165*5c591343SA. Cody Schuffelen //***************************************************************************** 1166*5c591343SA. Cody Schuffelen //** From CryptTest.c 1167*5c591343SA. Cody Schuffelen //***************************************************************************** 1168*5c591343SA. Cody Schuffelen // This structure contains the self-test state values for the cryptographic modules. 1169*5c591343SA. Cody Schuffelen EXTERN CRYPTO_SELF_TEST_STATE g_cryptoSelfTestState; 1170*5c591343SA. Cody Schuffelen 1171*5c591343SA. Cody Schuffelen //***************************************************************************** 1172*5c591343SA. Cody Schuffelen //** From Manufacture.c 1173*5c591343SA. Cody Schuffelen //***************************************************************************** 1174*5c591343SA. Cody Schuffelen EXTERN BOOL g_manufactured INITIALIZER(FALSE); 1175*5c591343SA. Cody Schuffelen 1176*5c591343SA. Cody Schuffelen // This value indicates if a TPM2_Startup commands has been 1177*5c591343SA. Cody Schuffelen // receive since the power on event. This flag is maintained in power 1178*5c591343SA. Cody Schuffelen // simulation module because this is the only place that may reliably set this 1179*5c591343SA. Cody Schuffelen // flag to FALSE. 1180*5c591343SA. Cody Schuffelen EXTERN BOOL g_initialized; 1181*5c591343SA. Cody Schuffelen 1182*5c591343SA. Cody Schuffelen //** Private data 1183*5c591343SA. Cody Schuffelen 1184*5c591343SA. Cody Schuffelen //***************************************************************************** 1185*5c591343SA. Cody Schuffelen //*** From SessionProcess.c 1186*5c591343SA. Cody Schuffelen //***************************************************************************** 1187*5c591343SA. Cody Schuffelen #if defined SESSION_PROCESS_C || defined GLOBAL_C || defined MANUFACTURE_C 1188*5c591343SA. Cody Schuffelen // The following arrays are used to save command sessions information so that the 1189*5c591343SA. Cody Schuffelen // command handle/session buffer does not have to be preserved for the duration of 1190*5c591343SA. Cody Schuffelen // the command. These arrays are indexed by the session index in accordance with 1191*5c591343SA. Cody Schuffelen // the order of sessions in the session area of the command. 1192*5c591343SA. Cody Schuffelen // 1193*5c591343SA. Cody Schuffelen // Array of the authorization session handles 1194*5c591343SA. Cody Schuffelen EXTERN TPM_HANDLE s_sessionHandles[MAX_SESSION_NUM]; 1195*5c591343SA. Cody Schuffelen 1196*5c591343SA. Cody Schuffelen // Array of authorization session attributes 1197*5c591343SA. Cody Schuffelen EXTERN TPMA_SESSION s_attributes[MAX_SESSION_NUM]; 1198*5c591343SA. Cody Schuffelen 1199*5c591343SA. Cody Schuffelen // Array of handles authorized by the corresponding authorization sessions; 1200*5c591343SA. Cody Schuffelen // and if none, then TPM_RH_UNASSIGNED value is used 1201*5c591343SA. Cody Schuffelen EXTERN TPM_HANDLE s_associatedHandles[MAX_SESSION_NUM]; 1202*5c591343SA. Cody Schuffelen 1203*5c591343SA. Cody Schuffelen // Array of nonces provided by the caller for the corresponding sessions 1204*5c591343SA. Cody Schuffelen EXTERN TPM2B_NONCE s_nonceCaller[MAX_SESSION_NUM]; 1205*5c591343SA. Cody Schuffelen 1206*5c591343SA. Cody Schuffelen // Array of authorization values (HMAC's or passwords) for the corresponding 1207*5c591343SA. Cody Schuffelen // sessions 1208*5c591343SA. Cody Schuffelen EXTERN TPM2B_AUTH s_inputAuthValues[MAX_SESSION_NUM]; 1209*5c591343SA. Cody Schuffelen 1210*5c591343SA. Cody Schuffelen // Array of pointers to the SESSION structures for the sessions in a command 1211*5c591343SA. Cody Schuffelen EXTERN SESSION *s_usedSessions[MAX_SESSION_NUM]; 1212*5c591343SA. Cody Schuffelen 1213*5c591343SA. Cody Schuffelen // Special value to indicate an undefined session index 1214*5c591343SA. Cody Schuffelen #define UNDEFINED_INDEX (0xFFFF) 1215*5c591343SA. Cody Schuffelen 1216*5c591343SA. Cody Schuffelen // Index of the session used for encryption of a response parameter 1217*5c591343SA. Cody Schuffelen EXTERN UINT32 s_encryptSessionIndex; 1218*5c591343SA. Cody Schuffelen 1219*5c591343SA. Cody Schuffelen // Index of the session used for decryption of a command parameter 1220*5c591343SA. Cody Schuffelen EXTERN UINT32 s_decryptSessionIndex; 1221*5c591343SA. Cody Schuffelen 1222*5c591343SA. Cody Schuffelen // Index of a session used for audit 1223*5c591343SA. Cody Schuffelen EXTERN UINT32 s_auditSessionIndex; 1224*5c591343SA. Cody Schuffelen 1225*5c591343SA. Cody Schuffelen // The cpHash for command audit 1226*5c591343SA. Cody Schuffelen #ifdef TPM_CC_GetCommandAuditDigest 1227*5c591343SA. Cody Schuffelen EXTERN TPM2B_DIGEST s_cpHashForCommandAudit; 1228*5c591343SA. Cody Schuffelen #endif 1229*5c591343SA. Cody Schuffelen 1230*5c591343SA. Cody Schuffelen // Flag indicating if NV update is pending for the lockOutAuthEnabled or 1231*5c591343SA. Cody Schuffelen // failedTries DA parameter 1232*5c591343SA. Cody Schuffelen EXTERN BOOL s_DAPendingOnNV; 1233*5c591343SA. Cody Schuffelen 1234*5c591343SA. Cody Schuffelen #endif // SESSION_PROCESS_C 1235*5c591343SA. Cody Schuffelen 1236*5c591343SA. Cody Schuffelen //***************************************************************************** 1237*5c591343SA. Cody Schuffelen //*** From DA.c 1238*5c591343SA. Cody Schuffelen //***************************************************************************** 1239*5c591343SA. Cody Schuffelen #if defined DA_C || defined GLOBAL_C || defined MANUFACTURE_C 1240*5c591343SA. Cody Schuffelen // This variable holds the accumulated time since the last time 1241*5c591343SA. Cody Schuffelen // that 'failedTries' was decremented. This value is in millisecond. 1242*5c591343SA. Cody Schuffelen #if !ACCUMULATE_SELF_HEAL_TIMER 1243*5c591343SA. Cody Schuffelen EXTERN UINT64 s_selfHealTimer; 1244*5c591343SA. Cody Schuffelen 1245*5c591343SA. Cody Schuffelen // This variable holds the accumulated time that the lockoutAuth has been 1246*5c591343SA. Cody Schuffelen // blocked. 1247*5c591343SA. Cody Schuffelen EXTERN UINT64 s_lockoutTimer; 1248*5c591343SA. Cody Schuffelen #endif // ACCUMULATE_SELF_HEAL_TIMER 1249*5c591343SA. Cody Schuffelen 1250*5c591343SA. Cody Schuffelen #endif // DA_C 1251*5c591343SA. Cody Schuffelen 1252*5c591343SA. Cody Schuffelen //***************************************************************************** 1253*5c591343SA. Cody Schuffelen //*** From NV.c 1254*5c591343SA. Cody Schuffelen //***************************************************************************** 1255*5c591343SA. Cody Schuffelen #if defined NV_C || defined GLOBAL_C 1256*5c591343SA. Cody Schuffelen // This marks the end of the NV area. This is a run-time variable as it might 1257*5c591343SA. Cody Schuffelen // not be compile-time constant. 1258*5c591343SA. Cody Schuffelen EXTERN NV_REF s_evictNvEnd; 1259*5c591343SA. Cody Schuffelen 1260*5c591343SA. Cody Schuffelen // This space is used to hold the index data for an orderly Index. It also contains 1261*5c591343SA. Cody Schuffelen // the attributes for the index. 1262*5c591343SA. Cody Schuffelen EXTERN BYTE s_indexOrderlyRam[RAM_INDEX_SPACE]; // The orderly NV Index data 1263*5c591343SA. Cody Schuffelen 1264*5c591343SA. Cody Schuffelen // This value contains the current max counter value. It is written to the end of 1265*5c591343SA. Cody Schuffelen // allocatable NV space each time an index is deleted or added. This value is 1266*5c591343SA. Cody Schuffelen // initialized on Startup. The indices are searched and the maximum of all the 1267*5c591343SA. Cody Schuffelen // current counter indices and this value is the initial value for this. 1268*5c591343SA. Cody Schuffelen EXTERN UINT64 s_maxCounter; 1269*5c591343SA. Cody Schuffelen 1270*5c591343SA. Cody Schuffelen // This is space used for the NV Index cache. As with a persistent object, the 1271*5c591343SA. Cody Schuffelen // contents of a referenced index are copied into the cache so that the 1272*5c591343SA. Cody Schuffelen // NV Index memory scanning and data copying can be reduced. 1273*5c591343SA. Cody Schuffelen // Only code that operates on NV Index data should use this cache directly. When 1274*5c591343SA. Cody Schuffelen // that action code runs, s_lastNvIndex will contain the index header information. 1275*5c591343SA. Cody Schuffelen // It will have been loaded when the handles were verified. 1276*5c591343SA. Cody Schuffelen // NOTE: An NV index handle can appear in many commands that do not operate on the 1277*5c591343SA. Cody Schuffelen // NV data (e.g. TPM2_StartAuthSession). However, only one NV Index at a time is 1278*5c591343SA. Cody Schuffelen // ever directly referenced by any command. If that changes, then the NV Index 1279*5c591343SA. Cody Schuffelen // caching needs to be changed to accommodate that. Currently, the code will verify 1280*5c591343SA. Cody Schuffelen // that only one NV Index is referenced by the handles of the command. 1281*5c591343SA. Cody Schuffelen EXTERN NV_INDEX s_cachedNvIndex; 1282*5c591343SA. Cody Schuffelen EXTERN NV_REF s_cachedNvRef; 1283*5c591343SA. Cody Schuffelen EXTERN BYTE *s_cachedNvRamRef; 1284*5c591343SA. Cody Schuffelen 1285*5c591343SA. Cody Schuffelen // Initial NV Index/evict object iterator value 1286*5c591343SA. Cody Schuffelen #define NV_REF_INIT (NV_REF)0xFFFFFFFF 1287*5c591343SA. Cody Schuffelen 1288*5c591343SA. Cody Schuffelen #endif 1289*5c591343SA. Cody Schuffelen 1290*5c591343SA. Cody Schuffelen //***************************************************************************** 1291*5c591343SA. Cody Schuffelen //*** From Object.c 1292*5c591343SA. Cody Schuffelen //***************************************************************************** 1293*5c591343SA. Cody Schuffelen #if defined OBJECT_C || defined GLOBAL_C 1294*5c591343SA. Cody Schuffelen // This type is the container for an object. 1295*5c591343SA. Cody Schuffelen 1296*5c591343SA. Cody Schuffelen EXTERN OBJECT s_objects[MAX_LOADED_OBJECTS]; 1297*5c591343SA. Cody Schuffelen 1298*5c591343SA. Cody Schuffelen #endif // OBJECT_C 1299*5c591343SA. Cody Schuffelen 1300*5c591343SA. Cody Schuffelen //***************************************************************************** 1301*5c591343SA. Cody Schuffelen //*** From PCR.c 1302*5c591343SA. Cody Schuffelen //***************************************************************************** 1303*5c591343SA. Cody Schuffelen #if defined PCR_C || defined GLOBAL_C 1304*5c591343SA. Cody Schuffelen // The following macro is used to define the per-implemented-hash space. This 1305*5c591343SA. Cody Schuffelen // implementation reserves space for all implemented hashes. 1306*5c591343SA. Cody Schuffelen #define PCR_ALL_HASH(HASH, Hash) BYTE Hash##Pcr[HASH##_DIGEST_SIZE]; 1307*5c591343SA. Cody Schuffelen 1308*5c591343SA. Cody Schuffelen typedef struct 1309*5c591343SA. Cody Schuffelen { 1310*5c591343SA. Cody Schuffelen FOR_EACH_HASH(PCR_ALL_HASH) 1311*5c591343SA. Cody Schuffelen } PCR; 1312*5c591343SA. Cody Schuffelen 1313*5c591343SA. Cody Schuffelen typedef struct 1314*5c591343SA. Cody Schuffelen { 1315*5c591343SA. Cody Schuffelen unsigned int stateSave : 1; // if the PCR value should be 1316*5c591343SA. Cody Schuffelen // saved in state save 1317*5c591343SA. Cody Schuffelen unsigned int resetLocality : 5; // The locality that the PCR 1318*5c591343SA. Cody Schuffelen // can be reset 1319*5c591343SA. Cody Schuffelen unsigned int extendLocality : 5; // The locality that the PCR 1320*5c591343SA. Cody Schuffelen // can be extend 1321*5c591343SA. Cody Schuffelen } PCR_Attributes; 1322*5c591343SA. Cody Schuffelen 1323*5c591343SA. Cody Schuffelen EXTERN PCR s_pcrs[IMPLEMENTATION_PCR]; 1324*5c591343SA. Cody Schuffelen 1325*5c591343SA. Cody Schuffelen #endif // PCR_C 1326*5c591343SA. Cody Schuffelen 1327*5c591343SA. Cody Schuffelen //***************************************************************************** 1328*5c591343SA. Cody Schuffelen //*** From Session.c 1329*5c591343SA. Cody Schuffelen //***************************************************************************** 1330*5c591343SA. Cody Schuffelen #if defined SESSION_C || defined GLOBAL_C 1331*5c591343SA. Cody Schuffelen // Container for HMAC or policy session tracking information 1332*5c591343SA. Cody Schuffelen typedef struct 1333*5c591343SA. Cody Schuffelen { 1334*5c591343SA. Cody Schuffelen BOOL occupied; 1335*5c591343SA. Cody Schuffelen SESSION session; // session structure 1336*5c591343SA. Cody Schuffelen } SESSION_SLOT; 1337*5c591343SA. Cody Schuffelen 1338*5c591343SA. Cody Schuffelen EXTERN SESSION_SLOT s_sessions[MAX_LOADED_SESSIONS]; 1339*5c591343SA. Cody Schuffelen 1340*5c591343SA. Cody Schuffelen // The index in contextArray that has the value of the oldest saved session 1341*5c591343SA. Cody Schuffelen // context. When no context is saved, this will have a value that is greater 1342*5c591343SA. Cody Schuffelen // than or equal to MAX_ACTIVE_SESSIONS. 1343*5c591343SA. Cody Schuffelen EXTERN UINT32 s_oldestSavedSession; 1344*5c591343SA. Cody Schuffelen 1345*5c591343SA. Cody Schuffelen // The number of available session slot openings. When this is 1, 1346*5c591343SA. Cody Schuffelen // a session can't be created or loaded if the GAP is maxed out. 1347*5c591343SA. Cody Schuffelen // The exception is that the oldest saved session context can always 1348*5c591343SA. Cody Schuffelen // be loaded (assuming that there is a space in memory to put it) 1349*5c591343SA. Cody Schuffelen EXTERN int s_freeSessionSlots; 1350*5c591343SA. Cody Schuffelen 1351*5c591343SA. Cody Schuffelen #endif // SESSION_C 1352*5c591343SA. Cody Schuffelen 1353*5c591343SA. Cody Schuffelen //***************************************************************************** 1354*5c591343SA. Cody Schuffelen //*** From IoBuffers.c 1355*5c591343SA. Cody Schuffelen //***************************************************************************** 1356*5c591343SA. Cody Schuffelen #if defined IO_BUFFER_C || defined GLOBAL_C 1357*5c591343SA. Cody Schuffelen // Each command function is allowed a structure for the inputs to the function and 1358*5c591343SA. Cody Schuffelen // a structure for the outputs. The command dispatch code unmarshals the input butter 1359*5c591343SA. Cody Schuffelen // to the command action input structure starting at the first byte of 1360*5c591343SA. Cody Schuffelen // s_actionIoBuffer. The value of s_actionIoAllocation is the number of UINT64 values 1361*5c591343SA. Cody Schuffelen // allocated. It is used to set the pointer for the response structure. The command 1362*5c591343SA. Cody Schuffelen // dispatch code will marshal the response values into the final output buffer. 1363*5c591343SA. Cody Schuffelen EXTERN UINT64 s_actionIoBuffer[768]; // action I/O buffer 1364*5c591343SA. Cody Schuffelen EXTERN UINT32 s_actionIoAllocation; // number of UIN64 allocated for the 1365*5c591343SA. Cody Schuffelen // action input structure 1366*5c591343SA. Cody Schuffelen #endif // IO_BUFFER_C 1367*5c591343SA. Cody Schuffelen 1368*5c591343SA. Cody Schuffelen //***************************************************************************** 1369*5c591343SA. Cody Schuffelen //*** From TPMFail.c 1370*5c591343SA. Cody Schuffelen //***************************************************************************** 1371*5c591343SA. Cody Schuffelen // This value holds the address of the string containing the name of the function 1372*5c591343SA. Cody Schuffelen // in which the failure occurred. This address value is not useful for anything 1373*5c591343SA. Cody Schuffelen // other than helping the vendor to know in which file the failure occurred. 1374*5c591343SA. Cody Schuffelen EXTERN BOOL g_inFailureMode; // Indicates that the TPM is in failure mode 1375*5c591343SA. Cody Schuffelen #if SIMULATION 1376*5c591343SA. Cody Schuffelen EXTERN BOOL g_forceFailureMode; // flag to force failure mode during test 1377*5c591343SA. Cody Schuffelen #endif 1378*5c591343SA. Cody Schuffelen 1379*5c591343SA. Cody Schuffelen typedef void(FailFunction)(const char *function, int line, int code); 1380*5c591343SA. Cody Schuffelen 1381*5c591343SA. Cody Schuffelen #if defined TPM_FAIL_C || defined GLOBAL_C 1382*5c591343SA. Cody Schuffelen EXTERN UINT32 s_failFunction; 1383*5c591343SA. Cody Schuffelen EXTERN UINT32 s_failLine; // the line in the file at which 1384*5c591343SA. Cody Schuffelen // the error was signaled 1385*5c591343SA. Cody Schuffelen EXTERN UINT32 s_failCode; // the error code used 1386*5c591343SA. Cody Schuffelen 1387*5c591343SA. Cody Schuffelen EXTERN FailFunction *LibFailCallback; 1388*5c591343SA. Cody Schuffelen 1389*5c591343SA. Cody Schuffelen #endif // TPM_FAIL_C 1390*5c591343SA. Cody Schuffelen 1391*5c591343SA. Cody Schuffelen //***************************************************************************** 1392*5c591343SA. Cody Schuffelen //*** From ACT_spt.c 1393*5c591343SA. Cody Schuffelen //***************************************************************************** 1394*5c591343SA. Cody Schuffelen // This value is used to indicate if an ACT has been updated since the last 1395*5c591343SA. Cody Schuffelen // TPM2_Startup() (one bit for each ACT). If the ACT is not updated 1396*5c591343SA. Cody Schuffelen // (TPM2_ACT_SetTimeout()) after a startup, then on each TPM2_Shutdown() the TPM will 1397*5c591343SA. Cody Schuffelen // save 1/2 of the current timer value. This prevents an attack on the ACT by saving 1398*5c591343SA. Cody Schuffelen // the counter and then running for a long period of time before doing a TPM Restart. 1399*5c591343SA. Cody Schuffelen // A quick TPM2_Shutdown() after each 1400*5c591343SA. Cody Schuffelen EXTERN UINT16 s_ActUpdated; 1401*5c591343SA. Cody Schuffelen 1402*5c591343SA. Cody Schuffelen //***************************************************************************** 1403*5c591343SA. Cody Schuffelen //*** From CommandCodeAttributes.c 1404*5c591343SA. Cody Schuffelen //***************************************************************************** 1405*5c591343SA. Cody Schuffelen // This array is instanced in CommandCodeAttributes.c when it includes 1406*5c591343SA. Cody Schuffelen // CommandCodeAttributes.h. Don't change the extern to EXTERN. 1407*5c591343SA. Cody Schuffelen extern const TPMA_CC s_ccAttr[]; 1408*5c591343SA. Cody Schuffelen extern const COMMAND_ATTRIBUTES s_commandAttributes[]; 1409*5c591343SA. Cody Schuffelen 1410*5c591343SA. Cody Schuffelen #endif // GLOBAL_H 1411