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