blob: 6c9788c7ef17369989169f63288e82b1a1c9f684 [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é-Gonnard860b5162015-01-28 17:12:07 +00008 * This file is part of mbed TLS (https://polarssl.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.
Paul Bakker5121ce52009-01-03 21:22:43 +000023 */
Paul Bakker40e46942009-01-03 21:51:57 +000024#ifndef POLARSSL_ARC4_H
25#define POLARSSL_ARC4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000026
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020027#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
30#include POLARSSL_CONFIG_FILE
31#endif
Paul Bakker90995b52013-06-24 19:20:35 +020032
Paul Bakker23986e52011-04-24 08:57:21 +000033#include <string.h>
34
Paul Bakker90995b52013-06-24 19:20:35 +020035#if !defined(POLARSSL_ARC4_ALT)
36// 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}
52arc4_context;
53
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 */
59void arc4_init( arc4_context *ctx );
60
61/**
62 * \brief Clear ARC4 context
63 *
64 * \param ctx ARC4 context to be cleared
65 */
66void arc4_free( arc4_context *ctx );
67
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 */
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +020075void arc4_setup( arc4_context *ctx, const unsigned char *key,
76 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 */
Paul Bakker23986e52011-04-24 08:57:21 +000088int arc4_crypt( 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
95#else /* POLARSSL_ARC4_ALT */
96#include "arc4_alt.h"
97#endif /* POLARSSL_ARC4_ALT */
98
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 */
108int arc4_self_test( int verbose );
109
110#ifdef __cplusplus
111}
112#endif
113
114#endif /* arc4.h */