| Kinetis SDK v.2.0 API Reference Manual Rev. 0 Freescale Semiconductor, Inc.

- Main Page
- Related Pages
- API Reference

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Macros | Enumerations | Functions
LTC AES driver
LTC Blocking APIs

## Overview

This section describes the programming interface of the LTC AES driver.

## Macros
#define | LTC_AES_BLOCK_SIZE 16
| AES block size in bytes.
#define | LTC_AES_IV_SIZE 16
| AES Input Vector size in bytes.
#define | LTC_AES_DecryptCtr(base, input, output, size, counter, key, keySize, counterlast, szLeft) LTC_AES_CryptCtr(base, input, output, size, counter, key, keySize, counterlast, szLeft)
| AES CTR decrypt is mapped to the AES CTR generic operation.
#define | LTC_AES_EncryptCtr(base, input, output, size, counter, key, keySize, counterlast, szLeft) LTC_AES_CryptCtr(base, input, output, size, counter, key, keySize, counterlast, szLeft)
| AES CTR encrypt is mapped to the AES CTR generic operation.

## Enumerations
enum | ltc_aes_key_t { kLTC_EncryptKey = 0U, kLTC_DecryptKey = 1U }
| Type of AES key for ECB and CBC decrypt operations. More...

## Functions
status_t | LTC_AES_GenerateDecryptKey (LTC_Type *base, const uint8_t *encryptKey, uint8_t *decryptKey, uint32_t keySize)
| Transforms an AES encrypt key (forward AES) into the decrypt key (inverse AES). More...
status_t | LTC_AES_EncryptEcb (LTC_Type *base, const uint8_t *plaintext, uint8_t *ciphertext, uint32_t size, const uint8_t *key, uint32_t keySize)
| Encrypts AES using the ECB block mode. More...
status_t | LTC_AES_DecryptEcb (LTC_Type *base, const uint8_t *ciphertext, uint8_t *plaintext, uint32_t size, const uint8_t *key, uint32_t keySize, ltc_aes_key_t keyType)
| Decrypts AES using ECB block mode. More...
status_t | LTC_AES_EncryptCbc (LTC_Type *base, const uint8_t *plaintext, uint8_t *ciphertext, uint32_t size, const uint8_t iv[LTC_AES_IV_SIZE], const uint8_t *key, uint32_t keySize)
| Encrypts AES using CBC block mode. More...
status_t | LTC_AES_DecryptCbc (LTC_Type *base, const uint8_t *ciphertext, uint8_t *plaintext, uint32_t size, const uint8_t iv[LTC_AES_IV_SIZE], const uint8_t *key, uint32_t keySize, ltc_aes_key_t keyType)
| Decrypts AES using CBC block mode. More...
status_t | LTC_AES_CryptCtr (LTC_Type *base, const uint8_t *input, uint8_t *output, uint32_t size, uint8_t counter[LTC_AES_BLOCK_SIZE], const uint8_t *key, uint32_t keySize, uint8_t counterlast[LTC_AES_BLOCK_SIZE], uint32_t *szLeft)
| Encrypts or decrypts AES using CTR block mode. More...
status_t | LTC_AES_EncryptTagGcm (LTC_Type *base, const uint8_t *plaintext, uint8_t *ciphertext, uint32_t size, const uint8_t *iv, uint32_t ivSize, const uint8_t *aad, uint32_t aadSize, const uint8_t *key, uint32_t keySize, uint8_t *tag, uint32_t tagSize)
| Encrypts AES and tags using GCM block mode. More...
status_t | LTC_AES_DecryptTagGcm (LTC_Type *base, const uint8_t *ciphertext, uint8_t *plaintext, uint32_t size, const uint8_t *iv, uint32_t ivSize, const uint8_t *aad, uint32_t aadSize, const uint8_t *key, uint32_t keySize, const uint8_t *tag, uint32_t tagSize)
| Decrypts AES and authenticates using GCM block mode. More...
status_t | LTC_AES_EncryptTagCcm (LTC_Type *base, const uint8_t *plaintext, uint8_t *ciphertext, uint32_t size, const uint8_t *iv, uint32_t ivSize, const uint8_t *aad, uint32_t aadSize, const uint8_t *key, uint32_t keySize, uint8_t *tag, uint32_t tagSize)
| Encrypts AES and tags using CCM block mode. More...
status_t | LTC_AES_DecryptTagCcm (LTC_Type *base, const uint8_t *ciphertext, uint8_t *plaintext, uint32_t size, const uint8_t *iv, uint32_t ivSize, const uint8_t *aad, uint32_t aadSize, const uint8_t *key, uint32_t keySize, const uint8_t *tag, uint32_t tagSize)
| Decrypts AES and authenticates using CCM block mode. More...

