Optimized RF24Network Layer v2.3.0
2024 - Optimized RF24 Network Layer for NRF24L01 & NRF52x radios
Loading...
Searching...
No Matches
RF24CCM.h File Reference
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <sys/random.h>
#include <RF24/RF24.h>

Go to the source code of this file.

Classes

class  RF24CCM

Namespaces

namespace  rf24ccm

Macros

#define RF24CCM_KEY_SIZE   16
#define RF24CCM_IV_SIZE   5
#define RF24CCM_COUNTER_SIZE   3
#define RF24CCM_MIC_SIZE   4
#define RF24CCM_NONCE_SIZE   13
#define RF24CCM_OVERHEAD   (RF24CCM_IV_SIZE + RF24CCM_COUNTER_SIZE + RF24CCM_MIC_SIZE)
#define RF24CCM_FRAME_SIZE   32

Functions

uint8_t rf24ccm::xtime (uint8_t x)
uint8_t rf24ccm::rotl8 (uint8_t x, uint8_t shift)
const uint8_t * rf24ccm::sbox ()
void rf24ccm::aesExpandKey (const uint8_t key[16], uint8_t roundKeys[176])
void rf24ccm::aesEncryptBlock (const uint8_t roundKeys[176], const uint8_t in[16], uint8_t out[16])
void rf24ccm::ccmMac (const uint8_t roundKeys[176], const uint8_t *nonce, uint8_t nonceLen, const uint8_t *aad, size_t aadLen, const uint8_t *msg, size_t msgLen, uint8_t micLen, uint8_t mac[16])
void rf24ccm::ccmCtr (const uint8_t roundKeys[176], const uint8_t *nonce, uint8_t nonceLen, const uint8_t *in, size_t len, uint8_t *out, uint8_t s0[16])
void rf24ccm::ccmEncrypt (const uint8_t roundKeys[176], const uint8_t *nonce, uint8_t nonceLen, const uint8_t *aad, size_t aadLen, const uint8_t *in, size_t len, uint8_t *out, uint8_t *mic, uint8_t micLen)
bool rf24ccm::ccmDecrypt (const uint8_t roundKeys[176], const uint8_t *nonce, uint8_t nonceLen, const uint8_t *aad, size_t aadLen, const uint8_t *in, size_t len, const uint8_t *mic, uint8_t micLen, uint8_t *out)

Detailed Description

An RF24 radio wrapper that encrypts and authenticates every radio frame with AES-128 CCM, using the same over-the-air format as the nrf_to_nrf library's CCM encryption. This lets Linux nodes (RF24Network, RF24Mesh and RF24Gateway) communicate with nRF52840 nodes that have radio.enableEncryption = true.

Frame format (the dynamic payload as seen by an nRF24L01):

| IV (5 bytes) | packet counter (3 bytes, little endian) | ciphertext | MIC (4 bytes) |

The nonce follows the Bluetooth LE CCM layout used by the nRF52 CCM peripheral: packet counter (5 bytes, little endian, direction bit 0) followed by the 8 byte IV (5 transmitted bytes, 3 zero bytes). The additional authenticated data is a single 0x00 byte.

Every frame carries 12 bytes of overhead, so an encrypted 32 byte frame holds 20 bytes of RF24Network data: an 8 byte header plus 12 bytes of payload.

Macro Definition Documentation

◆ RF24CCM_KEY_SIZE

#define RF24CCM_KEY_SIZE   16

◆ RF24CCM_IV_SIZE

#define RF24CCM_IV_SIZE   5

◆ RF24CCM_COUNTER_SIZE

#define RF24CCM_COUNTER_SIZE   3

◆ RF24CCM_MIC_SIZE

#define RF24CCM_MIC_SIZE   4

◆ RF24CCM_NONCE_SIZE

#define RF24CCM_NONCE_SIZE   13

◆ RF24CCM_OVERHEAD

#define RF24CCM_OVERHEAD   (RF24CCM_IV_SIZE + RF24CCM_COUNTER_SIZE + RF24CCM_MIC_SIZE)

◆ RF24CCM_FRAME_SIZE

#define RF24CCM_FRAME_SIZE   32