1 /* Microsoft Reference Implementation for TPM 2.0 2 * 3 * The copyright in this software is being made available under the BSD License, 4 * included below. This software may be subject to other third party and 5 * contributor rights, including patent rights, and no such rights are granted 6 * under this license. 7 * 8 * Copyright (c) Microsoft Corporation 9 * 10 * All rights reserved. 11 * 12 * BSD License 13 * 14 * Redistribution and use in source and binary forms, with or without modification, 15 * are permitted provided that the following conditions are met: 16 * 17 * Redistributions of source code must retain the above copyright notice, this list 18 * of conditions and the following disclaimer. 19 * 20 * Redistributions in binary form must reproduce the above copyright notice, this 21 * list of conditions and the following disclaimer in the documentation and/or 22 * other materials provided with the distribution. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 28 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 31 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 #ifndef _IMPLEMENTATION_H_ 37 #define _IMPLEMENTATION_H_ 38 39 #include "RuntimeSupport.h" 40 41 #include <TpmBuildSwitches.h> 42 #include <BaseTypes.h> 43 #include <TPMB.h> 44 45 #undef TRUE 46 #undef FALSE 47 48 #undef MAX 49 #define MAX(a, b) ((a) > (b) ? (a) : (b)) 50 51 #undef MIN 52 #define MIN(a, b) ((a) < (b) ? (a) : (b)) 53 54 // Table 2:3 - Definition of Base Types 55 // Base Types are in BaseTypes.h 56 57 // Table 2:4 - Defines for Logic Values 58 #define TRUE 1 59 #define FALSE 0 60 #define YES 1 61 #define NO 0 62 #define SET 1 63 #define CLEAR 0 64 65 // Table 0:1 - Defines for Processor Values 66 #ifndef BIG_ENDIAN_TPM 67 #define BIG_ENDIAN_TPM NO 68 #endif // BIG_ENDIAN_TPM 69 #define LITTLE_ENDIAN_TPM !BIG_ENDIAN_TPM 70 #ifndef MOST_SIGNIFICANT_BIT_0 71 #define MOST_SIGNIFICANT_BIT_0 NO 72 #endif // MOST_SIGNIFICANT_BIT_0 73 #define LEAST_SIGNIFICANT_BIT_0 !MOST_SIGNIFICANT_BIT_0 74 #ifndef AUTO_ALIGN 75 #define AUTO_ALIGN NO 76 #endif // AUTO_ALIGN 77 78 // Table 0:3 - Defines for Key Size Constants 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 85 #define TDES_KEY_SIZES_BITS {128,192} 86 #define TDES_KEY_SIZE_BITS_128 TDES_ALLOWED_KEY_SIZE_128 87 #define TDES_KEY_SIZE_BITS_192 TDES_ALLOWED_KEY_SIZE_192 88 #define MAX_TDES_KEY_BITS 192 89 #define MAX_TDES_KEY_BYTES 24 90 #define MAX_TDES_BLOCK_SIZE_BYTES \ 91 MAX(TDES_128_BLOCK_SIZE_BYTES, MAX(TDES_192_BLOCK_SIZE_BYTES, 0)) 92 93 #define AES_KEY_SIZES_BITS {128,256} 94 #define AES_KEY_SIZE_BITS_128 AES_ALLOWED_KEY_SIZE_128 95 #define AES_KEY_SIZE_BITS_256 AES_ALLOWED_KEY_SIZE_256 96 #define MAX_AES_KEY_BITS 256 97 #define MAX_AES_KEY_BYTES 32 98 #define MAX_AES_BLOCK_SIZE_BYTES \ 99 MAX(AES_128_BLOCK_SIZE_BYTES, MAX(AES_256_BLOCK_SIZE_BYTES, 0)) 100 101 #define SM4_KEY_SIZES_BITS {128} 102 #define SM4_KEY_SIZE_BITS_128 SM4_ALLOWED_KEY_SIZE_128 103 #define MAX_SM4_KEY_BITS 128 104 #define MAX_SM4_KEY_BYTES 16 105 #define MAX_SM4_BLOCK_SIZE_BYTES MAX(SM4_128_BLOCK_SIZE_BYTES, 0) 106 107 #define CAMELLIA_KEY_SIZES_BITS {128} 108 #define CAMELLIA_KEY_SIZE_BITS_128 CAMELLIA_ALLOWED_KEY_SIZE_128 109 #define MAX_CAMELLIA_KEY_BITS 128 110 #define MAX_CAMELLIA_KEY_BYTES 16 111 #define MAX_CAMELLIA_BLOCK_SIZE_BYTES MAX(CAMELLIA_128_BLOCK_SIZE_BYTES, 0) 112 113 // Table 0:4 - Defines for Implemented Curves 114 #define ECC_NIST_P192 NO 115 #define ECC_NIST_P224 NO 116 #define ECC_NIST_P256 YES 117 #define ECC_NIST_P384 YES 118 #define ECC_NIST_P521 YES 119 #ifdef USE_WOLFCRYPT 120 #define ECC_BN_P256 NO 121 #define ECC_SM2_P256 NO 122 #else 123 #define ECC_BN_P256 YES 124 #define ECC_SM2_P256 YES 125 #endif 126 #define ECC_BN_P638 NO 127 #define ECC_CURVES \ 128 {TPM_ECC_BN_P256, TPM_ECC_BN_P638, TPM_ECC_NIST_P192, \ 129 TPM_ECC_NIST_P224, TPM_ECC_NIST_P256, TPM_ECC_NIST_P384, \ 130 TPM_ECC_NIST_P521, TPM_ECC_SM2_P256} 131 #define ECC_CURVE_COUNT \ 132 (ECC_BN_P256 + ECC_BN_P638 + ECC_NIST_P192 + ECC_NIST_P224 + \ 133 ECC_NIST_P256 + ECC_NIST_P384 + ECC_NIST_P521 + ECC_SM2_P256) 134 #define MAX_ECC_KEY_BITS \ 135 MAX(ECC_BN_P256 * 256, MAX(ECC_BN_P638 * 638, \ 136 MAX(ECC_NIST_P192 * 192, MAX(ECC_NIST_P224 * 224, \ 137 MAX(ECC_NIST_P256 * 256, MAX(ECC_NIST_P384 * 384, \ 138 MAX(ECC_NIST_P521 * 521, MAX(ECC_SM2_P256 * 256, \ 139 0)))))))) 140 #define MAX_ECC_KEY_BYTES BITS_TO_BYTES(MAX_ECC_KEY_BITS) 141 142 // Table 0:6 - Defines for PLATFORM Values 143 #define PLATFORM_FAMILY TPM_SPEC_FAMILY 144 #define PLATFORM_LEVEL TPM_SPEC_LEVEL 145 #define PLATFORM_VERSION TPM_SPEC_VERSION 146 #define PLATFORM_YEAR TPM_SPEC_YEAR 147 #define PLATFORM_DAY_OF_YEAR TPM_SPEC_DAY_OF_YEAR 148 149 // Table 0:7 - Defines for Implementation Values 150 #define FIELD_UPGRADE_IMPLEMENTED NO 151 #define RADIX_BITS 32 152 #define HASH_ALIGNMENT 4 153 #define SYMMETRIC_ALIGNMENT 4 154 #ifdef USE_WOLFCRYPT 155 #define HASH_LIB WOLF 156 #define SYM_LIB WOLF 157 #define MATH_LIB WOLF 158 #else 159 #define HASH_LIB OSSL 160 #define SYM_LIB OSSL 161 #define MATH_LIB OSSL 162 #endif 163 #define BSIZE UINT16 164 #define IMPLEMENTATION_PCR 24 165 #define PLATFORM_PCR 24 166 #define DRTM_PCR 17 167 #define HCRTM_PCR 0 168 #define NUM_LOCALITIES 5 169 #define MAX_HANDLE_NUM 3 170 #define MAX_ACTIVE_SESSIONS 64 171 #define CONTEXT_SLOT UINT16 172 #define CONTEXT_COUNTER UINT64 173 #define MAX_LOADED_SESSIONS 3 174 #define MAX_SESSION_NUM 3 175 #define MAX_LOADED_OBJECTS 3 176 #define MIN_EVICT_OBJECTS 2 177 #define NUM_POLICY_PCR_GROUP 1 178 #define NUM_AUTHVALUE_PCR_GROUP 1 179 #define MAX_CONTEXT_SIZE 2474 180 #define MAX_DIGEST_BUFFER 1024 181 #define MAX_NV_INDEX_SIZE 2048 182 #define MAX_NV_BUFFER_SIZE 1024 183 #define MAX_CAP_BUFFER 1024 184 #define NV_MEMORY_SIZE 16384 185 #define MIN_COUNTER_INDICES 8 186 #define NUM_STATIC_PCR 16 187 #define MAX_ALG_LIST_SIZE 64 188 #define PRIMARY_SEED_SIZE 32 189 #define CONTEXT_ENCRYPT_ALGORITHM AES 190 #define NV_CLOCK_UPDATE_INTERVAL 12 191 #define NUM_POLICY_PCR 1 192 #define MAX_COMMAND_SIZE 4096 193 #define MAX_RESPONSE_SIZE 4096 194 #define ORDERLY_BITS 8 195 #define MAX_SYM_DATA 128 196 #define MAX_RNG_ENTROPY_SIZE 64 197 #define RAM_INDEX_SPACE 512 198 #define RSA_DEFAULT_PUBLIC_EXPONENT 0x00010001 199 #define ENABLE_PCR_NO_INCREMENT YES 200 #define CRT_FORMAT_RSA YES 201 #define VENDOR_COMMAND_COUNT 0 202 #define MAX_VENDOR_BUFFER_SIZE 1024 203 #define TPM_MAX_DERIVATION_BITS 8192 204 205 // Table 0:2 - Defines for Implemented Algorithms 206 #define ALG_AES ALG_YES 207 #define ALG_CAMELLIA ALG_NO /* Not specified by vendor */ 208 #define ALG_CBC ALG_YES 209 #define ALG_CFB ALG_YES 210 #define ALG_CMAC ALG_YES 211 #define ALG_CTR ALG_YES 212 #define ALG_ECB ALG_YES 213 #define ALG_ECC ALG_YES 214 #define ALG_ECDAA (ALG_YES && ALG_ECC) 215 #define ALG_ECDH (ALG_YES && ALG_ECC) 216 #define ALG_ECDSA (ALG_YES && ALG_ECC) 217 #define ALG_ECMQV (ALG_NO && ALG_ECC) 218 #define ALG_ECSCHNORR (ALG_YES && ALG_ECC) 219 #define ALG_HMAC ALG_YES 220 #define ALG_KDF1_SP800_108 ALG_YES 221 #define ALG_KDF1_SP800_56A (ALG_YES && ALG_ECC) 222 #define ALG_KDF2 ALG_NO 223 #define ALG_KEYEDHASH ALG_YES 224 #define ALG_MGF1 ALG_YES 225 #define ALG_OAEP (ALG_YES && ALG_RSA) 226 #define ALG_OFB ALG_YES 227 #define ALG_RSA ALG_YES 228 #define ALG_RSAES (ALG_YES && ALG_RSA) 229 #define ALG_RSAPSS (ALG_YES && ALG_RSA) 230 #define ALG_RSASSA (ALG_YES && ALG_RSA) 231 #define ALG_SHA ALG_NO /* Not specified by vendor */ 232 #define ALG_SHA1 ALG_YES 233 #define ALG_SHA256 ALG_YES 234 #define ALG_SHA384 ALG_YES 235 #define ALG_SHA512 ALG_YES 236 #define ALG_SM2 (ALG_NO && ALG_ECC) 237 #define ALG_SM3_256 ALG_NO 238 #define ALG_SM4 ALG_NO 239 #define ALG_SYMCIPHER ALG_YES 240 #define ALG_TDES ALG_NO 241 #define ALG_XOR ALG_YES 242 243 // Table 1:2 - Definition of TPM_ALG_ID Constants 244 typedef UINT16 TPM_ALG_ID; 245 #define ALG_ERROR_VALUE 0x0000 246 #define TPM_ALG_ERROR (TPM_ALG_ID)(ALG_ERROR_VALUE) 247 #define ALG_RSA_VALUE 0x0001 248 #if ALG_RSA 249 #define TPM_ALG_RSA (TPM_ALG_ID)(ALG_RSA_VALUE) 250 #endif // ALG_RSA 251 #define ALG_TDES_VALUE 0x0003 252 #if ALG_TDES 253 #define TPM_ALG_TDES (TPM_ALG_ID)(ALG_TDES_VALUE) 254 #endif // ALG_TDES 255 #define ALG_SHA_VALUE 0x0004 256 #if ALG_SHA 257 #define TPM_ALG_SHA (TPM_ALG_ID)(ALG_SHA_VALUE) 258 #endif // ALG_SHA 259 #define ALG_SHA1_VALUE 0x0004 260 #if ALG_SHA1 261 #define TPM_ALG_SHA1 (TPM_ALG_ID)(ALG_SHA1_VALUE) 262 #endif // ALG_SHA1 263 #define ALG_HMAC_VALUE 0x0005 264 #if ALG_HMAC 265 #define TPM_ALG_HMAC (TPM_ALG_ID)(ALG_HMAC_VALUE) 266 #endif // ALG_HMAC 267 #define ALG_AES_VALUE 0x0006 268 #if ALG_AES 269 #define TPM_ALG_AES (TPM_ALG_ID)(ALG_AES_VALUE) 270 #endif // ALG_AES 271 #define ALG_MGF1_VALUE 0x0007 272 #if ALG_MGF1 273 #define TPM_ALG_MGF1 (TPM_ALG_ID)(ALG_MGF1_VALUE) 274 #endif // ALG_MGF1 275 #define ALG_KEYEDHASH_VALUE 0x0008 276 #if ALG_KEYEDHASH 277 #define TPM_ALG_KEYEDHASH (TPM_ALG_ID)(ALG_KEYEDHASH_VALUE) 278 #endif // ALG_KEYEDHASH 279 #define ALG_XOR_VALUE 0x000A 280 #if ALG_XOR 281 #define TPM_ALG_XOR (TPM_ALG_ID)(ALG_XOR_VALUE) 282 #endif // ALG_XOR 283 #define ALG_SHA256_VALUE 0x000B 284 #if ALG_SHA256 285 #define TPM_ALG_SHA256 (TPM_ALG_ID)(ALG_SHA256_VALUE) 286 #endif // ALG_SHA256 287 #define ALG_SHA384_VALUE 0x000C 288 #if ALG_SHA384 289 #define TPM_ALG_SHA384 (TPM_ALG_ID)(ALG_SHA384_VALUE) 290 #endif // ALG_SHA384 291 #define ALG_SHA512_VALUE 0x000D 292 #if ALG_SHA512 293 #define TPM_ALG_SHA512 (TPM_ALG_ID)(ALG_SHA512_VALUE) 294 #endif // ALG_SHA512 295 #define ALG_NULL_VALUE 0x0010 296 #define TPM_ALG_NULL (TPM_ALG_ID)(ALG_NULL_VALUE) 297 #define ALG_SM3_256_VALUE 0x0012 298 #if ALG_SM3_256 299 #define TPM_ALG_SM3_256 (TPM_ALG_ID)(ALG_SM3_256_VALUE) 300 #endif // ALG_SM3_256 301 #define ALG_SM4_VALUE 0x0013 302 #if ALG_SM4 303 #define TPM_ALG_SM4 (TPM_ALG_ID)(ALG_SM4_VALUE) 304 #endif // ALG_SM4 305 #define ALG_RSASSA_VALUE 0x0014 306 #if ALG_RSASSA 307 #define TPM_ALG_RSASSA (TPM_ALG_ID)(ALG_RSASSA_VALUE) 308 #endif // ALG_RSASSA 309 #define ALG_RSAES_VALUE 0x0015 310 #if ALG_RSAES 311 #define TPM_ALG_RSAES (TPM_ALG_ID)(ALG_RSAES_VALUE) 312 #endif // ALG_RSAES 313 #define ALG_RSAPSS_VALUE 0x0016 314 #if ALG_RSAPSS 315 #define TPM_ALG_RSAPSS (TPM_ALG_ID)(ALG_RSAPSS_VALUE) 316 #endif // ALG_RSAPSS 317 #define ALG_OAEP_VALUE 0x0017 318 #if ALG_OAEP 319 #define TPM_ALG_OAEP (TPM_ALG_ID)(ALG_OAEP_VALUE) 320 #endif // ALG_OAEP 321 #define ALG_ECDSA_VALUE 0x0018 322 #if ALG_ECDSA 323 #define TPM_ALG_ECDSA (TPM_ALG_ID)(ALG_ECDSA_VALUE) 324 #endif // ALG_ECDSA 325 #define ALG_ECDH_VALUE 0x0019 326 #if ALG_ECDH 327 #define TPM_ALG_ECDH (TPM_ALG_ID)(ALG_ECDH_VALUE) 328 #endif // ALG_ECDH 329 #define ALG_ECDAA_VALUE 0x001A 330 #if ALG_ECDAA 331 #define TPM_ALG_ECDAA (TPM_ALG_ID)(ALG_ECDAA_VALUE) 332 #endif // ALG_ECDAA 333 #define ALG_SM2_VALUE 0x001B 334 #if ALG_SM2 335 #define TPM_ALG_SM2 (TPM_ALG_ID)(ALG_SM2_VALUE) 336 #endif // ALG_SM2 337 #define ALG_ECSCHNORR_VALUE 0x001C 338 #if ALG_ECSCHNORR 339 #define TPM_ALG_ECSCHNORR (TPM_ALG_ID)(ALG_ECSCHNORR_VALUE) 340 #endif // ALG_ECSCHNORR 341 #define ALG_ECMQV_VALUE 0x001D 342 #if ALG_ECMQV 343 #define TPM_ALG_ECMQV (TPM_ALG_ID)(ALG_ECMQV_VALUE) 344 #endif // ALG_ECMQV 345 #define ALG_KDF1_SP800_56A_VALUE 0x0020 346 #if ALG_KDF1_SP800_56A 347 #define TPM_ALG_KDF1_SP800_56A (TPM_ALG_ID)(ALG_KDF1_SP800_56A_VALUE) 348 #endif // ALG_KDF1_SP800_56A 349 #define ALG_KDF2_VALUE 0x0021 350 #if ALG_KDF2 351 #define TPM_ALG_KDF2 (TPM_ALG_ID)(ALG_KDF2_VALUE) 352 #endif // ALG_KDF2 353 #define ALG_KDF1_SP800_108_VALUE 0x0022 354 #if ALG_KDF1_SP800_108 355 #define TPM_ALG_KDF1_SP800_108 (TPM_ALG_ID)(ALG_KDF1_SP800_108_VALUE) 356 #endif // ALG_KDF1_SP800_108 357 #define ALG_ECC_VALUE 0x0023 358 #if ALG_ECC 359 #define TPM_ALG_ECC (TPM_ALG_ID)(ALG_ECC_VALUE) 360 #endif // ALG_ECC 361 #define ALG_SYMCIPHER_VALUE 0x0025 362 #if ALG_SYMCIPHER 363 #define TPM_ALG_SYMCIPHER (TPM_ALG_ID)(ALG_SYMCIPHER_VALUE) 364 #endif // ALG_SYMCIPHER 365 #define ALG_CAMELLIA_VALUE 0x0026 366 #if ALG_CAMELLIA 367 #define TPM_ALG_CAMELLIA (TPM_ALG_ID)(ALG_CAMELLIA_VALUE) 368 #endif // ALG_CAMELLIA 369 #define ALG_CMAC_VALUE 0x003F 370 #if ALG_CMAC 371 #define TPM_ALG_CMAC (TPM_ALG_ID)(ALG_CMAC_VALUE) 372 #endif // ALG_CMAC 373 #define ALG_CTR_VALUE 0x0040 374 #if ALG_CTR 375 #define TPM_ALG_CTR (TPM_ALG_ID)(ALG_CTR_VALUE) 376 #endif // ALG_CTR 377 #define ALG_OFB_VALUE 0x0041 378 #if ALG_OFB 379 #define TPM_ALG_OFB (TPM_ALG_ID)(ALG_OFB_VALUE) 380 #endif // ALG_OFB 381 #define ALG_CBC_VALUE 0x0042 382 #if ALG_CBC 383 #define TPM_ALG_CBC (TPM_ALG_ID)(ALG_CBC_VALUE) 384 #endif // ALG_CBC 385 #define ALG_CFB_VALUE 0x0043 386 #if ALG_CFB 387 #define TPM_ALG_CFB (TPM_ALG_ID)(ALG_CFB_VALUE) 388 #endif // ALG_CFB 389 #define ALG_ECB_VALUE 0x0044 390 #if ALG_ECB 391 #define TPM_ALG_ECB (TPM_ALG_ID)(ALG_ECB_VALUE) 392 #endif // ALG_ECB 393 // Values derived from Table 1:2 394 #define ALG_FIRST_VALUE 0x0001 395 #define TPM_ALG_FIRST (TPM_ALG_ID)(ALG_FIRST_VALUE) 396 #define ALG_LAST_VALUE 0x0044 397 #define TPM_ALG_LAST (TPM_ALG_ID)(ALG_LAST_VALUE) 398 399 // Table 1:3 - Definition of TPM_ECC_CURVE Constants 400 typedef UINT16 TPM_ECC_CURVE; 401 #define TPM_ECC_NONE (TPM_ECC_CURVE)(0x0000) 402 #define TPM_ECC_NIST_P192 (TPM_ECC_CURVE)(0x0001) 403 #define TPM_ECC_NIST_P224 (TPM_ECC_CURVE)(0x0002) 404 #define TPM_ECC_NIST_P256 (TPM_ECC_CURVE)(0x0003) 405 #define TPM_ECC_NIST_P384 (TPM_ECC_CURVE)(0x0004) 406 #define TPM_ECC_NIST_P521 (TPM_ECC_CURVE)(0x0005) 407 #define TPM_ECC_BN_P256 (TPM_ECC_CURVE)(0x0010) 408 #define TPM_ECC_BN_P638 (TPM_ECC_CURVE)(0x0011) 409 #define TPM_ECC_SM2_P256 (TPM_ECC_CURVE)(0x0020) 410 411 // Table 1:12 - Defines for SHA1 Hash Values 412 #define SHA1_DIGEST_SIZE 20 413 #define SHA1_BLOCK_SIZE 64 414 #define SHA1_DER_SIZE 15 415 #define SHA1_DER \ 416 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, \ 417 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14 418 419 // Table 1:13 - Defines for SHA256 Hash Values 420 #define SHA256_DIGEST_SIZE 32 421 #define SHA256_BLOCK_SIZE 64 422 #define SHA256_DER_SIZE 19 423 #define SHA256_DER \ 424 0x30, 0x31, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, \ 425 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, \ 426 0x00, 0x04, 0x20 427 428 // Table 1:14 - Defines for SHA384 Hash Values 429 #define SHA384_DIGEST_SIZE 48 430 #define SHA384_BLOCK_SIZE 128 431 #define SHA384_DER_SIZE 19 432 #define SHA384_DER \ 433 0x30, 0x41, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, \ 434 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, \ 435 0x00, 0x04, 0x30 436 437 // Table 1:15 - Defines for SHA512 Hash Values 438 #define SHA512_DIGEST_SIZE 64 439 #define SHA512_BLOCK_SIZE 128 440 #define SHA512_DER_SIZE 19 441 #define SHA512_DER \ 442 0x30, 0x51, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, \ 443 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, \ 444 0x00, 0x04, 0x40 445 446 // Table 1:16 - Defines for SM3_256 Hash Values 447 #define SM3_256_DIGEST_SIZE 32 448 #define SM3_256_BLOCK_SIZE 64 449 #define SM3_256_DER_SIZE 18 450 #define SM3_256_DER \ 451 0x30, 0x30, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x81, \ 452 0x1C, 0x81, 0x45, 0x01, 0x83, 0x11, 0x05, 0x00, \ 453 0x04, 0x20 454 455 // Table 1:17 - Defines for AES Symmetric Cipher Algorithm Constants 456 #define AES_ALLOWED_KEY_SIZE_128 YES 457 #define AES_ALLOWED_KEY_SIZE_192 YES 458 #define AES_ALLOWED_KEY_SIZE_256 YES 459 #define AES_128_BLOCK_SIZE_BYTES 16 460 #define AES_192_BLOCK_SIZE_BYTES 16 461 #define AES_256_BLOCK_SIZE_BYTES 16 462 463 // Table 1:18 - Defines for SM4 Symmetric Cipher Algorithm Constants 464 #define SM4_ALLOWED_KEY_SIZE_128 YES 465 #define SM4_128_BLOCK_SIZE_BYTES 16 466 467 // Table 1:19 - Defines for CAMELLIA Symmetric Cipher Algorithm Constants 468 #define CAMELLIA_ALLOWED_KEY_SIZE_128 YES 469 #define CAMELLIA_ALLOWED_KEY_SIZE_192 YES 470 #define CAMELLIA_ALLOWED_KEY_SIZE_256 YES 471 #define CAMELLIA_128_BLOCK_SIZE_BYTES 16 472 #define CAMELLIA_192_BLOCK_SIZE_BYTES 16 473 #define CAMELLIA_256_BLOCK_SIZE_BYTES 16 474 475 // Table 1:17 - Defines for TDES Symmetric Cipher Algorithm Constants 476 #define TDES_ALLOWED_KEY_SIZE_128 YES 477 #define TDES_ALLOWED_KEY_SIZE_192 YES 478 #define TDES_128_BLOCK_SIZE_BYTES 8 479 #define TDES_192_BLOCK_SIZE_BYTES 8 480 481 // Table 0:5 - Defines for Implemented Commands 482 #define CC_AC_GetCapability CC_YES 483 #define CC_AC_Send CC_YES 484 #define CC_ActivateCredential CC_YES 485 #define CC_Certify CC_YES 486 #define CC_CertifyCreation CC_YES 487 #define CC_ChangeEPS CC_YES 488 #define CC_ChangePPS CC_YES 489 #define CC_Clear CC_YES 490 #define CC_ClearControl CC_YES 491 #define CC_ClockRateAdjust CC_YES 492 #define CC_ClockSet CC_YES 493 #define CC_Commit (CC_YES && ALG_ECC) 494 #define CC_ContextLoad CC_YES 495 #define CC_ContextSave CC_YES 496 #define CC_Create CC_YES 497 #define CC_CreateLoaded CC_YES 498 #define CC_CreatePrimary CC_YES 499 #define CC_DictionaryAttackLockReset CC_YES 500 #define CC_DictionaryAttackParameters CC_YES 501 #define CC_Duplicate CC_YES 502 #define CC_ECC_Parameters (CC_YES && ALG_ECC) 503 #define CC_ECDH_KeyGen (CC_YES && ALG_ECC) 504 #define CC_ECDH_ZGen (CC_YES && ALG_ECC) 505 #define CC_EC_Ephemeral (CC_YES && ALG_ECC) 506 #define CC_EncryptDecrypt CC_YES 507 #define CC_EncryptDecrypt2 CC_YES 508 #define CC_EventSequenceComplete CC_YES 509 #define CC_EvictControl CC_YES 510 #define CC_FieldUpgradeData CC_NO 511 #define CC_FieldUpgradeStart CC_NO 512 #define CC_FirmwareRead CC_NO 513 #define CC_FlushContext CC_YES 514 #define CC_GetCapability CC_YES 515 #define CC_GetCommandAuditDigest CC_YES 516 #define CC_GetRandom CC_YES 517 #define CC_GetSessionAuditDigest CC_YES 518 #define CC_GetTestResult CC_YES 519 #define CC_GetTime CC_YES 520 #define CC_HMAC (CC_YES && !ALG_CMAC) 521 #define CC_HMAC_Start (CC_YES && !ALG_CMAC) 522 #define CC_Hash CC_YES 523 #define CC_HashSequenceStart CC_YES 524 #define CC_HierarchyChangeAuth CC_YES 525 #define CC_HierarchyControl CC_YES 526 #define CC_Import CC_YES 527 #define CC_IncrementalSelfTest CC_YES 528 #define CC_Load CC_YES 529 #define CC_LoadExternal CC_YES 530 #define CC_MAC (CC_YES && ALG_CMAC) 531 #define CC_MAC_Start (CC_YES && ALG_CMAC) 532 #define CC_MakeCredential CC_YES 533 #define CC_NV_Certify CC_YES 534 #define CC_NV_ChangeAuth CC_YES 535 #define CC_NV_DefineSpace CC_YES 536 #define CC_NV_Extend CC_YES 537 #define CC_NV_GlobalWriteLock CC_YES 538 #define CC_NV_Increment CC_YES 539 #define CC_NV_Read CC_YES 540 #define CC_NV_ReadLock CC_YES 541 #define CC_NV_ReadPublic CC_YES 542 #define CC_NV_SetBits CC_YES 543 #define CC_NV_UndefineSpace CC_YES 544 #define CC_NV_UndefineSpaceSpecial CC_YES 545 #define CC_NV_Write CC_YES 546 #define CC_NV_WriteLock CC_YES 547 #define CC_ObjectChangeAuth CC_YES 548 #define CC_PCR_Allocate CC_YES 549 #define CC_PCR_Event CC_YES 550 #define CC_PCR_Extend CC_YES 551 #define CC_PCR_Read CC_YES 552 #define CC_PCR_Reset CC_YES 553 #define CC_PCR_SetAuthPolicy CC_YES 554 #define CC_PCR_SetAuthValue CC_YES 555 #define CC_PP_Commands CC_YES 556 #define CC_PolicyAuthValue CC_YES 557 #define CC_PolicyAuthorize CC_YES 558 #define CC_PolicyAuthorizeNV CC_YES 559 #define CC_PolicyCommandCode CC_YES 560 #define CC_PolicyCounterTimer CC_YES 561 #define CC_PolicyCpHash CC_YES 562 #define CC_PolicyDuplicationSelect CC_YES 563 #define CC_PolicyGetDigest CC_YES 564 #define CC_PolicyLocality CC_YES 565 #define CC_PolicyNV CC_YES 566 #define CC_PolicyNameHash CC_YES 567 #define CC_PolicyNvWritten CC_YES 568 #define CC_PolicyOR CC_YES 569 #define CC_PolicyPCR CC_YES 570 #define CC_PolicyPassword CC_YES 571 #define CC_PolicyPhysicalPresence CC_YES 572 #define CC_PolicyRestart CC_YES 573 #define CC_PolicySecret CC_YES 574 #define CC_PolicySigned CC_YES 575 #define CC_PolicyTemplate CC_YES 576 #define CC_PolicyTicket CC_YES 577 #define CC_Policy_AC_SendSelect CC_YES 578 #define CC_Quote CC_YES 579 #define CC_RSA_Decrypt (CC_YES && ALG_RSA) 580 #define CC_RSA_Encrypt (CC_YES && ALG_RSA) 581 #define CC_ReadClock CC_YES 582 #define CC_ReadPublic CC_YES 583 #define CC_Rewrap CC_YES 584 #define CC_SelfTest CC_YES 585 #define CC_SequenceComplete CC_YES 586 #define CC_SequenceUpdate CC_YES 587 #define CC_SetAlgorithmSet CC_YES 588 #define CC_SetCommandCodeAuditStatus CC_YES 589 #define CC_SetPrimaryPolicy CC_YES 590 #define CC_Shutdown CC_YES 591 #define CC_Sign CC_YES 592 #define CC_StartAuthSession CC_YES 593 #define CC_Startup CC_YES 594 #define CC_StirRandom CC_YES 595 #define CC_TestParms CC_YES 596 #define CC_Unseal CC_YES 597 #define CC_Vendor_TCG_Test CC_YES 598 #define CC_VerifySignature CC_YES 599 #define CC_ZGen_2Phase (CC_YES && ALG_ECC) 600 601 // Table 2:12 - Definition of TPM_CC Constants 602 typedef UINT32 TPM_CC; 603 #if CC_NV_UndefineSpaceSpecial 604 #define TPM_CC_NV_UndefineSpaceSpecial (TPM_CC)(0x0000011F) 605 #endif 606 #if CC_EvictControl 607 #define TPM_CC_EvictControl (TPM_CC)(0x00000120) 608 #endif 609 #if CC_HierarchyControl 610 #define TPM_CC_HierarchyControl (TPM_CC)(0x00000121) 611 #endif 612 #if CC_NV_UndefineSpace 613 #define TPM_CC_NV_UndefineSpace (TPM_CC)(0x00000122) 614 #endif 615 #if CC_ChangeEPS 616 #define TPM_CC_ChangeEPS (TPM_CC)(0x00000124) 617 #endif 618 #if CC_ChangePPS 619 #define TPM_CC_ChangePPS (TPM_CC)(0x00000125) 620 #endif 621 #if CC_Clear 622 #define TPM_CC_Clear (TPM_CC)(0x00000126) 623 #endif 624 #if CC_ClearControl 625 #define TPM_CC_ClearControl (TPM_CC)(0x00000127) 626 #endif 627 #if CC_ClockSet 628 #define TPM_CC_ClockSet (TPM_CC)(0x00000128) 629 #endif 630 #if CC_HierarchyChangeAuth 631 #define TPM_CC_HierarchyChangeAuth (TPM_CC)(0x00000129) 632 #endif 633 #if CC_NV_DefineSpace 634 #define TPM_CC_NV_DefineSpace (TPM_CC)(0x0000012A) 635 #endif 636 #if CC_PCR_Allocate 637 #define TPM_CC_PCR_Allocate (TPM_CC)(0x0000012B) 638 #endif 639 #if CC_PCR_SetAuthPolicy 640 #define TPM_CC_PCR_SetAuthPolicy (TPM_CC)(0x0000012C) 641 #endif 642 #if CC_PP_Commands 643 #define TPM_CC_PP_Commands (TPM_CC)(0x0000012D) 644 #endif 645 #if CC_SetPrimaryPolicy 646 #define TPM_CC_SetPrimaryPolicy (TPM_CC)(0x0000012E) 647 #endif 648 #if CC_FieldUpgradeStart 649 #define TPM_CC_FieldUpgradeStart (TPM_CC)(0x0000012F) 650 #endif 651 #if CC_ClockRateAdjust 652 #define TPM_CC_ClockRateAdjust (TPM_CC)(0x00000130) 653 #endif 654 #if CC_CreatePrimary 655 #define TPM_CC_CreatePrimary (TPM_CC)(0x00000131) 656 #endif 657 #if CC_NV_GlobalWriteLock 658 #define TPM_CC_NV_GlobalWriteLock (TPM_CC)(0x00000132) 659 #endif 660 #if CC_GetCommandAuditDigest 661 #define TPM_CC_GetCommandAuditDigest (TPM_CC)(0x00000133) 662 #endif 663 #if CC_NV_Increment 664 #define TPM_CC_NV_Increment (TPM_CC)(0x00000134) 665 #endif 666 #if CC_NV_SetBits 667 #define TPM_CC_NV_SetBits (TPM_CC)(0x00000135) 668 #endif 669 #if CC_NV_Extend 670 #define TPM_CC_NV_Extend (TPM_CC)(0x00000136) 671 #endif 672 #if CC_NV_Write 673 #define TPM_CC_NV_Write (TPM_CC)(0x00000137) 674 #endif 675 #if CC_NV_WriteLock 676 #define TPM_CC_NV_WriteLock (TPM_CC)(0x00000138) 677 #endif 678 #if CC_DictionaryAttackLockReset 679 #define TPM_CC_DictionaryAttackLockReset (TPM_CC)(0x00000139) 680 #endif 681 #if CC_DictionaryAttackParameters 682 #define TPM_CC_DictionaryAttackParameters (TPM_CC)(0x0000013A) 683 #endif 684 #if CC_NV_ChangeAuth 685 #define TPM_CC_NV_ChangeAuth (TPM_CC)(0x0000013B) 686 #endif 687 #if CC_PCR_Event 688 #define TPM_CC_PCR_Event (TPM_CC)(0x0000013C) 689 #endif 690 #if CC_PCR_Reset 691 #define TPM_CC_PCR_Reset (TPM_CC)(0x0000013D) 692 #endif 693 #if CC_SequenceComplete 694 #define TPM_CC_SequenceComplete (TPM_CC)(0x0000013E) 695 #endif 696 #if CC_SetAlgorithmSet 697 #define TPM_CC_SetAlgorithmSet (TPM_CC)(0x0000013F) 698 #endif 699 #if CC_SetCommandCodeAuditStatus 700 #define TPM_CC_SetCommandCodeAuditStatus (TPM_CC)(0x00000140) 701 #endif 702 #if CC_FieldUpgradeData 703 #define TPM_CC_FieldUpgradeData (TPM_CC)(0x00000141) 704 #endif 705 #if CC_IncrementalSelfTest 706 #define TPM_CC_IncrementalSelfTest (TPM_CC)(0x00000142) 707 #endif 708 #if CC_SelfTest 709 #define TPM_CC_SelfTest (TPM_CC)(0x00000143) 710 #endif 711 #if CC_Startup 712 #define TPM_CC_Startup (TPM_CC)(0x00000144) 713 #endif 714 #if CC_Shutdown 715 #define TPM_CC_Shutdown (TPM_CC)(0x00000145) 716 #endif 717 #if CC_StirRandom 718 #define TPM_CC_StirRandom (TPM_CC)(0x00000146) 719 #endif 720 #if CC_ActivateCredential 721 #define TPM_CC_ActivateCredential (TPM_CC)(0x00000147) 722 #endif 723 #if CC_Certify 724 #define TPM_CC_Certify (TPM_CC)(0x00000148) 725 #endif 726 #if CC_PolicyNV 727 #define TPM_CC_PolicyNV (TPM_CC)(0x00000149) 728 #endif 729 #if CC_CertifyCreation 730 #define TPM_CC_CertifyCreation (TPM_CC)(0x0000014A) 731 #endif 732 #if CC_Duplicate 733 #define TPM_CC_Duplicate (TPM_CC)(0x0000014B) 734 #endif 735 #if CC_GetTime 736 #define TPM_CC_GetTime (TPM_CC)(0x0000014C) 737 #endif 738 #if CC_GetSessionAuditDigest 739 #define TPM_CC_GetSessionAuditDigest (TPM_CC)(0x0000014D) 740 #endif 741 #if CC_NV_Read 742 #define TPM_CC_NV_Read (TPM_CC)(0x0000014E) 743 #endif 744 #if CC_NV_ReadLock 745 #define TPM_CC_NV_ReadLock (TPM_CC)(0x0000014F) 746 #endif 747 #if CC_ObjectChangeAuth 748 #define TPM_CC_ObjectChangeAuth (TPM_CC)(0x00000150) 749 #endif 750 #if CC_PolicySecret 751 #define TPM_CC_PolicySecret (TPM_CC)(0x00000151) 752 #endif 753 #if CC_Rewrap 754 #define TPM_CC_Rewrap (TPM_CC)(0x00000152) 755 #endif 756 #if CC_Create 757 #define TPM_CC_Create (TPM_CC)(0x00000153) 758 #endif 759 #if CC_ECDH_ZGen 760 #define TPM_CC_ECDH_ZGen (TPM_CC)(0x00000154) 761 #endif 762 #if CC_HMAC 763 #define TPM_CC_HMAC (TPM_CC)(0x00000155) 764 #endif 765 #if CC_MAC 766 #define TPM_CC_MAC (TPM_CC)(0x00000155) 767 #endif 768 #if CC_Import 769 #define TPM_CC_Import (TPM_CC)(0x00000156) 770 #endif 771 #if CC_Load 772 #define TPM_CC_Load (TPM_CC)(0x00000157) 773 #endif 774 #if CC_Quote 775 #define TPM_CC_Quote (TPM_CC)(0x00000158) 776 #endif 777 #if CC_RSA_Decrypt 778 #define TPM_CC_RSA_Decrypt (TPM_CC)(0x00000159) 779 #endif 780 #if CC_HMAC_Start 781 #define TPM_CC_HMAC_Start (TPM_CC)(0x0000015B) 782 #endif 783 #if CC_MAC_Start 784 #define TPM_CC_MAC_Start (TPM_CC)(0x0000015B) 785 #endif 786 #if CC_SequenceUpdate 787 #define TPM_CC_SequenceUpdate (TPM_CC)(0x0000015C) 788 #endif 789 #if CC_Sign 790 #define TPM_CC_Sign (TPM_CC)(0x0000015D) 791 #endif 792 #if CC_Unseal 793 #define TPM_CC_Unseal (TPM_CC)(0x0000015E) 794 #endif 795 #if CC_PolicySigned 796 #define TPM_CC_PolicySigned (TPM_CC)(0x00000160) 797 #endif 798 #if CC_ContextLoad 799 #define TPM_CC_ContextLoad (TPM_CC)(0x00000161) 800 #endif 801 #if CC_ContextSave 802 #define TPM_CC_ContextSave (TPM_CC)(0x00000162) 803 #endif 804 #if CC_ECDH_KeyGen 805 #define TPM_CC_ECDH_KeyGen (TPM_CC)(0x00000163) 806 #endif 807 #if CC_EncryptDecrypt 808 #define TPM_CC_EncryptDecrypt (TPM_CC)(0x00000164) 809 #endif 810 #if CC_FlushContext 811 #define TPM_CC_FlushContext (TPM_CC)(0x00000165) 812 #endif 813 #if CC_LoadExternal 814 #define TPM_CC_LoadExternal (TPM_CC)(0x00000167) 815 #endif 816 #if CC_MakeCredential 817 #define TPM_CC_MakeCredential (TPM_CC)(0x00000168) 818 #endif 819 #if CC_NV_ReadPublic 820 #define TPM_CC_NV_ReadPublic (TPM_CC)(0x00000169) 821 #endif 822 #if CC_PolicyAuthorize 823 #define TPM_CC_PolicyAuthorize (TPM_CC)(0x0000016A) 824 #endif 825 #if CC_PolicyAuthValue 826 #define TPM_CC_PolicyAuthValue (TPM_CC)(0x0000016B) 827 #endif 828 #if CC_PolicyCommandCode 829 #define TPM_CC_PolicyCommandCode (TPM_CC)(0x0000016C) 830 #endif 831 #if CC_PolicyCounterTimer 832 #define TPM_CC_PolicyCounterTimer (TPM_CC)(0x0000016D) 833 #endif 834 #if CC_PolicyCpHash 835 #define TPM_CC_PolicyCpHash (TPM_CC)(0x0000016E) 836 #endif 837 #if CC_PolicyLocality 838 #define TPM_CC_PolicyLocality (TPM_CC)(0x0000016F) 839 #endif 840 #if CC_PolicyNameHash 841 #define TPM_CC_PolicyNameHash (TPM_CC)(0x00000170) 842 #endif 843 #if CC_PolicyOR 844 #define TPM_CC_PolicyOR (TPM_CC)(0x00000171) 845 #endif 846 #if CC_PolicyTicket 847 #define TPM_CC_PolicyTicket (TPM_CC)(0x00000172) 848 #endif 849 #if CC_ReadPublic 850 #define TPM_CC_ReadPublic (TPM_CC)(0x00000173) 851 #endif 852 #if CC_RSA_Encrypt 853 #define TPM_CC_RSA_Encrypt (TPM_CC)(0x00000174) 854 #endif 855 #if CC_StartAuthSession 856 #define TPM_CC_StartAuthSession (TPM_CC)(0x00000176) 857 #endif 858 #if CC_VerifySignature 859 #define TPM_CC_VerifySignature (TPM_CC)(0x00000177) 860 #endif 861 #if CC_ECC_Parameters 862 #define TPM_CC_ECC_Parameters (TPM_CC)(0x00000178) 863 #endif 864 #if CC_FirmwareRead 865 #define TPM_CC_FirmwareRead (TPM_CC)(0x00000179) 866 #endif 867 #if CC_GetCapability 868 #define TPM_CC_GetCapability (TPM_CC)(0x0000017A) 869 #endif 870 #if CC_GetRandom 871 #define TPM_CC_GetRandom (TPM_CC)(0x0000017B) 872 #endif 873 #if CC_GetTestResult 874 #define TPM_CC_GetTestResult (TPM_CC)(0x0000017C) 875 #endif 876 #if CC_Hash 877 #define TPM_CC_Hash (TPM_CC)(0x0000017D) 878 #endif 879 #if CC_PCR_Read 880 #define TPM_CC_PCR_Read (TPM_CC)(0x0000017E) 881 #endif 882 #if CC_PolicyPCR 883 #define TPM_CC_PolicyPCR (TPM_CC)(0x0000017F) 884 #endif 885 #if CC_PolicyRestart 886 #define TPM_CC_PolicyRestart (TPM_CC)(0x00000180) 887 #endif 888 #if CC_ReadClock 889 #define TPM_CC_ReadClock (TPM_CC)(0x00000181) 890 #endif 891 #if CC_PCR_Extend 892 #define TPM_CC_PCR_Extend (TPM_CC)(0x00000182) 893 #endif 894 #if CC_PCR_SetAuthValue 895 #define TPM_CC_PCR_SetAuthValue (TPM_CC)(0x00000183) 896 #endif 897 #if CC_NV_Certify 898 #define TPM_CC_NV_Certify (TPM_CC)(0x00000184) 899 #endif 900 #if CC_EventSequenceComplete 901 #define TPM_CC_EventSequenceComplete (TPM_CC)(0x00000185) 902 #endif 903 #if CC_HashSequenceStart 904 #define TPM_CC_HashSequenceStart (TPM_CC)(0x00000186) 905 #endif 906 #if CC_PolicyPhysicalPresence 907 #define TPM_CC_PolicyPhysicalPresence (TPM_CC)(0x00000187) 908 #endif 909 #if CC_PolicyDuplicationSelect 910 #define TPM_CC_PolicyDuplicationSelect (TPM_CC)(0x00000188) 911 #endif 912 #if CC_PolicyGetDigest 913 #define TPM_CC_PolicyGetDigest (TPM_CC)(0x00000189) 914 #endif 915 #if CC_TestParms 916 #define TPM_CC_TestParms (TPM_CC)(0x0000018A) 917 #endif 918 #if CC_Commit 919 #define TPM_CC_Commit (TPM_CC)(0x0000018B) 920 #endif 921 #if CC_PolicyPassword 922 #define TPM_CC_PolicyPassword (TPM_CC)(0x0000018C) 923 #endif 924 #if CC_ZGen_2Phase 925 #define TPM_CC_ZGen_2Phase (TPM_CC)(0x0000018D) 926 #endif 927 #if CC_EC_Ephemeral 928 #define TPM_CC_EC_Ephemeral (TPM_CC)(0x0000018E) 929 #endif 930 #if CC_PolicyNvWritten 931 #define TPM_CC_PolicyNvWritten (TPM_CC)(0x0000018F) 932 #endif 933 #if CC_PolicyTemplate 934 #define TPM_CC_PolicyTemplate (TPM_CC)(0x00000190) 935 #endif 936 #if CC_CreateLoaded 937 #define TPM_CC_CreateLoaded (TPM_CC)(0x00000191) 938 #endif 939 #if CC_PolicyAuthorizeNV 940 #define TPM_CC_PolicyAuthorizeNV (TPM_CC)(0x00000192) 941 #endif 942 #if CC_EncryptDecrypt2 943 #define TPM_CC_EncryptDecrypt2 (TPM_CC)(0x00000193) 944 #endif 945 #if CC_AC_GetCapability 946 #define TPM_CC_AC_GetCapability (TPM_CC)(0x00000194) 947 #endif 948 #if CC_AC_Send 949 #define TPM_CC_AC_Send (TPM_CC)(0x00000195) 950 #endif 951 #if CC_Policy_AC_SendSelect 952 #define TPM_CC_Policy_AC_SendSelect (TPM_CC)(0x00000196) 953 #endif 954 #define CC_VEND 0x20000000 955 #if CC_Vendor_TCG_Test 956 #define TPM_CC_Vendor_TCG_Test (TPM_CC)(0x20000000) 957 #endif 958 959 // Additional values for benefit of code 960 #define TPM_CC_FIRST 0x0000011F 961 #define TPM_CC_LAST 0x00000196 962 963 964 #if COMPRESSED_LISTS 965 #define ADD_FILL 0 966 #else 967 #define ADD_FILL 1 968 #endif 969 970 // Size the array of library commands based on whether or not 971 // the array is packed (only defined commands) or dense 972 // (having entries for unimplemented commands) 973 #define LIBRARY_COMMAND_ARRAY_SIZE (0 \ 974 + (ADD_FILL || CC_NV_UndefineSpaceSpecial) /* 0x0000011F */ \ 975 + (ADD_FILL || CC_EvictControl) /* 0x00000120 */ \ 976 + (ADD_FILL || CC_HierarchyControl) /* 0x00000121 */ \ 977 + (ADD_FILL || CC_NV_UndefineSpace) /* 0x00000122 */ \ 978 + ADD_FILL /* 0x00000123 */ \ 979 + (ADD_FILL || CC_ChangeEPS) /* 0x00000124 */ \ 980 + (ADD_FILL || CC_ChangePPS) /* 0x00000125 */ \ 981 + (ADD_FILL || CC_Clear) /* 0x00000126 */ \ 982 + (ADD_FILL || CC_ClearControl) /* 0x00000127 */ \ 983 + (ADD_FILL || CC_ClockSet) /* 0x00000128 */ \ 984 + (ADD_FILL || CC_HierarchyChangeAuth) /* 0x00000129 */ \ 985 + (ADD_FILL || CC_NV_DefineSpace) /* 0x0000012A */ \ 986 + (ADD_FILL || CC_PCR_Allocate) /* 0x0000012B */ \ 987 + (ADD_FILL || CC_PCR_SetAuthPolicy) /* 0x0000012C */ \ 988 + (ADD_FILL || CC_PP_Commands) /* 0x0000012D */ \ 989 + (ADD_FILL || CC_SetPrimaryPolicy) /* 0x0000012E */ \ 990 + (ADD_FILL || CC_FieldUpgradeStart) /* 0x0000012F */ \ 991 + (ADD_FILL || CC_ClockRateAdjust) /* 0x00000130 */ \ 992 + (ADD_FILL || CC_CreatePrimary) /* 0x00000131 */ \ 993 + (ADD_FILL || CC_NV_GlobalWriteLock) /* 0x00000132 */ \ 994 + (ADD_FILL || CC_GetCommandAuditDigest) /* 0x00000133 */ \ 995 + (ADD_FILL || CC_NV_Increment) /* 0x00000134 */ \ 996 + (ADD_FILL || CC_NV_SetBits) /* 0x00000135 */ \ 997 + (ADD_FILL || CC_NV_Extend) /* 0x00000136 */ \ 998 + (ADD_FILL || CC_NV_Write) /* 0x00000137 */ \ 999 + (ADD_FILL || CC_NV_WriteLock) /* 0x00000138 */ \ 1000 + (ADD_FILL || CC_DictionaryAttackLockReset) /* 0x00000139 */ \ 1001 + (ADD_FILL || CC_DictionaryAttackParameters) /* 0x0000013A */ \ 1002 + (ADD_FILL || CC_NV_ChangeAuth) /* 0x0000013B */ \ 1003 + (ADD_FILL || CC_PCR_Event) /* 0x0000013C */ \ 1004 + (ADD_FILL || CC_PCR_Reset) /* 0x0000013D */ \ 1005 + (ADD_FILL || CC_SequenceComplete) /* 0x0000013E */ \ 1006 + (ADD_FILL || CC_SetAlgorithmSet) /* 0x0000013F */ \ 1007 + (ADD_FILL || CC_SetCommandCodeAuditStatus) /* 0x00000140 */ \ 1008 + (ADD_FILL || CC_FieldUpgradeData) /* 0x00000141 */ \ 1009 + (ADD_FILL || CC_IncrementalSelfTest) /* 0x00000142 */ \ 1010 + (ADD_FILL || CC_SelfTest) /* 0x00000143 */ \ 1011 + (ADD_FILL || CC_Startup) /* 0x00000144 */ \ 1012 + (ADD_FILL || CC_Shutdown) /* 0x00000145 */ \ 1013 + (ADD_FILL || CC_StirRandom) /* 0x00000146 */ \ 1014 + (ADD_FILL || CC_ActivateCredential) /* 0x00000147 */ \ 1015 + (ADD_FILL || CC_Certify) /* 0x00000148 */ \ 1016 + (ADD_FILL || CC_PolicyNV) /* 0x00000149 */ \ 1017 + (ADD_FILL || CC_CertifyCreation) /* 0x0000014A */ \ 1018 + (ADD_FILL || CC_Duplicate) /* 0x0000014B */ \ 1019 + (ADD_FILL || CC_GetTime) /* 0x0000014C */ \ 1020 + (ADD_FILL || CC_GetSessionAuditDigest) /* 0x0000014D */ \ 1021 + (ADD_FILL || CC_NV_Read) /* 0x0000014E */ \ 1022 + (ADD_FILL || CC_NV_ReadLock) /* 0x0000014F */ \ 1023 + (ADD_FILL || CC_ObjectChangeAuth) /* 0x00000150 */ \ 1024 + (ADD_FILL || CC_PolicySecret) /* 0x00000151 */ \ 1025 + (ADD_FILL || CC_Rewrap) /* 0x00000152 */ \ 1026 + (ADD_FILL || CC_Create) /* 0x00000153 */ \ 1027 + (ADD_FILL || CC_ECDH_ZGen) /* 0x00000154 */ \ 1028 + (ADD_FILL || CC_HMAC || CC_MAC) /* 0x00000155 */ \ 1029 + (ADD_FILL || CC_Import) /* 0x00000156 */ \ 1030 + (ADD_FILL || CC_Load) /* 0x00000157 */ \ 1031 + (ADD_FILL || CC_Quote) /* 0x00000158 */ \ 1032 + (ADD_FILL || CC_RSA_Decrypt) /* 0x00000159 */ \ 1033 + ADD_FILL /* 0x0000015A */ \ 1034 + (ADD_FILL || CC_HMAC_Start || CC_MAC_Start) /* 0x0000015B */ \ 1035 + (ADD_FILL || CC_SequenceUpdate) /* 0x0000015C */ \ 1036 + (ADD_FILL || CC_Sign) /* 0x0000015D */ \ 1037 + (ADD_FILL || CC_Unseal) /* 0x0000015E */ \ 1038 + ADD_FILL /* 0x0000015F */ \ 1039 + (ADD_FILL || CC_PolicySigned) /* 0x00000160 */ \ 1040 + (ADD_FILL || CC_ContextLoad) /* 0x00000161 */ \ 1041 + (ADD_FILL || CC_ContextSave) /* 0x00000162 */ \ 1042 + (ADD_FILL || CC_ECDH_KeyGen) /* 0x00000163 */ \ 1043 + (ADD_FILL || CC_EncryptDecrypt) /* 0x00000164 */ \ 1044 + (ADD_FILL || CC_FlushContext) /* 0x00000165 */ \ 1045 + ADD_FILL /* 0x00000166 */ \ 1046 + (ADD_FILL || CC_LoadExternal) /* 0x00000167 */ \ 1047 + (ADD_FILL || CC_MakeCredential) /* 0x00000168 */ \ 1048 + (ADD_FILL || CC_NV_ReadPublic) /* 0x00000169 */ \ 1049 + (ADD_FILL || CC_PolicyAuthorize) /* 0x0000016A */ \ 1050 + (ADD_FILL || CC_PolicyAuthValue) /* 0x0000016B */ \ 1051 + (ADD_FILL || CC_PolicyCommandCode) /* 0x0000016C */ \ 1052 + (ADD_FILL || CC_PolicyCounterTimer) /* 0x0000016D */ \ 1053 + (ADD_FILL || CC_PolicyCpHash) /* 0x0000016E */ \ 1054 + (ADD_FILL || CC_PolicyLocality) /* 0x0000016F */ \ 1055 + (ADD_FILL || CC_PolicyNameHash) /* 0x00000170 */ \ 1056 + (ADD_FILL || CC_PolicyOR) /* 0x00000171 */ \ 1057 + (ADD_FILL || CC_PolicyTicket) /* 0x00000172 */ \ 1058 + (ADD_FILL || CC_ReadPublic) /* 0x00000173 */ \ 1059 + (ADD_FILL || CC_RSA_Encrypt) /* 0x00000174 */ \ 1060 + ADD_FILL /* 0x00000175 */ \ 1061 + (ADD_FILL || CC_StartAuthSession) /* 0x00000176 */ \ 1062 + (ADD_FILL || CC_VerifySignature) /* 0x00000177 */ \ 1063 + (ADD_FILL || CC_ECC_Parameters) /* 0x00000178 */ \ 1064 + (ADD_FILL || CC_FirmwareRead) /* 0x00000179 */ \ 1065 + (ADD_FILL || CC_GetCapability) /* 0x0000017A */ \ 1066 + (ADD_FILL || CC_GetRandom) /* 0x0000017B */ \ 1067 + (ADD_FILL || CC_GetTestResult) /* 0x0000017C */ \ 1068 + (ADD_FILL || CC_Hash) /* 0x0000017D */ \ 1069 + (ADD_FILL || CC_PCR_Read) /* 0x0000017E */ \ 1070 + (ADD_FILL || CC_PolicyPCR) /* 0x0000017F */ \ 1071 + (ADD_FILL || CC_PolicyRestart) /* 0x00000180 */ \ 1072 + (ADD_FILL || CC_ReadClock) /* 0x00000181 */ \ 1073 + (ADD_FILL || CC_PCR_Extend) /* 0x00000182 */ \ 1074 + (ADD_FILL || CC_PCR_SetAuthValue) /* 0x00000183 */ \ 1075 + (ADD_FILL || CC_NV_Certify) /* 0x00000184 */ \ 1076 + (ADD_FILL || CC_EventSequenceComplete) /* 0x00000185 */ \ 1077 + (ADD_FILL || CC_HashSequenceStart) /* 0x00000186 */ \ 1078 + (ADD_FILL || CC_PolicyPhysicalPresence) /* 0x00000187 */ \ 1079 + (ADD_FILL || CC_PolicyDuplicationSelect) /* 0x00000188 */ \ 1080 + (ADD_FILL || CC_PolicyGetDigest) /* 0x00000189 */ \ 1081 + (ADD_FILL || CC_TestParms) /* 0x0000018A */ \ 1082 + (ADD_FILL || CC_Commit) /* 0x0000018B */ \ 1083 + (ADD_FILL || CC_PolicyPassword) /* 0x0000018C */ \ 1084 + (ADD_FILL || CC_ZGen_2Phase) /* 0x0000018D */ \ 1085 + (ADD_FILL || CC_EC_Ephemeral) /* 0x0000018E */ \ 1086 + (ADD_FILL || CC_PolicyNvWritten) /* 0x0000018F */ \ 1087 + (ADD_FILL || CC_PolicyTemplate) /* 0x00000190 */ \ 1088 + (ADD_FILL || CC_CreateLoaded) /* 0x00000191 */ \ 1089 + (ADD_FILL || CC_PolicyAuthorizeNV) /* 0x00000192 */ \ 1090 + (ADD_FILL || CC_EncryptDecrypt2) /* 0x00000193 */ \ 1091 + (ADD_FILL || CC_AC_GetCapability) /* 0x00000194 */ \ 1092 + (ADD_FILL || CC_AC_Send) /* 0x00000195 */ \ 1093 + (ADD_FILL || CC_Policy_AC_SendSelect) /* 0x00000196 */ \ 1094 ) 1095 1096 #define VENDOR_COMMAND_ARRAY_SIZE (0 + CC_Vendor_TCG_Test) 1097 1098 #define COMMAND_COUNT (LIBRARY_COMMAND_ARRAY_SIZE + VENDOR_COMMAND_ARRAY_SIZE) 1099 1100 #define HASH_COUNT \ 1101 (ALG_SHA1 + ALG_SHA256 + ALG_SHA384 + ALG_SHA512 + ALG_SM3_256) 1102 1103 #define MAX_HASH_BLOCK_SIZE \ 1104 (MAX(ALG_SHA1 * SHA1_BLOCK_SIZE, \ 1105 MAX(ALG_SHA256 * SHA256_BLOCK_SIZE, \ 1106 MAX(ALG_SHA384 * SHA384_BLOCK_SIZE, \ 1107 MAX(ALG_SHA512 * SHA512_BLOCK_SIZE, \ 1108 MAX(ALG_SM3_256 * SM3_256_BLOCK_SIZE, \ 1109 0)))))) 1110 1111 #define MAX_DIGEST_SIZE \ 1112 (MAX(ALG_SHA1 * SHA1_DIGEST_SIZE, \ 1113 MAX(ALG_SHA256 * SHA256_DIGEST_SIZE, \ 1114 MAX(ALG_SHA384 * SHA384_DIGEST_SIZE, \ 1115 MAX(ALG_SHA512 * SHA512_DIGEST_SIZE, \ 1116 MAX(ALG_SM3_256 * SM3_256_DIGEST_SIZE, \ 1117 0)))))) 1118 1119 1120 #if MAX_DIGEST_SIZE == 0 || MAX_HASH_BLOCK_SIZE == 0 1121 #error "Hash data not valid" 1122 #endif 1123 1124 // Define the 2B structure that would hold any hash block 1125 TPM2B_TYPE(MAX_HASH_BLOCK, MAX_HASH_BLOCK_SIZE); 1126 1127 // Following typedef is for some old code 1128 typedef TPM2B_MAX_HASH_BLOCK TPM2B_HASH_BLOCK; 1129 1130 /* AddSymmetricConstants */ 1131 #ifndef ALG_AES 1132 #define ALG_AES NO 1133 #endif 1134 #ifndef MAX_AES_KEY_BITS 1135 #define MAX_AES_KEY_BITS 0 1136 #define MAX_AES_BLOCK_SIZE_BYTES 0 1137 #endif 1138 #ifndef ALG_CAMELLIA 1139 #define ALG_CAMELLIA NO 1140 #endif 1141 #ifndef MAX_CAMELLIA_KEY_BITS 1142 #define MAX_CAMELLIA_KEY_BITS 0 1143 #define MAX_CAMELLIA_BLOCK_SIZE_BYTES 0 1144 #endif 1145 #ifndef ALG_SM4 1146 #define ALG_SM4 NO 1147 #endif 1148 #ifndef MAX_SM4_KEY_BITS 1149 #define MAX_SM4_KEY_BITS 0 1150 #define MAX_SM4_BLOCK_SIZE_BYTES 0 1151 #endif 1152 #ifndef ALG_TDES 1153 #define ALG_TDES NO 1154 #endif 1155 #ifndef MAX_TDES_KEY_BITS 1156 #define MAX_TDES_KEY_BITS 0 1157 #define MAX_TDES_BLOCK_SIZE_BYTES 0 1158 #endif 1159 #define MAX_SYM_KEY_BITS \ 1160 (MAX(ALG_AES * MAX_AES_KEY_BITS, \ 1161 MAX(ALG_CAMELLIA * MAX_CAMELLIA_KEY_BITS, \ 1162 MAX(ALG_SM4 * MAX_SM4_KEY_BITS, \ 1163 MAX(ALG_TDES * MAX_TDES_KEY_BITS, \ 1164 0))))) 1165 1166 #define MAX_SYM_KEY_BYTES ((MAX_SYM_KEY_BITS + 7) / 8) 1167 1168 #define MAX_SYM_BLOCK_SIZE \ 1169 (MAX(ALG_AES * MAX_AES_BLOCK_SIZE_BYTES, \ 1170 MAX(ALG_CAMELLIA * MAX_CAMELLIA_BLOCK_SIZE_BYTES, \ 1171 MAX(ALG_SM4 * MAX_SM4_BLOCK_SIZE_BYTES, \ 1172 MAX(ALG_TDES * MAX_TDES_BLOCK_SIZE_BYTES, \ 1173 0))))) 1174 1175 #if MAX_SYM_KEY_BITS == 0 || MAX_SYM_BLOCK_SIZE == 0 1176 # error Bad size for MAX_SYM_KEY_BITS or MAX_SYM_BLOCK_SIZE 1177 #endif 1178 1179 #endif // _IMPLEMENTATION_H_ 1180