mbed TLS v2.2.0
Data Structures | Macros | Functions
ccm.h File Reference

Detailed Description

Counter with CBC-MAC (CCM) for 128-bit block ciphers.

Copyright (C) 2006-2015, ARM Limited, All Rights Reserved SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

This file is part of mbed TLS (https://tls.mbed.org)

Definition in file ccm.h.

#include "cipher.h"
Include dependency graph for ccm.h:

Go to the source code of this file.

Data Structures

struct  mbedtls_ccm_context
 CCM context structure. More...
 

Macros

#define MBEDTLS_ERR_CCM_BAD_INPUT   -0x000D
 Bad input parameters to function. More...
 
#define MBEDTLS_ERR_CCM_AUTH_FAILED   -0x000F
 Authenticated decryption failed. More...
 

Functions

void mbedtls_ccm_init (mbedtls_ccm_context *ctx)
 Initialize CCM context (just makes references valid) Makes the context ready for mbedtls_ccm_setkey() or mbedtls_ccm_free(). More...
 
int mbedtls_ccm_setkey (mbedtls_ccm_context *ctx, mbedtls_cipher_id_t cipher, const unsigned char *key, unsigned int keybits)
 CCM initialization (encryption and decryption) More...
 
void mbedtls_ccm_free (mbedtls_ccm_context *ctx)
 Free a CCM context and underlying cipher sub-context. More...
 
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)
 CCM buffer encryption. More...
 
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)
 CCM buffer authenticated decryption. More...
 

Macro Definition Documentation

#define MBEDTLS_ERR_CCM_AUTH_FAILED   -0x000F

Authenticated decryption failed.

Definition at line 29 of file ccm.h.

#define MBEDTLS_ERR_CCM_BAD_INPUT   -0x000D

Bad input parameters to function.

Definition at line 28 of file ccm.h.

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 
)

CCM buffer authenticated decryption.

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
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 
)

CCM buffer encryption.

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
void mbedtls_ccm_free ( mbedtls_ccm_context ctx)

Free a CCM context and underlying cipher sub-context.

Parameters
ctxCCM context to free
void mbedtls_ccm_init ( mbedtls_ccm_context ctx)

Initialize CCM context (just makes references valid) Makes the context ready for mbedtls_ccm_setkey() or mbedtls_ccm_free().

Parameters
ctxCCM context to initialize
int mbedtls_ccm_setkey ( mbedtls_ccm_context ctx,
mbedtls_cipher_id_t  cipher,
const unsigned char *  key,
unsigned int  keybits 
)

CCM initialization (encryption and decryption)

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