NXP NFC Reader Library v4.040.05.011646

Modules | Functions
CryptoSym
Common

This is only a wrapper layer to abstract the different CryptoSym implementations. More...

Collaboration diagram for CryptoSym:

## 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.

## Detailed Description

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:

- Before use of any function, the dedicated crypto implementation has to be initialized (e.g. phCryptoSym_Sw_Init)
- Functions using a key store (phCryptoSym_LoadKey and phCryptoSym_DiversifyKey) are only available if a key store has been passed during component initialization
- Before any cipher operation or MAC operation (phCryptoSym_Encrypt, phCryptoSym_Decrypt, phCryptoSym_CalculateMac) can be used, a key has to be loaded using either phCryptoSym_LoadKey or phCryptoSym_LoadKeyDirect
- Before any cipher operation or MAC operation (phCryptoSym_Encrypt, phCryptoSym_Decrypt, phCryptoSym_CalculateMac) can be used, an appropriate IV has to be loaded by calling phCryptoSym_LoadIv
- Using phCryptoSym_GetConfig, the block sizes and key lengths for the currently loaded key can be retrieved

## Macro Definition Documentation

## § PH_CRYPTOSYM_CONFIG_KEY_TYPE

#define PH_CRYPTOSYM_CONFIG_KEY_TYPE 0x0000U

Key Type.

Read-only. Possible Values are:

- PH_CRYPTOSYM_KEY_TYPE_AES128
- PH_CRYPTOSYM_KEY_TYPE_AES192
- PH_CRYPTOSYM_KEY_TYPE_AES256
- PH_CRYPTOSYM_KEY_TYPE_DES
- PH_CRYPTOSYM_KEY_TYPE_2K3DES
- PH_CRYPTOSYM_KEY_TYPE_3K3DES
- PH_CRYPTOSYM_KEY_TYPE_INVALID
- PH_CRYPTOSYM_KEY_TYPE_MIFARE

## § PH_CRYPTOSYM_CONFIG_KEY_SIZE

#define PH_CRYPTOSYM_CONFIG_KEY_SIZE 0x0001U

Key Size of currently loaded key.

Read-only.

## § PH_CRYPTOSYM_CONFIG_BLOCK_SIZE

#define PH_CRYPTOSYM_CONFIG_BLOCK_SIZE 0x0002U

Block Size of currently loaded key.

Read-only.

## § PH_CRYPTOSYM_CONFIG_KEEP_IV

#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.

## § PH_CRYPTOSYM_VALUE_KEEP_IV_OFF

#define PH_CRYPTOSYM_VALUE_KEEP_IV_OFF 0x0000U

Switch off Keep-IV behaviour.

## § PH_CRYPTOSYM_VALUE_KEEP_IV_ON

#define PH_CRYPTOSYM_VALUE_KEEP_IV_ON 0x0001U

Switch on Keep-IV behaviour.

## § PH_CRYPTOSYM_CIPHER_MODE_ECB

#define PH_CRYPTOSYM_CIPHER_MODE_ECB 0x00U

ECB Cipher Mode.

## § PH_CRYPTOSYM_CIPHER_MODE_CBC

#define PH_CRYPTOSYM_CIPHER_MODE_CBC 0x01U

CBC Cipher Mode.

## § PH_CRYPTOSYM_CIPHER_MODE_CBC_DF4

#define PH_CRYPTOSYM_CIPHER_MODE_CBC_DF4 0x02U

CBC Cipher Mode for DF4.

## § PH_CRYPTOSYM_MAC_MODE_CMAC

#define PH_CRYPTOSYM_MAC_MODE_CMAC 0x00U

CMAC MAC Mode.

## § PH_CRYPTOSYM_MAC_MODE_CBCMAC

#define PH_CRYPTOSYM_MAC_MODE_CBCMAC 0x01U

CBCMAC MAC Mode.

## § PH_CRYPTOSYM_KEY_TYPE_AES128

#define PH_CRYPTOSYM_KEY_TYPE_AES128 0x0000U

AES 128 Key [16 Bytes].

## § PH_CRYPTOSYM_KEY_TYPE_AES192

