mbed TLS v2.16.12
gcm.h
Go to the documentation of this file.
1 
14 /*
15  * Copyright The Mbed TLS Contributors
16  * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
17  *
18  * This file is provided under the Apache License 2.0, or the
19  * GNU General Public License v2.0 or later.
20  *
21  * **********
22  * Apache License 2.0:
23  *
24  * Licensed under the Apache License, Version 2.0 (the "License"); you may
25  * not use this file except in compliance with the License.
26  * You may obtain a copy of the License at
27  *
28  * http://www.apache.org/licenses/LICENSE-2.0
29  *
30  * Unless required by applicable law or agreed to in writing, software
31  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
32  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33  * See the License for the specific language governing permissions and
34  * limitations under the License.
35  *
36  * **********
37  *
38  * **********
39  * GNU General Public License v2.0 or later:
40  *
41  * This program is free software; you can redistribute it and/or modify
42  * it under the terms of the GNU General Public License as published by
43  * the Free Software Foundation; either version 2 of the License, or
44  * (at your option) any later version.
45  *
46  * This program is distributed in the hope that it will be useful,
47  * but WITHOUT ANY WARRANTY; without even the implied warranty of
48  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49  * GNU General Public License for more details.
50  *
51  * You should have received a copy of the GNU General Public License along
52  * with this program; if not, write to the Free Software Foundation, Inc.,
53  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
54  *
55  * **********
56  */
57 
58 #ifndef MBEDTLS_GCM_H
59 #define MBEDTLS_GCM_H
60 
61 #if !defined(MBEDTLS_CONFIG_FILE)
62 #include "config.h"
63 #else
64 #include MBEDTLS_CONFIG_FILE
65 #endif
66 
67 #include "cipher.h"
68 
69 #include <stdint.h>
70 
71 #define MBEDTLS_GCM_ENCRYPT 1
72 #define MBEDTLS_GCM_DECRYPT 0
73 
75 #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
76 
77 /* MBEDTLS_ERR_GCM_HW_ACCEL_FAILED is deprecated and should not be used. */
79 #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013
80 
82 #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
83 
84 #ifdef __cplusplus
85 extern "C" {
86 #endif
87 
88 #if !defined(MBEDTLS_GCM_ALT)
89 
93 typedef struct mbedtls_gcm_context
94 {
96  uint64_t HL[16];
97  uint64_t HH[16];
98  uint64_t len;
99  uint64_t add_len;
100  unsigned char base_ectr[16];
101  unsigned char y[16];
102  unsigned char buf[16];
103  int mode;
106 }
108 
109 #else /* !MBEDTLS_GCM_ALT */
110 #include "gcm_alt.h"
111 #endif /* !MBEDTLS_GCM_ALT */
112 
125 
143  mbedtls_cipher_id_t cipher,
144  const unsigned char *key,
145  unsigned int keybits );
146 
199  int mode,
200  size_t length,
201  const unsigned char *iv,
202  size_t iv_len,
203  const unsigned char *add,
204  size_t add_len,
205  const unsigned char *input,
206  unsigned char *output,
207  size_t tag_len,
208  unsigned char *tag );
209 
244  size_t length,
245  const unsigned char *iv,
246  size_t iv_len,
247  const unsigned char *add,
248  size_t add_len,
249  const unsigned char *tag,
250  size_t tag_len,
251  const unsigned char *input,
252  unsigned char *output );
253 
272  int mode,
273  const unsigned char *iv,
274  size_t iv_len,
275  const unsigned char *add,
276  size_t add_len );
277 
304  size_t length,
305  const unsigned char *input,
306  unsigned char *output );
307 
325  unsigned char *tag,
326  size_t tag_len );
327 
336 
337 #if defined(MBEDTLS_SELF_TEST)
338 
345 int mbedtls_gcm_self_test( int verbose );
346 
347 #endif /* MBEDTLS_SELF_TEST */
348 
349 #ifdef __cplusplus
350 }
351 #endif
352 
353 
354 #endif /* gcm.h */
This file contains an abstraction interface for use with the cipher primitives provided by the librar...
mbedtls_cipher_id_t
Supported cipher types.
Definition: cipher.h:117
Configuration options (set of defines)
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.
struct mbedtls_gcm_context mbedtls_gcm_context
The GCM context structure.
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.
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_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.
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_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_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.
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.
The GCM context structure.
Definition: gcm.h:94
unsigned char base_ectr[16]
Definition: gcm.h:100
unsigned char y[16]
Definition: gcm.h:101
mbedtls_cipher_context_t cipher_ctx
Definition: gcm.h:95
uint64_t HH[16]
Definition: gcm.h:97
unsigned char buf[16]
Definition: gcm.h:102
uint64_t len
Definition: gcm.h:98
uint64_t add_len
Definition: gcm.h:99
uint64_t HL[16]
Definition: gcm.h:96