mbed TLS v2.7.17
gcm.h
Go to the documentation of this file.
1 
12 /*
13  * Copyright The Mbed TLS Contributors
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:
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.
33  *
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  */
55 
56 #ifndef MBEDTLS_GCM_H
57 #define MBEDTLS_GCM_H
58 
59 #if !defined(MBEDTLS_CONFIG_FILE)
60 #include "config.h"
61 #else
62 #include MBEDTLS_CONFIG_FILE
63 #endif
64 
65 #include "cipher.h"
66 
67 #include <stdint.h>
68 
69 #define MBEDTLS_GCM_ENCRYPT 1
70 #define MBEDTLS_GCM_DECRYPT 0
71 
72 #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
73 #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013
74 #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
76 #if !defined(MBEDTLS_GCM_ALT)
77 
78 #ifdef __cplusplus
79 extern "C" {
80 #endif
81 
85 typedef struct {
87  uint64_t HL[16];
88  uint64_t HH[16];
89  uint64_t len;
90  uint64_t add_len;
91  unsigned char base_ectr[16];
92  unsigned char y[16];
93  unsigned char buf[16];
94  int mode;
97 }
99 
112 
128  mbedtls_cipher_id_t cipher,
129  const unsigned char *key,
130  unsigned int keybits );
131 
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 
216  size_t length,
217  const unsigned char *iv,
218  size_t iv_len,
219  const unsigned char *add,
220  size_t add_len,
221  const unsigned char *tag,
222  size_t tag_len,
223  const unsigned char *input,
224  unsigned char *output );
225 
241  int mode,
242  const unsigned char *iv,
243  size_t iv_len,
244  const unsigned char *add,
245  size_t add_len );
246 
267  size_t length,
268  const unsigned char *input,
269  unsigned char *output );
270 
285  unsigned char *tag,
286  size_t tag_len );
287 
295 
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 
313 int mbedtls_gcm_self_test( int verbose );
314 
315 #ifdef __cplusplus
316 }
317 #endif
318 
319 
320 #endif /* gcm.h */
void mbedtls_gcm_init(mbedtls_gcm_context *ctx)
This function initializes the specified GCM context, to make references valid, and prepares the conte...
int mbedtls_gcm_starts(mbedtls_gcm_context *ctx, int mode, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len)
This function starts a GCM encryption or decryption operation.
int mbedtls_gcm_self_test(int verbose)
The GCM checkup routine.
void mbedtls_gcm_free(mbedtls_gcm_context *ctx)
This function clears a GCM context and the underlying cipher sub-context.
The GCM context structure.
Definition: gcm.h:85
Configuration options (set of defines)
mbedtls_cipher_context_t cipher_ctx
Definition: gcm.h:86
int mbedtls_gcm_update(mbedtls_gcm_context *ctx, size_t length, const unsigned char *input, unsigned char *output)
This function feeds an input buffer into an ongoing GCM encryption or decryption operation.
uint64_t add_len
Definition: gcm.h:90
mbedtls_cipher_id_t
An enumeration of supported ciphers.
Definition: cipher.h:103
The generic cipher wrapper.
uint64_t len
Definition: gcm.h:89
int mbedtls_gcm_setkey(mbedtls_gcm_context *ctx, mbedtls_cipher_id_t cipher, const unsigned char *key, unsigned int keybits)
This function associates a GCM context with a cipher algorithm and a key.
int mbedtls_gcm_finish(mbedtls_gcm_context *ctx, unsigned char *tag, size_t tag_len)
This function finishes the GCM operation and generates the authentication tag.
int mbedtls_gcm_auth_decrypt(mbedtls_gcm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *tag, size_t tag_len, const unsigned char *input, unsigned char *output)
This function performs a GCM authenticated decryption of a buffer.
int mbedtls_gcm_crypt_and_tag(mbedtls_gcm_context *ctx, int mode, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *input, unsigned char *output, size_t tag_len, unsigned char *tag)
This function performs GCM encryption or decryption of a buffer.