aesce.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * \file aesce.h
  3. *
  4. * \brief Support hardware AES acceleration on Armv8-A processors with
  5. * the Armv8-A Cryptographic Extension in AArch64 execution state.
  6. *
  7. * \warning These functions are only for internal use by other library
  8. * functions; you must not call them directly.
  9. */
  10. /*
  11. * Copyright The Mbed TLS Contributors
  12. * SPDX-License-Identifier: Apache-2.0
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  15. * not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * http://www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  22. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. */
  26. #ifndef MBEDTLS_AESCE_H
  27. #define MBEDTLS_AESCE_H
  28. #include "mbedtls/build_info.h"
  29. #include "mbedtls/aes.h"
  30. #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \
  31. defined(__aarch64__) && !defined(MBEDTLS_HAVE_ARM64)
  32. #define MBEDTLS_HAVE_ARM64
  33. #endif
  34. #if defined(MBEDTLS_HAVE_ARM64)
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /**
  39. * \brief Internal function to detect the crypto extension in CPUs.
  40. *
  41. * \return 1 if CPU has support for the feature, 0 otherwise
  42. */
  43. int mbedtls_aesce_has_support(void);
  44. /**
  45. * \brief Internal AES-ECB block encryption and decryption
  46. *
  47. * \param ctx AES context
  48. * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
  49. * \param input 16-byte input block
  50. * \param output 16-byte output block
  51. *
  52. * \return 0 on success (cannot fail)
  53. */
  54. int mbedtls_aesce_crypt_ecb(mbedtls_aes_context *ctx,
  55. int mode,
  56. const unsigned char input[16],
  57. unsigned char output[16]);
  58. /**
  59. * \brief Internal GCM multiplication: c = a * b in GF(2^128)
  60. *
  61. * \note This function is only for internal use by other library
  62. * functions; you must not call it directly.
  63. *
  64. * \param c Result
  65. * \param a First operand
  66. * \param b Second operand
  67. *
  68. * \note Both operands and result are bit strings interpreted as
  69. * elements of GF(2^128) as per the GCM spec.
  70. */
  71. void mbedtls_aesce_gcm_mult(unsigned char c[16],
  72. const unsigned char a[16],
  73. const unsigned char b[16]);
  74. /**
  75. * \brief Internal round key inversion. This function computes
  76. * decryption round keys from the 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_aesce_inverse_key(unsigned char *invkey,
  83. const unsigned char *fwdkey,
  84. int nr);
  85. /**
  86. * \brief Internal key expansion for encryption
  87. *
  88. * \param rk Destination buffer where the round keys are written
  89. * \param key Encryption key
  90. * \param bits Key size in bits (must be 128, 192 or 256)
  91. *
  92. * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
  93. */
  94. int mbedtls_aesce_setkey_enc(unsigned char *rk,
  95. const unsigned char *key,
  96. size_t bits);
  97. #ifdef __cplusplus
  98. }
  99. #endif
  100. #endif /* MBEDTLS_HAVE_ARM64 */
  101. #endif /* MBEDTLS_AESCE_H */