mbed TLS v2.7.3
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 
125  int mode,
126  size_t length,
127  const unsigned char *iv,
128  size_t iv_len,
129  const unsigned char *add,
130  size_t add_len,
131  const unsigned char *input,
132  unsigned char *output,
133  size_t tag_len,
134  unsigned char *tag );
135 
159  size_t length,
160  const unsigned char *iv,
161  size_t iv_len,
162  const unsigned char *add,
163  size_t add_len,
164  const unsigned char *tag,
165  size_t tag_len,
166  const unsigned char *input,
167  unsigned char *output );
168 
184  int mode,
185  const unsigned char *iv,
186  size_t iv_len,
187  const unsigned char *add,
188  size_t add_len );
189 
210  size_t length,
211  const unsigned char *input,
212  unsigned char *output );
213 
228  unsigned char *tag,
229  size_t tag_len );
230 
238 
239 #ifdef __cplusplus
240 }
241 #endif
242 
243 #else /* !MBEDTLS_GCM_ALT */
244 #include "gcm_alt.h"
245 #endif /* !MBEDTLS_GCM_ALT */
246 
247 #ifdef __cplusplus
248 extern "C" {
249 #endif
250 
256 int mbedtls_gcm_self_test( int verbose );
257 
258 #ifdef __cplusplus
259 }
260 #endif
261 
262 
263 #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.