Mbed TLS v2.28.5
aesni.h
Go to the documentation of this file.
1
9/*
10 * Copyright The Mbed TLS Contributors
11 * SPDX-License-Identifier: Apache-2.0
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License"); you may
14 * not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
21 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 */
25#ifndef MBEDTLS_AESNI_H
26#define MBEDTLS_AESNI_H
27
28#if !defined(MBEDTLS_CONFIG_FILE)
29#include "mbedtls/config.h"
30#else
31#include MBEDTLS_CONFIG_FILE
32#endif
33
34#include "mbedtls/aes.h"
35
36#define MBEDTLS_AESNI_AES 0x02000000u
37#define MBEDTLS_AESNI_CLMUL 0x00000002u
38
39#if !defined(MBEDTLS_HAVE_X86_64) && \
40 (defined(__amd64__) || defined(__x86_64__) || \
41 defined(_M_X64) || defined(_M_AMD64)) && \
42 !defined(_M_ARM64EC)
43#define MBEDTLS_HAVE_X86_64
44#endif
45
46#if !defined(MBEDTLS_HAVE_X86) && \
47 (defined(__i386__) || defined(_M_IX86))
48#define MBEDTLS_HAVE_X86
49#endif
50
51#if defined(MBEDTLS_AESNI_C) && \
52 (defined(MBEDTLS_HAVE_X86_64) || defined(MBEDTLS_HAVE_X86))
53
54/* Can we do AESNI with intrinsics?
55 * (Only implemented with certain compilers, only for certain targets.)
56 *
57 * NOTE: MBEDTLS_AESNI_HAVE_INTRINSICS and MBEDTLS_AESNI_HAVE_CODE are internal
58 * macros that may change in future releases.
59 */
60#undef MBEDTLS_AESNI_HAVE_INTRINSICS
61#if defined(_MSC_VER)
62/* Visual Studio supports AESNI intrinsics since VS 2008 SP1. We only support
63 * VS 2013 and up for other reasons anyway, so no need to check the version. */
64#define MBEDTLS_AESNI_HAVE_INTRINSICS
65#endif
66/* GCC-like compilers: currently, we only support intrinsics if the requisite
67 * target flag is enabled when building the library (e.g. `gcc -mpclmul -msse2`
68 * or `clang -maes -mpclmul`). */
69#if defined(__GNUC__) && defined(__AES__) && defined(__PCLMUL__)
70#define MBEDTLS_AESNI_HAVE_INTRINSICS
71#endif
72
73/* Choose the implementation of AESNI, if one is available. */
74#undef MBEDTLS_AESNI_HAVE_CODE
75/* To minimize disruption when releasing the intrinsics-based implementation,
76 * favor the assembly-based implementation if it's available. We intend to
77 * revise this in a later release of Mbed TLS 3.x. In the long run, we will
78 * likely remove the assembly implementation. */
79#if defined(MBEDTLS_HAVE_ASM) && \
80 defined(__GNUC__) && defined(MBEDTLS_HAVE_X86_64)
81/* Can we do AESNI with inline assembly?
82 * (Only implemented with gas syntax, only for 64-bit.)
83 */
84#define MBEDTLS_AESNI_HAVE_CODE 1 // via assembly
85#elif defined(MBEDTLS_AESNI_HAVE_INTRINSICS)
86#define MBEDTLS_AESNI_HAVE_CODE 2 // via intrinsics
87#endif
88
89#if defined(MBEDTLS_AESNI_HAVE_CODE)
90
91#ifdef __cplusplus
92extern "C" {
93#endif
94
106int mbedtls_aesni_has_support(unsigned int what);
107
121int mbedtls_aesni_crypt_ecb(mbedtls_aes_context *ctx,
122 int mode,
123 const unsigned char input[16],
124 unsigned char output[16]);
125
139void mbedtls_aesni_gcm_mult(unsigned char c[16],
140 const unsigned char a[16],
141 const unsigned char b[16]);
142
154void mbedtls_aesni_inverse_key(unsigned char *invkey,
155 const unsigned char *fwdkey,
156 int nr);
157
170int mbedtls_aesni_setkey_enc(unsigned char *rk,
171 const unsigned char *key,
172 size_t bits);
173
174#ifdef __cplusplus
175}
176#endif
177
178#endif /* MBEDTLS_AESNI_HAVE_CODE */
179#endif /* MBEDTLS_AESNI_C && (MBEDTLS_HAVE_X86_64 || MBEDTLS_HAVE_X86) */
180
181#endif /* MBEDTLS_AESNI_H */
This file contains AES definitions and functions.
Configuration options (set of defines)
The AES context-type definition.
Definition: aes.h:91