NXP Reader Library  v17.1.0.2535

Implementation of SAM Key Management commands. More...

Collaboration diagram for 03_KeyManagement:

Modules

 Defines
 Definitions for SAM Key Management commands.
 

Functions

phStatus_t phhalHw_Sam_Cmd_SAM_ChangeKeyEntry (phhalHw_Sam_DataParams_t *pDataParams, uint8_t bKeyNo, uint8_t bProMas, uint8_t *pKeyData, uint8_t bKeyDataLen)
 Change a symmetric key entry in the key table of the SAM. More...
 
phStatus_t phhalHw_Sam_Cmd_SAM_ChangeKeyEntryOffline (phhalHw_Sam_DataParams_t *pDataParams, uint8_t bKeyNo, uint8_t bProMas, uint16_t wChangeCtr, uint8_t *pOfflineCrypto, uint8_t bOfflineCryptoLen, uint8_t bEnableOfflineAck, uint8_t **ppOfflineAck, uint16_t *pOfflineAckLen)
 Change a Offline symmetric key entry in the key entry table of the SAM. More...
 
phStatus_t phhalHw_Sam_Cmd_SAM_ChangeKUCEntry (phhalHw_Sam_DataParams_t *pDataParams, uint8_t bKucNo, uint8_t bProMas, uint8_t *pKucData, uint8_t bKucDataLen)
 Change the key usage counter (KUC). More...
 
phStatus_t phhalHw_Sam_Cmd_SAM_ChangeKUCEntryOffline (phhalHw_Sam_DataParams_t *pDataParams, uint8_t bKucNo, uint8_t bProMas, uint16_t wChangeCtr, uint8_t *pOfflineCrypto, uint8_t bOfflineCryptoLen, uint8_t bEnableOfflineAck, uint8_t **ppOfflineAck, uint16_t *pOfflineAckLen)
 Change a Offline KUC entry in the key entry table of the SAM. More...
 
phStatus_t phhalHw_Sam_Cmd_SAM_DisableKeyEntry (phhalHw_Sam_DataParams_t *pDataParams, uint8_t bKeyNo)
 Disable a key entry. More...
 
phStatus_t phhalHw_Sam_Cmd_SAM_DisableKeyEntryOffline (phhalHw_Sam_DataParams_t *pDataParams, uint8_t bKeyNo, uint16_t wChangeCtr, uint8_t *pOfflineCrypto, uint8_t bOfflineCryptoLen, uint8_t bEnableOfflineAck, uint8_t **ppOfflineAck, uint16_t *pOfflineAckLen)
 Disable a key entry using offline cryptogram. More...
 
phStatus_t phhalHw_Sam_Cmd_SAM_EncipherKeyEntry (phhalHw_Sam_DataParams_t *pDataParams, uint8_t bPersoKeyNo, uint8_t bKeyNo, uint8_t bOption, uint16_t wPersoCtr, uint8_t *pDivInput, uint8_t bDivInputLen, uint8_t **ppOfflineCrypto, uint16_t *pOfflineCryptoLen)
 The SAM_EncipherKeyEntry is a Personalization SAM command used to prepare a cryptogram (according to Offline change protection) for the OfflineChange key on a target SAM. More...
 
phStatus_t phhalHw_Sam_Cmd_SAM_GetKeyEntry (phhalHw_Sam_DataParams_t *pDataParams, uint8_t bKeyNo, uint8_t bMode, uint8_t **ppKeyEntry, uint16_t *pKeyEntryLen)
 Get information about a key entry. More...
 
phStatus_t phhalHw_Sam_Cmd_SAM_GetKUCEntry (phhalHw_Sam_DataParams_t *pDataParams, uint8_t bKucNo, uint8_t **ppKucEntry, uint16_t *pKucEntryLen)
 Get information about a key usage counter (KUC). More...
 
phStatus_t phhalHw_Sam_Cmd_SAM_DumpSessionKey (phhalHw_Sam_DataParams_t *pDataParams, uint8_t bDumpMode, uint8_t **ppSessionKey, uint16_t *pSessionKeyLen)
 Dump the current session key. More...
 
