arc4.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. /* MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED is deprecated and should not be used. */
  37. #define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED -0x0019 /**< ARC4 hardware accelerator failed. */
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. #if !defined(MBEDTLS_ARC4_ALT)
  42. // Regular implementation
  43. //
  44. /**
  45. * \brief ARC4 context structure
  46. *
  47. * \warning ARC4 is considered a weak cipher and its use constitutes a
  48. * security risk. We recommend considering stronger ciphers instead.
  49. *
  50. */
  51. typedef struct mbedtls_arc4_context
  52. {
  53. int x; /*!< permutation index */
  54. int y; /*!< permutation index */
  55. unsigned char m[256]; /*!< permutation table */
  56. }
  57. mbedtls_arc4_context;
  58. #else /* MBEDTLS_ARC4_ALT */
  59. #include "arc4_alt.h"
  60. #endif /* MBEDTLS_ARC4_ALT */
  61. /**
  62. * \brief Initialize ARC4 context
  63. *
  64. * \param ctx ARC4 context to be initialized
  65. *
  66. * \warning ARC4 is considered a weak cipher and its use constitutes a
  67. * security risk. We recommend considering stronger ciphers
  68. * instead.
  69. *
  70. */
  71. void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
  72. /**
  73. * \brief Clear ARC4 context
  74. *
  75. * \param ctx ARC4 context to be cleared
  76. *
  77. * \warning ARC4 is considered a weak cipher and its use constitutes a
  78. * security risk. We recommend considering stronger ciphers
  79. * instead.
  80. *
  81. */
  82. void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
  83. /**
  84. * \brief ARC4 key schedule
  85. *
  86. * \param ctx ARC4 context to be setup
  87. * \param key the secret key
  88. * \param keylen length of the key, in bytes
  89. *
  90. * \warning ARC4 is considered a weak cipher and its use constitutes a
  91. * security risk. We recommend considering stronger ciphers
  92. * instead.
  93. *
  94. */
  95. void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
  96. unsigned int keylen );
  97. /**
  98. * \brief ARC4 cipher function
  99. *
  100. * \param ctx ARC4 context
  101. * \param length length of the input data
  102. * \param input buffer holding the input data
  103. * \param output buffer for the output data
  104. *
  105. * \return 0 if successful
  106. *
  107. * \warning ARC4 is considered a weak cipher and its use constitutes a
  108. * security risk. We recommend considering stronger ciphers
  109. * instead.
  110. *
  111. */
  112. int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
  113. unsigned char *output );
  114. #if defined(MBEDTLS_SELF_TEST)
  115. /**
  116. * \brief Checkup routine
  117. *
  118. * \return 0 if successful, or 1 if the test failed
  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_self_test( int verbose );
  126. #endif /* MBEDTLS_SELF_TEST */
  127. #ifdef __cplusplus
  128. }
  129. #endif
  130. #endif /* arc4.h */