aesni.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #include "aes.h"
  28. #define MBEDTLS_AESNI_AES 0x02000000u
  29. #define MBEDTLS_AESNI_CLMUL 0x00000002u
  30. #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \
  31. ( defined(__amd64__) || defined(__x86_64__) ) && \
  32. ! defined(MBEDTLS_HAVE_X86_64)
  33. #define MBEDTLS_HAVE_X86_64
  34. #endif
  35. #if defined(MBEDTLS_HAVE_X86_64)
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. /**
  40. * \brief AES-NI features detection routine
  41. *
  42. * \param what The feature to detect
  43. * (MBEDTLS_AESNI_AES or MBEDTLS_AESNI_CLMUL)
  44. *
  45. * \return 1 if CPU has support for the feature, 0 otherwise
  46. */
  47. int mbedtls_aesni_has_support( unsigned int what );
  48. /**
  49. * \brief AES-NI AES-ECB block en(de)cryption
  50. *
  51. * \param ctx AES context
  52. * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
  53. * \param input 16-byte input block
  54. * \param output 16-byte output block
  55. *
  56. * \return 0 on success (cannot fail)
  57. */
  58. int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx,
  59. int mode,
  60. const unsigned char input[16],
  61. unsigned char output[16] );
  62. /**
  63. * \brief GCM multiplication: c = a * b in GF(2^128)
  64. *
  65. * \param c Result
  66. * \param a First operand
  67. * \param b Second operand
  68. *
  69. * \note Both operands and result are bit strings interpreted as
  70. * elements of GF(2^128) as per the GCM spec.
  71. */
  72. void mbedtls_aesni_gcm_mult( unsigned char c[16],
  73. const unsigned char a[16],
  74. const unsigned char b[16] );
  75. /**
  76. * \brief Compute decryption round keys from encryption round keys
  77. *
  78. * \param invkey Round keys for the equivalent inverse cipher
  79. * \param fwdkey Original round keys (for encryption)
  80. * \param nr Number of rounds (that is, number of round keys minus one)
  81. */
  82. void mbedtls_aesni_inverse_key( unsigned char *invkey,
  83. const unsigned char *fwdkey, int nr );
  84. /**
  85. * \brief Perform key expansion (for encryption)
  86. *
  87. * \param rk Destination buffer where the round keys are written
  88. * \param key Encryption key
  89. * \param bits Key size in bits (must be 128, 192 or 256)
  90. *
  91. * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
  92. */
  93. int mbedtls_aesni_setkey_enc( unsigned char *rk,
  94. const unsigned char *key,
  95. size_t bits );
  96. #ifdef __cplusplus
  97. }
  98. #endif
  99. #endif /* MBEDTLS_HAVE_X86_64 */
  100. #endif /* MBEDTLS_AESNI_H */