phStatus_t phhalHw_Sam_Cmd_SAM_DumpSecretKey (phhalHw_Sam_DataParams_t *pDataParams, uint8_t bDumpMode, uint8_t bKeyNo, uint8_t bKeyVer, uint8_t *pDivInput, uint8_t bDivInputLen, uint8_t **ppSecretKey, uint16_t *pSecretKeyLen)
 Retrive a PICC or OfflineCrypto key stored in the key table. More...
 
phStatus_t phhalHw_Sam_Cmd_SAM_DeriveKey (phhalHw_Sam_DataParams_t *pDataParams, uint8_t bSrcKeyNo, uint8_t bSrcKeyVer, uint8_t bDstKeyNo, uint8_t *pDeriveIn, uint8_t bDeriveInLen)
 Is used to derive a key from a source key (in other contexts often called master key) based on a CMAC operation. More...
 

Detailed Description

Implementation of SAM Key Management commands.

Function Documentation

◆ phhalHw_Sam_Cmd_SAM_ChangeKeyEntry()

phStatus_t phhalHw_Sam_Cmd_SAM_ChangeKeyEntry ( phhalHw_Sam_DataParams_t pDataParams,
uint8_t  bKeyNo,
uint8_t  bProMas,
uint8_t pKeyData,
uint8_t  bKeyDataLen 
)

Change a symmetric key entry in the key table of the SAM.

Returns
Status code
Return values
PH_ERR_SUCCESSOperation successful.
PH_ERR_INVALID_DATA_PARAMSpDataParams is NULL.
PH_ERR_INVALID_PARAMETERpKeyData is NULL.
OtherDepending on implementation and underlaying component.
Parameters
[in]pDataParams[In] Pointer to this layer's parameter structure.
[in]bKeyNo[In] Reference number of the key entry to be changed. One of the following,
  • NVM Keys: 0x00 - 0x7F
  • RAM Keys: 0xE0 - 0xE3
[in]bProMas[In] Program mask indicating the fields that should be changed. All the below option can be combined by using bitwise OR operator.
[in]pKeyData[In] Buffer containing the key data information to be updated.
[in]bKeyDataLen[In] Length of bytes available in pKeyData buffer.

◆ phhalHw_Sam_Cmd_SAM_ChangeKeyEntryOffline()

phStatus_t phhalHw_Sam_Cmd_SAM_ChangeKeyEntryOffline ( phhalHw_Sam_DataParams_t pDataParams,
uint8_t  bKeyNo,
uint8_t  bProMas,
uint16_t  wChangeCtr,
uint8_t pOfflineCrypto,
uint8_t  bOfflineCryptoLen,
uint8_t  bEnableOfflineAck,
uint8_t **  ppOfflineAck,
uint16_t pOfflineAckLen 
)

Change a Offline symmetric key entry in the key entry table of the SAM.

  • Selected by a change key (KeyNoCEK) of OfflineChange Key Class is restricting the key update to an active Offline Key Activation.
  • The command and its payload are protected by the Offline change protection.
Returns
Status code
Return values
PH_ERR_SUCCESSOperation successful.
PH_ERR_INVALID_DATA_PARAMSpDataParams is NULL.
PH_ERR_INVALID_PARAMETERpOfflineCrypto and pOfflineAck is NULL.
OtherDepending on implementation and underlaying component.
Parameters
[in]pDataParams[In] Pointer to this layer's parameter structure.
[in]bKeyNo[In] Reference number of the key entry to be changed. One of the following,
  • NVM Keys: 0x00 - 0x7F
  • RAM Keys: 0xE0 - 0xE3
[in]bProMas[In] Program mask indicating the fields that should be changed. All the below option can be combined by using bitwise OR operator.
[in]wChangeCtr[In] Change Counter to avoid replay attacks.
[in]pOfflineCrypto[In] Offline Cryptogram exchanged to SAM (EncKeyEntry + OfflineMAC)
  • Encrypted key entry as E(Kce, KeyEntry [|| SAMUID])
  • Integrity MAC protection as MACt (Kcm, CLA || INS || P1 || P2 || LC || Change_Ctr || E(Kce, KeyEntry [|| SAMUID]))
