mbed TLS v2.28.4
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 /* Can we do AESNI with inline assembly?
40  * (Only implemented with gas syntax, only for 64-bit.)
41  */
42 #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \
43  (defined(__amd64__) || defined(__x86_64__)) && \
44  !defined(MBEDTLS_HAVE_X86_64)
45 #define MBEDTLS_HAVE_X86_64
46 #endif
47 
48 #if defined(MBEDTLS_AESNI_C)
49 
50 /* Can we do AESNI with intrinsics?
51  * (Only implemented with certain compilers, only for certain targets.)
52  *
53  * NOTE: MBEDTLS_AESNI_HAVE_INTRINSICS and MBEDTLS_AESNI_HAVE_CODE are internal
54  * macros that may change in future releases.
55  */
56 #undef MBEDTLS_AESNI_HAVE_INTRINSICS
57 #if defined(_MSC_VER)
58 /* Visual Studio supports AESNI intrinsics since VS 2008 SP1. We only support
59  * VS 2013 and up for other reasons anyway, so no need to check the version. */
60 #define MBEDTLS_AESNI_HAVE_INTRINSICS
61 #endif
62 /* GCC-like compilers: currently, we only support intrinsics if the requisite
63  * target flag is enabled when building the library (e.g. `gcc -mpclmul -msse2`
64  * or `clang -maes -mpclmul`). */
65 #if defined(__GNUC__) && defined(__AES__) && defined(__PCLMUL__)
66 #define MBEDTLS_AESNI_HAVE_INTRINSICS
67 #endif
68 
69 /* Choose the implementation of AESNI, if one is available. */
70 #undef MBEDTLS_AESNI_HAVE_CODE
71 /* To minimize disruption when releasing the intrinsics-based implementation,
72  * favor the assembly-based implementation if it's available. We intend to
73  * revise this in a later release of Mbed TLS 3.x. In the long run, we will
74  * likely remove the assembly implementation. */
75 #if defined(MBEDTLS_HAVE_X86_64)
76 #define MBEDTLS_AESNI_HAVE_CODE 1 // via assembly
77 #elif defined(MBEDTLS_AESNI_HAVE_INTRINSICS)
78 #define MBEDTLS_AESNI_HAVE_CODE 2 // via intrinsics
79 #endif
80 
81 #if defined(MBEDTLS_AESNI_HAVE_CODE)
82 
83 #ifdef __cplusplus
84 extern "C" {
85 #endif
86 
98 int mbedtls_aesni_has_support(unsigned int what);
99 
113 int mbedtls_aesni_crypt_ecb(mbedtls_aes_context *ctx,
114  int mode,
115  const unsigned char input[16],
116  unsigned char output[16]);
117 
131 void mbedtls_aesni_gcm_mult(unsigned char c[16],
132  const unsigned char a[16],
133  const unsigned char b[16]);
134 
146 void mbedtls_aesni_inverse_key(unsigned char *invkey,
147  const unsigned char *fwdkey,
148  int nr);
149 
162 int mbedtls_aesni_setkey_enc(unsigned char *rk,
163  const unsigned char *key,
164  size_t bits);
165 
166 #ifdef __cplusplus
167 }
168 #endif
169 
170 #endif /* MBEDTLS_AESNI_HAVE_CODE */
171 #endif /* MBEDTLS_AESNI_C */
172 
173 #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