Solaris Software
Loading...
Searching...
No Matches
cipher.h File Reference

SPP packet AES-128-GCM cipher context. More...

Include dependency graph for cipher.h:
This graph shows which files directly or indirectly include this file:

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.

Detailed Description

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:

  • Constants/macros: K_SPP_CIPHER_*
  • Public functions: SPP_CIPHER_*
  • Pointer params: p_*

Definition in file cipher.h.

Macro Definition Documentation

◆ K_SPP_CIPHER_KEY_LEN

#define K_SPP_CIPHER_KEY_LEN   (16U)

AES-128 key length in bytes.

Definition at line 32 of file cipher.h.

◆ K_SPP_CIPHER_NONCE_LEN

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

◆ K_SPP_CIPHER_TAG_LEN

#define K_SPP_CIPHER_TAG_LEN   (16U)

GCM authentication tag length in bytes.

Definition at line 34 of file cipher.h.

◆ K_SPP_CIPHER_FRAME_LEN

#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:

#define K_SPP_CIPHER_FRAME_LEN
Total output frame size after encryption.
Definition cipher.h:45
uint8_t spp_uint8_t
Definition types.h:27

Definition at line 45 of file cipher.h.

Referenced by SPP_EXTERNAL_ENCRYPTION_CYPHER_encryptPacket(), and SPP_HAL_UART_transmit().

◆ K_SPP_CIPHER_KEY

#define K_SPP_CIPHER_KEY
Value:
{ 0x68, 0x6F, 0x6C, 0x79, 0x66, 0x75, 0x63, 0x6B, \
0x69, 0x6E, 0x67, 0x73, 0x68, 0x69, 0x74, 0x21 }

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.

Definition at line 53 of file cipher.h.

Function Documentation

◆ SPP_EXTERNAL_ENCRYPTION_CYPHER_encryptPacket()

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:

  • Bytes 0-3 : timestampMs (little-endian).
  • Bytes 4-5 : seq (little-endian).
  • Bytes 6-11 : 0x00 (reserved).

p_buffer must point to a buffer of at least K_SPP_CIPHER_FRAME_LEN bytes so the output frame fits.

Parameters
[in,out]p_bufferOn entry: raw SPP packet bytes. On exit: encrypted frame (nonce | ciphertext | tag).
[out]p_outSizeSet to K_SPP_CIPHER_FRAME_LEN on success.
Returns
K_SPP_OK on success, K_SPP_ERROR_NULL_POINTER if any pointer is NULL.

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

Here is the call graph for this function:
Here is the caller graph for this function: