aesni.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * This file is adapted from PolarSSL 1.3.19 (GPL)
  3. */
  4. /**
  5. * \file aesni.h
  6. *
  7. * \brief AES-NI for hardware AES acceleration on some Intel processors
  8. *
  9. * Copyright (C) 2013, ARM Limited, All Rights Reserved
  10. *
  11. * This file is part of mbed TLS (https://tls.mbed.org)
  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. #ifndef UDP2RAW_AESNI_H_
  28. #define UDP2RAW_AESNI_H_
  29. #ifndef AES_ENCRYPT
  30. #define AES_ENCRYPT 1
  31. #endif
  32. #ifndef AES_DECRYPT
  33. #define AES_DECRYPT 0
  34. #endif
  35. #if defined(__GNUC__) && \
  36. ( defined(__amd64__) || defined(__x86_64__) ) && \
  37. !defined(NO_AESACC)
  38. #define HAVE_AMD64
  39. #endif
  40. #if defined(HAVE_AMD64)
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /**
  45. * \brief AES-NI features detection routine
  46. *
  47. * \return 1 if CPU has support for AES-NI, 0 otherwise
  48. */
  49. int aesni_supported( void );
  50. /**
  51. * \brief AES-NI AES-ECB block en(de)cryption
  52. *
  53. * \param nr number of rounds
  54. * \param rk AES round keys
  55. * \param mode AES_ENCRYPT or AES_DECRYPT
  56. * \param input 16-byte input block
  57. * \param output 16-byte output block
  58. */
  59. void aesni_crypt_ecb( int nr,
  60. unsigned char *rk,
  61. int mode,
  62. const unsigned char input[16],
  63. unsigned char output[16] );
  64. /**
  65. * \brief Compute decryption round keys from encryption round keys
  66. *
  67. * \param invkey Round keys for the equivalent inverse cipher
  68. * \param fwdkey Original round keys (for encryption)
  69. * \param nr Number of rounds (that is, number of round keys minus one)
  70. */
  71. void aesni_inverse_key( unsigned char *invkey,
  72. const unsigned char *fwdkey, int nr );
  73. /**
  74. * \brief Perform 128-bit key expansion (for encryption)
  75. *
  76. * \param rk Destination buffer where the round keys are written
  77. * \param key Encryption key
  78. */
  79. void aesni_setkey_enc_128( unsigned char *rk,
  80. const unsigned char *key );
  81. /**
  82. * \brief Perform 192-bit key expansion (for encryption)
  83. *
  84. * \param rk Destination buffer where the round keys are written
  85. * \param key Encryption key
  86. */
  87. void aesni_setkey_enc_192( unsigned char *rk,
  88. const unsigned char *key );
  89. /**
  90. * \brief Perform 256-bit key expansion (for encryption)
  91. *
  92. * \param rk Destination buffer where the round keys are written
  93. * \param key Encryption key
  94. */
  95. void aesni_setkey_enc_256( unsigned char *rk,
  96. const unsigned char *key );
  97. #ifdef __cplusplus
  98. }
  99. #endif
  100. #endif /* HAVE_AMD64 */
  101. #endif /* _AESNI_H_ */