blob: 26de33f8d56e9c5aa0a4d027c71118aa5cdf552d [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
Darryl Greena40a1012018-01-05 15:33:17 +00005 */
6/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02007 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02008 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000021 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000022 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000023 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020024#ifndef MBEDTLS_ARC4_H
25#define MBEDTLS_ARC4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000026
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020031#endif
Paul Bakker90995b52013-06-24 19:20:35 +020032
Rich Evans00ab4702015-02-06 13:43:58 +000033#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000034
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020035#if !defined(MBEDTLS_ARC4_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020036// Regular implementation
37//
38
Paul Bakker407a0da2013-06-27 14:29:21 +020039#ifdef __cplusplus
40extern "C" {
41#endif
42
Paul Bakker5121ce52009-01-03 21:22:43 +000043/**
44 * \brief ARC4 context structure
45 */
46typedef struct
47{
48 int x; /*!< permutation index */
49 int y; /*!< permutation index */
50 unsigned char m[256]; /*!< permutation table */
51}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052mbedtls_arc4_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000053
Paul Bakker5121ce52009-01-03 21:22:43 +000054/**
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020055 * \brief Initialize ARC4 context
Paul Bakker5121ce52009-01-03 21:22:43 +000056 *
57 * \param ctx ARC4 context to be initialized
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020058 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020060
61/**
62 * \brief Clear ARC4 context
63 *
64 * \param ctx ARC4 context to be cleared
65 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020066void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +020067
68/**
69 * \brief ARC4 key schedule
70 *
71 * \param ctx ARC4 context to be setup
Paul Bakker5121ce52009-01-03 21:22:43 +000072 * \param key the secret key
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +020073 * \param keylen length of the key, in bytes
Paul Bakker5121ce52009-01-03 21:22:43 +000074 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +020076 unsigned int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +000077
78/**
79 * \brief ARC4 cipher function
80 *
81 * \param ctx ARC4 context
Paul Bakkerbaad6502010-03-21 15:42:15 +000082 * \param length length of the input data
83 * \param input buffer holding the input data
84 * \param output buffer for the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +000085 *
Paul Bakker27caa8a2010-03-21 15:43:59 +000086 * \return 0 if successful
Paul Bakker5121ce52009-01-03 21:22:43 +000087 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
Paul Bakkerbaad6502010-03-21 15:42:15 +000089 unsigned char *output );
Paul Bakker5121ce52009-01-03 21:22:43 +000090
Paul Bakker90995b52013-06-24 19:20:35 +020091#ifdef __cplusplus
92}
93#endif
94
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020095#else /* MBEDTLS_ARC4_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +020096#include "arc4_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020097#endif /* MBEDTLS_ARC4_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +020098
99#ifdef __cplusplus
100extern "C" {
101#endif
102
Paul Bakker9a736322012-11-14 12:39:52 +0000103/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000104 * \brief Checkup routine
105 *
106 * \return 0 if successful, or 1 if the test failed
107 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108int mbedtls_arc4_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000109
110#ifdef __cplusplus
111}
112#endif
113
114#endif /* arc4.h */