mbed TLS v2.7.6
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
15  *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may
17  * not use this file except in compliance with the License.
18  * You may obtain a copy of the License at
19  *
20  * http://www.apache.org/licenses/LICENSE-2.0
21  *
22  * Unless required by applicable law or agreed to in writing, software
23  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25  * See the License for the specific language governing permissions and
26  * limitations under the License.
27  *
28  * This file is part of Mbed TLS (https://tls.mbed.org)
29  */
30 
31 #ifndef MBEDTLS_GCM_H
32 #define MBEDTLS_GCM_H
33 
34 #include "cipher.h"
35 
36 #include <stdint.h>
37 
38 #define MBEDTLS_GCM_ENCRYPT 1
39 #define MBEDTLS_GCM_DECRYPT 0
40 
41 #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
42 #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013
43 #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
45 #if !defined(MBEDTLS_GCM_ALT)
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
54 typedef struct {
56  uint64_t HL[16];
57  uint64_t HH[16];
58  uint64_t len;
59  uint64_t add_len;
60  unsigned char base_ectr[16];
61  unsigned char y[16];
62  unsigned char buf[16];
63  int mode;
66 }
68 
81 
97  mbedtls_cipher_id_t cipher,
98  const unsigned char *key,
99  unsigned int keybits );
100 
146  int mode,
147  size_t length,
148  const unsigned char *iv,
149  size_t iv_len,
150  const unsigned char *add,
151  size_t add_len,
152  const unsigned char *input,
153  unsigned char *output,
154  size_t tag_len,
155  unsigned char *tag );
156 
185  size_t length,
186  const unsigned char *iv,
187  size_t iv_len,
188  const unsigned char *add,
189  size_t add_len,
190  const unsigned char *tag,
191  size_t tag_len,
192  const unsigned char *input,
193  unsigned char *output );
194 
210  int mode,
211  const unsigned char *iv,
212  size_t iv_len,
213  const unsigned char *add,
214  size_t add_len );
215 
236  size_t length,
237  const unsigned char *input,
238  unsigned char *output );
239 
254  unsigned char *tag,
255  size_t tag_len );
256 
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 
269 #else /* !MBEDTLS_GCM_ALT */
270 #include "gcm_alt.h"
271 #endif /* !MBEDTLS_GCM_ALT */
272 
273 #ifdef __cplusplus
274 extern "C" {
275 #endif
276 
282 int mbedtls_gcm_self_test( int verbose );
283 
284 #ifdef __cplusplus
285 }
286 #endif
287 
288 
289 #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:54
mbedtls_cipher_context_t cipher_ctx
Definition: gcm.h:55
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:59
mbedtls_cipher_id_t
An enumeration of supported ciphers.
Definition: cipher.h:78
The generic cipher wrapper.
uint64_t len
Definition: gcm.h:58
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.