blob: 046c84f56fc27fa316a5869a108434e142a5c709 [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é-Gonnard0edee5e2015-01-26 15:29:40 +00006 * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
Manuel Pégourié-Gonnarde12abf92015-01-28 17:13:45 +00008 * This file is part of mbed TLS (https://polarssl.org)
Paul Bakkere0ccd0a2009-01-04 16:27:10 +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
Paul Bakker4087c472013-06-12 16:49:10 +020027#include "config.h"
28
Paul Bakker23986e52011-04-24 08:57:21 +000029#include <string.h>
30
Paul Bakker4087c472013-06-12 16:49:10 +020031#if !defined(POLARSSL_ARC4_ALT)
32// Regular implementation
33//
34
Paul Bakker5121ce52009-01-03 21:22:43 +000035/**
36 * \brief ARC4 context structure
37 */
38typedef struct
39{
40 int x; /*!< permutation index */
41 int y; /*!< permutation index */
42 unsigned char m[256]; /*!< permutation table */
43}
44arc4_context;
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50/**
51 * \brief ARC4 key schedule
52 *
53 * \param ctx ARC4 context to be initialized
54 * \param key the secret key
55 * \param keylen length of the key
56 */
Paul Bakker23986e52011-04-24 08:57:21 +000057void arc4_setup( arc4_context *ctx, const unsigned char *key, unsigned int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +000058
59/**
60 * \brief ARC4 cipher function
61 *
62 * \param ctx ARC4 context
Paul Bakkerbaad6502010-03-21 15:42:15 +000063 * \param length length of the input data
64 * \param input buffer holding the input data
65 * \param output buffer for the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +000066 *
Paul Bakker27caa8a2010-03-21 15:43:59 +000067 * \return 0 if successful
Paul Bakker5121ce52009-01-03 21:22:43 +000068 */
Paul Bakker23986e52011-04-24 08:57:21 +000069int arc4_crypt( arc4_context *ctx, size_t length, const unsigned char *input,
Paul Bakkerbaad6502010-03-21 15:42:15 +000070 unsigned char *output );
Paul Bakker5121ce52009-01-03 21:22:43 +000071
Paul Bakker4087c472013-06-12 16:49:10 +020072#ifdef __cplusplus
73}
74#endif
75
76#else /* POLARSSL_ARC4_ALT */
77#include "arc4_alt.h"
78#endif /* POLARSSL_ARC4_ALT */
79
80#ifdef __cplusplus
81extern "C" {
82#endif
83
Paul Bakker9a736322012-11-14 12:39:52 +000084/**
Paul Bakker5121ce52009-01-03 21:22:43 +000085 * \brief Checkup routine
86 *
87 * \return 0 if successful, or 1 if the test failed
88 */
89int arc4_self_test( int verbose );
90
91#ifdef __cplusplus
92}
93#endif
94
95#endif /* arc4.h */