Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers aesni.h Source File

aesni.h

Go to the documentation of this file.
00001 /**
00002  * \file aesni.h
00003  *
00004  * \brief AES-NI for hardware AES acceleration on some Intel processors
00005  *
00006  * \warning These functions are only for internal use by other library
00007  *          functions; you must not call them directly.
00008  */
00009 /*
00010  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
00011  *  SPDX-License-Identifier: Apache-2.0
00012  *
00013  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
00014  *  not use this file except in compliance with the License.
00015  *  You may obtain a copy of the License at
00016  *
00017  *  http://www.apache.org/licenses/LICENSE-2.0
00018  *
00019  *  Unless required by applicable law or agreed to in writing, software
00020  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00021  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022  *  See the License for the specific language governing permissions and
00023  *  limitations under the License.
00024  *
00025  *  This file is part of mbed TLS (https://tls.mbed.org)
00026  */
00027 #ifndef MBEDTLS_AESNI_H
00028 #define MBEDTLS_AESNI_H
00029 
00030 #if !defined(MBEDTLS_CONFIG_FILE)
00031 #include "mbedtls/config.h"
00032 #else
00033 #include MBEDTLS_CONFIG_FILE
00034 #endif
00035 
00036 #include "mbedtls/aes.h"
00037 
00038 #define MBEDTLS_AESNI_AES      0x02000000u
00039 #define MBEDTLS_AESNI_CLMUL    0x00000002u
00040 
00041 #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) &&  \
00042     ( defined(__amd64__) || defined(__x86_64__) )   &&  \
00043     ! defined(MBEDTLS_HAVE_X86_64)
00044 #define MBEDTLS_HAVE_X86_64
00045 #endif
00046 
00047 #if defined(MBEDTLS_HAVE_X86_64)
00048 
00049 #ifdef __cplusplus
00050 extern "C" {
00051 #endif
00052 
00053 /**
00054  * \brief          Internal function to detect the AES-NI feature in CPUs.
00055  *
00056  * \note           This function is only for internal use by other library
00057  *                 functions; you must not call it directly.
00058  *
00059  * \param what     The feature to detect
00060  *                 (MBEDTLS_AESNI_AES or MBEDTLS_AESNI_CLMUL)
00061  *
00062  * \return         1 if CPU has support for the feature, 0 otherwise
00063  */
00064 int mbedtls_aesni_has_support( unsigned int what );
00065 
00066 /**
00067  * \brief          Internal AES-NI AES-ECB block encryption and decryption
00068  *
00069  * \note           This function is only for internal use by other library
00070  *                 functions; you must not call it directly.
00071  *
00072  * \param ctx      AES context
00073  * \param mode     MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
00074  * \param input    16-byte input block
00075  * \param output   16-byte output block
00076  *
00077  * \return         0 on success (cannot fail)
00078  */
00079 int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx,
00080                              int mode,
00081                              const unsigned char input[16],
00082                              unsigned char output[16] );
00083 
00084 /**
00085  * \brief          Internal GCM multiplication: c = a * b in GF(2^128)
00086  *
00087  * \note           This function is only for internal use by other library
00088  *                 functions; you must not call it directly.
00089  *
00090  * \param c        Result
00091  * \param a        First operand
00092  * \param b        Second operand
00093  *
00094  * \note           Both operands and result are bit strings interpreted as
00095  *                 elements of GF(2^128) as per the GCM spec.
00096  */
00097 void mbedtls_aesni_gcm_mult( unsigned char c[16],
00098                              const unsigned char a[16],
00099                              const unsigned char b[16] );
00100 
00101 /**
00102  * \brief           Internal round key inversion. This function computes
00103  *                  decryption round keys from the encryption round keys.
00104  *
00105  * \note            This function is only for internal use by other library
00106  *                  functions; you must not call it directly.
00107  *
00108  * \param invkey    Round keys for the equivalent inverse cipher
00109  * \param fwdkey    Original round keys (for encryption)
00110  * \param nr        Number of rounds (that is, number of round keys minus one)
00111  */
00112 void mbedtls_aesni_inverse_key( unsigned char *invkey,
00113                                 const unsigned char *fwdkey,
00114                                 int nr );
00115 
00116 /**
00117  * \brief           Internal key expansion for encryption
00118  *
00119  * \note            This function is only for internal use by other library
00120  *                  functions; you must not call it directly.
00121  *
00122  * \param rk        Destination buffer where the round keys are written
00123  * \param key       Encryption key
00124  * \param bits      Key size in bits (must be 128, 192 or 256)
00125  *
00126  * \return          0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
00127  */
00128 int mbedtls_aesni_setkey_enc( unsigned char *rk,
00129                               const unsigned char *key,
00130                               size_t bits );
00131 
00132 #ifdef __cplusplus
00133 }
00134 #endif
00135 
00136 #endif /* MBEDTLS_HAVE_X86_64 */
00137 
00138 #endif /* MBEDTLS_AESNI_H */