mbed TLS v2.12.0

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
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 * This file is part of Mbed TLS (https://tls.mbed.org)
31 */
32
33 #ifndef MBEDTLS_GCM_H
34 #define MBEDTLS_GCM_H
35
36 #include "cipher.h"
37
38 #include <stdint.h>
39
40 #define MBEDTLS_GCM_ENCRYPT 1
41 #define MBEDTLS_GCM_DECRYPT 0
42
43 #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
44 #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013
45 #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 #if !defined(MBEDTLS_GCM_ALT)
52
56 typedef struct {
57 mbedtls_cipher_context_t cipher_ctx;
58 uint64_t HL[16];
59 uint64_t HH[16];
60 uint64_t len;
61 uint64_t add_len;
62 unsigned char base_ectr[16];
63 unsigned char y[16];
64 unsigned char buf[16];
65 int mode;
68 }
69 mbedtls_gcm_context;
70
71 #else /* !MBEDTLS_GCM_ALT */
72 #include "gcm_alt.h"
73 #endif /* !MBEDTLS_GCM_ALT */
74
86 void mbedtls_gcm_init( mbedtls_gcm_context *ctx );
87
103 int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx,
104 mbedtls_cipher_id_t cipher,
105 const unsigned char *key,
106 unsigned int keybits );
107
152 int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx,
153 int mode,
154 size_t length,
155 const unsigned char *iv,
156 size_t iv_len,
157 const unsigned char *add,
158 size_t add_len,
159 const unsigned char *input,
160 unsigned char *output,
161 size_t tag_len,
162 unsigned char *tag );
163
191 int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx,
192 size_t length,
193 const unsigned char *iv,
194 size_t iv_len,
195 const unsigned char *add,
196 size_t add_len,
197 const unsigned char *tag,
198 size_t tag_len,
199 const unsigned char *input,
200 unsigned char *output );
201
218 int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
219 int mode,
220 const unsigned char *iv,
221 size_t iv_len,
222 const unsigned char *add,
223 size_t add_len );
224
246 int mbedtls_gcm_update( mbedtls_gcm_context *ctx,
247 size_t length,
248 const unsigned char *input,
249 unsigned char *output );
250
265 int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
266 unsigned char *tag,
267 size_t tag_len );
268
275 void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
276
283 int mbedtls_gcm_self_test( int verbose );
284
285 #ifdef __cplusplus
286 }
287 #endif
288
289
290 #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_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_self_test
int mbedtls_gcm_self_test(int verbose)
The GCM checkup routine.
mbedtls_gcm_free
void mbedtls_gcm_free(mbedtls_gcm_context *ctx)
This function clears a GCM context and the underlying cipher sub-context.
mbedtls_cipher_context_t
Definition: cipher.h:279
mbedtls_gcm_context
The GCM context structure.
Definition: gcm.h:56
mbedtls_gcm_context::cipher_ctx
mbedtls_cipher_context_t cipher_ctx
Definition: gcm.h:57
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_context::add_len
uint64_t add_len
Definition: gcm.h:61
mbedtls_cipher_id_t
mbedtls_cipher_id_t
Supported cipher types.
Definition: cipher.h:80
cipher.h
This file contains an abstraction interface for use with the cipher primitives provided by the librar...
mbedtls_gcm_context::len
uint64_t len
Definition: gcm.h:60
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_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.
mbedtls_gcm_context::mode
int mode
Definition: gcm.h:65
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.
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.