[in]bOfflineCryptoLen[In] Length of bytes available in pOfflineCrypto buffer
[in]bEnableOfflineAck[In] To Enable reception of Offline Acknowledge
[out]ppOfflineAck[Out] Offline Acknowledge information received from SAM. Will be based on
[out]pOfflineAckLen[Out] Length of bytes available in ppOfflineAck buffer

◆ phhalHw_Sam_Cmd_SAM_ChangeKUCEntry()

phStatus_t phhalHw_Sam_Cmd_SAM_ChangeKUCEntry ( phhalHw_Sam_DataParams_t pDataParams,
uint8_t  bKucNo,
uint8_t  bProMas,
uint8_t pKucData,
uint8_t  bKucDataLen 
)

Change the key usage counter (KUC).

Selection is done by its reference number.

Returns
Status code
Return values
PH_ERR_SUCCESSOperation successful.
PH_ERR_INVALID_DATA_PARAMSpDataParams is NULL.
PH_ERR_INVALID_PARAMETERpKucData is NULL.
OtherDepending on implementation and underlaying component.
Parameters
[in]pDataParams[In] Pointer to this layer's parameter structure.
[in]bKucNo[In] Reference number of the key usage counter to be updated (00h to 0Fh).
[in]bProMas[In] Program mask indicating the fields that should be changed. All the below option can be combined by using bitwise OR operator.
[in]pKucData[In] Buffer containing the Key Usage Counter data.
[in]bKucDataLen[In] Length of bytes available in pKucData buffer.

◆ phhalHw_Sam_Cmd_SAM_ChangeKUCEntryOffline()

phStatus_t phhalHw_Sam_Cmd_SAM_ChangeKUCEntryOffline ( phhalHw_Sam_DataParams_t pDataParams,
uint8_t  bKucNo,
uint8_t  bProMas,
uint16_t  wChangeCtr,
uint8_t pOfflineCrypto,
uint8_t  bOfflineCryptoLen,
uint8_t  bEnableOfflineAck,
uint8_t **  ppOfflineAck,
uint16_t pOfflineAckLen 
)

Change a Offline KUC entry in the key entry table of the SAM.

Returns
Status code
Return values
PH_ERR_SUCCESSOperation successful.
PH_ERR_INVALID_DATA_PARAMSpDataParams is NULL.
PH_ERR_INVALID_PARAMETERpOfflineCrypto and pOfflineAck is NULL.
OtherDepending on implementation and underlaying component.
Parameters
[in]pDataParams[In] Pointer to this layer's parameter structure.
[in]bKucNo[In] Reference number of the key usage counter to be updated (00h to 0Fh).
[in]bProMas[In] Program mask indicating the fields that should be changed. All the below option can be combined by using bitwise OR operator.
[in]wChangeCtr[In] Change Counter to avoid replay attacks.
[in]pOfflineCrypto[In] Offline Cryptogram exchanged to SAM (EncKUCEntry + OfflineMAC)
  • Encrypted key entry as E(Kce, KUCEntry [|| SAMUID])
  • Integrity MAC protection as MACt (Kcm, CLA || INS || P1 || P2 || LC || Change_Ctr || E(Kce, KUCEntry [|| SAMUID]))
[in]bOfflineCryptoLen[In] Length of bytes available in pOfflineCrypto buffer
[in]bEnableOfflineAck[In] To Enable reception of Offline Acknowledge
[out]ppOfflineAck[Out] Offline Acknowledge information received from SAM. Will be based on
[out]pOfflineAckLen[Out] Length of bytes available in ppOfflineAck buffer

◆ phhalHw_Sam_Cmd_SAM_DisableKeyEntry()

phStatus_t phhalHw_Sam_Cmd_SAM_DisableKeyEntry ( phhalHw_Sam_DataParams_t pDataParams,
uint8_t  bKeyNo 
)

