mbed TLS v3.1.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 {
79  unsigned char MBEDTLS_PRIVATE(y)[16];
80  unsigned char MBEDTLS_PRIVATE(ctr)[16];
82  size_t MBEDTLS_PRIVATE(plaintext_len);
83  size_t MBEDTLS_PRIVATE(add_len);
84  size_t MBEDTLS_PRIVATE(tag_len);
85  size_t MBEDTLS_PRIVATE(processed);
91  unsigned char MBEDTLS_PRIVATE(q);
92  unsigned char MBEDTLS_PRIVATE(mode);
97  int MBEDTLS_PRIVATE(state);
100 }
101 mbedtls_ccm_context;
102 
103 #else /* MBEDTLS_CCM_ALT */
104 #include "ccm_alt.h"
105 #endif /* MBEDTLS_CCM_ALT */
106 
114 void mbedtls_ccm_init( mbedtls_ccm_context *ctx );
115 
129 int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
130  mbedtls_cipher_id_t cipher,
131  const unsigned char *key,
132  unsigned int keybits );
133 
141 void mbedtls_ccm_free( mbedtls_ccm_context *ctx );
142 
179 int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
180  const unsigned char *iv, size_t iv_len,
181  const unsigned char *ad, size_t ad_len,
182  const unsigned char *input, unsigned char *output,
183  unsigned char *tag, size_t tag_len );
184 
228 int mbedtls_ccm_star_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
229  const unsigned char *iv, size_t iv_len,
230  const unsigned char *ad, size_t ad_len,
231  const unsigned char *input, unsigned char *output,
232  unsigned char *tag, size_t tag_len );
233 
265 int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
266  const unsigned char *iv, size_t iv_len,
267  const unsigned char *ad, size_t ad_len,
268  const unsigned char *input, unsigned char *output,
269  const unsigned char *tag, size_t tag_len );
270 
311 int mbedtls_ccm_star_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
312  const unsigned char *iv, size_t iv_len,
313  const unsigned char *ad, size_t ad_len,
314  const unsigned char *input, unsigned char *output,
315  const unsigned char *tag, size_t tag_len );
316 
345 int mbedtls_ccm_starts( mbedtls_ccm_context *ctx,
346  int mode,
347  const unsigned char *iv,
348  size_t iv_len );
349 
377 int mbedtls_ccm_set_lengths( mbedtls_ccm_context *ctx,
378  size_t total_ad_len,
379  size_t plaintext_len,
380  size_t tag_len );
381 
412 int mbedtls_ccm_update_ad( mbedtls_ccm_context *ctx,
413  const unsigned char *ad,
414  size_t ad_len );
415 
479 int mbedtls_ccm_update( mbedtls_ccm_context *ctx,
480  const unsigned char *input, size_t input_len,
481  unsigned char *output, size_t output_size,
482  size_t *output_len );
483 
515 int mbedtls_ccm_finish( mbedtls_ccm_context *ctx,
516  unsigned char *tag, size_t tag_len );
517 
518 #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
519 
525 int mbedtls_ccm_self_test( int verbose );
526 #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
527 
528 #ifdef __cplusplus
529 }
530 #endif
531 
532 #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...
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.
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:83
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 memebrs.
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...