blob: 08ffd2030790f88d5cb9faf1b8e0c73aa6f4b858 [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é-Gonnard6fb81872015-07-27 11:11:48 +02006 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02007 * SPDX-License-Identifier: Apache-2.0
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
10 * not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000020 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000021 * This file is part of mbed TLS (https://tls.mbed.org)
Hanno Becker15e49512017-09-25 14:53:51 +010022 *
23 * \warning ARC4 is considered a weak cipher and its use constitutes a
24 * security risk. We recommend considering stronger ciphers instead.
25 *
Paul Bakker5121ce52009-01-03 21:22:43 +000026 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#ifndef MBEDTLS_ARC4_H
28#define MBEDTLS_ARC4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000029
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020031#include "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
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020038#if !defined(MBEDTLS_ARC4_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020039// Regular implementation
40//
41
Paul Bakker407a0da2013-06-27 14:29:21 +020042#ifdef __cplusplus
43extern "C" {
44#endif
45
Paul Bakker5121ce52009-01-03 21:22:43 +000046/**
Hanno Becker15e49512017-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 */
53typedef struct
54{
55 int x; /*!< permutation index */
56 int y; /*!< permutation index */
57 unsigned char m[256]; /*!< permutation table */
58}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059mbedtls_arc4_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000060
Paul Bakker5121ce52009-01-03 21:22:43 +000061/**
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020062 * \brief Initialize ARC4 context
Paul Bakker5121ce52009-01-03 21:22:43 +000063 *
64 * \param ctx ARC4 context to be initialized
Hanno Becker15e49512017-09-25 14:53:51 +010065 *
66 * \warning ARC4 is considered a weak cipher and its use constitutes a
67 * security risk. We recommend considering stronger ciphers
68 * instead.
69 *
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020070 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020071void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020072
73/**
74 * \brief Clear ARC4 context
75 *
76 * \param ctx ARC4 context to be cleared
Hanno Becker15e49512017-09-25 14:53:51 +010077 *
78 * \warning ARC4 is considered a weak cipher and its use constitutes a
79 * security risk. We recommend considering stronger ciphers
80 * instead.
81 *
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020082 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020084
85/**
86 * \brief ARC4 key schedule
87 *
88 * \param ctx ARC4 context to be setup
Paul Bakker5121ce52009-01-03 21:22:43 +000089 * \param key the secret key
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +020090 * \param keylen length of the key, in bytes
Hanno Becker15e49512017-09-25 14:53:51 +010091 *
92 * \warning ARC4 is considered a weak cipher and its use constitutes a
93 * security risk. We recommend considering stronger ciphers
94 * instead.
95 *
Paul Bakker5121ce52009-01-03 21:22:43 +000096 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020097void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +020098 unsigned int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +000099
100/**
101 * \brief ARC4 cipher function
102 *
103 * \param ctx ARC4 context
Paul Bakkerbaad6502010-03-21 15:42:15 +0000104 * \param length length of the input data
105 * \param input buffer holding the input data
106 * \param output buffer for the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000107 *
Paul Bakker27caa8a2010-03-21 15:43:59 +0000108 * \return 0 if successful
Hanno Becker15e49512017-09-25 14:53:51 +0100109 *
110 * \warning ARC4 is considered a weak cipher and its use constitutes a
111 * security risk. We recommend considering stronger ciphers
112 * instead.
113 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000114 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200115int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
Paul Bakkerbaad6502010-03-21 15:42:15 +0000116 unsigned char *output );
Paul Bakker5121ce52009-01-03 21:22:43 +0000117
Paul Bakker90995b52013-06-24 19:20:35 +0200118#ifdef __cplusplus
119}
120#endif
121
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200122#else /* MBEDTLS_ARC4_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200123#include "arc4_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124#endif /* MBEDTLS_ARC4_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200125
126#ifdef __cplusplus
127extern "C" {
128#endif
129
Paul Bakker9a736322012-11-14 12:39:52 +0000130/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000131 * \brief Checkup routine
132 *
133 * \return 0 if successful, or 1 if the test failed
Hanno Becker15e49512017-09-25 14:53:51 +0100134 *
135 * \warning ARC4 is considered a weak cipher and its use constitutes a
136 * security risk. We recommend considering stronger ciphers
137 * instead.
138 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000139 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140int mbedtls_arc4_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000141
142#ifdef __cplusplus
143}
144#endif
145
146#endif /* arc4.h */