blob: 49cc37cdfac76e8c9655bf39557093ea864cc83d [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
5 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +00008 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakkerb96f1542010-07-18 20:36:00 +00009 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Hanno Beckerce0c9db2017-09-28 15:39:45 +010023 *
24 * \warning ARC4 is considered a weak cipher and its use constitutes a
25 * security risk. We recommend considering stronger ciphers instead.
26 *
Paul Bakker5121ce52009-01-03 21:22:43 +000027 */
Paul Bakker40e46942009-01-03 21:51:57 +000028#ifndef POLARSSL_ARC4_H
29#define POLARSSL_ARC4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000030
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020031#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020032#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020033#else
34#include POLARSSL_CONFIG_FILE
35#endif
Paul Bakker90995b52013-06-24 19:20:35 +020036
Rich Evans00ab4702015-02-06 13:43:58 +000037#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000038
Paul Bakker90995b52013-06-24 19:20:35 +020039#if !defined(POLARSSL_ARC4_ALT)
40// Regular implementation
41//
42
Paul Bakker407a0da2013-06-27 14:29:21 +020043#ifdef __cplusplus
44extern "C" {
45#endif
46
Paul Bakker5121ce52009-01-03 21:22:43 +000047/**
48 * \brief ARC4 context structure
Hanno Beckerce0c9db2017-09-28 15:39:45 +010049 *
50 * \warning ARC4 is considered a weak cipher and its use constitutes a
51 * security risk. We recommend considering stronger ciphers
52 * instead.
53 *
Paul Bakker5121ce52009-01-03 21:22:43 +000054 */
55typedef struct
56{
57 int x; /*!< permutation index */
58 int y; /*!< permutation index */
59 unsigned char m[256]; /*!< permutation table */
60}
61arc4_context;
62
Paul Bakker5121ce52009-01-03 21:22:43 +000063/**
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020064 * \brief Initialize ARC4 context
Paul Bakker5121ce52009-01-03 21:22:43 +000065 *
66 * \param ctx ARC4 context to be initialized
Hanno Beckerce0c9db2017-09-28 15:39:45 +010067 *
68 * \warning ARC4 is considered a weak cipher and its use constitutes a
69 * security risk. We recommend considering stronger ciphers
70 * instead.
71 *
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020072 */
73void arc4_init( arc4_context *ctx );
74
75/**
76 * \brief Clear ARC4 context
77 *
78 * \param ctx ARC4 context to be cleared
Hanno Beckerce0c9db2017-09-28 15:39:45 +010079 *
80 * \warning ARC4 is considered a weak cipher and its use constitutes a
81 * security risk. We recommend considering stronger ciphers
82 * instead.
83 *
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020084 */
85void arc4_free( arc4_context *ctx );
86
87/**
88 * \brief ARC4 key schedule
89 *
90 * \param ctx ARC4 context to be setup
Paul Bakker5121ce52009-01-03 21:22:43 +000091 * \param key the secret key
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +020092 * \param keylen length of the key, in bytes
Hanno Beckerce0c9db2017-09-28 15:39:45 +010093 *
94 * \warning ARC4 is considered a weak cipher and its use constitutes a
95 * security risk. We recommend considering stronger ciphers
96 * instead.
97 *
Paul Bakker5121ce52009-01-03 21:22:43 +000098 */
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +020099void arc4_setup( arc4_context *ctx, const unsigned char *key,
100 unsigned int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000101
102/**
103 * \brief ARC4 cipher function
104 *
105 * \param ctx ARC4 context
Paul Bakkerbaad6502010-03-21 15:42:15 +0000106 * \param length length of the input data
107 * \param input buffer holding the input data
108 * \param output buffer for the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000109 *
Paul Bakker27caa8a2010-03-21 15:43:59 +0000110 * \return 0 if successful
Hanno Beckerce0c9db2017-09-28 15:39:45 +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 Bakker5121ce52009-01-03 21:22:43 +0000116 */
Paul Bakker23986e52011-04-24 08:57:21 +0000117int arc4_crypt( arc4_context *ctx, size_t length, const unsigned char *input,
Paul Bakkerbaad6502010-03-21 15:42:15 +0000118 unsigned char *output );
Paul Bakker5121ce52009-01-03 21:22:43 +0000119
Paul Bakker90995b52013-06-24 19:20:35 +0200120#ifdef __cplusplus
121}
122#endif
123
124#else /* POLARSSL_ARC4_ALT */
125#include "arc4_alt.h"
126#endif /* POLARSSL_ARC4_ALT */
127
128#ifdef __cplusplus
129extern "C" {
130#endif
131
Paul Bakker9a736322012-11-14 12:39:52 +0000132/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000133 * \brief Checkup routine
134 *
135 * \return 0 if successful, or 1 if the test failed
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100136 *
137 * \warning ARC4 is considered a weak cipher and its use constitutes a
138 * security risk. We recommend considering stronger ciphers
139 * instead.
140 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000141 */
142int arc4_self_test( int verbose );
143
144#ifdef __cplusplus
145}
146#endif
147
148#endif /* arc4.h */