Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  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.  
  30. #include "aes.h"
  31.  
  32. #define POLARSSL_ERR_PADLOCK_DATA_MISALIGNED               -0x0030  /**< Input data should be aligned. */
  33.  
  34. #if defined(POLARSSL_HAVE_ASM) && defined(__GNUC__) && defined(__i386__)
  35.  
  36. #ifndef POLARSSL_HAVE_X86
  37. #define POLARSSL_HAVE_X86
  38. #endif
  39.  
  40. #ifdef _MSC_VER
  41. #include <basetsd.h>
  42. typedef INT32 int32_t;
  43. #else
  44. #include <inttypes.h>
  45. #endif
  46.  
  47.  
  48. #define PADLOCK_RNG 0x000C
  49. #define PADLOCK_ACE 0x00C0
  50. #define PADLOCK_PHE 0x0C00
  51. #define PADLOCK_PMM 0x3000
  52.  
  53. #define PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15))
  54.  
  55. #ifdef __cplusplus
  56. extern "C" {
  57. #endif
  58.  
  59. /**
  60.  * \brief          PadLock detection routine
  61.  *
  62.  * \param          The feature to detect
  63.  *
  64.  * \return         1 if CPU has support for the feature, 0 otherwise
  65.  */
  66. int padlock_supports( int feature );
  67.  
  68. /**
  69.  * \brief          PadLock AES-ECB block en(de)cryption
  70.  *
  71.  * \param ctx      AES context
  72.  * \param mode     AES_ENCRYPT or AES_DECRYPT
  73.  * \param input    16-byte input block
  74.  * \param output   16-byte output block
  75.  *
  76.  * \return         0 if success, 1 if operation failed
  77.  */
  78. int padlock_xcryptecb( aes_context *ctx,
  79.                        int mode,
  80.                        const unsigned char input[16],
  81.                        unsigned char output[16] );
  82.  
  83. /**
  84.  * \brief          PadLock AES-CBC buffer en(de)cryption
  85.  *
  86.  * \param ctx      AES context
  87.  * \param mode     AES_ENCRYPT or AES_DECRYPT
  88.  * \param length   length of the input data
  89.  * \param iv       initialization vector (updated after use)
  90.  * \param input    buffer holding the input data
  91.  * \param output   buffer holding the output data
  92.  *
  93.  * \return         0 if success, 1 if operation failed
  94.  */
  95. int padlock_xcryptcbc( aes_context *ctx,
  96.                        int mode,
  97.                        size_t length,
  98.                        unsigned char iv[16],
  99.                        const unsigned char *input,
  100.                        unsigned char *output );
  101.  
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105.  
  106. #endif /* HAVE_X86  */
  107.  
  108. #endif /* padlock.h */
  109.