padlock.h 3.8 KB

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