blob: 5fc5395a8c43e4d20aa54236bd27447781e85fbe [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)
Paul Bakker5121ce52009-01-03 21:22:43 +000022 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020023#ifndef MBEDTLS_ARC4_H
24#define MBEDTLS_ARC4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000025
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020027#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#endif
Paul Bakker90995b52013-06-24 19:20:35 +020031
Rich Evans00ab4702015-02-06 13:43:58 +000032#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000033
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020034#if !defined(MBEDTLS_ARC4_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020035// Regular implementation
36//
37
Paul Bakker407a0da2013-06-27 14:29:21 +020038#ifdef __cplusplus
39extern "C" {
40#endif
41
Paul Bakker5121ce52009-01-03 21:22:43 +000042/**
43 * \brief ARC4 context structure
44 */
45typedef struct
46{
47 int x; /*!< permutation index */
48 int y; /*!< permutation index */
49 unsigned char m[256]; /*!< permutation table */
50}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051mbedtls_arc4_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000052
Paul Bakker5121ce52009-01-03 21:22:43 +000053/**
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020054 * \brief Initialize ARC4 context
Paul Bakker5121ce52009-01-03 21:22:43 +000055 *
56 * \param ctx ARC4 context to be initialized
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020057 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020058void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020059
60/**
61 * \brief Clear ARC4 context
62 *
63 * \param ctx ARC4 context to be cleared
64 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020065void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020066
67/**
68 * \brief ARC4 key schedule
69 *
70 * \param ctx ARC4 context to be setup
Paul Bakker5121ce52009-01-03 21:22:43 +000071 * \param key the secret key
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +020072 * \param keylen length of the key, in bytes
Paul Bakker5121ce52009-01-03 21:22:43 +000073 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020074void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +020075 unsigned int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +000076
77/**
78 * \brief ARC4 cipher function
79 *
80 * \param ctx ARC4 context
Paul Bakkerbaad6502010-03-21 15:42:15 +000081 * \param length length of the input data
82 * \param input buffer holding the input data
83 * \param output buffer for the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +000084 *
Paul Bakker27caa8a2010-03-21 15:43:59 +000085 * \return 0 if successful
Paul Bakker5121ce52009-01-03 21:22:43 +000086 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020087int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
Paul Bakkerbaad6502010-03-21 15:42:15 +000088 unsigned char *output );
Paul Bakker5121ce52009-01-03 21:22:43 +000089
Paul Bakker90995b52013-06-24 19:20:35 +020090#ifdef __cplusplus
91}
92#endif
93
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020094#else /* MBEDTLS_ARC4_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +020095#include "arc4_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096#endif /* MBEDTLS_ARC4_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +020097
98#ifdef __cplusplus
99extern "C" {
100#endif
101
Paul Bakker9a736322012-11-14 12:39:52 +0000102/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000103 * \brief Checkup routine
104 *
105 * \return 0 if successful, or 1 if the test failed
106 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200107int mbedtls_arc4_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000108
109#ifdef __cplusplus
110}
111#endif
112
113#endif /* arc4.h */