mbed TLS v2.28.2
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 
34 #if !defined(MBEDTLS_CONFIG_FILE)
35 #include "mbedtls/config.h"
36 #else
37 #include MBEDTLS_CONFIG_FILE
38 #endif
39 
40 #include "mbedtls/cipher.h"
41 
42 #include <stdint.h>
43 
44 #define MBEDTLS_GCM_ENCRYPT 1
45 #define MBEDTLS_GCM_DECRYPT 0
46 
48 #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
49 
50 /* MBEDTLS_ERR_GCM_HW_ACCEL_FAILED is deprecated and should not be used. */
52 #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013
53 
55 #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
61 #if !defined(MBEDTLS_GCM_ALT)
62 
66 typedef struct mbedtls_gcm_context
67 {
69  uint64_t HL[16];
70  uint64_t HH[16];
71  uint64_t len;
72  uint64_t add_len;
73  unsigned char base_ectr[16];
74  unsigned char y[16];
75  unsigned char buf[16];
76  int mode;
79 }
81 
82 #else /* !MBEDTLS_GCM_ALT */
83 #include "gcm_alt.h"
84 #endif /* !MBEDTLS_GCM_ALT */
85 
98 
116  mbedtls_cipher_id_t cipher,
117  const unsigned char *key,
118  unsigned int keybits );
119 
172  int mode,
173  size_t length,
174  const unsigned char *iv,
175  size_t iv_len,
176  const unsigned char *add,
177  size_t add_len,
178  const unsigned char *input,
179  unsigned char *output,
180  size_t tag_len,
181  unsigned char *tag );
182 
217  size_t length,
218  const unsigned char *iv,
219  size_t iv_len,
220  const unsigned char *add,
221  size_t add_len,
222  const unsigned char *tag,
223  size_t tag_len,
224  const unsigned char *input,
225  unsigned char *output );
226 
245  int mode,
246  const unsigned char *iv,
247  size_t iv_len,
248  const unsigned char *add,
249  size_t add_len );
250 
277  size_t length,
278  const unsigned char *input,
279  unsigned char *output );
280 
298  unsigned char *tag,
299  size_t tag_len );
300 
309 
310 #if defined(MBEDTLS_SELF_TEST)
311 
318 int mbedtls_gcm_self_test( int verbose );
319 
320 #endif /* MBEDTLS_SELF_TEST */
321 
322 #ifdef __cplusplus
323 }
324 #endif
325 
326 
327 #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:90
Configuration options (set of defines)
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.
struct mbedtls_gcm_context mbedtls_gcm_context
The GCM context structure.
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_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_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.
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.
The GCM context structure.
Definition: gcm.h:67
unsigned char base_ectr[16]
Definition: gcm.h:73
unsigned char y[16]
Definition: gcm.h:74
mbedtls_cipher_context_t cipher_ctx
Definition: gcm.h:68
uint64_t HH[16]
Definition: gcm.h:70
unsigned char buf[16]
Definition: gcm.h:75
uint64_t len
Definition: gcm.h:71
uint64_t add_len
Definition: gcm.h:72
uint64_t HL[16]
Definition: gcm.h:69