Microchip® Advanced Software Framework

stb_help.c File Reference
#include <string.h>
#include "pal.h"
#include "tal.h"
#include "ieee_const.h"
#include "stb.h"

Macros

#define MIN(a, b)   ((a) < (b)) ? (a) : (b)
 

Functions

void compute_mic (uint8_t *buffer, uint8_t *mic, uint8_t *nonce, uint8_t hdr_len, uint8_t pld_len)
 Computes MIC. More...
 
void encrypt_pldmic (uint8_t *buffer, uint8_t *nonce, uint8_t mic_len, uint8_t pld_len)
 Encrypts and decrypts payload and MIC. More...
 
void encrypt_with_padding (uint8_t *start, uint8_t buflen)
 CBC Encrypt data stream with null padding at the end. More...
 

#define MIN (   a,
 
)    ((a) < (b)) ? (a) : (b)

Referenced by compute_mic(), and encrypt_pldmic().

void compute_mic ( uint8_t *  buffer,
uint8_t *  mic,
uint8_t *  nonce,
uint8_t  hdr_len,
uint8_t  pld_len 
)

Computes MIC.

This function computes the MIC according to CCM.

The key was initialized in other functions before.

Parameters
[in]bufferInput data (frame, not padded yet)
[out]micComputed MIC of size AES_BLOCKSIZE
[in]nonceThe nonce: Initialization Vector (IV) as used in cryptography; the ZigBee nonce are the bytes 2...14 of this nonce
[in]hdr_lenSize of plain text header in bytes (may be 0)
[in]pld_lenLength of payload in bytes (may be 0)

References AES_BLOCKSIZE, AES_DIR_ENCRYPT, AES_MODE_CBC, AES_MODE_ECB, encrypt_with_padding(), MIN, NULL, sal_aes_exec(), sal_aes_read(), sal_aes_setup(), and sal_aes_wrrd().

Referenced by stb_ccm_secure().

void encrypt_pldmic ( uint8_t *  buffer,
uint8_t *  nonce,
uint8_t  mic_len,
uint8_t  pld_len 
)

Encrypts and decrypts payload and MIC.

This function perform encryption and decryption of the payload and the MIC.

Parameters
[in]bufferInput data (frame, not padded yet)
[in]nonceThe nonce
[in]mic_lenSize of MIC in bytes (may be 0)
[in]pld_lenLength of payload in bytes (may be 0)

References AES_BLOCKSIZE, AES_DIR_ENCRYPT, AES_MODE_ECB, i, MIN, NULL, sal_aes_read(), sal_aes_setup(), and sal_aes_wrrd().

Referenced by stb_ccm_secure().

void encrypt_with_padding ( uint8_t *  start,
uint8_t  buflen 
)

CBC Encrypt data stream with null padding at the end.

This function preforms CBC Encryption in the actual mode with actual key and portions of AES_BLOCKSIZE length. If the last block has less than AES_BLOCKSIZE bytes, it is padded with null bytes to this length and then encrypted.

No result is return; the CBC-MAC must be read separately.

Parameters
startPointer to start address
buflenNumber of bytes to be encrypted; if 0, nothing happens

References AES_BLOCKSIZE, NULL, sal_aes_exec(), and sal_aes_wrrd().

Referenced by compute_mic().