#define PH_CRYPTOSYM_KEY_TYPE_AES192 0x0001U

AES 192 Key [24 Bytes].

## § PH_CRYPTOSYM_KEY_TYPE_AES256

#define PH_CRYPTOSYM_KEY_TYPE_AES256 0x0002U

AES 256 Key [32 Bytes].

## § PH_CRYPTOSYM_KEY_TYPE_DES

#define PH_CRYPTOSYM_KEY_TYPE_DES 0x0003U

DES Single Key [8 Bytes].

## § PH_CRYPTOSYM_KEY_TYPE_2K3DES

#define PH_CRYPTOSYM_KEY_TYPE_2K3DES 0x0004U

2 Key Triple Des [16 Bytes].

## § PH_CRYPTOSYM_KEY_TYPE_3K3DES

#define PH_CRYPTOSYM_KEY_TYPE_3K3DES 0x0005U

3 Key Triple Des [24 Bytes].

## § PH_CRYPTOSYM_KEY_TYPE_MIFARE

#define PH_CRYPTOSYM_KEY_TYPE_MIFARE 0x0006U

MIFARE (R) Key.

## § PH_CRYPTOSYM_DIV_MODE_DESFIRE

#define PH_CRYPTOSYM_DIV_MODE_DESFIRE 0x0000U

DESFire Key Diversification.

## § PH_CRYPTOSYM_DIV_MODE_MIFARE_PLUS

#define PH_CRYPTOSYM_DIV_MODE_MIFARE_PLUS 0x0001U

MIFARE Plus Key Diversification.

## § PH_CRYPTOSYM_DIV_MODE_MASK

#define PH_CRYPTOSYM_DIV_MODE_MASK 0x00FFU

Bitmask for diversification Mode.

## § PH_CRYPTOSYM_DIV_OPTION_2K3DES_FULL

#define PH_CRYPTOSYM_DIV_OPTION_2K3DES_FULL 0x0000U

Option for 2K3DES full-key diversification (only with PH_CRYPTOSYM_DIV_MODE_DESFIRE).

## § PH_CRYPTOSYM_DIV_OPTION_2K3DES_HALF

#define PH_CRYPTOSYM_DIV_OPTION_2K3DES_HALF 0x8000U

Option for 2K3DES half-key diversification (only with PH_CRYPTOSYM_DIV_MODE_DESFIRE).

## Function Documentation

## § phCryptoSym_InvalidateKey()

phStatus_t phCryptoSym_InvalidateKey | ( | void * | pDataParams | ) |

Invalidate the currently loaded key.

Resets the key, the IV, the keep IV flag and the key Type.

Returns
  Status code

Return values

  PH_ERR_SUCCESS | Operation successful.

Parameters

  [in] | pDataParams | Pointer to this layer's parameter structure

## § phCryptoSym_Encrypt()

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:

- PH_CRYPTOSYM_CIPHER_MODE_ECB
- PH_CRYPTOSYM_CIPHER_MODE_CBC
- PH_CRYPTOSYM_CIPHER_MODE_CBC_DF4

The following Flags are supported:

- PH_EXCHANGE_DEFAULT
- PH_EXCHANGE_BUFFER_FIRST
- PH_EXCHANGE_BUFFER_CONT
- PH_EXCHANGE_BUFFER_LAST

Note: The input data length needs to be a multiple of the current block size

Returns
  Status code

Return values

  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.

