mbed TLS v2.16.7
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: Apache-2.0 OR GPL-2.0-or-later
17  *
18  * This file is provided under the Apache License 2.0, or the
19  * GNU General Public License v2.0 or later.
20  *
21  * **********
22  * Apache License 2.0:
23  *
24  * Licensed under the Apache License, Version 2.0 (the "License"); you may
25  * not use this file except in compliance with the License.
26  * You may obtain a copy of the License at
27  *
28  * http://www.apache.org/licenses/LICENSE-2.0
29  *
30  * Unless required by applicable law or agreed to in writing, software
31  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
32  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33  * See the License for the specific language governing permissions and
34  * limitations under the License.
35  *
36  * **********
37  *
38  * **********
39  * GNU General Public License v2.0 or later:
40  *
41  * This program is free software; you can redistribute it and/or modify
42  * it under the terms of the GNU General Public License as published by
43  * the Free Software Foundation; either version 2 of the License, or
44  * (at your option) any later version.
45  *
46  * This program is distributed in the hope that it will be useful,
47  * but WITHOUT ANY WARRANTY; without even the implied warranty of
48  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49  * GNU General Public License for more details.
50  *
51  * You should have received a copy of the GNU General Public License along
52  * with this program; if not, write to the Free Software Foundation, Inc.,
53  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
54  *
55  * **********
56  *
57  * This file is part of Mbed TLS (https://tls.mbed.org)
58  */
59 
60 #ifndef MBEDTLS_GCM_H
61 #define MBEDTLS_GCM_H
62 
63 #if !defined(MBEDTLS_CONFIG_FILE)
64 #include "config.h"
65 #else
66 #include MBEDTLS_CONFIG_FILE
67 #endif
68 
69 #include "cipher.h"
70 
71 #include <stdint.h>
72 
73 #define MBEDTLS_GCM_ENCRYPT 1
74 #define MBEDTLS_GCM_DECRYPT 0
75 
76 #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
78 /* MBEDTLS_ERR_GCM_HW_ACCEL_FAILED is deprecated and should not be used. */
79 #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013
81 #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
83 #ifdef __cplusplus
84 extern "C" {
85 #endif
86 
87 #if !defined(MBEDTLS_GCM_ALT)
88 
92 typedef struct mbedtls_gcm_context
93 {
95  uint64_t HL[16];
96  uint64_t HH[16];
97  uint64_t len;
98  uint64_t add_len;
99  unsigned char base_ectr[16];
100  unsigned char y[16];
101  unsigned char buf[16];
102  int mode;
105 }
107 
108 #else /* !MBEDTLS_GCM_ALT */
109 #include "gcm_alt.h"
110 #endif /* !MBEDTLS_GCM_ALT */
111 
124 
142  mbedtls_cipher_id_t cipher,
143  const unsigned char *key,
144  unsigned int keybits );
145 
198  int mode,
199  size_t length,
200  const unsigned char *iv,
201  size_t iv_len,
202  const unsigned char *add,
203  size_t add_len,
204  const unsigned char *input,
205  unsigned char *output,
206  size_t tag_len,
207  unsigned char *tag );
208 
243  size_t length,
244  const unsigned char *iv,
245  size_t iv_len,
246  const unsigned char *add,
247  size_t add_len,
248  const unsigned char *tag,
249  size_t tag_len,
250  const unsigned char *input,
251  unsigned char *output );
252 
271  int mode,
272  const unsigned char *iv,
273  size_t iv_len,
274  const unsigned char *add,
275  size_t add_len );
276 
303  size_t length,
304  const unsigned char *input,
305  unsigned char *output );
306 
324  unsigned char *tag,
325  size_t tag_len );
326 
335 
336 #if defined(MBEDTLS_SELF_TEST)
337 
344 int mbedtls_gcm_self_test( int verbose );
345 
346 #endif /* MBEDTLS_SELF_TEST */
347 
348 #ifdef __cplusplus
349 }
350 #endif
351 
352 
353 #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:102
mbedtls_cipher_id_t
mbedtls_cipher_id_t
Supported cipher types.
Definition: cipher.h:111
mbedtls_gcm_context::add_len
uint64_t add_len
Definition: gcm.h:98
mbedtls_gcm_context::HL
uint64_t HL[16]
Definition: gcm.h:95
mbedtls_gcm_context
The GCM context structure.
Definition: gcm.h:93
mbedtls_gcm_context::len
uint64_t len
Definition: gcm.h:97
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:101
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:312
mbedtls_gcm_context::y
unsigned char y[16]
Definition: gcm.h:100
config.h
Configuration options (set of defines)
mbedtls_gcm_context::HH
uint64_t HH[16]
Definition: gcm.h:96
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:94
mbedtls_gcm_context::base_ectr
unsigned char base_ectr[16]
Definition: gcm.h:99
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.