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