SamAV2 implementation of the phSam interface. More...

Data Structures | |
| struct | phKeyStore_SamAV2_DataParams_t |
| Sam parameter structure. More... | |
| struct | phKeyStore_SamAV2_KeyEntry_t |
| SamAV2 Key Entry Structure. More... | |
Macros | |
| #define | PH_KEYSTORE_SAMAV2_AV1_MODE 0x01U |
| Define the AV1 mode of the KeyStore. | |
| #define | PH_KEYSTORE_SAMAV2_AV2_MODE 0x02U |
| Define the AV2 mode of the KeyStore. | |
Key Classes | |
| #define | PH_KEYSTORE_SAMAV2_KEY_CLASS_HOST 0x00U |
| Host key: has to be either AES128 or AES192. | |
| #define | PH_KEYSTORE_SAMAV2_KEY_CLASS_PICC 0x01U |
| PICC key: has to be either AES128, single DES, 2 Key Triple DES, 3 Key Triple DES or MIFARE. | |
| #define | PH_KEYSTORE_SAMAV2_KEY_CLASS_OFFLINE_CHANGE 0x02U |
| Offline change key: has to be either AES128 or AES192. | |
| #define | PH_KEYSTORE_SAMAV2_KEY_CLASS_OFFLINE_CRYPTO 0x04U |
| Offline crypto key: has to be either AES128, AES192, single DES with CRC32 protection, 2 Key Triple DES with CRC32 protection or 3 Key Triple DES. | |
DES Key Options | |
| #define | PH_KEYSTORE_SAMAV2_DES_OPTION_DESFIRE4 0x00U |
| DESFire 4 compatibility mode. | |
| #define | PH_KEYSTORE_SAMAV2_DES_OPTION_ISO_CRC16 0x01U |
| ISO 10116 mode with CRC16 protection and 4 bytes MAC. | |
| #define | PH_KEYSTORE_SAMAV2_DES_OPTION_ISO_CRC32 0x02U |
| ISO 10116 mode with CRC32 protection and 8 bytes MAC. | |
| #define | PH_KEYSTORE_SAMAV3_DES_OPTION_DESFIRE4 0x00U |
| DESFire 4 compatibility mode. | |
| #define | PH_KEYSTORE_SAMAV3_DES_OPTION_ISO_CRC16 0x01U |
| ISO 10116 mode with CRC16 protection and 4 bytes MAC. | |
| #define | PH_KEYSTORE_SAMAV3_DES_OPTION_ISO_CRC32 0x02U |
| ISO 10116 mode with CRC32 protection and 8 bytes MAC. | |
KeyStore Configs | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_ALLOW_DUMP_SESSION_KEY 0x0000U |
| Enable or Disable SAM_ChangeKeyMIFARE and SAM_DumpSessionKey command. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_ALLOW_CRYPTO_SECRET_KEY 0x0001U |
| Enable or Disable crypto based on the secret key for AV1 mode. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_ALLOW_DUMP_SECRET_KEY 0x0002U |
| Enable or Disable SAM_DumpSecretKey command for AV2 mode. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_KEEP_IV 0x0003U |
| Enable or Disable the reset of init vector after a crypto command. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_ENABLE_HIGH_SEC_LEVEL 0x0004U |
| Enable or Disable Higher Command Security Level for AV1 Master Key. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_ENABLE_HOST_AUTH 0x0005U |
| Enable or Disable Host Authentication for AV2 mode. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_ENABLE_HOST_AUTH_AFTER_RESET 0x0006U |
| Enable or Disable Host Authentication after reset for AV1 Master Key. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_ENABLE_LOCK_UNLOCK 0x0007U |
| Enable or Disable LockUnlock for AV2 mode. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_DISABLE_CHANGE_KEY_PICC 0x0008U |
| Enable or Disable SAM_ChangeKeyPICC command. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_DISABLE_ENCRYPTION 0x0009U |
| Enable or Disable SAM_DecipherData command. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_DISABLE_DECRYPTION 0x000AU |
| Enable or Disable SAM_EncipherData command. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_DISABLE_VERIFY_MAC 0x000BU |
| Enable or Disable SAM_VerifyMAC command. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_DISABLE_GENERATE_MAC 0x000CU |
| Enable or Disable SAM_GenerateMAC command. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_MANDATE_KEY_DIVERSIFICATION 0x000DU |
| Mandate or not key diversification. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_CHANGE_KEY_PLAIN 0x000EU |
| Enable plain exchange of ChangeKey functions for AV1 mode. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_KEYCLASS 0x000FU |
| Key Class used in key store. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_KEYNO_CEK 0x0010U |
| Key Number of Change Entry key. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_KEYV_CEK 0x0011U |
| Key Version of Change Entry key. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_KEYNO_CKUC 0x0012U |
| Key Number of Change KUC. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_KEYV_CKUC 0x0013U |
| Key Version of Change KUC. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_DISABLE_KEY_ENTRY 0x0014U |
| Enable or Disable Key Entry. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_DF_AID 0x0015U |
| MIFARE DESFire application ID. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_DF_KEY_NO 0x0016U |
| MIFARE DESFire key number. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_REF_NO_KUC 0x0017U |
| Reference number of key usage counter. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_DES_KEY_OPTION 0x0018U |
| Option for single DES and 2 Key Triple DES keys. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_KEYNO_MF_DIV_A 0x0019U |
| Key Number used for MIFARE key A diversification. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_KEYV_MF_DIV_A 0x001AU |
| Key Version used for MIFARE key A diversification. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_KEYNO_MF_DIV_B 0x001BU |
| Key Number used for MIFARE key B diversification. | |
| #define | PH_KEYSTORE_SAMAV2_CONFIG_KEYV_MF_DIV_B 0x001CU |
| Key Version used for MIFARE key B diversification. | |
SamAV2 implementation of the phSam interface.
| phStatus_t phKeyStore_SamAV2_Init | ( | phKeyStore_SamAV2_DataParams_t * | pDataParams, |
| uint16_t | wSizeOfDataParams, | ||
| phhalHw_SamAV2_DataParams_t * | pHalDataParams | ||
| ) |
Initializes the KeyStore component as SAM AV2 component.
| PH_ERR_SUCCESS | Operation successful. |
| [in] | pDataParams | [In] Pointer to this layer's parameter structure. |
| [in] | wSizeOfDataParams | [In] Specifies the size of the data parameter structure. |
| [in] | pHalDataParams | [In] Pointer to the parameter structure of the underlying layer. |
| phStatus_t phKeyStore_SamAV2_FormatKeyEntry | ( | phKeyStore_SamAV2_DataParams_t * | pDataParams, |
| uint16_t | wKeyNo, | ||
| uint16_t | wNewKeyType | ||
| ) |
Format a key entry to a new KeyType.
The function changes a symmetric key entry of the SAM to a new key type. First the command phhalHw_SamAV2_Cmd_SAM_GetKeyEntry is executed to get the current change key number of the key entry. Afterwards a new key entry is written by the phhalHw_SamAV2_Cmd_SAM_ChangeKeyEntry command. The keys and key versions, of this new entry are set to zero. DF_Aid, DFKeyNo, RefNoKUC, SET, ExtSET, KeyNoCEK and KeyVCEK are set according to the configuration parameters. In case of a MIFARE key entry the diversification keys for key A and key B of all three key versions are set according to the configuration parameters. Therefore PH_KEYSTORE_SAMAV2_CONFIG_KEYNO_MF_DIV_A and PH_KEYSTORE_SAMAV2_CONFIG_KEYV_MF_DIV_A resp. PH_KEYSTORE_SAMAV2_CONFIG_KEYNO_MF_DIV_B and PH_KEYSTORE_SAMAV2_CONFIG_KEYV_MF_DIV_B have to point to a 2K3DES key.
| PH_ERR_SUCCESS | Operation successful. |
| Other | Depending on implementation and underlaying component. |
| [in] | pDataParams | [In] Pointer to this layers parameter structure. |
| [in] | wKeyNo | [In] KeyEntry number to be formatted (0x00 to F0). |
| [in] | wNewKeyType | [In] New key type of the KeyEntry (predefined type of KeyType). |
| phStatus_t phKeyStore_SamAV2_SetKey | ( | phKeyStore_SamAV2_DataParams_t * | pDataParams, |
| uint16_t | wKeyNo, | ||
| uint16_t | wKeyVersion, | ||
| uint16_t | wKeyType, | ||
| uint8_t * | pNewKey, | ||
| uint16_t | wNewKeyVersion | ||
| ) |
Change a key entry at a given version.
First the command phhalHw_SamAV2_Cmd_SAM_GetKeyEntry is executed to get the information about the current key entry. If the current key type does not match with wKeyType or if the selected key version wKeyVersion is not part of the current key entry the function is aborted. Otherwhise the key with the given version is set to pKey and its version is set to wNewKeyVersion by the phhalHw_SamAV2_Cmd_SAM_ChangeKeyEntry. DF_Aid, DFKeyNo, RefNoKUC, SET, ExtSET, KeyNoCEK and KeyVCEK are set according to the configuration parameters. In case of a MIFARE key entry the diversification keys for key A and key B of all key versions are set according to the configuration parameters. Therefore PH_KEYSTORE_SAMAV2_CONFIG_KEYNO_MF_DIV_A and PH_KEYSTORE_SAMAV2_CONFIG_KEYV_MF_DIV_A resp. PH_KEYSTORE_SAMAV2_CONFIG_KEYNO_MF_DIV_B and PH_KEYSTORE_SAMAV2_CONFIG_KEYV_MF_DIV_B have to point to a 2K3DES key.
| PH_ERR_SUCCESS | Operation successful. |
| PH_ERR_INVALID_PARAMETER | KeyType missmatch or key version not found. |
| Other | Depending on implementation and underlaying component. |
| [in] | pDataParams | [In] Pointer to this layers parameter structure. |
| [in] | wKeyNo | [In] Key number of the key to be loaded. |
| [in] | wKeyVersion | [In] Key version of the key to be loaded. |
| [in] | wKeyType | [In] Key type of the key to be loaded. |
| [in] | pNewKey | [In] Pointer to the key itself. |
| [in] | wNewKeyVersion | [In] New Key version of the key to be updated. |
| phStatus_t phKeyStore_SamAV2_SetKeyAtPos | ( | phKeyStore_SamAV2_DataParams_t * | pDataParams, |
| uint16_t | wKeyNo, | ||
| uint16_t | wPos, | ||
| uint16_t | wKeyType, | ||
| uint8_t * | pNewKey, | ||
| uint16_t | wNewKeyVersion | ||
| ) |
Change a key entry at the specified position.
First the command phhalHw_SamAV2_Cmd_SAM_GetKeyEntry is executed to get the information about the current key entry. If the current key type does not match with wKeyType or if the selected key position is wrong the function is aborted. Otherwhise the key at position wPos (00h to 02h) is set to pKey and its version is set to wNewKeyVersion by the phhalHw_SamAV2_Cmd_SAM_ChangeKeyEntry. DF_Aid, DFKeyNo, RefNoKUC, SET, ExtSET, KeyNoCEK and KeyVCEK are set according to the configuration parameters. In case of a MIFARE key entry the diversification keys for key A and key B of all key versions are set according to the configuration parameters. These parameters can be accessd via PH_KEYSTORE_SAMAV2_CONFIG_KEYNO_MF_DIV_A and PH_KEYSTORE_SAMAV2_CONFIG_KEYV_MF_DIV_A resp. PH_KEYSTORE_SAMAV2_CONFIG_KEYNO_MF_DIV_B and PH_KEYSTORE_SAMAV2_CONFIG_KEYV_MF_DIV_B.
| PH_ERR_SUCCESS | Operation successful. |
| PH_ERR_INVALID_PARAMETER | KeyType missmatch or wrong wPos. |
| Other | Depending on implementation and underlaying component. |
| [in] | pDataParams | [In] Pointer to this layers parameter structure. |
| [in] | wKeyNo | [In] Key number of key to be updated. |
| [in] | wPos | [In] Key position to be updated (0, 2 or 3). |
| [in] | wKeyType | [In] Key type of key to be updated. |
| [in] | pNewKey | [In] Key to be updated. |
| [in] | wNewKeyVersion | [In] New key version of the key at pos wPos. |
| phStatus_t phKeyStore_SamAV2_SetKUC | ( | phKeyStore_SamAV2_DataParams_t * | pDataParams, |
| uint16_t | wKeyNo, | ||
| uint16_t | wRefNoKUC | ||
| ) |
Change the KUC of a key entry.
First the command phhalHw_SamAV2_Cmd_SAM_GetKeyEntry is executed to get the change key of the current key entry. Afterwards the reference number of the KUC is set to wRefNoKUC via the phhalHw_SamAV2_Cmd_SAM_ChangeKeyEntry command.
| PH_ERR_SUCCESS | Operation successful. |
| Other | Depending on implementation and underlaying component. |
| [in] | pDataParams | [In] Pointer to this layers parameter structure. |
| [in] | wKeyNo | [In] KeyEntry number. |
| [in] | wRefNoKUC | [In] Reference Number of the key usage counter used together with that key. |
| phStatus_t phKeyStore_SamAV2_SetFullKeyEntry | ( | phKeyStore_SamAV2_DataParams_t * | pDataParams, |
| uint16_t | wNoOfKeys, | ||
| uint16_t | wKeyNo, | ||
| uint16_t | wNewRefNoKUC, | ||
| uint16_t | wNewKeyType, | ||
| uint8_t * | pNewKeys, | ||
| uint16_t * | pNewKeyVersionList | ||
| ) |
Change a full key entry.
First the command phhalHw_SamAV2_Cmd_SAM_GetKeyEntry is executed to get the information about the current key entry. If the current key type does not match with wKeyType also all keys of the entry have to be updated. If wNoOfKeys is 01h key A is changed to pKeys, if it is 02h key A and B are changed to pKeys and if it is 03h key A, B and C are changed to pKeys via the phhalHw_SamAV2_Cmd_SAM_ChangeKeyEntry command. If a key is changed also its version is changed to the value listed in pKeyVersionList. Keys which are not provided by pKeys are set to zero togheter with its versions. If wNoOfKeys is set to 0 key and version update is skiped. The fields DF_Aid, DFKeyNo, SET, ExtSET, KeyNoCEK and KeyVCEK are set according to the configuration parameters. In case of a MIFARE key entry the diversification keys for key A and key B of all key versions are set according to the configuration parameters. These parameters can be accessd via PH_KEYSTORE_SAMAV2_CONFIG_KEYNO_MF_DIV_A and PH_KEYSTORE_SAMAV2_CONFIG_KEYV_MF_DIV_A resp. PH_KEYSTORE_SAMAV2_CONFIG_KEYNO_MF_DIV_B and PH_KEYSTORE_SAMAV2_CONFIG_KEYV_MF_DIV_B.
| PH_ERR_SUCCESS | Operation successful. |
| PH_ERR_INVALID_PARAMETER | KeyType missmatch or wrong wNoOfKeys. |
| Other | Depending on implementation and underlaying component. |
| [in] | pDataParams | [In] Pointer to this layer's parameter structure. |
| [in] | wNoOfKeys | [In] Number of keys in pNewKeys. |
| [in] | wKeyNo | [In] Number of the keys to be changed in the entry. |
| [in] | wNewRefNoKUC | [In] Reference number of the key usage counter to be used. |
| [in] | wNewKeyType | [In] Key type of the new key. |
| [in] | pNewKeys | [In] Buffer containing the Keys to be updated. This buffer has to be wNoOfKeys * keylength bytes long. |
| [in] | pNewKeyVersionList | [In] KeyVersionList of the key to be loaded. This buffer has to be wNoOfKeys*2 bytes long. |
| phStatus_t phKeyStore_SamAV2_GetKeyEntry | ( | phKeyStore_SamAV2_DataParams_t * | pDataParams, |
| uint16_t | wKeyNo, | ||
| uint16_t | wKeyVersionBufSize, | ||
| uint16_t * | wKeyVersion, | ||
| uint16_t * | wKeyVersionLength, | ||
| uint16_t * | pKeyType | ||
| ) |
Get a key entry information block.
The function returns the key type and all key versions of a key entry. This information is retrieved by the phhalHw_SamAV2_Cmd_SAM_GetKeyEntry command. All additional information which is returned by the phhalHw_SamAV2_Cmd_SAM_GetKeyEntry command is stored in the configuration parameters of this layer. To access these values the function phKeyStore_SamAV2_GetConfig has to be used.
| PH_ERR_SUCCESS | Operation successful. |
| Other | Depending on implementation and underlaying component. |
| [in] | pDataParams | [In] Pointer to this layer's parameter structure. |
| [in] | wKeyNo | [In] Key number of the key entry of interest. |
| [in] | wKeyVersionBufSize | [In] Buffer Size of wKeyVersion. |
| [out] | wKeyVersion | [Out] Array for version information. |
| [out] | wKeyVersionLength | [Out] Length of valid data in wKeyVersion. |
| [out] | pKeyType | [Out] Type of the key. |
| phStatus_t phKeyStore_SamAV2_GetKey | ( | phKeyStore_SamAV2_DataParams_t * | pDataParams, |
| uint16_t | wKeyNo, | ||
| uint16_t | wKeyVersion, | ||
| uint8_t | bKeyBufSize, | ||
| uint8_t * | pKey, | ||
| uint16_t * | pKeyType | ||
| ) |
Get a key.
The function returns a key selected by its key version:
| PH_ERR_SUCCESS | Operation successful. |
| Other | Depending on implementation and underlaying component. |
| [in] | pDataParams | [In] Pointer to this layer's parameter structure. |
| [in] | wKeyNo | [In] Key number of the key to be retrieved. |
| [in] | wKeyVersion | [In] Key version of the key to be retrieved). |
| [in] | bKeyBufSize | [In] Size of the key buffer. |
| [out] | pKey | [Out] Pointer to the key itself. |
| [out] | pKeyType | [Out] Type of the key. |
| phStatus_t phKeyStore_SamAV2_SetConfig | ( | phKeyStore_SamAV2_DataParams_t * | pDataParams, |
| uint16_t | wConfig, | ||
| uint16_t | wValue | ||
| ) |
Set configuration parameter.
| PH_ERR_SUCCESS | Operation successful. |
| Other | Depending on implementation and underlaying component. |
| [in] | pDataParams | [In] Pointer to this layer's parameter structure. |
| [in] | wConfig | [In] Configuration Identifier |
| [in] | wValue | [In] Configuration Value |
| phStatus_t phKeyStore_SamAV2_SetConfigStr | ( | phKeyStore_SamAV2_DataParams_t * | pDataParams, |
| uint16_t | wConfig, | ||
| uint8_t * | pBuffer, | ||
| uint16_t | wBufferLength | ||
| ) |
Set configuration parameter.
| PH_ERR_SUCCESS | Operation successful. |
| Other | Depending on implementation and underlaying component. |
| [in] | pDataParams | [In] Pointer to this layer's parameter structure. |
| [in] | wConfig | [In] Configuration Identifier. |
| [in] | pBuffer | [In] Buffer containing the configuration string. |
| [in] | wBufferLength | [In] Length of configuration string. |
| phStatus_t phKeyStore_SamAV2_GetConfig | ( | phKeyStore_SamAV2_DataParams_t * | pDataParams, |
| uint16_t | wConfig, | ||
| uint16_t * | pValue | ||
| ) |
Get configuration parameter.
| PH_ERR_SUCCESS | Operation successful. |
| Other | Depending on implementation and underlaying component. |
| [in] | pDataParams | [In] Pointer to this layer's parameter structure. |
| [in] | wConfig | [In] Configuration Identifier |
| [out] | pValue | [Out] Configuration Value |
| phStatus_t phKeyStore_SamAV2_GetConfigStr | ( | phKeyStore_SamAV2_DataParams_t * | pDataParams, |
| uint16_t | wConfig, | ||
| uint8_t ** | ppBuffer, | ||
| uint16_t * | pBufferLength | ||
| ) |
Get configuration parameter.
| PH_ERR_SUCCESS | Operation successful. |
| Other | Depending on implementation and underlaying component. |
| [in] | pDataParams | [In] Pointer to this layer's parameter structure. |
| [in] | wConfig | [In] Configuration Identifier |
| [out] | ppBuffer | [Out] Pointer to the buffer containing the configuration string. |
| [out] | pBufferLength | [Out] Amount of valid bytes in the configuration string buffer. |
| phStatus_t phKeyStore_SamAV2_ChangeKUC | ( | phKeyStore_SamAV2_DataParams_t * | pDataParams, |
| uint16_t | wRefNoKUC, | ||
| uint32_t | dwLimit | ||
| ) |
Change a key usage counter entry.
The function changes the KUC by using the phhalHw_SamAV2_Cmd_SAM_ChangeKUCEntry command. KeyNoCKUC and KeyVCKUC are set to according to the configuration parameters.
| PH_ERR_SUCCESS | Operation successful. |
| Other | Depending on implementation and underlaying component. |
| [in] | pDataParams | [In] Pointer to this layer's parameter structure. |
| [in] | wRefNoKUC | [In] Number of key entry. |
| [in] | dwLimit | [In] Limit of the Key Usage Counter |
| phStatus_t phKeyStore_SamAV2_GetKUC | ( | phKeyStore_SamAV2_DataParams_t * | pDataParams, |
| uint16_t | wRefNoKUC, | ||
| uint32_t * | pdwLimit, | ||
| uint32_t * | pdwCurVal | ||
| ) |
Obtain a key usage counter entry.
The function returnes the KUC entry retrieved by the phhalHw_SamAV2_Cmd_SAM_GetKUCEntry command. KeyNoCKUC and KeyVCKUC are stored in the configuration parameters and can be accessed via the phKeyStore_SamAV2_GetConfig function.
| PH_ERR_SUCCESS | Operation successful. |
| Other | Depending on implementation and underlaying component. |
| [in] | pDataParams | [In] Pointer to this layer's parameter structure. |
| [in] | wRefNoKUC | [In] number of the key usage counter to be looked at (00h to 0Fh) |
| [out] | pdwLimit | [Out] Currently set Limit in the KUC |
| [out] | pdwCurVal | [Out] Currently value in the KUC |