blob: 6313651207cd5924c56dc53fbe6eb527a3f74dc7 [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úti1e148272020-08-07 13:07:28 +020010 * Copyright The Mbed TLS Contributors
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020011 * 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.
Paul Bakkerb96f1542010-07-18 20:36:00 +000024 *
Paul Bakker5121ce52009-01-03 21:22:43 +000025 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#ifndef MBEDTLS_ARC4_H
27#define MBEDTLS_ARC4_H
Mateusz Starzyk846f0212021-05-19 19:44:07 +020028#include "mbedtls/private_access.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000029
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010031#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020032#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020033#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020034#endif
Paul Bakker90995b52013-06-24 19:20:35 +020035
Rich Evans00ab4702015-02-06 13:43:58 +000036#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000037
Paul Bakker407a0da2013-06-27 14:29:21 +020038#ifdef __cplusplus
39extern "C" {
40#endif
41
Ron Eldorb2aacec2017-05-18 16:53:08 +030042#if !defined(MBEDTLS_ARC4_ALT)
43// Regular implementation
44//
45
Paul Bakker5121ce52009-01-03 21:22:43 +000046/**
Hanno Beckerbbca8c52017-09-25 14:53:51 +010047 * \brief ARC4 context structure
48 *
49 * \warning ARC4 is considered a weak cipher and its use constitutes a
50 * security risk. We recommend considering stronger ciphers instead.
51 *
Paul Bakker5121ce52009-01-03 21:22:43 +000052 */
Dawid Drozd428cc522018-07-24 10:02:47 +020053typedef struct mbedtls_arc4_context
Paul Bakker5121ce52009-01-03 21:22:43 +000054{
Mateusz Starzyk846f0212021-05-19 19:44:07 +020055 int MBEDTLS_PRIVATE(x); /*!< permutation index */
56 int MBEDTLS_PRIVATE(y); /*!< permutation index */
57 unsigned char MBEDTLS_PRIVATE(m)[256]; /*!< permutation table */
Paul Bakker5121ce52009-01-03 21:22:43 +000058}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059mbedtls_arc4_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000060
Ron Eldorb2aacec2017-05-18 16:53:08 +030061#else /* MBEDTLS_ARC4_ALT */
62#include "arc4_alt.h"
63#endif /* MBEDTLS_ARC4_ALT */
64
Paul Bakker5121ce52009-01-03 21:22:43 +000065/**
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020066 * \brief Initialize ARC4 context
Paul Bakker5121ce52009-01-03 21:22:43 +000067 *
68 * \param ctx ARC4 context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010069 *
70 * \warning ARC4 is considered a weak cipher and its use constitutes a
71 * security risk. We recommend considering stronger ciphers
72 * instead.
73 *
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020074 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020076
77/**
78 * \brief Clear ARC4 context
79 *
80 * \param ctx ARC4 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010081 *
82 * \warning ARC4 is considered a weak cipher and its use constitutes a
83 * security risk. We recommend considering stronger ciphers
84 * instead.
85 *
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020086 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020087void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020088
89/**
90 * \brief ARC4 key schedule
91 *
92 * \param ctx ARC4 context to be setup
Paul Bakker5121ce52009-01-03 21:22:43 +000093 * \param key the secret key
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +020094 * \param keylen length of the key, in bytes
Hanno Beckerbbca8c52017-09-25 14:53:51 +010095 *
96 * \warning ARC4 is considered a weak cipher and its use constitutes a
97 * security risk. We recommend considering stronger ciphers
98 * instead.
99 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000100 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200101void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200102 unsigned int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000103
104/**
105 * \brief ARC4 cipher function
106 *
107 * \param ctx ARC4 context
Paul Bakkerbaad6502010-03-21 15:42:15 +0000108 * \param length length of the input data
109 * \param input buffer holding the input data
110 * \param output buffer for the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000111 *
Paul Bakker27caa8a2010-03-21 15:43:59 +0000112 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100113 *
114 * \warning ARC4 is considered a weak cipher and its use constitutes a
115 * security risk. We recommend considering stronger ciphers
116 * instead.
117 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000118 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200119int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
Paul Bakkerbaad6502010-03-21 15:42:15 +0000120 unsigned char *output );
Paul Bakker5121ce52009-01-03 21:22:43 +0000121
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500122#if defined(MBEDTLS_SELF_TEST)
123
Paul Bakker9a736322012-11-14 12:39:52 +0000124/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000125 * \brief Checkup routine
126 *
127 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100128 *
129 * \warning ARC4 is considered a weak cipher and its use constitutes a
130 * security risk. We recommend considering stronger ciphers
131 * instead.
132 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000133 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200134int mbedtls_arc4_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000135
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500136#endif /* MBEDTLS_SELF_TEST */
137
Paul Bakker5121ce52009-01-03 21:22:43 +0000138#ifdef __cplusplus
139}
140#endif
141
142#endif /* arc4.h */