b1b7f1cdec6f859bde9d5a8f51fb94d53d223ff7
4 * \brief AES-NI for hardware AES acceleration on some Intel processors
6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
7 * SPDX-License-Identifier: Apache-2.0
9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
10 * not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * This file is part of mbed TLS (https://tls.mbed.org)
23 #ifndef MBEDTLS_AESNI_H
24 #define MBEDTLS_AESNI_H
28 #define MBEDTLS_AESNI_AES 0x02000000u
29 #define MBEDTLS_AESNI_CLMUL 0x00000002u
31 #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \
32 ( defined(__amd64__) || defined(__x86_64__) ) && \
33 ! defined(MBEDTLS_HAVE_X86_64)
34 #define MBEDTLS_HAVE_X86_64
37 #if defined(MBEDTLS_HAVE_X86_64)
44 * \brief AES-NI features detection routine
46 * \param what The feature to detect
47 * (MBEDTLS_AESNI_AES or MBEDTLS_AESNI_CLMUL)
49 * \return 1 if CPU has support for the feature, 0 otherwise
51 int mbedtls_aesni_has_support( unsigned int what
);
54 * \brief AES-NI AES-ECB block en(de)cryption
56 * \param ctx AES context
57 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
58 * \param input 16-byte input block
59 * \param output 16-byte output block
61 * \return 0 on success (cannot fail)
63 int mbedtls_aesni_crypt_ecb( mbedtls_aes_context
*ctx
,
65 const unsigned char input
[16],
66 unsigned char output
[16] );
69 * \brief GCM multiplication: c = a * b in GF(2^128)
72 * \param a First operand
73 * \param b Second operand
75 * \note Both operands and result are bit strings interpreted as
76 * elements of GF(2^128) as per the GCM spec.
78 void mbedtls_aesni_gcm_mult( unsigned char c
[16],
79 const unsigned char a
[16],
80 const unsigned char b
[16] );
83 * \brief Compute decryption round keys from encryption round keys
85 * \param invkey Round keys for the equivalent inverse cipher
86 * \param fwdkey Original round keys (for encryption)
87 * \param nr Number of rounds (that is, number of round keys minus one)
89 void mbedtls_aesni_inverse_key( unsigned char *invkey
,
90 const unsigned char *fwdkey
, int nr
);
93 * \brief Perform key expansion (for encryption)
95 * \param rk Destination buffer where the round keys are written
96 * \param key Encryption key
97 * \param bits Key size in bits (must be 128, 192 or 256)
99 * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
101 int mbedtls_aesni_setkey_enc( unsigned char *rk
,
102 const unsigned char *key
,
109 #endif /* MBEDTLS_HAVE_X86_64 */
111 #endif /* MBEDTLS_AESNI_H */