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: GPL-2.0
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * This file is part of mbed TLS (https://tls.mbed.org)
25 #ifndef MBEDTLS_AESNI_H
26 #define MBEDTLS_AESNI_H
30 #define MBEDTLS_AESNI_AES 0x02000000u
31 #define MBEDTLS_AESNI_CLMUL 0x00000002u
33 #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \
34 ( defined(__amd64__) || defined(__x86_64__) ) && \
35 ! defined(MBEDTLS_HAVE_X86_64)
36 #define MBEDTLS_HAVE_X86_64
39 #if defined(MBEDTLS_HAVE_X86_64)
46 * \brief AES-NI features detection routine
48 * \param what The feature to detect
49 * (MBEDTLS_AESNI_AES or MBEDTLS_AESNI_CLMUL)
51 * \return 1 if CPU has support for the feature, 0 otherwise
53 int mbedtls_aesni_has_support( unsigned int what
);
56 * \brief AES-NI AES-ECB block en(de)cryption
58 * \param ctx AES context
59 * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
60 * \param input 16-byte input block
61 * \param output 16-byte output block
63 * \return 0 on success (cannot fail)
65 int mbedtls_aesni_crypt_ecb( mbedtls_aes_context
*ctx
,
67 const unsigned char input
[16],
68 unsigned char output
[16] );
71 * \brief GCM multiplication: c = a * b in GF(2^128)
74 * \param a First operand
75 * \param b Second operand
77 * \note Both operands and result are bit strings interpreted as
78 * elements of GF(2^128) as per the GCM spec.
80 void mbedtls_aesni_gcm_mult( unsigned char c
[16],
81 const unsigned char a
[16],
82 const unsigned char b
[16] );
85 * \brief Compute decryption round keys from encryption round keys
87 * \param invkey Round keys for the equivalent inverse cipher
88 * \param fwdkey Original round keys (for encryption)
89 * \param nr Number of rounds (that is, number of round keys minus one)
91 void mbedtls_aesni_inverse_key( unsigned char *invkey
,
92 const unsigned char *fwdkey
, int nr
);
95 * \brief Perform key expansion (for encryption)
97 * \param rk Destination buffer where the round keys are written
98 * \param key Encryption key
99 * \param bits Key size in bits (must be 128, 192 or 256)
101 * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
103 int mbedtls_aesni_setkey_enc( unsigned char *rk
,
104 const unsigned char *key
,
111 #endif /* MBEDTLS_HAVE_X86_64 */
113 #endif /* MBEDTLS_AESNI_H */