[MBEDTLS]
[reactos.git] / reactos / sdk / include / reactos / libs / mbedtls / aesni.h
1 /**
2 * \file aesni.h
3 *
4 * \brief AES-NI for hardware AES acceleration on some Intel processors
5 *
6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
7 * SPDX-License-Identifier: GPL-2.0
8 *
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.
13 *
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.
18 *
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.
22 *
23 * This file is part of mbed TLS (https://tls.mbed.org)
24 */
25 #ifndef MBEDTLS_AESNI_H
26 #define MBEDTLS_AESNI_H
27
28 #include "aes.h"
29
30 #define MBEDTLS_AESNI_AES 0x02000000u
31 #define MBEDTLS_AESNI_CLMUL 0x00000002u
32
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
37 #endif
38
39 #if defined(MBEDTLS_HAVE_X86_64)
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /**
46 * \brief AES-NI features detection routine
47 *
48 * \param what The feature to detect
49 * (MBEDTLS_AESNI_AES or MBEDTLS_AESNI_CLMUL)
50 *
51 * \return 1 if CPU has support for the feature, 0 otherwise
52 */
53 int mbedtls_aesni_has_support( unsigned int what );
54
55 /**
56 * \brief AES-NI AES-ECB block en(de)cryption
57 *
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
62 *
63 * \return 0 on success (cannot fail)
64 */
65 int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx,
66 int mode,
67 const unsigned char input[16],
68 unsigned char output[16] );
69
70 /**
71 * \brief GCM multiplication: c = a * b in GF(2^128)
72 *
73 * \param c Result
74 * \param a First operand
75 * \param b Second operand
76 *
77 * \note Both operands and result are bit strings interpreted as
78 * elements of GF(2^128) as per the GCM spec.
79 */
80 void mbedtls_aesni_gcm_mult( unsigned char c[16],
81 const unsigned char a[16],
82 const unsigned char b[16] );
83
84 /**
85 * \brief Compute decryption round keys from encryption round keys
86 *
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)
90 */
91 void mbedtls_aesni_inverse_key( unsigned char *invkey,
92 const unsigned char *fwdkey, int nr );
93
94 /**
95 * \brief Perform key expansion (for encryption)
96 *
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)
100 *
101 * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
102 */
103 int mbedtls_aesni_setkey_enc( unsigned char *rk,
104 const unsigned char *key,
105 size_t bits );
106
107 #ifdef __cplusplus
108 }
109 #endif
110
111 #endif /* MBEDTLS_HAVE_X86_64 */
112
113 #endif /* MBEDTLS_AESNI_H */