Home | History | Annotate | Download | only in generator
      1 # Copyright 2014 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 """Provides selector information for TPM 2.0 unions.
      6 
      7 Describing this information explicitly is easier than extracting it from the
      8 specification.
      9 """
     10 
     11 _SELECTORS = {
     12     'TPMU_HA': {
     13         'type': ['TPMI_ALG_HASH'],
     14         'selectors': {
     15             'TPM_ALG_SHA1': 'sha1',
     16             'TPM_ALG_SHA256': 'sha256',
     17             'TPM_ALG_SM3_256': 'sm3_256',
     18             'TPM_ALG_SHA384': 'sha384',
     19             'TPM_ALG_SHA512': 'sha512',
     20             'TPM_ALG_NULL': ''
     21         }
     22     },
     23     'TPMU_CAPABILITIES': {
     24         'type': ['TPM_CAP'],
     25         'selectors': {
     26             'TPM_CAP_ALGS': 'algorithms',
     27             'TPM_CAP_HANDLES': 'handles',
     28             'TPM_CAP_COMMANDS': 'command',
     29             'TPM_CAP_PP_COMMANDS': 'ppCommands',
     30             'TPM_CAP_AUDIT_COMMANDS': 'auditCommands',
     31             'TPM_CAP_PCRS': 'assignedPCR',
     32             'TPM_CAP_TPM_PROPERTIES': 'tpmProperties',
     33             'TPM_CAP_PCR_PROPERTIES': 'pcrProperties',
     34             'TPM_CAP_ECC_CURVES': 'eccCurves',
     35         }
     36     },
     37     'TPMU_ATTEST': {
     38         'type': ['TPMI_ST_ATTEST'],
     39         'selectors': {
     40             'TPM_ST_ATTEST_CERTIFY': 'certify',
     41             'TPM_ST_ATTEST_CREATION': 'creation',
     42             'TPM_ST_ATTEST_QUOTE': 'quote',
     43             'TPM_ST_ATTEST_COMMAND_AUDIT': 'commandAudit',
     44             'TPM_ST_ATTEST_SESSION_AUDIT': 'sessionAudit',
     45             'TPM_ST_ATTEST_TIME': 'time',
     46             'TPM_ST_ATTEST_NV': 'nv',
     47         }
     48     },
     49     'TPMU_SYM_KEY_BITS': {
     50         'type': ['TPMI_ALG_SYM', 'TPMI_ALG_SYM_OBJECT'],
     51         'selectors': {
     52             'TPM_ALG_AES': 'aes',
     53             'TPM_ALG_SM4': 'SM4',
     54             'TPM_ALG_XOR': 'xor_',
     55             'TPM_ALG_NULL': '',
     56         }
     57     },
     58     'TPMU_SYM_MODE': {
     59         'type': ['TPMI_ALG_SYM', 'TPMI_ALG_SYM_OBJECT'],
     60         'selectors': {
     61             'TPM_ALG_AES': 'aes',
     62             'TPM_ALG_SM4': 'SM4',
     63             'TPM_ALG_XOR': '',
     64             'TPM_ALG_NULL': '',
     65         }
     66     },
     67     'TPMU_SYM_DETAILS': {
     68         'type': ['TPMI_ALG_SYM', 'TPMI_ALG_SYM_OBJECT'],
     69         'selectors': {}
     70     },
     71     'TPMU_SCHEME_KEYEDHASH': {
     72         'type': ['TPMI_ALG_KEYEDHASH_SCHEME'],
     73         'selectors': {
     74             'TPM_ALG_HMAC': 'hmac',
     75             'TPM_ALG_XOR': 'xor_',
     76             'TPM_ALG_NULL': '',
     77         }
     78     },
     79     'TPMU_SIG_SCHEME': {
     80         'type': ['TPMI_ALG_SIG_SCHEME', 'TPMI_ALG_ECC_SCHEME'],
     81         'selectors': {
     82             'TPM_ALG_RSASSA': 'rsassa',
     83             'TPM_ALG_RSAPSS': 'rsapss',
     84             'TPM_ALG_ECDSA': 'ecdsa',
     85             'TPM_ALG_SM2': 'sm2',
     86             'TPM_ALG_ECDAA': 'ecdaa',
     87             'TPM_ALG_ECSCHNORR': 'ecSchnorr',
     88             'TPM_ALG_HMAC': 'hmac',
     89             'TPM_ALG_NULL': '',
     90         }
     91     },
     92     'TPMU_KDF_SCHEME': {
     93         'type': ['TPMI_ALG_KDF'],
     94         'selectors': {
     95             'TPM_ALG_MGF1': 'mgf1',
     96             'TPM_ALG_KDF1_SP800_56a': 'kdf1_SP800_56a',
     97             'TPM_ALG_KDF2': 'kdf2',
     98             'TPM_ALG_KDF1_SP800_108': 'kdf1_sp800_108',
     99             'TPM_ALG_NULL': '',
    100         }
    101     },
    102     'TPMU_ASYM_SCHEME': {
    103         'type': ['TPMI_ALG_ASYM_SCHEME',
    104                  'TPMI_ALG_RSA_SCHEME',
    105                  'TPMI_ALG_RSA_DECRYPT',
    106                  'TPMI_ALG_ECC_SCHEME'],
    107         'selectors': {
    108             'TPM_ALG_RSASSA': 'rsassa',
    109             'TPM_ALG_RSAPSS': 'rsapss',
    110             'TPM_ALG_RSAES': '',
    111             'TPM_ALG_OAEP': 'oaep',
    112             'TPM_ALG_ECDSA': 'ecdsa',
    113             'TPM_ALG_SM2': 'sm2',
    114             'TPM_ALG_ECDAA': 'ecdaa',
    115             'TPM_ALG_ECSCHNORR': 'ecSchnorr',
    116             'TPM_ALG_ECDH': 'ecdh',
    117             'TPM_ALG_NULL': '',
    118         }
    119     },
    120     'TPMU_SIGNATURE': {
    121         'type': ['TPMI_ALG_SIG_SCHEME'],
    122         'selectors': {
    123             'TPM_ALG_RSASSA': 'rsassa',
    124             'TPM_ALG_RSAPSS': 'rsapss',
    125             'TPM_ALG_ECDSA': 'ecdsa',
    126             'TPM_ALG_SM2': 'sm2',
    127             'TPM_ALG_ECDAA': 'ecdaa',
    128             'TPM_ALG_ECSCHNORR': 'ecschnorr',
    129             'TPM_ALG_HMAC': 'hmac',
    130             'TPM_ALG_NULL': '',
    131         }
    132     },
    133     'TPMU_PUBLIC_PARMS': {
    134         'type': ['TPMI_ALG_PUBLIC'],
    135         'selectors': {
    136             'TPM_ALG_KEYEDHASH': 'keyedHashDetail',
    137             'TPM_ALG_SYMCIPHER': 'symDetail',
    138             'TPM_ALG_RSA': 'rsaDetail',
    139             'TPM_ALG_ECC': 'eccDetail',
    140         }
    141     },
    142     'TPMU_PUBLIC_ID': {
    143         'type': ['TPMI_ALG_PUBLIC'],
    144         'selectors': {
    145             'TPM_ALG_KEYEDHASH': 'keyedHash',
    146             'TPM_ALG_SYMCIPHER': 'sym',
    147             'TPM_ALG_RSA': 'rsa',
    148             'TPM_ALG_ECC': 'ecc',
    149         }
    150     },
    151     'TPMU_SENSITIVE_COMPOSITE': {
    152         'type': ['TPMI_ALG_PUBLIC'],
    153         'selectors': {
    154             'TPM_ALG_KEYEDHASH': 'bits',
    155             'TPM_ALG_SYMCIPHER': 'sym',
    156             'TPM_ALG_RSA': 'rsa',
    157             'TPM_ALG_ECC': 'ecc',
    158         }
    159     },
    160 }
    161 
    162 
    163 def GetUnionSelectorType(union_type):
    164   """Returns the selector type for a given union."""
    165   return _SELECTORS[union_type]['type'][0]
    166 
    167 
    168 def GetUnionSelectorTypes(union_type):
    169   """Returns a list of all acceptable selector types for a given union."""
    170   return _SELECTORS[union_type]['type']
    171 
    172 
    173 def GetUnionSelectorValues(union_type):
    174   """Returns the list of possible selector values for a given union."""
    175   return _SELECTORS[union_type]['selectors'].keys()
    176 
    177 
    178 def GetUnionSelectorField(union_type, selector_value):
    179   """Returns the union field associated with a given selector value."""
    180   return _SELECTORS[union_type]['selectors'][selector_value]
    181