Parameters

  [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

## § phCryptoSym_Decrypt()

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:

- PH_CRYPTOSYM_CIPHER_MODE_ECB
- PH_CRYPTOSYM_CIPHER_MODE_CBC
- PH_CRYPTOSYM_CIPHER_MODE_CBC_DF4

The following Flags are supported:

- PH_EXCHANGE_DEFAULT
- PH_EXCHANGE_BUFFER_FIRST
- PH_EXCHANGE_BUFFER_CONT
- PH_EXCHANGE_BUFFER_LAST

Note: The input data length needs to be a multiple of the current block size

Returns
  Status code

Return values

  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.

Parameters

  [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

## § phCryptoSym_CalculateMac()

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:

- PH_CRYPTOSYM_MAC_MODE_CMAC
- PH_CRYPTOSYM_MAC_MODE_CBCMAC

The following Flags are supported:

- PH_EXCHANGE_DEFAULT
- PH_EXCHANGE_BUFFER_FIRST
- PH_EXCHANGE_BUFFER_CONT
- PH_EXCHANGE_BUFFER_LAST

Note: If PH_EXCHANGE_BUFFERED_BIT is set, the input length needs to be a multiple of the block length!

Returns
  Status code

Return values

  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.

Parameters

  [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

## § phCryptoSym_LoadIv()

phStatus_t phCryptoSym_LoadIv | ( | void * | pDataParams,
|  | const uint8_t * | pIV,
|  | uint8_t | bIVLength
| ) |  |

Load IV.

Note: Before loading of an IV can be performed, a key has to be loaded upfront.

Returns
  Status code

Return values

  PH_ERR_SUCCESS | Operation successful.
  PH_ERR_INVALID_PARAMETER | bIVLength does not match the current block size.

Parameters

  [in] | pDataParams | Pointer to this layer's parameter structure.
  [in] | pIV | IV[bIVLength].
  [in] | bIVLength | Length of IV.

## § phCryptoSym_LoadKey()

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.

Returns
  Status code

Return values

  PH_ERR_SUCCESS | Operation successful.
  PH_ERR_INVALID_DATA_PARAMS | No keystore specified at Init.
  PH_ERR_UNSUPPORTED_PARAMETER | Key Type not supported.

Parameters

  [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

## § phCryptoSym_LoadKeyDirect()

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.

Returns
  Status code

Return values

  PH_ERR_SUCCESS | Operation successful.
  PH_ERR_UNSUPPORTED_PARAMETER | Key Type not supported.

Parameters

  [in] | pDataParams | Pointer to this layer's parameter structure.
  [in] | pKey | key pointer to the key
  [in] | wKeyType | ID of the Key type

## § phCryptoSym_SetConfig()

phStatus_t phCryptoSym_SetConfig | ( | void * | pDataParams,
|  | uint16_t | wConfig,
|  | uint16_t | wValue
| ) |  |

Set configuration parameter.

Returns
  Status code

Return values

  PH_ERR_SUCCESS | Operation successful.
  PH_ERR_UNSUPPORTED_PARAMETER | Invalid (Unsupported) wConfig.
  PH_ERR_INVALID_PARAMETER | Valid wConfig but invalid wValue for that config.

Parameters

  [in] | pDataParams | Pointer to this layer's parameter structure.
  [in] | wConfig | Configuration Identifier
  [in] | wValue | Configuration Value

## § phCryptoSym_GetConfig()

phStatus_t phCryptoSym_GetConfig | ( | void * | pDataParams,
|  | uint16_t | wConfig,
|  | uint16_t * | pValue
| ) |  |

Get configuration parameter.

Returns
  Status code

Return values

  PH_ERR_SUCCESS | Operation successful.
  PH_ERR_UNSUPPORTED_PARAMETER | Invalid (Unsupported) wConfig.
  PH_ERR_INVALID_PARAMETER | Value behind wConfig not valid at the moment.

Parameters

  [in] | pDataParams | Pointer to this layer's parameter structure.
  [in] | wConfig | Configuration Identifier
  [out] | pValue | Configuration Value

## § phCryptoSym_DiversifyKey()

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_CRYPTOSYM_DIV_MODE_MIFARE_PLUS

Returns
  Status code

Return values

  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.

Parameters

  [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

## § phCryptoSym_DiversifyDirectKey()

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_CRYPTOSYM_DIV_MODE_MIFARE_PLUS

Returns
  Status code

Return values

  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.

Parameters

  [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

## § phCryptoSym_ApplyPadding()

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.

Returns
  Status code

Return values

  PH_ERR_SUCCESS | Operation successful.
  PH_ERR_BUFFER_OVERFLOW | wDataOutBufSize is too small.
  PH_ERR_INVALID_PARAMETER | Unsupported bOption.

Parameters

  [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

## § phCryptoSym_RemovePadding()

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.

Returns
  Status code

Return values

  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.

Parameters

  [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