Mbed TLS v3.5.0
ccm.h
Go to the documentation of this file.
1
30/*
31 * Copyright The Mbed TLS Contributors
32 * SPDX-License-Identifier: Apache-2.0
33 *
34 * Licensed under the Apache License, Version 2.0 (the "License"); you may
35 * not use this file except in compliance with the License.
36 * You may obtain a copy of the License at
37 *
38 * http://www.apache.org/licenses/LICENSE-2.0
39 *
40 * Unless required by applicable law or agreed to in writing, software
41 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
42 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43 * See the License for the specific language governing permissions and
44 * limitations under the License.
45 */
46
47#ifndef MBEDTLS_CCM_H
48#define MBEDTLS_CCM_H
50
51#include "mbedtls/build_info.h"
52
53#include "mbedtls/cipher.h"
54
55#define MBEDTLS_CCM_DECRYPT 0
56#define MBEDTLS_CCM_ENCRYPT 1
57#define MBEDTLS_CCM_STAR_DECRYPT 2
58#define MBEDTLS_CCM_STAR_ENCRYPT 3
59
61#define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D
63#define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69#if !defined(MBEDTLS_CCM_ALT)
70// Regular implementation
71//
72
77typedef struct mbedtls_ccm_context {
78 unsigned char MBEDTLS_PRIVATE(y)[16];
79 unsigned char MBEDTLS_PRIVATE(ctr)[16];
80 size_t MBEDTLS_PRIVATE(plaintext_len);
81 size_t MBEDTLS_PRIVATE(add_len);
82 size_t MBEDTLS_PRIVATE(tag_len);
83 size_t MBEDTLS_PRIVATE(processed);
89 unsigned int MBEDTLS_PRIVATE(q);
90 unsigned int MBEDTLS_PRIVATE(mode);
96 int MBEDTLS_PRIVATE(state);
98}
100
101#else /* MBEDTLS_CCM_ALT */
102#include "ccm_alt.h"
103#endif /* MBEDTLS_CCM_ALT */
104
113
128 mbedtls_cipher_id_t cipher,
129 const unsigned char *key,
130 unsigned int keybits);
131
140
178 const unsigned char *iv, size_t iv_len,
179 const unsigned char *ad, size_t ad_len,
180 const unsigned char *input, unsigned char *output,
181 unsigned char *tag, size_t tag_len);
182
227 const unsigned char *iv, size_t iv_len,
228 const unsigned char *ad, size_t ad_len,
229 const unsigned char *input, unsigned char *output,
230 unsigned char *tag, size_t tag_len);
231
264 const unsigned char *iv, size_t iv_len,
265 const unsigned char *ad, size_t ad_len,
266 const unsigned char *input, unsigned char *output,
267 const unsigned char *tag, size_t tag_len);
268
310 const unsigned char *iv, size_t iv_len,
311 const unsigned char *ad, size_t ad_len,
312 const unsigned char *input, unsigned char *output,
313 const unsigned char *tag, size_t tag_len);
314
344 int mode,
345 const unsigned char *iv,
346 size_t iv_len);
347
376 size_t total_ad_len,
377 size_t plaintext_len,
378 size_t tag_len);
379
411 const unsigned char *ad,
412 size_t ad_len);
413
478 const unsigned char *input, size_t input_len,
479 unsigned char *output, size_t output_size,
480 size_t *output_len);
481
514 unsigned char *tag, size_t tag_len);
515
516#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
523int mbedtls_ccm_self_test(int verbose);
524#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
525
526#ifdef __cplusplus
527}
528#endif
529
530#endif /* MBEDTLS_CCM_H */
int mbedtls_ccm_encrypt_and_tag(mbedtls_ccm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *ad, size_t ad_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_self_test(int verbose)
The CCM checkup routine.
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_starts(mbedtls_ccm_context *ctx, int mode, const unsigned char *iv, size_t iv_len)
This function starts a CCM encryption or decryption operation.
int mbedtls_ccm_star_auth_decrypt(mbedtls_ccm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *ad, size_t ad_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_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.
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 *ad, size_t ad_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_finish(mbedtls_ccm_context *ctx, unsigned char *tag, size_t tag_len)
This function finishes the CCM operation and generates the authentication tag.
int mbedtls_ccm_set_lengths(mbedtls_ccm_context *ctx, size_t total_ad_len, size_t plaintext_len, size_t tag_len)
This function declares the lengths of the message and additional data for a CCM encryption or decrypt...
int mbedtls_ccm_update(mbedtls_ccm_context *ctx, const unsigned char *input, size_t input_len, unsigned char *output, size_t output_size, size_t *output_len)
This function feeds an input buffer into an ongoing CCM encryption or decryption operation.
struct mbedtls_ccm_context mbedtls_ccm_context
The CCM context-type definition. The CCM context is passed to the APIs called.
void mbedtls_ccm_init(mbedtls_ccm_context *ctx)
This function initializes the specified CCM context, to make references valid, and prepare the contex...
int mbedtls_ccm_auth_decrypt(mbedtls_ccm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *ad, size_t ad_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_update_ad(mbedtls_ccm_context *ctx, const unsigned char *ad, size_t ad_len)
This function feeds an input buffer as associated data (authenticated but not encrypted data) in a CC...
This file contains an abstraction interface for use with the cipher primitives provided by the librar...
mbedtls_cipher_id_t
Supported cipher types.
Definition: cipher.h:78
Build-time configuration info.
Macro wrapper for struct's members.
#define MBEDTLS_PRIVATE(member)
The CCM context-type definition. The CCM context is passed to the APIs called.
Definition: ccm.h:77