arc4.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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: Apache-2.0
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  10. * not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  17. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. *
  21. * This file is part of mbed TLS (https://tls.mbed.org)
  22. */
  23. #ifndef MBEDTLS_ARC4_H
  24. #define MBEDTLS_ARC4_H
  25. #if !defined(MBEDTLS_CONFIG_FILE)
  26. #include "config.h"
  27. #else
  28. #include MBEDTLS_CONFIG_FILE
  29. #endif
  30. #include <stddef.h>
  31. #if !defined(MBEDTLS_ARC4_ALT)
  32. // Regular implementation
  33. //
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /**
  38. * \brief ARC4 context structure
  39. */
  40. typedef struct
  41. {
  42. int x; /*!< permutation index */
  43. int y; /*!< permutation index */
  44. unsigned char m[256]; /*!< permutation table */
  45. }
  46. mbedtls_arc4_context;
  47. /**
  48. * \brief Initialize ARC4 context
  49. *
  50. * \param ctx ARC4 context to be initialized
  51. */
  52. void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
  53. /**
  54. * \brief Clear ARC4 context
  55. *
  56. * \param ctx ARC4 context to be cleared
  57. */
  58. void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
  59. /**
  60. * \brief ARC4 key schedule
  61. *
  62. * \param ctx ARC4 context to be setup
  63. * \param key the secret key
  64. * \param keylen length of the key, in bytes
  65. */
  66. void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
  67. unsigned int keylen );
  68. /**
  69. * \brief ARC4 cipher function
  70. *
  71. * \param ctx ARC4 context
  72. * \param length length of the input data
  73. * \param input buffer holding the input data
  74. * \param output buffer for the output data
  75. *
  76. * \return 0 if successful
  77. */
  78. int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
  79. unsigned char *output );
  80. #ifdef __cplusplus
  81. }
  82. #endif
  83. #else /* MBEDTLS_ARC4_ALT */
  84. #include "arc4_alt.h"
  85. #endif /* MBEDTLS_ARC4_ALT */
  86. #ifdef __cplusplus
  87. extern "C" {
  88. #endif
  89. /**
  90. * \brief Checkup routine
  91. *
  92. * \return 0 if successful, or 1 if the test failed
  93. */
  94. int mbedtls_arc4_self_test( int verbose );
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. #endif /* arc4.h */