Module nrf52833_hal::ccm

source ·
Expand description

HAL blocking interface to the AES CCM mode encryption.

Counter with CBC-MAC (CCM) mode is an authenticated encryption algorithm designed to provide both authentication and confidentiality during data transfer.

§Packet Format

The packets, required by the methods in this module, need to be in a specific format, displayed below:

Cleartext packet:

+----------+---------------+----------+------------------+
| S0       | Packet length | S1       | Payload          |
| (1 byte) | (1 byte)      | (1 byte) | (0 - 251* bytes) |
+----------+---------------+----------+------------------+

The contents of S0 and S1 are not relevant, but the fields must be present in the slice. The encryption operation will append a four-byte MIC after the payload field and add four to the Payload length field. Because of that, this module can only encrypt packets with payloads lengths up to 251 bytes. The cipher packet slice passed to the encryption method must have enough space for the clear packet plus MIC.

Ciphertext packet:

+----------+---------------+----------+-----------------+-------------+
| S0       | Packet length | S1       | Payload          | MIC        |
| (1 byte) | (1 byte)      | (1 byte) | (0 - 251* bytes) | (4 bytes)  |
+----------+---------------+----------+-----------------+-------------+

The contents of S0 and S1 are not relevant, but the fields must be present in the slice. The Packet length is the sum of the lengths of the Payload and MIC. The decryption operation will also check the MIC field and return an error when it is invalid and it will decrement the Length field by four. During decryption, the clear text slice does not need to have space for the MIC field.

  • nRF51 devices only support payloads of up to 27 bytes.

§Scratch Area

The peripheral also needs an area in RAM to store temporary values used during encryption/decryption. The scratch slice must have a minimum length of 43 bytes, or (16 + Packet Length) bytes, whatever is largest.

Structs§

  • A safe, blocking wrapper around the AES-CCM peripheral.
  • Data used for encryption/decryption.

Enums§