Disable a key entry.

  • The SAM_DisableKeyEntry is used to disable any key entry of the KST, hence enabling SETBit9. The plain data field is not present.
  • If there is an active authentication with a key of the targeted key entry, be it a Host Authentication (Logical Channel Global State), or any PICC Authentication or key activation (XMode State), this will be reset on any LC.
  • Note that even if the Host Authentication on the current LC is reset, the current command response will still be processed with secure messaging.
  • After executing this command, the corresponding disable flag in the key entry is set and the key entry cannot be used anymore for authentication and key change procedures.
  • The key entry can still be read by a SAM_GetKeyEntry command.
  • To reactivate the entry, a SAM_ChangeKeyEntry command has to be issued.
  • All fields in the key entry can still be changed by this command even if the entry has been disabled.
Returns
Status code
Return values
PH_ERR_SUCCESSOperation successful.
PH_ERR_INVALID_DATA_PARAMSpDataParams is NULL.
OtherDepending on implementation and underlaying component.
Parameters
[in]pDataParams[In] Pointer to this layer's parameter structure.
[in]bKeyNo[In] Key reference number of the key entry to disable. One of the following,
  • NVM Keys: 0x00 - 0x7F
  • RAM Keys: 0xE0 - 0xE3

◆ phhalHw_Sam_Cmd_SAM_DisableKeyEntryOffline()

phStatus_t phhalHw_Sam_Cmd_SAM_DisableKeyEntryOffline ( phhalHw_Sam_DataParams_t pDataParams,
uint8_t  bKeyNo,
uint16_t  wChangeCtr,
uint8_t pOfflineCrypto,
uint8_t  bOfflineCryptoLen,
uint8_t  bEnableOfflineAck,
uint8_t **  ppOfflineAck,
uint16_t pOfflineAckLen 
)

Disable a key entry using offline cryptogram.

Returns
Status code
Return values
PH_ERR_SUCCESSOperation successful.
PH_ERR_INVALID_DATA_PARAMSpDataParams is NULL.
PH_ERR_INVALID_PARAMETERpOfflineCrypto and pOfflineAck is NULL.
OtherDepending on implementation and underlaying component.
Parameters
[in]pDataParams[In] Pointer to this layer's parameter structure.
[in]bKeyNo[In] Key reference number of the key entry to disable. One of the following,
  • NVM Keys: 0x00 - 0x7F
  • RAM Keys: 0xE0 - 0xE3
[in]wChangeCtr[In] Change Counter to avoid replay attacks.
[in]pOfflineCrypto[In] Offline Cryptogram exchanged to SAM (EncKUCEntry + OfflineMAC)
  • Encrypted GoldField as E(Kce, SAMUID)
  • Integrity MAC protection as MACt (Kcm, CLA || INS || P1 || P2 || LC || Change_Ctr [|| E(Kce, SAMUID)])
[in]bOfflineCryptoLen[In] Length of bytes available in pOfflineCrypto buffer
[in]bEnableOfflineAck[In] To Enable reception of Offline Acknowledge
[out]ppOfflineAck[Out] Offline Acknowledge information received from SAM. Will be based on
[out]pOfflineAckLen[Out] Length of bytes available in ppOfflineAck buffer

◆ phhalHw_Sam_Cmd_SAM_EncipherKeyEntry()

phStatus_t phhalHw_Sam_Cmd_SAM_EncipherKeyEntry ( phhalHw_Sam_DataParams_t pDataParams,
uint8_t  bPersoKeyNo,
uint8_t  bKeyNo,
uint8_t  bOption,
uint16_t  wPersoCtr,
uint8_t pDivInput,
uint8_t  bDivInputLen,
uint8_t **  ppOfflineCrypto,
uint16_t pOfflineCryptoLen 
)

The SAM_EncipherKeyEntry is a Personalization SAM command used to prepare a cryptogram (according to Offline change protection) for the OfflineChange key on a target SAM.

The target Offline change counter (Perso_Ctr) are included in the generated cryptogram. It is only relevant for the target SAM and it shall not be compared to the (local) Change_Ctr.

Returns
Status code
Return values
PH_ERR_SUCCESSOperation successful.
PH_ERR_INVALID_DATA_PARAMSpDataParams is NULL.
PH_ERR_INVALID_PARAMETERpDivInput and pOfflineCryptoLen is NULL.
OtherDepending on implementation and underlaying component.
Parameters
[in]pDataParams[In] Pointer to this layer's parameter structure.
[in]bPersoKeyNo[In] Key reference number of the KST Key Entry to include in the cryptogram. One of the following,
  • NVM Keys: 0x00 - 0x7F
  • RAM Keys: 0xE0 - 0xE3
