padlock.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * \file padlock.h
  3. *
  4. * \brief VIA PadLock ACE for HW encryption/decryption supported by some processors
  5. *
  6. * Copyright (C) 2006-2010, Brainspark B.V.
  7. *
  8. * This file is part of PolarSSL (http://www.polarssl.org)
  9. * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
  10. *
  11. * All rights reserved.
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License along
  24. * with this program; if not, write to the Free Software Foundation, Inc.,
  25. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  26. */
  27. #ifndef POLARSSL_PADLOCK_H
  28. #define POLARSSL_PADLOCK_H
  29. #include "polarssl/aes.h"
  30. #define POLARSSL_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
  31. #if defined(POLARSSL_HAVE_ASM) && defined(__GNUC__) && defined(__i386__)
  32. #ifndef POLARSSL_HAVE_X86
  33. #define POLARSSL_HAVE_X86
  34. #endif
  35. #define PADLOCK_RNG 0x000C
  36. #define PADLOCK_ACE 0x00C0
  37. #define PADLOCK_PHE 0x0C00
  38. #define PADLOCK_PMM 0x3000
  39. #define PADLOCK_ALIGN16(x) (unsigned long *) (16 + ((long) x & ~15))
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /**
  44. * \brief PadLock detection routine
  45. *
  46. * \param The feature to detect
  47. *
  48. * \return 1 if CPU has support for the feature, 0 otherwise
  49. */
  50. int padlock_supports( int feature );
  51. /**
  52. * \brief PadLock AES-ECB block en(de)cryption
  53. *
  54. * \param ctx AES context
  55. * \param mode AES_ENCRYPT or AES_DECRYPT
  56. * \param input 16-byte input block
  57. * \param output 16-byte output block
  58. *
  59. * \return 0 if success, 1 if operation failed
  60. */
  61. int padlock_xcryptecb( aes_context *ctx,
  62. int mode,
  63. const unsigned char input[16],
  64. unsigned char output[16] );
  65. /**
  66. * \brief PadLock AES-CBC buffer en(de)cryption
  67. *
  68. * \param ctx AES context
  69. * \param mode AES_ENCRYPT or AES_DECRYPT
  70. * \param length length of the input data
  71. * \param iv initialization vector (updated after use)
  72. * \param input buffer holding the input data
  73. * \param output buffer holding the output data
  74. *
  75. * \return 0 if success, 1 if operation failed
  76. */
  77. int padlock_xcryptcbc( aes_context *ctx,
  78. int mode,
  79. size_t length,
  80. unsigned char iv[16],
  81. const unsigned char *input,
  82. unsigned char *output );
  83. #ifdef __cplusplus
  84. }
  85. #endif
  86. #endif /* HAVE_X86 */
  87. #endif /* padlock.h */