mbed TLS v2.7.10
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 #if !defined(MBEDTLS_CONFIG_FILE)
35 #include "config.h"
36 #else
37 #include MBEDTLS_CONFIG_FILE
38 #endif
39 
40 #include "cipher.h"
41 
42 #include <stdint.h>
43 
44 #define MBEDTLS_GCM_ENCRYPT 1
45 #define MBEDTLS_GCM_DECRYPT 0
46 
47 #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
48 #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013
49 #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
51 #if !defined(MBEDTLS_GCM_ALT)
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
60 typedef struct {
62  uint64_t HL[16];
63  uint64_t HH[16];
64  uint64_t len;
65  uint64_t add_len;
66  unsigned char base_ectr[16];
67  unsigned char y[16];
68  unsigned char buf[16];
69  int mode;
72 }
74 
87 
103  mbedtls_cipher_id_t cipher,
104  const unsigned char *key,
105  unsigned int keybits );
106 
152  int mode,
153  size_t length,
154  const unsigned char *iv,
155  size_t iv_len,
156  const unsigned char *add,
157  size_t add_len,
158  const unsigned char *input,
159  unsigned char *output,
160  size_t tag_len,
161  unsigned char *tag );
162 
191  size_t length,
192  const unsigned char *iv,
193  size_t iv_len,
194  const unsigned char *add,
195  size_t add_len,
196  const unsigned char *tag,
197  size_t tag_len,
198  const unsigned char *input,
199  unsigned char *output );
200 
216  int mode,
217  const unsigned char *iv,
218  size_t iv_len,
219  const unsigned char *add,
220  size_t add_len );
221 
242  size_t length,
243  const unsigned char *input,
244  unsigned char *output );
245 
260  unsigned char *tag,
261  size_t tag_len );
262 
270 
271 #ifdef __cplusplus
272 }
273 #endif
274 
275 #else /* !MBEDTLS_GCM_ALT */
276 #include "gcm_alt.h"
277 #endif /* !MBEDTLS_GCM_ALT */
278 
279 #ifdef __cplusplus
280 extern "C" {
281 #endif
282 
288 int mbedtls_gcm_self_test( int verbose );
289 
290 #ifdef __cplusplus
291 }
292 #endif
293 
294 
295 #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:60
Configuration options (set of defines)
mbedtls_cipher_context_t cipher_ctx
Definition: gcm.h:61
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:65
mbedtls_cipher_id_t
An enumeration of supported ciphers.
Definition: cipher.h:78
The generic cipher wrapper.
uint64_t len
Definition: gcm.h:64
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.