[in]bKeyNo[In] Key reference number of the KSTKeyEntry in the target SAM (00h to 7Fh).
[in]bOption[In] Option to include Key diversification and SAM UID in command.
[in]wPersoCtr[In] Change Counter to avoid replay attacks
[in]pDivInput[In] Diversification Input used to diversify the key.
[in]bDivInputLen[In] Length of bytes available in pDivInput buffer.
[out]ppOfflineCrypto[Out] Offline crypto information received from SAM.
  • EncKeyEntry: Encrypted key entry as E( K_{pe} , NewEntry [|| SAMUID])
  • OfflineMAC: Integrity MAC protection as MACt ( Kpm , Channel || 0xC1 || KeyNo || ProMas || 2 + 80 + 8 || Perso_Ctr || EncKeyEntry)
[out]pOfflineCryptoLen[Out] Length of bytes available in ppOfflineCrypto buffer

◆ phhalHw_Sam_Cmd_SAM_GetKeyEntry()

phStatus_t phhalHw_Sam_Cmd_SAM_GetKeyEntry ( phhalHw_Sam_DataParams_t pDataParams,
uint8_t  bKeyNo,
uint8_t  bMode,
uint8_t **  ppKeyEntry,
uint16_t pKeyEntryLen 
)

Get information about a key entry.

  • SAM_GetKeyEntry allows reading the contents of the KST Key Entry specified in bKeyNo parameter.
  • Instead of the full keys on positions a, b and c, only their key version will be returned, each packed in one byte.
  • This command can be issued without valid (host) authentication.
  • Supports retrieval of NVM and RAM Keys.
Returns
Status code
Return values
PH_ERR_SUCCESSOperation successful.
PH_ERR_INVALID_DATA_PARAMSpDataParams is NULL.
PH_ERR_INVALID_PARAMETERpKeyEntryLen is NULL.
OtherDepending on implementation and underlaying component.
Parameters
[in]pDataParams[In] Pointer to this layer's parameter structure.
[in]bKeyNo[In] Key reference number of the key entry to get. One of the following,
  • NVM Keys : 0x00 - 0x7F
  • PLUnlock Key: 0xF0
  • RAM Key : 0xE0 - 0xE3
[in]bMode[In] Key entry format to be used. Not applicable for RAM Keys
[out]ppKeyEntry[Out] Buffer containing the information about the key entry.
[out]pKeyEntryLen[Out] Length of bytes available in ppKeyEntry buffer.

◆ phhalHw_Sam_Cmd_SAM_GetKUCEntry()

phStatus_t phhalHw_Sam_Cmd_SAM_GetKUCEntry ( phhalHw_Sam_DataParams_t pDataParams,
uint8_t  bKucNo,
uint8_t **  ppKucEntry,
uint16_t pKucEntryLen 
)

Get information about a key usage counter (KUC).

  • SAM_GetKUCEntry allows reading the contents of the Key usage counter specified in bKucNo parameter.
  • This command can be issued without valid (host) authentication.
Returns
Status code
Return values
PH_ERR_SUCCESSOperation successful.
PH_ERR_INVALID_DATA_PARAMSpDataParams is NULL.
PH_ERR_INVALID_PARAMETERpKucEntryLen is NULL.
OtherDepending on implementation and underlaying component.
Parameters
[in]pDataParams[In] Pointer to this layer's parameter structure.
[in]bKucNo[In] Reference number of the key usage counter to be returned (00h to 0Fh).
[out]ppKucEntry[Out] Buffer containing the KUC entry.
[out]pKucEntryLen[Out] Length of bytes available in ppKucEntry buffer.

◆ phhalHw_Sam_Cmd_SAM_DumpSessionKey()

phStatus_t phhalHw_Sam_Cmd_SAM_DumpSessionKey ( phhalHw_Sam_DataParams_t pDataParams,
uint8_t  bDumpMode,
uint8_t **  ppSessionKey,
uint16_t pSessionKeyLen 
)

