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