File syn_cose.c¶
FileList > proto > syn_cose.c
Go to the source code of this file
Zero-Heap CBOR Object Signing and Encryption (COSE - RFC 9052) implementation.
#include "syntropic/proto/syn_cose.h"#include "syntropic/util/syn_random.h"#include <string.h>
Public Functions¶
| Type | Name |
|---|---|
| SYN_Status | syn_cose_encrypt0_create (SYN_COSE_Algorithm alg, const uint8_t * key, const uint8_t * iv, size_t iv_len, const uint8_t * kid, size_t kid_len, const uint8_t * plaintext, size_t plaintext_len, const uint8_t * external_aad, size_t external_aad_len, uint8_t * out_buf, size_t out_buf_size, size_t * out_len) Encrypt a payload into a COSE_Encrypt0 (Tag 16) message using ChaCha20/Poly1305. |
| SYN_Status | syn_cose_encrypt0_decrypt (const uint8_t * msg, size_t msg_len, const uint8_t * key, const uint8_t * external_aad, size_t external_aad_len, uint8_t * out_plaintext, size_t out_plaintext_size, size_t * out_plaintext_len, SYN_COSE_Encrypt0Message * parsed_out) Decrypt and verify a COSE_Encrypt0 message. |
| SYN_Status | syn_cose_key_decode (const uint8_t * buf, size_t buf_len, SYN_COSE_Key * key_out) Decode a CBOR-encoded COSE_Key map into a SYN_COSE_Key structure. |
| SYN_Status | syn_cose_key_encode (const SYN_COSE_Key * key, uint8_t * out_buf, size_t out_buf_size, size_t * out_len) Encode a COSE_Key structure into CBOR format. |
| SYN_Status | syn_cose_mac0_create (SYN_COSE_Algorithm alg, const uint8_t * key, size_t key_len, const uint8_t * kid, size_t kid_len, const uint8_t * payload, size_t payload_len, const uint8_t * external_aad, size_t external_aad_len, uint8_t * out_buf, size_t out_buf_size, size_t * out_len) Create a COSE_Mac0 (Tag 17) message using HMAC-SHA256. |
| SYN_Status | syn_cose_mac0_verify (const uint8_t * msg, size_t msg_len, const uint8_t * key, size_t key_len, const uint8_t * external_aad, size_t external_aad_len, SYN_COSE_Mac0Message * parsed_out) Verify a COSE_Mac0 message using HMAC-SHA256. |
| SYN_Status | syn_cose_sign1_create (SYN_COSE_Algorithm alg, const uint8_t * secret_key, const uint8_t * public_key, const uint8_t * kid, size_t kid_len, const uint8_t * payload, size_t payload_len, const uint8_t * external_aad, size_t external_aad_len, uint8_t * out_buf, size_t out_buf_size, size_t * out_len) Create a COSE_Sign1 (Tag 18) message signed with EdDSA (Ed25519) or ES256 (P-256). |
| SYN_Status | syn_cose_sign1_verify (const uint8_t * msg, size_t msg_len, const uint8_t * public_key, size_t public_key_len, const uint8_t * external_aad, size_t external_aad_len, SYN_COSE_Sign1Message * parsed_out) Parse and verify a COSE_Sign1 message using the signer's public key. |
Public Functions Documentation¶
function syn_cose_encrypt0_create¶
Encrypt a payload into a COSE_Encrypt0 (Tag 16) message using ChaCha20/Poly1305.
SYN_Status syn_cose_encrypt0_create (
SYN_COSE_Algorithm alg,
const uint8_t * key,
const uint8_t * iv,
size_t iv_len,
const uint8_t * kid,
size_t kid_len,
const uint8_t * plaintext,
size_t plaintext_len,
const uint8_t * external_aad,
size_t external_aad_len,
uint8_t * out_buf,
size_t out_buf_size,
size_t * out_len
)
Parameters:
algEncryption algorithm (SYN_COSE_ALGO_CHACHA20_POLY1305).keySymmetric key (32 bytes).ivNonce / IV (12 bytes for ChaCha20/Poly1305).iv_lenIV length.kidOptional key identifier (NULL if unused).kid_lenKey identifier length.plaintextPlaintext payload to encrypt.plaintext_lenPlaintext length.external_aadOptional external associated data (NULL if unused).external_aad_lenExternal AAD length.out_buf[out] Output buffer for encoded COSE_Encrypt0 message.out_buf_sizeCapacity of output buffer.out_len[out] Number of bytes written to output buffer.
Returns:
SYN_Status SYN_OK on success, error code otherwise.
function syn_cose_encrypt0_decrypt¶
Decrypt and verify a COSE_Encrypt0 message.
SYN_Status syn_cose_encrypt0_decrypt (
const uint8_t * msg,
size_t msg_len,
const uint8_t * key,
const uint8_t * external_aad,
size_t external_aad_len,
uint8_t * out_plaintext,
size_t out_plaintext_size,
size_t * out_plaintext_len,
SYN_COSE_Encrypt0Message * parsed_out
)
Parameters:
msgRaw COSE_Encrypt0 CBOR encoded message.msg_lenMessage length.keySymmetric key (32 bytes).external_aadOptional external associated data (NULL if unused).external_aad_lenExternal AAD length.out_plaintext[out] Output buffer for decrypted plaintext.out_plaintext_sizeOutput buffer capacity.out_plaintext_len[out] Number of plaintext bytes written.parsed_out[out] Optional parsed message details (may be NULL).
Returns:
SYN_Status SYN_OK if decrypted and authenticated, error code otherwise.
function syn_cose_key_decode¶
Decode a CBOR-encoded COSE_Key map into a SYN_COSE_Key structure.
Parameters:
bufInput CBOR buffer.buf_lenLength of CBOR buffer.key_out[out] Decoded key descriptor.
Returns:
SYN_Status SYN_OK on success, error code otherwise.
function syn_cose_key_encode¶
Encode a COSE_Key structure into CBOR format.
SYN_Status syn_cose_key_encode (
const SYN_COSE_Key * key,
uint8_t * out_buf,
size_t out_buf_size,
size_t * out_len
)
Parameters:
keyPointer to populated COSE_Key descriptor.out_buf[out] Output buffer for encoded CBOR map.out_buf_sizeCapacity of output buffer.out_len[out] Number of bytes written.
Returns:
SYN_Status SYN_OK on success, error code otherwise.
function syn_cose_mac0_create¶
Create a COSE_Mac0 (Tag 17) message using HMAC-SHA256.
SYN_Status syn_cose_mac0_create (
SYN_COSE_Algorithm alg,
const uint8_t * key,
size_t key_len,
const uint8_t * kid,
size_t kid_len,
const uint8_t * payload,
size_t payload_len,
const uint8_t * external_aad,
size_t external_aad_len,
uint8_t * out_buf,
size_t out_buf_size,
size_t * out_len
)
Parameters:
algMAC algorithm (SYN_COSE_ALGO_HMAC_256_256 or SYN_COSE_ALGO_HMAC_256_64).keyMAC key.key_lenKey length in bytes.kidOptional key identifier (NULL if unused).kid_lenKey identifier length.payloadMessage payload to authenticate.payload_lenPayload length.external_aadOptional external associated data (NULL if unused).external_aad_lenExternal AAD length.out_buf[out] Output buffer for encoded COSE_Mac0 message.out_buf_sizeCapacity of output buffer.out_len[out] Number of bytes written to output buffer.
Returns:
SYN_Status SYN_OK on success, error code otherwise.
function syn_cose_mac0_verify¶
Verify a COSE_Mac0 message using HMAC-SHA256.
SYN_Status syn_cose_mac0_verify (
const uint8_t * msg,
size_t msg_len,
const uint8_t * key,
size_t key_len,
const uint8_t * external_aad,
size_t external_aad_len,
SYN_COSE_Mac0Message * parsed_out
)
Parameters:
msgRaw COSE_Mac0 CBOR encoded message.msg_lenMessage length.keyMAC key.key_lenKey length in bytes.external_aadOptional external associated data (NULL if unused).external_aad_lenExternal AAD length.parsed_out[out] Optional parsed message details (may be NULL).
Returns:
SYN_Status SYN_OK if authentication tag is valid, error code otherwise.
function syn_cose_sign1_create¶
Create a COSE_Sign1 (Tag 18) message signed with EdDSA (Ed25519) or ES256 (P-256).
SYN_Status syn_cose_sign1_create (
SYN_COSE_Algorithm alg,
const uint8_t * secret_key,
const uint8_t * public_key,
const uint8_t * kid,
size_t kid_len,
const uint8_t * payload,
size_t payload_len,
const uint8_t * external_aad,
size_t external_aad_len,
uint8_t * out_buf,
size_t out_buf_size,
size_t * out_len
)
Parameters:
algSignature algorithm (SYN_COSE_ALGO_EDDSA or SYN_COSE_ALGO_ES256).secret_keySecret key (32 bytes for Ed25519 / P-256 scalar).public_keyPublic key (32 bytes for Ed25519, 64/65 bytes for P-256).kidOptional key identifier (NULL if unused).kid_lenKey identifier length.payloadMessage payload to sign.payload_lenPayload length.external_aadOptional external associated data (NULL if unused).external_aad_lenExternal AAD length.out_buf[out] Output buffer for encoded COSE_Sign1 message.out_buf_sizeCapacity of output buffer.out_len[out] Number of bytes written to output buffer.
Returns:
SYN_Status SYN_OK on success, error code otherwise.
function syn_cose_sign1_verify¶
Parse and verify a COSE_Sign1 message using the signer's public key.
SYN_Status syn_cose_sign1_verify (
const uint8_t * msg,
size_t msg_len,
const uint8_t * public_key,
size_t public_key_len,
const uint8_t * external_aad,
size_t external_aad_len,
SYN_COSE_Sign1Message * parsed_out
)
Parameters:
msgRaw COSE_Sign1 CBOR encoded message.msg_lenMessage length.public_keyPublic key of the signer.public_key_lenPublic key length (32 for Ed25519, 64/65 for P-256).external_aadOptional external associated data (NULL if unused).external_aad_lenExternal AAD length.parsed_out[out] Optional parsed message details (may be NULL).
Returns:
SYN_Status SYN_OK if verified and valid, error code otherwise.
The documentation for this class was generated from the following file src/syntropic/proto/syn_cose.c