Kenji Arai / TYBLE16_mbedlized_os5_several_examples_1st

Dependencies:   nRF51_Vdd TextLCD BME280

Embed: (wiki syntax)

« Back to documentation index

ccm.h File Reference

ccm.h File Reference

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

Go to the source code of this file.

Data Structures

struct  mbedtls_ccm_context
 The CCM context-type definition. More...

Typedefs

typedef struct mbedtls_ccm_context mbedtls_ccm_context
 The CCM context-type definition.

Functions

void 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().
int 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.
void mbedtls_ccm_free (mbedtls_ccm_context *ctx)
 This function releases and clears the specified CCM context and underlying cipher sub-context.
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)
 This function encrypts a buffer using CCM.
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)
 This function encrypts a buffer using CCM*.
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)
 This function performs a CCM authenticated decryption of a buffer.
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)
 This function performs a CCM* authenticated decryption of a buffer.
int mbedtls_ccm_self_test (int verbose)
 The CCM checkup routine.

Detailed Description

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.

Definition in file ccm.h.


Typedef Documentation

The CCM context-type definition.

The CCM context is passed to the APIs called.


Function Documentation

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 
)

This function performs a CCM authenticated decryption of a buffer.

Parameters:
ctxThe CCM context to use for decryption.
lengthThe length of the input data in Bytes.
ivInitialization vector (nonce).
iv_lenThe 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.
addThe additional data field.
add_lenThe length of additional data in Bytes. Must be less than 2^16 - 2^8.
inputThe buffer holding the input data.
outputThe buffer holding the output data. Must be at least length Bytes wide.
tagThe buffer holding the authentication field.
tag_lenThe length of the authentication field in Bytes. 4, 6, 8, 10, 12, 14 or 16.
Returns:
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.

This function performs a CCM authenticated decryption of a buffer.

Parameters:
ctxCCM context
lengthlength of the input data
ivinitialization vector
iv_lenlength of IV
addadditional data
add_lenlength of additional data
inputbuffer holding the input data
outputbuffer for holding the output data
tagbuffer holding the tag
tag_lenlength of the tag
Returns:
0 if successful and authenticated, MBEDTLS_ERR_CCM_AUTH_FAILED if tag does not match

Definition at line 105 of file ccm_alt.c.

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 
)

This function encrypts a buffer using CCM.

Note:
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.
Parameters:
ctxThe CCM context to use for encryption.
lengthThe length of the input data in Bytes.
ivInitialization vector (nonce).
iv_lenThe 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.
addThe additional data field.
add_lenThe length of additional data in Bytes. Must be less than 2^16 - 2^8.
inputThe buffer holding the input data.
outputThe buffer holding the output data. Must be at least length Bytes wide.
tagThe buffer holding the authentication field.
tag_lenThe length of the authentication field to generate in Bytes: 4, 6, 8, 10, 12, 14 or 16.
Returns:
0 on success.
A CCM or cipher-specific error code on failure.

This function encrypts a buffer using CCM.

Parameters:
ctxCCM context
lengthlength of the input data in bytes
ivnonce (initialization vector)
iv_lenlength of IV in bytes must be 2, 3, 4, 5, 6, 7 or 8
addadditional data
add_lenlength of additional data in bytes must be less than 2^16 - 2^8
inputbuffer holding the input data
outputbuffer for holding the output data must be at least 'length' bytes wide
tagbuffer for holding the tag
tag_lenlength of the tag to generate in bytes must be 4, 6, 8, 10, 14 or 16
Note:
The tag is written to a separate buffer. To get the tag concatenated with the output as in the CCM spec, use tag = output + length and make sure the output buffer is at least length + tag_len wide.
Returns:
0 if successful

Definition at line 68 of file ccm_alt.c.

void mbedtls_ccm_free ( mbedtls_ccm_context ctx )

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

Parameters:
ctxThe CCM context to clear.

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

Parameters:
ctxCCM context to free

Definition at line 38 of file ccm_alt.c.

void 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().

Parameters:
ctxThe CCM context to initialize.

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

Parameters:
ctxCCM context to initialize

Definition at line 33 of file ccm_alt.c.

int mbedtls_ccm_self_test ( int  verbose )

The CCM checkup routine.

Returns:
0 on success.
1 on failure.

Definition at line 427 of file ccm.c.

int 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.

Parameters:
ctxThe CCM context to initialize.
cipherThe 128-bit block cipher to use.
keyThe encryption key.
keybitsThe key size in bits. This must be acceptable by the cipher.
Returns:
0 on success.
A CCM or cipher-specific error code on failure.

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

Parameters:
ctxCCM context to be initialized
ciphercipher to use (a 128-bit block cipher)
keyencryption key
keybitskey size in bits (must be acceptable by the cipher)
Returns:
0 if successful, or a cipher specific error code

Definition at line 43 of file ccm_alt.c.

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 
)

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

Note:
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.)
Parameters:
ctxThe CCM context to use for decryption.
lengthThe length of the input data in Bytes.
ivInitialization vector (nonce).
iv_lenThe 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.
addThe additional data field.
add_lenThe length of additional data in Bytes. Must be less than 2^16 - 2^8.
inputThe buffer holding the input data.
outputThe buffer holding the output data. Must be at least length Bytes wide.
tagThe buffer holding the authentication field.
tag_lenThe length of the authentication field in Bytes. 0, 4, 6, 8, 10, 12, 14 or 16.
Warning:
Passing 0 as tag_len means that the message is no longer authenticated.
Returns:
0 on success.
MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match.
A cipher-specific error code on calculation failure.

Definition at line 333 of file ccm.c.

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 
)

This function encrypts a buffer using CCM*.

Note:
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.
Parameters:
ctxThe CCM context to use for encryption.
lengthThe length of the input data in Bytes.
ivInitialization vector (nonce).
iv_lenThe 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.
addThe additional data field.
add_lenThe length of additional data in Bytes. Must be less than 2^16 - 2^8.
inputThe buffer holding the input data.
outputThe buffer holding the output data. Must be at least length Bytes wide.
tagThe buffer holding the authentication field.
tag_lenThe length of the authentication field to generate in Bytes: 0, 4, 6, 8, 10, 12, 14 or 16.
Warning:
Passing 0 as tag_len means that the message is no longer authenticated.
Returns:
0 on success.
A CCM or cipher-specific error code on failure.

Definition at line 307 of file ccm.c.