Mbed TLS v3.5.2
Loading...
Searching...
No Matches
ccm.h
Go to the documentation of this file.
1
30/*
31 * Copyright The Mbed TLS Contributors
32 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
33 */
34
35#ifndef MBEDTLS_CCM_H
36#define MBEDTLS_CCM_H
38
39#include "mbedtls/build_info.h"
40
41#include "mbedtls/cipher.h"
42
43#define MBEDTLS_CCM_DECRYPT 0
44#define MBEDTLS_CCM_ENCRYPT 1
45#define MBEDTLS_CCM_STAR_DECRYPT 2
46#define MBEDTLS_CCM_STAR_ENCRYPT 3
47
49#define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D
51#define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57#if !defined(MBEDTLS_CCM_ALT)
58// Regular implementation
59//
60
65typedef struct mbedtls_ccm_context {
66 unsigned char MBEDTLS_PRIVATE(y)[16];
67 unsigned char MBEDTLS_PRIVATE(ctr)[16];
68 size_t MBEDTLS_PRIVATE(plaintext_len);
69 size_t MBEDTLS_PRIVATE(add_len);
70 size_t MBEDTLS_PRIVATE(tag_len);
71 size_t MBEDTLS_PRIVATE(processed);
77 unsigned int MBEDTLS_PRIVATE(q);
78 unsigned int MBEDTLS_PRIVATE(mode);
84 int MBEDTLS_PRIVATE(state);
86}
88
89#else /* MBEDTLS_CCM_ALT */
90#include "ccm_alt.h"
91#endif /* MBEDTLS_CCM_ALT */
92
101
116 mbedtls_cipher_id_t cipher,
117 const unsigned char *key,
118 unsigned int keybits);
119
128
166 const unsigned char *iv, size_t iv_len,
167 const unsigned char *ad, size_t ad_len,
168 const unsigned char *input, unsigned char *output,
169 unsigned char *tag, size_t tag_len);
170
215 const unsigned char *iv, size_t iv_len,
216 const unsigned char *ad, size_t ad_len,
217 const unsigned char *input, unsigned char *output,
218 unsigned char *tag, size_t tag_len);
219
252 const unsigned char *iv, size_t iv_len,
253 const unsigned char *ad, size_t ad_len,
254 const unsigned char *input, unsigned char *output,
255 const unsigned char *tag, size_t tag_len);
256
298 const unsigned char *iv, size_t iv_len,
299 const unsigned char *ad, size_t ad_len,
300 const unsigned char *input, unsigned char *output,
301 const unsigned char *tag, size_t tag_len);
302
332 int mode,
333 const unsigned char *iv,
334 size_t iv_len);
335
364 size_t total_ad_len,
365 size_t plaintext_len,
366 size_t tag_len);
367
399 const unsigned char *ad,
400 size_t ad_len);
401
466 const unsigned char *input, size_t input_len,
467 unsigned char *output, size_t output_size,
468 size_t *output_len);
469
502 unsigned char *tag, size_t tag_len);
503
504#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
511int mbedtls_ccm_self_test(int verbose);
512#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
513
514#ifdef __cplusplus
515}
516#endif
517
518#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:66
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:65