Mbed TLS v3.5.0
cmac.h
Go to the documentation of this file.
1 
10 /*
11  * Copyright The Mbed TLS Contributors
12  * SPDX-License-Identifier: Apache-2.0
13  *
14  * Licensed under the Apache License, Version 2.0 (the "License"); you may
15  * not use this file except in compliance with the License.
16  * You may obtain a copy of the License at
17  *
18  * http://www.apache.org/licenses/LICENSE-2.0
19  *
20  * Unless required by applicable law or agreed to in writing, software
21  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23  * See the License for the specific language governing permissions and
24  * limitations under the License.
25  */
26 
27 #ifndef MBEDTLS_CMAC_H
28 #define MBEDTLS_CMAC_H
29 #include "mbedtls/private_access.h"
30 
31 #include "mbedtls/build_info.h"
32 
33 #include "mbedtls/cipher.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #define MBEDTLS_AES_BLOCK_SIZE 16
40 #define MBEDTLS_DES3_BLOCK_SIZE 8
41 
42 /* We don't support Camellia or ARIA in this module */
43 #if defined(MBEDTLS_AES_C)
44 #define MBEDTLS_CMAC_MAX_BLOCK_SIZE 16
45 #else
46 #define MBEDTLS_CMAC_MAX_BLOCK_SIZE 8
47 #endif
48 
49 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
58 /* Before Mbed TLS 3.5, this was the maximum block size supported by the CMAC
59  * module, so it didn't take Camellia or ARIA into account. Since the name
60  * of the macro doesn't even convey "CMAC", this was misleading. Now the size
61  * is sufficient for any cipher, but the name is defined in cmac.h for
62  * backward compatibility. */
63 #define MBEDTLS_CIPHER_BLKSIZE_MAX MBEDTLS_MAX_BLOCK_LENGTH
64 #endif /* MBEDTLS_DEPRECATED_REMOVED */
65 
66 #if !defined(MBEDTLS_CMAC_ALT)
67 
74 
77  unsigned char MBEDTLS_PRIVATE(unprocessed_block)[MBEDTLS_CMAC_MAX_BLOCK_SIZE];
78 
80  size_t MBEDTLS_PRIVATE(unprocessed_len);
81 };
82 
83 #else /* !MBEDTLS_CMAC_ALT */
84 #include "cmac_alt.h"
85 #endif /* !MBEDTLS_CMAC_ALT */
86 
118  const unsigned char *key, size_t keybits);
119 
143  const unsigned char *input, size_t ilen);
144 
162  unsigned char *output);
163 
181 
210  const unsigned char *key, size_t keylen,
211  const unsigned char *input, size_t ilen,
212  unsigned char *output);
213 
214 #if defined(MBEDTLS_AES_C)
232 int mbedtls_aes_cmac_prf_128(const unsigned char *key, size_t key_len,
233  const unsigned char *input, size_t in_len,
234  unsigned char output[16]);
235 #endif /* MBEDTLS_AES_C */
236 
237 #if defined(MBEDTLS_SELF_TEST) && (defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C))
251 int mbedtls_cmac_self_test(int verbose);
252 #endif /* MBEDTLS_SELF_TEST && ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 
258 #endif /* MBEDTLS_CMAC_H */
This file contains an abstraction interface for use with the cipher primitives provided by the librar...
int mbedtls_cipher_cmac_update(mbedtls_cipher_context_t *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing CMAC computation.
int mbedtls_cipher_cmac_reset(mbedtls_cipher_context_t *ctx)
This function starts a new CMAC operation with the same key as the previous one.
int mbedtls_cmac_self_test(int verbose)
The CMAC checkup routine.
int mbedtls_cipher_cmac_finish(mbedtls_cipher_context_t *ctx, unsigned char *output)
This function finishes an ongoing CMAC operation, and writes the result to the output buffer.
#define MBEDTLS_CMAC_MAX_BLOCK_SIZE
Definition: cmac.h:44
int mbedtls_aes_cmac_prf_128(const unsigned char *key, size_t key_len, const unsigned char *input, size_t in_len, unsigned char output[16])
This function implements the AES-CMAC-PRF-128 pseudorandom function, as defined in RFC-4615: The Adva...
int mbedtls_cipher_cmac_starts(mbedtls_cipher_context_t *ctx, const unsigned char *key, size_t keybits)
This function starts a new CMAC computation by setting the CMAC key, and preparing to authenticate th...
int mbedtls_cipher_cmac(const mbedtls_cipher_info_t *cipher_info, const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char *output)
This function calculates the full generic CMAC on the input buffer with the provided key.
Build-time configuration info.
Macro wrapper for struct's members.
#define MBEDTLS_PRIVATE(member)