## Enumeration Type Documentation

enum ltc_aes_key_t

Enumerator
kLTC_EncryptKey | Input key is an encrypt key.
kLTC_DecryptKey | Input key is a decrypt key.

## Function Documentation

status_t LTC_AES_GenerateDecryptKey | ( | LTC_Type * | base,
|  | const uint8_t * | encryptKey,
|  | uint8_t * | decryptKey,
|  | uint32_t | keySize
| ) |  |

Transforms the AES encrypt key (forward AES) into the decrypt key (inverse AES). The key derived by this function can be used as a direct load decrypt key for AES ECB and CBC decryption operations (keyType argument).

Parameters

  | base | LTC peripheral base address
  | encryptKey | Input key for decrypt key transformation
  [out] | decryptKey | Output key, the decrypt form of the AES key.
  | keySize | Size of the input key and output key in bytes. Must be 16, 24, or 32.

Returns
  Status from key generation operation

status_t LTC_AES_EncryptEcb | ( | LTC_Type * | base,
|  | const uint8_t * | plaintext,
|  | uint8_t * | ciphertext,
|  | uint32_t | size,
|  | const uint8_t * | key,
|  | uint32_t | keySize
| ) |  |

Encrypts AES using the ECB block mode.

Parameters

  | base | LTC peripheral base address
  | plaintext | Input plain text to encrypt
  [out] | ciphertext | Output cipher text
  | size | Size of input and output data in bytes. Must be multiple of 16 bytes.
  | key | Input key to use for encryption
  | keySize | Size of the input key, in bytes. Must be 16, 24, or 32.

Returns
  Status from encrypt operation

status_t LTC_AES_DecryptEcb | ( | LTC_Type * | base,
|  | const uint8_t * | ciphertext,
|  | uint8_t * | plaintext,
|  | uint32_t | size,
|  | const uint8_t * | key,
|  | uint32_t | keySize,
|  | ltc_aes_key_t | keyType
| ) |  |

Decrypts AES using ECB block mode.

Parameters

  | base | LTC peripheral base address
  | ciphertext | Input cipher text to decrypt
  [out] | plaintext | Output plain text
  | size | Size of input and output data in bytes. Must be multiple of 16 bytes.
  | key | Input key.
  | keySize | Size of the input key, in bytes. Must be 16, 24, or 32.
  | keyType | Input type of the key (allows to directly load decrypt key for AES ECB decrypt operation.)

Returns
  Status from decrypt operation

status_t LTC_AES_EncryptCbc | ( | LTC_Type * | base,
|  | const uint8_t * | plaintext,
|  | uint8_t * | ciphertext,
|  | uint32_t | size,
|  | const uint8_t | iv[LTC_AES_IV_SIZE],
|  | const uint8_t * | key,
|  | uint32_t | keySize
| ) |  |

Parameters

  | base | LTC peripheral base address
  | plaintext | Input plain text to encrypt
  [out] | ciphertext | Output cipher text
  | size | Size of input and output data in bytes. Must be multiple of 16 bytes.
  | iv | Input initial vector to combine with the first input block.
  | key | Input key to use for encryption
  | keySize | Size of the input key, in bytes. Must be 16, 24, or 32.

