mbed TLS v2.16.1
gcm.h
Go to the documentation of this file.
1 
14 /*
15  * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
16  * SPDX-License-Identifier: GPL-2.0
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License along
29  * with this program; if not, write to the Free Software Foundation, Inc.,
30  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31  *
32  * This file is part of Mbed TLS (https://tls.mbed.org)
33  */
34 
35 #ifndef MBEDTLS_GCM_H
36 #define MBEDTLS_GCM_H
37 
38 #if !defined(MBEDTLS_CONFIG_FILE)
39 #include "config.h"
40 #else
41 #include MBEDTLS_CONFIG_FILE
42 #endif
43 
44 #include "cipher.h"
45 
46 #include <stdint.h>
47 
48 #define MBEDTLS_GCM_ENCRYPT 1
49 #define MBEDTLS_GCM_DECRYPT 0
50 
51 #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
53 /* MBEDTLS_ERR_GCM_HW_ACCEL_FAILED is deprecated and should not be used. */
54 #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013
56 #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 #if !defined(MBEDTLS_GCM_ALT)
63 
67 typedef struct mbedtls_gcm_context
68 {
70  uint64_t HL[16];
71  uint64_t HH[16];
72  uint64_t len;
73  uint64_t add_len;
74  unsigned char base_ectr[16];
75  unsigned char y[16];
76  unsigned char buf[16];
77  int mode;
80 }
82 
83 #else /* !MBEDTLS_GCM_ALT */
84 #include "gcm_alt.h"
85 #endif /* !MBEDTLS_GCM_ALT */
86 
99 
117  mbedtls_cipher_id_t cipher,
118  const unsigned char *key,
119  unsigned int keybits );
120 
173  int mode,
174  size_t length,
175  const unsigned char *iv,
176  size_t iv_len,
177  const unsigned char *add,
178  size_t add_len,
179  const unsigned char *input,
180  unsigned char *output,
181  size_t tag_len,
182  unsigned char *tag );
183 
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 
246  int mode,
247  const unsigned char *iv,
248  size_t iv_len,
249  const unsigned char *add,
250  size_t add_len );
251 
278  size_t length,
279  const unsigned char *input,
280  unsigned char *output );
281 
299  unsigned char *tag,
300  size_t tag_len );
301 
310 
311 #if defined(MBEDTLS_SELF_TEST)
312 
319 int mbedtls_gcm_self_test( int verbose );
320 
321 #endif /* MBEDTLS_SELF_TEST */
322 
323 #ifdef __cplusplus
324 }
325 #endif
326 
327 
328 #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:67
Configuration options (set of defines)
mbedtls_cipher_context_t cipher_ctx
Definition: gcm.h:69
unsigned char buf[16]
Definition: gcm.h:76
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.
struct mbedtls_gcm_context mbedtls_gcm_context
The GCM context structure.
unsigned char y[16]
Definition: gcm.h:75
uint64_t HH[16]
Definition: gcm.h:71
uint64_t add_len
Definition: gcm.h:73
mbedtls_cipher_id_t
Supported cipher types.
Definition: cipher.h:86
uint64_t HL[16]
Definition: gcm.h:70
This file contains an abstraction interface for use with the cipher primitives provided by the librar...
uint64_t len
Definition: gcm.h:72
unsigned char base_ectr[16]
Definition: gcm.h:74
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.