Mbed TLS v3.6.3
Loading...
Searching...
No Matches
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
22
23#include "mbedtls/build_info.h"
24
25#include "mbedtls/cipher.h"
26
27#if defined(MBEDTLS_BLOCK_CIPHER_C)
29#endif
30
31#include <stdint.h>
32
33#define MBEDTLS_GCM_ENCRYPT 1
34#define MBEDTLS_GCM_DECRYPT 0
35
37#define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
39#define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
41#define MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL -0x0016
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47#if !defined(MBEDTLS_GCM_ALT)
48
49#if defined(MBEDTLS_GCM_LARGE_TABLE)
50#define MBEDTLS_GCM_HTABLE_SIZE 256
51#else
52#define MBEDTLS_GCM_HTABLE_SIZE 16
53#endif
54
58typedef struct mbedtls_gcm_context {
59#if defined(MBEDTLS_BLOCK_CIPHER_C)
61#else
63#endif
65 uint64_t MBEDTLS_PRIVATE(len);
66 uint64_t MBEDTLS_PRIVATE(add_len);
67 unsigned char MBEDTLS_PRIVATE(base_ectr)[16];
68 unsigned char MBEDTLS_PRIVATE(y)[16];
69 unsigned char MBEDTLS_PRIVATE(buf)[16];
70 unsigned char MBEDTLS_PRIVATE(mode);
73 unsigned char MBEDTLS_PRIVATE(acceleration);
74}
76
77#else /* !MBEDTLS_GCM_ALT */
78#include "gcm_alt.h"
79#endif /* !MBEDTLS_GCM_ALT */
80
93
111 mbedtls_cipher_id_t cipher,
112 const unsigned char *key,
113 unsigned int keybits);
114
166 int mode,
167 size_t length,
168 const unsigned char *iv,
169 size_t iv_len,
170 const unsigned char *add,
171 size_t add_len,
172 const unsigned char *input,
173 unsigned char *output,
174 size_t tag_len,
175 unsigned char *tag);
176
213 size_t length,
214 const unsigned char *iv,
215 size_t iv_len,
216 const unsigned char *add,
217 size_t add_len,
218 const unsigned char *tag,
219 size_t tag_len,
220 const unsigned char *input,
221 unsigned char *output);
222
237 int mode,
238 const unsigned char *iv,
239 size_t iv_len);
240
262 const unsigned char *add,
263 size_t add_len);
264
319 const unsigned char *input, size_t input_length,
320 unsigned char *output, size_t output_size,
321 size_t *output_length);
322
357 unsigned char *output, size_t output_size,
358 size_t *output_length,
359 unsigned char *tag, size_t tag_len);
360
369
370#if defined(MBEDTLS_SELF_TEST)
371
378int mbedtls_gcm_self_test(int verbose);
379
380#endif /* MBEDTLS_SELF_TEST */
381
382#ifdef __cplusplus
383}
384#endif
385
386
387#endif /* gcm.h */
Internal abstraction layer.
This file contains an abstraction interface for use with the cipher primitives provided by the librar...
mbedtls_cipher_id_t
Supported cipher types.
Definition: cipher.h:66
#define MBEDTLS_GCM_HTABLE_SIZE
Definition: gcm.h:52
int mbedtls_gcm_update(mbedtls_gcm_context *ctx, const unsigned char *input, size_t input_length, unsigned char *output, size_t output_size, size_t *output_length)
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.
int mbedtls_gcm_finish(mbedtls_gcm_context *ctx, unsigned char *output, size_t output_size, size_t *output_length, unsigned char *tag, size_t tag_len)
This function finishes the GCM operation and generates the authentication 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.
int mbedtls_gcm_update_ad(mbedtls_gcm_context *ctx, const unsigned char *add, size_t add_len)
This function feeds an input buffer as associated data (authenticated but not encrypted data) in a GC...
int mbedtls_gcm_starts(mbedtls_gcm_context *ctx, int mode, const unsigned char *iv, size_t iv_len)
This function starts a GCM encryption or decryption operation.
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_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_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.
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.
Build-time configuration info.
Macro wrapper for struct's members.
#define MBEDTLS_PRIVATE(member)
The GCM context structure.
Definition: gcm.h:58