Subversion Repositories Kolibri OS

Rev

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

  1. /**
  2.  * \file xtea.h
  3.  *
  4.  * \brief XTEA block cipher (32-bit)
  5.  */
  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_XTEA_H
  27. #define MBEDTLS_XTEA_H
  28.  
  29. #if !defined(MBEDTLS_CONFIG_FILE)
  30. #include "config.h"
  31. #else
  32. #include MBEDTLS_CONFIG_FILE
  33. #endif
  34.  
  35. #include <stddef.h>
  36. #include <stdint.h>
  37.  
  38. #define MBEDTLS_XTEA_ENCRYPT     1
  39. #define MBEDTLS_XTEA_DECRYPT     0
  40.  
  41. #define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH             -0x0028  /**< The data input has an invalid length. */
  42.  
  43. /* MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED is deprecated and should not be used. */
  44. #define MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED                  -0x0029  /**< XTEA hardware accelerator failed. */
  45.  
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49.  
  50. #if !defined(MBEDTLS_XTEA_ALT)
  51. // Regular implementation
  52. //
  53.  
  54. /**
  55.  * \brief          XTEA context structure
  56.  */
  57. typedef struct mbedtls_xtea_context
  58. {
  59.     uint32_t k[4];       /*!< key */
  60. }
  61. mbedtls_xtea_context;
  62.  
  63. #else  /* MBEDTLS_XTEA_ALT */
  64. #include "xtea_alt.h"
  65. #endif /* MBEDTLS_XTEA_ALT */
  66.  
  67. /**
  68.  * \brief          Initialize XTEA context
  69.  *
  70.  * \param ctx      XTEA context to be initialized
  71.  */
  72. void mbedtls_xtea_init( mbedtls_xtea_context *ctx );
  73.  
  74. /**
  75.  * \brief          Clear XTEA context
  76.  *
  77.  * \param ctx      XTEA context to be cleared
  78.  */
  79. void mbedtls_xtea_free( mbedtls_xtea_context *ctx );
  80.  
  81. /**
  82.  * \brief          XTEA key schedule
  83.  *
  84.  * \param ctx      XTEA context to be initialized
  85.  * \param key      the secret key
  86.  */
  87. void mbedtls_xtea_setup( mbedtls_xtea_context *ctx, const unsigned char key[16] );
  88.  
  89. /**
  90.  * \brief          XTEA cipher function
  91.  *
  92.  * \param ctx      XTEA context
  93.  * \param mode     MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
  94.  * \param input    8-byte input block
  95.  * \param output   8-byte output block
  96.  *
  97.  * \return         0 if successful
  98.  */
  99. int mbedtls_xtea_crypt_ecb( mbedtls_xtea_context *ctx,
  100.                     int mode,
  101.                     const unsigned char input[8],
  102.                     unsigned char output[8] );
  103.  
  104. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  105. /**
  106.  * \brief          XTEA CBC cipher function
  107.  *
  108.  * \param ctx      XTEA context
  109.  * \param mode     MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
  110.  * \param length   the length of input, multiple of 8
  111.  * \param iv       initialization vector for CBC mode
  112.  * \param input    input block
  113.  * \param output   output block
  114.  *
  115.  * \return         0 if successful,
  116.  *                 MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0
  117.  */
  118. int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx,
  119.                     int mode,
  120.                     size_t length,
  121.                     unsigned char iv[8],
  122.                     const unsigned char *input,
  123.                     unsigned char *output);
  124. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  125.  
  126. #if defined(MBEDTLS_SELF_TEST)
  127.  
  128. /**
  129.  * \brief          Checkup routine
  130.  *
  131.  * \return         0 if successful, or 1 if the test failed
  132.  */
  133. int mbedtls_xtea_self_test( int verbose );
  134.  
  135. #endif /* MBEDTLS_SELF_TEST */
  136.  
  137. #ifdef __cplusplus
  138. }
  139. #endif
  140.  
  141. #endif /* xtea.h */
  142.