Subversion Repositories Kolibri OS

Rev

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

  1. /**
  2.  * \file arc4.h
  3.  *
  4.  * \brief The ARCFOUR stream cipher
  5.  *
  6.  * \warning   ARC4 is considered a weak cipher and its use constitutes a
  7.  *            security risk. We recommend considering stronger ciphers instead.
  8.  */
  9. /*
  10.  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  11.  *  SPDX-License-Identifier: GPL-2.0
  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.  *  This file is part of mbed TLS (https://tls.mbed.org)
  28.  *
  29.  */
  30. #ifndef MBEDTLS_ARC4_H
  31. #define MBEDTLS_ARC4_H
  32.  
  33. #if !defined(MBEDTLS_CONFIG_FILE)
  34. #include "config.h"
  35. #else
  36. #include MBEDTLS_CONFIG_FILE
  37. #endif
  38.  
  39. #include <stddef.h>
  40.  
  41. /* MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED is deprecated and should not be used. */
  42. #define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED                  -0x0019  /**< ARC4 hardware accelerator failed. */
  43.  
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47.  
  48. #if !defined(MBEDTLS_ARC4_ALT)
  49. // Regular implementation
  50. //
  51.  
  52. /**
  53.  * \brief     ARC4 context structure
  54.  *
  55.  * \warning   ARC4 is considered a weak cipher and its use constitutes a
  56.  *            security risk. We recommend considering stronger ciphers instead.
  57.  *
  58.  */
  59. typedef struct mbedtls_arc4_context
  60. {
  61.     int x;                      /*!< permutation index */
  62.     int y;                      /*!< permutation index */
  63.     unsigned char m[256];       /*!< permutation table */
  64. }
  65. mbedtls_arc4_context;
  66.  
  67. #else  /* MBEDTLS_ARC4_ALT */
  68. #include "arc4_alt.h"
  69. #endif /* MBEDTLS_ARC4_ALT */
  70.  
  71. /**
  72.  * \brief          Initialize ARC4 context
  73.  *
  74.  * \param ctx      ARC4 context to be initialized
  75.  *
  76.  * \warning        ARC4 is considered a weak cipher and its use constitutes a
  77.  *                 security risk. We recommend considering stronger ciphers
  78.  *                 instead.
  79.  *
  80.  */
  81. void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
  82.  
  83. /**
  84.  * \brief          Clear ARC4 context
  85.  *
  86.  * \param ctx      ARC4 context to be cleared
  87.  *
  88.  * \warning        ARC4 is considered a weak cipher and its use constitutes a
  89.  *                 security risk. We recommend considering stronger ciphers
  90.  *                 instead.
  91.  *
  92.  */
  93. void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
  94.  
  95. /**
  96.  * \brief          ARC4 key schedule
  97.  *
  98.  * \param ctx      ARC4 context to be setup
  99.  * \param key      the secret key
  100.  * \param keylen   length of the key, in bytes
  101.  *
  102.  * \warning        ARC4 is considered a weak cipher and its use constitutes a
  103.  *                 security risk. We recommend considering stronger ciphers
  104.  *                 instead.
  105.  *
  106.  */
  107. void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
  108.                  unsigned int keylen );
  109.  
  110. /**
  111.  * \brief          ARC4 cipher function
  112.  *
  113.  * \param ctx      ARC4 context
  114.  * \param length   length of the input data
  115.  * \param input    buffer holding the input data
  116.  * \param output   buffer for the output data
  117.  *
  118.  * \return         0 if successful
  119.  *
  120.  * \warning        ARC4 is considered a weak cipher and its use constitutes a
  121.  *                 security risk. We recommend considering stronger ciphers
  122.  *                 instead.
  123.  *
  124.  */
  125. int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
  126.                 unsigned char *output );
  127.  
  128. #if defined(MBEDTLS_SELF_TEST)
  129.  
  130. /**
  131.  * \brief          Checkup routine
  132.  *
  133.  * \return         0 if successful, or 1 if the test failed
  134.  *
  135.  * \warning        ARC4 is considered a weak cipher and its use constitutes a
  136.  *                 security risk. We recommend considering stronger ciphers
  137.  *                 instead.
  138.  *
  139.  */
  140. int mbedtls_arc4_self_test( int verbose );
  141.  
  142. #endif /* MBEDTLS_SELF_TEST */
  143.  
  144. #ifdef __cplusplus
  145. }
  146. #endif
  147.  
  148. #endif /* arc4.h */
  149.