mbed TLS v2.7.16
gcm.h
Go to the documentation of this file.
1 
12 /*
13  * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
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  * This file is part of Mbed TLS (https://tls.mbed.org)
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 
74 #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
75 #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013
76 #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
78 #if !defined(MBEDTLS_GCM_ALT)
79 
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83 
87 typedef struct {
89  uint64_t HL[16];
90  uint64_t HH[16];
91  uint64_t len;
92  uint64_t add_len;
93  unsigned char base_ectr[16];
94  unsigned char y[16];
95  unsigned char buf[16];
96  int mode;
99 }
101 
114 
130  mbedtls_cipher_id_t cipher,
131  const unsigned char *key,
132  unsigned int keybits );
133 
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 
218  size_t length,
219  const unsigned char *iv,
220  size_t iv_len,
221  const unsigned char *add,
222  size_t add_len,
223  const unsigned char *tag,
224  size_t tag_len,
225  const unsigned char *input,
226  unsigned char *output );
227 
243  int mode,
244  const unsigned char *iv,
245  size_t iv_len,
246  const unsigned char *add,
247  size_t add_len );
248 
269  size_t length,
270  const unsigned char *input,
271  unsigned char *output );
272 
287  unsigned char *tag,
288  size_t tag_len );
289 
297 
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 
315 int mbedtls_gcm_self_test( int verbose );
316 
317 #ifdef __cplusplus
318 }
319 #endif
320 
321 
322 #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:87
Configuration options (set of defines)
mbedtls_cipher_context_t cipher_ctx
Definition: gcm.h:88
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:92
mbedtls_cipher_id_t
An enumeration of supported ciphers.
Definition: cipher.h:105
The generic cipher wrapper.
uint64_t len
Definition: gcm.h:91
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.