Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /**
  2.  * \file aesni.h
  3.  *
  4.  * \brief AES-NI for hardware AES acceleration on some Intel processors
  5.  *
  6.  * \warning These functions are only for internal use by other library
  7.  *          functions; you must not call them directly.
  8.  */
  9. /*
  10.  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  11.  *  SPDX-License-Identifier: GPL-2.0
  12.  *
  13.  *  This program is free software; you can redistribute it and/or modify
  14.  *  it under the terms of the GNU General Public License as published by
  15.  *  the Free Software Foundation; either version 2 of the License, or
  16.  *  (at your option) any later version.
  17.  *
  18.  *  This program is distributed in the hope that it will be useful,
  19.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  *  GNU General Public License for more details.
  22.  *
  23.  *  You should have received a copy of the GNU General Public License along
  24.  *  with this program; if not, write to the Free Software Foundation, Inc.,
  25.  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  26.  *
  27.  *  This file is part of mbed TLS (https://tls.mbed.org)
  28.  */
  29. #ifndef MBEDTLS_AESNI_H
  30. #define MBEDTLS_AESNI_H
  31.  
  32. #if !defined(MBEDTLS_CONFIG_FILE)
  33. #include "config.h"
  34. #else
  35. #include MBEDTLS_CONFIG_FILE
  36. #endif
  37.  
  38. #include "aes.h"
  39.  
  40. #define MBEDTLS_AESNI_AES      0x02000000u
  41. #define MBEDTLS_AESNI_CLMUL    0x00000002u
  42.  
  43. #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) &&  \
  44.     ( defined(__amd64__) || defined(__x86_64__) )   &&  \
  45.     ! defined(MBEDTLS_HAVE_X86_64)
  46. #define MBEDTLS_HAVE_X86_64
  47. #endif
  48.  
  49. #if defined(MBEDTLS_HAVE_X86_64)
  50.  
  51. #ifdef __cplusplus
  52. extern "C" {
  53. #endif
  54.  
  55. /**
  56.  * \brief          Internal function to detect the AES-NI feature in CPUs.
  57.  *
  58.  * \note           This function is only for internal use by other library
  59.  *                 functions; you must not call it directly.
  60.  *
  61.  * \param what     The feature to detect
  62.  *                 (MBEDTLS_AESNI_AES or MBEDTLS_AESNI_CLMUL)
  63.  *
  64.  * \return         1 if CPU has support for the feature, 0 otherwise
  65.  */
  66. int mbedtls_aesni_has_support( unsigned int what );
  67.  
  68. /**
  69.  * \brief          Internal AES-NI AES-ECB block encryption and decryption
  70.  *
  71.  * \note           This function is only for internal use by other library
  72.  *                 functions; you must not call it directly.
  73.  *
  74.  * \param ctx      AES context
  75.  * \param mode     MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
  76.  * \param input    16-byte input block
  77.  * \param output   16-byte output block
  78.  *
  79.  * \return         0 on success (cannot fail)
  80.  */
  81. int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx,
  82.                              int mode,
  83.                              const unsigned char input[16],
  84.                              unsigned char output[16] );
  85.  
  86. /**
  87.  * \brief          Internal GCM multiplication: c = a * b in GF(2^128)
  88.  *
  89.  * \note           This function is only for internal use by other library
  90.  *                 functions; you must not call it directly.
  91.  *
  92.  * \param c        Result
  93.  * \param a        First operand
  94.  * \param b        Second operand
  95.  *
  96.  * \note           Both operands and result are bit strings interpreted as
  97.  *                 elements of GF(2^128) as per the GCM spec.
  98.  */
  99. void mbedtls_aesni_gcm_mult( unsigned char c[16],
  100.                              const unsigned char a[16],
  101.                              const unsigned char b[16] );
  102.  
  103. /**
  104.  * \brief           Internal round key inversion. This function computes
  105.  *                  decryption round keys from the encryption round keys.
  106.  *
  107.  * \note            This function is only for internal use by other library
  108.  *                  functions; you must not call it directly.
  109.  *
  110.  * \param invkey    Round keys for the equivalent inverse cipher
  111.  * \param fwdkey    Original round keys (for encryption)
  112.  * \param nr        Number of rounds (that is, number of round keys minus one)
  113.  */
  114. void mbedtls_aesni_inverse_key( unsigned char *invkey,
  115.                                 const unsigned char *fwdkey,
  116.                                 int nr );
  117.  
  118. /**
  119.  * \brief           Internal key expansion for encryption
  120.  *
  121.  * \note            This function is only for internal use by other library
  122.  *                  functions; you must not call it directly.
  123.  *
  124.  * \param rk        Destination buffer where the round keys are written
  125.  * \param key       Encryption key
  126.  * \param bits      Key size in bits (must be 128, 192 or 256)
  127.  *
  128.  * \return          0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
  129.  */
  130. int mbedtls_aesni_setkey_enc( unsigned char *rk,
  131.                               const unsigned char *key,
  132.                               size_t bits );
  133.  
  134. #ifdef __cplusplus
  135. }
  136. #endif
  137.  
  138. #endif /* MBEDTLS_HAVE_X86_64 */
  139.  
  140. #endif /* MBEDTLS_AESNI_H */
  141.