arc4.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. #if !defined(MBEDTLS_ARC4_ALT)
  41. // Regular implementation
  42. //
  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. #else /* MBEDTLS_ARC4_ALT */
  58. #include "arc4_alt.h"
  59. #endif /* MBEDTLS_ARC4_ALT */
  60. /**
  61. * \brief Initialize ARC4 context
  62. *
  63. * \param ctx ARC4 context to be initialized
  64. *
  65. * \warning ARC4 is considered a weak cipher and its use constitutes a
  66. * security risk. We recommend considering stronger ciphers
  67. * instead.
  68. *
  69. */
  70. void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
  71. /**
  72. * \brief Clear ARC4 context
  73. *
  74. * \param ctx ARC4 context to be cleared
  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_free( mbedtls_arc4_context *ctx );
  82. /**
  83. * \brief ARC4 key schedule
  84. *
  85. * \param ctx ARC4 context to be setup
  86. * \param key the secret key
  87. * \param keylen length of the key, in bytes
  88. *
  89. * \warning ARC4 is considered a weak cipher and its use constitutes a
  90. * security risk. We recommend considering stronger ciphers
  91. * instead.
  92. *
  93. */
  94. void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
  95. unsigned int keylen );
  96. /**
  97. * \brief ARC4 cipher function
  98. *
  99. * \param ctx ARC4 context
  100. * \param length length of the input data
  101. * \param input buffer holding the input data
  102. * \param output buffer for the output data
  103. *
  104. * \return 0 if successful
  105. *
  106. * \warning ARC4 is considered a weak cipher and its use constitutes a
  107. * security risk. We recommend considering stronger ciphers
  108. * instead.
  109. *
  110. */
  111. int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
  112. unsigned char *output );
  113. /**
  114. * \brief Checkup routine
  115. *
  116. * \return 0 if successful, or 1 if the test failed
  117. *
  118. * \warning ARC4 is considered a weak cipher and its use constitutes a
  119. * security risk. We recommend considering stronger ciphers
  120. * instead.
  121. *
  122. */
  123. int mbedtls_arc4_self_test( int verbose );
  124. #ifdef __cplusplus
  125. }
  126. #endif
  127. #endif /* arc4.h */