SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration

Detailed Description

AES-CCM.

Data Structures

struct  SharkSslAesCcmCtx
 AesCcmCtx. More...
 

Typedefs

typedef struct SharkSslAesCcmCtx SharkSslAesCcmCtx
 AesCcmCtx. More...
 

Functions

SHARKSSL_API SHARKSSL_AES_API_STATUS SharkSslAesCcmCtx_constructor (SharkSslAesCcmCtx *ctx, const U8 *key, U8 keyLen, U8 tagLen)
 Initialize. More...
 
SHARKSSL_API int SharkSslAesCcmCtx_encrypt (SharkSslAesCcmCtx *ctx, const U8 vect[12], U8 *tagout, const U8 *auth, U16 authlen, const U8 *input, U8 *output, U32 len)
 Encrypt. More...
 
SHARKSSL_API int SharkSslAesCcmCtx_decrypt (SharkSslAesCcmCtx *ctx, const U8 vect[12], U8 *tagin, const U8 *auth, U16 authlen, const U8 *input, U8 *output, U32 len)
 Decrypt. More...
 

Typedef Documentation

◆ SharkSslAesCcmCtx

AesCcmCtx.

Function Documentation

◆ SharkSslAesCcmCtx_constructor()

SHARKSSL_AES_API_STATUS SharkSslAesCcmCtx_constructor ( SharkSslAesCcmCtx *  ctx,
const U8 *  key,
U8  keyLen,
U8  tagLen 
)

Initialize.

The caller owns the context.

Parameters
ctxUninitialized data of size sizeof(SharkSslAesCcmCtx).
keythe encryption/decryption key
keyLen'key' length
tagLenlength of the tag (8 or 16 bytes)

The key length is in bytes: 16, 24, or 32, subject to the enabled algorithms/backend. Clear the context with its destructor after use.

Returns
Native build: void, with no return value. With SHARKSSL_PSA_CONSUMER_STANDALONE_AES=1: int, 0 on success and -1 on invalid arguments or provider failure.

◆ SharkSslAesCcmCtx_decrypt()

int SharkSslAesCcmCtx_decrypt ( SharkSslAesCcmCtx *  ctx,
const U8  vect[12],
U8 *  tagin,
const U8 *  auth,
U16  authlen,
const U8 *  input,
U8 *  output,
U32  len 
)

Decrypt.

Parameters
ctxSharkSslAesCcmCtx *; required initialized context with an 8- or 16-byte tag.
vectconst U8[12]; required nonce. For encryption, never reuse a nonce with the same key.
taginU8 *; required expected tag of ctx->tagLen bytes; borrowed for comparison.
authconst U8 *; additional authenticated data, or NULL with authlen=0.
authlenU16; AAD length in bytes. The native default requires less than 15; SHARKSSL_ENABLE_CCM_AUTH_ALL=1 permits lengths below 0xFEFF.
inputconst U8 *; required input buffer.
outputU8 *; required output buffer of at least len bytes; exact in-place operation is supported. Discard output unless the call succeeds.
lenU32; message length in bytes. The fixed 12-byte CCM nonce limits the encoded message length to less than 2^24 bytes.
Returns
int: 0 on success; nonzero on tag mismatch, or -1 on a PSA argument/provider failure. Native decryption can leave unauthenticated plaintext in output: do not use it before checking the result.

◆ SharkSslAesCcmCtx_encrypt()

int SharkSslAesCcmCtx_encrypt ( SharkSslAesCcmCtx *  ctx,
const U8  vect[12],
U8 *  tagout,
const U8 *  auth,
U16  authlen,
const U8 *  input,
U8 *  output,
U32  len 
)

Encrypt.

Parameters
ctxSharkSslAesCcmCtx *; required initialized context with an 8- or 16-byte tag.
vectconst U8[12]; required nonce. For encryption, never reuse a nonce with the same key.
tagoutU8 *; required output tag buffer of ctx->tagLen bytes.
authconst U8 *; additional authenticated data, or NULL with authlen=0.
authlenU16; AAD length in bytes. The native default requires less than 15; SHARKSSL_ENABLE_CCM_AUTH_ALL=1 permits lengths below 0xFEFF.
inputconst U8 *; required input buffer.
outputU8 *; required output buffer of at least len bytes; exact in-place operation is supported. Discard output unless the call succeeds.
lenU32; message length in bytes. The fixed 12-byte CCM nonce limits the encoded message length to less than 2^24 bytes.
Returns
int: 0 on success; -1 on a PSA argument/provider failure. Native encryption requires valid inputs and returns 0.