• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright (C) 2014 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17"""Provides selector information for TPM 2.0 unions.
18
19Describing this information explicitly is easier than extracting it from the
20specification.
21"""
22
23_SELECTORS = {
24    'TPMU_HA': {
25        'type': ['TPMI_ALG_HASH'],
26        'selectors': {
27            'TPM_ALG_SHA1': 'sha1[SHA1_DIGEST_SIZE]',
28            'TPM_ALG_SHA256': 'sha256[SHA256_DIGEST_SIZE]',
29            'TPM_ALG_SM3_256': 'sm3_256[SM3_256_DIGEST_SIZE]',
30            'TPM_ALG_SHA384': 'sha384[SHA384_DIGEST_SIZE]',
31            'TPM_ALG_SHA512': 'sha512[SHA512_DIGEST_SIZE]',
32            'TPM_ALG_NULL': ''
33        }
34    },
35    'TPMU_CAPABILITIES': {
36        'type': ['TPM_CAP'],
37        'selectors': {
38            'TPM_CAP_ALGS': 'algorithms',
39            'TPM_CAP_HANDLES': 'handles',
40            'TPM_CAP_COMMANDS': 'command',
41            'TPM_CAP_PP_COMMANDS': 'ppCommands',
42            'TPM_CAP_AUDIT_COMMANDS': 'auditCommands',
43            'TPM_CAP_PCRS': 'assignedPCR',
44            'TPM_CAP_TPM_PROPERTIES': 'tpmProperties',
45            'TPM_CAP_PCR_PROPERTIES': 'pcrProperties',
46            'TPM_CAP_ECC_CURVES': 'eccCurves',
47        }
48    },
49    'TPMU_ATTEST': {
50        'type': ['TPMI_ST_ATTEST'],
51        'selectors': {
52            'TPM_ST_ATTEST_CERTIFY': 'certify',
53            'TPM_ST_ATTEST_CREATION': 'creation',
54            'TPM_ST_ATTEST_QUOTE': 'quote',
55            'TPM_ST_ATTEST_COMMAND_AUDIT': 'commandAudit',
56            'TPM_ST_ATTEST_SESSION_AUDIT': 'sessionAudit',
57            'TPM_ST_ATTEST_TIME': 'time',
58            'TPM_ST_ATTEST_NV': 'nv',
59        }
60    },
61    'TPMU_SYM_KEY_BITS': {
62        'type': ['TPMI_ALG_SYM', 'TPMI_ALG_SYM_OBJECT'],
63        'selectors': {
64            'TPM_ALG_AES': 'aes',
65            'TPM_ALG_SM4': 'SM4',
66            'TPM_ALG_XOR': 'xor_',
67            'TPM_ALG_NULL': '',
68        }
69    },
70    'TPMU_SYM_MODE': {
71        'type': ['TPMI_ALG_SYM', 'TPMI_ALG_SYM_OBJECT'],
72        'selectors': {
73            'TPM_ALG_AES': 'aes',
74            'TPM_ALG_SM4': 'SM4',
75            'TPM_ALG_XOR': '',
76            'TPM_ALG_NULL': '',
77        }
78    },
79    'TPMU_SYM_DETAILS': {
80        'type': ['TPMI_ALG_SYM', 'TPMI_ALG_SYM_OBJECT'],
81        'selectors': {}
82    },
83    'TPMU_SCHEME_KEYEDHASH': {
84        'type': ['TPMI_ALG_KEYEDHASH_SCHEME'],
85        'selectors': {
86            'TPM_ALG_HMAC': 'hmac',
87            'TPM_ALG_XOR': 'xor_',
88            'TPM_ALG_NULL': '',
89        }
90    },
91    'TPMU_SIG_SCHEME': {
92        'type': ['TPMI_ALG_SIG_SCHEME', 'TPMI_ALG_ECC_SCHEME'],
93        'selectors': {
94            'TPM_ALG_RSASSA': 'rsassa',
95            'TPM_ALG_RSAPSS': 'rsapss',
96            'TPM_ALG_ECDSA': 'ecdsa',
97            'TPM_ALG_SM2': 'sm2',
98            'TPM_ALG_ECDAA': 'ecdaa',
99            'TPM_ALG_ECSCHNORR': 'ecSchnorr',
100            'TPM_ALG_HMAC': 'hmac',
101            'TPM_ALG_NULL': '',
102        }
103    },
104    'TPMU_KDF_SCHEME': {
105        'type': ['TPMI_ALG_KDF'],
106        'selectors': {
107            'TPM_ALG_MGF1': 'mgf1',
108            'TPM_ALG_KDF1_SP800_56a': 'kdf1_SP800_56a',
109            'TPM_ALG_KDF2': 'kdf2',
110            'TPM_ALG_KDF1_SP800_108': 'kdf1_sp800_108',
111            'TPM_ALG_NULL': '',
112        }
113    },
114    'TPMU_ASYM_SCHEME': {
115        'type': ['TPMI_ALG_ASYM_SCHEME',
116                 'TPMI_ALG_RSA_SCHEME',
117                 'TPMI_ALG_RSA_DECRYPT',
118                 'TPMI_ALG_ECC_SCHEME'],
119        'selectors': {
120            'TPM_ALG_RSASSA': 'rsassa',
121            'TPM_ALG_RSAPSS': 'rsapss',
122            'TPM_ALG_RSAES': '',
123            'TPM_ALG_OAEP': 'oaep',
124            'TPM_ALG_ECDSA': 'ecdsa',
125            'TPM_ALG_SM2': 'sm2',
126            'TPM_ALG_ECDAA': 'ecdaa',
127            'TPM_ALG_ECSCHNORR': 'ecSchnorr',
128            'TPM_ALG_ECDH': 'ecdh',
129            'TPM_ALG_NULL': '',
130        }
131    },
132    'TPMU_SIGNATURE': {
133        'type': ['TPMI_ALG_SIG_SCHEME'],
134        'selectors': {
135            'TPM_ALG_RSASSA': 'rsassa',
136            'TPM_ALG_RSAPSS': 'rsapss',
137            'TPM_ALG_ECDSA': 'ecdsa',
138            'TPM_ALG_SM2': 'sm2',
139            'TPM_ALG_ECDAA': 'ecdaa',
140            'TPM_ALG_ECSCHNORR': 'ecschnorr',
141            'TPM_ALG_HMAC': 'hmac',
142            'TPM_ALG_NULL': '',
143        }
144    },
145    'TPMU_PUBLIC_PARMS': {
146        'type': ['TPMI_ALG_PUBLIC'],
147        'selectors': {
148            'TPM_ALG_KEYEDHASH': 'keyedHashDetail',
149            'TPM_ALG_SYMCIPHER': 'symDetail',
150            'TPM_ALG_RSA': 'rsaDetail',
151            'TPM_ALG_ECC': 'eccDetail',
152        }
153    },
154    'TPMU_PUBLIC_ID': {
155        'type': ['TPMI_ALG_PUBLIC'],
156        'selectors': {
157            'TPM_ALG_KEYEDHASH': 'keyedHash',
158            'TPM_ALG_SYMCIPHER': 'sym',
159            'TPM_ALG_RSA': 'rsa',
160            'TPM_ALG_ECC': 'ecc',
161        }
162    },
163    'TPMU_SENSITIVE_COMPOSITE': {
164        'type': ['TPMI_ALG_PUBLIC'],
165        'selectors': {
166            'TPM_ALG_KEYEDHASH': 'bits',
167            'TPM_ALG_SYMCIPHER': 'sym',
168            'TPM_ALG_RSA': 'rsa',
169            'TPM_ALG_ECC': 'ecc',
170        }
171    },
172}
173
174
175def GetUnionSelectorType(union_type):
176  """Returns the selector type for a given union."""
177  return _SELECTORS[union_type]['type'][0]
178
179
180def GetUnionSelectorTypes(union_type):
181  """Returns a list of all acceptable selector types for a given union."""
182  return _SELECTORS[union_type]['type']
183
184
185def GetUnionSelectorValues(union_type):
186  """Returns the list of possible selector values for a given union."""
187  return _SELECTORS[union_type]['selectors'].keys()
188
189
190def GetUnionSelectorField(union_type, selector_value):
191  """Returns the union field associated with a given selector value."""
192  return _SELECTORS[union_type]['selectors'][selector_value]
193