padlock.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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: GPL-2.0
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. *
  24. * This file is part of mbed TLS (https://tls.mbed.org)
  25. */
  26. #ifndef MBEDTLS_PADLOCK_H
  27. #define MBEDTLS_PADLOCK_H
  28. #include "aes.h"
  29. #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
  30. #if defined(__has_feature)
  31. #if __has_feature(address_sanitizer)
  32. #define MBEDTLS_HAVE_ASAN
  33. #endif
  34. #endif
  35. /* Some versions of ASan result in errors about not enough registers */
  36. #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
  37. !defined(MBEDTLS_HAVE_ASAN)
  38. #ifndef MBEDTLS_HAVE_X86
  39. #define MBEDTLS_HAVE_X86
  40. #endif
  41. #include <stdint.h>
  42. #define MBEDTLS_PADLOCK_RNG 0x000C
  43. #define MBEDTLS_PADLOCK_ACE 0x00C0
  44. #define MBEDTLS_PADLOCK_PHE 0x0C00
  45. #define MBEDTLS_PADLOCK_PMM 0x3000
  46. #define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15))
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. /**
  51. * \brief PadLock detection routine
  52. *
  53. * \param feature The feature to detect
  54. *
  55. * \return 1 if CPU has support for the feature, 0 otherwise
  56. */
  57. int mbedtls_padlock_has_support( int feature );
  58. /**
  59. * \brief PadLock AES-ECB block en(de)cryption
  60. *
  61. * \param ctx AES context
  62. * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
  63. * \param input 16-byte input block
  64. * \param output 16-byte output block
  65. *
  66. * \return 0 if success, 1 if operation failed
  67. */
  68. int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx,
  69. int mode,
  70. const unsigned char input[16],
  71. unsigned char output[16] );
  72. /**
  73. * \brief PadLock AES-CBC buffer en(de)cryption
  74. *
  75. * \param ctx AES context
  76. * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
  77. * \param length length of the input data
  78. * \param iv initialization vector (updated after use)
  79. * \param input buffer holding the input data
  80. * \param output buffer holding the output data
  81. *
  82. * \return 0 if success, 1 if operation failed
  83. */
  84. int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx,
  85. int mode,
  86. size_t length,
  87. unsigned char iv[16],
  88. const unsigned char *input,
  89. unsigned char *output );
  90. #ifdef __cplusplus
  91. }
  92. #endif
  93. #endif /* HAVE_X86 */
  94. #endif /* padlock.h */