Dump the current session key.

  • Retrieve the session key of an established authentication with a DESFire PICC or a MIFARE Plus PICC. In this case, an active PICC authentication (for these card types) is required.
  • Retrieve the derived LRP key material. In this case, an KeyClass.OfflineCrypto activation of KeyType.AES_128LRP is required, that is the SAM must be in PICCState.OfflineCrypto.
Returns
Status code
Return values
PH_ERR_SUCCESSOperation successful.
PHHAL_HW_SAM_ERR_OK_CHAINING_ACTIVECorrect execution - more data available in response.
PH_ERR_INVALID_DATA_PARAMSpDataParams is NULL.
PH_ERR_INVALID_PARAMETERpSessionKeyLen is NULL.
OtherDepending on implementation and underlaying component.
Parameters
[in]pDataParams[In] Pointer to this layer's parameter structure.
[in]bDumpMode[In] Dump Mode.
[out]ppSessionKey[Out] Buffer containing Current session key information.
[out]pSessionKeyLen[Out] Length of bytes available in ppSessionKey buffer.

◆ phhalHw_Sam_Cmd_SAM_DumpSecretKey()

phStatus_t phhalHw_Sam_Cmd_SAM_DumpSecretKey ( phhalHw_Sam_DataParams_t pDataParams,
uint8_t  bDumpMode,
uint8_t  bKeyNo,
uint8_t  bKeyVer,
uint8_t pDivInput,
uint8_t  bDivInputLen,
uint8_t **  ppSecretKey,
uint16_t pSecretKeyLen 
)

Retrive a PICC or OfflineCrypto key stored in the key table.

Returns
Status code
Return values
PH_ERR_SUCCESSOperation successful.
PH_ERR_INVALID_DATA_PARAMSpDataParams is NULL.
PH_ERR_INVALID_PARAMETERpDivInput and pSecretKeyLen is NULL.
OtherDepending on implementation and underlaying component.
Parameters
[in]pDataParams[In] Pointer to this layer's parameter structure.
[in]bDumpMode[In] Dump Mode.
[in]bKeyNo[In] Reference number of the key entry to be dumped. One of the following
  • NVM Keys: 0x00 - 0x7F
  • RAM Keys: 0xE0 - 0xE3
[in]bKeyVer[In] Reference version of the key entry to be dumped.
[in]pDivInput[In] Diversification Input used to diversify the key.
[in]bDivInputLen[In] Length of bytes available in pDivInput buffer.
[out]ppSecretKey[Out] Buffer containing the plain secret key.
[out]pSecretKeyLen[Out] Length of bytes available in ppSecretKey buffer.

◆ phhalHw_Sam_Cmd_SAM_DeriveKey()

phStatus_t phhalHw_Sam_Cmd_SAM_DeriveKey ( phhalHw_Sam_DataParams_t pDataParams,
uint8_t  bSrcKeyNo,
uint8_t  bSrcKeyVer,
uint8_t  bDstKeyNo,
uint8_t pDeriveIn,
uint8_t  bDeriveInLen 
)

Is used to derive a key from a source key (in other contexts often called master key) based on a CMAC operation.

In a MIFARE context, this command can be used to support session key generations for the Transaction MAC and Secure Dynamic Messaging features, for back-end (and / or reader) interpretation and validation of the cryptograms created by the PICC.

Returns
Status code
Return values
PH_ERR_SUCCESSOperation successful.
PH_ERR_INVALID_DATA_PARAMSpDataParams is NULL.
PH_ERR_INVALID_PARAMETERpDeriveIn is NULL.
OtherDepending on implementation and underlaying component.
Parameters
[in]pDataParams[In] Pointer to this layer's parameter structure.
[in]bSrcKeyNo[In] Key number of the source key. One of the following,
  • NVM Keys: 0x00 - 0x7F
  • RAM Keys: 0xE0 - 0xE3
[in]bSrcKeyVer[In] Key version of the source key (00h to FFh).
[in]bDstKeyNo[In] Key number of the destination key entry, only RAM Keys: 0xE0 - 0xE3
[in]pDeriveIn[In] The derivation input for deriving the key.
[in]bDeriveInLen[In] Length of derivation input used to derive the key.