padlock.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * \file padlock.h
  3. *
  4. * \brief VIA PadLock ACE for HW encryption/decryption supported by some
  5. * processors
  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 OR GPL-2.0-or-later
  13. */
  14. #ifndef MBEDTLS_PADLOCK_H
  15. #define MBEDTLS_PADLOCK_H
  16. #include "mbedtls/build_info.h"
  17. #include "mbedtls/aes.h"
  18. #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
  19. #if defined(__has_feature)
  20. #if __has_feature(address_sanitizer)
  21. #define MBEDTLS_HAVE_ASAN
  22. #endif
  23. #endif
  24. /*
  25. * - `padlock` is implements with GNUC assembly for x86 target.
  26. * - Some versions of ASan result in errors about not enough registers.
  27. */
  28. #if defined(MBEDTLS_PADLOCK_C) && \
  29. defined(__GNUC__) && defined(MBEDTLS_ARCH_IS_X86) && \
  30. defined(MBEDTLS_HAVE_ASM) && \
  31. !defined(MBEDTLS_HAVE_ASAN)
  32. #define MBEDTLS_VIA_PADLOCK_HAVE_CODE
  33. #include <stdint.h>
  34. #define MBEDTLS_PADLOCK_RNG 0x000C
  35. #define MBEDTLS_PADLOCK_ACE 0x00C0
  36. #define MBEDTLS_PADLOCK_PHE 0x0C00
  37. #define MBEDTLS_PADLOCK_PMM 0x3000
  38. #define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15))
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /**
  43. * \brief Internal PadLock detection routine
  44. *
  45. * \note This function is only for internal use by other library
  46. * functions; you must not call it directly.
  47. *
  48. * \param feature The feature to detect
  49. *
  50. * \return non-zero if CPU has support for the feature, 0 otherwise
  51. */
  52. int mbedtls_padlock_has_support(int feature);
  53. /**
  54. * \brief Internal PadLock AES-ECB block en(de)cryption
  55. *
  56. * \note This function is only for internal use by other library
  57. * functions; you must not call it directly.
  58. *
  59. * \param ctx AES context
  60. * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
  61. * \param input 16-byte input block
  62. * \param output 16-byte output block
  63. *
  64. * \return 0 if success, 1 if operation failed
  65. */
  66. int mbedtls_padlock_xcryptecb(mbedtls_aes_context *ctx,
  67. int mode,
  68. const unsigned char input[16],
  69. unsigned char output[16]);
  70. /**
  71. * \brief Internal PadLock AES-CBC buffer en(de)cryption
  72. *
  73. * \note This function is only for internal use by other library
  74. * functions; you must not call it directly.
  75. *
  76. * \param ctx AES context
  77. * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
  78. * \param length length of the input data
  79. * \param iv initialization vector (updated after use)
  80. * \param input buffer holding the input data
  81. * \param output buffer holding the output data
  82. *
  83. * \return 0 if success, 1 if operation failed
  84. */
  85. int mbedtls_padlock_xcryptcbc(mbedtls_aes_context *ctx,
  86. int mode,
  87. size_t length,
  88. unsigned char iv[16],
  89. const unsigned char *input,
  90. unsigned char *output);
  91. #ifdef __cplusplus
  92. }
  93. #endif
  94. #endif /* HAVE_X86 */
  95. #endif /* padlock.h */