RadioLib Universal wireless communication library for Arduino

Public Member Functions | List of all members
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, 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

  in | Input ciphertext data.
  len | Length of the input data.
  out | Buffer 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

  in | Input plaintext data (unpadded).
  len | Length of the input data.
  out | Buffer 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

  in | Input data (unpadded).
  len | Length of the input data.
  cmac | Buffer 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

  key | AES key to use.

## ◆ verifyCMAC()

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

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

Parameters

  in | Input data (unpadded).
  len | Length of the input data.
  cmac | CMAC to verify.

Returns
  True if valid, false otherwise.

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

- src/utils/Cryptography.h
- src/utils/Cryptography.cpp