Returns
  Status from encrypt operation

status_t LTC_AES_DecryptCbc | ( | LTC_Type * | base,
|  | const uint8_t * | ciphertext,
|  | uint8_t * | plaintext,
|  | uint32_t | size,
|  | const uint8_t | iv[LTC_AES_IV_SIZE],
|  | const uint8_t * | key,
|  | uint32_t | keySize,
|  | ltc_aes_key_t | keyType
| ) |  |

Parameters

  | base | LTC peripheral base address
  | ciphertext | Input cipher text to decrypt
  [out] | plaintext | Output plain text
  | size | Size of input and output data in bytes. Must be multiple of 16 bytes.
  | iv | Input initial vector to combine with the first input block.
  | key | Input key to use for decryption
  | keySize | Size of the input key, in bytes. Must be 16, 24, or 32.
  | keyType | Input type of the key (allows to directly load decrypt key for AES CBC decrypt operation.)

Returns
  Status from decrypt operation

status_t LTC_AES_CryptCtr | ( | LTC_Type * | base,
|  | const uint8_t * | input,
|  | uint8_t * | output,
|  | uint32_t | size,
|  | uint8_t | counter[LTC_AES_BLOCK_SIZE],
|  | const uint8_t * | key,
|  | uint32_t | keySize,
|  | uint8_t | counterlast[LTC_AES_BLOCK_SIZE],
|  | uint32_t * | szLeft
| ) |  |

Encrypts or decrypts AES using CTR block mode. AES CTR mode uses only forward AES cipher and same algorithm for encryption and decryption. The only difference between encryption and decryption is that, for encryption, the input argument is plain text and the output argument is cipher text. For decryption, the input argument is cipher text and the output argument is plain text.

Parameters

  | base | LTC peripheral base address
  | input | Input data for CTR block mode
  [out] | output | Output data for CTR block mode
  | size | Size of input and output data in bytes
  [in,out] | counter | Input counter (updates on return)
  | key | Input key to use for forward AES cipher
  | keySize | Size of the input key, in bytes. Must be 16, 24, or 32.
  [out] | counterlast | Output cipher of last counter, for chained CTR calls. NULL can be passed if chained calls are not used.
  [out] | szLeft | Output number of bytes in left unused in counterlast block. NULL can be passed if chained calls are not used.

Returns
  Status from encrypt operation

status_t LTC_AES_EncryptTagGcm | ( | LTC_Type * | base,
|  | const uint8_t * | plaintext,
|  | uint8_t * | ciphertext,
|  | uint32_t | size,
|  | const uint8_t * | iv,
|  | uint32_t | ivSize,
|  | const uint8_t * | aad,
|  | uint32_t | aadSize,
|  | const uint8_t * | key,
|  | uint32_t | keySize,
|  | uint8_t * | tag,
|  | uint32_t | tagSize
| ) |  |

Encrypts AES and optionally tags using GCM block mode. If plaintext is NULL, only the GHASH is calculated and output in the 'tag' field.

Parameters

  | base | LTC peripheral base address
  | plaintext | Input plain text to encrypt
  [out] | ciphertext | Output cipher text.
  | size | Size of input and output data in bytes
  | iv | Input initial vector
  | ivSize | Size of the IV
  | aad | Input additional authentication data
  | aadSize | Input size in bytes of AAD
  | key | Input key to use for encryption
  | keySize | Size of the input key, in bytes. Must be 16, 24, or 32.
  [out] | tag | Output hash tag. Set to NULL to skip tag processing.
  | tagSize | Input size of the tag to generate, in bytes. Must be 4,8,12,13,14,15 or 16.

Returns
  Status from encrypt operation

status_t LTC_AES_DecryptTagGcm | ( | LTC_Type * | base,
|  | const uint8_t * | ciphertext,
|  | uint8_t * | plaintext,
|  | uint32_t | size,
|  | const uint8_t * | iv,
|  | uint32_t | ivSize,
|  | const uint8_t * | aad,
|  | uint32_t | aadSize,
|  | const uint8_t * | key,
|  | uint32_t | keySize,
|  | const uint8_t * | tag,
|  | uint32_t | tagSize
| ) |  |

