padlock.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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
  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_PADLOCK_H
  27. #define MBEDTLS_PADLOCK_H
  28. #if !defined(MBEDTLS_CONFIG_FILE)
  29. #include "mbedtls/config.h"
  30. #else
  31. #include MBEDTLS_CONFIG_FILE
  32. #endif
  33. #include "mbedtls/aes.h"
  34. #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
  35. #if defined(__has_feature)
  36. #if __has_feature(address_sanitizer)
  37. #define MBEDTLS_HAVE_ASAN
  38. #endif
  39. #endif
  40. /* Some versions of ASan result in errors about not enough registers */
  41. #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
  42. !defined(MBEDTLS_HAVE_ASAN)
  43. #ifndef MBEDTLS_HAVE_X86
  44. #define MBEDTLS_HAVE_X86
  45. #endif
  46. #include <stdint.h>
  47. #define MBEDTLS_PADLOCK_RNG 0x000C
  48. #define MBEDTLS_PADLOCK_ACE 0x00C0
  49. #define MBEDTLS_PADLOCK_PHE 0x0C00
  50. #define MBEDTLS_PADLOCK_PMM 0x3000
  51. #define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15))
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. /**
  56. * \brief Internal PadLock detection routine
  57. *
  58. * \note This function is only for internal use by other library
  59. * functions; you must not call it directly.
  60. *
  61. * \param feature The feature to detect
  62. *
  63. * \return non-zero if CPU has support for the feature, 0 otherwise
  64. */
  65. int mbedtls_padlock_has_support( int feature );
  66. /**
  67. * \brief Internal PadLock AES-ECB block en(de)cryption
  68. *
  69. * \note This function is only for internal use by other library
  70. * functions; you must not call it directly.
  71. *
  72. * \param ctx AES context
  73. * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
  74. * \param input 16-byte input block
  75. * \param output 16-byte output block
  76. *
  77. * \return 0 if success, 1 if operation failed
  78. */
  79. int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx,
  80. int mode,
  81. const unsigned char input[16],
  82. unsigned char output[16] );
  83. /**
  84. * \brief Internal PadLock AES-CBC buffer en(de)cryption
  85. *
  86. * \note This function is only for internal use by other library
  87. * functions; you must not call it directly.
  88. *
  89. * \param ctx AES context
  90. * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
  91. * \param length length of the input data
  92. * \param iv initialization vector (updated after use)
  93. * \param input buffer holding the input data
  94. * \param output buffer holding the output data
  95. *
  96. * \return 0 if success, 1 if operation failed
  97. */
  98. int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx,
  99. int mode,
  100. size_t length,
  101. unsigned char iv[16],
  102. const unsigned char *input,
  103. unsigned char *output );
  104. #ifdef __cplusplus
  105. }
  106. #endif
  107. #endif /* HAVE_X86 */
  108. #endif /* padlock.h */