ccm.h
mbedtls/config.h
mbedtls/cipher.h
ccm.h
mbedtls/check_config.h
mbedtls/cipher.h
mbedtls/config.h
mbedtls/platform_time.h
mbedtls/platform_util.h
limits.h
stddef.h
time.h
mbedtls_ccm_context
MBEDTLS_ERR_CCM_BAD_INPUT
-0x000D

Bad input parameters to the function.

MBEDTLS_ERR_CCM_AUTH_FAILED
-0x000F

Authenticated decryption failed.

MBEDTLS_ERR_CCM_HW_ACCEL_FAILED
-0x0011

CCM hardware accelerator failed.

struct mbedtls_ccm_context typedef struct mbedtls_ccm_context mbedtls_ccm_context mbedtls_ccm_context

The CCM context-type definition. The CCM context is passed to the APIs called.

void void mbedtls_ccm_init (mbedtls_ccm_context *ctx) mbedtls_ccm_init mbedtls_ccm_context * ctx

This function initializes the specified CCM context, to make references valid, and prepare the context for mbedtls_ccm_setkey() or mbedtls_ccm_free().

ctx

The CCM context to initialize. This must not be `NULL`.

int int mbedtls_ccm_setkey (mbedtls_ccm_context *ctx, mbedtls_cipher_id_t cipher, const unsigned char *key, unsigned int keybits) mbedtls_ccm_setkey mbedtls_ccm_context * ctx mbedtls_cipher_id_t cipher const unsigned char * key unsigned int keybits

This function initializes the CCM context set in the `ctx` parameter and sets the encryption key.

ctx

The CCM context to initialize. This must be an initialized context.

cipher

The 128-bit block cipher to use.

key

The encryption key. This must not be `NULL`.

keybits

The key size in bits. This must be acceptable by the cipher.

`0` on success.

A CCM or cipher-specific error code on failure.

void void mbedtls_ccm_free (mbedtls_ccm_context *ctx) mbedtls_ccm_free mbedtls_ccm_context * ctx

This function releases and clears the specified CCM context and underlying cipher sub-context.

ctx

The CCM context to clear. If this is `NULL`, the function has no effect. Otherwise, this must be initialized.

int int mbedtls_ccm_encrypt_and_tag (mbedtls_ccm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *input, unsigned char *output, unsigned char *tag, size_t tag_len) mbedtls_ccm_encrypt_and_tag mbedtls_ccm_context * ctx size_t length const unsigned char * iv size_t iv_len const unsigned char * add size_t add_len const unsigned char * input unsigned char * output unsigned char * tag size_t tag_len

This function encrypts a buffer using CCM.

The tag is written to a separate buffer. To concatenate the `tag` with the `output`, as done in RFC-3610: Counter with CBC-MAC (CCM), use `tag` = `output` + `length`, and make sure that the output buffer is at least `length` + `tag_len` wide.

ctx

The CCM context to use for encryption. This must be initialized and bound to a key.

length

The length of the input data in Bytes.

iv

The initialization vector (nonce). This must be a readable buffer of at least `iv_len` Bytes.

iv_len

The length of the nonce in Bytes: 7, 8, 9, 10, 11, 12, or 13. The length L of the message length field is 15 - `iv_len`.

add

The additional data field. If `add_len` is greater than zero, `add` must be a readable buffer of at least that length.

add_len

The length of additional data in Bytes. This must be less than `2^16 - 2^8`.

input

The buffer holding the input data. If `length` is greater than zero, `input` must be a readable buffer of at least that length.

output

The buffer holding the output data. If `length` is greater than zero, `output` must be a writable buffer of at least that length.

tag

The buffer holding the authentication field. This must be a writable buffer of at least `tag_len` Bytes.

tag_len

The length of the authentication field to generate in Bytes: 4, 6, 8, 10, 12, 14 or 16.

`0` on success.

A CCM or cipher-specific error code on failure.

int int mbedtls_ccm_star_encrypt_and_tag (mbedtls_ccm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *input, unsigned char *output, unsigned char *tag, size_t tag_len) mbedtls_ccm_star_encrypt_and_tag mbedtls_ccm_context * ctx size_t length const unsigned char * iv size_t iv_len const unsigned char * add size_t add_len const unsigned char * input unsigned char * output unsigned char * tag size_t tag_len

This function encrypts a buffer using CCM*.

