Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file gcm.h |
| 3 | * |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 4 | * \brief Galois/Counter Mode (GCM) for 128-bit block ciphers, as defined |
| 5 | * in <em>D. McGrew, J. Viega, The Galois/Counter Mode of Operation |
| 6 | * (GCM), Natl. Inst. Stand. Technol.</em> |
| 7 | * |
| 8 | * For more information on GCM, see <em>NIST SP 800-38D: Recommendation for |
| 9 | * Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC</em>. |
| 10 | * |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 11 | */ |
| 12 | /* |
Bence Szépkúti | 44bfbe3 | 2020-08-19 16:54:51 +0200 | [diff] [blame] | 13 | * Copyright The Mbed TLS Contributors |
Bence Szépkúti | 4e9f712 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 14 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 15 | * |
| 16 | * This file is provided under the Apache License 2.0, or the |
| 17 | * GNU General Public License v2.0 or later. |
| 18 | * |
| 19 | * ********** |
| 20 | * Apache License 2.0: |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 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. |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 33 | * |
Bence Szépkúti | 4e9f712 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 34 | * ********** |
| 35 | * |
| 36 | * ********** |
| 37 | * GNU General Public License v2.0 or later: |
| 38 | * |
| 39 | * This program is free software; you can redistribute it and/or modify |
| 40 | * it under the terms of the GNU General Public License as published by |
| 41 | * the Free Software Foundation; either version 2 of the License, or |
| 42 | * (at your option) any later version. |
| 43 | * |
| 44 | * This program is distributed in the hope that it will be useful, |
| 45 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 46 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 47 | * GNU General Public License for more details. |
| 48 | * |
| 49 | * You should have received a copy of the GNU General Public License along |
| 50 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 51 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 52 | * |
| 53 | * ********** |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 54 | */ |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 55 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 56 | #ifndef MBEDTLS_GCM_H |
| 57 | #define MBEDTLS_GCM_H |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 58 | |
Ron Eldor | 0559c66 | 2018-02-14 16:02:41 +0200 | [diff] [blame] | 59 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 60 | #include "config.h" |
| 61 | #else |
| 62 | #include MBEDTLS_CONFIG_FILE |
| 63 | #endif |
| 64 | |
Paul Bakker | 43aff2a | 2013-09-09 00:10:27 +0200 | [diff] [blame] | 65 | #include "cipher.h" |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 66 | |
| 67 | #include <stdint.h> |
| 68 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 69 | #define MBEDTLS_GCM_ENCRYPT 1 |
| 70 | #define MBEDTLS_GCM_DECRYPT 0 |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 71 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 72 | #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012 /**< Authenticated decryption failed. */ |
Gilles Peskine | 7ecab3d | 2018-01-26 17:56:38 +0100 | [diff] [blame] | 73 | #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013 /**< GCM hardware accelerator failed. */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 74 | #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014 /**< Bad input parameters to function. */ |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 75 | |
Jaeden Amero | 1526330 | 2017-09-21 12:53:48 +0100 | [diff] [blame] | 76 | #if !defined(MBEDTLS_GCM_ALT) |
| 77 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 78 | #ifdef __cplusplus |
| 79 | extern "C" { |
| 80 | #endif |
| 81 | |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 82 | /** |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 83 | * \brief The GCM context structure. |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 84 | */ |
| 85 | typedef struct { |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 86 | mbedtls_cipher_context_t cipher_ctx; /*!< The cipher context used. */ |
| 87 | uint64_t HL[16]; /*!< Precalculated HTable low. */ |
| 88 | uint64_t HH[16]; /*!< Precalculated HTable high. */ |
| 89 | uint64_t len; /*!< The total length of the encrypted data. */ |
| 90 | uint64_t add_len; /*!< The total length of the additional data. */ |
| 91 | unsigned char base_ectr[16]; /*!< The first ECTR for tag. */ |
| 92 | unsigned char y[16]; /*!< The Y working value. */ |
| 93 | unsigned char buf[16]; /*!< The buf working value. */ |
| 94 | int mode; /*!< The operation to perform: |
| 95 | #MBEDTLS_GCM_ENCRYPT or |
| 96 | #MBEDTLS_GCM_DECRYPT. */ |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 97 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 98 | mbedtls_gcm_context; |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 99 | |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 100 | /** |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 101 | * \brief This function initializes the specified GCM context, |
| 102 | * to make references valid, and prepares the context |
| 103 | * for mbedtls_gcm_setkey() or mbedtls_gcm_free(). |
Manuel Pégourié-Gonnard | c34e8dd | 2015-04-28 21:42:17 +0200 | [diff] [blame] | 104 | * |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 105 | * The function does not bind the GCM context to a particular |
| 106 | * cipher, nor set the key. For this purpose, use |
| 107 | * mbedtls_gcm_setkey(). |
| 108 | * |
| 109 | * \param ctx The GCM context to initialize. |
Manuel Pégourié-Gonnard | c34e8dd | 2015-04-28 21:42:17 +0200 | [diff] [blame] | 110 | */ |
| 111 | void mbedtls_gcm_init( mbedtls_gcm_context *ctx ); |
| 112 | |
| 113 | /** |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 114 | * \brief This function associates a GCM context with a |
| 115 | * cipher algorithm and a key. |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 116 | * |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 117 | * \param ctx The GCM context to initialize. |
| 118 | * \param cipher The 128-bit block cipher to use. |
| 119 | * \param key The encryption key. |
| 120 | * \param keybits The key size in bits. Valid options are: |
| 121 | * <ul><li>128 bits</li> |
| 122 | * <li>192 bits</li> |
| 123 | * <li>256 bits</li></ul> |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 124 | * |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 125 | * \return \c 0 on success, or a cipher specific error code. |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 126 | */ |
Manuel Pégourié-Gonnard | c34e8dd | 2015-04-28 21:42:17 +0200 | [diff] [blame] | 127 | int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx, |
| 128 | mbedtls_cipher_id_t cipher, |
| 129 | const unsigned char *key, |
Manuel Pégourié-Gonnard | b8186a5 | 2015-06-18 14:58:58 +0200 | [diff] [blame] | 130 | unsigned int keybits ); |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 131 | |
| 132 | /** |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 133 | * \brief This function performs GCM encryption or decryption of a buffer. |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 134 | * |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 135 | * \note For encryption, the output buffer can be the same as the input buffer. |
| 136 | * For decryption, the output buffer cannot be the same as input buffer. |
| 137 | * If the buffers overlap, the output buffer must trail at least 8 Bytes |
Paul Bakker | ca4ab49 | 2012-04-18 14:23:57 +0000 | [diff] [blame] | 138 | * behind the input buffer. |
| 139 | * |
Gilles Peskine | 282bd24 | 2018-06-01 17:55:41 +0200 | [diff] [blame] | 140 | * \warning When this function performs a decryption, it outputs the |
| 141 | * authentication tag and does not verify that the data is |
| 142 | * authentic. You should use this function to perform encryption |
| 143 | * only. For decryption, use mbedtls_gcm_auth_decrypt() instead. |
| 144 | * |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 145 | * \param ctx The GCM context to use for encryption or decryption. |
Gilles Peskine | db37cb4 | 2018-06-07 14:46:02 +0200 | [diff] [blame] | 146 | * \param mode The operation to perform: |
| 147 | * - #MBEDTLS_GCM_ENCRYPT to perform authenticated encryption. |
| 148 | * The ciphertext is written to \p output and the |
| 149 | * authentication tag is written to \p tag. |
| 150 | * - #MBEDTLS_GCM_DECRYPT to perform decryption. |
| 151 | * The plaintext is written to \p output and the |
| 152 | * authentication tag is written to \p tag. |
| 153 | * Note that this mode is not recommended, because it does |
| 154 | * not verify the authenticity of the data. For this reason, |
| 155 | * you should use mbedtls_gcm_auth_decrypt() instead of |
| 156 | * calling this function in decryption mode. |
Gilles Peskine | 282bd24 | 2018-06-01 17:55:41 +0200 | [diff] [blame] | 157 | * \param length The length of the input data, which is equal to the length |
| 158 | * of the output data. |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 159 | * \param iv The initialization vector. |
| 160 | * \param iv_len The length of the IV. |
| 161 | * \param add The buffer holding the additional data. |
| 162 | * \param add_len The length of the additional data. |
Gilles Peskine | 282bd24 | 2018-06-01 17:55:41 +0200 | [diff] [blame] | 163 | * \param input The buffer holding the input data. Its size is \b length. |
| 164 | * \param output The buffer for holding the output data. It must have room |
| 165 | * for \b length bytes. |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 166 | * \param tag_len The length of the tag to generate. |
| 167 | * \param tag The buffer for holding the tag. |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 168 | * |
Gilles Peskine | 282bd24 | 2018-06-01 17:55:41 +0200 | [diff] [blame] | 169 | * \return \c 0 if the encryption or decryption was performed |
| 170 | * successfully. Note that in #MBEDTLS_GCM_DECRYPT mode, |
| 171 | * this does not indicate that the data is authentic. |
| 172 | * \return #MBEDTLS_ERR_GCM_BAD_INPUT if the lengths are not valid. |
| 173 | * \return #MBEDTLS_ERR_GCM_HW_ACCEL_FAILED or a cipher-specific |
| 174 | * error code if the encryption or decryption failed. |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 175 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 176 | int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx, |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 177 | int mode, |
| 178 | size_t length, |
| 179 | const unsigned char *iv, |
| 180 | size_t iv_len, |
| 181 | const unsigned char *add, |
| 182 | size_t add_len, |
| 183 | const unsigned char *input, |
| 184 | unsigned char *output, |
| 185 | size_t tag_len, |
| 186 | unsigned char *tag ); |
| 187 | |
| 188 | /** |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 189 | * \brief This function performs a GCM authenticated decryption of a |
| 190 | * buffer. |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 191 | * |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 192 | * \note For decryption, the output buffer cannot be the same as input buffer. |
| 193 | * If the buffers overlap, the output buffer must trail at least 8 Bytes |
Paul Bakker | ca4ab49 | 2012-04-18 14:23:57 +0000 | [diff] [blame] | 194 | * behind the input buffer. |
| 195 | * |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 196 | * \param ctx The GCM context. |
Gilles Peskine | 282bd24 | 2018-06-01 17:55:41 +0200 | [diff] [blame] | 197 | * \param length The length of the ciphertext to decrypt, which is also |
| 198 | * the length of the decrypted plaintext. |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 199 | * \param iv The initialization vector. |
| 200 | * \param iv_len The length of the IV. |
| 201 | * \param add The buffer holding the additional data. |
| 202 | * \param add_len The length of the additional data. |
Gilles Peskine | 282bd24 | 2018-06-01 17:55:41 +0200 | [diff] [blame] | 203 | * \param tag The buffer holding the tag to verify. |
| 204 | * \param tag_len The length of the tag to verify. |
| 205 | * \param input The buffer holding the ciphertext. Its size is \b length. |
| 206 | * \param output The buffer for holding the decrypted plaintext. It must |
| 207 | * have room for \b length bytes. |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 208 | * |
Gilles Peskine | 282bd24 | 2018-06-01 17:55:41 +0200 | [diff] [blame] | 209 | * \return \c 0 if successful and authenticated. |
| 210 | * \return #MBEDTLS_ERR_GCM_AUTH_FAILED if the tag does not match. |
| 211 | * \return #MBEDTLS_ERR_GCM_BAD_INPUT if the lengths are not valid. |
| 212 | * \return #MBEDTLS_ERR_GCM_HW_ACCEL_FAILED or a cipher-specific |
| 213 | * error code if the decryption failed. |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 214 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 215 | int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx, |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 216 | size_t length, |
| 217 | const unsigned char *iv, |
| 218 | size_t iv_len, |
| 219 | const unsigned char *add, |
| 220 | size_t add_len, |
Paul Bakker | b9d3cfa | 2013-06-26 15:07:16 +0200 | [diff] [blame] | 221 | const unsigned char *tag, |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 222 | size_t tag_len, |
| 223 | const unsigned char *input, |
| 224 | unsigned char *output ); |
| 225 | |
| 226 | /** |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 227 | * \brief This function starts a GCM encryption or decryption |
| 228 | * operation. |
Paul Bakker | b9d3cfa | 2013-06-26 15:07:16 +0200 | [diff] [blame] | 229 | * |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 230 | * \param ctx The GCM context. |
| 231 | * \param mode The operation to perform: #MBEDTLS_GCM_ENCRYPT or |
| 232 | * #MBEDTLS_GCM_DECRYPT. |
| 233 | * \param iv The initialization vector. |
| 234 | * \param iv_len The length of the IV. |
| 235 | * \param add The buffer holding the additional data, or NULL if \p add_len is 0. |
| 236 | * \param add_len The length of the additional data. If 0, \p add is NULL. |
Paul Bakker | b9d3cfa | 2013-06-26 15:07:16 +0200 | [diff] [blame] | 237 | * |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 238 | * \return \c 0 on success. |
Paul Bakker | b9d3cfa | 2013-06-26 15:07:16 +0200 | [diff] [blame] | 239 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 240 | int mbedtls_gcm_starts( mbedtls_gcm_context *ctx, |
Paul Bakker | b9d3cfa | 2013-06-26 15:07:16 +0200 | [diff] [blame] | 241 | int mode, |
| 242 | const unsigned char *iv, |
| 243 | size_t iv_len, |
| 244 | const unsigned char *add, |
| 245 | size_t add_len ); |
| 246 | |
| 247 | /** |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 248 | * \brief This function feeds an input buffer into an ongoing GCM |
| 249 | * encryption or decryption operation. |
Paul Bakker | b9d3cfa | 2013-06-26 15:07:16 +0200 | [diff] [blame] | 250 | * |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 251 | * ` The function expects input to be a multiple of 16 |
| 252 | * Bytes. Only the last call before calling |
| 253 | * mbedtls_gcm_finish() can be less than 16 Bytes. |
| 254 | * |
| 255 | * \note For decryption, the output buffer cannot be the same as input buffer. |
| 256 | * If the buffers overlap, the output buffer must trail at least 8 Bytes |
Paul Bakker | b9d3cfa | 2013-06-26 15:07:16 +0200 | [diff] [blame] | 257 | * behind the input buffer. |
| 258 | * |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 259 | * \param ctx The GCM context. |
| 260 | * \param length The length of the input data. This must be a multiple of 16 except in the last call before mbedtls_gcm_finish(). |
| 261 | * \param input The buffer holding the input data. |
| 262 | * \param output The buffer for holding the output data. |
Paul Bakker | b9d3cfa | 2013-06-26 15:07:16 +0200 | [diff] [blame] | 263 | * |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 264 | * \return \c 0 on success, or #MBEDTLS_ERR_GCM_BAD_INPUT on failure. |
Paul Bakker | b9d3cfa | 2013-06-26 15:07:16 +0200 | [diff] [blame] | 265 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 266 | int mbedtls_gcm_update( mbedtls_gcm_context *ctx, |
Paul Bakker | b9d3cfa | 2013-06-26 15:07:16 +0200 | [diff] [blame] | 267 | size_t length, |
| 268 | const unsigned char *input, |
| 269 | unsigned char *output ); |
| 270 | |
| 271 | /** |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 272 | * \brief This function finishes the GCM operation and generates |
| 273 | * the authentication tag. |
Paul Bakker | b9d3cfa | 2013-06-26 15:07:16 +0200 | [diff] [blame] | 274 | * |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 275 | * It wraps up the GCM stream, and generates the |
| 276 | * tag. The tag can have a maximum length of 16 Bytes. |
Paul Bakker | b9d3cfa | 2013-06-26 15:07:16 +0200 | [diff] [blame] | 277 | * |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 278 | * \param ctx The GCM context. |
| 279 | * \param tag The buffer for holding the tag. |
| 280 | * \param tag_len The length of the tag to generate. Must be at least four. |
| 281 | * |
| 282 | * \return \c 0 on success, or #MBEDTLS_ERR_GCM_BAD_INPUT on failure. |
Paul Bakker | b9d3cfa | 2013-06-26 15:07:16 +0200 | [diff] [blame] | 283 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 284 | int mbedtls_gcm_finish( mbedtls_gcm_context *ctx, |
Paul Bakker | b9d3cfa | 2013-06-26 15:07:16 +0200 | [diff] [blame] | 285 | unsigned char *tag, |
| 286 | size_t tag_len ); |
| 287 | |
| 288 | /** |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 289 | * \brief This function clears a GCM context and the underlying |
| 290 | * cipher sub-context. |
Manuel Pégourié-Gonnard | 4fe9200 | 2013-09-13 13:45:58 +0200 | [diff] [blame] | 291 | * |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 292 | * \param ctx The GCM context to clear. |
Manuel Pégourié-Gonnard | 4fe9200 | 2013-09-13 13:45:58 +0200 | [diff] [blame] | 293 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 294 | void mbedtls_gcm_free( mbedtls_gcm_context *ctx ); |
Manuel Pégourié-Gonnard | 4fe9200 | 2013-09-13 13:45:58 +0200 | [diff] [blame] | 295 | |
Jaeden Amero | 1526330 | 2017-09-21 12:53:48 +0100 | [diff] [blame] | 296 | #ifdef __cplusplus |
| 297 | } |
| 298 | #endif |
| 299 | |
| 300 | #else /* !MBEDTLS_GCM_ALT */ |
| 301 | #include "gcm_alt.h" |
| 302 | #endif /* !MBEDTLS_GCM_ALT */ |
| 303 | |
| 304 | #ifdef __cplusplus |
| 305 | extern "C" { |
| 306 | #endif |
| 307 | |
Manuel Pégourié-Gonnard | 4fe9200 | 2013-09-13 13:45:58 +0200 | [diff] [blame] | 308 | /** |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 309 | * \brief The GCM checkup routine. |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 310 | * |
Rose Zadik | 17b4f7f | 2018-01-26 10:56:42 +0000 | [diff] [blame] | 311 | * \return \c 0 on success, or \c 1 on failure. |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 312 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 313 | int mbedtls_gcm_self_test( int verbose ); |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 314 | |
| 315 | #ifdef __cplusplus |
| 316 | } |
| 317 | #endif |
| 318 | |
Jaeden Amero | 1526330 | 2017-09-21 12:53:48 +0100 | [diff] [blame] | 319 | |
Paul Bakker | 89e80c9 | 2012-03-20 13:50:09 +0000 | [diff] [blame] | 320 | #endif /* gcm.h */ |