RadioLib
Universal wireless communication library for Arduino
RadioLibAES128 Class Reference

Class to perform AES encryption, decryption and CMAC. More...

#include <Cryptography.h>

Public Member Functions

 RadioLibAES128 ()
 Default constructor.
 
void init (uint8_t *key)
 Initialize the AES. More...
 
size_t encryptECB (uint8_t *in, size_t len, uint8_t *out)
 Perform ECB-type AES encryption. More...
 
size_t decryptECB (uint8_t *in, size_t len, uint8_t *out)
 Perform ECB-type AES decryption. More...
 
void generateCMAC (uint8_t *in, size_t len, uint8_t *cmac)
 Calculate message authentication code according to RFC4493. More...
 
bool verifyCMAC (uint8_t *in, size_t len, const uint8_t *cmac)
 Verify the received CMAC. This just calculates the CMAC again and compares the results. More...
 

Detailed Description

Class to perform AES encryption, decryption and CMAC.

Most of the implementation here is adapted from https://github.com/kokke/tiny-AES-c Additional code and CMAC calculation is from https://github.com/megrxu/AES-CMAC

Member Function Documentation

◆ decryptECB()

size_t RadioLibAES128::decryptECB ( uint8_t *  in,
size_t  len,
uint8_t *  out 
)

Perform ECB-type AES decryption.

Parameters
inInput ciphertext data.
lenLength of the input data.
outBuffer to save the output plaintext into. It is up to the caller to ensure the buffer is sufficiently large to save the data!
Returns
The number of bytes saved into the output buffer.

◆ encryptECB()

size_t RadioLibAES128::encryptECB ( uint8_t *  in,
size_t  len,
uint8_t *  out 
)

Perform ECB-type AES encryption.

Parameters
inInput plaintext data (unpadded).
lenLength of the input data.
outBuffer to save the output ciphertext into. It is up to the caller to ensure the buffer is sufficiently large to save the data!
Returns
The number of bytes saved into the output buffer.

◆ generateCMAC()

void RadioLibAES128::generateCMAC ( uint8_t *  in,
size_t  len,
uint8_t *  cmac 
)

Calculate message authentication code according to RFC4493.

Parameters
inInput data (unpadded).
lenLength of the input data.
cmacBuffer to save the output MAC into. The buffer must be at least 16 bytes long!

◆ init()

void RadioLibAES128::init ( uint8_t *  key)

Initialize the AES.

Parameters
keyAES key to use.

◆ verifyCMAC()

bool RadioLibAES128::verifyCMAC ( uint8_t *  in,
size_t  len,
const uint8_t *  cmac 
)

Verify the received CMAC. This just calculates the CMAC again and compares the results.

Parameters
inInput data (unpadded).
lenLength of the input data.
cmacCMAC to verify.
Returns
True if valid, false otherwise.

The documentation for this class was generated from the following files: