4 * \brief AES-NI for hardware AES acceleration on some Intel processors
6 * \warning These functions are only for internal use by other library
7 * functions; you must not call them directly.
10 * Copyright The Mbed TLS Contributors
11 * SPDX-License-Identifier: Apache-2.0
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
17 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 #ifndef MBEDTLS_AESNI_H
26 #define MBEDTLS_AESNI_H
28 #if !defined(MBEDTLS_CONFIG_FILE)
29 #include "mbedtls/config.h"
31 #include MBEDTLS_CONFIG_FILE
34 #include "mbedtls/aes.h"
36 #define MBEDTLS_AESNI_AES 0x02000000u
37 #define MBEDTLS_AESNI_CLMUL 0x00000002u
39 #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \
40 ( defined(__amd64__) || defined(__x86_64__) ) && \
41 ! defined(MBEDTLS_HAVE_X86_64)
42 #define MBEDTLS_HAVE_X86_64
45 #if defined(MBEDTLS_HAVE_X86_64)
52 * \brief Internal function to detect the AES-NI feature in CPUs.
54 * \note This function is only for internal use by other library
55 * functions; you must not call it directly.
57 * \param what The feature to detect
58 * (MBEDTLS_AESNI_AES or MBEDTLS_AESNI_CLMUL)
60 * \return 1 if CPU has support for the feature, 0 otherwise
62 int mbedtls_aesni_has_support(unsigned int what
);
65 * \brief Internal AES-NI AES-ECB block encryption and decryption
67 * \note This function is only for internal use by other library
68 * functions; you must not call it directly.
70 * \param ctx AES context
71 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
72 * \param input 16-byte input block
73 * \param output 16-byte output block
75 * \return 0 on success (cannot fail)
77 int mbedtls_aesni_crypt_ecb(mbedtls_aes_context
*ctx
,
79 const unsigned char input
[16],
80 unsigned char output
[16]);
83 * \brief Internal GCM multiplication: c = a * b in GF(2^128)
85 * \note This function is only for internal use by other library
86 * functions; you must not call it directly.
89 * \param a First operand
90 * \param b Second operand
92 * \note Both operands and result are bit strings interpreted as
93 * elements of GF(2^128) as per the GCM spec.
95 void mbedtls_aesni_gcm_mult(unsigned char c
[16],
96 const unsigned char a
[16],
97 const unsigned char b
[16]);
100 * \brief Internal round key inversion. This function computes
101 * decryption round keys from the encryption round keys.
103 * \note This function is only for internal use by other library
104 * functions; you must not call it directly.
106 * \param invkey Round keys for the equivalent inverse cipher
107 * \param fwdkey Original round keys (for encryption)
108 * \param nr Number of rounds (that is, number of round keys minus one)
110 void mbedtls_aesni_inverse_key(unsigned char *invkey
,
111 const unsigned char *fwdkey
,
115 * \brief Internal key expansion for encryption
117 * \note This function is only for internal use by other library
118 * functions; you must not call it directly.
120 * \param rk Destination buffer where the round keys are written
121 * \param key Encryption key
122 * \param bits Key size in bits (must be 128, 192 or 256)
124 * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
126 int mbedtls_aesni_setkey_enc(unsigned char *rk
,
127 const unsigned char *key
,
134 #endif /* MBEDTLS_HAVE_X86_64 */
136 #endif /* MBEDTLS_AESNI_H */