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 | * |
Janos Follath | 6b4bd3d | 2018-05-29 11:30:26 +0100 | [diff] [blame] | 17 | * Definition of CCM: |
| 18 | * http://csrc.nist.gov/publications/nistpubs/800-38C/SP800-38C_updated-July20_2007.pdf |
| 19 | * RFC 3610 "Counter with CBC-MAC (CCM)" |
| 20 | * |
| 21 | * Related: |
| 22 | * RFC 5116 "An Interface and Algorithms for Authenticated Encryption" |
| 23 | * |
| 24 | * Definition of CCM*: |
| 25 | * IEEE 802.15.4 - IEEE Standard for Local and metropolitan area networks |
| 26 | * Integer representation is fixed most-significant-octet-first order and |
| 27 | * the representation of octets is most-significant-bit-first order. This is |
| 28 | * consistent with RFC 3610. |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 29 | */ |
| 30 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 31 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 7ff7965 | 2023-11-03 12:04:52 +0000 | [diff] [blame] | 32 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
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 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 35 | #ifndef MBEDTLS_CCM_H |
| 36 | #define MBEDTLS_CCM_H |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 37 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 38 | #if !defined(MBEDTLS_CONFIG_FILE) |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 39 | #include "mbedtls/config.h" |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 40 | #else |
| 41 | #include MBEDTLS_CONFIG_FILE |
| 42 | #endif |
| 43 | |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 44 | #include "mbedtls/cipher.h" |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 45 | |
Gilles Peskine | a397443 | 2021-07-26 18:48:10 +0200 | [diff] [blame] | 46 | /** Bad input parameters to the function. */ |
| 47 | #define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D |
| 48 | /** Authenticated decryption failed. */ |
| 49 | #define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F |
Ron Eldor | 9924bdc | 2018-10-04 10:59:13 +0300 | [diff] [blame] | 50 | |
| 51 | /* MBEDTLS_ERR_CCM_HW_ACCEL_FAILED is deprecated and should not be used. */ |
Gilles Peskine | a397443 | 2021-07-26 18:48:10 +0200 | [diff] [blame] | 52 | /** CCM hardware accelerator failed. */ |
| 53 | #define MBEDTLS_ERR_CCM_HW_ACCEL_FAILED -0x0011 |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 54 | |
| 55 | #ifdef __cplusplus |
| 56 | extern "C" { |
| 57 | #endif |
| 58 | |
Ron Eldor | 4e6d55d | 2018-02-07 16:36:15 +0200 | [diff] [blame] | 59 | #if !defined(MBEDTLS_CCM_ALT) |
| 60 | // Regular implementation |
| 61 | // |
| 62 | |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 63 | /** |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 64 | * \brief The CCM context-type definition. The CCM context is passed |
| 65 | * to the APIs called. |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 66 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 67 | typedef struct mbedtls_ccm_context { |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 68 | mbedtls_cipher_context_t cipher_ctx; /*!< The cipher context used. */ |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 69 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 70 | mbedtls_ccm_context; |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 71 | |
Ron Eldor | 4e6d55d | 2018-02-07 16:36:15 +0200 | [diff] [blame] | 72 | #else /* MBEDTLS_CCM_ALT */ |
| 73 | #include "ccm_alt.h" |
| 74 | #endif /* MBEDTLS_CCM_ALT */ |
| 75 | |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 76 | /** |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 77 | * \brief This function initializes the specified CCM context, |
| 78 | * to make references valid, and prepare the context |
| 79 | * for mbedtls_ccm_setkey() or mbedtls_ccm_free(). |
Manuel Pégourié-Gonnard | 6963ff0 | 2015-04-28 18:02:54 +0200 | [diff] [blame] | 80 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 81 | * \param ctx The CCM context to initialize. This must not be \c NULL. |
Manuel Pégourié-Gonnard | 6963ff0 | 2015-04-28 18:02:54 +0200 | [diff] [blame] | 82 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 83 | void mbedtls_ccm_init(mbedtls_ccm_context *ctx); |
Manuel Pégourié-Gonnard | 6963ff0 | 2015-04-28 18:02:54 +0200 | [diff] [blame] | 84 | |
| 85 | /** |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 86 | * \brief This function initializes the CCM context set in the |
| 87 | * \p ctx parameter and sets the encryption key. |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 88 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 89 | * \param ctx The CCM context to initialize. This must be an initialized |
| 90 | * context. |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 91 | * \param cipher The 128-bit block cipher to use. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 92 | * \param key The encryption key. This must not be \c NULL. |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 93 | * \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] | 94 | * |
Rose Zadik | 4ee9d24 | 2018-03-26 17:18:44 +0100 | [diff] [blame] | 95 | * \return \c 0 on success. |
Rose Zadik | ef87179 | 2018-04-17 10:41:48 +0100 | [diff] [blame] | 96 | * \return A CCM or cipher-specific error code on failure. |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 97 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 98 | int mbedtls_ccm_setkey(mbedtls_ccm_context *ctx, |
| 99 | mbedtls_cipher_id_t cipher, |
| 100 | const unsigned char *key, |
| 101 | unsigned int keybits); |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 102 | |
| 103 | /** |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 104 | * \brief This function releases and clears the specified CCM context |
| 105 | * and underlying cipher sub-context. |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 106 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 107 | * \param ctx The CCM context to clear. If this is \c NULL, the function |
| 108 | * has no effect. Otherwise, this must be initialized. |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 109 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 110 | void mbedtls_ccm_free(mbedtls_ccm_context *ctx); |
Manuel Pégourié-Gonnard | 9fe0d13 | 2014-05-06 12:12:45 +0200 | [diff] [blame] | 111 | |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 112 | /** |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 113 | * \brief This function encrypts a buffer using CCM. |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 114 | * |
Rose Zadik | 4ee9d24 | 2018-03-26 17:18:44 +0100 | [diff] [blame] | 115 | * \note The tag is written to a separate buffer. To concatenate |
| 116 | * the \p tag with the \p output, as done in <em>RFC-3610: |
| 117 | * Counter with CBC-MAC (CCM)</em>, use |
| 118 | * \p tag = \p output + \p length, and make sure that the |
| 119 | * output buffer is at least \p length + \p tag_len wide. |
| 120 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 121 | * \param ctx The CCM context to use for encryption. This must be |
| 122 | * initialized and bound to a key. |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 123 | * \param length The length of the input data in Bytes. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 124 | * \param iv The initialization vector (nonce). This must be a readable |
| 125 | * buffer of at least \p iv_len Bytes. |
Janos Follath | 6b4bd3d | 2018-05-29 11:30:26 +0100 | [diff] [blame] | 126 | * \param iv_len The length of the nonce in Bytes: 7, 8, 9, 10, 11, 12, |
| 127 | * or 13. The length L of the message length field is |
| 128 | * 15 - \p iv_len. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 129 | * \param add The additional data field. If \p add_len is greater than |
| 130 | * zero, \p add must be a readable buffer of at least that |
| 131 | * length. |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 132 | * \param add_len The length of additional data in Bytes. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 133 | * This must be less than `2^16 - 2^8`. |
| 134 | * \param input The buffer holding the input data. If \p length is greater |
| 135 | * than zero, \p input must be a readable buffer of at least |
| 136 | * that length. |
| 137 | * \param output The buffer holding the output data. If \p length is greater |
| 138 | * than zero, \p output must be a writable buffer of at least |
| 139 | * that length. |
| 140 | * \param tag The buffer holding the authentication field. This must be a |
Yonatan Goldschmidt | 6e2af09 | 2020-09-12 00:19:52 +0300 | [diff] [blame] | 141 | * writable buffer of at least \p tag_len Bytes. |
Janos Follath | 6b4bd3d | 2018-05-29 11:30:26 +0100 | [diff] [blame] | 142 | * \param tag_len The length of the authentication field to generate in Bytes: |
Mathieu Briand | ffb6efd | 2018-02-07 10:29:27 +0100 | [diff] [blame] | 143 | * 4, 6, 8, 10, 12, 14 or 16. |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 144 | * |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 145 | * \return \c 0 on success. |
Rose Zadik | ef87179 | 2018-04-17 10:41:48 +0100 | [diff] [blame] | 146 | * \return A CCM or cipher-specific error code on failure. |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 147 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 148 | int mbedtls_ccm_encrypt_and_tag(mbedtls_ccm_context *ctx, size_t length, |
| 149 | const unsigned char *iv, size_t iv_len, |
| 150 | const unsigned char *add, size_t add_len, |
| 151 | const unsigned char *input, unsigned char *output, |
| 152 | unsigned char *tag, size_t tag_len); |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 153 | |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 154 | /** |
Janos Follath | 5dc8cfa | 2018-04-27 14:45:49 +0100 | [diff] [blame] | 155 | * \brief This function encrypts a buffer using CCM*. |
| 156 | * |
| 157 | * \note The tag is written to a separate buffer. To concatenate |
| 158 | * the \p tag with the \p output, as done in <em>RFC-3610: |
| 159 | * Counter with CBC-MAC (CCM)</em>, use |
| 160 | * \p tag = \p output + \p length, and make sure that the |
| 161 | * output buffer is at least \p length + \p tag_len wide. |
| 162 | * |
| 163 | * \note When using this function in a variable tag length context, |
| 164 | * the tag length has to be encoded into the \p iv passed to |
| 165 | * this function. |
| 166 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 167 | * \param ctx The CCM context to use for encryption. This must be |
| 168 | * initialized and bound to a key. |
Janos Follath | 5dc8cfa | 2018-04-27 14:45:49 +0100 | [diff] [blame] | 169 | * \param length The length of the input data in Bytes. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 170 | * \param iv The initialization vector (nonce). This must be a readable |
| 171 | * buffer of at least \p iv_len Bytes. |
Janos Follath | 6b4bd3d | 2018-05-29 11:30:26 +0100 | [diff] [blame] | 172 | * \param iv_len The length of the nonce in Bytes: 7, 8, 9, 10, 11, 12, |
| 173 | * or 13. The length L of the message length field is |
| 174 | * 15 - \p iv_len. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 175 | * \param add The additional data field. This must be a readable buffer of |
| 176 | * at least \p add_len Bytes. |
Janos Follath | 5dc8cfa | 2018-04-27 14:45:49 +0100 | [diff] [blame] | 177 | * \param add_len The length of additional data in Bytes. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 178 | * This must be less than 2^16 - 2^8. |
| 179 | * \param input The buffer holding the input data. If \p length is greater |
| 180 | * than zero, \p input must be a readable buffer of at least |
| 181 | * that length. |
| 182 | * \param output The buffer holding the output data. If \p length is greater |
| 183 | * than zero, \p output must be a writable buffer of at least |
| 184 | * that length. |
| 185 | * \param tag The buffer holding the authentication field. This must be a |
Yonatan Goldschmidt | 6e2af09 | 2020-09-12 00:19:52 +0300 | [diff] [blame] | 186 | * writable buffer of at least \p tag_len Bytes. |
Janos Follath | 6b4bd3d | 2018-05-29 11:30:26 +0100 | [diff] [blame] | 187 | * \param tag_len The length of the authentication field to generate in Bytes: |
Janos Follath | 5dc8cfa | 2018-04-27 14:45:49 +0100 | [diff] [blame] | 188 | * 0, 4, 6, 8, 10, 12, 14 or 16. |
| 189 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 190 | * \warning Passing \c 0 as \p tag_len means that the message is no |
Janos Follath | 5dc8cfa | 2018-04-27 14:45:49 +0100 | [diff] [blame] | 191 | * longer authenticated. |
| 192 | * |
| 193 | * \return \c 0 on success. |
| 194 | * \return A CCM or cipher-specific error code on failure. |
| 195 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 196 | int mbedtls_ccm_star_encrypt_and_tag(mbedtls_ccm_context *ctx, size_t length, |
| 197 | const unsigned char *iv, size_t iv_len, |
| 198 | const unsigned char *add, size_t add_len, |
| 199 | const unsigned char *input, unsigned char *output, |
| 200 | unsigned char *tag, size_t tag_len); |
Janos Follath | 5dc8cfa | 2018-04-27 14:45:49 +0100 | [diff] [blame] | 201 | |
| 202 | /** |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 203 | * \brief This function performs a CCM authenticated decryption of a |
| 204 | * buffer. |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 205 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 206 | * \param ctx The CCM context to use for decryption. This must be |
| 207 | * initialized and bound to a key. |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 208 | * \param length The length of the input data in Bytes. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 209 | * \param iv The initialization vector (nonce). This must be a readable |
| 210 | * buffer of at least \p iv_len Bytes. |
Janos Follath | 6b4bd3d | 2018-05-29 11:30:26 +0100 | [diff] [blame] | 211 | * \param iv_len The length of the nonce in Bytes: 7, 8, 9, 10, 11, 12, |
| 212 | * or 13. The length L of the message length field is |
| 213 | * 15 - \p iv_len. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 214 | * \param add The additional data field. This must be a readable buffer |
| 215 | * of at least that \p add_len Bytes.. |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 216 | * \param add_len The length of additional data in Bytes. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 217 | * This must be less than 2^16 - 2^8. |
| 218 | * \param input The buffer holding the input data. If \p length is greater |
| 219 | * than zero, \p input must be a readable buffer of at least |
| 220 | * that length. |
| 221 | * \param output The buffer holding the output data. If \p length is greater |
| 222 | * than zero, \p output must be a writable buffer of at least |
| 223 | * that length. |
| 224 | * \param tag The buffer holding the authentication field. This must be a |
| 225 | * readable buffer of at least \p tag_len Bytes. |
| 226 | * \param tag_len The length of the authentication field to generate in Bytes: |
Mathieu Briand | ffb6efd | 2018-02-07 10:29:27 +0100 | [diff] [blame] | 227 | * 4, 6, 8, 10, 12, 14 or 16. |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 228 | * |
Rose Zadik | 379b95c | 2018-04-17 16:43:00 +0100 | [diff] [blame] | 229 | * \return \c 0 on success. This indicates that the message is authentic. |
| 230 | * \return #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match. |
| 231 | * \return A cipher-specific error code on calculation failure. |
Manuel Pégourié-Gonnard | 0023233 | 2014-05-06 15:56:07 +0200 | [diff] [blame] | 232 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 233 | int mbedtls_ccm_auth_decrypt(mbedtls_ccm_context *ctx, size_t length, |
| 234 | const unsigned char *iv, size_t iv_len, |
| 235 | const unsigned char *add, size_t add_len, |
| 236 | const unsigned char *input, unsigned char *output, |
| 237 | const unsigned char *tag, size_t tag_len); |
Manuel Pégourié-Gonnard | 637eb3d | 2014-05-06 12:13:09 +0200 | [diff] [blame] | 238 | |
Janos Follath | 5dc8cfa | 2018-04-27 14:45:49 +0100 | [diff] [blame] | 239 | /** |
| 240 | * \brief This function performs a CCM* authenticated decryption of a |
| 241 | * buffer. |
| 242 | * |
| 243 | * \note When using this function in a variable tag length context, |
| 244 | * the tag length has to be decoded from \p iv and passed to |
| 245 | * this function as \p tag_len. (\p tag needs to be adjusted |
| 246 | * accordingly.) |
| 247 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 248 | * \param ctx The CCM context to use for decryption. This must be |
| 249 | * initialized and bound to a key. |
Janos Follath | 5dc8cfa | 2018-04-27 14:45:49 +0100 | [diff] [blame] | 250 | * \param length The length of the input data in Bytes. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 251 | * \param iv The initialization vector (nonce). This must be a readable |
| 252 | * buffer of at least \p iv_len Bytes. |
Janos Follath | 6b4bd3d | 2018-05-29 11:30:26 +0100 | [diff] [blame] | 253 | * \param iv_len The length of the nonce in Bytes: 7, 8, 9, 10, 11, 12, |
| 254 | * or 13. The length L of the message length field is |
| 255 | * 15 - \p iv_len. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 256 | * \param add The additional data field. This must be a readable buffer of |
| 257 | * at least that \p add_len Bytes. |
Janos Follath | 5dc8cfa | 2018-04-27 14:45:49 +0100 | [diff] [blame] | 258 | * \param add_len The length of additional data in Bytes. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 259 | * This must be less than 2^16 - 2^8. |
| 260 | * \param input The buffer holding the input data. If \p length is greater |
| 261 | * than zero, \p input must be a readable buffer of at least |
| 262 | * that length. |
| 263 | * \param output The buffer holding the output data. If \p length is greater |
| 264 | * than zero, \p output must be a writable buffer of at least |
| 265 | * that length. |
| 266 | * \param tag The buffer holding the authentication field. This must be a |
| 267 | * readable buffer of at least \p tag_len Bytes. |
Janos Follath | 6b4bd3d | 2018-05-29 11:30:26 +0100 | [diff] [blame] | 268 | * \param tag_len The length of the authentication field in Bytes. |
Janos Follath | 5dc8cfa | 2018-04-27 14:45:49 +0100 | [diff] [blame] | 269 | * 0, 4, 6, 8, 10, 12, 14 or 16. |
| 270 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 271 | * \warning Passing \c 0 as \p tag_len means that the message is nos |
Janos Follath | 5dc8cfa | 2018-04-27 14:45:49 +0100 | [diff] [blame] | 272 | * longer authenticated. |
| 273 | * |
Janos Follath | 143b319 | 2018-05-30 13:57:29 +0100 | [diff] [blame] | 274 | * \return \c 0 on success. |
Janos Follath | 5dc8cfa | 2018-04-27 14:45:49 +0100 | [diff] [blame] | 275 | * \return #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match. |
| 276 | * \return A cipher-specific error code on calculation failure. |
| 277 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 278 | int mbedtls_ccm_star_auth_decrypt(mbedtls_ccm_context *ctx, size_t length, |
| 279 | const unsigned char *iv, size_t iv_len, |
| 280 | const unsigned char *add, size_t add_len, |
| 281 | const unsigned char *input, unsigned char *output, |
| 282 | const unsigned char *tag, size_t tag_len); |
Steven Cooreman | 222e2ff | 2017-04-04 11:37:15 +0200 | [diff] [blame] | 283 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 284 | #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C) |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 285 | /** |
Rose Zadik | eecdbea | 2018-01-24 12:56:53 +0000 | [diff] [blame] | 286 | * \brief The CCM checkup routine. |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 287 | * |
Rose Zadik | 4ee9d24 | 2018-03-26 17:18:44 +0100 | [diff] [blame] | 288 | * \return \c 0 on success. |
| 289 | * \return \c 1 on failure. |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 290 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 291 | int mbedtls_ccm_self_test(int verbose); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 292 | #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */ |
Manuel Pégourié-Gonnard | a6916fa | 2014-05-02 15:17:29 +0200 | [diff] [blame] | 293 | |
| 294 | #ifdef __cplusplus |
| 295 | } |
| 296 | #endif |
| 297 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 298 | #endif /* MBEDTLS_CCM_H */ |