RadioLib
Universal wireless communication library for Arduino
Loading...
Searching...
No Matches
RadioLibAES128 Class Referenceabstract

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

#include <Cryptography.h>

Inheritance diagram for RadioLibAES128:
RadioLibSoftwareAES128

Public Member Functions

 RadioLibAES128 ()
 Default constructor.
 
virtual void init (uint8_t *key)=0
 Initialize the AES. If the user has a hardware with AES acceleration, this method is the interface to implement. By default a software-only implementation is provided in RadioLibSoftwareAES128.
 
virtual size_t encryptECB (const uint8_t *in, size_t len, uint8_t *out)=0
 Perform ECB-type AES encryption. If the user has a hardware with AES acceleration, this method is the interface to implement. By default a software-only implementation is provided in RadioLibSoftwareAES128.
 
virtual size_t decryptECB (const uint8_t *in, size_t len, uint8_t *out)=0
 Perform ECB-type AES decryption. If the user has a hardware with AES acceleration, this method is the interface to implement. By default a software-only implementation is provided in RadioLibSoftwareAES128.
 
void generateCMAC (const uint8_t *in, size_t len, uint8_t *cmac)
 Calculate message authentication code according to RFC4493.
 
void initCMAC (RadioLibCmacState *st)
 Initialize the CMAC state. This must be called before any updateCMAC calls.
 
void updateCMAC (RadioLibCmacState *st, const uint8_t *data, size_t len)
 Update the CMAC state with a chunk of data. This can be called multiple times to process the data in chunks.
 
void finishCMAC (RadioLibCmacState *st, uint8_t *out)
 Finalize the CMAC calculation and save the result. This must be called after all updateCMAC calls are done.
 
bool verifyCMAC (const uint8_t *in, size_t len, const uint8_t *cmac)
 Verify the received CMAC. This just calculates the CMAC again and compares the results.
 

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()

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

Perform ECB-type AES decryption. If the user has a hardware with AES acceleration, this method is the interface to implement. By default a software-only implementation is provided in RadioLibSoftwareAES128.

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.

Implemented in RadioLibSoftwareAES128.

◆ encryptECB()

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

Perform ECB-type AES encryption. If the user has a hardware with AES acceleration, this method is the interface to implement. By default a software-only implementation is provided in RadioLibSoftwareAES128.

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.

Implemented in RadioLibSoftwareAES128.

◆ finishCMAC()

void RadioLibAES128::finishCMAC ( RadioLibCmacState st,
uint8_t *  out 
)

Finalize the CMAC calculation and save the result. This must be called after all updateCMAC calls are done.

Parameters
stState to finalize.
outBuffer to save the output MAC into. The buffer must be at least 16 bytes long!

◆ generateCMAC()

void RadioLibAES128::generateCMAC ( const 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()

virtual void RadioLibAES128::init ( uint8_t *  key)
pure virtual

Initialize the AES. If the user has a hardware with AES acceleration, this method is the interface to implement. By default a software-only implementation is provided in RadioLibSoftwareAES128.

Parameters
keyAES key to use.

Implemented in RadioLibSoftwareAES128.

◆ initCMAC()

void RadioLibAES128::initCMAC ( RadioLibCmacState st)

Initialize the CMAC state. This must be called before any updateCMAC calls.

Parameters
stState to initialize.

◆ updateCMAC()

void RadioLibAES128::updateCMAC ( RadioLibCmacState st,
const uint8_t *  data,
size_t  len 
)

Update the CMAC state with a chunk of data. This can be called multiple times to process the data in chunks.

Parameters
stState to update.
dataInput data (unpadded).
lenLength of the input data.

◆ verifyCMAC()

bool RadioLibAES128::verifyCMAC ( const 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: