Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /**
  2.  * \file padlock.h
  3.  *
  4.  * \brief VIA PadLock ACE for HW encryption/decryption supported by some
  5.  *        processors
  6.  *
  7.  * \warning These functions are only for internal use by other library
  8.  *          functions; you must not call them directly.
  9.  */
  10. /*
  11.  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  12.  *  SPDX-License-Identifier: GPL-2.0
  13.  *
  14.  *  This program is free software; you can redistribute it and/or modify
  15.  *  it under the terms of the GNU General Public License as published by
  16.  *  the Free Software Foundation; either version 2 of the License, or
  17.  *  (at your option) any later version.
  18.  *
  19.  *  This program is distributed in the hope that it will be useful,
  20.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22.  *  GNU General Public License for more details.
  23.  *
  24.  *  You should have received a copy of the GNU General Public License along
  25.  *  with this program; if not, write to the Free Software Foundation, Inc.,
  26.  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  27.  *
  28.  *  This file is part of mbed TLS (https://tls.mbed.org)
  29.  */
  30. #ifndef MBEDTLS_PADLOCK_H
  31. #define MBEDTLS_PADLOCK_H
  32.  
  33. #if !defined(MBEDTLS_CONFIG_FILE)
  34. #include "config.h"
  35. #else
  36. #include MBEDTLS_CONFIG_FILE
  37. #endif
  38.  
  39. #include "aes.h"
  40.  
  41. #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED               -0x0030  /**< Input data should be aligned. */
  42.  
  43. #if defined(__has_feature)
  44. #if __has_feature(address_sanitizer)
  45. #define MBEDTLS_HAVE_ASAN
  46. #endif
  47. #endif
  48.  
  49. /* Some versions of ASan result in errors about not enough registers */
  50. #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
  51.     !defined(MBEDTLS_HAVE_ASAN)
  52.  
  53. #ifndef MBEDTLS_HAVE_X86
  54. #define MBEDTLS_HAVE_X86
  55. #endif
  56.  
  57. #include <stdint.h>
  58.  
  59. #define MBEDTLS_PADLOCK_RNG 0x000C
  60. #define MBEDTLS_PADLOCK_ACE 0x00C0
  61. #define MBEDTLS_PADLOCK_PHE 0x0C00
  62. #define MBEDTLS_PADLOCK_PMM 0x3000
  63.  
  64. #define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15))
  65.  
  66. #ifdef __cplusplus
  67. extern "C" {
  68. #endif
  69.  
  70. /**
  71.  * \brief          Internal PadLock detection routine
  72.  *
  73.  * \note           This function is only for internal use by other library
  74.  *                 functions; you must not call it directly.
  75.  *
  76.  * \param feature  The feature to detect
  77.  *
  78.  * \return         1 if CPU has support for the feature, 0 otherwise
  79.  */
  80. int mbedtls_padlock_has_support( int feature );
  81.  
  82. /**
  83.  * \brief          Internal PadLock AES-ECB block en(de)cryption
  84.  *
  85.  * \note           This function is only for internal use by other library
  86.  *                 functions; you must not call it directly.
  87.  *
  88.  * \param ctx      AES context
  89.  * \param mode     MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
  90.  * \param input    16-byte input block
  91.  * \param output   16-byte output block
  92.  *
  93.  * \return         0 if success, 1 if operation failed
  94.  */
  95. int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx,
  96.                                int mode,
  97.                                const unsigned char input[16],
  98.                                unsigned char output[16] );
  99.  
  100. /**
  101.  * \brief          Internal PadLock AES-CBC buffer en(de)cryption
  102.  *
  103.  * \note           This function is only for internal use by other library
  104.  *                 functions; you must not call it directly.
  105.  *
  106.  * \param ctx      AES context
  107.  * \param mode     MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
  108.  * \param length   length of the input data
  109.  * \param iv       initialization vector (updated after use)
  110.  * \param input    buffer holding the input data
  111.  * \param output   buffer holding the output data
  112.  *
  113.  * \return         0 if success, 1 if operation failed
  114.  */
  115. int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx,
  116.                                int mode,
  117.                                size_t length,
  118.                                unsigned char iv[16],
  119.                                const unsigned char *input,
  120.                                unsigned char *output );
  121.  
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125.  
  126. #endif /* HAVE_X86  */
  127.  
  128. #endif /* padlock.h */
  129.