blob: e717aa1bffc66b0c62c894c026f771df3a89f93d [file] [log] [blame]
Paul Bakker89e80c92012-03-20 13:50:09 +00001/**
2 * \file gcm.h
3 *
Rose Zadikd8c4f612018-03-27 11:43:04 +01004 * \brief This file contains GCM definitions and functions.
5 *
6 * The Galois/Counter Mode (GCM) for 128-bit block ciphers is defined
7 * in <em>D. McGrew, J. Viega, The Galois/Counter Mode of Operation
8 * (GCM), Natl. Inst. Stand. Technol.</em>
Rose Zadik17b4f7f2018-01-26 10:56:42 +00009 *
10 * For more information on GCM, see <em>NIST SP 800-38D: Recommendation for
11 * Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC</em>.
12 *
Darryl Greena40a1012018-01-05 15:33:17 +000013 */
14/*
Bence Szépkúti1e148272020-08-07 13:07:28 +020015 * Copyright The Mbed TLS Contributors
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020016 * SPDX-License-Identifier: Apache-2.0
17 *
18 * Licensed under the Apache License, Version 2.0 (the "License"); you may
19 * not use this file except in compliance with the License.
20 * You may obtain a copy of the License at
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Unless required by applicable law or agreed to in writing, software
25 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
26 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27 * See the License for the specific language governing permissions and
28 * limitations under the License.
Paul Bakker89e80c92012-03-20 13:50:09 +000029 */
Rose Zadik17b4f7f2018-01-26 10:56:42 +000030
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020031#ifndef MBEDTLS_GCM_H
32#define MBEDTLS_GCM_H
Paul Bakker89e80c92012-03-20 13:50:09 +000033
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050034#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010035#include "mbedtls/config.h"
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050036#else
37#include MBEDTLS_CONFIG_FILE
38#endif
39
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010040#include "mbedtls/cipher.h"
Paul Bakker89e80c92012-03-20 13:50:09 +000041
42#include <stdint.h>
43
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044#define MBEDTLS_GCM_ENCRYPT 1
45#define MBEDTLS_GCM_DECRYPT 0
Paul Bakker89e80c92012-03-20 13:50:09 +000046
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020047#define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012 /**< Authenticated decryption failed. */
Ron Eldor9924bdc2018-10-04 10:59:13 +030048
49/* MBEDTLS_ERR_GCM_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010050#define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013 /**< GCM hardware accelerator failed. */
Ron Eldor9924bdc2018-10-04 10:59:13 +030051
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014 /**< Bad input parameters to function. */
Paul Bakker89e80c92012-03-20 13:50:09 +000053
Paul Bakker407a0da2013-06-27 14:29:21 +020054#ifdef __cplusplus
55extern "C" {
56#endif
57
Ron Eldor4e6d55d2018-02-07 16:36:15 +020058#if !defined(MBEDTLS_GCM_ALT)
59
Paul Bakker89e80c92012-03-20 13:50:09 +000060/**
Rose Zadik17b4f7f2018-01-26 10:56:42 +000061 * \brief The GCM context structure.
Paul Bakker89e80c92012-03-20 13:50:09 +000062 */
Dawid Drozd428cc522018-07-24 10:02:47 +020063typedef struct mbedtls_gcm_context
64{
Rose Zadik17b4f7f2018-01-26 10:56:42 +000065 mbedtls_cipher_context_t cipher_ctx; /*!< The cipher context used. */
66 uint64_t HL[16]; /*!< Precalculated HTable low. */
67 uint64_t HH[16]; /*!< Precalculated HTable high. */
68 uint64_t len; /*!< The total length of the encrypted data. */
69 uint64_t add_len; /*!< The total length of the additional data. */
70 unsigned char base_ectr[16]; /*!< The first ECTR for tag. */
71 unsigned char y[16]; /*!< The Y working value. */
72 unsigned char buf[16]; /*!< The buf working value. */
73 int mode; /*!< The operation to perform:
74 #MBEDTLS_GCM_ENCRYPT or
75 #MBEDTLS_GCM_DECRYPT. */
Paul Bakker89e80c92012-03-20 13:50:09 +000076}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077mbedtls_gcm_context;
Paul Bakker89e80c92012-03-20 13:50:09 +000078
Ron Eldor4e6d55d2018-02-07 16:36:15 +020079#else /* !MBEDTLS_GCM_ALT */
80#include "gcm_alt.h"
81#endif /* !MBEDTLS_GCM_ALT */
82
Paul Bakker89e80c92012-03-20 13:50:09 +000083/**
Rose Zadik17b4f7f2018-01-26 10:56:42 +000084 * \brief This function initializes the specified GCM context,
85 * to make references valid, and prepares the context
86 * for mbedtls_gcm_setkey() or mbedtls_gcm_free().
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +020087 *
Rose Zadik17b4f7f2018-01-26 10:56:42 +000088 * The function does not bind the GCM context to a particular
89 * cipher, nor set the key. For this purpose, use
90 * mbedtls_gcm_setkey().
91 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -050092 * \param ctx The GCM context to initialize. This must not be \c NULL.
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +020093 */
94void mbedtls_gcm_init( mbedtls_gcm_context *ctx );
95
96/**
Rose Zadik17b4f7f2018-01-26 10:56:42 +000097 * \brief This function associates a GCM context with a
98 * cipher algorithm and a key.
Paul Bakker89e80c92012-03-20 13:50:09 +000099 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500100 * \param ctx The GCM context. This must be initialized.
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000101 * \param cipher The 128-bit block cipher to use.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500102 * \param key The encryption key. This must be a readable buffer of at
103 * least \p keybits bits.
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000104 * \param keybits The key size in bits. Valid options are:
105 * <ul><li>128 bits</li>
106 * <li>192 bits</li>
107 * <li>256 bits</li></ul>
Paul Bakker89e80c92012-03-20 13:50:09 +0000108 *
Rose Zadikd8c4f612018-03-27 11:43:04 +0100109 * \return \c 0 on success.
110 * \return A cipher-specific error code on failure.
Paul Bakker89e80c92012-03-20 13:50:09 +0000111 */
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200112int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx,
113 mbedtls_cipher_id_t cipher,
114 const unsigned char *key,
Manuel Pégourié-Gonnardb8186a52015-06-18 14:58:58 +0200115 unsigned int keybits );
Paul Bakker89e80c92012-03-20 13:50:09 +0000116
117/**
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000118 * \brief This function performs GCM encryption or decryption of a buffer.
Paul Bakker89e80c92012-03-20 13:50:09 +0000119 *
Rose Zadikd8c4f612018-03-27 11:43:04 +0100120 * \note For encryption, the output buffer can be the same as the
121 * input buffer. For decryption, the output buffer cannot be
122 * the same as input buffer. If the buffers overlap, the output
123 * buffer must trail at least 8 Bytes behind the input buffer.
Paul Bakkerca4ab492012-04-18 14:23:57 +0000124 *
Gilles Peskine80f679b2018-06-01 17:55:41 +0200125 * \warning When this function performs a decryption, it outputs the
126 * authentication tag and does not verify that the data is
127 * authentic. You should use this function to perform encryption
128 * only. For decryption, use mbedtls_gcm_auth_decrypt() instead.
129 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500130 * \param ctx The GCM context to use for encryption or decryption. This
131 * must be initialized.
Gilles Peskine0a0e08a2018-06-07 14:46:02 +0200132 * \param mode The operation to perform:
133 * - #MBEDTLS_GCM_ENCRYPT to perform authenticated encryption.
134 * The ciphertext is written to \p output and the
135 * authentication tag is written to \p tag.
136 * - #MBEDTLS_GCM_DECRYPT to perform decryption.
137 * The plaintext is written to \p output and the
138 * authentication tag is written to \p tag.
139 * Note that this mode is not recommended, because it does
140 * not verify the authenticity of the data. For this reason,
141 * you should use mbedtls_gcm_auth_decrypt() instead of
142 * calling this function in decryption mode.
Gilles Peskine80f679b2018-06-01 17:55:41 +0200143 * \param length The length of the input data, which is equal to the length
144 * of the output data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500145 * \param iv The initialization vector. This must be a readable buffer of
146 * at least \p iv_len Bytes.
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000147 * \param iv_len The length of the IV.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500148 * \param add The buffer holding the additional data. This must be of at
149 * least that size in Bytes.
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000150 * \param add_len The length of the additional data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500151 * \param input The buffer holding the input data. If \p length is greater
152 * than zero, this must be a readable buffer of at least that
153 * size in Bytes.
154 * \param output The buffer for holding the output data. If \p length is greater
155 * than zero, this must be a writable buffer of at least that
156 * size in Bytes.
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000157 * \param tag_len The length of the tag to generate.
Yonatan Goldschmidt6e2af092020-09-12 00:19:52 +0300158 * \param tag The buffer for holding the tag. This must be a writable
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500159 * buffer of at least \p tag_len Bytes.
Paul Bakker89e80c92012-03-20 13:50:09 +0000160 *
Gilles Peskine80f679b2018-06-01 17:55:41 +0200161 * \return \c 0 if the encryption or decryption was performed
162 * successfully. Note that in #MBEDTLS_GCM_DECRYPT mode,
163 * this does not indicate that the data is authentic.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500164 * \return #MBEDTLS_ERR_GCM_BAD_INPUT if the lengths or pointers are
165 * not valid or a cipher-specific error code if the encryption
Ron Eldor9924bdc2018-10-04 10:59:13 +0300166 * or decryption failed.
Paul Bakker89e80c92012-03-20 13:50:09 +0000167 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200168int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx,
Paul Bakker89e80c92012-03-20 13:50:09 +0000169 int mode,
170 size_t length,
171 const unsigned char *iv,
172 size_t iv_len,
173 const unsigned char *add,
174 size_t add_len,
175 const unsigned char *input,
176 unsigned char *output,
177 size_t tag_len,
178 unsigned char *tag );
179
180/**
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000181 * \brief This function performs a GCM authenticated decryption of a
182 * buffer.
Paul Bakker89e80c92012-03-20 13:50:09 +0000183 *
Rose Zadikd8c4f612018-03-27 11:43:04 +0100184 * \note For decryption, the output buffer cannot be the same as
185 * input buffer. If the buffers overlap, the output buffer
186 * must trail at least 8 Bytes behind the input buffer.
Paul Bakkerca4ab492012-04-18 14:23:57 +0000187 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500188 * \param ctx The GCM context. This must be initialized.
Gilles Peskine80f679b2018-06-01 17:55:41 +0200189 * \param length The length of the ciphertext to decrypt, which is also
190 * the length of the decrypted plaintext.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500191 * \param iv The initialization vector. This must be a readable buffer
192 * of at least \p iv_len Bytes.
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000193 * \param iv_len The length of the IV.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500194 * \param add The buffer holding the additional data. This must be of at
195 * least that size in Bytes.
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000196 * \param add_len The length of the additional data.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500197 * \param tag The buffer holding the tag to verify. This must be a
198 * readable buffer of at least \p tag_len Bytes.
Gilles Peskine80f679b2018-06-01 17:55:41 +0200199 * \param tag_len The length of the tag to verify.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500200 * \param input The buffer holding the ciphertext. If \p length is greater
201 * than zero, this must be a readable buffer of at least that
202 * size.
203 * \param output The buffer for holding the decrypted plaintext. If \p length
204 * is greater than zero, this must be a writable buffer of at
205 * least that size.
Paul Bakker89e80c92012-03-20 13:50:09 +0000206 *
Gilles Peskine80f679b2018-06-01 17:55:41 +0200207 * \return \c 0 if successful and authenticated.
208 * \return #MBEDTLS_ERR_GCM_AUTH_FAILED if the tag does not match.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500209 * \return #MBEDTLS_ERR_GCM_BAD_INPUT if the lengths or pointers are
210 * not valid or a cipher-specific error code if the decryption
211 * failed.
Paul Bakker89e80c92012-03-20 13:50:09 +0000212 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200213int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx,
Paul Bakker89e80c92012-03-20 13:50:09 +0000214 size_t length,
215 const unsigned char *iv,
216 size_t iv_len,
217 const unsigned char *add,
218 size_t add_len,
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +0200219 const unsigned char *tag,
Paul Bakker89e80c92012-03-20 13:50:09 +0000220 size_t tag_len,
221 const unsigned char *input,
222 unsigned char *output );
223
224/**
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000225 * \brief This function starts a GCM encryption or decryption
226 * operation.
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +0200227 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500228 * \param ctx The GCM context. This must be initialized.
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000229 * \param mode The operation to perform: #MBEDTLS_GCM_ENCRYPT or
230 * #MBEDTLS_GCM_DECRYPT.
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500231 * \param iv The initialization vector. This must be a readable buffer of
232 * at least \p iv_len Bytes.
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000233 * \param iv_len The length of the IV.
Gilles Peskine295fc132021-04-15 18:32:23 +0200234 *
235 * \return \c 0 on success.
236 */
237int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
238 int mode,
239 const unsigned char *iv,
240 size_t iv_len );
241
242/**
Gilles Peskine52118182021-05-18 20:38:33 +0200243 * \brief This function feeds an input buffer as associated data
244 * (authenticated but not encrypted data) in a GCM
245 * encryption or decryption operation.
Gilles Peskine295fc132021-04-15 18:32:23 +0200246 *
Gilles Peskine8e8cdd12021-05-18 21:02:13 +0200247 * Call this function after mbedtls_gcm_starts() to pass
248 * the associated data. If the associated data is empty,
249 * you do not need to call this function. You may not
250 * call this function after calling mbedtls_cipher_update().
251 *
Gilles Peskine295fc132021-04-15 18:32:23 +0200252 * \note This function may only be called once per operation:
253 * you must pass the whole associated data in a single
254 * call. This limitation will be lifted in a future version
255 * of Mbed TLS.
256 *
257 * \param ctx The GCM context. This must have been started with
258 * mbedtls_gcm_starts() and must not have yet received
259 * any input with mbedtls_gcm_update().
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500260 * \param add The buffer holding the additional data, or \c NULL
261 * if \p add_len is \c 0.
262 * \param add_len The length of the additional data. If \c 0,
263 * \p add may be \c NULL.
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +0200264 *
Rose Zadikd8c4f612018-03-27 11:43:04 +0100265 * \return \c 0 on success.
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +0200266 */
Gilles Peskine295fc132021-04-15 18:32:23 +0200267int mbedtls_gcm_update_ad( mbedtls_gcm_context *ctx,
268 const unsigned char *add,
269 size_t add_len );
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +0200270
271/**
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000272 * \brief This function feeds an input buffer into an ongoing GCM
273 * encryption or decryption operation.
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +0200274 *
Gilles Peskine8e8cdd12021-05-18 21:02:13 +0200275 * You may call this function zero, one or more times
276 * to pass successive parts of the input: the plaintext to
277 * encrypt, or the ciphertext (not including the tag) to
278 * decrypt. After the last part of the input, call
279 * mbedtls_gcm_finish().
280 *
Gilles Peskineb7bb06872021-05-18 22:31:53 +0200281 * This function may produce output in one of the following
282 * ways:
283 * - Immediate output: the output length is always equal
284 * to the input length.
285 * - Buffered output: the output consists of a whole number
286 * of 16-byte blocks. If the total input length so far
287 * (not including associated data) is 16 \* *B* + *A*
288 * with *A* < 16 then the total output length is 16 \* *B*.
289 *
290 * In particular:
291 * - It is always correct to call this function with
292 * \c output_size >= \c input_size + 15.
293 * - If \c input_size is a multiple of 16 for all the calls
294 * to this function during an operation, then it is
295 * correct to use \c output_size = \c input_size.
296 *
Rose Zadikd8c4f612018-03-27 11:43:04 +0100297 * \note For decryption, the output buffer cannot be the same as
298 * input buffer. If the buffers overlap, the output buffer
299 * must trail at least 8 Bytes behind the input buffer.
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +0200300 *
Gilles Peskinea56c4482021-04-15 17:22:35 +0200301 * \param ctx The GCM context. This must be initialized.
302 * \param input The buffer holding the input data. If \p input_length
303 * is greater than zero, this must be a readable buffer
304 * of at least \p input_length bytes.
305 * \param input_length The length of the input data in bytes.
Gilles Peskine518fdb02021-05-18 20:43:31 +0200306 * \param output The buffer for the output data. If \p output_size
Gilles Peskinea56c4482021-04-15 17:22:35 +0200307 * is greater than zero, this must be a writable buffer of
308 * of at least \p output_size bytes.
Gilles Peskinea56c4482021-04-15 17:22:35 +0200309 * \param output_size The size of the output buffer in bytes.
Gilles Peskineb7bb06872021-05-18 22:31:53 +0200310 * See the function description regarding the output size.
Gilles Peskinea56c4482021-04-15 17:22:35 +0200311 * \param output_length On success, \p *output_length contains the actual
312 * length of the output written in \p output.
313 * On failure, the content of \p *output_length is
314 * unspecified.
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +0200315 *
Rose Zadikd8c4f612018-03-27 11:43:04 +0100316 * \return \c 0 on success.
Gilles Peskined9380b52021-05-18 21:02:52 +0200317 * \return #MBEDTLS_ERR_GCM_BAD_INPUT on failure:
318 * total input length too long,
319 * unsupported input/output buffer overlap detected,
320 * or \p output_size too small.
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +0200321 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200322int mbedtls_gcm_update( mbedtls_gcm_context *ctx,
Gilles Peskinea56c4482021-04-15 17:22:35 +0200323 const unsigned char *input, size_t input_length,
324 unsigned char *output, size_t output_size,
325 size_t *output_length );
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +0200326
327/**
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000328 * \brief This function finishes the GCM operation and generates
329 * the authentication tag.
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +0200330 *
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000331 * It wraps up the GCM stream, and generates the
332 * tag. The tag can have a maximum length of 16 Bytes.
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +0200333 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500334 * \param ctx The GCM context. This must be initialized.
Yonatan Goldschmidt6e2af092020-09-12 00:19:52 +0300335 * \param tag The buffer for holding the tag. This must be a writable
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500336 * buffer of at least \p tag_len Bytes.
337 * \param tag_len The length of the tag to generate. This must be at least
338 * four.
Gilles Peskine9461e452021-04-15 16:48:32 +0200339 * \param output The buffer for the final output.
Gilles Peskineb7bb06872021-05-18 22:31:53 +0200340 * If \p output_size is nonzero, this must be a writable
341 * buffer of at least \p output_size bytes.
342 * \param output_size The size of the \p output buffer in bytes.
343 * This must be large enough for the output that
344 * mbedtls_gcm_update() has not produced. In particular:
345 * - If mbedtls_gcm_update() produces immediate output,
346 * or if the total input size is a multiple of \c 16,
347 * then mbedtls_gcm_finish() never produces any output,
348 * so \p output_size can be \c 0.
349 * - \p output_size never needs to be more than \c 15.
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000350 *
Rose Zadikd8c4f612018-03-27 11:43:04 +0100351 * \return \c 0 on success.
Gilles Peskined9380b52021-05-18 21:02:52 +0200352 * \return #MBEDTLS_ERR_GCM_BAD_INPUT on failure:
353 * invalid value of \p tag_len,
354 * or \p output_len too small.
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +0200355 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200356int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
Gilles Peskineb7bb06872021-05-18 22:31:53 +0200357 unsigned char *output, size_t output_size,
Gilles Peskine9461e452021-04-15 16:48:32 +0200358 unsigned char *tag, size_t tag_len );
Paul Bakkerb9d3cfa2013-06-26 15:07:16 +0200359
360/**
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000361 * \brief This function clears a GCM context and the underlying
362 * cipher sub-context.
Manuel Pégourié-Gonnard4fe92002013-09-13 13:45:58 +0200363 *
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500364 * \param ctx The GCM context to clear. If this is \c NULL, the call has
365 * no effect. Otherwise, this must be initialized.
Manuel Pégourié-Gonnard4fe92002013-09-13 13:45:58 +0200366 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200367void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
Manuel Pégourié-Gonnard4fe92002013-09-13 13:45:58 +0200368
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500369#if defined(MBEDTLS_SELF_TEST)
370
Manuel Pégourié-Gonnard4fe92002013-09-13 13:45:58 +0200371/**
Rose Zadik17b4f7f2018-01-26 10:56:42 +0000372 * \brief The GCM checkup routine.
Paul Bakker89e80c92012-03-20 13:50:09 +0000373 *
Rose Zadikd8c4f612018-03-27 11:43:04 +0100374 * \return \c 0 on success.
375 * \return \c 1 on failure.
Paul Bakker89e80c92012-03-20 13:50:09 +0000376 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200377int mbedtls_gcm_self_test( int verbose );
Paul Bakker89e80c92012-03-20 13:50:09 +0000378
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500379#endif /* MBEDTLS_SELF_TEST */
380
Paul Bakker89e80c92012-03-20 13:50:09 +0000381#ifdef __cplusplus
382}
383#endif
384
Jaeden Amero15263302017-09-21 12:53:48 +0100385
Paul Bakker89e80c92012-03-20 13:50:09 +0000386#endif /* gcm.h */