arc4.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * \file arc4.h
  3. *
  4. * \brief The ARCFOUR stream cipher
  5. *
  6. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  7. * SPDX-License-Identifier: GPL-2.0
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. *
  23. * This file is part of mbed TLS (https://tls.mbed.org)
  24. */
  25. #ifndef MBEDTLS_ARC4_H
  26. #define MBEDTLS_ARC4_H
  27. #if !defined(MBEDTLS_CONFIG_FILE)
  28. #include "config.h"
  29. #else
  30. #include MBEDTLS_CONFIG_FILE
  31. #endif
  32. #include <stddef.h>
  33. #if !defined(MBEDTLS_ARC4_ALT)
  34. // Regular implementation
  35. //
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. /**
  40. * \brief ARC4 context structure
  41. */
  42. typedef struct
  43. {
  44. int x; /*!< permutation index */
  45. int y; /*!< permutation index */
  46. unsigned char m[256]; /*!< permutation table */
  47. }
  48. mbedtls_arc4_context;
  49. /**
  50. * \brief Initialize ARC4 context
  51. *
  52. * \param ctx ARC4 context to be initialized
  53. */
  54. void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
  55. /**
  56. * \brief Clear ARC4 context
  57. *
  58. * \param ctx ARC4 context to be cleared
  59. */
  60. void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
  61. /**
  62. * \brief ARC4 key schedule
  63. *
  64. * \param ctx ARC4 context to be setup
  65. * \param key the secret key
  66. * \param keylen length of the key, in bytes
  67. */
  68. void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
  69. unsigned int keylen );
  70. /**
  71. * \brief ARC4 cipher function
  72. *
  73. * \param ctx ARC4 context
  74. * \param length length of the input data
  75. * \param input buffer holding the input data
  76. * \param output buffer for the output data
  77. *
  78. * \return 0 if successful
  79. */
  80. int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
  81. unsigned char *output );
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. #else /* MBEDTLS_ARC4_ALT */
  86. #include "arc4_alt.h"
  87. #endif /* MBEDTLS_ARC4_ALT */
  88. #ifdef __cplusplus
  89. extern "C" {
  90. #endif
  91. /**
  92. * \brief Checkup routine
  93. *
  94. * \return 0 if successful, or 1 if the test failed
  95. */
  96. int mbedtls_arc4_self_test( int verbose );
  97. #ifdef __cplusplus
  98. }
  99. #endif
  100. #endif /* arc4.h */