The tag is written to a separate buffer. To concatenate the `tag` with the `output`, as done in RFC-3610: Counter with CBC-MAC (CCM), use `tag` = `output` + `length`, and make sure that the output buffer is at least `length` + `tag_len` wide.

When using this function in a variable tag length context, the tag length has to be encoded into the `iv` passed to this function.

ctx

The CCM context to use for encryption. This must be initialized and bound to a key.

length

The length of the input data in Bytes.

iv

The initialization vector (nonce). This must be a readable buffer of at least `iv_len` Bytes.

iv_len

The length of the nonce in Bytes: 7, 8, 9, 10, 11, 12, or 13. The length L of the message length field is 15 - `iv_len`.

add

The additional data field. This must be a readable buffer of at least `add_len` Bytes.

add_len

The length of additional data in Bytes. This must be less than 2^16 - 2^8.

input

The buffer holding the input data. If `length` is greater than zero, `input` must be a readable buffer of at least that length.

output

The buffer holding the output data. If `length` is greater than zero, `output` must be a writable buffer of at least that length.

tag

The buffer holding the authentication field. This must be a writable buffer of at least `tag_len` Bytes.

tag_len

The length of the authentication field to generate in Bytes: 0, 4, 6, 8, 10, 12, 14 or 16.

Passing `0` as `tag_len` means that the message is no longer authenticated.

`0` on success.

A CCM or cipher-specific error code on failure.

int int mbedtls_ccm_auth_decrypt (mbedtls_ccm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *input, unsigned char *output, const unsigned char *tag, size_t tag_len) mbedtls_ccm_auth_decrypt mbedtls_ccm_context * ctx size_t length const unsigned char * iv size_t iv_len const unsigned char * add size_t add_len const unsigned char * input unsigned char * output const unsigned char * tag size_t tag_len

This function performs a CCM authenticated decryption of a buffer.

ctx

The CCM context to use for decryption. This must be initialized and bound to a key.

length

The length of the input data in Bytes.

iv

The initialization vector (nonce). This must be a readable buffer of at least `iv_len` Bytes.

iv_len

The length of the nonce in Bytes: 7, 8, 9, 10, 11, 12, or 13. The length L of the message length field is 15 - `iv_len`.

add

The additional data field. This must be a readable buffer of at least that `add_len` Bytes..

add_len

The length of additional data in Bytes. This must be less than 2^16 - 2^8.

input

The buffer holding the input data. If `length` is greater than zero, `input` must be a readable buffer of at least that length.

output

The buffer holding the output data. If `length` is greater than zero, `output` must be a writable buffer of at least that length.

tag

The buffer holding the authentication field. This must be a readable buffer of at least `tag_len` Bytes.

tag_len

The length of the authentication field to generate in Bytes: 4, 6, 8, 10, 12, 14 or 16.

`0` on success. This indicates that the message is authentic.

MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match.

A cipher-specific error code on calculation failure.

int int mbedtls_ccm_star_auth_decrypt (mbedtls_ccm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *input, unsigned char *output, const unsigned char *tag, size_t tag_len) mbedtls_ccm_star_auth_decrypt mbedtls_ccm_context * ctx size_t length const unsigned char * iv size_t iv_len const unsigned char * add size_t add_len const unsigned char * input unsigned char * output const unsigned char * tag size_t tag_len

This function performs a CCM* authenticated decryption of a buffer.

When using this function in a variable tag length context, the tag length has to be decoded from `iv` and passed to this function as `tag_len`. (`tag` needs to be adjusted accordingly.)

ctx

The CCM context to use for decryption. This must be initialized and bound to a key.

length

The length of the input data in Bytes.

iv

The initialization vector (nonce). This must be a readable buffer of at least `iv_len` Bytes.

iv_len

The length of the nonce in Bytes: 7, 8, 9, 10, 11, 12, or 13. The length L of the message length field is 15 - `iv_len`.

add

The additional data field. This must be a readable buffer of at least that `add_len` Bytes.

add_len

The length of additional data in Bytes. This must be less than 2^16 - 2^8.

input

The buffer holding the input data. If `length` is greater than zero, `input` must be a readable buffer of at least that length.

output

The buffer holding the output data. If `length` is greater than zero, `output` must be a writable buffer of at least that length.

tag

The buffer holding the authentication field. This must be a readable buffer of at least `tag_len` Bytes.

tag_len

The length of the authentication field in Bytes. 0, 4, 6, 8, 10, 12, 14 or 16.

Passing `0` as `tag_len` means that the message is nos longer authenticated.

`0` on success.

MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match.

