blob: fb044d5b7fd33d4a2f8b25192a29ec31b8b6f3be [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/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +020010 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
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 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000025 * This file is part of mbed TLS (https://tls.mbed.org)
Hanno Beckerbbca8c52017-09-25 14:53:51 +010026 *
Paul Bakker5121ce52009-01-03 21:22:43 +000027 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#ifndef MBEDTLS_ARC4_H
29#define MBEDTLS_ARC4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000030
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020031#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020032#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020033#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020034#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020035#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
Ron Eldor9924bdc2018-10-04 10:59:13 +030039/* MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010040#define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED -0x0019 /**< ARC4 hardware accelerator failed. */
41
Paul Bakker407a0da2013-06-27 14:29:21 +020042#ifdef __cplusplus
43extern "C" {
44#endif
45
Ron Eldorb2aacec2017-05-18 16:53:08 +030046#if !defined(MBEDTLS_ARC4_ALT)
47// Regular implementation
48//
49
Paul Bakker5121ce52009-01-03 21:22:43 +000050/**
Hanno Beckerbbca8c52017-09-25 14:53:51 +010051 * \brief ARC4 context structure
52 *
53 * \warning ARC4 is considered a weak cipher and its use constitutes a
54 * security risk. We recommend considering stronger ciphers instead.
55 *
Paul Bakker5121ce52009-01-03 21:22:43 +000056 */
Dawid Drozd428cc522018-07-24 10:02:47 +020057typedef struct mbedtls_arc4_context
Paul Bakker5121ce52009-01-03 21:22:43 +000058{
59 int x; /*!< permutation index */
60 int y; /*!< permutation index */
61 unsigned char m[256]; /*!< permutation table */
62}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063mbedtls_arc4_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000064
Ron Eldorb2aacec2017-05-18 16:53:08 +030065#else /* MBEDTLS_ARC4_ALT */
66#include "arc4_alt.h"
67#endif /* MBEDTLS_ARC4_ALT */
68
Paul Bakker5121ce52009-01-03 21:22:43 +000069/**
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020070 * \brief Initialize ARC4 context
Paul Bakker5121ce52009-01-03 21:22:43 +000071 *
72 * \param ctx ARC4 context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010073 *
74 * \warning ARC4 is considered a weak cipher and its use constitutes a
75 * security risk. We recommend considering stronger ciphers
76 * instead.
77 *
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020078 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020079void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020080
81/**
82 * \brief Clear ARC4 context
83 *
84 * \param ctx ARC4 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010085 *
86 * \warning ARC4 is considered a weak cipher and its use constitutes a
87 * security risk. We recommend considering stronger ciphers
88 * instead.
89 *
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020090 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020091void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020092
93/**
94 * \brief ARC4 key schedule
95 *
96 * \param ctx ARC4 context to be setup
Paul Bakker5121ce52009-01-03 21:22:43 +000097 * \param key the secret key
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +020098 * \param keylen length of the key, in bytes
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 Bakker5121ce52009-01-03 21:22:43 +0000104 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200105void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200106 unsigned int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000107
108/**
109 * \brief ARC4 cipher function
110 *
111 * \param ctx ARC4 context
Paul Bakkerbaad6502010-03-21 15:42:15 +0000112 * \param length length of the input data
113 * \param input buffer holding the input data
114 * \param output buffer for the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000115 *
Paul Bakker27caa8a2010-03-21 15:43:59 +0000116 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100117 *
118 * \warning ARC4 is considered a weak cipher and its use constitutes a
119 * security risk. We recommend considering stronger ciphers
120 * instead.
121 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000122 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
Paul Bakkerbaad6502010-03-21 15:42:15 +0000124 unsigned char *output );
Paul Bakker5121ce52009-01-03 21:22:43 +0000125
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500126#if defined(MBEDTLS_SELF_TEST)
127
Paul Bakker9a736322012-11-14 12:39:52 +0000128/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000129 * \brief Checkup routine
130 *
131 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100132 *
133 * \warning ARC4 is considered a weak cipher and its use constitutes a
134 * security risk. We recommend considering stronger ciphers
135 * instead.
136 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000137 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200138int mbedtls_arc4_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000139
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500140#endif /* MBEDTLS_SELF_TEST */
141
Paul Bakker5121ce52009-01-03 21:22:43 +0000142#ifdef __cplusplus
143}
144#endif
145
146#endif /* arc4.h */