Mbed TLS v3.5.0
gcm.h
Go to the documentation of this file.
1 
14 /*
15  * Copyright The Mbed TLS Contributors
16  * SPDX-License-Identifier: Apache-2.0
17  *
18  * Licensed under the Apache License, Version 2.0 (the "License"); you may
19  * not use this file except in compliance with the License.
20  * You may obtain a copy of the License at
21  *
22  * http://www.apache.org/licenses/LICENSE-2.0
23  *
24  * Unless required by applicable law or agreed to in writing, software
25  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
26  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27  * See the License for the specific language governing permissions and
28  * limitations under the License.
29  */
30 
31 #ifndef MBEDTLS_GCM_H
32 #define MBEDTLS_GCM_H
33 #include "mbedtls/private_access.h"
34 
35 #include "mbedtls/build_info.h"
36 
37 #include "mbedtls/cipher.h"
38 
39 #include <stdint.h>
40 
41 #define MBEDTLS_GCM_ENCRYPT 1
42 #define MBEDTLS_GCM_DECRYPT 0
43 
45 #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
47 #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
49 #define MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL -0x0016
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 #if !defined(MBEDTLS_GCM_ALT)
56 
60 typedef struct mbedtls_gcm_context {
62  uint64_t MBEDTLS_PRIVATE(HL)[16];
63  uint64_t MBEDTLS_PRIVATE(HH)[16];
64  uint64_t MBEDTLS_PRIVATE(len);
65  uint64_t MBEDTLS_PRIVATE(add_len);
66  unsigned char MBEDTLS_PRIVATE(base_ectr)[16];
67  unsigned char MBEDTLS_PRIVATE(y)[16];
68  unsigned char MBEDTLS_PRIVATE(buf)[16];
69  int MBEDTLS_PRIVATE(mode);
72 }
74 
75 #else /* !MBEDTLS_GCM_ALT */
76 #include "gcm_alt.h"
77 #endif /* !MBEDTLS_GCM_ALT */
78 
91 
109  mbedtls_cipher_id_t cipher,
110  const unsigned char *key,
111  unsigned int keybits);
112 
165  int mode,
166  size_t length,
167  const unsigned char *iv,
168  size_t iv_len,
169  const unsigned char *add,
170  size_t add_len,
171  const unsigned char *input,
172  unsigned char *output,
173  size_t tag_len,
174  unsigned char *tag);
175 
210  size_t length,
211  const unsigned char *iv,
212  size_t iv_len,
213  const unsigned char *add,
214  size_t add_len,
215  const unsigned char *tag,
216  size_t tag_len,
217  const unsigned char *input,
218  unsigned char *output);
219 
234  int mode,
235  const unsigned char *iv,
236  size_t iv_len);
237 
259  const unsigned char *add,
260  size_t add_len);
261 
314  const unsigned char *input, size_t input_length,
315  unsigned char *output, size_t output_size,
316  size_t *output_length);
317 
352  unsigned char *output, size_t output_size,
353  size_t *output_length,
354  unsigned char *tag, size_t tag_len);
355 
364 
365 #if defined(MBEDTLS_SELF_TEST)
366 
373 int mbedtls_gcm_self_test(int verbose);
374 
375 #endif /* MBEDTLS_SELF_TEST */
376 
377 #ifdef __cplusplus
378 }
379 #endif
380 
381 
382 #endif /* gcm.h */
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:78
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:60