mbed TLS v3.4.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
49 #include "mbedtls/private_access.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
62 
63 #define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F
64 
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 
69 #if !defined(MBEDTLS_CCM_ALT)
70 // Regular implementation
71 //
72 
77 typedef struct mbedtls_ccm_context {
78  unsigned char MBEDTLS_PRIVATE(y)[16];
79  unsigned char MBEDTLS_PRIVATE(ctr)[16];
81  size_t MBEDTLS_PRIVATE(plaintext_len);
82  size_t MBEDTLS_PRIVATE(add_len);
83  size_t MBEDTLS_PRIVATE(tag_len);
84  size_t MBEDTLS_PRIVATE(processed);
90  unsigned char MBEDTLS_PRIVATE(q);
91  unsigned char MBEDTLS_PRIVATE(mode);
96  int MBEDTLS_PRIVATE(state);
99 }
101 
102 #else /* MBEDTLS_CCM_ALT */
103 #include "ccm_alt.h"
104 #endif /* MBEDTLS_CCM_ALT */
105 
114 
129  mbedtls_cipher_id_t cipher,
130  const unsigned char *key,
131  unsigned int keybits);
132 
141 
178 int mbedtls_ccm_encrypt_and_tag(mbedtls_ccm_context *ctx, size_t length,
179  const unsigned char *iv, size_t iv_len,
180  const unsigned char *ad, size_t ad_len,
181  const unsigned char *input, unsigned char *output,
182  unsigned char *tag, size_t tag_len);
183 
228  const unsigned char *iv, size_t iv_len,
229  const unsigned char *ad, size_t ad_len,
230  const unsigned char *input, unsigned char *output,
231  unsigned char *tag, size_t tag_len);
232 
264 int mbedtls_ccm_auth_decrypt(mbedtls_ccm_context *ctx, size_t length,
265  const unsigned char *iv, size_t iv_len,
266  const unsigned char *ad, size_t ad_len,
267  const unsigned char *input, unsigned char *output,
268  const unsigned char *tag, size_t tag_len);
269 
310 int mbedtls_ccm_star_auth_decrypt(mbedtls_ccm_context *ctx, size_t length,
311  const unsigned char *iv, size_t iv_len,
312  const unsigned char *ad, size_t ad_len,
313  const unsigned char *input, unsigned char *output,
314  const unsigned char *tag, size_t tag_len);
315 
345  int mode,
346  const unsigned char *iv,
347  size_t iv_len);
348 
377  size_t total_ad_len,
378  size_t plaintext_len,
379  size_t tag_len);
380 
412  const unsigned char *ad,
413  size_t ad_len);
414 
479  const unsigned char *input, size_t input_len,
480  unsigned char *output, size_t output_size,
481  size_t *output_len);
482 
515  unsigned char *tag, size_t tag_len);
516 
517 #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
518 
524 int mbedtls_ccm_self_test(int verbose);
525 #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
526 
527 #ifdef __cplusplus
528 }
529 #endif
530 
531 #endif /* MBEDTLS_CCM_H */
void mbedtls_ccm_free(mbedtls_ccm_context *ctx)
This function releases and clears the specified CCM context and underlying cipher sub-context...
The CCM context-type definition. The CCM context is passed to the APIs called.
Definition: ccm.h:77
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.
#define MBEDTLS_PRIVATE(member)
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_finish(mbedtls_ccm_context *ctx, unsigned char *tag, size_t tag_len)
This function finishes the CCM operation and generates the authentication tag.
struct mbedtls_ccm_context mbedtls_ccm_context
The CCM context-type definition. The CCM context is passed to the APIs called.
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_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...
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.
mbedtls_cipher_id_t
Supported cipher types.
Definition: cipher.h:78
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_starts(mbedtls_ccm_context *ctx, int mode, const unsigned char *iv, size_t iv_len)
This function starts a CCM encryption or decryption operation.
Macro wrapper for struct's members.
This file contains an abstraction interface for use with the cipher primitives provided by the librar...
Build-time configuration info.
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_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_self_test(int verbose)
The CCM checkup routine.
void mbedtls_ccm_init(mbedtls_ccm_context *ctx)
This function initializes the specified CCM context, to make references valid, and prepare the contex...