Decrypts AES and optionally authenticates using GCM block mode. If ciphertext is NULL, only the GHASH is calculated and compared with the received GHASH in 'tag' field.

Parameters

  | base | LTC peripheral base address
  | ciphertext | Input cipher text to decrypt
  [out] | plaintext | Output plain text.
  | size | Size of input and output data in bytes
  | iv | Input initial vector
  | ivSize | Size of the IV
  | aad | Input additional authentication data
  | aadSize | Input size in bytes of AAD
  | key | Input key to use for encryption
  | keySize | Size of the input key, in bytes. Must be 16, 24, or 32.
  | tag | Input hash tag to compare. Set to NULL to skip tag processing.
  | tagSize | Input size of the tag, in bytes. Must be 4, 8, 12, 13, 14, 15, or 16.

Returns
  Status from decrypt operation

status_t LTC_AES_EncryptTagCcm | ( | LTC_Type * | base,
|  | const uint8_t * | plaintext,
|  | uint8_t * | ciphertext,
|  | uint32_t | size,
|  | const uint8_t * | iv,
|  | uint32_t | ivSize,
|  | const uint8_t * | aad,
|  | uint32_t | aadSize,
|  | const uint8_t * | key,
|  | uint32_t | keySize,
|  | uint8_t * | tag,
|  | uint32_t | tagSize
| ) |  |

Encrypts AES and optionally tags using CCM block mode.

Parameters

  | base | LTC peripheral base address
  | plaintext | Input plain text to encrypt
  [out] | ciphertext | Output cipher text.
  | size | Size of input and output data in bytes. Zero means authentication only.
  | iv | Nonce
  | ivSize | Length of the Nonce in bytes. Must be 7, 8, 9, 10, 11, 12, or 13.
  | aad | Input additional authentication data. Can be NULL if aadSize is zero.
  | aadSize | Input size in bytes of AAD. Zero means data mode only (authentication skipped).
  | key | Input key to use for encryption
  | keySize | Size of the input key, in bytes. Must be 16, 24, or 32.
  [out] | tag | Generated output tag. Set to NULL to skip tag processing.
  | tagSize | Input size of the tag to generate, in bytes. Must be 4, 6, 8, 10, 12, 14, or 16.

Returns
  Status from encrypt operation

status_t LTC_AES_DecryptTagCcm | ( | LTC_Type * | base,
|  | const uint8_t * | ciphertext,
|  | uint8_t * | plaintext,
|  | uint32_t | size,
|  | const uint8_t * | iv,
|  | uint32_t | ivSize,
|  | const uint8_t * | aad,
|  | uint32_t | aadSize,
|  | const uint8_t * | key,
|  | uint32_t | keySize,
|  | const uint8_t * | tag,
|  | uint32_t | tagSize
| ) |  |

Decrypts AES and optionally authenticates using CCM block mode.

Parameters

  | base | LTC peripheral base address
  | ciphertext | Input cipher text to decrypt
  [out] | plaintext | Output plain text.
  | size | Size of input and output data in bytes. Zero means authentication only.
  | iv | Nonce
  | ivSize | Length of the Nonce in bytes. Must be 7, 8, 9, 10, 11, 12, or 13.
  | aad | Input additional authentication data. Can be NULL if aadSize is zero.
  | aadSize | Input size in bytes of AAD. Zero means data mode only (authentication skipped).
  | key | Input key to use for decryption
  | keySize | Size of the input key, in bytes. Must be 16, 24, or 32.
  | tag | Received tag. Set to NULL to skip tag processing.
  | tagSize | Input size of the received tag to compare with the computed tag, in bytes. Must be 4, 6, 8, 10, 12, 14, or 16.

Returns
  Status from decrypt operation