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 #include "InternalRoutines.h" 9 typedef struct 10 { 11 TPM_ALG_ID algID; 12 TPMA_ALGORITHM attributes; 13 } ALGORITHM; 14 static const ALGORITHM s_algorithms[] = 15 { 16 #ifdef TPM_ALG_RSA 17 {TPM_ALG_RSA, {1, 0, 0, 1, 0, 0, 0, 0, 0}}, 18 #endif 19 #ifdef TPM_ALG_DES 20 {TPM_ALG_DES, {0, 1, 0, 0, 0, 0, 0, 0, 0}}, 21 #endif 22 #ifdef TPM_ALG_3DES 23 {TPM_ALG__3DES, {0, 1, 0, 0, 0, 0, 0, 0, 0}}, 24 #endif 25 #ifdef TPM_ALG_SHA1 26 {TPM_ALG_SHA1, {0, 0, 1, 0, 0, 0, 0, 0, 0}}, 27 #endif 28 #ifdef TPM_ALG_HMAC 29 {TPM_ALG_HMAC, {0, 0, 1, 0, 0, 1, 0, 0, 0}}, 30 #endif 31 #ifdef TPM_ALG_AES 32 {TPM_ALG_AES, {0, 1, 0, 0, 0, 0, 0, 0, 0}}, 33 #endif 34 #ifdef TPM_ALG_MGF1 35 {TPM_ALG_MGF1, {0, 0, 1, 0, 0, 0, 0, 1, 0}}, 36 #endif 37 {TPM_ALG_KEYEDHASH, {0, 0, 1, 1, 0, 1, 1, 0, 0}}, 38 #ifdef TPM_ALG_XOR 39 {TPM_ALG_XOR, {0, 1, 1, 0, 0, 0, 0, 0, 0}}, 40 #endif 41 #ifdef TPM_ALG_SHA256 42 {TPM_ALG_SHA256, {0, 0, 1, 0, 0, 0, 0, 0, 0}}, 43 #endif 44 #ifdef TPM_ALG_SHA384 45 {TPM_ALG_SHA384, {0, 0, 1, 0, 0, 0, 0, 0, 0}}, 46 #endif 47 #ifdef TPM_ALG_SHA512 48 {TPM_ALG_SHA512, {0, 0, 1, 0, 0, 0, 0, 0, 0}}, 49 #endif 50 #ifdef TPM_ALG_WHIRLPOOL512 51 {TPM_ALG_WHIRLPOOL512, {0, 0, 1, 0, 0, 0, 0, 0, 0}}, 52 #endif 53 #ifdef TPM_ALG_SM3_256 54 {TPM_ALG_SM3_256, {0, 0, 1, 0, 0, 0, 0, 0, 0}}, 55 #endif 56 #ifdef TPM_ALG_SM4 57 {TPM_ALG_SM4, {0, 1, 0, 0, 0, 0, 0, 0, 0}}, 58 #endif 59 #ifdef TPM_ALG_RSASSA 60 {TPM_ALG_RSASSA, {1, 0, 0, 0, 0, 1, 0, 0, 0}}, 61 #endif 62 #ifdef TPM_ALG_RSAES 63 {TPM_ALG_RSAES, {1, 0, 0, 0, 0, 0, 1, 0, 0}}, 64 #endif 65 #ifdef TPM_ALG_RSAPSS 66 {TPM_ALG_RSAPSS, {1, 0, 0, 0, 0, 1, 0, 0, 0}}, 67 #endif 68 #ifdef TPM_ALG_OAEP 69 {TPM_ALG_OAEP, {1, 0, 0, 0, 0, 0, 1, 0, 0}}, 70 #endif 71 #ifdef TPM_ALG_ECDSA 72 {TPM_ALG_ECDSA, {1, 0, 0, 0, 0, 1, 0, 1, 0}}, 73 #endif 74 #ifdef TPM_ALG_ECDH 75 {TPM_ALG_ECDH, {1, 0, 0, 0, 0, 0, 0, 1, 0}}, 76 #endif 77 #ifdef TPM_ALG_ECDAA 78 {TPM_ALG_ECDAA, {1, 0, 0, 0, 0, 1, 0, 0, 0}}, 79 #endif 80 #ifdef TPM_ALG_ECSCHNORR 81 {TPM_ALG_ECSCHNORR, {1, 0, 0, 0, 0, 1, 0, 0, 0}}, 82 #endif 83 #ifdef TPM_ALG_KDF1_SP800_56A 84 {TPM_ALG_KDF1_SP800_56A,{0, 0, 1, 0, 0, 0, 0, 1, 0}}, 85 #endif 86 #ifdef TPM_ALG_KDF2 87 {TPM_ALG_KDF2, {0, 0, 1, 0, 0, 0, 0, 1, 0}}, 88 #endif 89 #ifdef TPM_ALG_KDF1_SP800_108 90 {TPM_ALG_KDF1_SP800_108,{0, 0, 1, 0, 0, 0, 0, 1, 0}}, 91 #endif 92 #ifdef TPM_ALG_ECC 93 {TPM_ALG_ECC, {1, 0, 0, 1, 0, 0, 0, 0, 0}}, 94 #endif 95 {TPM_ALG_SYMCIPHER, {0, 0, 0, 1, 0, 0, 0, 0, 0}}, 96 #ifdef TPM_ALG_CTR 97 {TPM_ALG_CTR, {0, 1, 0, 0, 0, 0, 1, 0, 0}}, 98 #endif 99 #ifdef TPM_ALG_OFB 100 {TPM_ALG_OFB, {0, 1, 0, 0, 0, 0, 1, 0, 0}}, 101 #endif 102 #ifdef TPM_ALG_CBC 103 {TPM_ALG_CBC, {0, 1, 0, 0, 0, 0, 1, 0, 0}}, 104 #endif 105 #ifdef TPM_ALG_CFB 106 {TPM_ALG_CFB, {0, 1, 0, 0, 0, 0, 1, 0, 0}}, 107 #endif 108 #ifdef TPM_ALG_ECB 109 {TPM_ALG_ECB, {0, 1, 0, 0, 0, 0, 1, 0, 0}}, 110 #endif 111 }; 112 // 113 // 114 // AlgorithmCapGetImplemented() 115 // 116 // This function is used by TPM2_GetCapability() to return a list of the implemented algorithms. 117 // 118 // 119 // 120 // 121 // Return Value Meaning 122 // 123 // YES more algorithms to report 124 // NO no more algorithms to report 125 // 126 TPMI_YES_NO 127 AlgorithmCapGetImplemented( 128 TPM_ALG_ID algID, // IN: the starting algorithm ID 129 UINT32 count, // IN: count of returned algorithms 130 TPML_ALG_PROPERTY *algList // OUT: algorithm list 131 ) 132 { 133 TPMI_YES_NO more = NO; 134 UINT32 i; 135 UINT32 algNum; 136 // initialize output algorithm list 137 algList->count = 0; 138 // The maximum count of algorithms we may return is MAX_CAP_ALGS. 139 if(count > MAX_CAP_ALGS) 140 count = MAX_CAP_ALGS; 141 // Compute how many algorithms are defined in s_algorithms array. 142 algNum = sizeof(s_algorithms) / sizeof(s_algorithms[0]); 143 // Scan the implemented algorithm list to see if there is a match to 'algID'. 144 for(i = 0; i < algNum; i++) 145 { 146 // If algID is less than the starting algorithm ID, skip it 147 if(s_algorithms[i].algID < algID) 148 continue; 149 if(algList->count < count) 150 { 151 // If we have not filled up the return list, add more algorithms 152 // to it 153 algList->algProperties[algList->count].alg = s_algorithms[i].algID; 154 algList->algProperties[algList->count].algProperties = 155 s_algorithms[i].attributes; 156 algList->count++; 157 } 158 else 159 { 160 // If the return list is full but we still have algorithms 161 // available, report this and stop scanning. 162 more = YES; 163 break; 164 } 165 } 166 return more; 167 } 168 LIB_EXPORT 169 void 170 AlgorithmGetImplementedVector( 171 ALGORITHM_VECTOR *implemented // OUT: the implemented bits are SET 172 ) 173 { 174 int index; 175 // Nothing implemented until we say it is 176 MemorySet(implemented, 0, sizeof(ALGORITHM_VECTOR)); 177 for(index = (sizeof(s_algorithms) / sizeof(s_algorithms[0])) - 1; 178 index >= 0; 179 index--) 180 SET_BIT(s_algorithms[index].algID, *implemented); 181 return; 182 } 183