A cipher-specific error code on calculation failure.

int int mbedtls_ccm_self_test (int verbose) mbedtls_ccm_self_test int verbose

The CCM checkup routine.

`0` on success.

`1` on failure.

This file provides an API for the CCM authenticated encryption mode for block ciphers.

CCM combines Counter mode encryption with CBC-MAC authentication for 128-bit block ciphers.

Input to CCM includes the following elements:

- Payload - data that is both authenticated and encrypted.

- Associated data (Adata) - data that is authenticated but not encrypted, For example, a header.

- Nonce - A unique value that is assigned to the payload and the associated data.

Definition of CCM: http://csrc.nist.gov/publications/nistpubs/800-38C/SP800-38C_updated-July20_2007.pdf RFC 3610 "Counter with CBC-MAC (CCM)"

Related: RFC 5116 "An Interface and Algorithms for Authenticated Encryption"

Definition of CCM*: IEEE 802.15.4 - IEEE Standard for Local and metropolitan area networks Integer representation is fixed most-significant-octet-first order and the representation of octets is most-significant-bit-first order. This is consistent with RFC 3610.

    /*
    *CopyrightTheMbedTLSContributors
    *SPDX-License-Identifier:Apache-2.0ORGPL-2.0-or-later
    */

    #ifndefMBEDTLS_CCM_H
    #defineMBEDTLS_CCM_H

    #if!defined(MBEDTLS_CONFIG_FILE)
    #include"mbedtls/config.h"
    #else
    #includeMBEDTLS_CONFIG_FILE
    #endif

    #include"mbedtls/cipher.h"

    #defineMBEDTLS_ERR_CCM_BAD_INPUT-0x000D
    #defineMBEDTLS_ERR_CCM_AUTH_FAILED-0x000F

    /*MBEDTLS_ERR_CCM_HW_ACCEL_FAILEDisdeprecatedandshouldnotbeused.*/
    #defineMBEDTLS_ERR_CCM_HW_ACCEL_FAILED-0x0011

    #ifdef__cplusplus
    extern"C"{
    #endif

    #if!defined(MBEDTLS_CCM_ALT)
    //Regularimplementation
    //

    typedefstructmbedtls_ccm_context{
    mbedtls_cipher_context_tcipher_ctx;
    }
    mbedtls_ccm_context;

    #else/*MBEDTLS_CCM_ALT*/
    #include"ccm_alt.h"
    #endif/*MBEDTLS_CCM_ALT*/

    voidmbedtls_ccm_init(mbedtls_ccm_context*ctx);

    intmbedtls_ccm_setkey(mbedtls_ccm_context*ctx,
    mbedtls_cipher_id_tcipher,
    constunsignedchar*key,
    unsignedintkeybits);

    voidmbedtls_ccm_free(mbedtls_ccm_context*ctx);

    intmbedtls_ccm_encrypt_and_tag(mbedtls_ccm_context*ctx,size_tlength,
    constunsignedchar*iv,size_tiv_len,
    constunsignedchar*add,size_tadd_len,
    constunsignedchar*input,unsignedchar*output,
    unsignedchar*tag,size_ttag_len);

    intmbedtls_ccm_star_encrypt_and_tag(mbedtls_ccm_context*ctx,size_tlength,
    constunsignedchar*iv,size_tiv_len,
    constunsignedchar*add,size_tadd_len,
    constunsignedchar*input,unsignedchar*output,
    unsignedchar*tag,size_ttag_len);

    intmbedtls_ccm_auth_decrypt(mbedtls_ccm_context*ctx,size_tlength,
    constunsignedchar*iv,size_tiv_len,
    constunsignedchar*add,size_tadd_len,
    constunsignedchar*input,unsignedchar*output,
    constunsignedchar*tag,size_ttag_len);

    intmbedtls_ccm_star_auth_decrypt(mbedtls_ccm_context*ctx,size_tlength,
    constunsignedchar*iv,size_tiv_len,
    constunsignedchar*add,size_tadd_len,
    constunsignedchar*input,unsignedchar*output,
    constunsignedchar*tag,size_ttag_len);

    #ifdefined(MBEDTLS_SELF_TEST)&&defined(MBEDTLS_AES_C)
    intmbedtls_ccm_self_test(intverbose);
    #endif/*MBEDTLS_SELF_TEST&&MBEDTLS_AES_C*/

    #ifdef__cplusplus
    }
    #endif

    #endif/*MBEDTLS_CCM_H*/