SPP packet AES-128-GCM cipher context. More...
Go to the source code of this file.
Macros | |
| #define | K_SPP_CIPHER_KEY_LEN (16U) |
| #define | K_SPP_CIPHER_NONCE_LEN (12U) |
| #define | K_SPP_CIPHER_TAG_LEN (16U) |
| #define | K_SPP_CIPHER_FRAME_LEN (K_SPP_CIPHER_NONCE_LEN + sizeof(SPP_Packet_t) + K_SPP_CIPHER_TAG_LEN) |
| Total output frame size after encryption. | |
| #define | K_SPP_CIPHER_KEY |
| AES-128 symmetric key shared between transmitter and receiver. | |
Functions | |
| SPP_RetVal_t | SPP_EXTERNAL_ENCRYPTION_CYPHER_encryptPacket (spp_uint8_t *p_buffer, spp_uint16_t *p_outSize) |
| Encrypt an SPP packet buffer in-place with AES-128-GCM. | |
SPP packet AES-128-GCM cipher context.
Provides a single function that encrypts a raw SPP packet buffer in-place, prepending the derived nonce and appending the GCM authentication tag. The output frame layout is:
[ nonce (12 B) | ciphertext (sizeof SPP_Packet_t) | tag (16 B) ]
The nonce is derived from the packet's timestamp and sequence counter to guarantee uniqueness per transmission. The symmetric key is stored in this header and must match on both ends of the link.
Naming conventions used in this file:
Definition in file cipher.h.
| #define K_SPP_CIPHER_KEY_LEN (16U) |
| #define K_SPP_CIPHER_NONCE_LEN (12U) |
GCM recommended nonce length in bytes.
Definition at line 33 of file cipher.h.
Referenced by s_buildNonce(), and SPP_EXTERNAL_ENCRYPTION_CYPHER_encryptPacket().
| #define K_SPP_CIPHER_TAG_LEN (16U) |
| #define K_SPP_CIPHER_FRAME_LEN (K_SPP_CIPHER_NONCE_LEN + sizeof(SPP_Packet_t) + K_SPP_CIPHER_TAG_LEN) |
Total output frame size after encryption.
Layout: nonce | ciphertext | tag. Declare the output buffer with this size:
Definition at line 45 of file cipher.h.
Referenced by SPP_EXTERNAL_ENCRYPTION_CYPHER_encryptPacket(), and SPP_HAL_UART_transmit().
| #define K_SPP_CIPHER_KEY |
AES-128 symmetric key shared between transmitter and receiver.
Replace the placeholder bytes with the actual pre-shared key before deployment. Both ends of the link must use the identical value.
| SPP_RetVal_t SPP_EXTERNAL_ENCRYPTION_CYPHER_encryptPacket | ( | spp_uint8_t * | p_buffer, |
| spp_uint16_t * | p_outSize ) |
Encrypt an SPP packet buffer in-place with AES-128-GCM.
Reads sizeof(SPP_Packet_t) bytes from p_buffer, encrypts them, and overwrites p_buffer with the output frame:
[ nonce (12 B) | ciphertext (sizeof SPP_Packet_t) | tag (16 B) ]
The nonce is derived from the packet header:
p_buffer must point to a buffer of at least K_SPP_CIPHER_FRAME_LEN bytes so the output frame fits.
| [in,out] | p_buffer | On entry: raw SPP packet bytes. On exit: encrypted frame (nonce | ciphertext | tag). |
| [out] | p_outSize | Set to K_SPP_CIPHER_FRAME_LEN on success. |
Definition at line 56 of file cipher.c.
References K_SPP_CIPHER_FRAME_LEN, K_SPP_CIPHER_NONCE_LEN, K_SPP_ERROR_NULL_POINTER, K_SPP_OK, s_buildNonce(), s_key, SPP_EXTERNAL_ENCRYPTION_CYPHER_encryptPacket(), SPP_EXTERNAL_ENCRYPTION_gcmEncrypt(), and SPP_Packet_t.
Referenced by SPP_EXTERNAL_ENCRYPTION_CYPHER_encryptPacket(), and SPP_HAL_UART_transmit().