Home | History | Annotate | Download | only in tpm2
      1 // This file was extracted from the TCG Published
      2 // Trusted Platform Module Library
      3 // Part 4: Supporting Routines
      4 // Family "2.0"
      5 // Level 00 Revision 01.16
      6 // October 30, 2014
      7 
      8 #ifndef _IMPLEMENTATION_H_
      9 #define _IMPLEMENTATION_H_
     10 #include     "BaseTypes.h"
     11 #include     "TPMB.h"
     12 #undef TRUE
     13 #undef FALSE
     14 //
     15 //     This table is built in to TpmStructures() Change these definitions to turn all algorithms or commands on or
     16 //     off
     17 //
     18 #define         ALG_YES         YES
     19 #define         ALG_NO          NO
     20 #define         CC_YES          YES
     21 #define         CC_NO           NO
     22 //
     23 //     From TPM 2.0 Part 2: Table 4 - Defines for Logic Values
     24 //
     25 #define    TRUE       1
     26 #define    FALSE      0
     27 #define    YES        1
     28 #define    NO         0
     29 #define    SET        1
     30 #define    CLEAR      0
     31 //
     32 //     From Vendor-Specific: Table 1 - Defines for Processor Values
     33 //
     34 #define    BIG_ENDIAN_TPM             NO
     35 #define    LITTLE_ENDIAN_TPM          YES
     36 #define    NO_AUTO_ALIGN              NO
     37 //
     38 //     From Vendor-Specific: Table 2 - Defines for Implemented Algorithms
     39 //
     40 #define    ALG_RSA                     ALG_YES
     41 #define    ALG_SHA1                    ALG_YES
     42 #define    ALG_HMAC                    ALG_YES
     43 #define    ALG_AES                     ALG_YES
     44 #define    ALG_MGF1                    ALG_YES
     45 #define    ALG_XOR                     ALG_YES
     46 #define    ALG_KEYEDHASH               ALG_YES
     47 #define    ALG_SHA256                  ALG_YES
     48 #ifdef EMBEDDED_MODE
     49 #define    ALG_SHA384                  ALG_NO
     50 #else
     51 #define    ALG_SHA384                  ALG_YES
     52 #endif
     53 #define    ALG_SHA512                  ALG_NO
     54 #define    ALG_SM3_256                 ALG_NO
     55 #define    ALG_SM4                     ALG_NO
     56 #define    ALG_RSASSA                  (ALG_YES*ALG_RSA)
     57 #define    ALG_RSAES                   (ALG_YES*ALG_RSA)
     58 #define    ALG_RSAPSS                  (ALG_YES*ALG_RSA)
     59 #define   ALG_OAEP                  (ALG_YES*ALG_RSA)
     60 #define   ALG_ECC                   ALG_YES
     61 #define   ALG_ECDH                  (ALG_YES*ALG_ECC)
     62 #define   ALG_ECDSA                 (ALG_YES*ALG_ECC)
     63 #define   ALG_ECDAA                 (ALG_YES*ALG_ECC)
     64 #define   ALG_SM2                   (ALG_YES*ALG_ECC)
     65 #define   ALG_ECSCHNORR             (ALG_YES*ALG_ECC)
     66 #define   ALG_ECMQV                 (ALG_NO*ALG_ECC)
     67 #define   ALG_SYMCIPHER             ALG_YES
     68 #define   ALG_KDF1_SP800_56A        (ALG_YES*ALG_ECC)
     69 #define   ALG_KDF2                  ALG_NO
     70 #define   ALG_KDF1_SP800_108        ALG_YES
     71 #define   ALG_CTR                   ALG_YES
     72 #define   ALG_OFB                   ALG_YES
     73 #define   ALG_CBC                   ALG_YES
     74 #define   ALG_CFB                   ALG_YES
     75 #define   ALG_ECB                   ALG_YES
     76 //
     77 //     From Vendor-Specific: Table 4 - Defines for Key Size Constants
     78 //
     79 #define RSA_KEY_SIZES_BITS          {1024,2048}
     80 #define RSA_KEY_SIZE_BITS_1024      RSA_ALLOWED_KEY_SIZE_1024
     81 #define RSA_KEY_SIZE_BITS_2048      RSA_ALLOWED_KEY_SIZE_2048
     82 #define MAX_RSA_KEY_BITS            2048
     83 #define MAX_RSA_KEY_BYTES           256
     84 #define AES_KEY_SIZES_BITS          {128,256}
     85 #define AES_KEY_SIZE_BITS_128       AES_ALLOWED_KEY_SIZE_128
     86 #define AES_KEY_SIZE_BITS_256       AES_ALLOWED_KEY_SIZE_256
     87 #define MAX_AES_KEY_BITS            256
     88 #define MAX_AES_KEY_BYTES           32
     89 #define MAX_AES_BLOCK_SIZE_BYTES                               \
     90            MAX(AES_128_BLOCK_SIZE_BYTES,                      \
     91            MAX(AES_256_BLOCK_SIZE_BYTES, 0))
     92 #define SM4_KEY_SIZES_BITS          {128}
     93 #define SM4_KEY_SIZE_BITS_128       SM4_ALLOWED_KEY_SIZE_128
     94 #define MAX_SM4_KEY_BITS            128
     95 #define MAX_SM4_KEY_BYTES           16
     96 #define MAX_SM4_BLOCK_SIZE_BYTES                               \
     97            MAX(SM4_128_BLOCK_SIZE_BYTES, 0)
     98 #define CAMELLIA_KEY_SIZES_BITS     {128}
     99 #define CAMELLIA_KEY_SIZE_BITS_128      CAMELLIA_ALLOWED_KEY_SIZE_128
    100 #define MAX_CAMELLIA_KEY_BITS       128
    101 #define MAX_CAMELLIA_KEY_BYTES      16
    102 #define MAX_CAMELLIA_BLOCK_SIZE_BYTES                          \
    103            MAX(CAMELLIA_128_BLOCK_SIZE_BYTES, 0)
    104 //
    105 //     From Vendor-Specific: Table 5 - Defines for Implemented Curves
    106 //
    107 #define ECC_NIST_P256          YES
    108 #define ECC_NIST_P384          YES
    109 #define ECC_BN_P256            YES
    110 #define ECC_CURVES             {\
    111    TPM_ECC_BN_P256, TPM_ECC_NIST_P256, TPM_ECC_NIST_P384}
    112 #define ECC_KEY_SIZES_BITS     {256, 384}
    113 #define ECC_KEY_SIZE_BITS_256
    114 #define ECC_KEY_SIZE_BITS_384
    115 #define MAX_ECC_KEY_BITS       384
    116 #define MAX_ECC_KEY_BYTES      48
    117 //
    118 //     From Vendor-Specific: Table 6 - Defines for Implemented Commands
    119 //
    120 #define   CC_ActivateCredential                  CC_YES
    121 #define   CC_Certify                             CC_YES
    122 #define   CC_CertifyCreation                     CC_YES
    123 //
    124 #define    CC_ChangeEPS                      CC_YES
    125 #define    CC_ChangePPS                      CC_YES
    126 #define    CC_Clear                          CC_YES
    127 #define    CC_ClearControl                   CC_YES
    128 #define    CC_ClockRateAdjust                CC_YES
    129 #define    CC_ClockSet                       CC_YES
    130 #define    CC_Commit                         (CC_YES*ALG_ECC)
    131 #define    CC_ContextLoad                    CC_YES
    132 #define    CC_ContextSave                    CC_YES
    133 #define    CC_Create                         CC_YES
    134 #define    CC_CreatePrimary                  CC_YES
    135 #define    CC_DictionaryAttackLockReset      CC_YES
    136 #define    CC_DictionaryAttackParameters     CC_YES
    137 #define    CC_Duplicate                      CC_YES
    138 #define    CC_ECC_Parameters                 (CC_YES*ALG_ECC)
    139 #define    CC_ECDH_KeyGen                    (CC_YES*ALG_ECC)
    140 #define    CC_ECDH_ZGen                      (CC_YES*ALG_ECC)
    141 #define    CC_EncryptDecrypt                 CC_YES
    142 #define    CC_EventSequenceComplete          CC_YES
    143 #define    CC_EvictControl                   CC_YES
    144 #define    CC_FieldUpgradeData               CC_NO
    145 #define    CC_FieldUpgradeStart              CC_NO
    146 #define    CC_FirmwareRead                   CC_NO
    147 #define    CC_FlushContext                   CC_YES
    148 #define    CC_GetCapability                  CC_YES
    149 #define    CC_GetCommandAuditDigest          CC_YES
    150 #define    CC_GetRandom                      CC_YES
    151 #define    CC_GetSessionAuditDigest          CC_YES
    152 #define    CC_GetTestResult                  CC_YES
    153 #define    CC_GetTime                        CC_YES
    154 #define    CC_Hash                           CC_YES
    155 #define    CC_HashSequenceStart              CC_YES
    156 #define    CC_HierarchyChangeAuth            CC_YES
    157 #define    CC_HierarchyControl               CC_YES
    158 #define    CC_HMAC                           CC_YES
    159 #define    CC_HMAC_Start                     CC_YES
    160 #define    CC_Import                         CC_YES
    161 #define    CC_IncrementalSelfTest            CC_YES
    162 #define    CC_Load                           CC_YES
    163 #define    CC_LoadExternal                   CC_YES
    164 #define    CC_MakeCredential                 CC_YES
    165 #define    CC_NV_Certify                     CC_YES
    166 #define    CC_NV_ChangeAuth                  CC_YES
    167 #define    CC_NV_DefineSpace                 CC_YES
    168 #define    CC_NV_Extend                      CC_YES
    169 #define    CC_NV_GlobalWriteLock             CC_YES
    170 #define    CC_NV_Increment                   CC_YES
    171 #define    CC_NV_Read                        CC_YES
    172 #define    CC_NV_ReadLock                    CC_YES
    173 #define    CC_NV_ReadPublic                  CC_YES
    174 #define    CC_NV_SetBits                     CC_YES
    175 #define    CC_NV_UndefineSpace               CC_YES
    176 #define    CC_NV_UndefineSpaceSpecial        CC_YES
    177 #define    CC_NV_Write                       CC_YES
    178 #define    CC_NV_WriteLock                   CC_YES
    179 #define    CC_ObjectChangeAuth               CC_YES
    180 #define    CC_PCR_Allocate                   CC_YES
    181 #define    CC_PCR_Event                      CC_YES
    182 #define    CC_PCR_Extend                     CC_YES
    183 #define    CC_PCR_Read                       CC_YES
    184 #define    CC_PCR_Reset                      CC_YES
    185 #define    CC_PCR_SetAuthPolicy              CC_YES
    186 #define    CC_PCR_SetAuthValue               CC_YES
    187 #define    CC_PolicyAuthorize                CC_YES
    188 #define    CC_PolicyAuthValue                CC_YES
    189 #define    CC_PolicyCommandCode              CC_YES
    190 #define   CC_PolicyCounterTimer                  CC_YES
    191 #define   CC_PolicyCpHash                        CC_YES
    192 #define   CC_PolicyDuplicationSelect             CC_YES
    193 #define   CC_PolicyGetDigest                     CC_YES
    194 #define   CC_PolicyLocality                      CC_YES
    195 #define   CC_PolicyNameHash                      CC_YES
    196 #define   CC_PolicyNV                            CC_YES
    197 #define   CC_PolicyOR                            CC_YES
    198 #define   CC_PolicyPassword                      CC_YES
    199 #define   CC_PolicyPCR                           CC_YES
    200 #define   CC_PolicyPhysicalPresence              CC_YES
    201 #define   CC_PolicyRestart                       CC_YES
    202 #define   CC_PolicySecret                        CC_YES
    203 #define   CC_PolicySigned                        CC_YES
    204 #define   CC_PolicyTicket                        CC_YES
    205 #define   CC_PP_Commands                         CC_YES
    206 #define   CC_Quote                               CC_YES
    207 #define   CC_ReadClock                           CC_YES
    208 #define   CC_ReadPublic                          CC_YES
    209 #define   CC_Rewrap                              CC_YES
    210 #define   CC_RSA_Decrypt                         (CC_YES*ALG_RSA)
    211 #define   CC_RSA_Encrypt                         (CC_YES*ALG_RSA)
    212 #define   CC_SelfTest                            CC_YES
    213 #define   CC_SequenceComplete                    CC_YES
    214 #define   CC_SequenceUpdate                      CC_YES
    215 #define   CC_SetAlgorithmSet                     CC_YES
    216 #define   CC_SetCommandCodeAuditStatus           CC_YES
    217 #define   CC_SetPrimaryPolicy                    CC_YES
    218 #define   CC_Shutdown                            CC_YES
    219 #define   CC_Sign                                CC_YES
    220 #define   CC_StartAuthSession                    CC_YES
    221 #define   CC_Startup                             CC_YES
    222 #define   CC_StirRandom                          CC_YES
    223 #define   CC_TestParms                           CC_YES
    224 #define   CC_Unseal                              CC_YES
    225 #define   CC_VerifySignature                     CC_YES
    226 #define   CC_ZGen_2Phase                         (CC_YES*ALG_ECC)
    227 #define   CC_EC_Ephemeral                        (CC_YES*ALG_ECC)
    228 #define   CC_PolicyNvWritten                     CC_YES
    229 //
    230 //      From Vendor-Specific: Table 7 - Defines for Implementation Values
    231 //
    232 #define   FIELD_UPGRADE_IMPLEMENTED              NO
    233 #define   BSIZE                                  UINT16
    234 #define   BUFFER_ALIGNMENT                       4
    235 #define   IMPLEMENTATION_PCR                     24
    236 #define   PLATFORM_PCR                           24
    237 #define   DRTM_PCR                               17
    238 #define   HCRTM_PCR                              0
    239 #define   NUM_LOCALITIES                         5
    240 #define   MAX_HANDLE_NUM                         3
    241 #define   MAX_ACTIVE_SESSIONS                    64
    242 #define   CONTEXT_SLOT                           UINT16
    243 #define   CONTEXT_COUNTER                        UINT64
    244 #define   MAX_LOADED_SESSIONS                    3
    245 #define   MAX_SESSION_NUM                        3
    246 #define   MAX_LOADED_OBJECTS                     3
    247 #define   MIN_EVICT_OBJECTS                      2
    248 #define   PCR_SELECT_MIN                         ((PLATFORM_PCR+7)/8)
    249 #define   PCR_SELECT_MAX                         ((IMPLEMENTATION_PCR+7)/8)
    250 #define   NUM_POLICY_PCR_GROUP                   1
    251 #define   NUM_AUTHVALUE_PCR_GROUP                1
    252 #define   MAX_CONTEXT_SIZE                       2048
    253 #define   MAX_DIGEST_BUFFER                      1024
    254 #define   MAX_NV_INDEX_SIZE                      2048
    255 //
    256 #define MAX_NV_BUFFER_SIZE                1024
    257 #define MAX_CAP_BUFFER                    1024
    258 #ifdef EMBEDDED_MODE
    259 #define NV_MEMORY_SIZE                    8192
    260 #else
    261 #define NV_MEMORY_SIZE                    16384
    262 #endif
    263 #define NUM_STATIC_PCR                    16
    264 #define MAX_ALG_LIST_SIZE                 64
    265 #define TIMER_PRESCALE                    100000
    266 #define PRIMARY_SEED_SIZE                 32
    267 #define CONTEXT_ENCRYPT_ALG               TPM_ALG_AES
    268 #define CONTEXT_ENCRYPT_KEY_BITS          MAX_SYM_KEY_BITS
    269 #define CONTEXT_ENCRYPT_KEY_BYTES         ((CONTEXT_ENCRYPT_KEY_BITS+7)/8)
    270 #define CONTEXT_INTEGRITY_HASH_ALG        TPM_ALG_SHA256
    271 #define CONTEXT_INTEGRITY_HASH_SIZE       SHA256_DIGEST_SIZE
    272 #define PROOF_SIZE                        CONTEXT_INTEGRITY_HASH_SIZE
    273 #define NV_CLOCK_UPDATE_INTERVAL          12
    274 #define NUM_POLICY_PCR                    1
    275 #define MAX_COMMAND_SIZE                  4096
    276 #define MAX_RESPONSE_SIZE                 4096
    277 #define ORDERLY_BITS                      8
    278 #define MAX_ORDERLY_COUNT                 ((1<<ORDERLY_BITS)-1)
    279 #define ALG_ID_FIRST                      TPM_ALG_FIRST
    280 #define ALG_ID_LAST                       TPM_ALG_LAST
    281 #define MAX_SYM_DATA                      128
    282 #define MAX_RNG_ENTROPY_SIZE              64
    283 #define RAM_INDEX_SPACE                   512
    284 #define RSA_DEFAULT_PUBLIC_EXPONENT       0x00010001
    285 #define ENABLE_PCR_NO_INCREMENT           YES
    286 #define CRT_FORMAT_RSA                    YES
    287 #define PRIVATE_VENDOR_SPECIFIC_BYTES     \
    288    ((MAX_RSA_KEY_BYTES/2)*(3+CRT_FORMAT_RSA*2))
    289 //
    290 //      From TCG Algorithm Registry: Table 2 - Definition of TPM_ALG_ID Constants
    291 //
    292 typedef UINT16              TPM_ALG_ID;
    293 #define TPM_ALG_ERROR                (TPM_ALG_ID)(0x0000)
    294 #define ALG_ERROR_VALUE              0x0000
    295 #if defined ALG_RSA && ALG_RSA == YES
    296 #define TPM_ALG_RSA                  (TPM_ALG_ID)(0x0001)
    297 #endif
    298 #define ALG_RSA_VALUE                0x0001
    299 #if defined ALG_SHA && ALG_SHA == YES
    300 #define TPM_ALG_SHA                  (TPM_ALG_ID)(0x0004)
    301 #endif
    302 #define ALG_SHA_VALUE                0x0004
    303 #if defined ALG_SHA1 && ALG_SHA1 == YES
    304 #define TPM_ALG_SHA1                 (TPM_ALG_ID)(0x0004)
    305 #endif
    306 #define ALG_SHA1_VALUE               0x0004
    307 #if defined ALG_HMAC && ALG_HMAC == YES
    308 #define TPM_ALG_HMAC                  (TPM_ALG_ID)(0x0005)
    309 #endif
    310 #define ALG_HMAC_VALUE               0x0005
    311 #if defined ALG_AES && ALG_AES == YES
    312 #define TPM_ALG_AES                  (TPM_ALG_ID)(0x0006)
    313 #endif
    314 #define ALG_AES_VALUE                0x0006
    315 #if defined ALG_MGF1 && ALG_MGF1 == YES
    316 #define TPM_ALG_MGF1                 (TPM_ALG_ID)(0x0007)
    317 #endif
    318 #define ALG_MGF1_VALUE               0x0007
    319 #if defined ALG_KEYEDHASH && ALG_KEYEDHASH == YES
    320 #define TPM_ALG_KEYEDHASH            (TPM_ALG_ID)(0x0008)
    321 #endif
    322 #define ALG_KEYEDHASH_VALUE          0x0008
    323 #if defined ALG_XOR && ALG_XOR == YES
    324 #define TPM_ALG_XOR                  (TPM_ALG_ID)(0x000A)
    325 //
    326 #endif
    327 #define ALG_XOR_VALUE                0x000A
    328 #if defined ALG_SHA256 && ALG_SHA256 == YES
    329 #define TPM_ALG_SHA256               (TPM_ALG_ID)(0x000B)
    330 #endif
    331 #define ALG_SHA256_VALUE             0x000B
    332 #if defined ALG_SHA384 && ALG_SHA384 == YES
    333 #define TPM_ALG_SHA384               (TPM_ALG_ID)(0x000C)
    334 #endif
    335 #define ALG_SHA384_VALUE             0x000C
    336 #if defined ALG_SHA512 && ALG_SHA512 == YES
    337 #define TPM_ALG_SHA512               (TPM_ALG_ID)(0x000D)
    338 #endif
    339 #define ALG_SHA512_VALUE             0x000D
    340 #define TPM_ALG_NULL                 (TPM_ALG_ID)(0x0010)
    341 #define ALG_NULL_VALUE               0x0010
    342 #if defined ALG_SM3_256 && ALG_SM3_256 == YES
    343 #define TPM_ALG_SM3_256              (TPM_ALG_ID)(0x0012)
    344 #endif
    345 #define ALG_SM3_256_VALUE            0x0012
    346 #if defined ALG_SM4 && ALG_SM4 == YES
    347 #define TPM_ALG_SM4                  (TPM_ALG_ID)(0x0013)
    348 #endif
    349 #define ALG_SM4_VALUE                0x0013
    350 #if defined ALG_RSASSA && ALG_RSASSA == YES
    351 #define TPM_ALG_RSASSA               (TPM_ALG_ID)(0x0014)
    352 #endif
    353 #define ALG_RSASSA_VALUE             0x0014
    354 #if defined ALG_RSAES && ALG_RSAES == YES
    355 #define TPM_ALG_RSAES                (TPM_ALG_ID)(0x0015)
    356 #endif
    357 #define ALG_RSAES_VALUE              0x0015
    358 #if defined ALG_RSAPSS && ALG_RSAPSS == YES
    359 #define TPM_ALG_RSAPSS               (TPM_ALG_ID)(0x0016)
    360 #endif
    361 #define ALG_RSAPSS_VALUE             0x0016
    362 #if defined ALG_OAEP && ALG_OAEP == YES
    363 #define TPM_ALG_OAEP                 (TPM_ALG_ID)(0x0017)
    364 #endif
    365 #define ALG_OAEP_VALUE               0x0017
    366 #if defined ALG_ECDSA && ALG_ECDSA == YES
    367 #define TPM_ALG_ECDSA                (TPM_ALG_ID)(0x0018)
    368 #endif
    369 #define ALG_ECDSA_VALUE              0x0018
    370 #if defined ALG_ECDH && ALG_ECDH == YES
    371 #define TPM_ALG_ECDH                 (TPM_ALG_ID)(0x0019)
    372 #endif
    373 #define ALG_ECDH_VALUE               0x0019
    374 #if defined ALG_ECDAA && ALG_ECDAA == YES
    375 #define TPM_ALG_ECDAA                (TPM_ALG_ID)(0x001A)
    376 #endif
    377 #define ALG_ECDAA_VALUE              0x001A
    378 #if defined ALG_SM2 && ALG_SM2 == YES
    379 #define TPM_ALG_SM2                  (TPM_ALG_ID)(0x001B)
    380 #endif
    381 #define ALG_SM2_VALUE                0x001B
    382 #if defined ALG_ECSCHNORR && ALG_ECSCHNORR == YES
    383 #define TPM_ALG_ECSCHNORR            (TPM_ALG_ID)(0x001C)
    384 #endif
    385 #define ALG_ECSCHNORR_VALUE          0x001C
    386 #if defined ALG_ECMQV && ALG_ECMQV == YES
    387 #define TPM_ALG_ECMQV                (TPM_ALG_ID)(0x001D)
    388 #endif
    389 #define ALG_ECMQV_VALUE              0x001D
    390 #if defined ALG_KDF1_SP800_56A && ALG_KDF1_SP800_56A == YES
    391 #define TPM_ALG_KDF1_SP800_56A       (TPM_ALG_ID)(0x0020)
    392 #endif
    393 #define ALG_KDF1_SP800_56A_VALUE     0x0020
    394 #if defined ALG_KDF2 && ALG_KDF2 == YES
    395 #define TPM_ALG_KDF2                 (TPM_ALG_ID)(0x0021)
    396 #endif
    397 #define ALG_KDF2_VALUE               0x0021
    398 #if defined ALG_KDF1_SP800_108 && ALG_KDF1_SP800_108 == YES
    399 #define TPM_ALG_KDF1_SP800_108       (TPM_ALG_ID)(0x0022)
    400 #endif
    401 #define ALG_KDF1_SP800_108_VALUE     0x0022
    402 #if defined ALG_ECC && ALG_ECC == YES
    403 #define TPM_ALG_ECC                  (TPM_ALG_ID)(0x0023)
    404 #endif
    405 #define ALG_ECC_VALUE                0x0023
    406 #if defined ALG_SYMCIPHER && ALG_SYMCIPHER == YES
    407 #define TPM_ALG_SYMCIPHER            (TPM_ALG_ID)(0x0025)
    408 #endif
    409 #define ALG_SYMCIPHER_VALUE          0x0025
    410 #if defined ALG_CAMELLIA && ALG_CAMELLIA == YES
    411 #define TPM_ALG_CAMELLIA             (TPM_ALG_ID)(0x0026)
    412 #endif
    413 #define ALG_CAMELLIA_VALUE           0x0026
    414 #if defined ALG_CTR && ALG_CTR == YES
    415 #define TPM_ALG_CTR                  (TPM_ALG_ID)(0x0040)
    416 #endif
    417 #define ALG_CTR_VALUE                0x0040
    418 #if defined ALG_OFB && ALG_OFB == YES
    419 #define TPM_ALG_OFB                   (TPM_ALG_ID)(0x0041)
    420 #endif
    421 #define ALG_OFB_VALUE                0x0041
    422 #if defined ALG_CBC && ALG_CBC == YES
    423 #define TPM_ALG_CBC                  (TPM_ALG_ID)(0x0042)
    424 #endif
    425 #define ALG_CBC_VALUE                0x0042
    426 #if defined ALG_CFB && ALG_CFB == YES
    427 #define TPM_ALG_CFB                  (TPM_ALG_ID)(0x0043)
    428 #endif
    429 #define ALG_CFB_VALUE                0x0043
    430 #if defined ALG_ECB && ALG_ECB == YES
    431 #define TPM_ALG_ECB                  (TPM_ALG_ID)(0x0044)
    432 #endif
    433 #define ALG_ECB_VALUE                0x0044
    434 #define TPM_ALG_FIRST                (TPM_ALG_ID)(0x0001)
    435 #define ALG_FIRST_VALUE              0x0001
    436 #define TPM_ALG_LAST                 (TPM_ALG_ID)(0x0044)
    437 #define ALG_LAST_VALUE               0x0044
    438 //
    439 //      From TCG Algorithm Registry: Table 3 - Definition of TPM_ECC_CURVE Constants
    440 //
    441 typedef    UINT16                 TPM_ECC_CURVE;
    442 #define    TPM_ECC_NONE             (TPM_ECC_CURVE)(0x0000)
    443 #define    TPM_ECC_NIST_P192        (TPM_ECC_CURVE)(0x0001)
    444 #define    TPM_ECC_NIST_P224        (TPM_ECC_CURVE)(0x0002)
    445 #define    TPM_ECC_NIST_P256        (TPM_ECC_CURVE)(0x0003)
    446 #define    TPM_ECC_NIST_P384        (TPM_ECC_CURVE)(0x0004)
    447 #define    TPM_ECC_NIST_P521        (TPM_ECC_CURVE)(0x0005)
    448 #define    TPM_ECC_BN_P256          (TPM_ECC_CURVE)(0x0010)
    449 #define    TPM_ECC_BN_P638          (TPM_ECC_CURVE)(0x0011)
    450 #define    TPM_ECC_SM2_P256         (TPM_ECC_CURVE)(0x0020)
    451 //
    452 //      From TCG Algorithm Registry: Table 4 - Defines for NIST_P192 ECC Values Data in CrpiEccData.c From
    453 //      TCG Algorithm Registry: Table 5 - Defines for NIST_P224 ECC Values Data in CrpiEccData.c From TCG
    454 //      Algorithm Registry: Table 6 - Defines for NIST_P256 ECC Values Data in CrpiEccData.c From TCG
    455 //      Algorithm Registry: Table 7 - Defines for NIST_P384 ECC Values Data in CrpiEccData.c From TCG
    456 //
    457 //      Algorithm Registry: Table 8 - Defines for NIST_P521 ECC Values Data in CrpiEccData.c     From   TCG
    458 //      Algorithm Registry: Table 9 - Defines for BN_P256 ECC Values Data in CrpiEccData.c       From   TCG
    459 //      Algorithm Registry: Table 10 - Defines for BN_P638 ECC Values Data in CrpiEccData.c      From   TCG
    460 //      Algorithm Registry: Table 11 - Defines for SM2_P256 ECC Values Data in CrpiEccData.c     From   TCG
    461 //      Algorithm Registry: Table 12 - Defines for SHA1 Hash Values
    462 //
    463 #define SHA1_DIGEST_SIZE     20
    464 #define SHA_DIGEST_SIZE      SHA1_DIGEST_SIZE
    465 #define SHA1_BLOCK_SIZE      64
    466 #define SHA1_DER_SIZE        15
    467 #define SHA1_DER             \
    468    0x30,0x21,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x04,0x14
    469 //
    470 //      From TCG Algorithm Registry: Table 13 - Defines for SHA256 Hash Values
    471 //
    472 #define   SHA256_DIGEST_SIZE       32
    473 #define   SHA256_BLOCK_SIZE        64
    474 #define   SHA256_DER_SIZE          19
    475 #define   SHA256_DER               \
    476    0x30,0x31,0x30,0x0D,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x01,0x05,0x00,0x04,0x20
    477 //
    478 //      From TCG Algorithm Registry: Table 14 - Defines for SHA384 Hash Values
    479 //
    480 #define   SHA384_DIGEST_SIZE       48
    481 #define   SHA384_BLOCK_SIZE        128
    482 #define   SHA384_DER_SIZE          19
    483 #define   SHA384_DER               \
    484    0x30,0x41,0x30,0x0D,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x02,0x05,0x00,0x04,0x30
    485 //
    486 //      From TCG Algorithm Registry: Table 15 - Defines for SHA512 Hash Values
    487 //
    488 #define   SHA512_DIGEST_SIZE       64
    489 #define   SHA512_BLOCK_SIZE        128
    490 #define   SHA512_DER_SIZE          19
    491 #define   SHA512_DER               \
    492    0x30,0x51,0x30,0x0D,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x03,0x05,0x00,0x04,0x40
    493 //
    494 //      From TCG Algorithm Registry: Table 16 - Defines for SM3_256 Hash Values
    495 //
    496 #define   SM3_256_DIGEST_SIZE       32
    497 #define   SM3_256_BLOCK_SIZE        64
    498 #define   SM3_256_DER_SIZE          18
    499 #define   SM3_256_DER               \
    500 //      0x30,0x30,0x30,0x0C,0x06,0x08,0x2A,0x81,0x1C,0x81,0x45,0x01,0x83,0x11,0x05,0x00,0x04,0
    501 //      x20
    502 //
    503 //      From TCG Algorithm Registry: Table 17 - Defines for AES Symmetric Cipher Algorithm Constants
    504 //
    505 #define   AES_ALLOWED_KEY_SIZE_128        YES
    506 #define   AES_ALLOWED_KEY_SIZE_192        YES
    507 #define   AES_ALLOWED_KEY_SIZE_256        YES
    508 #define   AES_128_BLOCK_SIZE_BYTES        16
    509 #define   AES_192_BLOCK_SIZE_BYTES        16
    510 #define   AES_256_BLOCK_SIZE_BYTES        16
    511 //
    512 //      From TCG Algorithm Registry: Table 18 - Defines for SM4 Symmetric Cipher Algorithm Constants
    513 #define    SM4_ALLOWED_KEY_SIZE_128       YES
    514 #define    SM4_128_BLOCK_SIZE_BYTES       16
    515 //
    516 //      From TCG Algorithm Registry: Table 19 - Defines for CAMELLIA Symmetric Cipher Algorithm Constants
    517 //
    518 #define    CAMELLIA_ALLOWED_KEY_SIZE_128        YES
    519 #define    CAMELLIA_ALLOWED_KEY_SIZE_192        YES
    520 #define    CAMELLIA_ALLOWED_KEY_SIZE_256        YES
    521 #define    CAMELLIA_128_BLOCK_SIZE_BYTES        16
    522 #define    CAMELLIA_192_BLOCK_SIZE_BYTES        16
    523 #define    CAMELLIA_256_BLOCK_SIZE_BYTES        16
    524 //
    525 //      From TPM 2.0 Part 2: Table 13 - Definition of TPM_CC Constants
    526 //
    527 typedef UINT32              TPM_CC;
    528 #define TPM_CC_FIRST                          (TPM_CC)(0x0000011F)
    529 #define TPM_CC_PP_FIRST                       (TPM_CC)(0x0000011F)
    530 #if defined CC_NV_UndefineSpaceSpecial && CC_NV_UndefineSpaceSpecial == YES
    531 #define TPM_CC_NV_UndefineSpaceSpecial        (TPM_CC)(0x0000011F)
    532 #endif
    533 #if defined CC_EvictControl && CC_EvictControl == YES
    534 #define TPM_CC_EvictControl                   (TPM_CC)(0x00000120)
    535 #endif
    536 #if defined CC_HierarchyControl && CC_HierarchyControl == YES
    537 #define TPM_CC_HierarchyControl               (TPM_CC)(0x00000121)
    538 #endif
    539 #if defined CC_NV_UndefineSpace && CC_NV_UndefineSpace == YES
    540 #define TPM_CC_NV_UndefineSpace               (TPM_CC)(0x00000122)
    541 #endif
    542 #if defined CC_ChangeEPS && CC_ChangeEPS == YES
    543 #define TPM_CC_ChangeEPS                      (TPM_CC)(0x00000124)
    544 #endif
    545 #if defined CC_ChangePPS && CC_ChangePPS == YES
    546 #define TPM_CC_ChangePPS                      (TPM_CC)(0x00000125)
    547 #endif
    548 #if defined CC_Clear && CC_Clear == YES
    549 #define TPM_CC_Clear                          (TPM_CC)(0x00000126)
    550 #endif
    551 #if defined CC_ClearControl && CC_ClearControl == YES
    552 #define TPM_CC_ClearControl                   (TPM_CC)(0x00000127)
    553 #endif
    554 #if defined CC_ClockSet && CC_ClockSet == YES
    555 #define TPM_CC_ClockSet                       (TPM_CC)(0x00000128)
    556 #endif
    557 #if defined CC_HierarchyChangeAuth && CC_HierarchyChangeAuth == YES
    558 #define TPM_CC_HierarchyChangeAuth            (TPM_CC)(0x00000129)
    559 #endif
    560 #if defined CC_NV_DefineSpace && CC_NV_DefineSpace == YES
    561 #define TPM_CC_NV_DefineSpace                 (TPM_CC)(0x0000012A)
    562 #endif
    563 #if defined CC_PCR_Allocate && CC_PCR_Allocate == YES
    564 #define TPM_CC_PCR_Allocate                   (TPM_CC)(0x0000012B)
    565 #endif
    566 #if defined CC_PCR_SetAuthPolicy && CC_PCR_SetAuthPolicy == YES
    567 #define TPM_CC_PCR_SetAuthPolicy              (TPM_CC)(0x0000012C)
    568 #endif
    569 #if defined CC_PP_Commands && CC_PP_Commands == YES
    570 #define TPM_CC_PP_Commands                    (TPM_CC)(0x0000012D)
    571 #endif
    572 #if defined CC_SetPrimaryPolicy && CC_SetPrimaryPolicy == YES
    573 #define TPM_CC_SetPrimaryPolicy               (TPM_CC)(0x0000012E)
    574 #endif
    575 #if defined CC_FieldUpgradeStart && CC_FieldUpgradeStart == YES
    576 #define TPM_CC_FieldUpgradeStart              (TPM_CC)(0x0000012F)
    577 #endif
    578 #if defined CC_ClockRateAdjust && CC_ClockRateAdjust == YES
    579 #define TPM_CC_ClockRateAdjust                (TPM_CC)(0x00000130)
    580 #endif
    581 #if defined CC_CreatePrimary && CC_CreatePrimary == YES
    582 #define TPM_CC_CreatePrimary                  (TPM_CC)(0x00000131)
    583 #endif
    584 #if defined CC_NV_GlobalWriteLock && CC_NV_GlobalWriteLock == YES
    585 #define TPM_CC_NV_GlobalWriteLock             (TPM_CC)(0x00000132)
    586 #endif
    587 #define TPM_CC_PP_LAST                        (TPM_CC)(0x00000132)
    588 #if defined CC_GetCommandAuditDigest && CC_GetCommandAuditDigest == YES
    589 #define TPM_CC_GetCommandAuditDigest          (TPM_CC)(0x00000133)
    590 #endif
    591 #if defined CC_NV_Increment && CC_NV_Increment == YES
    592 #define TPM_CC_NV_Increment                   (TPM_CC)(0x00000134)
    593 #endif
    594 #if defined CC_NV_SetBits && CC_NV_SetBits == YES
    595 #define TPM_CC_NV_SetBits                     (TPM_CC)(0x00000135)
    596 #endif
    597 #if defined CC_NV_Extend && CC_NV_Extend == YES
    598 #define TPM_CC_NV_Extend                      (TPM_CC)(0x00000136)
    599 #endif
    600 #if defined CC_NV_Write && CC_NV_Write == YES
    601 #define TPM_CC_NV_Write                       (TPM_CC)(0x00000137)
    602 #endif
    603 #if defined CC_NV_WriteLock && CC_NV_WriteLock == YES
    604 #define TPM_CC_NV_WriteLock                   (TPM_CC)(0x00000138)
    605 #endif
    606 #if defined CC_DictionaryAttackLockReset && CC_DictionaryAttackLockReset == YES
    607 #define TPM_CC_DictionaryAttackLockReset      (TPM_CC)(0x00000139)
    608 #endif
    609 #if defined CC_DictionaryAttackParameters && CC_DictionaryAttackParameters == YES
    610 #define TPM_CC_DictionaryAttackParameters     (TPM_CC)(0x0000013A)
    611 #endif
    612 #if defined CC_NV_ChangeAuth && CC_NV_ChangeAuth == YES
    613 #define TPM_CC_NV_ChangeAuth                  (TPM_CC)(0x0000013B)
    614 #endif
    615 #if defined CC_PCR_Event && CC_PCR_Event == YES
    616 #define TPM_CC_PCR_Event                      (TPM_CC)(0x0000013C)
    617 #endif
    618 #if defined CC_PCR_Reset && CC_PCR_Reset == YES
    619 #define TPM_CC_PCR_Reset                      (TPM_CC)(0x0000013D)
    620 #endif
    621 #if defined CC_SequenceComplete && CC_SequenceComplete == YES
    622 #define TPM_CC_SequenceComplete               (TPM_CC)(0x0000013E)
    623 #endif
    624 #if defined CC_SetAlgorithmSet && CC_SetAlgorithmSet == YES
    625 #define TPM_CC_SetAlgorithmSet                (TPM_CC)(0x0000013F)
    626 #endif
    627 #if defined CC_SetCommandCodeAuditStatus && CC_SetCommandCodeAuditStatus == YES
    628 #define TPM_CC_SetCommandCodeAuditStatus      (TPM_CC)(0x00000140)
    629 #endif
    630 #if defined CC_FieldUpgradeData && CC_FieldUpgradeData == YES
    631 #define TPM_CC_FieldUpgradeData               (TPM_CC)(0x00000141)
    632 #endif
    633 #if defined CC_IncrementalSelfTest && CC_IncrementalSelfTest == YES
    634 #define TPM_CC_IncrementalSelfTest            (TPM_CC)(0x00000142)
    635 #endif
    636 #if defined CC_SelfTest && CC_SelfTest == YES
    637 #define TPM_CC_SelfTest                       (TPM_CC)(0x00000143)
    638 #endif
    639 #if defined CC_Startup && CC_Startup == YES
    640 #define TPM_CC_Startup                        (TPM_CC)(0x00000144)
    641 #endif
    642 #if defined CC_Shutdown && CC_Shutdown == YES
    643 #define TPM_CC_Shutdown                       (TPM_CC)(0x00000145)
    644 #endif
    645 #if defined CC_StirRandom && CC_StirRandom == YES
    646 #define TPM_CC_StirRandom                     (TPM_CC)(0x00000146)
    647 #endif
    648 #if defined CC_ActivateCredential && CC_ActivateCredential == YES
    649 #define TPM_CC_ActivateCredential             (TPM_CC)(0x00000147)
    650 #endif
    651 #if defined CC_Certify && CC_Certify == YES
    652 #define TPM_CC_Certify                        (TPM_CC)(0x00000148)
    653 #endif
    654 #if defined CC_PolicyNV && CC_PolicyNV == YES
    655 #define TPM_CC_PolicyNV                       (TPM_CC)(0x00000149)
    656 #endif
    657 #if defined CC_CertifyCreation && CC_CertifyCreation == YES
    658 #define TPM_CC_CertifyCreation                (TPM_CC)(0x0000014A)
    659 #endif
    660 #if defined CC_Duplicate && CC_Duplicate == YES
    661 #define TPM_CC_Duplicate                      (TPM_CC)(0x0000014B)
    662 #endif
    663 #if defined CC_GetTime && CC_GetTime == YES
    664 #define TPM_CC_GetTime                        (TPM_CC)(0x0000014C)
    665 #endif
    666 #if defined CC_GetSessionAuditDigest && CC_GetSessionAuditDigest == YES
    667 #define TPM_CC_GetSessionAuditDigest          (TPM_CC)(0x0000014D)
    668 #endif
    669 #if defined CC_NV_Read && CC_NV_Read == YES
    670 #define TPM_CC_NV_Read                        (TPM_CC)(0x0000014E)
    671 #endif
    672 #if defined CC_NV_ReadLock && CC_NV_ReadLock == YES
    673 #define TPM_CC_NV_ReadLock                    (TPM_CC)(0x0000014F)
    674 #endif
    675 #if defined CC_ObjectChangeAuth && CC_ObjectChangeAuth == YES
    676 #define TPM_CC_ObjectChangeAuth               (TPM_CC)(0x00000150)
    677 #endif
    678 #if defined CC_PolicySecret && CC_PolicySecret == YES
    679 #define TPM_CC_PolicySecret                   (TPM_CC)(0x00000151)
    680 #endif
    681 #if defined CC_Rewrap && CC_Rewrap == YES
    682 #define TPM_CC_Rewrap                         (TPM_CC)(0x00000152)
    683 #endif
    684 #if defined CC_Create && CC_Create == YES
    685 #define TPM_CC_Create                         (TPM_CC)(0x00000153)
    686 #endif
    687 #if defined CC_ECDH_ZGen && CC_ECDH_ZGen == YES
    688 #define TPM_CC_ECDH_ZGen                      (TPM_CC)(0x00000154)
    689 #endif
    690 #if defined CC_HMAC && CC_HMAC == YES
    691 #define TPM_CC_HMAC                           (TPM_CC)(0x00000155)
    692 #endif
    693 #if defined CC_Import && CC_Import == YES
    694 #define TPM_CC_Import                         (TPM_CC)(0x00000156)
    695 #endif
    696 #if defined CC_Load && CC_Load == YES
    697 #define TPM_CC_Load                           (TPM_CC)(0x00000157)
    698 #endif
    699 #if defined CC_Quote && CC_Quote == YES
    700 #define TPM_CC_Quote                          (TPM_CC)(0x00000158)
    701 #endif
    702 #if defined CC_RSA_Decrypt && CC_RSA_Decrypt == YES
    703 #define TPM_CC_RSA_Decrypt                    (TPM_CC)(0x00000159)
    704 #endif
    705 #if defined CC_HMAC_Start && CC_HMAC_Start == YES
    706 #define TPM_CC_HMAC_Start                     (TPM_CC)(0x0000015B)
    707 #endif
    708 #if defined CC_SequenceUpdate && CC_SequenceUpdate == YES
    709 #define TPM_CC_SequenceUpdate                 (TPM_CC)(0x0000015C)
    710 #endif
    711 #if defined CC_Sign && CC_Sign == YES
    712 #define TPM_CC_Sign                           (TPM_CC)(0x0000015D)
    713 #endif
    714 #if defined CC_Unseal && CC_Unseal == YES
    715 #define TPM_CC_Unseal                         (TPM_CC)(0x0000015E)
    716 #endif
    717 #if defined CC_PolicySigned && CC_PolicySigned == YES
    718 #define TPM_CC_PolicySigned                   (TPM_CC)(0x00000160)
    719 #endif
    720 #if defined CC_ContextLoad && CC_ContextLoad == YES
    721 #define TPM_CC_ContextLoad                    (TPM_CC)(0x00000161)
    722 #endif
    723 #if defined CC_ContextSave && CC_ContextSave == YES
    724 #define TPM_CC_ContextSave                    (TPM_CC)(0x00000162)
    725 #endif
    726 #if defined CC_ECDH_KeyGen && CC_ECDH_KeyGen == YES
    727 #define TPM_CC_ECDH_KeyGen                    (TPM_CC)(0x00000163)
    728 #endif
    729 #if defined CC_EncryptDecrypt && CC_EncryptDecrypt == YES
    730 #define TPM_CC_EncryptDecrypt                 (TPM_CC)(0x00000164)
    731 #endif
    732 #if defined CC_FlushContext && CC_FlushContext == YES
    733 #define TPM_CC_FlushContext                   (TPM_CC)(0x00000165)
    734 #endif
    735 #if defined CC_LoadExternal && CC_LoadExternal == YES
    736 #define TPM_CC_LoadExternal                   (TPM_CC)(0x00000167)
    737 #endif
    738 #if defined CC_MakeCredential && CC_MakeCredential == YES
    739 #define TPM_CC_MakeCredential                 (TPM_CC)(0x00000168)
    740 #endif
    741 #if defined CC_NV_ReadPublic && CC_NV_ReadPublic == YES
    742 #define TPM_CC_NV_ReadPublic                  (TPM_CC)(0x00000169)
    743 #endif
    744 #if defined CC_PolicyAuthorize && CC_PolicyAuthorize == YES
    745 #define TPM_CC_PolicyAuthorize                (TPM_CC)(0x0000016A)
    746 #endif
    747 #if defined CC_PolicyAuthValue && CC_PolicyAuthValue == YES
    748 #define TPM_CC_PolicyAuthValue                (TPM_CC)(0x0000016B)
    749 #endif
    750 #if defined CC_PolicyCommandCode && CC_PolicyCommandCode == YES
    751 #define TPM_CC_PolicyCommandCode              (TPM_CC)(0x0000016C)
    752 #endif
    753 #if defined CC_PolicyCounterTimer && CC_PolicyCounterTimer == YES
    754 #define TPM_CC_PolicyCounterTimer             (TPM_CC)(0x0000016D)
    755 #endif
    756 #if defined CC_PolicyCpHash && CC_PolicyCpHash == YES
    757 #define TPM_CC_PolicyCpHash                   (TPM_CC)(0x0000016E)
    758 #endif
    759 #if defined CC_PolicyLocality && CC_PolicyLocality == YES
    760 #define TPM_CC_PolicyLocality                 (TPM_CC)(0x0000016F)
    761 #endif
    762 #if defined CC_PolicyNameHash && CC_PolicyNameHash == YES
    763 #define TPM_CC_PolicyNameHash                 (TPM_CC)(0x00000170)
    764 #endif
    765 #if defined CC_PolicyOR && CC_PolicyOR == YES
    766 #define TPM_CC_PolicyOR                       (TPM_CC)(0x00000171)
    767 #endif
    768 #if defined CC_PolicyTicket && CC_PolicyTicket == YES
    769 #define TPM_CC_PolicyTicket                   (TPM_CC)(0x00000172)
    770 #endif
    771 #if defined CC_ReadPublic && CC_ReadPublic == YES
    772 #define TPM_CC_ReadPublic                     (TPM_CC)(0x00000173)
    773 #endif
    774 #if defined CC_RSA_Encrypt && CC_RSA_Encrypt == YES
    775 #define TPM_CC_RSA_Encrypt                    (TPM_CC)(0x00000174)
    776 #endif
    777 #if defined CC_StartAuthSession && CC_StartAuthSession == YES
    778 #define TPM_CC_StartAuthSession               (TPM_CC)(0x00000176)
    779 #endif
    780 #if defined CC_VerifySignature && CC_VerifySignature == YES
    781 #define TPM_CC_VerifySignature                (TPM_CC)(0x00000177)
    782 #endif
    783 #if defined CC_ECC_Parameters && CC_ECC_Parameters == YES
    784 #define TPM_CC_ECC_Parameters                 (TPM_CC)(0x00000178)
    785 #endif
    786 #if defined CC_FirmwareRead && CC_FirmwareRead == YES
    787 #define TPM_CC_FirmwareRead                   (TPM_CC)(0x00000179)
    788 #endif
    789 #if defined CC_GetCapability && CC_GetCapability == YES
    790 #define TPM_CC_GetCapability                  (TPM_CC)(0x0000017A)
    791 #endif
    792 #if defined CC_GetRandom && CC_GetRandom == YES
    793 #define TPM_CC_GetRandom                      (TPM_CC)(0x0000017B)
    794 #endif
    795 #if defined CC_GetTestResult && CC_GetTestResult == YES
    796 #define TPM_CC_GetTestResult                  (TPM_CC)(0x0000017C)
    797 #endif
    798 #if defined CC_Hash && CC_Hash == YES
    799 #define TPM_CC_Hash                           (TPM_CC)(0x0000017D)
    800 #endif
    801 #if defined CC_PCR_Read && CC_PCR_Read == YES
    802 #define TPM_CC_PCR_Read                       (TPM_CC)(0x0000017E)
    803 #endif
    804 #if defined CC_PolicyPCR && CC_PolicyPCR == YES
    805 #define TPM_CC_PolicyPCR                      (TPM_CC)(0x0000017F)
    806 #endif
    807 #if defined CC_PolicyRestart && CC_PolicyRestart == YES
    808 #define TPM_CC_PolicyRestart                  (TPM_CC)(0x00000180)
    809 #endif
    810 #if defined CC_ReadClock && CC_ReadClock == YES
    811 #define TPM_CC_ReadClock                      (TPM_CC)(0x00000181)
    812 #endif
    813 #if defined CC_PCR_Extend && CC_PCR_Extend == YES
    814 #define TPM_CC_PCR_Extend                     (TPM_CC)(0x00000182)
    815 #endif
    816 #if defined CC_PCR_SetAuthValue && CC_PCR_SetAuthValue == YES
    817 #define TPM_CC_PCR_SetAuthValue               (TPM_CC)(0x00000183)
    818 #endif
    819 #if defined CC_NV_Certify && CC_NV_Certify == YES
    820 #define TPM_CC_NV_Certify                     (TPM_CC)(0x00000184)
    821 #endif
    822 #if defined CC_EventSequenceComplete && CC_EventSequenceComplete == YES
    823 #define TPM_CC_EventSequenceComplete          (TPM_CC)(0x00000185)
    824 #endif
    825 #if defined CC_HashSequenceStart && CC_HashSequenceStart == YES
    826 #define TPM_CC_HashSequenceStart              (TPM_CC)(0x00000186)
    827 #endif
    828 #if defined CC_PolicyPhysicalPresence && CC_PolicyPhysicalPresence == YES
    829 #define TPM_CC_PolicyPhysicalPresence         (TPM_CC)(0x00000187)
    830 #endif
    831 #if defined CC_PolicyDuplicationSelect && CC_PolicyDuplicationSelect == YES
    832 #define TPM_CC_PolicyDuplicationSelect        (TPM_CC)(0x00000188)
    833 #endif
    834 #if defined CC_PolicyGetDigest && CC_PolicyGetDigest == YES
    835 #define TPM_CC_PolicyGetDigest                (TPM_CC)(0x00000189)
    836 #endif
    837 #if defined CC_TestParms && CC_TestParms == YES
    838 #define TPM_CC_TestParms                      (TPM_CC)(0x0000018A)
    839 #endif
    840 #if defined CC_Commit && CC_Commit == YES
    841 #define TPM_CC_Commit                         (TPM_CC)(0x0000018B)
    842 #endif
    843 #if defined CC_PolicyPassword && CC_PolicyPassword == YES
    844 #define TPM_CC_PolicyPassword                 (TPM_CC)(0x0000018C)
    845 #endif
    846 #if defined CC_ZGen_2Phase && CC_ZGen_2Phase == YES
    847 #define TPM_CC_ZGen_2Phase                    (TPM_CC)(0x0000018D)
    848 #endif
    849 #if defined CC_EC_Ephemeral && CC_EC_Ephemeral == YES
    850 #define TPM_CC_EC_Ephemeral                   (TPM_CC)(0x0000018E)
    851 #endif
    852 #if defined CC_PolicyNvWritten && CC_PolicyNvWritten == YES
    853 #define TPM_CC_PolicyNvWritten                (TPM_CC)(0x0000018F)
    854 #endif
    855 #define TPM_CC_LAST                           (TPM_CC)(0x0000018F)
    856 #ifndef MAX
    857 #define MAX(a, b) ((a) > (b) ? (a) : (b))
    858 #endif
    859 #define MAX_HASH_BLOCK_SIZE (                    \
    860    MAX(ALG_SHA1 * SHA1_BLOCK_SIZE,              \
    861    MAX(ALG_SHA256 * SHA256_BLOCK_SIZE,          \
    862    MAX(ALG_SHA384 * SHA384_BLOCK_SIZE,          \
    863    MAX(ALG_SM3_256 * SM3_256_BLOCK_SIZE,        \
    864    MAX(ALG_SHA512 * SHA512_BLOCK_SIZE,          \
    865    0 ))))))
    866 #define MAX_DIGEST_SIZE      (                   \
    867    MAX(ALG_SHA1 * SHA1_DIGEST_SIZE,             \
    868    MAX(ALG_SHA256 * SHA256_DIGEST_SIZE,         \
    869    MAX(ALG_SHA384 * SHA384_DIGEST_SIZE,         \
    870    MAX(ALG_SM3_256 * SM3_256_DIGEST_SIZE,       \
    871    MAX(ALG_SHA512 * SHA512_DIGEST_SIZE,         \
    872    0 ))))))
    873 #if MAX_DIGEST_SIZE == 0 || MAX_HASH_BLOCK_SIZE == 0
    874 #error "Hash data not valid"
    875 #endif
    876 #define HASH_COUNT (ALG_SHA1+ALG_SHA256+ALG_SHA384+ALG_SM3_256+ALG_SHA512)
    877 //
    878 //      Define the 2B structure that would hold any hash block
    879 //
    880 TPM2B_TYPE(MAX_HASH_BLOCK, MAX_HASH_BLOCK_SIZE);
    881 //
    882 //      Folloing typedef is for some old code
    883 //
    884 typedef TPM2B_MAX_HASH_BLOCK    TPM2B_HASH_BLOCK;
    885 #ifndef MAX
    886 #define MAX(a, b) ((a) > (b) ? (a) : (b))
    887 #endif
    888 #ifndef ALG_CAMELLIA
    889 #   define ALG_CAMELLIA         NO
    890 #endif
    891 #ifndef MAX_CAMELLIA_KEY_BITS
    892 #   define      MAX_CAMELLIA_KEY_BITS 0
    893 #   define      MAX_CAMELLIA_BLOCK_SIZE_BYTES 0
    894 #endif
    895 #ifndef ALG_SM4
    896 #   define ALG_SM4         NO
    897 #endif
    898 #ifndef MAX_SM4_KEY_BITS
    899 #   define      MAX_SM4_KEY_BITS 0
    900 #   define      MAX_SM4_BLOCK_SIZE_BYTES 0
    901 #endif
    902 #ifndef ALG_AES
    903 #   define ALG_AES         NO
    904 #endif
    905 #ifndef MAX_AES_KEY_BITS
    906 #   define      MAX_AES_KEY_BITS 0
    907 #   define      MAX_AES_BLOCK_SIZE_BYTES 0
    908 #endif
    909 #define MAX_SYM_KEY_BITS (                                \
    910            MAX(MAX_CAMELLIA_KEY_BITS * ALG_CAMELLIA,            \
    911            MAX(MAX_SM4_KEY_BITS * ALG_SM4,           \
    912            MAX(MAX_AES_KEY_BITS * ALG_AES,           \
    913            0))))
    914 #define MAX_SYM_KEY_BYTES ((MAX_SYM_KEY_BITS + 7) / 8)
    915 #define MAX_SYM_BLOCK_SIZE (                              \
    916            MAX(MAX_CAMELLIA_BLOCK_SIZE_BYTES * ALG_CAMELLIA,    \
    917            MAX(MAX_SM4_BLOCK_SIZE_BYTES * ALG_SM4,   \
    918            MAX(MAX_AES_BLOCK_SIZE_BYTES * ALG_AES,   \
    919            0))))
    920 #if MAX_SYM_KEY_BITS == 0 || MAX_SYM_BLOCK_SIZE == 0
    921 #   error Bad size for MAX_SYM_KEY_BITS or MAX_SYM_BLOCK_SIZE
    922 #endif
    923 //
    924 //      Define the 2B structure for a seed
    925 //
    926 TPM2B_TYPE(SEED, PRIMARY_SEED_SIZE);
    927 
    928 #define UNREFERENCED_PARAMETER(x) (void)(x)
    929 #endif // _IMPLEMENTATION_H_
    930