Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file arc4.h |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 3 | * |
Paul Bakker | 37ca75d | 2011-01-06 12:28:03 +0000 | [diff] [blame] | 4 | * \brief The ARCFOUR stream cipher |
| 5 | * |
Manuel Pégourié-Gonnard | 0edee5e | 2015-01-26 15:29:40 +0000 | [diff] [blame^] | 6 | * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 7 | * |
Manuel Pégourié-Gonnard | 0edee5e | 2015-01-26 15:29:40 +0000 | [diff] [blame^] | 8 | * This file is part of mbed TLS (https://www.polarssl.org) |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 9 | * |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 10 | * 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 Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 23 | */ |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 24 | #ifndef POLARSSL_ARC4_H |
| 25 | #define POLARSSL_ARC4_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 26 | |
Paul Bakker | 4087c47 | 2013-06-12 16:49:10 +0200 | [diff] [blame] | 27 | #include "config.h" |
| 28 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 29 | #include <string.h> |
| 30 | |
Paul Bakker | 4087c47 | 2013-06-12 16:49:10 +0200 | [diff] [blame] | 31 | #if !defined(POLARSSL_ARC4_ALT) |
| 32 | // Regular implementation |
| 33 | // |
| 34 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 35 | /** |
| 36 | * \brief ARC4 context structure |
| 37 | */ |
| 38 | typedef struct |
| 39 | { |
| 40 | int x; /*!< permutation index */ |
| 41 | int y; /*!< permutation index */ |
| 42 | unsigned char m[256]; /*!< permutation table */ |
| 43 | } |
| 44 | arc4_context; |
| 45 | |
| 46 | #ifdef __cplusplus |
| 47 | extern "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 Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 57 | void arc4_setup( arc4_context *ctx, const unsigned char *key, unsigned int keylen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * \brief ARC4 cipher function |
| 61 | * |
| 62 | * \param ctx ARC4 context |
Paul Bakker | baad650 | 2010-03-21 15:42:15 +0000 | [diff] [blame] | 63 | * \param length length of the input data |
| 64 | * \param input buffer holding the input data |
| 65 | * \param output buffer for the output data |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 66 | * |
Paul Bakker | 27caa8a | 2010-03-21 15:43:59 +0000 | [diff] [blame] | 67 | * \return 0 if successful |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 68 | */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 69 | int arc4_crypt( arc4_context *ctx, size_t length, const unsigned char *input, |
Paul Bakker | baad650 | 2010-03-21 15:42:15 +0000 | [diff] [blame] | 70 | unsigned char *output ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 71 | |
Paul Bakker | 4087c47 | 2013-06-12 16:49:10 +0200 | [diff] [blame] | 72 | #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 |
| 81 | extern "C" { |
| 82 | #endif |
| 83 | |
Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 84 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 85 | * \brief Checkup routine |
| 86 | * |
| 87 | * \return 0 if successful, or 1 if the test failed |
| 88 | */ |
| 89 | int arc4_self_test( int verbose ); |
| 90 | |
| 91 | #ifdef __cplusplus |
| 92 | } |
| 93 | #endif |
| 94 | |
| 95 | #endif /* arc4.h */ |