4 * \brief The ARCFOUR stream cipher
6 * \warning ARC4 is considered a weak cipher and its use constitutes a
7 * security risk. We recommend considering stronger ciphers instead.
10 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
11 * SPDX-License-Identifier: Apache-2.0
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
17 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 * This file is part of mbed TLS (https://tls.mbed.org)
28 #ifndef MBEDTLS_ARC4_H
29 #define MBEDTLS_ARC4_H
31 #if !defined(MBEDTLS_CONFIG_FILE)
34 #include MBEDTLS_CONFIG_FILE
39 /* MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED is deprecated and should not be used. */
40 #define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED -0x0019 /**< ARC4 hardware accelerator failed. */
46 #if !defined(MBEDTLS_ARC4_ALT)
47 // Regular implementation
51 * \brief ARC4 context structure
53 * \warning ARC4 is considered a weak cipher and its use constitutes a
54 * security risk. We recommend considering stronger ciphers instead.
57 typedef struct mbedtls_arc4_context
59 int x; /*!< permutation index */
60 int y; /*!< permutation index */
61 unsigned char m[256]; /*!< permutation table */
65 #else /* MBEDTLS_ARC4_ALT */
67 #endif /* MBEDTLS_ARC4_ALT */
70 * \brief Initialize ARC4 context
72 * \param ctx ARC4 context to be initialized
74 * \warning ARC4 is considered a weak cipher and its use constitutes a
75 * security risk. We recommend considering stronger ciphers
79 void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
82 * \brief Clear ARC4 context
84 * \param ctx ARC4 context to be cleared
86 * \warning ARC4 is considered a weak cipher and its use constitutes a
87 * security risk. We recommend considering stronger ciphers
91 void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
94 * \brief ARC4 key schedule
96 * \param ctx ARC4 context to be setup
97 * \param key the secret key
98 * \param keylen length of the key, in bytes
100 * \warning ARC4 is considered a weak cipher and its use constitutes a
101 * security risk. We recommend considering stronger ciphers
105 void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
106 unsigned int keylen );
109 * \brief ARC4 cipher function
111 * \param ctx ARC4 context
112 * \param length length of the input data
113 * \param input buffer holding the input data
114 * \param output buffer for the output data
116 * \return 0 if successful
118 * \warning ARC4 is considered a weak cipher and its use constitutes a
119 * security risk. We recommend considering stronger ciphers
123 int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
124 unsigned char *output );
126 #if defined(MBEDTLS_SELF_TEST)
129 * \brief Checkup routine
131 * \return 0 if successful, or 1 if the test failed
133 * \warning ARC4 is considered a weak cipher and its use constitutes a
134 * security risk. We recommend considering stronger ciphers
138 int mbedtls_arc4_self_test( int verbose );
140 #endif /* MBEDTLS_SELF_TEST */