NXP NFC Reader Library
v4.040.05.011646
|
This is only a wrapper layer to abstract the different CryptoSym implementations. More...
![]() |
Modules | |
Component : Software | |
Software implementation of the Symmetric Cryptography interface. | |
Functions | |
phStatus_t | phCryptoSym_InvalidateKey (void *pDataParams) |
Invalidate the currently loaded key. More... | |
phStatus_t | phCryptoSym_Encrypt (void *pDataParams, uint16_t wOption, const uint8_t *pPlainBuffer, uint16_t wBufferLength, uint8_t *pEncryptedBuffer) |
Perform Encryption with one of the supported crypto modes. More... | |
phStatus_t | phCryptoSym_Decrypt (void *pDataParams, uint16_t wOption, const uint8_t *pEncryptedBuffer, uint16_t wBufferLength, uint8_t *pPlainBuffer) |
Perform Decryption with one of the supported crypto modes. More... | |
phStatus_t | phCryptoSym_CalculateMac (void *pDataParams, uint16_t wOption, const uint8_t *pData, uint16_t wDataLength, uint8_t *pMac, uint8_t *pMacLength) |
Calculate MAC with one of the supported MAC modes. More... | |
phStatus_t | phCryptoSym_LoadIv (void *pDataParams, const uint8_t *pIV, uint8_t bIVLength) |
Load IV. More... | |
phStatus_t | phCryptoSym_LoadKey (void *pDataParams, uint16_t wKeyNo, uint16_t wKeyVersion, uint16_t wKeyType) |
Load Key. More... | |
phStatus_t | phCryptoSym_LoadKeyDirect (void *pDataParams, const uint8_t *pKey, uint16_t wKeyType) |
Direct Load Key. More... | |
phStatus_t | phCryptoSym_SetConfig (void *pDataParams, uint16_t wConfig, uint16_t wValue) |
Set configuration parameter. More... | |
phStatus_t | phCryptoSym_GetConfig (void *pDataParams, uint16_t wConfig, uint16_t *pValue) |
Get configuration parameter. More... | |
phStatus_t | phCryptoSym_DiversifyKey (void *pDataParams, uint16_t wOption, uint16_t wKeyNo, uint16_t wKeyVersion, uint8_t *pDivInput, uint8_t bLenDivInput, uint8_t *pDiversifiedKey) |
Diversify Key - Note: This function invalidates the currently loaded key. More... | |
phStatus_t | phCryptoSym_DiversifyDirectKey (void *pDataParams, uint16_t wOption, uint8_t *pKey, uint16_t wKeyType, uint8_t *pDivInput, uint8_t bLenDivInput, uint8_t *pDiversifiedKey) |
Diversify Direct Key - Note: This function invalidates the currently loaded key. More... | |
phStatus_t | phCryptoSym_ApplyPadding (uint8_t bOption, const uint8_t *pDataIn, uint16_t wDataInLength, uint8_t bBlockSize, uint16_t wDataOutBufSize, uint8_t *pDataOut, uint16_t *pDataOutLength) |
Apply Padding to a given data buffer. More... | |
phStatus_t | phCryptoSym_RemovePadding (uint8_t bOption, const uint8_t *pDataIn, uint16_t wDataInLength, uint8_t bBlockSize, uint16_t wDataOutBufSize, uint8_t *pDataOut, uint16_t *pDataOutLength) |
Remove Padding to a given data buffer. More... | |
CryptoSym Layer Configs | |
#define | PH_CRYPTOSYM_CONFIG_KEY_TYPE 0x0000U |
Key Type. More... | |
#define | PH_CRYPTOSYM_CONFIG_KEY_SIZE 0x0001U |
Key Size of currently loaded key. More... | |
#define | PH_CRYPTOSYM_CONFIG_BLOCK_SIZE 0x0002U |
Block Size of currently loaded key. More... | |
#define | PH_CRYPTOSYM_CONFIG_KEEP_IV 0x0003U |
Keep init vector. More... | |
Supported IV Updated Behaviour Modes | |
#define | PH_CRYPTOSYM_VALUE_KEEP_IV_OFF 0x0000U |
Switch off Keep-IV behaviour. More... | |
#define | PH_CRYPTOSYM_VALUE_KEEP_IV_ON 0x0001U |
Switch on Keep-IV behaviour. More... | |
Supported Padding Modes. | |
#define | PH_CRYPTOSYM_PADDING_MODE_1 00U |
Pad with all zeros. | |
#define | PH_CRYPTOSYM_PADDING_MODE_2 01U |
Pad with a one followed by all zeros. | |
Supported Cipher Modes | |
#define | PH_CRYPTOSYM_CIPHER_MODE_ECB 0x00U |
ECB Cipher Mode. More... | |
#define | PH_CRYPTOSYM_CIPHER_MODE_CBC 0x01U |
CBC Cipher Mode. More... | |
#define | PH_CRYPTOSYM_CIPHER_MODE_CBC_DF4 0x02U |
CBC Cipher Mode for DF4. More... | |
Supported Mac Modes | |
#define | PH_CRYPTOSYM_MAC_MODE_CMAC 0x00U |
CMAC MAC Mode. More... | |
#define | PH_CRYPTOSYM_MAC_MODE_CBCMAC 0x01U |
CBCMAC MAC Mode. More... | |
Supported Key Types to be used in key loading functionality. | |
#define | PH_CRYPTOSYM_KEY_TYPE_AES128 0x0000U |
AES 128 Key [16 Bytes]. More... | |
#define | PH_CRYPTOSYM_KEY_TYPE_AES192 0x0001U |
AES 192 Key [24 Bytes]. More... | |
#define | PH_CRYPTOSYM_KEY_TYPE_AES256 0x0002U |
AES 256 Key [32 Bytes]. More... | |
#define | PH_CRYPTOSYM_KEY_TYPE_DES 0x0003U |
DES Single Key [8 Bytes]. More... | |
#define | PH_CRYPTOSYM_KEY_TYPE_2K3DES 0x0004U |
2 Key Triple Des [16 Bytes]. More... | |
#define | PH_CRYPTOSYM_KEY_TYPE_3K3DES 0x0005U |
3 Key Triple Des [24 Bytes]. More... | |
#define | PH_CRYPTOSYM_KEY_TYPE_INVALID 0xFFFFU |
Invalid Key. | |
#define | PH_CRYPTOSYM_KEY_TYPE_MIFARE 0x0006U |
MIFARE (R) Key. More... | |
Supported Diversification Types | |
#define | PH_CRYPTOSYM_DIV_MODE_DESFIRE 0x0000U |
DESFire Key Diversification. More... | |
#define | PH_CRYPTOSYM_DIV_MODE_MIFARE_PLUS 0x0001U |
MIFARE Plus Key Diversification. More... | |
#define | PH_CRYPTOSYM_DIV_MODE_MASK 0x00FFU |
Bitmask for diversification Mode. More... | |
#define | PH_CRYPTOSYM_DIV_OPTION_2K3DES_FULL 0x0000U |
Option for 2K3DES full-key diversification (only with PH_CRYPTOSYM_DIV_MODE_DESFIRE). More... | |
#define | PH_CRYPTOSYM_DIV_OPTION_2K3DES_HALF 0x8000U |
Option for 2K3DES half-key diversification (only with PH_CRYPTOSYM_DIV_MODE_DESFIRE). More... | |
General DES Defines. | |
#define | PH_CRYPTOSYM_DES_BLOCK_SIZE 8U |
Block size in DES algorithm. | |
#define | PH_CRYPTOSYM_DES_KEY_SIZE 8U |
Key size in DES algorithm for 56 bit key. | |
#define | PH_CRYPTOSYM_2K3DES_KEY_SIZE 16U |
Key size in AES algorithm for 112 bit key. | |
#define | PH_CRYPTOSYM_3K3DES_KEY_SIZE 24U |
Key size in AES algorithm for 168 bit key. | |
General AES Defines. | |
#define | PH_CRYPTOSYM_AES_BLOCK_SIZE 16U |
Block size in AES algorithm. | |
#define | PH_CRYPTOSYM_AES128_KEY_SIZE 16U |
Key size in AES algorithm for 128 bit key. | |
#define | PH_CRYPTOSYM_AES192_KEY_SIZE 24U |
Key size in AES algorithm for 192 bit key. | |
#define | PH_CRYPTOSYM_AES256_KEY_SIZE 32U |
Key size in AES algorithm for 256 bit key. | |
This is only a wrapper layer to abstract the different CryptoSym implementations.
With this wrapper it is possible to support more than one CryptoSym implementation in parallel, by adapting this wrapper.
Important hints for users of this component:
#define PH_CRYPTOSYM_CONFIG_KEY_TYPE 0x0000U |
#define PH_CRYPTOSYM_CONFIG_KEY_SIZE 0x0001U |
Key Size of currently loaded key.
Read-only.
#define PH_CRYPTOSYM_CONFIG_BLOCK_SIZE 0x0002U |
Block Size of currently loaded key.
Read-only.
#define PH_CRYPTOSYM_CONFIG_KEEP_IV 0x0003U |
Keep init vector.
Either PH_CRYPTOSYM_VALUE_KEEP_IV_OFF or PH_CRYPTOSYM_VALUE_KEEP_IV_ON.
This flag has to be used in combination with the option flag in the Encrypt/Decrypt/CalculateMac
function: If either the option in the function or this flag is set, the IV will be updated before
returning of the function.
R/W access possible.
#define PH_CRYPTOSYM_VALUE_KEEP_IV_OFF 0x0000U |
Switch off Keep-IV behaviour.
#define PH_CRYPTOSYM_VALUE_KEEP_IV_ON 0x0001U |
Switch on Keep-IV behaviour.
#define PH_CRYPTOSYM_CIPHER_MODE_ECB 0x00U |
ECB Cipher Mode.
#define PH_CRYPTOSYM_CIPHER_MODE_CBC 0x01U |
CBC Cipher Mode.
#define PH_CRYPTOSYM_CIPHER_MODE_CBC_DF4 0x02U |
CBC Cipher Mode for DF4.
#define PH_CRYPTOSYM_MAC_MODE_CMAC 0x00U |
CMAC MAC Mode.
#define PH_CRYPTOSYM_MAC_MODE_CBCMAC 0x01U |
CBCMAC MAC Mode.
#define PH_CRYPTOSYM_KEY_TYPE_AES128 0x0000U |
AES 128 Key [16 Bytes].
#define PH_CRYPTOSYM_KEY_TYPE_AES192 0x0001U |
AES 192 Key [24 Bytes].
#define PH_CRYPTOSYM_KEY_TYPE_AES256 0x0002U |
AES 256 Key [32 Bytes].
#define PH_CRYPTOSYM_KEY_TYPE_DES 0x0003U |
DES Single Key [8 Bytes].
#define PH_CRYPTOSYM_KEY_TYPE_2K3DES 0x0004U |
2 Key Triple Des [16 Bytes].
#define PH_CRYPTOSYM_KEY_TYPE_3K3DES 0x0005U |
3 Key Triple Des [24 Bytes].
#define PH_CRYPTOSYM_KEY_TYPE_MIFARE 0x0006U |
MIFARE (R) Key.
#define PH_CRYPTOSYM_DIV_MODE_DESFIRE 0x0000U |
DESFire Key Diversification.
#define PH_CRYPTOSYM_DIV_MODE_MIFARE_PLUS 0x0001U |
MIFARE Plus Key Diversification.
#define PH_CRYPTOSYM_DIV_MODE_MASK 0x00FFU |
Bitmask for diversification Mode.
#define PH_CRYPTOSYM_DIV_OPTION_2K3DES_FULL 0x0000U |
Option for 2K3DES full-key diversification (only with PH_CRYPTOSYM_DIV_MODE_DESFIRE).
#define PH_CRYPTOSYM_DIV_OPTION_2K3DES_HALF 0x8000U |
Option for 2K3DES half-key diversification (only with PH_CRYPTOSYM_DIV_MODE_DESFIRE).
phStatus_t phCryptoSym_InvalidateKey | ( | void * | pDataParams | ) |
Invalidate the currently loaded key.
Resets the key, the IV, the keep IV flag and the key Type.
PH_ERR_SUCCESS | Operation successful. |
[in] | pDataParams | Pointer to this layer's parameter structure |
phStatus_t phCryptoSym_Encrypt | ( | void * | pDataParams, |
uint16_t | wOption, | ||
const uint8_t * | pPlainBuffer, | ||
uint16_t | wBufferLength, | ||
uint8_t * | pEncryptedBuffer | ||
) |
Perform Encryption with one of the supported crypto modes.
The option word specifies the operation mode to use and the update behavior of the IV. All modes of operation are coded in the LSB, the flags in the MSB. The following Cipher modes are supported:
The following Flags are supported:
Note: The input data length needs to be a multiple of the current block size
PH_ERR_SUCCESS | Operation successful. |
PH_ERR_INVALID_PARAMETER | wPlainBufferLength is not a multiple of the current block size. |
PH_ERR_INVALID_PARAMETER | An unsupported key is loaded (or no key is loaded). |
PH_ERR_UNSUPPORTED_PARAMETER | An unknown cipher option wOption is specified. |
[in] | pDataParams | Pointer to this layer's parameter structure. |
[in] | wOption | Option byte specifying the cipher mode and the update behavior of the IV |
[in] | pPlainBuffer | plain data buffer |
[in] | wBufferLength | length of plain and encrypted data buffer - needs to be a multiple of the current block size |
[out] | pEncryptedBuffer | encrypted data buffer |
phStatus_t phCryptoSym_Decrypt | ( | void * | pDataParams, |
uint16_t | wOption, | ||
const uint8_t * | pEncryptedBuffer, | ||
uint16_t | wBufferLength, | ||
uint8_t * | pPlainBuffer | ||
) |
Perform Decryption with one of the supported crypto modes.
The option word specifies the operation mode to use and the update behavior of the IV. All modes of operation are coded in the LSB, the flags in the MSB. The following Cipher modes are supported:
The following Flags are supported:
Note: The input data length needs to be a multiple of the current block size
PH_ERR_SUCCESS | Operation successful. |
PH_ERR_INVALID_PARAMETER | wPlainBufferLength is not a multiple of the current block size. |
PH_ERR_INVALID_PARAMETER | An unsupported key is loaded (or no key is loaded). |
PH_ERR_UNSUPPORTED_PARAMETER | An unknown cipher option wOption is specified. |
[in] | pDataParams | Pointer to this layer's parameter structure. |
[in] | wOption | Option byte specifying the cipher mode and the update behavior of the IV |
[in] | pEncryptedBuffer | encrypted data buffer |
[in] | wBufferLength | length of plain and encrypted data buffer - needs to be a multiple of the current block size |
[out] | pPlainBuffer | plain data buffer |
phStatus_t phCryptoSym_CalculateMac | ( | void * | pDataParams, |
uint16_t | wOption, | ||
const uint8_t * | pData, | ||
uint16_t | wDataLength, | ||
uint8_t * | pMac, | ||
uint8_t * | pMacLength | ||
) |
Calculate MAC with one of the supported MAC modes.
The option word specifies the MAC mode to use and the update behavior of the IV as well as the completion behavior. All modes of operation are coded in the LSB, the flags in the MSB. The following Cipher modes are supported:
The following Flags are supported:
Note: If PH_EXCHANGE_BUFFERED_BIT is set, the input length needs to be a multiple of the block length!
PH_ERR_SUCCESS | Operation successful. |
PH_ERR_INVALID_PARAMETER | wDataLength is not a multiple of the current block size and the option PH_EXCHANGE_BUFFERED_BIT is set. |
PH_ERR_INVALID_PARAMETER | An unsupported key is loaded (or no key is loaded). |
PH_ERR_UNSUPPORTED_PARAMETER | An unknown mac option wOption is specified. |
[in] | pDataParams | Pointer to this layer's parameter structure. |
[in] | wOption | Option byte specifying the MAC mode and the update behavior of the IV and the completion flag. |
[in] | pData | input block; uint8_t[wDataLength] |
[in] | wDataLength | number of input data bytes |
[out] | pMac | output MAC block; uint8_t[16] |
[out] | pMacLength | Length of MAC |
Load IV.
Note: Before loading of an IV can be performed, a key has to be loaded upfront.
PH_ERR_SUCCESS | Operation successful. |
PH_ERR_INVALID_PARAMETER | bIVLength does not match the current block size. |
[in] | pDataParams | Pointer to this layer's parameter structure. |
[in] | pIV | IV[bIVLength]. |
[in] | bIVLength | Length of IV. |
phStatus_t phCryptoSym_LoadKey | ( | void * | pDataParams, |
uint16_t | wKeyNo, | ||
uint16_t | wKeyVersion, | ||
uint16_t | wKeyType | ||
) |
Load Key.
This function uses the key storage provided at component initialization to retrieve the key identified by wKeyNo and wKeyVersion. After retrieving the key is loaded into the internal key storage array to be prepared for subsequent cipher operations.
PH_ERR_SUCCESS | Operation successful. |
PH_ERR_INVALID_DATA_PARAMS | No keystore specified at Init. |
PH_ERR_UNSUPPORTED_PARAMETER | Key Type not supported. |
[in] | pDataParams | Pointer to this layer's parameter structure. |
[in] | wKeyNo | Number of the Key |
[in] | wKeyVersion | Version of the key |
[in] | wKeyType | Type of Key |
phStatus_t phCryptoSym_LoadKeyDirect | ( | void * | pDataParams, |
const uint8_t * | pKey, | ||
uint16_t | wKeyType | ||
) |
Direct Load Key.
The key provided in the pKey parameter is loaded into the internal key storage array to be prepared for subsequent cipher operations.
PH_ERR_SUCCESS | Operation successful. |
PH_ERR_UNSUPPORTED_PARAMETER | Key Type not supported. |
[in] | pDataParams | Pointer to this layer's parameter structure. |
[in] | pKey | key pointer to the key |
[in] | wKeyType | ID of the Key type |
Set configuration parameter.
PH_ERR_SUCCESS | Operation successful. |
PH_ERR_UNSUPPORTED_PARAMETER | Invalid (Unsupported) wConfig. |
PH_ERR_INVALID_PARAMETER | Valid wConfig but invalid wValue for that config. |
[in] | pDataParams | Pointer to this layer's parameter structure. |
[in] | wConfig | Configuration Identifier |
[in] | wValue | Configuration Value |
Get configuration parameter.
PH_ERR_SUCCESS | Operation successful. |
PH_ERR_UNSUPPORTED_PARAMETER | Invalid (Unsupported) wConfig. |
PH_ERR_INVALID_PARAMETER | Value behind wConfig not valid at the moment. |
[in] | pDataParams | Pointer to this layer's parameter structure. |
[in] | wConfig | Configuration Identifier |
[out] | pValue | Configuration Value |
phStatus_t phCryptoSym_DiversifyKey | ( | void * | pDataParams, |
uint16_t | wOption, | ||
uint16_t | wKeyNo, | ||
uint16_t | wKeyVersion, | ||
uint8_t * | pDivInput, | ||
uint8_t | bLenDivInput, | ||
uint8_t * | pDiversifiedKey | ||
) |
Diversify Key - Note: This function invalidates the currently loaded key.
Using the key stored in the keystore passed at initialization of the component and identified by wKeyNo and wKeyVersion this function calculates a diversified key according to the wOption specified that can be used in different applications. The following key diversification methods are supported:
PH_ERR_SUCCESS | Operation successful. |
PH_ERR_INVALID_DATA_PARAMS | No keystore specified at Init. |
PH_ERR_UNSUPPORTED_PARAMETER | Key Type not supported (for key diversification). |
PH_ERR_LENGTH_ERROR | Length of diversification input is wrong. |
[in] | pDataParams | Pointer to this layer's parameter structure. |
[in] | wOption | Option to specify the diversification method |
[in] | wKeyNo | Number of the Key |
[in] | wKeyVersion | Version of the key |
[in] | pDivInput | Diversification Input used to diversify the key. |
[in] | bLenDivInput | Length of diversification input used to diversify the key. If 0, no diversification is performed. |
[out] | pDiversifiedKey | Diversified key |
phStatus_t phCryptoSym_DiversifyDirectKey | ( | void * | pDataParams, |
uint16_t | wOption, | ||
uint8_t * | pKey, | ||
uint16_t | wKeyType, | ||
uint8_t * | pDivInput, | ||
uint8_t | bLenDivInput, | ||
uint8_t * | pDiversifiedKey | ||
) |
Diversify Direct Key - Note: This function invalidates the currently loaded key.
Using the key passed in the pKey parameter this function calculates a diversified key according to the wOption specified that can be used in different applications. The following key diversification methods are supported:
PH_ERR_SUCCESS | Operation successful. |
PH_ERR_UNSUPPORTED_PARAMETER | Key Type not supported (for key diversification). |
PH_ERR_LENGTH_ERROR | Length of diversification input is wrong. |
[in] | pDataParams | Pointer to this layer's parameter structure. |
[in] | wOption | Option to specify the diversification method |
[in] | pKey | Key to be diversified |
[in] | wKeyType | Type of the key |
[in] | pDivInput | Diversification Input used to diversify the key. |
[in] | bLenDivInput | Length of diversification input used to diversify the key. If 0, no diversification is performed. |
[out] | pDiversifiedKey | Diversified key |
phStatus_t phCryptoSym_ApplyPadding | ( | uint8_t | bOption, |
const uint8_t * | pDataIn, | ||
uint16_t | wDataInLength, | ||
uint8_t | bBlockSize, | ||
uint16_t | wDataOutBufSize, | ||
uint8_t * | pDataOut, | ||
uint16_t * | pDataOutLength | ||
) |
Apply Padding to a given data buffer.
PH_ERR_SUCCESS | Operation successful. |
PH_ERR_BUFFER_OVERFLOW | wDataOutBufSize is too small. |
PH_ERR_INVALID_PARAMETER | Unsupported bOption. |
[in] | bOption | Specifies padding mode (1 or 2) |
[in] | pDataIn | Pointer to input data array |
[in] | wDataInLength | Length of input data |
[in] | bBlockSize | Block size to be used for padding |
[in] | wDataOutBufSize | Size of data array |
[out] | pDataOut | Pointer to output data array |
[out] | pDataOutLength | Length of output data |
phStatus_t phCryptoSym_RemovePadding | ( | uint8_t | bOption, |
const uint8_t * | pDataIn, | ||
uint16_t | wDataInLength, | ||
uint8_t | bBlockSize, | ||
uint16_t | wDataOutBufSize, | ||
uint8_t * | pDataOut, | ||
uint16_t * | pDataOutLength | ||
) |
Remove Padding to a given data buffer.
PH_ERR_SUCCESS | Operation successful. |
PH_ERR_INVALID_PARAMETER | wDataInLength is not a multiple of the bBlockSize parameter. |
PH_ERR_INVALID_PARAMETER | Unsupported bOption. |
PH_ERR_FRAMING_ERROR | Padding byte wrong. |
[in] | bOption | Specifies padding mode (1 or 2) |
[in] | pDataIn | Pointer to input data array |
[in] | wDataInLength | Length of input data |
[in] | bBlockSize | Block size to be used for padding |
[in] | wDataOutBufSize | Size of data array |
[out] | pDataOut | Pointer to output data array |
[out] | pDataOutLength | Length of output data |