Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 1 | /** |
| 2 | * \file ccm.h |
| 3 | * |
Rose Zadik | 477dce1 | 2018-04-17 16:31:22 +0100 | [diff] [blame] | 4 | * \brief This file provides an API for the CCM authenticated encryption |
| 5 | * mode for block ciphers. |
Rose Zadik | 4ee9d24 | 2018-03-26 17:18:44 +0100 | [diff] [blame] | 6 | * |
| 7 | * CCM combines Counter mode encryption with CBC-MAC authentication |
| 8 | * for 128-bit block ciphers. |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 9 | * |
| 10 | * Input to CCM includes the following elements: |
| 11 | * <ul><li>Payload - data that is both authenticated and encrypted.</li> |
| 12 | * <li>Associated data (Adata) - data that is authenticated but not |
| 13 | * encrypted, For example, a header.</li> |
| 14 | * <li>Nonce - A unique value that is assigned to the payload and the |
| 15 | * associated data.</li></ul> |
| 16 | * |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 17 | */ |
| 18 | /* |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 19 | * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 20 | * SPDX-License-Identifier: Apache-2.0 |
| 21 | * |
| 22 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 23 | * not use this file except in compliance with the License. |
| 24 | * You may obtain a copy of the License at |
| 25 | * |
| 26 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 27 | * |
| 28 | * Unless required by applicable law or agreed to in writing, software |
| 29 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 30 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 31 | * See the License for the specific language governing permissions and |
| 32 | * limitations under the License. |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 33 | * |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 34 | * This file is part of Mbed TLS (https://tls.mbed.org) |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 35 | */ |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 36 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 37 | #ifndef MBEDTLS_CCM_H |
| 38 | #define MBEDTLS_CCM_H |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 39 | |
| 40 | #include "cipher.h" |
| 41 | |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 42 | #define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D /**< Bad input parameters to the function. */ |
| 43 | #define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F /**< Authenticated decryption failed. */ |
| 44 | #define MBEDTLS_ERR_CCM_HW_ACCEL_FAILED -0x0011 /**< CCM hardware accelerator failed. */ |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 45 | |
Steven Cooreman | 222e2ff | 2017-04-04 11:37:15 +0200 | [diff] [blame] | 46 | |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 47 | #ifdef __cplusplus |
| 48 | extern "C" { |
| 49 | #endif |
| 50 | |
Ron Eldor | 4e6d55d | 2018-02-07 16:36:15 +0200 | [diff] [blame] | 51 | #if !defined(MBEDTLS_CCM_ALT) |
| 52 | // Regular implementation |
| 53 | // |
| 54 | |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 55 | /** |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 56 | * \brief The CCM context-type definition. The CCM context is passed |
| 57 | * to the APIs called. |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 58 | */ |
| 59 | typedef struct { |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 60 | mbedtls_cipher_context_t cipher_ctx; /*!< The cipher context used. */ |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 61 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 62 | mbedtls_ccm_context; |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 63 | |
Ron Eldor | 4e6d55d | 2018-02-07 16:36:15 +0200 | [diff] [blame] | 64 | #else /* MBEDTLS_CCM_ALT */ |
| 65 | #include "ccm_alt.h" |
| 66 | #endif /* MBEDTLS_CCM_ALT */ |
| 67 | |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 68 | /** |
Janos Follath | f60c815 | 2018-04-27 14:45:49 +0100 | [diff] [blame] | 69 | * \brief The CCM* callback for encrypting with variable tag length. |
| 70 | * The function pointer is passed to the APIs called. This |
| 71 | * function calculates the nonce and returns it in a buffer. |
| 72 | * |
| 73 | * \warning This function must not return the same nonce more than once |
| 74 | * in the lifetime of the key! |
| 75 | * |
| 76 | * \note To prevent attacks taking advantage of the variable tag |
| 77 | * length CCM* encodes the tag length in the nonce. The method |
| 78 | * of encoding may vary. Standards might mandate encoding other |
| 79 | * information in the nonce (e.g. address and frame counter) |
| 80 | * too. |
| 81 | * |
| 82 | * \param app_ctx A pointer to structure containing the application context |
| 83 | * if it is necessary for calculating the initialisation vector |
| 84 | * (nonce). |
| 85 | * \param tag_len Length of the tag in bytes. |
| 86 | * \nonce Output variable, points to the buffer capable of holding the |
| 87 | * calculated nonce. Must be at least \p nonce_len bytes long. |
| 88 | * \nonce_len The length of the nonce in bytes. |
| 89 | * |
| 90 | * \return \c 0 on success. |
| 91 | * \return MBEDTLS_ERR_CCM_BAD_INPUT error code on failure. |
| 92 | */ |
| 93 | typedef int (*mbedtls_ccm_star_get_nonce_t)( void *app_ctx, size_t tag_len, |
| 94 | unsigned char *nonce, |
| 95 | size_t nonce_len ); |
| 96 | |
| 97 | /** |
| 98 | * \brief The CCM* callback for decrypting with variable tag length. |
| 99 | * The function pointer is passed to the APIs called. This |
| 100 | * function calculates and returns the length of the tag in the |
| 101 | * output parameter. |
| 102 | * |
| 103 | * \param app_ctx A pointer to structure containing the application context |
| 104 | * if it is necessary for decoding the tag length or validating |
| 105 | * the initialisation vector (nonce). |
| 106 | * \param tag_len Output variable for holding the tag length in bytes. |
| 107 | * \nonce A buffer containing the nonce. |
| 108 | * \nonce_len The length of the nonce in bytes. |
| 109 | * |
| 110 | * \return \c 0 on success. |
| 111 | * \return MBEDTLS_ERR_CCM_BAD_INPUT error code on failure. |
| 112 | */ |
| 113 | typedef int (*mbedtls_ccm_star_get_tag_len_t)( void *app_ctx, size_t* tag_len, |
| 114 | const unsigned char *nonce, |
| 115 | size_t nonce_len ); |
| 116 | |
| 117 | /** |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 118 | * \brief This function initializes the specified CCM context, |
| 119 | * to make references valid, and prepare the context |
| 120 | * for mbedtls_ccm_setkey() or mbedtls_ccm_free(). |
Manuel Pégourié-Gonnard | 6963ff0 | 2015-04-28 18:02:54 +0200 | [diff] [blame] | 121 | * |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 122 | * \param ctx The CCM context to initialize. |
Manuel Pégourié-Gonnard | 6963ff0 | 2015-04-28 18:02:54 +0200 | [diff] [blame] | 123 | */ |
| 124 | void mbedtls_ccm_init( mbedtls_ccm_context *ctx ); |
| 125 | |
| 126 | /** |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 127 | * \brief This function initializes the CCM context set in the |
| 128 | * \p ctx parameter and sets the encryption key. |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 129 | * |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 130 | * \param ctx The CCM context to initialize. |
| 131 | * \param cipher The 128-bit block cipher to use. |
| 132 | * \param key The encryption key. |
| 133 | * \param keybits The key size in bits. This must be acceptable by the cipher. |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 134 | * |
Rose Zadik | 4ee9d24 | 2018-03-26 17:18:44 +0100 | [diff] [blame] | 135 | * \return \c 0 on success. |
Rose Zadik | ef87179 | 2018-04-17 10:41:48 +0100 | [diff] [blame] | 136 | * \return A CCM or cipher-specific error code on failure. |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 137 | */ |
Manuel Pégourié-Gonnard | 6963ff0 | 2015-04-28 18:02:54 +0200 | [diff] [blame] | 138 | int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx, |
| 139 | mbedtls_cipher_id_t cipher, |
| 140 | const unsigned char *key, |
Manuel Pégourié-Gonnard | b8186a5 | 2015-06-18 14:58:58 +0200 | [diff] [blame] | 141 | unsigned int keybits ); |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 142 | |
| 143 | /** |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 144 | * \brief This function releases and clears the specified CCM context |
| 145 | * and underlying cipher sub-context. |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 146 | * |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 147 | * \param ctx The CCM context to clear. |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 148 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 149 | void mbedtls_ccm_free( mbedtls_ccm_context *ctx ); |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 150 | |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 151 | /** |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 152 | * \brief This function encrypts a buffer using CCM. |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 153 | * |
Rose Zadik | 4ee9d24 | 2018-03-26 17:18:44 +0100 | [diff] [blame] | 154 | * \note The tag is written to a separate buffer. To concatenate |
| 155 | * the \p tag with the \p output, as done in <em>RFC-3610: |
| 156 | * Counter with CBC-MAC (CCM)</em>, use |
| 157 | * \p tag = \p output + \p length, and make sure that the |
| 158 | * output buffer is at least \p length + \p tag_len wide. |
| 159 | * |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 160 | * \param ctx The CCM context to use for encryption. |
| 161 | * \param length The length of the input data in Bytes. |
| 162 | * \param iv Initialization vector (nonce). |
| 163 | * \param iv_len The length of the IV in Bytes: 7, 8, 9, 10, 11, 12, or 13. |
| 164 | * \param add The additional data field. |
| 165 | * \param add_len The length of additional data in Bytes. |
| 166 | * Must be less than 2^16 - 2^8. |
| 167 | * \param input The buffer holding the input data. |
| 168 | * \param output The buffer holding the output data. |
| 169 | * Must be at least \p length Bytes wide. |
| 170 | * \param tag The buffer holding the tag. |
| 171 | * \param tag_len The length of the tag to generate in Bytes: |
Mathieu Briand | ffb6efd | 2018-02-07 10:29:27 +0100 | [diff] [blame] | 172 | * 4, 6, 8, 10, 12, 14 or 16. |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 173 | * |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 174 | * \return \c 0 on success. |
Rose Zadik | ef87179 | 2018-04-17 10:41:48 +0100 | [diff] [blame] | 175 | * \return A CCM or cipher-specific error code on failure. |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 176 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 177 | int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length, |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 178 | const unsigned char *iv, size_t iv_len, |
| 179 | const unsigned char *add, size_t add_len, |
| 180 | const unsigned char *input, unsigned char *output, |
| 181 | unsigned char *tag, size_t tag_len ); |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 182 | |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 183 | /** |
Janos Follath | f60c815 | 2018-04-27 14:45:49 +0100 | [diff] [blame] | 184 | * \brief This function encrypts a buffer using CCM* with fixed tag |
| 185 | * length. |
| 186 | * |
| 187 | * \note The tag is written to a separate buffer. To concatenate |
| 188 | * the \p tag with the \p output, as done in <em>RFC-3610: |
| 189 | * Counter with CBC-MAC (CCM)</em>, use |
| 190 | * \p tag = \p output + \p length, and make sure that the |
| 191 | * output buffer is at least \p length + \p tag_len wide. |
| 192 | * |
| 193 | * \param ctx The CCM context to use for encryption. |
| 194 | * \param length The length of the input data in Bytes. |
| 195 | * \param iv Initialization vector (nonce). |
| 196 | * \param iv_len The length of the IV in Bytes: 7, 8, 9, 10, 11, 12, or 13. |
| 197 | * \param add The additional data field. |
| 198 | * \param add_len The length of additional data in Bytes. |
| 199 | * Must be less than 2^16 - 2^8. |
| 200 | * \param input The buffer holding the input data. |
| 201 | * \param output The buffer holding the output data. |
| 202 | * Must be at least \p length Bytes wide. |
| 203 | * \param tag The buffer holding the tag. |
| 204 | * \param tag_len The length of the tag to generate in Bytes: |
| 205 | * 0, 4, 6, 8, 10, 12, 14 or 16. |
| 206 | * |
| 207 | * \warning Passing 0 as \p tag_len means that the message is no |
| 208 | * longer authenticated. |
| 209 | * |
| 210 | * \return \c 0 on success. |
| 211 | * \return A CCM or cipher-specific error code on failure. |
| 212 | */ |
| 213 | int mbedtls_ccm_sfix_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length, |
| 214 | const unsigned char *iv, size_t iv_len, |
| 215 | const unsigned char *add, size_t add_len, |
| 216 | const unsigned char *input, unsigned char *output, |
| 217 | unsigned char *tag, size_t tag_len ); |
| 218 | |
| 219 | /** |
| 220 | * \brief This function encrypts a buffer using CCM* with variable |
| 221 | * tag length. |
| 222 | * |
| 223 | * \note The tag is written to a separate buffer. To concatenate |
| 224 | * the \p tag with the \p output, as done in <em>RFC-3610: |
| 225 | * Counter with CBC-MAC (CCM)</em>, use |
| 226 | * \p tag = \p output + \p length, and make sure that the |
| 227 | * output buffer is at least \p length + \p tag_len wide. |
| 228 | * |
| 229 | * \param ctx The CCM context to use for encryption. |
| 230 | * \param length The length of the input data in Bytes. |
| 231 | * \param iv_len The length of the IV in Bytes: 7, 8, 9, 10, 11, 12, |
| 232 | * or 13. |
| 233 | * \param add The additional data field. |
| 234 | * \param add_len The length of additional data in Bytes. |
| 235 | * Must be less than 2^16 - 2^8. |
| 236 | * \param input The buffer holding the input data. |
| 237 | * \param output The buffer holding the output data. |
| 238 | * Must be at least \p length Bytes wide. |
| 239 | * \param tag The buffer holding the tag. |
| 240 | * \param tag_len The length of the tag to generate in Bytes: |
| 241 | * 0, 4, 6, 8, 10, 12, 14 or 16. |
| 242 | * \param get_iv A callback function returning the IV (nonce) with the |
| 243 | * tag length encoded in it. |
| 244 | * \param get_iv_ctx Context passed to the \p get_iv callback. |
| 245 | * |
| 246 | * \warning Passing 0 as \p tag_len means that the message is no |
| 247 | * longer authenticated. |
| 248 | * |
| 249 | * \return \c 0 on success. |
| 250 | * \return A CCM or cipher-specific error code on failure. |
| 251 | */ |
| 252 | int mbedtls_ccm_svar_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length, |
| 253 | size_t iv_len, const unsigned char *add, |
| 254 | size_t add_len, const unsigned char *input, |
| 255 | unsigned char *output, unsigned char *tag, |
| 256 | size_t tag_len, mbedtls_ccm_star_get_nonce_t get_iv, |
| 257 | void *get_iv_ctx ); |
| 258 | |
| 259 | /** |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 260 | * \brief This function performs a CCM authenticated decryption of a |
| 261 | * buffer. |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 262 | * |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 263 | * \param ctx The CCM context to use for decryption. |
| 264 | * \param length The length of the input data in Bytes. |
| 265 | * \param iv Initialization vector. |
| 266 | * \param iv_len The length of the IV in Bytes: 7, 8, 9, 10, 11, 12, or 13. |
| 267 | * \param add The additional data field. |
| 268 | * \param add_len The length of additional data in Bytes. |
Mathieu Briand | ffb6efd | 2018-02-07 10:29:27 +0100 | [diff] [blame] | 269 | * Must be less than 2^16 - 2^8. |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 270 | * \param input The buffer holding the input data. |
| 271 | * \param output The buffer holding the output data. |
Mathieu Briand | ffb6efd | 2018-02-07 10:29:27 +0100 | [diff] [blame] | 272 | * Must be at least \p length Bytes wide. |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 273 | * \param tag The buffer holding the tag. |
| 274 | * \param tag_len The length of the tag in Bytes. |
Mathieu Briand | ffb6efd | 2018-02-07 10:29:27 +0100 | [diff] [blame] | 275 | * 4, 6, 8, 10, 12, 14 or 16. |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 276 | * |
Rose Zadik | 379b95c | 2018-04-17 16:43:00 +0100 | [diff] [blame] | 277 | * \return \c 0 on success. This indicates that the message is authentic. |
| 278 | * \return #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match. |
| 279 | * \return A cipher-specific error code on calculation failure. |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 280 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 281 | int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length, |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 282 | const unsigned char *iv, size_t iv_len, |
| 283 | const unsigned char *add, size_t add_len, |
| 284 | const unsigned char *input, unsigned char *output, |
| 285 | const unsigned char *tag, size_t tag_len ); |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 286 | |
Janos Follath | f60c815 | 2018-04-27 14:45:49 +0100 | [diff] [blame] | 287 | /** |
| 288 | * \brief This function performs a CCM* authenticated decryption of a |
| 289 | * buffer with fixed tag length. |
| 290 | * |
| 291 | * \param ctx The CCM context to use for decryption. |
| 292 | * \param length The length of the input data in Bytes. |
| 293 | * \param iv Initialization vector. |
| 294 | * \param iv_len The length of the IV in Bytes: 7, 8, 9, 10, 11, 12, or 13. |
| 295 | * \param add The additional data field. |
| 296 | * \param add_len The length of additional data in Bytes. |
| 297 | * Must be less than 2^16 - 2^8. |
| 298 | * \param input The buffer holding the input data. |
| 299 | * \param output The buffer holding the output data. |
| 300 | * Must be at least \p length Bytes wide. |
| 301 | * \param tag The buffer holding the tag. |
| 302 | * \param tag_len The length of the tag in Bytes. |
| 303 | * 0, 4, 6, 8, 10, 12, 14 or 16. |
| 304 | * |
| 305 | * \warning Passing 0 as \p tag_len means that the message is no |
| 306 | * longer authenticated. |
| 307 | * |
| 308 | * \return \c 0 on success. This indicates that the message is |
| 309 | * authentic. |
| 310 | * \return #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match. |
| 311 | * \return A cipher-specific error code on calculation failure. |
| 312 | */ |
| 313 | int mbedtls_ccm_sfix_auth_decrypt( mbedtls_ccm_context *ctx, size_t length, |
| 314 | const unsigned char *iv, size_t iv_len, |
| 315 | const unsigned char *add, size_t add_len, |
| 316 | const unsigned char *input, unsigned char *output, |
| 317 | const unsigned char *tag, size_t tag_len ); |
| 318 | |
| 319 | /** |
| 320 | * \brief This function performs a CCM* authenticated decryption |
| 321 | * of a buffer with variable tag length. |
| 322 | * |
| 323 | * \param ctx The CCM context to use for decryption. |
| 324 | * \param length The length of the input data in Bytes. |
| 325 | * \param iv Initialization vector. |
| 326 | * \param iv_len The length of the IV in Bytes: 7, 8, 9, 10, 11, 12, |
| 327 | * or 13. |
| 328 | * \param add The additional data field. |
| 329 | * \param add_len The length of additional data in Bytes. |
| 330 | * Must be less than 2^16 - 2^8. |
| 331 | * \param input The buffer holding the input data. Unlike the \p input |
| 332 | * parameters of other Mbed TLS CCM functions, this buffer |
| 333 | * holds the concatenation of the encrypted data and the |
| 334 | * authentication tag. |
| 335 | * \param output The buffer holding the output data. |
| 336 | * Must be at least \p length Bytes wide. |
| 337 | * \param output_len The length of the decrypted data. |
| 338 | * \param get_tag_len A callback function returning the tag length. |
| 339 | * \param get_tlen_ctx Context passed to the \p get_tag_len callback. |
| 340 | * |
| 341 | * |
| 342 | * \return \c 0 on success. This indicates that the message is |
| 343 | * authentic. |
| 344 | * \return #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match. |
| 345 | * \return A cipher-specific error code on calculation failure. |
| 346 | */ |
| 347 | int mbedtls_ccm_svar_auth_decrypt( mbedtls_ccm_context *ctx, size_t length, |
| 348 | const unsigned char *iv, size_t iv_len, |
| 349 | const unsigned char *add, size_t add_len, |
| 350 | const unsigned char *input, unsigned char *output, |
| 351 | size_t* output_len, |
| 352 | mbedtls_ccm_star_get_tag_len_t get_tag_len, |
| 353 | void *get_tlen_ctx ); |
| 354 | |
Steven Cooreman | 222e2ff | 2017-04-04 11:37:15 +0200 | [diff] [blame] | 355 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 356 | #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C) |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 357 | /** |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 358 | * \brief The CCM checkup routine. |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 359 | * |
Rose Zadik | 4ee9d24 | 2018-03-26 17:18:44 +0100 | [diff] [blame] | 360 | * \return \c 0 on success. |
| 361 | * \return \c 1 on failure. |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 362 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 363 | int mbedtls_ccm_self_test( int verbose ); |
| 364 | #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */ |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 365 | |
| 366 | #ifdef __cplusplus |
| 367 | } |
| 368 | #endif |
| 369 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 370 | #endif /* MBEDTLS_CCM_H */ |