Solaris Software
Toggle main menu visibility
Loading...
Searching...
No Matches
cipher.h
Go to the documentation of this file.
1
/**
2
* @file cipher.h
3
* @brief SPP packet AES-128-GCM cipher context.
4
*
5
* Provides a single function that encrypts a raw SPP packet buffer in-place,
6
* prepending the derived nonce and appending the GCM authentication tag.
7
* The output frame layout is:
8
*
9
* [ nonce (12 B) | ciphertext (sizeof SPP_Packet_t) | tag (16 B) ]
10
*
11
* The nonce is derived from the packet's timestamp and sequence counter to
12
* guarantee uniqueness per transmission. The symmetric key is stored in this
13
* header and must match on both ends of the link.
14
*
15
* Naming conventions used in this file:
16
* - Constants/macros: K_SPP_CIPHER_*
17
* - Public functions: SPP_CIPHER_*
18
* - Pointer params: p_*
19
*/
20
21
#ifndef SPP_EXTERNAL_CIPHER_H
22
#define SPP_EXTERNAL_CIPHER_H
23
24
#include "
spp/core/types.h
"
25
#include "
spp/core/packet.h
"
26
#include "
spp/core/returnTypes.h
"
27
28
/* ----------------------------------------------------------------
29
* DEFINES
30
* ---------------------------------------------------------------- */
31
32
#define K_SPP_CIPHER_KEY_LEN (16U)
/**< AES-128 key length in bytes. */
33
#define K_SPP_CIPHER_NONCE_LEN (12U)
/**< GCM recommended nonce length in bytes. */
34
#define K_SPP_CIPHER_TAG_LEN (16U)
/**< GCM authentication tag length in bytes. */
35
36
/**
37
* @brief Total output frame size after encryption.
38
*
39
* Layout: nonce | ciphertext | tag.
40
* Declare the output buffer with this size:
41
* @code
42
* spp_uint8_t buf[K_SPP_CIPHER_FRAME_LEN];
43
* @endcode
44
*/
45
#define K_SPP_CIPHER_FRAME_LEN (K_SPP_CIPHER_NONCE_LEN + sizeof(SPP_Packet_t) + K_SPP_CIPHER_TAG_LEN)
46
47
/**
48
* @brief AES-128 symmetric key shared between transmitter and receiver.
49
*
50
* Replace the placeholder bytes with the actual pre-shared key before
51
* deployment. Both ends of the link must use the identical value.
52
*/
53
#define K_SPP_CIPHER_KEY \
54
{ 0x68, 0x6F, 0x6C, 0x79, 0x66, 0x75, 0x63, 0x6B, \
55
0x69, 0x6E, 0x67, 0x73, 0x68, 0x69, 0x74, 0x21 }
56
57
/* ----------------------------------------------------------------
58
* PUBLIC FUNCTIONS
59
* ---------------------------------------------------------------- */
60
61
/**
62
* @brief Encrypt an SPP packet buffer in-place with AES-128-GCM.
63
*
64
* Reads sizeof(SPP_Packet_t) bytes from @p p_buffer, encrypts them, and
65
* overwrites @p p_buffer with the output frame:
66
*
67
* [ nonce (12 B) | ciphertext (sizeof SPP_Packet_t) | tag (16 B) ]
68
*
69
* The nonce is derived from the packet header:
70
* - Bytes 0-3 : timestampMs (little-endian).
71
* - Bytes 4-5 : seq (little-endian).
72
* - Bytes 6-11 : 0x00 (reserved).
73
*
74
* @p p_buffer must point to a buffer of at least @ref K_SPP_CIPHER_FRAME_LEN
75
* bytes so the output frame fits.
76
*
77
* @param[in,out] p_buffer On entry: raw SPP packet bytes.
78
* On exit: encrypted frame (nonce | ciphertext | tag).
79
* @param[out] p_outSize Set to @ref K_SPP_CIPHER_FRAME_LEN on success.
80
*
81
* @return K_SPP_OK on success, K_SPP_ERROR_NULL_POINTER if any pointer is NULL.
82
*/
83
SPP_RetVal_t
SPP_EXTERNAL_ENCRYPTION_CYPHER_encryptPacket
(
spp_uint8_t
*p_buffer,
spp_uint16_t
*p_outSize);
84
85
#endif
/* SPP_EXTERNAL_CIPHER_H */
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.
Definition
cipher.c:56
packet.h
Solaris Packet Protocol (SPP) packet structure definitions.
returnTypes.h
Standard return-value type used across all SPP modules.
SPP_RetVal_t
SPP_RetVal_t
Unified return type for all SPP API functions.
Definition
returnTypes.h:24
types.h
Portable integer types and SPI/storage configuration types for SPP.
spp_uint16_t
uint16_t spp_uint16_t
Definition
types.h:29
spp_uint8_t
uint8_t spp_uint8_t
Definition
types.h:27
solaris-v2
spp
external
encryption
cipher.h
Generated by
1.18.0