padlock.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * \file padlock.h
  3. *
  4. * \brief VIA PadLock ACE for HW encryption/decryption supported by some
  5. * processors
  6. *
  7. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  8. * SPDX-License-Identifier: Apache-2.0
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  11. * not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  18. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. *
  22. * This file is part of mbed TLS (https://tls.mbed.org)
  23. */
  24. #ifndef MBEDTLS_PADLOCK_H
  25. #define MBEDTLS_PADLOCK_H
  26. #include "aes.h"
  27. #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
  28. #if defined(__has_feature)
  29. #if __has_feature(address_sanitizer)
  30. #define MBEDTLS_HAVE_ASAN
  31. #endif
  32. #endif
  33. /* Some versions of ASan result in errors about not enough registers */
  34. #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
  35. !defined(MBEDTLS_HAVE_ASAN)
  36. #ifndef MBEDTLS_HAVE_X86
  37. #define MBEDTLS_HAVE_X86
  38. #endif
  39. #include <stdint.h>
  40. #define MBEDTLS_PADLOCK_RNG 0x000C
  41. #define MBEDTLS_PADLOCK_ACE 0x00C0
  42. #define MBEDTLS_PADLOCK_PHE 0x0C00
  43. #define MBEDTLS_PADLOCK_PMM 0x3000
  44. #define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15))
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. /**
  49. * \brief PadLock detection routine
  50. *
  51. * \param feature The feature to detect
  52. *
  53. * \return 1 if CPU has support for the feature, 0 otherwise
  54. */
  55. int mbedtls_padlock_has_support( int feature );
  56. /**
  57. * \brief PadLock AES-ECB block en(de)cryption
  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 PadLock AES-CBC buffer en(de)cryption
  72. *
  73. * \param ctx AES context
  74. * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
  75. * \param length length of the input data
  76. * \param iv initialization vector (updated after use)
  77. * \param input buffer holding the input data
  78. * \param output buffer holding the output data
  79. *
  80. * \return 0 if success, 1 if operation failed
  81. */
  82. int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx,
  83. int mode,
  84. size_t length,
  85. unsigned char iv[16],
  86. const unsigned char *input,
  87. unsigned char *output );
  88. #ifdef __cplusplus
  89. }
  90. #endif
  91. #endif /* HAVE_X86 */
  92. #endif /* padlock.h */