MCUXpresso SDK API Reference Manual
Rev. 1
NXP Semiconductors
|
The mmCAU software library uses the mmCAU co-processor that is connected to the ARM Cortex-M4/M0+ Private Peripheral Bus (PPB). In this chapter, CAU refers to both CAU and mmCAU unless explicitly noted.
The following chapter describes how to use the mmCAU software library in any application to integrate a cryptographic algorithm or hashing function supported by the software library. NXP products supported by the software library are MCU/MPUs. Check the specific Freescale product for CAU availability.
The library is as compact and generic as possible to simplify the integration with existing cryptographic software. The library has a standard header file with ANSI C prototypes for all functions: "cau_api.h". This software library is thread safe only if CAU registers are saved on a context switch. The mmCAU software library is also compatible to ARM C compiler conventions (EABI). All pointers passed to mmCAU API functions (input and output data blocks, keys, key schedules, and so on) are aligned to 0-modulo-4 addresses.
For applications that don't need to deal with the aligned addresses, a simple wrapper layer is provided. The wrapper layer consists of the "fsl_mmcau.h" header file and "fsl_mmcau.c" source code file. The only function of the wrapper layer is that it supports unaligned addresses
. The CAU library supports the following encryption/decryption algorithms and hashing functions:
Note: 3DES crypto algorithms are supported by calling the corresponding DES crypto function three times. Hardware support for SHA256 is only present in the CAU version 2. See the appropriate MCU/MPU reference manual for details about availability. Additionally, the cau_sha256_initialize_output() function checks the hardware revision and returns a (-1) value if the CAU lacks SHA256 support.
Table 1 shows the crypto algorithms and hashing functions included in the software library:
Crypto Algorithms | AES128 AES192 AES256 | cau_aes_set_key |
cau_aes_encrypt | ||
cau_aes_decrypt | ||
DES/3DES | cau_des_chk_parity | |
cau_des_encrypt | ||
cau_des_decrypt | ||
Hashing Functions | MD5 | cau_md5_initialize_output |
cau_md5_hash_n | ||
cau_md5_update | ||
cau_md5_hash | ||
SHA1 | cau_sha1_initialize_output | |
cau_sha1_hash_n | ||
cau_sha1_update | ||
cau_sha1_hash | ||
SHA256 | cau_sha256_initialize_output | |
cau_sha256_hash_n | ||
cau_sha256_update | ||
cau_sha256_hash |
Table 1: Library Overview
The software library contains the following files:
File | Description |
cau_api.h | CAU and mmCAU header file |
lib_mmcau.a | mmCAU library |
Table 2: File Description
The header file and lib_mmcau.a must always be included in the project.
Functions | |
void | cau_aes_set_key (const unsigned char *key, const int key_size, unsigned char *key_sch) |
AES: Performs an AES key expansion. More... | |
void | cau_aes_encrypt (const unsigned char *in, const unsigned char *key_sch, const int nr, unsigned char *out) |
AES: Encrypts a single 16 byte block. More... | |
void | cau_aes_decrypt (const unsigned char *in, const unsigned char *key_sch, const int nr, unsigned char *out) |
AES: Decrypts a single 16-byte block. More... | |
int | cau_des_chk_parity (const unsigned char *key) |
DES: Checks key parity. More... | |
void | cau_des_encrypt (const unsigned char *in, const unsigned char *key, unsigned char *out) |
DES: Encrypts a single 8-byte block. More... | |
void | cau_des_decrypt (const unsigned char *in, const unsigned char *key, unsigned char *out) |
DES: Decrypts a single 8-byte block. More... | |
void | cau_md5_initialize_output (const unsigned char *md5_state) |
MD5: Initializes the MD5 state variables. More... | |
void | cau_md5_hash_n (const unsigned char *msg_data, const int num_blks, unsigned char *md5_state) |
MD5: Updates MD5 state variables with n message blocks. More... | |
void | cau_md5_update (const unsigned char *msg_data, const int num_blks, unsigned char *md5_state) |
MD5: Updates MD5 state variables. More... | |
void | cau_md5_hash (const unsigned char *msg_data, unsigned char *md5_state) |
MD5: Updates MD5 state variables with one message block. More... | |
void | cau_sha1_initialize_output (const unsigned int *sha1_state) |
SHA1: Initializes the SHA1 state variables. More... | |
void | cau_sha1_hash_n (const unsigned char *msg_data, const int num_blks, unsigned int *sha1_state) |
SHA1: Updates SHA1 state variables with n message blocks. More... | |
void | cau_sha1_update (const unsigned char *msg_data, const int num_blks, unsigned int *sha1_state) |
SHA1: Updates SHA1 state variables. More... | |
void | cau_sha1_hash (const unsigned char *msg_data, unsigned int *sha1_state) |
SHA1: Updates SHA1 state variables with one message block. More... | |
int | cau_sha256_initialize_output (const unsigned int *output) |
SHA256: Initializes the SHA256 state variables. More... | |
void | cau_sha256_hash_n (const unsigned char *input, const int num_blks, unsigned int *output) |
SHA256: Updates SHA256 state variables with n message blocks. More... | |
void | cau_sha256_update (const unsigned char *input, const int num_blks, unsigned int *output) |
SHA256: Updates SHA256 state variables. More... | |
void | cau_sha256_hash (const unsigned char *input, unsigned int *output) |
SHA256: Updates SHA256 state variables with one message block. More... | |
status_t | MMCAU_AES_SetKey (const uint8_t *key, const size_t keySize, uint8_t *keySch) |
AES: Performs an AES key expansion. More... | |
status_t | MMCAU_AES_EncryptEcb (const uint8_t *in, const uint8_t *keySch, uint32_t aesRounds, uint8_t *out) |
AES: Encrypts a single 16 byte block. More... | |
status_t | MMCAU_AES_DecryptEcb (const uint8_t *in, const uint8_t *keySch, uint32_t aesRounds, uint8_t *out) |
AES: Decrypts a single 16-byte block. More... | |
status_t | MMCAU_DES_ChkParity (const uint8_t *key) |
DES: Checks the key parity. More... | |
status_t | MMCAU_DES_EncryptEcb (const uint8_t *in, const uint8_t *key, uint8_t *out) |
DES: Encrypts a single 8-byte block. More... | |
status_t | MMCAU_DES_DecryptEcb (const uint8_t *in, const uint8_t *key, uint8_t *out) |
DES: Decrypts a single 8-byte block. More... | |
status_t | MMCAU_MD5_InitializeOutput (uint32_t *md5State) |
MD5: Initializes the MD5 state variables. More... | |
status_t | MMCAU_MD5_HashN (const uint8_t *msgData, uint32_t numBlocks, uint32_t *md5State) |
MD5: Updates the MD5 state variables with n message blocks. More... | |
status_t | MMCAU_MD5_Update (const uint8_t *msgData, uint32_t numBlocks, uint32_t *md5State) |
MD5: Updates the MD5 state variables. More... | |
status_t | MMCAU_SHA1_InitializeOutput (uint32_t *sha1State) |
SHA1: Initializes the SHA1 state variables. More... | |
status_t | MMCAU_SHA1_HashN (const uint8_t *msgData, uint32_t numBlocks, uint32_t *sha1State) |
SHA1: Updates the SHA1 state variables with n message blocks. More... | |
status_t | MMCAU_SHA1_Update (const uint8_t *msgData, uint32_t numBlocks, uint32_t *sha1State) |
SHA1: Updates the SHA1 state variables. More... | |
status_t | MMCAU_SHA256_InitializeOutput (uint32_t *sha256State) |
SHA256: Initializes the SHA256 state variables. More... | |
status_t | MMCAU_SHA256_HashN (const uint8_t *input, uint32_t numBlocks, uint32_t *sha256State) |
SHA256: Updates the SHA256 state variables with n message blocks. More... | |
status_t | MMCAU_SHA256_Update (const uint8_t *input, uint32_t numBlocks, uint32_t *sha256State) |
SHA256: Updates SHA256 state variables. More... | |
void cau_aes_set_key | ( | const unsigned char * | key, |
const int | key_size, | ||
unsigned char * | key_sch | ||
) |
This function performs an AES key expansion
key | Pointer to input key (128, 192, 256 bits in length). | |
key_size | Key size in bits (128, 192, 256) | |
[out] | key_sch | Pointer to key schedule output (44, 52, 60 longwords) |
[in] Key Size (bits) | [out] Key Schedule Size (32 bit data values) |
---|---|
128 | 44 |
192 | 52 |
256 | 60 |
void cau_aes_encrypt | ( | const unsigned char * | in, |
const unsigned char * | key_sch, | ||
const int | nr, | ||
unsigned char * | out | ||
) |
This function encrypts a single 16-byte block for AES128, AES192 and AES256
in | Pointer to 16-byte block of input plaintext | |
key_sch | Pointer to key schedule (44, 52, 60 longwords) | |
nr | Number of AES rounds (10, 12, 14 = f(key_schedule)) | |
[out] | out | Pointer to 16-byte block of output ciphertext |
Block Cipher | [in] Key Schedule Size (longwords) | [in] Number of AES rounds |
---|---|---|
AES128 | 44 | 10 |
AES192 | 52 | 12 |
AES256 | 60 | 14 |
void cau_aes_decrypt | ( | const unsigned char * | in, |
const unsigned char * | key_sch, | ||
const int | nr, | ||
unsigned char * | out | ||
) |
This function decrypts a single 16-byte block for AES128, AES192 and AES256
in | Pointer to 16-byte block of input ciphertext | |
key_sch | Pointer to key schedule (44, 52, 60 longwords) | |
nr | Number of AES rounds (10, 12, 14 = f(key_schedule)) | |
[out] | out | Pointer to 16-byte block of output plaintext |
Block Cipher | [in] Key Schedule Size (longwords) | [in] Number of AES rounds |
---|---|---|
AES128 | 44 | 10 |
AES192 | 52 | 12 |
AES256 | 60 | 14 |
int cau_des_chk_parity | ( | const unsigned char * | key | ) |
This function checks the parity of a DES key
key | 64-bit DES key with parity bits. Must have word (4 bytes) alignment. |
void cau_des_encrypt | ( | const unsigned char * | in, |
const unsigned char * | key, | ||
unsigned char * | out | ||
) |
This function encrypts a single 8-byte block with DES algorithm.
in | Pointer to 8-byte block of input plaintext | |
key | Pointer to 64-bit DES key with parity bits | |
[out] | out | Pointer to 8-byte block of output ciphertext |
void cau_des_decrypt | ( | const unsigned char * | in, |
const unsigned char * | key, | ||
unsigned char * | out | ||
) |
This function decrypts a single 8-byte block with DES algorithm.
in | Pointer to 8-byte block of input ciphertext | |
key | Pointer to 64-bit DES key with parity bits | |
[out] | out | Pointer to 8-byte block of output plaintext |
void cau_md5_initialize_output | ( | const unsigned char * | md5_state | ) |
This function initializes the MD5 state variables. The output can be used as input to cau_md5_hash() and cau_md5_hash_n().
[out] | md5_state | Pointer to 128-bit block of md5 state variables: a,b,c,d |
void cau_md5_hash_n | ( | const unsigned char * | msg_data, |
const int | num_blks, | ||
unsigned char * | md5_state | ||
) |
This function updates MD5 state variables for one or more input message blocks
msg_data | Pointer to start of input message data | |
num_blks | Number of 512-bit blocks to process | |
[in,out] | md5_state | Pointer to 128-bit block of MD5 state variables: a,b,c,d |
void cau_md5_update | ( | const unsigned char * | msg_data, |
const int | num_blks, | ||
unsigned char * | md5_state | ||
) |
This function updates MD5 state variables for one or more input message blocks. It starts a new hash as it internally calls cau_md5_initialize_output() first.
msg_data | Pointer to start of input message data | |
num_blks | Number of 512-bit blocks to process | |
[out] | md5_state | Pointer to 128-bit block of MD5 state variables: a,b,c,d |
void cau_md5_hash | ( | const unsigned char * | msg_data, |
unsigned char * | md5_state | ||
) |
This function updates MD5 state variables for one input message block
msg_data | Pointer to start of 512-bits of input message data | |
[in,out] | md5_state | Pointer to 128-bit block of MD5 state variables: a,b,c,d |
void cau_sha1_initialize_output | ( | const unsigned int * | sha1_state | ) |
This function initializes the SHA1 state variables. The output can be used as input to cau_sha1_hash() and cau_sha1_hash_n().
[out] | sha1_state | Pointer to 160-bit block of SHA1 state variables: a,b,c,d,e |
void cau_sha1_hash_n | ( | const unsigned char * | msg_data, |
const int | num_blks, | ||
unsigned int * | sha1_state | ||
) |
This function updates SHA1 state variables for one or more input message blocks
msg_data | Pointer to start of input message data | |
num_blks | Number of 512-bit blocks to process | |
[in,out] | sha1_state | Pointer to 160-bit block of SHA1 state variables: a,b,c,d,e |
void cau_sha1_update | ( | const unsigned char * | msg_data, |
const int | num_blks, | ||
unsigned int * | sha1_state | ||
) |
This function updates SHA1 state variables for one or more input message blocks. It starts a new hash as it internally calls cau_sha1_initialize_output() first.
msg_data | Pointer to start of input message data | |
num_blks | Number of 512-bit blocks to process | |
[out] | sha1_state | Pointer to 160-bit block of SHA1 state variables: a,b,c,d,e |
void cau_sha1_hash | ( | const unsigned char * | msg_data, |
unsigned int * | sha1_state | ||
) |
This function updates SHA1 state variables for one input message block
msg_data | Pointer to start of 512-bits of input message data | |
[in,out] | sha1_state | Pointer to 160-bit block of SHA1 state variables: a,b,c,d,e |
int cau_sha256_initialize_output | ( | const unsigned int * | output | ) |
This function initializes the SHA256 state variables. The output can be used as input to cau_sha256_hash() and cau_sha256_hash_n().
[out] | output | Pointer to 256-bit block of SHA2 state variables a,b,c,d,e,f,g,h |
void cau_sha256_hash_n | ( | const unsigned char * | input, |
const int | num_blks, | ||
unsigned int * | output | ||
) |
This function updates SHA256 state variables for one or more input message blocks
input | Pointer to start of input message data | |
num_blks | Number of 512-bit blocks to process | |
[in,out] | output | Pointer to 256-bit block of SHA2 state variables: a,b,c,d,e,f,g,h |
void cau_sha256_update | ( | const unsigned char * | input, |
const int | num_blks, | ||
unsigned int * | output | ||
) |
This function updates SHA256 state variables for one or more input message blocks. It starts a new hash as it internally calls cau_sha256_initialize_output() first.
input | Pointer to start of input message data | |
num_blks | Number of 512-bit blocks to process | |
[out] | output | Pointer to 256-bit block of SHA2 state variables: a,b,c,d,e,f,g,h |
void cau_sha256_hash | ( | const unsigned char * | input, |
unsigned int * | output | ||
) |
This function updates SHA256 state variables for one input message block
input | Pointer to start of 512-bits of input message data | |
[in,out] | output | Pointer to 256-bit block of SHA2 state variables: a,b,c,d,e,f,g,h |
status_t MMCAU_AES_SetKey | ( | const uint8_t * | key, |
const size_t | keySize, | ||
uint8_t * | keySch | ||
) |
This function performs an AES key expansion.
key | Pointer to input key (128, 192, 256 bits in length). | |
keySize | Key size in bytes (16, 24, 32) | |
[out] | keySch | Pointer to key schedule output (44, 52, 60 longwords) |
[in] Key Size (bits) | [out] Key Schedule Size (32 bit data values) |
---|---|
128 | 44 |
192 | 52 |
256 | 60 |
status_t MMCAU_AES_EncryptEcb | ( | const uint8_t * | in, |
const uint8_t * | keySch, | ||
uint32_t | aesRounds, | ||
uint8_t * | out | ||
) |
This function encrypts a single 16-byte block for AES128, AES192, and AES256.
in | Pointer to 16-byte block of input plaintext. | |
keySch | Pointer to key schedule (44, 52, 60 longwords). | |
aesRounds | Number of AES rounds (10, 12, 14 = f(key_schedule)). | |
[out] | out | Pointer to 16-byte block of output ciphertext. |
Block Cipher | [in] Key Schedule Size (longwords) | [in] Number of AES rounds |
---|---|---|
AES128 | 44 | 10 |
AES192 | 52 | 12 |
AES256 | 60 | 14 |
status_t MMCAU_AES_DecryptEcb | ( | const uint8_t * | in, |
const uint8_t * | keySch, | ||
uint32_t | aesRounds, | ||
uint8_t * | out | ||
) |
This function decrypts a single 16-byte block for AES128, AES192, and AES256.
in | Pointer to 16-byte block of input ciphertext. | |
keySch | Pointer to key schedule (44, 52, 60 longwords). | |
aesRounds | Number of AES rounds (10, 12, 14 = f(key_schedule)). | |
[out] | out | Pointer to 16-byte block of output plaintext. |
Block Cipher | [in] Key Schedule Size (longwords) | [in] Number of AES rounds |
---|---|---|
AES128 | 44 | 10 |
AES192 | 52 | 12 |
AES256 | 60 | 14 |
status_t MMCAU_DES_ChkParity | ( | const uint8_t * | key | ) |
This function checks the parity of a DES key.
key | 64-bit DES key with parity bits. |
status_t MMCAU_DES_EncryptEcb | ( | const uint8_t * | in, |
const uint8_t * | key, | ||
uint8_t * | out | ||
) |
This function encrypts a single 8-byte block with the DES algorithm.
in | Pointer to 8-byte block of input plaintext. | |
key | Pointer to 64-bit DES key with parity bits. | |
[out] | out | Pointer to 8-byte block of output ciphertext. |
status_t MMCAU_DES_DecryptEcb | ( | const uint8_t * | in, |
const uint8_t * | key, | ||
uint8_t * | out | ||
) |
This function decrypts a single 8-byte block with the DES algorithm.
in | Pointer to 8-byte block of input ciphertext. | |
key | Pointer to 64-bit DES key with parity bits. | |
[out] | out | Pointer to 8-byte block of output plaintext. |
status_t MMCAU_MD5_InitializeOutput | ( | uint32_t * | md5State | ) |
This function initializes the MD5 state variables. The output can be used as input to MMCAU_MD5_HashN().
[out] | md5State | Pointer to 128-bit block of md5 state variables: a,b,c,d |
status_t MMCAU_MD5_HashN | ( | const uint8_t * | msgData, |
uint32_t | numBlocks, | ||
uint32_t * | md5State | ||
) |
This function updates the MD5 state variables for one or more input message blocks.
msgData | Pointer to start of input message data. | |
numBlocks | Number of 512-bit blocks to process. | |
[in,out] | md5State | Pointer to 128-bit block of MD5 state variables: a, b, c, d. |
status_t MMCAU_MD5_Update | ( | const uint8_t * | msgData, |
uint32_t | numBlocks, | ||
uint32_t * | md5State | ||
) |
This function updates the MD5 state variables for one or more input message blocks. It starts a new hash as it internally calls MMCAU_MD5_InitializeOutput() first.
msgData | Pointer to start of input message data. | |
numBlocks | Number of 512-bit blocks to process. | |
[out] | md5State | Pointer to 128-bit block of MD5 state variables: a, b, c, d. |
status_t MMCAU_SHA1_InitializeOutput | ( | uint32_t * | sha1State | ) |
This function initializes the SHA1 state variables. The output can be used as input to MMCAU_SHA1_HashN().
[out] | sha1State | Pointer to 160-bit block of SHA1 state variables: a, b, c, d, e. |
status_t MMCAU_SHA1_HashN | ( | const uint8_t * | msgData, |
uint32_t | numBlocks, | ||
uint32_t * | sha1State | ||
) |
This function updates the SHA1 state variables for one or more input message blocks.
msgData | Pointer to start of input message data. | |
numBlocks | Number of 512-bit blocks to process. | |
[in,out] | sha1State | Pointer to 160-bit block of SHA1 state variables: a, b, c, d, e. |
status_t MMCAU_SHA1_Update | ( | const uint8_t * | msgData, |
uint32_t | numBlocks, | ||
uint32_t * | sha1State | ||
) |
This function updates the SHA1 state variables for one or more input message blocks. It starts a new hash as it internally calls MMCAU_SHA1_InitializeOutput() first.
msgData | Pointer to start of input message data. | |
numBlocks | Number of 512-bit blocks to process. | |
[out] | sha1State | Pointer to 160-bit block of SHA1 state variables: a, b, c, d, e. |
status_t MMCAU_SHA256_InitializeOutput | ( | uint32_t * | sha256State | ) |
This function initializes the SHA256 state variables. The output can be used as input to MMCAU_SHA256_HashN().
[out] | sha256State | Pointer to 256-bit block of SHA2 state variables a, b, c, d, e, f, g, h. |
status_t MMCAU_SHA256_HashN | ( | const uint8_t * | input, |
uint32_t | numBlocks, | ||
uint32_t * | sha256State | ||
) |
This function updates SHA256 state variables for one or more input message blocks.
input | Pointer to start of input message data. | |
numBlocks | Number of 512-bit blocks to process. | |
[in,out] | sha256State | Pointer to 256-bit block of SHA2 state variables: a, b, c, d, e, f, g, h. |
status_t MMCAU_SHA256_Update | ( | const uint8_t * | input, |
uint32_t | numBlocks, | ||
uint32_t * | sha256State | ||
) |
This function updates the SHA256 state variables for one or more input message blocks. It starts a new hash as it internally calls cau_sha256_initialize_output() first.
input | Pointer to start of input message data. | |
numBlocks | Number of 512-bit blocks to process. | |
[out] | sha256State | Pointer to 256-bit block of SHA2 state variables: a, b, c, d, e, f, g, h. |