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