padlock.h 3.1 KB

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