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

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

#include "external/encryption/cipher.h"
#include "external/encryption/encryption.h"
#include <string.h>
Include dependency graph for cipher.c:

Go to the source code of this file.

Functions

static void s_buildNonce (const SPP_Packet_t *p_packet, spp_uint8_t p_nonce[K_SPP_CIPHER_NONCE_LEN])
 Derive the 12-byte GCM nonce from an SPP packet header.
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.

Variables

static const spp_uint8_t s_key [K_SPP_CIPHER_KEY_LEN] = K_SPP_CIPHER_KEY

Detailed Description

SPP packet AES-128-GCM cipher context implementation.

Encrypts a raw SPP packet buffer in-place, producing the output frame: [ nonce (12 B) | ciphertext (sizeof SPP_Packet_t) | tag (16 B) ]

Definition in file cipher.c.

Function Documentation

◆ s_buildNonce()

void s_buildNonce ( const SPP_Packet_t * p_packet,
spp_uint8_t p_nonce[K_SPP_CIPHER_NONCE_LEN] )
static

Derive the 12-byte GCM nonce from an SPP packet header.

Parameters
[in]p_packetPacket to derive nonce from.
[out]p_nonce12-byte output buffer.

Definition at line 34 of file cipher.c.

References K_SPP_CIPHER_NONCE_LEN, s_buildNonce(), and SPP_Packet_t.

Referenced by s_buildNonce(), and SPP_EXTERNAL_ENCRYPTION_CYPHER_encryptPacket().

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

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

Variable Documentation

◆ s_key

Definition at line 22 of file cipher.c.

Referenced by SPP_EXTERNAL_ENCRYPTION_CYPHER_encryptPacket().