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