arc4.h 3.9 KB

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