Mbed TLS v2.28.8
gcm.h
Go to the documentation of this file.
1 
14 /*
15  * Copyright The Mbed TLS Contributors
16  * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
17  */
18 
19 #ifndef MBEDTLS_GCM_H
20 #define MBEDTLS_GCM_H
21 
22 #if !defined(MBEDTLS_CONFIG_FILE)
23 #include "mbedtls/config.h"
24 #else
25 #include MBEDTLS_CONFIG_FILE
26 #endif
27 
28 #include "mbedtls/cipher.h"
29 
30 #include <stdint.h>
31 
32 #define MBEDTLS_GCM_ENCRYPT 1
33 #define MBEDTLS_GCM_DECRYPT 0
34 
36 #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
37 
38 /* MBEDTLS_ERR_GCM_HW_ACCEL_FAILED is deprecated and should not be used. */
40 #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013
41 
43 #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 #if !defined(MBEDTLS_GCM_ALT)
50 
54 typedef struct mbedtls_gcm_context {
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 
69 #else /* !MBEDTLS_GCM_ALT */
70 #include "gcm_alt.h"
71 #endif /* !MBEDTLS_GCM_ALT */
72 
85 
103  mbedtls_cipher_id_t cipher,
104  const unsigned char *key,
105  unsigned int keybits);
106 
159  int mode,
160  size_t length,
161  const unsigned char *iv,
162  size_t iv_len,
163  const unsigned char *add,
164  size_t add_len,
165  const unsigned char *input,
166  unsigned char *output,
167  size_t tag_len,
168  unsigned char *tag);
169 
204  size_t length,
205  const unsigned char *iv,
206  size_t iv_len,
207  const unsigned char *add,
208  size_t add_len,
209  const unsigned char *tag,
210  size_t tag_len,
211  const unsigned char *input,
212  unsigned char *output);
213 
232  int mode,
233  const unsigned char *iv,
234  size_t iv_len,
235  const unsigned char *add,
236  size_t add_len);
237 
264  size_t length,
265  const unsigned char *input,
266  unsigned char *output);
267 
285  unsigned char *tag,
286  size_t tag_len);
287 
296 
297 #if defined(MBEDTLS_SELF_TEST)
298 
305 int mbedtls_gcm_self_test(int verbose);
306 
307 #endif /* MBEDTLS_SELF_TEST */
308 
309 #ifdef __cplusplus
310 }
311 #endif
312 
313 
314 #endif /* gcm.h */
mbedtls_gcm_init
void mbedtls_gcm_init(mbedtls_gcm_context *ctx)
This function initializes the specified GCM context, to make references valid, and prepares the conte...
mbedtls_gcm_free
void mbedtls_gcm_free(mbedtls_gcm_context *ctx)
This function clears a GCM context and the underlying cipher sub-context.
mbedtls_gcm_context::mode
int mode
Definition: gcm.h:63
mbedtls_cipher_id_t
mbedtls_cipher_id_t
Supported cipher types.
Definition: cipher.h:78
mbedtls_gcm_context::add_len
uint64_t add_len
Definition: gcm.h:59
mbedtls_gcm_context::HL
uint64_t HL[16]
Definition: gcm.h:56
mbedtls_gcm_context
The GCM context structure.
Definition: gcm.h:54
mbedtls_gcm_context::len
uint64_t len
Definition: gcm.h:58
mbedtls_gcm_self_test
int mbedtls_gcm_self_test(int verbose)
The GCM checkup routine.
mbedtls_gcm_finish
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.
cipher.h
This file contains an abstraction interface for use with the cipher primitives provided by the librar...
mbedtls_gcm_context::buf
unsigned char buf[16]
Definition: gcm.h:62
mbedtls_gcm_starts
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.
mbedtls_gcm_crypt_and_tag
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.
mbedtls_gcm_update
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.
mbedtls_gcm_setkey
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.
mbedtls_cipher_context_t
Definition: cipher.h:305
mbedtls_gcm_context::y
unsigned char y[16]
Definition: gcm.h:61
config.h
Configuration options (set of defines)
mbedtls_gcm_context::HH
uint64_t HH[16]
Definition: gcm.h:57
mbedtls_gcm_context
struct mbedtls_gcm_context mbedtls_gcm_context
The GCM context structure.
mbedtls_gcm_context::cipher_ctx
mbedtls_cipher_context_t cipher_ctx
Definition: gcm.h:55
mbedtls_gcm_context::base_ectr
unsigned char base_ectr[16]
Definition: gcm.h:60
mbedtls_gcm_auth_decrypt
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.