blob: cfe3aea96a8262c0e658e2c738e03368ee239adc [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file arc4.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief The ARCFOUR stream cipher
Hanno Beckerbbca8c52017-09-25 14:53:51 +01005 *
6 * \warning ARC4 is considered a weak cipher and its use constitutes a
7 * security risk. We recommend considering stronger ciphers instead.
Darryl Greena40a1012018-01-05 15:33:17 +00008 */
9/*
Bence Szépkútia2947ac2020-08-19 16:37:36 +020010 * Copyright The Mbed TLS Contributors
Bence Szépkútif744bd72020-06-05 13:02:18 +020011 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
12 *
13 * This file is provided under the Apache License 2.0, or the
14 * GNU General Public License v2.0 or later.
15 *
16 * **********
17 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020018 *
19 * Licensed under the Apache License, Version 2.0 (the "License"); you may
20 * not use this file except in compliance with the License.
21 * You may obtain a copy of the License at
22 *
23 * http://www.apache.org/licenses/LICENSE-2.0
24 *
25 * Unless required by applicable law or agreed to in writing, software
26 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
27 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 * See the License for the specific language governing permissions and
29 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000030 *
Bence Szépkútif744bd72020-06-05 13:02:18 +020031 * **********
32 *
33 * **********
34 * GNU General Public License v2.0 or later:
35 *
36 * This program is free software; you can redistribute it and/or modify
37 * it under the terms of the GNU General Public License as published by
38 * the Free Software Foundation; either version 2 of the License, or
39 * (at your option) any later version.
40 *
41 * This program is distributed in the hope that it will be useful,
42 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 * GNU General Public License for more details.
45 *
46 * You should have received a copy of the GNU General Public License along
47 * with this program; if not, write to the Free Software Foundation, Inc.,
48 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
49 *
50 * **********
51 *
Paul Bakker5121ce52009-01-03 21:22:43 +000052 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020053#ifndef MBEDTLS_ARC4_H
54#define MBEDTLS_ARC4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000055
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020057#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020058#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020060#endif
Paul Bakker90995b52013-06-24 19:20:35 +020061
Rich Evans00ab4702015-02-06 13:43:58 +000062#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000063
Ron Eldor9924bdc2018-10-04 10:59:13 +030064/* MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskine1990fab2021-07-26 18:48:10 +020065/** ARC4 hardware accelerator failed. */
66#define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED -0x0019
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010067
Paul Bakker407a0da2013-06-27 14:29:21 +020068#ifdef __cplusplus
69extern "C" {
70#endif
71
Ron Eldorb2aacec2017-05-18 16:53:08 +030072#if !defined(MBEDTLS_ARC4_ALT)
73// Regular implementation
74//
75
Paul Bakker5121ce52009-01-03 21:22:43 +000076/**
Hanno Beckerbbca8c52017-09-25 14:53:51 +010077 * \brief ARC4 context structure
78 *
79 * \warning ARC4 is considered a weak cipher and its use constitutes a
80 * security risk. We recommend considering stronger ciphers instead.
81 *
Paul Bakker5121ce52009-01-03 21:22:43 +000082 */
Dawid Drozd428cc522018-07-24 10:02:47 +020083typedef struct mbedtls_arc4_context
Paul Bakker5121ce52009-01-03 21:22:43 +000084{
85 int x; /*!< permutation index */
86 int y; /*!< permutation index */
87 unsigned char m[256]; /*!< permutation table */
88}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089mbedtls_arc4_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000090
Ron Eldorb2aacec2017-05-18 16:53:08 +030091#else /* MBEDTLS_ARC4_ALT */
92#include "arc4_alt.h"
93#endif /* MBEDTLS_ARC4_ALT */
94
Paul Bakker5121ce52009-01-03 21:22:43 +000095/**
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020096 * \brief Initialize ARC4 context
Paul Bakker5121ce52009-01-03 21:22:43 +000097 *
98 * \param ctx ARC4 context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010099 *
100 * \warning ARC4 is considered a weak cipher and its use constitutes a
101 * security risk. We recommend considering stronger ciphers
102 * instead.
103 *
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200104 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200105void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200106
107/**
108 * \brief Clear ARC4 context
109 *
110 * \param ctx ARC4 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100111 *
112 * \warning ARC4 is considered a weak cipher and its use constitutes a
113 * security risk. We recommend considering stronger ciphers
114 * instead.
115 *
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200116 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200117void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200118
119/**
120 * \brief ARC4 key schedule
121 *
122 * \param ctx ARC4 context to be setup
Paul Bakker5121ce52009-01-03 21:22:43 +0000123 * \param key the secret key
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +0200124 * \param keylen length of the key, in bytes
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100125 *
126 * \warning ARC4 is considered a weak cipher and its use constitutes a
127 * security risk. We recommend considering stronger ciphers
128 * instead.
129 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000130 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200132 unsigned int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000133
134/**
135 * \brief ARC4 cipher function
136 *
137 * \param ctx ARC4 context
Paul Bakkerbaad6502010-03-21 15:42:15 +0000138 * \param length length of the input data
139 * \param input buffer holding the input data
140 * \param output buffer for the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000141 *
Paul Bakker27caa8a2010-03-21 15:43:59 +0000142 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100143 *
144 * \warning ARC4 is considered a weak cipher and its use constitutes a
145 * security risk. We recommend considering stronger ciphers
146 * instead.
147 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000148 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200149int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
Paul Bakkerbaad6502010-03-21 15:42:15 +0000150 unsigned char *output );
Paul Bakker5121ce52009-01-03 21:22:43 +0000151
Ron Eldorfa8f6352017-06-20 15:48:46 +0300152#if defined(MBEDTLS_SELF_TEST)
153
Paul Bakker9a736322012-11-14 12:39:52 +0000154/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000155 * \brief Checkup routine
156 *
157 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100158 *
159 * \warning ARC4 is considered a weak cipher and its use constitutes a
160 * security risk. We recommend considering stronger ciphers
161 * instead.
162 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000163 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200164int mbedtls_arc4_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000165
Ron Eldorfa8f6352017-06-20 15:48:46 +0300166#endif /* MBEDTLS_SELF_TEST */
167
Paul Bakker5121ce52009-01-03 21:22:43 +0000168#ifdef __cplusplus
169}
170#endif
171
172#endif /* arc4.h */